2 * Copyright (c) 1995 Steven Wallace
3 * Copyright (c) 1994, 1995 Scott Bartram
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley.
11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement:
13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratory.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgement:
26 * This product includes software developed by the University of
27 * California, Berkeley and its contributors.
28 * 4. Neither the name of the University nor the names of its contributors
29 * may be used to endorse or promote products derived from this software
30 * without specific prior written permission.
32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
46 * @(#)sun_misc.c 8.1 (Berkeley) 6/18/93
48 * $FreeBSD: src/sys/i386/ibcs2/ibcs2_misc.c,v 1.34 1999/09/29 15:12:09 marcel Exp $
49 * $DragonFly: src/sys/emulation/ibcs2/i386/Attic/ibcs2_misc.c,v 1.10 2004/10/12 19:20:36 dillon Exp $
53 * IBCS2 compatibility module.
55 * IBCS2 system calls that are implemented differently in BSD are
58 #include <sys/param.h>
59 #include <sys/dirent.h>
60 #include <sys/fcntl.h>
62 #include <sys/filedesc.h>
63 #include <sys/kernel.h>
65 #include <sys/malloc.h>
66 #include <sys/reboot.h>
67 #include <sys/resourcevar.h>
69 #include <sys/sysctl.h>
70 #include <sys/sysproto.h>
71 #include <sys/systm.h>
73 #include <sys/times.h>
74 #include <sys/vnode.h>
77 #include <machine/cpu.h>
79 #include "ibcs2_dirent.h"
80 #include "ibcs2_signal.h"
81 #include "ibcs2_proto.h"
82 #include "ibcs2_unistd.h"
83 #include "ibcs2_util.h"
84 #include "ibcs2_utime.h"
85 #include "ibcs2_xenix.h"
88 ibcs2_ulimit(struct ibcs2_ulimit_args *uap)
93 struct setrlimit_args {
98 struct proc *p = curproc;
100 #define IBCS2_GETFSIZE 1
101 #define IBCS2_SETFSIZE 2
102 #define IBCS2_GETPSIZE 3
103 #define IBCS2_GETDTABLESIZE 4
105 switch (SCARG(uap, cmd)) {
107 uap->sysmsg_result = p->p_rlimit[RLIMIT_FSIZE].rlim_cur;
108 if (uap->sysmsg_result == -1)
109 uap->sysmsg_result = 0x7fffffff;
111 case IBCS2_SETFSIZE: /* XXX - fix this */
113 rl.rlim_cur = SCARG(uap, newlimit);
114 sra.resource = RLIMIT_FSIZE;
116 error = setrlimit(&sra);
118 uap->sysmsg_result = p->p_rlimit[RLIMIT_FSIZE].rlim_cur;
120 DPRINTF(("failed "));
123 uap->sysmsg_result = SCARG(uap, newlimit);
127 uap->sysmsg_result = p->p_rlimit[RLIMIT_RSS].rlim_cur; /* XXX */
129 case IBCS2_GETDTABLESIZE:
130 uap->cmd = IBCS2_SC_OPEN_MAX;
131 return ibcs2_sysconf((struct ibcs2_sysconf_args *)uap);
137 #define IBCS2_WSTOPPED 0177
138 #define IBCS2_STOPCODE(sig) ((sig) << 8 | IBCS2_WSTOPPED)
140 ibcs2_wait(struct ibcs2_wait_args *uap)
142 struct proc *p = curproc;
145 struct trapframe *tf = p->p_md.md_regs;
147 SCARG(&w4, rusage) = NULL;
148 if ((tf->tf_eflags & (PSL_Z|PSL_PF|PSL_N|PSL_V))
149 == (PSL_Z|PSL_PF|PSL_N|PSL_V)) {
151 SCARG(&w4, pid) = SCARG(uap, a1);
152 SCARG(&w4, status) = (int *)SCARG(uap, a2);
153 SCARG(&w4, options) = SCARG(uap, a3);
156 SCARG(&w4, pid) = WAIT_ANY;
157 SCARG(&w4, status) = (int *)SCARG(uap, a1);
158 SCARG(&w4, options) = 0;
160 if ((error = wait4(&w4)) != 0)
162 uap->sysmsg_fds[0] = w4.sysmsg_fds[0];
163 if (SCARG(&w4, status)) { /* this is real iBCS brain-damage */
164 error = copyin((caddr_t)SCARG(&w4, status), (caddr_t)&status,
165 sizeof(SCARG(&w4, status)));
169 /* convert status/signal result */
170 if(WIFSTOPPED(status))
172 IBCS2_STOPCODE(bsd_to_ibcs2_sig[_SIG_IDX(WSTOPSIG(status))]);
173 else if(WIFSIGNALED(status))
174 status = bsd_to_ibcs2_sig[_SIG_IDX(WTERMSIG(status))];
175 /* else exit status -- identical */
177 /* record result/status */
178 uap->sysmsg_fds[1] = status;
179 return copyout((caddr_t)&status, (caddr_t)SCARG(&w4, status),
180 sizeof(SCARG(&w4, status)));
187 ibcs2_execv(struct ibcs2_execv_args *uap)
189 struct execve_args ea;
190 caddr_t sg = stackgap_init();
193 CHECKALTEXIST(&sg, uap->path);
195 /* note: parts of result64 may be maintained or cleared by execve */
196 ea.sysmsg_result64 = uap->sysmsg_result64;
197 ea.fname = uap->path;
201 uap->sysmsg_result64 = ea.sysmsg_result64;
206 ibcs2_execve(struct ibcs2_execve_args *uap)
208 caddr_t sg = stackgap_init();
209 CHECKALTEXIST(&sg, SCARG(uap, path));
210 return execve((struct execve_args *)uap);
214 ibcs2_umount(struct ibcs2_umount_args *uap)
216 struct unmount_args um;
219 SCARG(&um, path) = SCARG(uap, name);
220 SCARG(&um, flags) = 0;
221 error = unmount(&um);
222 uap->sysmsg_result = um.sysmsg_result;
227 ibcs2_mount(struct ibcs2_mount_args *uap)
230 int oflags = SCARG(uap, flags), nflags, error;
231 char fsname[MFSNAMELEN];
233 if (oflags & (IBCS2_MS_NOSUB | IBCS2_MS_SYS5))
235 if ((oflags & IBCS2_MS_NEWTYPE) == 0)
238 if (oflags & IBCS2_MS_RDONLY)
239 nflags |= MNT_RDONLY;
240 if (oflags & IBCS2_MS_NOSUID)
241 nflags |= MNT_NOSUID;
242 if (oflags & IBCS2_MS_REMOUNT)
243 nflags |= MNT_UPDATE;
244 SCARG(uap, flags) = nflags;
246 if (error = copyinstr((caddr_t)SCARG(uap, type), fsname, sizeof fsname,
250 if (strcmp(fsname, "4.2") == 0) {
251 SCARG(uap, type) = (caddr_t)STACK_ALLOC();
252 if (error = copyout("ufs", SCARG(uap, type), sizeof("ufs")))
254 } else if (strcmp(fsname, "nfs") == 0) {
255 struct ibcs2_nfs_args sna;
256 struct sockaddr_in sain;
260 if (error = copyin(SCARG(uap, data), &sna, sizeof sna))
262 if (error = copyin(sna.addr, &sain, sizeof sain))
264 bcopy(&sain, &sa, sizeof sa);
265 sa.sa_len = sizeof(sain);
266 SCARG(uap, data) = (caddr_t)STACK_ALLOC();
267 na.addr = (struct sockaddr *)((int)SCARG(uap, data) + sizeof na);
268 na.sotype = SOCK_DGRAM;
269 na.proto = IPPROTO_UDP;
270 na.fh = (nfsv2fh_t *)sna.fh;
271 na.flags = sna.flags;
272 na.wsize = sna.wsize;
273 na.rsize = sna.rsize;
274 na.timeo = sna.timeo;
275 na.retrans = sna.retrans;
276 na.hostname = sna.hostname;
278 if (error = copyout(&sa, na.addr, sizeof sa))
280 if (error = copyout(&na, SCARG(uap, data), sizeof na))
290 * Read iBCS2-style directory entries. We suck them into kernel space so
291 * that they can be massaged before being copied out to user code. Like
292 * SunOS, we squish out `empty' entries.
294 * This is quite ugly, but what do you expect from compatibility code?
298 ibcs2_getdents(struct ibcs2_getdents_args *uap)
300 struct thread *td = curthread;
301 struct proc *p = td->td_proc;
303 caddr_t inp, buf; /* BSD-format */
304 int len, reclen; /* BSD-format */
305 caddr_t outp; /* iBCS2-format */
306 int resid; /* iBCS2-format */
310 struct ibcs2_dirent idb;
311 off_t off; /* true file offset */
312 int buflen, error, eofflag;
313 u_long *cookies = NULL, *cookiep;
315 #define BSD_DIRENT(cp) ((struct dirent *)(cp))
316 #define IBCS2_RECLEN(reclen) (reclen + sizeof(u_short))
320 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
322 if ((fp->f_flag & FREAD) == 0)
324 vp = (struct vnode *)fp->f_data;
325 if (vp->v_type != VDIR) /* XXX vnode readdir op should do this */
329 #define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */
330 buflen = max(DIRBLKSIZ, SCARG(uap, nbytes));
331 buflen = min(buflen, MAXBSIZE);
332 buf = malloc(buflen, M_TEMP, M_WAITOK);
333 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
336 aiov.iov_len = buflen;
337 auio.uio_iov = &aiov;
339 auio.uio_rw = UIO_READ;
340 auio.uio_segflg = UIO_SYSSPACE;
342 auio.uio_resid = buflen;
343 auio.uio_offset = off;
346 free(cookies, M_TEMP);
351 * First we read into the malloc'ed buffer, then
352 * we massage it into user space, one record at a time.
354 if ((error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies, &cookies)) != 0)
357 outp = SCARG(uap, buf);
358 resid = SCARG(uap, nbytes);
359 if ((len = buflen - auio.uio_resid) <= 0)
366 * When using cookies, the vfs has the option of reading from
367 * a different offset than that supplied (UFS truncates the
368 * offset to a block boundary to make sure that it never reads
369 * partway through a directory entry, even if the directory
370 * has been compacted).
372 while (len > 0 && ncookies > 0 && *cookiep <= off) {
373 len -= BSD_DIRENT(inp)->d_reclen;
374 inp += BSD_DIRENT(inp)->d_reclen;
380 for (; len > 0; len -= reclen) {
381 if (cookiep && ncookies == 0)
383 reclen = BSD_DIRENT(inp)->d_reclen;
385 printf("ibcs2_getdents: reclen=%d\n", reclen);
389 if (BSD_DIRENT(inp)->d_fileno == 0) {
390 inp += reclen; /* it is a hole; squish it out */
398 if (reclen > len || resid < IBCS2_RECLEN(reclen)) {
399 /* entry too big for buffer, so just stop */
404 * Massage in place to make a iBCS2-shaped dirent (otherwise
405 * we have to worry about touching user memory outside of
406 * the copyout() call).
408 idb.d_ino = (ibcs2_ino_t)BSD_DIRENT(inp)->d_fileno;
409 idb.d_off = (ibcs2_off_t)off;
410 idb.d_reclen = (u_short)IBCS2_RECLEN(reclen);
411 if ((error = copyout((caddr_t)&idb, outp, 10)) != 0 ||
412 (error = copyout(BSD_DIRENT(inp)->d_name, outp + 10,
413 BSD_DIRENT(inp)->d_namlen + 1)) != 0)
415 /* advance past this real entry */
422 /* advance output past iBCS2-shaped entry */
423 outp += IBCS2_RECLEN(reclen);
424 resid -= IBCS2_RECLEN(reclen);
426 /* if we squished out the whole block, try again */
427 if (outp == SCARG(uap, buf))
429 fp->f_offset = off; /* update the vnode offset */
431 uap->sysmsg_result = SCARG(uap, nbytes) - resid;
434 free(cookies, M_TEMP);
435 VOP_UNLOCK(vp, 0, td);
441 ibcs2_read(struct ibcs2_read_args *uap)
443 struct thread *td = curthread;
444 struct proc *p = td->td_proc;
446 caddr_t inp, buf; /* BSD-format */
447 int len, reclen; /* BSD-format */
448 caddr_t outp; /* iBCS2-format */
449 int resid; /* iBCS2-format */
453 struct ibcs2_direct {
457 off_t off; /* true file offset */
458 int buflen, error, eofflag, size;
459 u_long *cookies = NULL, *cookiep;
464 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) {
466 return read((struct read_args *)uap);
470 if ((fp->f_flag & FREAD) == 0)
472 vp = (struct vnode *)fp->f_data;
473 if (vp->v_type != VDIR)
474 return read((struct read_args *)uap);
476 DPRINTF(("ibcs2_read: read directory\n"));
479 buflen = max(DIRBLKSIZ, SCARG(uap, nbytes));
480 buflen = min(buflen, MAXBSIZE);
481 buf = malloc(buflen, M_TEMP, M_WAITOK);
482 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
485 aiov.iov_len = buflen;
486 auio.uio_iov = &aiov;
488 auio.uio_rw = UIO_READ;
489 auio.uio_segflg = UIO_SYSSPACE;
491 auio.uio_resid = buflen;
492 auio.uio_offset = off;
495 free(cookies, M_TEMP);
500 * First we read into the malloc'ed buffer, then
501 * we massage it into user space, one record at a time.
503 if ((error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies, &cookies)) != 0) {
504 DPRINTF(("VOP_READDIR failed: %d\n", error));
508 outp = SCARG(uap, buf);
509 resid = SCARG(uap, nbytes);
510 if ((len = buflen - auio.uio_resid) <= 0)
517 * When using cookies, the vfs has the option of reading from
518 * a different offset than that supplied (UFS truncates the
519 * offset to a block boundary to make sure that it never reads
520 * partway through a directory entry, even if the directory
521 * has been compacted).
523 while (len > 0 && ncookies > 0 && *cookiep <= off) {
524 len -= BSD_DIRENT(inp)->d_reclen;
525 inp += BSD_DIRENT(inp)->d_reclen;
531 for (; len > 0 && resid > 0; len -= reclen) {
532 if (cookiep && ncookies == 0)
534 reclen = BSD_DIRENT(inp)->d_reclen;
536 printf("ibcs2_read: reclen=%d\n", reclen);
540 if (BSD_DIRENT(inp)->d_fileno == 0) {
541 inp += reclen; /* it is a hole; squish it out */
549 if (reclen > len || resid < sizeof(struct ibcs2_direct)) {
550 /* entry too big for buffer, so just stop */
555 * Massage in place to make a iBCS2-shaped dirent (otherwise
556 * we have to worry about touching user memory outside of
557 * the copyout() call).
559 * TODO: if length(filename) > 14, then break filename into
560 * multiple entries and set inode = 0xffff except last
562 idb.ino = (BSD_DIRENT(inp)->d_fileno > 0xfffe) ? 0xfffe :
563 BSD_DIRENT(inp)->d_fileno;
564 (void)copystr(BSD_DIRENT(inp)->d_name, idb.name, 14, &size);
565 bzero(idb.name + size, 14 - size);
566 if ((error = copyout(&idb, outp, sizeof(struct ibcs2_direct))) != 0)
568 /* advance past this real entry */
575 /* advance output past iBCS2-shaped entry */
576 outp += sizeof(struct ibcs2_direct);
577 resid -= sizeof(struct ibcs2_direct);
579 /* if we squished out the whole block, try again */
580 if (outp == SCARG(uap, buf))
582 fp->f_offset = off; /* update the vnode offset */
584 uap->sysmsg_result = SCARG(uap, nbytes) - resid;
587 free(cookies, M_TEMP);
588 VOP_UNLOCK(vp, 0, td);
594 ibcs2_mknod(struct ibcs2_mknod_args *uap)
596 caddr_t sg = stackgap_init();
599 CHECKALTCREAT(&sg, SCARG(uap, path));
600 if (S_ISFIFO(SCARG(uap, mode))) {
601 struct mkfifo_args ap;
602 SCARG(&ap, path) = SCARG(uap, path);
603 SCARG(&ap, mode) = SCARG(uap, mode);
605 uap->sysmsg_result = ap.sysmsg_result;
607 struct mknod_args ap;
608 SCARG(&ap, path) = SCARG(uap, path);
609 SCARG(&ap, mode) = SCARG(uap, mode);
610 SCARG(&ap, dev) = SCARG(uap, dev);
612 uap->sysmsg_result = ap.sysmsg_result;
618 ibcs2_getgroups(struct ibcs2_getgroups_args *uap)
621 ibcs2_gid_t *iset = NULL;
622 struct getgroups_args sa;
624 caddr_t sg = stackgap_init();
626 SCARG(&sa, gidsetsize) = SCARG(uap, gidsetsize);
627 if (SCARG(uap, gidsetsize)) {
628 SCARG(&sa, gidset) = stackgap_alloc(&sg, NGROUPS_MAX *
630 iset = stackgap_alloc(&sg, SCARG(uap, gidsetsize) *
631 sizeof(ibcs2_gid_t));
633 if ((error = getgroups(&sa)) != 0)
635 uap->sysmsg_result = sa.sysmsg_result;
636 if (SCARG(uap, gidsetsize) == 0)
639 for (i = 0, gp = SCARG(&sa, gidset); i < uap->sysmsg_result; i++)
640 iset[i] = (ibcs2_gid_t)*gp++;
641 if (uap->sysmsg_result && (error = copyout((caddr_t)iset,
642 (caddr_t)SCARG(uap, gidset),
643 sizeof(ibcs2_gid_t) * uap->sysmsg_result)))
649 ibcs2_setgroups(struct ibcs2_setgroups_args *uap)
653 struct setgroups_args sa;
655 caddr_t sg = stackgap_init();
657 SCARG(&sa, gidsetsize) = SCARG(uap, gidsetsize);
658 SCARG(&sa, gidset) = stackgap_alloc(&sg, SCARG(&sa, gidsetsize) *
660 iset = stackgap_alloc(&sg, SCARG(&sa, gidsetsize) *
661 sizeof(ibcs2_gid_t *));
662 if (SCARG(&sa, gidsetsize)) {
663 if ((error = copyin((caddr_t)SCARG(uap, gidset), (caddr_t)iset,
664 sizeof(ibcs2_gid_t *) *
665 SCARG(uap, gidsetsize))) != 0)
668 for (i = 0, gp = SCARG(&sa, gidset); i < SCARG(&sa, gidsetsize); i++)
669 *gp++ = (gid_t)iset[i];
670 error = setgroups(&sa);
671 uap->sysmsg_result = sa.sysmsg_result;
676 ibcs2_setuid(struct ibcs2_setuid_args *uap)
678 struct setuid_args sa;
681 SCARG(&sa, uid) = (uid_t)SCARG(uap, uid);
683 uap->sysmsg_result = sa.sysmsg_result;
688 ibcs2_setgid(struct ibcs2_setgid_args *uap)
690 struct setgid_args sa;
693 SCARG(&sa, gid) = (gid_t)SCARG(uap, gid);
695 uap->sysmsg_result = sa.sysmsg_result;
700 ibcs2_time(struct ibcs2_time_args *uap)
705 uap->sysmsg_result = tv.tv_sec;
707 return copyout((caddr_t)&tv.tv_sec, (caddr_t)SCARG(uap, tp),
708 sizeof(ibcs2_time_t));
714 ibcs2_pathconf(struct ibcs2_pathconf_args *uap)
716 SCARG(uap, name)++; /* iBCS2 _PC_* defines are offset by one */
717 return pathconf((struct pathconf_args *)uap);
721 ibcs2_fpathconf(struct ibcs2_fpathconf_args *uap)
723 SCARG(uap, name)++; /* iBCS2 _PC_* defines are offset by one */
724 return fpathconf((struct fpathconf_args *)uap);
728 ibcs2_sysconf(struct ibcs2_sysconf_args *uap)
730 int mib[2], value, len, error;
731 struct sysctl_args sa;
732 struct __getrlimit_args ga;
734 switch(SCARG(uap, name)) {
735 case IBCS2_SC_ARG_MAX:
736 mib[1] = KERN_ARGMAX;
739 case IBCS2_SC_CHILD_MAX:
741 caddr_t sg = stackgap_init();
743 SCARG(&ga, which) = RLIMIT_NPROC;
744 SCARG(&ga, rlp) = stackgap_alloc(&sg, sizeof(struct rlimit *));
745 if ((error = getrlimit(&ga)) != 0)
747 uap->sysmsg_result = SCARG(&ga, rlp)->rlim_cur;
751 case IBCS2_SC_CLK_TCK:
752 uap->sysmsg_result = hz;
755 case IBCS2_SC_NGROUPS_MAX:
756 mib[1] = KERN_NGROUPS;
759 case IBCS2_SC_OPEN_MAX:
761 caddr_t sg = stackgap_init();
763 SCARG(&ga, which) = RLIMIT_NOFILE;
764 SCARG(&ga, rlp) = stackgap_alloc(&sg, sizeof(struct rlimit *));
765 if ((error = getrlimit(&ga)) != 0)
767 uap->sysmsg_result = SCARG(&ga, rlp)->rlim_cur;
771 case IBCS2_SC_JOB_CONTROL:
772 mib[1] = KERN_JOB_CONTROL;
775 case IBCS2_SC_SAVED_IDS:
776 mib[1] = KERN_SAVED_IDS;
779 case IBCS2_SC_VERSION:
780 mib[1] = KERN_POSIX1;
783 case IBCS2_SC_PASS_MAX:
784 uap->sysmsg_result = 128; /* XXX - should we create PASS_MAX ? */
787 case IBCS2_SC_XOPEN_VERSION:
788 uap->sysmsg_result = 2; /* XXX: What should that be? */
797 SCARG(&sa, name) = mib;
798 SCARG(&sa, namelen) = 2;
799 SCARG(&sa, old) = &value;
800 SCARG(&sa, oldlenp) = &len;
801 SCARG(&sa, new) = NULL;
802 SCARG(&sa, newlen) = 0;
803 if ((error = __sysctl(&sa)) != 0)
805 uap->sysmsg_result = value;
810 ibcs2_alarm(struct ibcs2_alarm_args *uap)
813 struct itimerval *itp, *oitp;
814 struct setitimer_args sa;
815 caddr_t sg = stackgap_init();
817 itp = stackgap_alloc(&sg, sizeof(*itp));
818 oitp = stackgap_alloc(&sg, sizeof(*oitp));
819 timevalclear(&itp->it_interval);
820 itp->it_value.tv_sec = SCARG(uap, sec);
821 itp->it_value.tv_usec = 0;
823 SCARG(&sa, which) = ITIMER_REAL;
824 SCARG(&sa, itv) = itp;
825 SCARG(&sa, oitv) = oitp;
826 error = setitimer(&sa);
829 if (oitp->it_value.tv_usec)
830 oitp->it_value.tv_sec++;
831 uap->sysmsg_result = oitp->it_value.tv_sec;
836 ibcs2_times(struct ibcs2_times_args *uap)
839 struct getrusage_args ga;
842 caddr_t sg = stackgap_init();
843 struct rusage *ru = stackgap_alloc(&sg, sizeof(*ru));
844 #define CONVTCK(r) (r.tv_sec * hz + r.tv_usec / (1000000 / hz))
846 SCARG(&ga, who) = RUSAGE_SELF;
847 SCARG(&ga, rusage) = ru;
848 error = getrusage(&ga);
851 tms.tms_utime = CONVTCK(ru->ru_utime);
852 tms.tms_stime = CONVTCK(ru->ru_stime);
854 SCARG(&ga, who) = RUSAGE_CHILDREN;
855 error = getrusage(&ga);
858 tms.tms_cutime = CONVTCK(ru->ru_utime);
859 tms.tms_cstime = CONVTCK(ru->ru_stime);
862 uap->sysmsg_result = CONVTCK(t);
864 return copyout((caddr_t)&tms, (caddr_t)SCARG(uap, tp),
869 ibcs2_stime(struct ibcs2_stime_args *uap)
872 struct settimeofday_args sa;
873 caddr_t sg = stackgap_init();
875 SCARG(&sa, tv) = stackgap_alloc(&sg, sizeof(*SCARG(&sa, tv)));
876 SCARG(&sa, tzp) = NULL;
877 if ((error = copyin((caddr_t)SCARG(uap, timep),
878 &(SCARG(&sa, tv)->tv_sec), sizeof(long))) != 0)
880 SCARG(&sa, tv)->tv_usec = 0;
881 if ((error = settimeofday(&sa)) != 0)
883 uap->sysmsg_result = sa.sysmsg_result;
888 ibcs2_utime(struct ibcs2_utime_args *uap)
891 struct utimes_args sa;
893 caddr_t sg = stackgap_init();
895 CHECKALTEXIST(&sg, SCARG(uap, path));
896 SCARG(&sa, path) = SCARG(uap, path);
897 if (SCARG(uap, buf)) {
898 struct ibcs2_utimbuf ubuf;
900 if ((error = copyin((caddr_t)SCARG(uap, buf), (caddr_t)&ubuf,
903 SCARG(&sa, tptr) = stackgap_alloc(&sg,
904 2 * sizeof(struct timeval *));
905 tp = (struct timeval *)SCARG(&sa, tptr);
906 tp->tv_sec = ubuf.actime;
909 tp->tv_sec = ubuf.modtime;
912 SCARG(&sa, tptr) = NULL;
914 uap->sysmsg_result = sa.sysmsg_result;
919 ibcs2_nice(struct ibcs2_nice_args *uap)
921 struct proc *p = curproc;
923 struct setpriority_args sa;
925 SCARG(&sa, which) = PRIO_PROCESS;
927 SCARG(&sa, prio) = p->p_nice + SCARG(uap, incr);
928 if ((error = setpriority(&sa)) != 0)
930 uap->sysmsg_result = p->p_nice;
935 * iBCS2 getpgrp, setpgrp, setsid, and setpgid
939 ibcs2_pgrpsys(struct ibcs2_pgrpsys_args *uap)
941 struct proc *p = curproc;
943 switch (SCARG(uap, type)) {
944 case 0: /* getpgrp */
945 uap->sysmsg_result = p->p_pgrp->pg_id;
948 case 1: /* setpgrp */
950 struct setpgid_args sa;
953 SCARG(&sa, pgid) = 0;
955 uap->sysmsg_result = p->p_pgrp->pg_id;
959 case 2: /* setpgid */
961 struct setpgid_args sa;
964 SCARG(&sa, pid) = SCARG(uap, pid);
965 SCARG(&sa, pgid) = SCARG(uap, pgid);
966 error = setpgid(&sa);
967 uap->sysmsg_result = sa.sysmsg_result;
973 struct setsid_args sida;
976 error = setsid(&sida);
977 uap->sysmsg_result = sida.sysmsg_result;
987 * XXX - need to check for nested calls
991 ibcs2_plock(struct ibcs2_plock_args *uap)
994 #define IBCS2_UNLOCK 0
995 #define IBCS2_PROCLOCK 1
996 #define IBCS2_TEXTLOCK 2
997 #define IBCS2_DATALOCK 4
1000 if ((error = suser(curthread)) != 0)
1002 switch(SCARG(uap, cmd)) {
1004 case IBCS2_PROCLOCK:
1005 case IBCS2_TEXTLOCK:
1006 case IBCS2_DATALOCK:
1007 return 0; /* XXX - TODO */
1013 ibcs2_uadmin(struct ibcs2_uadmin_args *uap)
1015 #define SCO_A_REBOOT 1
1016 #define SCO_A_SHUTDOWN 2
1017 #define SCO_A_REMOUNT 4
1018 #define SCO_A_CLOCK 8
1019 #define SCO_A_SETCONFIG 128
1020 #define SCO_A_GETDEV 130
1022 #define SCO_AD_HALT 0
1023 #define SCO_AD_BOOT 1
1024 #define SCO_AD_IBOOT 2
1025 #define SCO_AD_PWRDOWN 3
1026 #define SCO_AD_PWRNAP 4
1028 #define SCO_AD_PANICBOOT 1
1030 #define SCO_AD_GETBMAJ 0
1031 #define SCO_AD_GETCMAJ 1
1033 if (suser(curthread))
1036 switch(SCARG(uap, cmd)) {
1038 case SCO_A_SHUTDOWN:
1039 switch(SCARG(uap, func)) {
1040 struct reboot_args r;
1042 case SCO_AD_PWRDOWN:
1048 r.opt = RB_AUTOBOOT;
1054 case SCO_A_SETCONFIG:
1057 return EINVAL; /* XXX - TODO */
1063 ibcs2_sysfs(struct ibcs2_sysfs_args *uap)
1065 #define IBCS2_GETFSIND 1
1066 #define IBCS2_GETFSTYP 2
1067 #define IBCS2_GETNFSTYP 3
1069 switch(SCARG(uap, cmd)) {
1070 case IBCS2_GETFSIND:
1071 case IBCS2_GETFSTYP:
1072 case IBCS2_GETNFSTYP:
1075 return EINVAL; /* XXX - TODO */
1079 ibcs2_unlink(struct ibcs2_unlink_args *uap)
1081 caddr_t sg = stackgap_init();
1083 CHECKALTEXIST(&sg, SCARG(uap, path));
1084 return unlink((struct unlink_args *)uap);
1088 ibcs2_chdir(struct ibcs2_chdir_args *uap)
1090 caddr_t sg = stackgap_init();
1092 CHECKALTEXIST(&sg, SCARG(uap, path));
1093 return chdir((struct chdir_args *)uap);
1097 ibcs2_chmod(struct ibcs2_chmod_args *uap)
1099 caddr_t sg = stackgap_init();
1101 CHECKALTEXIST(&sg, SCARG(uap, path));
1102 return chmod((struct chmod_args *)uap);
1106 ibcs2_chown(struct ibcs2_chown_args *uap)
1108 caddr_t sg = stackgap_init();
1110 CHECKALTEXIST(&sg, SCARG(uap, path));
1111 return chown((struct chown_args *)uap);
1115 ibcs2_rmdir(struct ibcs2_rmdir_args *uap)
1117 caddr_t sg = stackgap_init();
1119 CHECKALTEXIST(&sg, SCARG(uap, path));
1120 return rmdir((struct rmdir_args *)uap);
1124 ibcs2_mkdir(struct ibcs2_mkdir_args *uap)
1126 caddr_t sg = stackgap_init();
1128 CHECKALTCREAT(&sg, SCARG(uap, path));
1129 return mkdir((struct mkdir_args *)uap);
1133 ibcs2_symlink(struct ibcs2_symlink_args *uap)
1135 caddr_t sg = stackgap_init();
1137 CHECKALTEXIST(&sg, SCARG(uap, path));
1138 CHECKALTCREAT(&sg, SCARG(uap, link));
1139 return symlink((struct symlink_args *)uap);
1143 ibcs2_rename(struct ibcs2_rename_args *uap)
1145 caddr_t sg = stackgap_init();
1147 CHECKALTEXIST(&sg, SCARG(uap, from));
1148 CHECKALTCREAT(&sg, SCARG(uap, to));
1149 return rename((struct rename_args *)uap);
1153 ibcs2_readlink(struct ibcs2_readlink_args *uap)
1155 caddr_t sg = stackgap_init();
1157 CHECKALTEXIST(&sg, SCARG(uap, path));
1158 return readlink((struct readlink_args *) uap);