2 * SPDX-License-Identifier: BSD-4-Clause
4 * Copyright (c) 1995 Steven Wallace
5 * Copyright (c) 1994, 1995 Scott Bartram
6 * Copyright (c) 1992, 1993
7 * The Regents of the University of California. All rights reserved.
9 * This software was developed by the Computer Systems Engineering group
10 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
11 * contributed to Berkeley.
13 * All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Lawrence Berkeley Laboratory.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
26 * 3. All advertising materials mentioning features or use of this software
27 * must display the following acknowledgement:
28 * This product includes software developed by the University of
29 * California, Berkeley and its contributors.
30 * 4. Neither the name of the University nor the names of its contributors
31 * may be used to endorse or promote products derived from this software
32 * without specific prior written permission.
34 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
35 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
38 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
48 * @(#)sun_misc.c 8.1 (Berkeley) 6/18/93
51 #include <sys/cdefs.h>
52 __FBSDID("$FreeBSD$");
55 * IBCS2 compatibility module.
57 * IBCS2 system calls that are implemented differently in BSD are
60 #include <sys/param.h>
61 #include <sys/systm.h>
62 #include <sys/capsicum.h>
63 #include <sys/dirent.h>
64 #include <sys/fcntl.h>
65 #include <sys/filedesc.h>
66 #include <sys/imgact.h>
67 #include <sys/kernel.h>
69 #include <sys/malloc.h>
70 #include <sys/file.h> /* Must come after sys/malloc.h */
71 #include <sys/mutex.h>
72 #include <sys/namei.h>
74 #include <sys/reboot.h>
75 #include <sys/resourcevar.h>
77 #include <sys/sysctl.h>
78 #include <sys/syscallsubr.h>
79 #include <sys/sysproto.h>
81 #include <sys/times.h>
82 #include <sys/vnode.h>
85 #include <machine/cpu.h>
87 #include <i386/ibcs2/ibcs2_dirent.h>
88 #include <i386/ibcs2/ibcs2_signal.h>
89 #include <i386/ibcs2/ibcs2_proto.h>
90 #include <i386/ibcs2/ibcs2_unistd.h>
91 #include <i386/ibcs2/ibcs2_util.h>
92 #include <i386/ibcs2/ibcs2_utime.h>
93 #include <i386/ibcs2/ibcs2_xenix.h>
95 #include <security/mac/mac_framework.h>
98 ibcs2_ulimit(struct thread *td, struct ibcs2_ulimit_args *uap)
102 #define IBCS2_GETFSIZE 1
103 #define IBCS2_SETFSIZE 2
104 #define IBCS2_GETPSIZE 3
105 #define IBCS2_GETDTABLESIZE 4
109 td->td_retval[0] = lim_cur(td, RLIMIT_FSIZE);
110 if (td->td_retval[0] == -1)
111 td->td_retval[0] = 0x7fffffff;
114 rl.rlim_max = lim_max(td, RLIMIT_FSIZE);
115 rl.rlim_cur = uap->newlimit;
116 error = kern_setrlimit(td, RLIMIT_FSIZE, &rl);
118 td->td_retval[0] = lim_cur(td, RLIMIT_FSIZE);
120 DPRINTF(("failed "));
124 td->td_retval[0] = lim_cur(td, RLIMIT_RSS); /* XXX */
126 case IBCS2_GETDTABLESIZE:
127 uap->cmd = IBCS2_SC_OPEN_MAX;
128 return ibcs2_sysconf(td, (struct ibcs2_sysconf_args *)uap);
134 #define IBCS2_WSTOPPED 0177
135 #define IBCS2_STOPCODE(sig) ((sig) << 8 | IBCS2_WSTOPPED)
137 ibcs2_wait(struct thread *td, struct ibcs2_wait_args *uap)
139 int error, options, status;
142 struct trapframe *tf = td->td_frame;
144 if ((tf->tf_eflags & (PSL_Z|PSL_PF|PSL_N|PSL_V))
145 == (PSL_Z|PSL_PF|PSL_N|PSL_V)) {
148 statusp = (int *)uap->a2;
153 statusp = (int *)uap->a1;
156 error = kern_wait(td, pid, &status, options, NULL);
161 * Convert status/signal result.
163 if (WIFSTOPPED(status)) {
164 if (WSTOPSIG(status) <= 0 ||
165 WSTOPSIG(status) > IBCS2_SIGTBLSZ)
168 IBCS2_STOPCODE(bsd_to_ibcs2_sig[_SIG_IDX(WSTOPSIG(status))]);
169 } else if (WIFSIGNALED(status)) {
170 if (WTERMSIG(status) <= 0 ||
171 WTERMSIG(status) > IBCS2_SIGTBLSZ)
173 status = bsd_to_ibcs2_sig[_SIG_IDX(WTERMSIG(status))];
175 /* else exit status -- identical */
177 /* record result/status */
178 td->td_retval[1] = status;
179 return copyout(&status, statusp, sizeof(status));
186 ibcs2_execv(struct thread *td, struct ibcs2_execv_args *uap)
188 struct image_args eargs;
189 struct vmspace *oldvmspace;
193 CHECKALTEXIST(td, uap->path, &path);
195 error = pre_execve(td, &oldvmspace);
200 error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp, NULL);
203 error = kern_execve(td, &eargs, NULL);
204 post_execve(td, error, oldvmspace);
209 ibcs2_execve(struct thread *td, struct ibcs2_execve_args *uap)
211 struct image_args eargs;
212 struct vmspace *oldvmspace;
216 CHECKALTEXIST(td, uap->path, &path);
218 error = pre_execve(td, &oldvmspace);
223 error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp,
227 error = kern_execve(td, &eargs, NULL);
228 post_execve(td, error, oldvmspace);
233 ibcs2_umount(struct thread *td, struct ibcs2_umount_args *uap)
235 struct unmount_args um;
239 return sys_unmount(td, &um);
243 ibcs2_mount(struct thread *td, struct ibcs2_mount_args *uap)
246 int oflags = uap->flags, nflags, error;
247 char fsname[MFSNAMELEN];
249 if (oflags & (IBCS2_MS_NOSUB | IBCS2_MS_SYS5))
251 if ((oflags & IBCS2_MS_NEWTYPE) == 0)
254 if (oflags & IBCS2_MS_RDONLY)
255 nflags |= MNT_RDONLY;
256 if (oflags & IBCS2_MS_NOSUID)
257 nflags |= MNT_NOSUID;
258 if (oflags & IBCS2_MS_REMOUNT)
259 nflags |= MNT_UPDATE;
262 if (error = copyinstr((caddr_t)uap->type, fsname, sizeof fsname,
266 if (strcmp(fsname, "4.2") == 0) {
267 uap->type = (caddr_t)STACK_ALLOC();
268 if (error = copyout("ufs", uap->type, sizeof("ufs")))
270 } else if (strcmp(fsname, "nfs") == 0) {
271 struct ibcs2_nfs_args sna;
272 struct sockaddr_in sain;
276 if (error = copyin(uap->data, &sna, sizeof sna))
278 if (error = copyin(sna.addr, &sain, sizeof sain))
280 bcopy(&sain, &sa, sizeof sa);
281 sa.sa_len = sizeof(sain);
282 uap->data = (caddr_t)STACK_ALLOC();
283 na.addr = (struct sockaddr *)((int)uap->data + sizeof na);
284 na.sotype = SOCK_DGRAM;
285 na.proto = IPPROTO_UDP;
286 na.fh = (nfsv2fh_t *)sna.fh;
287 na.flags = sna.flags;
288 na.wsize = sna.wsize;
289 na.rsize = sna.rsize;
290 na.timeo = sna.timeo;
291 na.retrans = sna.retrans;
292 na.hostname = sna.hostname;
294 if (error = copyout(&sa, na.addr, sizeof sa))
296 if (error = copyout(&na, uap->data, sizeof na))
299 return (mount(td, uap));
306 * Read iBCS2-style directory entries. We suck them into kernel space so
307 * that they can be massaged before being copied out to user code. Like
308 * SunOS, we squish out `empty' entries.
310 * This is quite ugly, but what do you expect from compatibility code?
314 ibcs2_getdents(struct thread *td, struct ibcs2_getdents_args *uap)
317 caddr_t inp, buf; /* BSD-format */
318 int len, reclen; /* BSD-format */
319 caddr_t outp; /* iBCS2-format */
320 int resid; /* iBCS2-format */
325 struct ibcs2_dirent idb;
326 off_t off; /* true file offset */
327 int buflen, error, eofflag;
328 u_long *cookies = NULL, *cookiep;
330 #define BSD_DIRENT(cp) ((struct dirent *)(cp))
331 #define IBCS2_RECLEN(reclen) (reclen + sizeof(u_short))
333 error = getvnode(td, uap->fd, cap_rights_init(&rights, CAP_READ), &fp);
336 if ((fp->f_flag & FREAD) == 0) {
341 if (vp->v_type != VDIR) { /* XXX vnode readdir op should do this */
347 #define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */
348 buflen = max(DIRBLKSIZ, uap->nbytes);
349 buflen = min(buflen, MAXBSIZE);
350 buf = malloc(buflen, M_TEMP, M_WAITOK);
351 vn_lock(vp, LK_SHARED | LK_RETRY);
354 aiov.iov_len = buflen;
355 auio.uio_iov = &aiov;
357 auio.uio_rw = UIO_READ;
358 auio.uio_segflg = UIO_SYSSPACE;
360 auio.uio_resid = buflen;
361 auio.uio_offset = off;
364 free(cookies, M_TEMP);
369 error = mac_vnode_check_readdir(td->td_ucred, vp);
375 * First we read into the malloc'ed buffer, then
376 * we massage it into user space, one record at a time.
378 if ((error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies, &cookies)) != 0)
383 if ((len = buflen - auio.uio_resid) <= 0)
390 * When using cookies, the vfs has the option of reading from
391 * a different offset than that supplied (UFS truncates the
392 * offset to a block boundary to make sure that it never reads
393 * partway through a directory entry, even if the directory
394 * has been compacted).
396 while (len > 0 && ncookies > 0 && *cookiep <= off) {
397 len -= BSD_DIRENT(inp)->d_reclen;
398 inp += BSD_DIRENT(inp)->d_reclen;
404 for (; len > 0; len -= reclen) {
405 if (cookiep && ncookies == 0)
407 reclen = BSD_DIRENT(inp)->d_reclen;
409 printf("ibcs2_getdents: reclen=%d\n", reclen);
413 if (BSD_DIRENT(inp)->d_fileno == 0) {
414 inp += reclen; /* it is a hole; squish it out */
422 if (reclen > len || resid < IBCS2_RECLEN(reclen)) {
423 /* entry too big for buffer, so just stop */
428 * Massage in place to make an iBCS2-shaped dirent (otherwise
429 * we have to worry about touching user memory outside of
430 * the copyout() call).
432 idb.d_ino = (ibcs2_ino_t)BSD_DIRENT(inp)->d_fileno;
433 idb.d_off = (ibcs2_off_t)off;
434 idb.d_reclen = (u_short)IBCS2_RECLEN(reclen);
435 if ((error = copyout((caddr_t)&idb, outp, 10)) != 0 ||
436 (error = copyout(BSD_DIRENT(inp)->d_name, outp + 10,
437 BSD_DIRENT(inp)->d_namlen + 1)) != 0)
439 /* advance past this real entry */
446 /* advance output past iBCS2-shaped entry */
447 outp += IBCS2_RECLEN(reclen);
448 resid -= IBCS2_RECLEN(reclen);
450 /* if we squished out the whole block, try again */
451 if (outp == uap->buf)
453 fp->f_offset = off; /* update the vnode offset */
455 td->td_retval[0] = uap->nbytes - resid;
460 free(cookies, M_TEMP);
466 ibcs2_read(struct thread *td, struct ibcs2_read_args *uap)
469 caddr_t inp, buf; /* BSD-format */
470 int len, reclen; /* BSD-format */
471 caddr_t outp; /* iBCS2-format */
472 int resid; /* iBCS2-format */
477 struct ibcs2_direct {
481 off_t off; /* true file offset */
482 int buflen, error, eofflag, size;
483 u_long *cookies = NULL, *cookiep;
486 error = getvnode(td, uap->fd, cap_rights_init(&rights, CAP_READ), &fp);
489 return sys_read(td, (struct read_args *)uap);
493 if ((fp->f_flag & FREAD) == 0) {
498 if (vp->v_type != VDIR) {
500 return sys_read(td, (struct read_args *)uap);
505 DPRINTF(("ibcs2_read: read directory\n"));
507 buflen = max(DIRBLKSIZ, uap->nbytes);
508 buflen = min(buflen, MAXBSIZE);
509 buf = malloc(buflen, M_TEMP, M_WAITOK);
510 vn_lock(vp, LK_SHARED | LK_RETRY);
513 aiov.iov_len = buflen;
514 auio.uio_iov = &aiov;
516 auio.uio_rw = UIO_READ;
517 auio.uio_segflg = UIO_SYSSPACE;
519 auio.uio_resid = buflen;
520 auio.uio_offset = off;
523 free(cookies, M_TEMP);
528 error = mac_vnode_check_readdir(td->td_ucred, vp);
534 * First we read into the malloc'ed buffer, then
535 * we massage it into user space, one record at a time.
537 if ((error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies, &cookies)) != 0) {
538 DPRINTF(("VOP_READDIR failed: %d\n", error));
544 if ((len = buflen - auio.uio_resid) <= 0)
551 * When using cookies, the vfs has the option of reading from
552 * a different offset than that supplied (UFS truncates the
553 * offset to a block boundary to make sure that it never reads
554 * partway through a directory entry, even if the directory
555 * has been compacted).
557 while (len > 0 && ncookies > 0 && *cookiep <= off) {
558 len -= BSD_DIRENT(inp)->d_reclen;
559 inp += BSD_DIRENT(inp)->d_reclen;
565 for (; len > 0 && resid > 0; len -= reclen) {
566 if (cookiep && ncookies == 0)
568 reclen = BSD_DIRENT(inp)->d_reclen;
570 printf("ibcs2_read: reclen=%d\n", reclen);
574 if (BSD_DIRENT(inp)->d_fileno == 0) {
575 inp += reclen; /* it is a hole; squish it out */
583 if (reclen > len || resid < sizeof(struct ibcs2_direct)) {
584 /* entry too big for buffer, so just stop */
589 * Massage in place to make an iBCS2-shaped dirent (otherwise
590 * we have to worry about touching user memory outside of
591 * the copyout() call).
593 * TODO: if length(filename) > 14, then break filename into
594 * multiple entries and set inode = 0xffff except last
596 idb.ino = (BSD_DIRENT(inp)->d_fileno > 0xfffe) ? 0xfffe :
597 BSD_DIRENT(inp)->d_fileno;
598 (void)copystr(BSD_DIRENT(inp)->d_name, idb.name, 14, &size);
599 bzero(idb.name + size, 14 - size);
600 if ((error = copyout(&idb, outp, sizeof(struct ibcs2_direct))) != 0)
602 /* advance past this real entry */
609 /* advance output past iBCS2-shaped entry */
610 outp += sizeof(struct ibcs2_direct);
611 resid -= sizeof(struct ibcs2_direct);
613 /* if we squished out the whole block, try again */
614 if (outp == uap->buf)
616 fp->f_offset = off; /* update the vnode offset */
618 td->td_retval[0] = uap->nbytes - resid;
623 free(cookies, M_TEMP);
629 ibcs2_mknod(struct thread *td, struct ibcs2_mknod_args *uap)
634 CHECKALTCREAT(td, uap->path, &path);
635 if (S_ISFIFO(uap->mode)) {
636 error = kern_mkfifoat(td, AT_FDCWD, path,
637 UIO_SYSSPACE, uap->mode);
639 error = kern_mknodat(td, AT_FDCWD, path, UIO_SYSSPACE,
640 uap->mode, uap->dev);
647 ibcs2_getgroups(struct thread *td, struct ibcs2_getgroups_args *uap)
655 ngrp = cred->cr_ngroups;
657 if (uap->gidsetsize == 0) {
661 if (uap->gidsetsize < ngrp)
664 iset = malloc(ngrp * sizeof(*iset), M_TEMP, M_WAITOK);
665 for (i = 0; i < ngrp; i++)
666 iset[i] = (ibcs2_gid_t)cred->cr_groups[i];
667 error = copyout(iset, uap->gidset, ngrp * sizeof(ibcs2_gid_t));
670 td->td_retval[0] = ngrp;
675 ibcs2_setgroups(struct thread *td, struct ibcs2_setgroups_args *uap)
681 if (uap->gidsetsize < 0 || uap->gidsetsize > ngroups_max + 1)
683 if (uap->gidsetsize && uap->gidset == NULL)
685 gp = malloc(uap->gidsetsize * sizeof(*gp), M_TEMP, M_WAITOK);
686 if (uap->gidsetsize) {
687 iset = malloc(uap->gidsetsize * sizeof(*iset), M_TEMP, M_WAITOK);
688 error = copyin(uap->gidset, iset, sizeof(ibcs2_gid_t) *
694 for (i = 0; i < uap->gidsetsize; i++)
695 gp[i] = (gid_t)iset[i];
698 error = kern_setgroups(td, uap->gidsetsize, gp);
705 ibcs2_setuid(struct thread *td, struct ibcs2_setuid_args *uap)
707 struct setuid_args sa;
709 sa.uid = (uid_t)uap->uid;
710 return sys_setuid(td, &sa);
714 ibcs2_setgid(struct thread *td, struct ibcs2_setgid_args *uap)
716 struct setgid_args sa;
718 sa.gid = (gid_t)uap->gid;
719 return sys_setgid(td, &sa);
723 ibcs2_time(struct thread *td, struct ibcs2_time_args *uap)
728 td->td_retval[0] = tv.tv_sec;
730 return copyout((caddr_t)&tv.tv_sec, (caddr_t)uap->tp,
731 sizeof(ibcs2_time_t));
737 ibcs2_pathconf(struct thread *td, struct ibcs2_pathconf_args *uap)
742 CHECKALTEXIST(td, uap->path, &path);
743 uap->name++; /* iBCS2 _PC_* defines are offset by one */
744 error = kern_pathconf(td, path, UIO_SYSSPACE, uap->name, FOLLOW);
750 ibcs2_fpathconf(struct thread *td, struct ibcs2_fpathconf_args *uap)
752 uap->name++; /* iBCS2 _PC_* defines are offset by one */
753 return sys_fpathconf(td, (struct fpathconf_args *)uap);
757 ibcs2_sysconf(struct thread *td, struct ibcs2_sysconf_args *uap)
759 int mib[2], value, len, error;
762 case IBCS2_SC_ARG_MAX:
763 mib[1] = KERN_ARGMAX;
766 case IBCS2_SC_CHILD_MAX:
767 td->td_retval[0] = lim_cur(td, RLIMIT_NPROC);
770 case IBCS2_SC_CLK_TCK:
771 td->td_retval[0] = hz;
774 case IBCS2_SC_NGROUPS_MAX:
775 mib[1] = KERN_NGROUPS;
778 case IBCS2_SC_OPEN_MAX:
779 td->td_retval[0] = lim_cur(td, RLIMIT_NOFILE);
782 case IBCS2_SC_JOB_CONTROL:
783 mib[1] = KERN_JOB_CONTROL;
786 case IBCS2_SC_SAVED_IDS:
787 mib[1] = KERN_SAVED_IDS;
790 case IBCS2_SC_VERSION:
791 mib[1] = KERN_POSIX1;
794 case IBCS2_SC_PASS_MAX:
795 td->td_retval[0] = 128; /* XXX - should we create PASS_MAX ? */
798 case IBCS2_SC_XOPEN_VERSION:
799 td->td_retval[0] = 2; /* XXX: What should that be? */
808 error = kernel_sysctl(td, mib, 2, &value, &len, NULL, 0, NULL, 0);
811 td->td_retval[0] = value;
816 ibcs2_alarm(struct thread *td, struct ibcs2_alarm_args *uap)
818 struct itimerval itv, oitv;
821 timevalclear(&itv.it_interval);
822 itv.it_value.tv_sec = uap->sec;
823 itv.it_value.tv_usec = 0;
824 error = kern_setitimer(td, ITIMER_REAL, &itv, &oitv);
827 if (oitv.it_value.tv_usec != 0)
828 oitv.it_value.tv_sec++;
829 td->td_retval[0] = oitv.it_value.tv_sec;
834 ibcs2_times(struct thread *td, struct ibcs2_times_args *uap)
841 #define CONVTCK(r) (r.tv_sec * hz + r.tv_usec / (1000000 / hz))
843 error = kern_getrusage(td, RUSAGE_SELF, &ru);
846 tms.tms_utime = CONVTCK(ru.ru_utime);
847 tms.tms_stime = CONVTCK(ru.ru_stime);
849 error = kern_getrusage(td, RUSAGE_CHILDREN, &ru);
852 tms.tms_cutime = CONVTCK(ru.ru_utime);
853 tms.tms_cstime = CONVTCK(ru.ru_stime);
856 td->td_retval[0] = CONVTCK(t);
858 return (copyout(&tms, uap->tp, sizeof(struct tms)));
862 ibcs2_stime(struct thread *td, struct ibcs2_stime_args *uap)
868 error = copyin(uap->timep, &secs, sizeof(long));
873 error = kern_settimeofday(td, &tv, NULL);
880 ibcs2_utime(struct thread *td, struct ibcs2_utime_args *uap)
882 struct ibcs2_utimbuf ubuf;
883 struct timeval tbuf[2], *tp;
888 error = copyin(uap->buf, &ubuf, sizeof(ubuf));
891 tbuf[0].tv_sec = ubuf.actime;
893 tbuf[1].tv_sec = ubuf.modtime;
899 CHECKALTEXIST(td, uap->path, &path);
900 error = kern_utimesat(td, AT_FDCWD, path, UIO_SYSSPACE,
907 ibcs2_nice(struct thread *td, struct ibcs2_nice_args *uap)
910 struct setpriority_args sa;
912 sa.which = PRIO_PROCESS;
914 sa.prio = td->td_proc->p_nice + uap->incr;
915 if ((error = sys_setpriority(td, &sa)) != 0)
917 td->td_retval[0] = td->td_proc->p_nice;
922 * iBCS2 getpgrp, setpgrp, setsid, and setpgid
926 ibcs2_pgrpsys(struct thread *td, struct ibcs2_pgrpsys_args *uap)
928 struct proc *p = td->td_proc;
930 case 0: /* getpgrp */
932 td->td_retval[0] = p->p_pgrp->pg_id;
936 case 1: /* setpgrp */
938 struct setpgid_args sa;
942 sys_setpgid(td, &sa);
944 td->td_retval[0] = p->p_pgrp->pg_id;
949 case 2: /* setpgid */
951 struct setpgid_args sa;
955 return sys_setpgid(td, &sa);
959 return sys_setsid(td, NULL);
967 * XXX - need to check for nested calls
971 ibcs2_plock(struct thread *td, struct ibcs2_plock_args *uap)
974 #define IBCS2_UNLOCK 0
975 #define IBCS2_PROCLOCK 1
976 #define IBCS2_TEXTLOCK 2
977 #define IBCS2_DATALOCK 4
982 error = priv_check(td, PRIV_VM_MUNLOCK);
991 error = priv_check(td, PRIV_VM_MLOCK);
1001 ibcs2_uadmin(struct thread *td, struct ibcs2_uadmin_args *uap)
1003 #define SCO_A_REBOOT 1
1004 #define SCO_A_SHUTDOWN 2
1005 #define SCO_A_REMOUNT 4
1006 #define SCO_A_CLOCK 8
1007 #define SCO_A_SETCONFIG 128
1008 #define SCO_A_GETDEV 130
1010 #define SCO_AD_HALT 0
1011 #define SCO_AD_BOOT 1
1012 #define SCO_AD_IBOOT 2
1013 #define SCO_AD_PWRDOWN 3
1014 #define SCO_AD_PWRNAP 4
1016 #define SCO_AD_PANICBOOT 1
1018 #define SCO_AD_GETBMAJ 0
1019 #define SCO_AD_GETCMAJ 1
1023 case SCO_A_SHUTDOWN:
1025 struct reboot_args r;
1027 case SCO_AD_PWRDOWN:
1030 return (sys_reboot(td, &r));
1033 r.opt = RB_AUTOBOOT;
1034 return (sys_reboot(td, &r));
1039 case SCO_A_SETCONFIG:
1042 return EINVAL; /* XXX - TODO */
1048 ibcs2_sysfs(struct thread *td, struct ibcs2_sysfs_args *uap)
1050 #define IBCS2_GETFSIND 1
1051 #define IBCS2_GETFSTYP 2
1052 #define IBCS2_GETNFSTYP 3
1055 case IBCS2_GETFSIND:
1056 case IBCS2_GETFSTYP:
1057 case IBCS2_GETNFSTYP:
1060 return EINVAL; /* XXX - TODO */
1064 ibcs2_unlink(struct thread *td, struct ibcs2_unlink_args *uap)
1069 CHECKALTEXIST(td, uap->path, &path);
1070 error = kern_unlinkat(td, AT_FDCWD, path, UIO_SYSSPACE, 0);
1076 ibcs2_chdir(struct thread *td, struct ibcs2_chdir_args *uap)
1081 CHECKALTEXIST(td, uap->path, &path);
1082 error = kern_chdir(td, path, UIO_SYSSPACE);
1088 ibcs2_chmod(struct thread *td, struct ibcs2_chmod_args *uap)
1093 CHECKALTEXIST(td, uap->path, &path);
1094 error = kern_fchmodat(td, AT_FDCWD, path, UIO_SYSSPACE, uap->mode, 0);
1100 ibcs2_chown(struct thread *td, struct ibcs2_chown_args *uap)
1105 CHECKALTEXIST(td, uap->path, &path);
1106 error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE, uap->uid,
1113 ibcs2_rmdir(struct thread *td, struct ibcs2_rmdir_args *uap)
1118 CHECKALTEXIST(td, uap->path, &path);
1119 error = kern_rmdirat(td, AT_FDCWD, path, UIO_SYSSPACE);
1125 ibcs2_mkdir(struct thread *td, struct ibcs2_mkdir_args *uap)
1130 CHECKALTEXIST(td, uap->path, &path);
1131 error = kern_mkdirat(td, AT_FDCWD, path, UIO_SYSSPACE, uap->mode);
1137 ibcs2_symlink(struct thread *td, struct ibcs2_symlink_args *uap)
1142 CHECKALTEXIST(td, uap->path, &path);
1145 * Have to expand CHECKALTCREAT() so that 'path' can be freed on
1148 error = ibcs2_emul_find(td, uap->link, UIO_USERSPACE, &link, 1);
1153 error = kern_symlinkat(td, path, AT_FDCWD, link, UIO_SYSSPACE);
1160 ibcs2_rename(struct thread *td, struct ibcs2_rename_args *uap)
1165 CHECKALTEXIST(td, uap->from, &from);
1168 * Have to expand CHECKALTCREAT() so that 'from' can be freed on
1171 error = ibcs2_emul_find(td, uap->to, UIO_USERSPACE, &to, 1);
1176 error = kern_renameat(td, AT_FDCWD, from, AT_FDCWD, to, UIO_SYSSPACE);
1183 ibcs2_readlink(struct thread *td, struct ibcs2_readlink_args *uap)
1188 CHECKALTEXIST(td, uap->path, &path);
1189 error = kern_readlinkat(td, AT_FDCWD, path, UIO_SYSSPACE,
1190 uap->buf, UIO_USERSPACE, uap->count);