Home | History | Annotate | Line # | Download | only in sunos
sunos_misc.c revision 1.65.4.1
      1  1.65.4.1   mycroft /*	$NetBSD: sunos_misc.c,v 1.65.4.1 1996/12/10 08:48:54 mycroft Exp $	*/
      2      1.30       cgd 
      3       1.1   deraadt /*
      4       1.1   deraadt  * Copyright (c) 1992, 1993
      5       1.1   deraadt  *	The Regents of the University of California.  All rights reserved.
      6       1.1   deraadt  *
      7       1.1   deraadt  * This software was developed by the Computer Systems Engineering group
      8       1.1   deraadt  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9       1.1   deraadt  * contributed to Berkeley.
     10       1.1   deraadt  *
     11       1.1   deraadt  * All advertising materials mentioning features or use of this software
     12       1.1   deraadt  * must display the following acknowledgement:
     13       1.1   deraadt  *	This product includes software developed by the University of
     14       1.1   deraadt  *	California, Lawrence Berkeley Laboratory.
     15       1.1   deraadt  *
     16       1.1   deraadt  * Redistribution and use in source and binary forms, with or without
     17       1.1   deraadt  * modification, are permitted provided that the following conditions
     18       1.1   deraadt  * are met:
     19       1.1   deraadt  * 1. Redistributions of source code must retain the above copyright
     20       1.1   deraadt  *    notice, this list of conditions and the following disclaimer.
     21       1.1   deraadt  * 2. Redistributions in binary form must reproduce the above copyright
     22       1.1   deraadt  *    notice, this list of conditions and the following disclaimer in the
     23       1.1   deraadt  *    documentation and/or other materials provided with the distribution.
     24       1.1   deraadt  * 3. All advertising materials mentioning features or use of this software
     25       1.1   deraadt  *    must display the following acknowledgement:
     26       1.1   deraadt  *	This product includes software developed by the University of
     27       1.1   deraadt  *	California, Berkeley and its contributors.
     28       1.1   deraadt  * 4. Neither the name of the University nor the names of its contributors
     29       1.1   deraadt  *    may be used to endorse or promote products derived from this software
     30       1.1   deraadt  *    without specific prior written permission.
     31       1.1   deraadt  *
     32       1.1   deraadt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     33       1.1   deraadt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     34       1.1   deraadt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     35       1.1   deraadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     36       1.1   deraadt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37       1.1   deraadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38       1.1   deraadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39       1.1   deraadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     40       1.1   deraadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     41       1.1   deraadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     42       1.1   deraadt  * SUCH DAMAGE.
     43       1.1   deraadt  *
     44      1.33   deraadt  *	@(#)sunos_misc.c	8.1 (Berkeley) 6/18/93
     45       1.1   deraadt  *
     46      1.33   deraadt  *	Header: sunos_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
     47       1.1   deraadt  */
     48       1.1   deraadt 
     49       1.1   deraadt /*
     50       1.1   deraadt  * SunOS compatibility module.
     51       1.1   deraadt  *
     52       1.1   deraadt  * SunOS system calls that are implemented differently in BSD are
     53       1.1   deraadt  * handled here.
     54       1.1   deraadt  */
     55       1.1   deraadt 
     56       1.1   deraadt #include <sys/param.h>
     57       1.1   deraadt #include <sys/systm.h>
     58      1.10   deraadt #include <sys/namei.h>
     59       1.1   deraadt #include <sys/proc.h>
     60      1.63       gwr #include <sys/dirent.h>
     61       1.1   deraadt #include <sys/file.h>
     62      1.10   deraadt #include <sys/stat.h>
     63       1.1   deraadt #include <sys/filedesc.h>
     64       1.1   deraadt #include <sys/ioctl.h>
     65       1.8   deraadt #include <sys/kernel.h>
     66      1.44  christos #include <sys/reboot.h>
     67       1.1   deraadt #include <sys/malloc.h>
     68       1.1   deraadt #include <sys/mbuf.h>
     69       1.1   deraadt #include <sys/mman.h>
     70       1.1   deraadt #include <sys/mount.h>
     71      1.35   deraadt #include <sys/ptrace.h>
     72       1.1   deraadt #include <sys/resource.h>
     73       1.1   deraadt #include <sys/resourcevar.h>
     74       1.1   deraadt #include <sys/signal.h>
     75       1.1   deraadt #include <sys/signalvar.h>
     76       1.1   deraadt #include <sys/socket.h>
     77      1.60        pk #include <sys/tty.h>
     78       1.1   deraadt #include <sys/vnode.h>
     79       1.1   deraadt #include <sys/uio.h>
     80       1.1   deraadt #include <sys/wait.h>
     81       1.8   deraadt #include <sys/utsname.h>
     82      1.12   deraadt #include <sys/unistd.h>
     83      1.33   deraadt #include <sys/syscallargs.h>
     84      1.64  christos #include <sys/conf.h>
     85      1.64  christos #include <sys/socketvar.h>
     86      1.55   mycroft 
     87      1.33   deraadt #include <compat/sunos/sunos.h>
     88      1.33   deraadt #include <compat/sunos/sunos_syscallargs.h>
     89      1.48        pk #include <compat/sunos/sunos_util.h>
     90      1.56   mycroft #include <compat/sunos/sunos_dirent.h>
     91       1.1   deraadt 
     92      1.10   deraadt #include <netinet/in.h>
     93      1.10   deraadt 
     94       1.7   deraadt #include <miscfs/specfs/specdev.h>
     95       1.1   deraadt 
     96      1.27        pk #include <nfs/rpcv2.h>
     97      1.61        pk #include <nfs/nfsproto.h>
     98      1.27        pk #include <nfs/nfs.h>
     99      1.27        pk 
    100       1.1   deraadt #include <vm/vm.h>
    101       1.1   deraadt 
    102      1.64  christos static int sunstatfs __P((struct statfs *, caddr_t));
    103      1.64  christos static void sunos_pollscan __P((struct proc *, struct sunos_pollfd *,
    104      1.64  christos 				int, register_t *));
    105      1.33   deraadt int
    106      1.55   mycroft sunos_sys_wait4(p, v, retval)
    107       1.1   deraadt 	struct proc *p;
    108      1.54   thorpej 	void *v;
    109      1.32       cgd 	register_t *retval;
    110       1.1   deraadt {
    111      1.55   mycroft 	struct sunos_sys_wait4_args *uap = v;
    112      1.33   deraadt 	if (SCARG(uap, pid) == 0)
    113      1.33   deraadt 		SCARG(uap, pid) = WAIT_ANY;
    114      1.55   mycroft 	return (sys_wait4(p, uap, retval));
    115       1.1   deraadt }
    116       1.1   deraadt 
    117      1.33   deraadt int
    118      1.55   mycroft sunos_sys_creat(p, v, retval)
    119       1.1   deraadt 	struct proc *p;
    120      1.54   thorpej 	void *v;
    121      1.32       cgd 	register_t *retval;
    122       1.1   deraadt {
    123      1.55   mycroft 	struct sunos_sys_creat_args *uap = v;
    124      1.55   mycroft 	struct sys_open_args ouap;
    125       1.1   deraadt 
    126      1.50  christos 	caddr_t sg = stackgap_init(p->p_emul);
    127      1.50  christos 	SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    128      1.48        pk 
    129      1.33   deraadt 	SCARG(&ouap, path) = SCARG(uap, path);
    130      1.33   deraadt 	SCARG(&ouap, flags) = O_WRONLY | O_CREAT | O_TRUNC;
    131      1.33   deraadt 	SCARG(&ouap, mode) = SCARG(uap, mode);
    132      1.55   mycroft 
    133      1.55   mycroft 	return (sys_open(p, &ouap, retval));
    134       1.1   deraadt }
    135       1.1   deraadt 
    136      1.33   deraadt int
    137      1.55   mycroft sunos_sys_access(p, v, retval)
    138      1.48        pk 	struct proc *p;
    139      1.54   thorpej 	void *v;
    140      1.48        pk 	register_t *retval;
    141      1.48        pk {
    142      1.55   mycroft 	struct sunos_sys_access_args *uap = v;
    143      1.50  christos 	caddr_t sg = stackgap_init(p->p_emul);
    144      1.50  christos 	SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    145      1.48        pk 
    146      1.55   mycroft 	return (sys_access(p, uap, retval));
    147      1.48        pk }
    148      1.48        pk 
    149      1.48        pk int
    150      1.55   mycroft sunos_sys_stat(p, v, retval)
    151      1.48        pk 	struct proc *p;
    152      1.54   thorpej 	void *v;
    153      1.48        pk 	register_t *retval;
    154      1.48        pk {
    155      1.55   mycroft 	struct sunos_sys_stat_args *uap = v;
    156      1.50  christos 	caddr_t sg = stackgap_init(p->p_emul);
    157      1.50  christos 	SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    158      1.48        pk 
    159      1.55   mycroft 	return (compat_43_sys_stat(p, uap, retval));
    160      1.48        pk }
    161      1.48        pk 
    162      1.48        pk int
    163      1.55   mycroft sunos_sys_lstat(p, v, retval)
    164      1.48        pk 	struct proc *p;
    165      1.54   thorpej 	void *v;
    166      1.48        pk 	register_t *retval;
    167      1.48        pk {
    168      1.55   mycroft 	struct sunos_sys_lstat_args *uap = v;
    169      1.50  christos 	caddr_t sg = stackgap_init(p->p_emul);
    170      1.50  christos 	SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    171      1.48        pk 
    172      1.55   mycroft 	return (compat_43_sys_lstat(p, uap, retval));
    173      1.48        pk }
    174      1.48        pk 
    175      1.48        pk int
    176      1.55   mycroft sunos_sys_execv(p, v, retval)
    177       1.1   deraadt 	struct proc *p;
    178      1.54   thorpej 	void *v;
    179      1.32       cgd 	register_t *retval;
    180       1.1   deraadt {
    181  1.65.4.1   mycroft 	struct sunos_sys_execv_args /* {
    182  1.65.4.1   mycroft 		syscallarg(char *) path;
    183  1.65.4.1   mycroft 		syscallarg(char **) argv;
    184  1.65.4.1   mycroft 	} */ *uap = v;
    185  1.65.4.1   mycroft 	struct sys_execve_args ap;
    186  1.65.4.1   mycroft 	caddr_t sg;
    187       1.1   deraadt 
    188  1.65.4.1   mycroft 	sg = stackgap_init(p->p_emul);
    189      1.50  christos 	SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    190      1.48        pk 
    191  1.65.4.1   mycroft 	SCARG(&ap, path) = SCARG(uap, path);
    192  1.65.4.1   mycroft 	SCARG(&ap, argp) = SCARG(uap, argp);
    193  1.65.4.1   mycroft 	SCARG(&ap, envp) = NULL;
    194  1.65.4.1   mycroft 
    195  1.65.4.1   mycroft 	return (sys_execve(p, &ap, retval));
    196  1.65.4.1   mycroft }
    197  1.65.4.1   mycroft 
    198  1.65.4.1   mycroft int
    199  1.65.4.1   mycroft sunos_sys_execve(p, v, retval)
    200  1.65.4.1   mycroft 	struct proc *p;
    201  1.65.4.1   mycroft 	void *v;
    202  1.65.4.1   mycroft 	register_t *retval;
    203  1.65.4.1   mycroft {
    204  1.65.4.1   mycroft 	struct sunos_sys_execve_args /* {
    205  1.65.4.1   mycroft 		syscallarg(char *) path;
    206  1.65.4.1   mycroft 		syscallarg(char **) argv;
    207  1.65.4.1   mycroft 		syscallarg(char **) envp;
    208  1.65.4.1   mycroft 	} */ *uap = v;
    209  1.65.4.1   mycroft 	struct sys_execve_args ap;
    210  1.65.4.1   mycroft 	caddr_t sg;
    211  1.65.4.1   mycroft 
    212  1.65.4.1   mycroft 	sg = stackgap_init(p->p_emul);
    213  1.65.4.1   mycroft 	SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    214  1.65.4.1   mycroft 
    215  1.65.4.1   mycroft 	SCARG(&ap, path) = SCARG(uap, path);
    216  1.65.4.1   mycroft 	SCARG(&ap, argp) = SCARG(uap, argp);
    217  1.65.4.1   mycroft 	SCARG(&ap, envp) = SCARG(uap, envp);
    218      1.55   mycroft 
    219  1.65.4.1   mycroft 	return (sys_execve(p, &ap, retval));
    220       1.1   deraadt }
    221       1.1   deraadt 
    222      1.33   deraadt int
    223      1.55   mycroft sunos_sys_omsync(p, v, retval)
    224       1.1   deraadt 	struct proc *p;
    225      1.54   thorpej 	void *v;
    226      1.32       cgd 	register_t *retval;
    227       1.1   deraadt {
    228      1.55   mycroft 	struct sunos_sys_omsync_args *uap = v;
    229      1.55   mycroft 	struct sys_msync_args ouap;
    230       1.1   deraadt 
    231      1.33   deraadt 	if (SCARG(uap, flags))
    232       1.1   deraadt 		return (EINVAL);
    233      1.33   deraadt 	SCARG(&ouap, addr) = SCARG(uap, addr);
    234      1.33   deraadt 	SCARG(&ouap, len) = SCARG(uap, len);
    235      1.55   mycroft 
    236      1.55   mycroft 	return (sys_msync(p, &ouap, retval));
    237       1.1   deraadt }
    238       1.1   deraadt 
    239      1.33   deraadt int
    240      1.55   mycroft sunos_sys_unmount(p, v, retval)
    241      1.33   deraadt 	struct proc *p;
    242      1.54   thorpej 	void *v;
    243      1.32       cgd 	register_t *retval;
    244       1.1   deraadt {
    245      1.55   mycroft 	struct sunos_sys_unmount_args *uap = v;
    246      1.55   mycroft 	struct sys_unmount_args ouap;
    247      1.54   thorpej 
    248      1.55   mycroft 	SCARG(&ouap, path) = SCARG(uap, path);
    249      1.55   mycroft 	SCARG(&ouap, flags) = 0;
    250      1.55   mycroft 
    251      1.55   mycroft 	return (sys_unmount(p, &ouap, retval));
    252      1.33   deraadt }
    253       1.1   deraadt 
    254      1.61        pk /*
    255      1.61        pk  * Conversion table for SunOS NFS mount flags.
    256      1.61        pk  */
    257      1.61        pk static struct {
    258      1.61        pk 	int	sun_flg;
    259      1.61        pk 	int	bsd_flg;
    260      1.61        pk } sunnfs_flgtab[] = {
    261      1.61        pk 	{ SUNNFS_SOFT,		NFSMNT_SOFT },
    262      1.61        pk 	{ SUNNFS_WSIZE,		NFSMNT_WSIZE },
    263      1.61        pk 	{ SUNNFS_RSIZE,		NFSMNT_RSIZE },
    264      1.61        pk 	{ SUNNFS_TIMEO,		NFSMNT_TIMEO },
    265      1.61        pk 	{ SUNNFS_RETRANS,	NFSMNT_RETRANS },
    266      1.61        pk 	{ SUNNFS_HOSTNAME,	0 },			/* Ignored */
    267      1.61        pk 	{ SUNNFS_INT,		NFSMNT_INT },
    268      1.61        pk 	{ SUNNFS_NOAC,		0 },			/* Ignored */
    269      1.61        pk 	{ SUNNFS_ACREGMIN,	0 },			/* Ignored */
    270      1.61        pk 	{ SUNNFS_ACREGMAX,	0 },			/* Ignored */
    271      1.61        pk 	{ SUNNFS_ACDIRMIN,	0 },			/* Ignored */
    272      1.61        pk 	{ SUNNFS_ACDIRMAX,	0 },			/* Ignored */
    273      1.61        pk 	{ SUNNFS_SECURE,	0 },			/* Ignored */
    274      1.61        pk 	{ SUNNFS_NOCTO,		0 },			/* Ignored */
    275      1.61        pk 	{ SUNNFS_POSIX,		0 }			/* Ignored */
    276      1.61        pk };
    277      1.61        pk 
    278      1.33   deraadt int
    279      1.55   mycroft sunos_sys_mount(p, v, retval)
    280       1.1   deraadt 	struct proc *p;
    281      1.54   thorpej 	void *v;
    282      1.32       cgd 	register_t *retval;
    283       1.1   deraadt {
    284      1.55   mycroft 	struct sunos_sys_mount_args *uap = v;
    285      1.51    briggs 	struct emul *e = p->p_emul;
    286      1.33   deraadt 	int oflags = SCARG(uap, flags), nflags, error;
    287      1.16   deraadt 	char fsname[MFSNAMELEN];
    288      1.16   deraadt 
    289       1.1   deraadt 	if (oflags & (SUNM_NOSUB | SUNM_SYS5))
    290       1.1   deraadt 		return (EINVAL);
    291      1.16   deraadt 	if ((oflags & SUNM_NEWTYPE) == 0)
    292      1.16   deraadt 		return (EINVAL);
    293       1.1   deraadt 	nflags = 0;
    294       1.1   deraadt 	if (oflags & SUNM_RDONLY)
    295       1.1   deraadt 		nflags |= MNT_RDONLY;
    296       1.1   deraadt 	if (oflags & SUNM_NOSUID)
    297       1.1   deraadt 		nflags |= MNT_NOSUID;
    298       1.1   deraadt 	if (oflags & SUNM_REMOUNT)
    299       1.1   deraadt 		nflags |= MNT_UPDATE;
    300      1.33   deraadt 	SCARG(uap, flags) = nflags;
    301      1.10   deraadt 
    302      1.64  christos 	error = copyinstr((caddr_t)SCARG(uap, type), fsname,
    303      1.64  christos 	    sizeof fsname, (size_t *)0);
    304      1.64  christos 	if (error)
    305      1.16   deraadt 		return (error);
    306      1.16   deraadt 
    307      1.49       cgd 	if (strncmp(fsname, "4.2", sizeof fsname) == 0) {
    308      1.33   deraadt 		SCARG(uap, type) = STACKGAPBASE;
    309      1.64  christos 		error = copyout("ffs", SCARG(uap, type), sizeof("ffs"));
    310      1.64  christos 		if (error)
    311      1.16   deraadt 			return (error);
    312      1.49       cgd 	} else if (strncmp(fsname, "nfs", sizeof fsname) == 0) {
    313      1.33   deraadt 		struct sunos_nfs_args sna;
    314      1.10   deraadt 		struct sockaddr_in sain;
    315      1.10   deraadt 		struct nfs_args na;
    316      1.10   deraadt 		struct sockaddr sa;
    317      1.61        pk 		int n;
    318      1.10   deraadt 
    319      1.64  christos 		error = copyin(SCARG(uap, data), &sna, sizeof sna);
    320      1.64  christos 		if (error)
    321      1.10   deraadt 			return (error);
    322      1.64  christos 		error = copyin(sna.addr, &sain, sizeof sain);
    323      1.64  christos 		if (error)
    324      1.10   deraadt 			return (error);
    325      1.10   deraadt 		bcopy(&sain, &sa, sizeof sa);
    326      1.10   deraadt 		sa.sa_len = sizeof(sain);
    327      1.33   deraadt 		SCARG(uap, data) = STACKGAPBASE;
    328      1.61        pk 		na.version = NFS_ARGSVERSION;
    329      1.61        pk 		na.addr = (struct sockaddr *)
    330      1.61        pk 			  ((int)SCARG(uap, data) + sizeof na);
    331      1.29        pk 		na.addrlen = sizeof(struct sockaddr);
    332      1.10   deraadt 		na.sotype = SOCK_DGRAM;
    333      1.10   deraadt 		na.proto = IPPROTO_UDP;
    334      1.61        pk 		na.fh = (void *)sna.fh;
    335      1.61        pk 		na.fhsize = NFSX_V2FH;
    336      1.61        pk 		na.flags = 0;
    337      1.61        pk 		n = sizeof(sunnfs_flgtab) / sizeof(sunnfs_flgtab[0]);
    338      1.61        pk 		while (--n >= 0)
    339      1.61        pk 			if (sna.flags & sunnfs_flgtab[n].sun_flg)
    340      1.61        pk 				na.flags |= sunnfs_flgtab[n].bsd_flg;
    341      1.10   deraadt 		na.wsize = sna.wsize;
    342      1.10   deraadt 		na.rsize = sna.rsize;
    343      1.62        pk 		if (na.flags & NFSMNT_RSIZE) {
    344      1.62        pk 			na.flags |= NFSMNT_READDIRSIZE;
    345      1.62        pk 			na.readdirsize = na.rsize;
    346      1.62        pk 		}
    347      1.10   deraadt 		na.timeo = sna.timeo;
    348      1.10   deraadt 		na.retrans = sna.retrans;
    349      1.10   deraadt 		na.hostname = sna.hostname;
    350      1.10   deraadt 
    351      1.64  christos 		error = copyout(&sa, na.addr, sizeof sa);
    352      1.64  christos 		if (error)
    353      1.10   deraadt 			return (error);
    354      1.64  christos 		error = copyout(&na, SCARG(uap, data), sizeof na);
    355      1.64  christos 		if (error)
    356      1.10   deraadt 			return (error);
    357      1.10   deraadt 	}
    358      1.55   mycroft 	return (sys_mount(p, (struct sys_mount_args *)uap, retval));
    359       1.1   deraadt }
    360       1.1   deraadt 
    361      1.28   deraadt #if defined(NFSCLIENT)
    362      1.33   deraadt int
    363      1.55   mycroft async_daemon(p, v, retval)
    364      1.27        pk 	struct proc *p;
    365      1.55   mycroft 	void *v;
    366      1.32       cgd 	register_t *retval;
    367      1.27        pk {
    368      1.55   mycroft 	struct sys_nfssvc_args ouap;
    369      1.27        pk 
    370      1.33   deraadt 	SCARG(&ouap, flag) = NFSSVC_BIOD;
    371      1.33   deraadt 	SCARG(&ouap, argp) = NULL;
    372      1.55   mycroft 
    373      1.55   mycroft 	return (sys_nfssvc(p, &ouap, retval));
    374      1.27        pk }
    375      1.28   deraadt #endif /* NFSCLIENT */
    376      1.27        pk 
    377      1.33   deraadt int
    378      1.55   mycroft sunos_sys_sigpending(p, v, retval)
    379       1.1   deraadt 	struct proc *p;
    380      1.54   thorpej 	void *v;
    381      1.32       cgd 	register_t *retval;
    382       1.1   deraadt {
    383      1.55   mycroft 	struct sunos_sys_sigpending_args *uap = v;
    384      1.21   deraadt 	int mask = p->p_siglist & p->p_sigmask;
    385       1.1   deraadt 
    386      1.33   deraadt 	return (copyout((caddr_t)&mask, (caddr_t)SCARG(uap, mask), sizeof(int)));
    387       1.1   deraadt }
    388       1.1   deraadt 
    389       1.1   deraadt /*
    390       1.1   deraadt  * Read Sun-style directory entries.  We suck them into kernel space so
    391       1.1   deraadt  * that they can be massaged before being copied out to user code.  Like
    392       1.1   deraadt  * SunOS, we squish out `empty' entries.
    393       1.1   deraadt  *
    394       1.1   deraadt  * This is quite ugly, but what do you expect from compatibility code?
    395       1.1   deraadt  */
    396      1.33   deraadt int
    397      1.55   mycroft sunos_sys_getdents(p, v, retval)
    398       1.1   deraadt 	struct proc *p;
    399      1.54   thorpej 	void *v;
    400      1.32       cgd 	register_t *retval;
    401       1.1   deraadt {
    402      1.56   mycroft 	struct sunos_sys_getdents_args *uap = v;
    403      1.56   mycroft 	struct dirent *bdp;
    404      1.56   mycroft 	struct vnode *vp;
    405      1.56   mycroft 	caddr_t inp, buf;	/* BSD-format */
    406      1.56   mycroft 	int len, reclen;	/* BSD-format */
    407      1.56   mycroft 	caddr_t outp;		/* Sun-format */
    408      1.56   mycroft 	int resid, sunos_reclen;/* Sun-format */
    409       1.1   deraadt 	struct file *fp;
    410       1.1   deraadt 	struct uio auio;
    411       1.1   deraadt 	struct iovec aiov;
    412      1.56   mycroft 	struct sunos_dirent idb;
    413       1.1   deraadt 	off_t off;			/* true file offset */
    414       1.1   deraadt 	int buflen, error, eofflag;
    415      1.56   mycroft 	u_long *cookiebuf, *cookie;
    416      1.56   mycroft 	int ncookies;
    417       1.1   deraadt 
    418      1.33   deraadt 	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
    419       1.1   deraadt 		return (error);
    420      1.56   mycroft 
    421       1.1   deraadt 	if ((fp->f_flag & FREAD) == 0)
    422       1.1   deraadt 		return (EBADF);
    423      1.56   mycroft 
    424       1.1   deraadt 	vp = (struct vnode *)fp->f_data;
    425      1.56   mycroft 
    426       1.1   deraadt 	if (vp->v_type != VDIR)	/* XXX  vnode readdir op should do this */
    427       1.1   deraadt 		return (EINVAL);
    428      1.56   mycroft 
    429      1.33   deraadt 	buflen = min(MAXBSIZE, SCARG(uap, nbytes));
    430       1.1   deraadt 	buf = malloc(buflen, M_TEMP, M_WAITOK);
    431      1.56   mycroft 	ncookies = buflen / 16;
    432      1.56   mycroft 	cookiebuf = malloc(ncookies * sizeof(*cookiebuf), M_TEMP, M_WAITOK);
    433       1.1   deraadt 	VOP_LOCK(vp);
    434       1.1   deraadt 	off = fp->f_offset;
    435       1.1   deraadt again:
    436       1.1   deraadt 	aiov.iov_base = buf;
    437       1.1   deraadt 	aiov.iov_len = buflen;
    438       1.1   deraadt 	auio.uio_iov = &aiov;
    439       1.1   deraadt 	auio.uio_iovcnt = 1;
    440       1.1   deraadt 	auio.uio_rw = UIO_READ;
    441       1.1   deraadt 	auio.uio_segflg = UIO_SYSSPACE;
    442       1.1   deraadt 	auio.uio_procp = p;
    443       1.1   deraadt 	auio.uio_resid = buflen;
    444       1.1   deraadt 	auio.uio_offset = off;
    445       1.1   deraadt 	/*
    446       1.1   deraadt 	 * First we read into the malloc'ed buffer, then
    447       1.1   deraadt 	 * we massage it into user space, one record at a time.
    448       1.1   deraadt 	 */
    449      1.56   mycroft 	error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, cookiebuf,
    450      1.56   mycroft 	    ncookies);
    451      1.59   ghudson 	if (error)
    452      1.59   ghudson 		goto out;
    453      1.56   mycroft 
    454       1.1   deraadt 	inp = buf;
    455      1.33   deraadt 	outp = SCARG(uap, buf);
    456      1.33   deraadt 	resid = SCARG(uap, nbytes);
    457       1.1   deraadt 	if ((len = buflen - auio.uio_resid) == 0)
    458       1.1   deraadt 		goto eof;
    459      1.56   mycroft 
    460      1.56   mycroft 	for (cookie = cookiebuf; len > 0; len -= reclen) {
    461      1.56   mycroft 		bdp = (struct dirent *)inp;
    462      1.56   mycroft 		reclen = bdp->d_reclen;
    463       1.1   deraadt 		if (reclen & 3)
    464      1.33   deraadt 			panic("sunos_getdents");
    465      1.56   mycroft 		off = *cookie++;	/* each entry points to next */
    466      1.56   mycroft 		if (bdp->d_fileno == 0) {
    467       1.1   deraadt 			inp += reclen;	/* it is a hole; squish it out */
    468       1.1   deraadt 			continue;
    469       1.1   deraadt 		}
    470      1.56   mycroft 		sunos_reclen = SUNOS_RECLEN(&idb, bdp->d_namlen);
    471      1.56   mycroft 		if (reclen > len || resid < sunos_reclen) {
    472       1.1   deraadt 			/* entry too big for buffer, so just stop */
    473       1.1   deraadt 			outp++;
    474       1.1   deraadt 			break;
    475       1.1   deraadt 		}
    476       1.1   deraadt 		/*
    477       1.1   deraadt 		 * Massage in place to make a Sun-shaped dirent (otherwise
    478       1.1   deraadt 		 * we have to worry about touching user memory outside of
    479       1.1   deraadt 		 * the copyout() call).
    480       1.1   deraadt 		 */
    481      1.56   mycroft 		idb.d_fileno = bdp->d_fileno;
    482      1.56   mycroft 		idb.d_off = off;
    483      1.56   mycroft 		idb.d_reclen = sunos_reclen;
    484      1.56   mycroft 		idb.d_namlen = bdp->d_namlen;
    485      1.56   mycroft 		strcpy(idb.d_name, bdp->d_name);
    486      1.56   mycroft 		if ((error = copyout((caddr_t)&idb, outp, sunos_reclen)) != 0)
    487       1.1   deraadt 			goto out;
    488       1.1   deraadt 		/* advance past this real entry */
    489       1.1   deraadt 		inp += reclen;
    490       1.1   deraadt 		/* advance output past Sun-shaped entry */
    491      1.56   mycroft 		outp += sunos_reclen;
    492      1.56   mycroft 		resid -= sunos_reclen;
    493       1.1   deraadt 	}
    494      1.56   mycroft 
    495       1.1   deraadt 	/* if we squished out the whole block, try again */
    496      1.33   deraadt 	if (outp == SCARG(uap, buf))
    497       1.1   deraadt 		goto again;
    498       1.1   deraadt 	fp->f_offset = off;		/* update the vnode offset */
    499      1.56   mycroft 
    500       1.1   deraadt eof:
    501      1.33   deraadt 	*retval = SCARG(uap, nbytes) - resid;
    502       1.1   deraadt out:
    503       1.1   deraadt 	VOP_UNLOCK(vp);
    504      1.56   mycroft 	free(cookiebuf, M_TEMP);
    505       1.1   deraadt 	free(buf, M_TEMP);
    506       1.1   deraadt 	return (error);
    507       1.1   deraadt }
    508       1.1   deraadt 
    509      1.33   deraadt #define	SUNOS__MAP_NEW	0x80000000	/* if not, old mmap & cannot handle */
    510       1.4   deraadt 
    511      1.33   deraadt int
    512      1.55   mycroft sunos_sys_mmap(p, v, retval)
    513       1.1   deraadt 	register struct proc *p;
    514      1.54   thorpej 	void *v;
    515      1.32       cgd 	register_t *retval;
    516       1.1   deraadt {
    517      1.55   mycroft 	register struct sunos_sys_mmap_args *uap = v;
    518      1.55   mycroft 	struct sys_mmap_args ouap;
    519       1.1   deraadt 	register struct filedesc *fdp;
    520       1.1   deraadt 	register struct file *fp;
    521       1.1   deraadt 	register struct vnode *vp;
    522       1.1   deraadt 
    523       1.1   deraadt 	/*
    524      1.14       cgd 	 * Verify the arguments.
    525       1.1   deraadt 	 */
    526      1.33   deraadt 	if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
    527      1.14       cgd 		return (EINVAL);			/* XXX still needed? */
    528       1.4   deraadt 
    529      1.33   deraadt 	if ((SCARG(uap, flags) & SUNOS__MAP_NEW) == 0)
    530       1.1   deraadt 		return (EINVAL);
    531       1.1   deraadt 
    532      1.34   deraadt 	SCARG(&ouap, flags) = SCARG(uap, flags) & ~SUNOS__MAP_NEW;
    533      1.34   deraadt 	SCARG(&ouap, addr) = SCARG(uap, addr);
    534      1.34   deraadt 
    535      1.34   deraadt 	if ((SCARG(&ouap, flags) & MAP_FIXED) == 0 &&
    536      1.34   deraadt 	    SCARG(&ouap, addr) != 0 &&
    537      1.34   deraadt 	    SCARG(&ouap, addr) < (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ))
    538      1.34   deraadt 		SCARG(&ouap, addr) = (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ);
    539      1.34   deraadt 
    540      1.34   deraadt 	SCARG(&ouap, len) = SCARG(uap, len);
    541      1.34   deraadt 	SCARG(&ouap, prot) = SCARG(uap, prot);
    542      1.34   deraadt 	SCARG(&ouap, fd) = SCARG(uap, fd);
    543      1.34   deraadt 	SCARG(&ouap, pos) = SCARG(uap, pos);
    544      1.10   deraadt 
    545       1.1   deraadt 	/*
    546       1.1   deraadt 	 * Special case: if fd refers to /dev/zero, map as MAP_ANON.  (XXX)
    547       1.1   deraadt 	 */
    548       1.1   deraadt 	fdp = p->p_fd;
    549      1.34   deraadt 	if ((unsigned)SCARG(&ouap, fd) < fdp->fd_nfiles &&		/*XXX*/
    550      1.34   deraadt 	    (fp = fdp->fd_ofiles[SCARG(&ouap, fd)]) != NULL &&		/*XXX*/
    551       1.1   deraadt 	    fp->f_type == DTYPE_VNODE &&				/*XXX*/
    552       1.1   deraadt 	    (vp = (struct vnode *)fp->f_data)->v_type == VCHR &&	/*XXX*/
    553      1.23   deraadt 	    iszerodev(vp->v_rdev)) {					/*XXX*/
    554      1.34   deraadt 		SCARG(&ouap, flags) |= MAP_ANON;
    555      1.34   deraadt 		SCARG(&ouap, fd) = -1;
    556      1.14       cgd 	}
    557       1.4   deraadt 
    558      1.55   mycroft 	return (sys_mmap(p, &ouap, retval));
    559       1.1   deraadt }
    560       1.1   deraadt 
    561       1.1   deraadt #define	MC_SYNC		1
    562       1.1   deraadt #define	MC_LOCK		2
    563       1.1   deraadt #define	MC_UNLOCK	3
    564       1.1   deraadt #define	MC_ADVISE	4
    565       1.1   deraadt #define	MC_LOCKAS	5
    566       1.1   deraadt #define	MC_UNLOCKAS	6
    567       1.1   deraadt 
    568      1.33   deraadt int
    569      1.55   mycroft sunos_sys_mctl(p, v, retval)
    570       1.1   deraadt 	register struct proc *p;
    571      1.54   thorpej 	void *v;
    572      1.32       cgd 	register_t *retval;
    573       1.1   deraadt {
    574      1.55   mycroft 	register struct sunos_sys_mctl_args *uap = v;
    575       1.1   deraadt 
    576      1.33   deraadt 	switch (SCARG(uap, func)) {
    577       1.1   deraadt 	case MC_ADVISE:		/* ignore for now */
    578       1.1   deraadt 		return (0);
    579       1.1   deraadt 	case MC_SYNC:		/* translate to msync */
    580      1.55   mycroft 		return (sys_msync(p, uap, retval));
    581       1.1   deraadt 	default:
    582       1.1   deraadt 		return (EINVAL);
    583       1.1   deraadt 	}
    584       1.1   deraadt }
    585       1.1   deraadt 
    586      1.33   deraadt int
    587      1.55   mycroft sunos_sys_setsockopt(p, v, retval)
    588       1.1   deraadt 	struct proc *p;
    589      1.54   thorpej 	void *v;
    590      1.32       cgd 	register_t *retval;
    591       1.1   deraadt {
    592      1.55   mycroft 	register struct sunos_sys_setsockopt_args *uap = v;
    593       1.1   deraadt 	struct file *fp;
    594       1.1   deraadt 	struct mbuf *m = NULL;
    595       1.1   deraadt 	int error;
    596       1.1   deraadt 
    597      1.64  christos 	if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0)
    598       1.1   deraadt 		return (error);
    599       1.1   deraadt #define	SO_DONTLINGER (~SO_LINGER)
    600      1.33   deraadt 	if (SCARG(uap, name) == SO_DONTLINGER) {
    601       1.1   deraadt 		m = m_get(M_WAIT, MT_SOOPTS);
    602       1.1   deraadt 		if (m == NULL)
    603       1.1   deraadt 			return (ENOBUFS);
    604       1.1   deraadt 		mtod(m, struct linger *)->l_onoff = 0;
    605       1.1   deraadt 		m->m_len = sizeof(struct linger);
    606      1.33   deraadt 		return (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
    607       1.1   deraadt 		    SO_LINGER, m));
    608       1.1   deraadt 	}
    609      1.37        pk 	if (SCARG(uap, level) == IPPROTO_IP) {
    610      1.37        pk #define		SUNOS_IP_MULTICAST_IF		2
    611      1.37        pk #define		SUNOS_IP_MULTICAST_TTL		3
    612      1.37        pk #define		SUNOS_IP_MULTICAST_LOOP		4
    613      1.37        pk #define		SUNOS_IP_ADD_MEMBERSHIP		5
    614      1.37        pk #define		SUNOS_IP_DROP_MEMBERSHIP	6
    615      1.37        pk 		static int ipoptxlat[] = {
    616      1.37        pk 			IP_MULTICAST_IF,
    617      1.37        pk 			IP_MULTICAST_TTL,
    618      1.37        pk 			IP_MULTICAST_LOOP,
    619      1.37        pk 			IP_ADD_MEMBERSHIP,
    620      1.37        pk 			IP_DROP_MEMBERSHIP
    621      1.37        pk 		};
    622      1.37        pk 		if (SCARG(uap, name) >= SUNOS_IP_MULTICAST_IF &&
    623      1.37        pk 		    SCARG(uap, name) <= SUNOS_IP_DROP_MEMBERSHIP) {
    624      1.37        pk 			SCARG(uap, name) =
    625      1.37        pk 			    ipoptxlat[SCARG(uap, name) - SUNOS_IP_MULTICAST_IF];
    626      1.37        pk 		}
    627      1.37        pk 	}
    628      1.33   deraadt 	if (SCARG(uap, valsize) > MLEN)
    629       1.1   deraadt 		return (EINVAL);
    630      1.33   deraadt 	if (SCARG(uap, val)) {
    631       1.1   deraadt 		m = m_get(M_WAIT, MT_SOOPTS);
    632       1.1   deraadt 		if (m == NULL)
    633       1.1   deraadt 			return (ENOBUFS);
    634      1.64  christos 		error = copyin(SCARG(uap, val), mtod(m, caddr_t),
    635      1.64  christos 		    (u_int)SCARG(uap, valsize));
    636      1.64  christos 		if (error) {
    637       1.1   deraadt 			(void) m_free(m);
    638       1.1   deraadt 			return (error);
    639       1.1   deraadt 		}
    640      1.33   deraadt 		m->m_len = SCARG(uap, valsize);
    641       1.1   deraadt 	}
    642      1.33   deraadt 	return (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
    643      1.33   deraadt 	    SCARG(uap, name), m));
    644       1.1   deraadt }
    645       1.1   deraadt 
    646      1.33   deraadt int
    647      1.55   mycroft sunos_sys_fchroot(p, v, retval)
    648       1.1   deraadt 	register struct proc *p;
    649      1.54   thorpej 	void *v;
    650      1.32       cgd 	register_t *retval;
    651       1.1   deraadt {
    652      1.55   mycroft 	register struct sunos_sys_fchroot_args *uap = v;
    653       1.1   deraadt 	register struct filedesc *fdp = p->p_fd;
    654       1.1   deraadt 	register struct vnode *vp;
    655       1.1   deraadt 	struct file *fp;
    656       1.1   deraadt 	int error;
    657       1.1   deraadt 
    658       1.1   deraadt 	if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
    659       1.1   deraadt 		return (error);
    660      1.33   deraadt 	if ((error = getvnode(fdp, SCARG(uap, fd), &fp)) != 0)
    661       1.1   deraadt 		return (error);
    662       1.1   deraadt 	vp = (struct vnode *)fp->f_data;
    663       1.1   deraadt 	VOP_LOCK(vp);
    664       1.1   deraadt 	if (vp->v_type != VDIR)
    665       1.1   deraadt 		error = ENOTDIR;
    666       1.1   deraadt 	else
    667       1.1   deraadt 		error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p);
    668       1.1   deraadt 	VOP_UNLOCK(vp);
    669       1.1   deraadt 	if (error)
    670       1.1   deraadt 		return (error);
    671       1.1   deraadt 	VREF(vp);
    672       1.1   deraadt 	if (fdp->fd_rdir != NULL)
    673       1.1   deraadt 		vrele(fdp->fd_rdir);
    674       1.1   deraadt 	fdp->fd_rdir = vp;
    675       1.1   deraadt 	return (0);
    676       1.3   deraadt }
    677       1.3   deraadt 
    678       1.3   deraadt /*
    679       1.3   deraadt  * XXX: This needs cleaning up.
    680       1.3   deraadt  */
    681      1.33   deraadt int
    682      1.55   mycroft sunos_sys_auditsys(p, v, retval)
    683      1.40   deraadt 	struct proc *p;
    684      1.55   mycroft 	void *v;
    685      1.40   deraadt 	register_t *retval;
    686       1.3   deraadt {
    687       1.3   deraadt 	return 0;
    688       1.8   deraadt }
    689       1.8   deraadt 
    690      1.33   deraadt int
    691      1.55   mycroft sunos_sys_uname(p, v, retval)
    692       1.8   deraadt 	struct proc *p;
    693      1.54   thorpej 	void *v;
    694      1.32       cgd 	register_t *retval;
    695       1.8   deraadt {
    696      1.55   mycroft 	struct sunos_sys_uname_args *uap = v;
    697      1.33   deraadt 	struct sunos_utsname sut;
    698      1.22   deraadt 	extern char ostype[], machine[], osrelease[];
    699       1.8   deraadt 
    700      1.22   deraadt 	bzero(&sut, sizeof(sut));
    701       1.8   deraadt 
    702      1.22   deraadt 	bcopy(ostype, sut.sysname, sizeof(sut.sysname) - 1);
    703      1.22   deraadt 	bcopy(hostname, sut.nodename, sizeof(sut.nodename));
    704      1.22   deraadt 	sut.nodename[sizeof(sut.nodename)-1] = '\0';
    705      1.22   deraadt 	bcopy(osrelease, sut.release, sizeof(sut.release) - 1);
    706      1.22   deraadt 	bcopy("1", sut.version, sizeof(sut.version) - 1);
    707      1.22   deraadt 	bcopy(machine, sut.machine, sizeof(sut.machine) - 1);
    708       1.8   deraadt 
    709      1.33   deraadt 	return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, name),
    710      1.33   deraadt 	    sizeof(struct sunos_utsname));
    711       1.8   deraadt }
    712       1.8   deraadt 
    713       1.8   deraadt int
    714      1.55   mycroft sunos_sys_setpgrp(p, v, retval)
    715       1.8   deraadt 	struct proc *p;
    716      1.54   thorpej 	void *v;
    717      1.32       cgd 	register_t *retval;
    718       1.8   deraadt {
    719      1.55   mycroft 	struct sunos_sys_setpgrp_args *uap = v;
    720      1.54   thorpej 
    721       1.8   deraadt 	/*
    722       1.8   deraadt 	 * difference to our setpgid call is to include backwards
    723       1.8   deraadt 	 * compatibility to pre-setsid() binaries. Do setsid()
    724       1.8   deraadt 	 * instead of setpgid() in those cases where the process
    725       1.8   deraadt 	 * tries to create a new session the old way.
    726       1.8   deraadt 	 */
    727      1.55   mycroft 	if (!SCARG(uap, pgid) &&
    728      1.55   mycroft 	    (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
    729      1.55   mycroft 		return sys_setsid(p, uap, retval);
    730       1.8   deraadt 	else
    731      1.55   mycroft 		return sys_setpgid(p, uap, retval);
    732       1.8   deraadt }
    733       1.8   deraadt 
    734      1.33   deraadt int
    735      1.55   mycroft sunos_sys_open(p, v, retval)
    736       1.8   deraadt 	struct proc *p;
    737      1.54   thorpej 	void *v;
    738      1.32       cgd 	register_t *retval;
    739       1.8   deraadt {
    740      1.55   mycroft 	struct sunos_sys_open_args *uap = v;
    741       1.8   deraadt 	int l, r;
    742      1.39        pk 	int noctty;
    743       1.8   deraadt 	int ret;
    744       1.8   deraadt 
    745      1.50  christos 	caddr_t sg = stackgap_init(p->p_emul);
    746      1.50  christos 	SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    747      1.48        pk 
    748       1.8   deraadt 	/* convert mode into NetBSD mode */
    749      1.39        pk 	l = SCARG(uap, flags);
    750      1.39        pk 	noctty = l & 0x8000;
    751       1.8   deraadt 	r =	(l & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800));
    752       1.8   deraadt 	r |=	((l & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
    753       1.8   deraadt 	r |=	((l & 0x0080) ? O_SHLOCK : 0);
    754       1.8   deraadt 	r |=	((l & 0x0100) ? O_EXLOCK : 0);
    755       1.8   deraadt 	r |=	((l & 0x2000) ? O_FSYNC : 0);
    756       1.8   deraadt 
    757      1.39        pk 	SCARG(uap, flags) = r;
    758      1.55   mycroft 	ret = sys_open(p, (struct sys_open_args *)uap, retval);
    759       1.8   deraadt 
    760      1.20       cgd 	if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
    761       1.8   deraadt 		struct filedesc *fdp = p->p_fd;
    762       1.8   deraadt 		struct file *fp = fdp->fd_ofiles[*retval];
    763       1.8   deraadt 
    764       1.8   deraadt 		/* ignore any error, just give it a try */
    765       1.8   deraadt 		if (fp->f_type == DTYPE_VNODE)
    766      1.55   mycroft 			(fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t)0, p);
    767       1.8   deraadt 	}
    768       1.8   deraadt 	return ret;
    769      1.10   deraadt }
    770      1.10   deraadt 
    771      1.11    chopps #if defined (NFSSERVER)
    772      1.33   deraadt int
    773      1.55   mycroft sunos_sys_nfssvc(p, v, retval)
    774      1.10   deraadt 	struct proc *p;
    775      1.54   thorpej 	void *v;
    776      1.32       cgd 	register_t *retval;
    777      1.10   deraadt {
    778      1.64  christos #if 0
    779      1.55   mycroft 	struct sunos_sys_nfssvc_args *uap = v;
    780      1.51    briggs 	struct emul *e = p->p_emul;
    781      1.55   mycroft 	struct sys_nfssvc_args outuap;
    782      1.10   deraadt 	struct sockaddr sa;
    783      1.10   deraadt 	int error;
    784      1.10   deraadt 
    785      1.10   deraadt 	bzero(&outuap, sizeof outuap);
    786      1.33   deraadt 	SCARG(&outuap, fd) = SCARG(uap, fd);
    787      1.33   deraadt 	SCARG(&outuap, mskval) = STACKGAPBASE;
    788      1.33   deraadt 	SCARG(&outuap, msklen) = sizeof sa;
    789      1.33   deraadt 	SCARG(&outuap, mtchval) = SCARG(&outuap, mskval) + sizeof sa;
    790      1.33   deraadt 	SCARG(&outuap, mtchlen) = sizeof sa;
    791      1.10   deraadt 
    792      1.10   deraadt 	bzero(&sa, sizeof sa);
    793      1.33   deraadt 	if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
    794      1.10   deraadt 		return (error);
    795      1.33   deraadt 	if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
    796      1.10   deraadt 		return (error);
    797      1.10   deraadt 
    798      1.10   deraadt 	return nfssvc(p, &outuap, retval);
    799      1.33   deraadt #else
    800      1.33   deraadt 	return (ENOSYS);
    801      1.33   deraadt #endif
    802      1.10   deraadt }
    803      1.11    chopps #endif /* NFSSERVER */
    804      1.10   deraadt 
    805      1.33   deraadt int
    806      1.55   mycroft sunos_sys_ustat(p, v, retval)
    807      1.10   deraadt 	struct proc *p;
    808      1.54   thorpej 	void *v;
    809      1.32       cgd 	register_t *retval;
    810      1.10   deraadt {
    811      1.55   mycroft 	struct sunos_sys_ustat_args *uap = v;
    812      1.33   deraadt 	struct sunos_ustat us;
    813      1.10   deraadt 	int error;
    814      1.10   deraadt 
    815      1.10   deraadt 	bzero(&us, sizeof us);
    816      1.10   deraadt 
    817      1.10   deraadt 	/*
    818      1.10   deraadt 	 * XXX: should set f_tfree and f_tinode at least
    819      1.33   deraadt 	 * How do we translate dev -> fstat? (and then to sunos_ustat)
    820      1.10   deraadt 	 */
    821      1.10   deraadt 
    822      1.64  christos 	if ((error = copyout(&us, SCARG(uap, buf), sizeof us)) != 0)
    823      1.10   deraadt 		return (error);
    824      1.10   deraadt 	return 0;
    825      1.10   deraadt }
    826      1.10   deraadt 
    827      1.33   deraadt int
    828      1.55   mycroft sunos_sys_quotactl(p, v, retval)
    829      1.10   deraadt 	struct proc *p;
    830      1.54   thorpej 	void *v;
    831      1.32       cgd 	register_t *retval;
    832      1.10   deraadt {
    833      1.54   thorpej 
    834      1.10   deraadt 	return EINVAL;
    835      1.10   deraadt }
    836      1.10   deraadt 
    837      1.33   deraadt int
    838      1.55   mycroft sunos_sys_vhangup(p, v, retval)
    839      1.10   deraadt 	struct proc *p;
    840      1.55   mycroft 	void *v;
    841      1.32       cgd 	register_t *retval;
    842      1.10   deraadt {
    843      1.60        pk 	struct session *sp = p->p_session;
    844      1.60        pk 
    845      1.60        pk 	if (sp->s_ttyvp == 0)
    846      1.60        pk 		return 0;
    847      1.60        pk 
    848      1.60        pk 	if (sp->s_ttyp && sp->s_ttyp->t_session == sp && sp->s_ttyp->t_pgrp)
    849      1.60        pk 		pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1);
    850      1.60        pk 
    851      1.60        pk 	(void) ttywait(sp->s_ttyp);
    852      1.60        pk 	if (sp->s_ttyvp)
    853      1.60        pk 		vgoneall(sp->s_ttyvp);
    854      1.60        pk 	if (sp->s_ttyvp)
    855      1.60        pk 		vrele(sp->s_ttyvp);
    856      1.60        pk 	sp->s_ttyvp = NULL;
    857      1.55   mycroft 
    858      1.10   deraadt 	return 0;
    859      1.10   deraadt }
    860      1.10   deraadt 
    861      1.64  christos static int
    862      1.10   deraadt sunstatfs(sp, buf)
    863      1.10   deraadt 	struct statfs *sp;
    864      1.10   deraadt 	caddr_t buf;
    865      1.10   deraadt {
    866      1.33   deraadt 	struct sunos_statfs ssfs;
    867      1.10   deraadt 
    868      1.10   deraadt 	bzero(&ssfs, sizeof ssfs);
    869      1.10   deraadt 	ssfs.f_type = 0;
    870      1.16   deraadt 	ssfs.f_bsize = sp->f_bsize;
    871      1.10   deraadt 	ssfs.f_blocks = sp->f_blocks;
    872      1.10   deraadt 	ssfs.f_bfree = sp->f_bfree;
    873      1.10   deraadt 	ssfs.f_bavail = sp->f_bavail;
    874      1.10   deraadt 	ssfs.f_files = sp->f_files;
    875      1.10   deraadt 	ssfs.f_ffree = sp->f_ffree;
    876      1.10   deraadt 	ssfs.f_fsid = sp->f_fsid;
    877      1.10   deraadt 	return copyout((caddr_t)&ssfs, buf, sizeof ssfs);
    878      1.10   deraadt }
    879      1.10   deraadt 
    880      1.33   deraadt int
    881      1.55   mycroft sunos_sys_statfs(p, v, retval)
    882      1.10   deraadt 	struct proc *p;
    883      1.54   thorpej 	void *v;
    884      1.32       cgd 	register_t *retval;
    885      1.10   deraadt {
    886      1.55   mycroft 	struct sunos_sys_statfs_args *uap = v;
    887      1.10   deraadt 	register struct mount *mp;
    888      1.10   deraadt 	register struct statfs *sp;
    889      1.10   deraadt 	int error;
    890      1.10   deraadt 	struct nameidata nd;
    891      1.10   deraadt 
    892      1.50  christos 	caddr_t sg = stackgap_init(p->p_emul);
    893      1.50  christos 	SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    894      1.48        pk 
    895      1.33   deraadt 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    896      1.64  christos 	if ((error = namei(&nd)) != 0)
    897      1.10   deraadt 		return (error);
    898      1.27        pk 	mp = nd.ni_vp->v_mount;
    899      1.10   deraadt 	sp = &mp->mnt_stat;
    900      1.27        pk 	vrele(nd.ni_vp);
    901      1.64  christos 	if ((error = VFS_STATFS(mp, sp, p)) != 0)
    902      1.10   deraadt 		return (error);
    903      1.10   deraadt 	sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
    904      1.33   deraadt 	return sunstatfs(sp, (caddr_t)SCARG(uap, buf));
    905      1.10   deraadt }
    906      1.10   deraadt 
    907      1.33   deraadt int
    908      1.55   mycroft sunos_sys_fstatfs(p, v, retval)
    909      1.10   deraadt 	struct proc *p;
    910      1.54   thorpej 	void *v;
    911      1.32       cgd 	register_t *retval;
    912      1.10   deraadt {
    913      1.55   mycroft 	struct sunos_sys_fstatfs_args *uap = v;
    914      1.10   deraadt 	struct file *fp;
    915      1.10   deraadt 	struct mount *mp;
    916      1.10   deraadt 	register struct statfs *sp;
    917      1.10   deraadt 	int error;
    918      1.10   deraadt 
    919      1.64  christos 	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
    920      1.10   deraadt 		return (error);
    921      1.10   deraadt 	mp = ((struct vnode *)fp->f_data)->v_mount;
    922      1.10   deraadt 	sp = &mp->mnt_stat;
    923      1.64  christos 	if ((error = VFS_STATFS(mp, sp, p)) != 0)
    924      1.10   deraadt 		return (error);
    925      1.10   deraadt 	sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
    926      1.33   deraadt 	return sunstatfs(sp, (caddr_t)SCARG(uap, buf));
    927      1.10   deraadt }
    928      1.10   deraadt 
    929      1.33   deraadt int
    930      1.55   mycroft sunos_sys_exportfs(p, v, retval)
    931      1.10   deraadt 	struct proc *p;
    932      1.54   thorpej 	void *v;
    933      1.32       cgd 	register_t *retval;
    934      1.10   deraadt {
    935      1.10   deraadt 	/*
    936      1.10   deraadt 	 * XXX: should perhaps translate into a mount(2)
    937      1.10   deraadt 	 * with MOUNT_EXPORT?
    938      1.10   deraadt 	 */
    939      1.10   deraadt 	return 0;
    940      1.10   deraadt }
    941      1.10   deraadt 
    942      1.33   deraadt int
    943      1.55   mycroft sunos_sys_mknod(p, v, retval)
    944      1.10   deraadt 	struct proc *p;
    945      1.54   thorpej 	void *v;
    946      1.32       cgd 	register_t *retval;
    947      1.10   deraadt {
    948      1.55   mycroft 	struct sunos_sys_mknod_args *uap = v;
    949      1.55   mycroft 
    950      1.50  christos 	caddr_t sg = stackgap_init(p->p_emul);
    951      1.50  christos 	SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    952      1.48        pk 
    953      1.33   deraadt 	if (S_ISFIFO(SCARG(uap, mode)))
    954      1.55   mycroft 		return sys_mkfifo(p, uap, retval);
    955      1.10   deraadt 
    956      1.55   mycroft 	return sys_mknod(p, (struct sys_mknod_args *)uap, retval);
    957      1.12   deraadt }
    958      1.12   deraadt 
    959      1.33   deraadt #define SUNOS_SC_ARG_MAX	1
    960      1.33   deraadt #define SUNOS_SC_CHILD_MAX	2
    961      1.33   deraadt #define SUNOS_SC_CLK_TCK	3
    962      1.33   deraadt #define SUNOS_SC_NGROUPS_MAX	4
    963      1.33   deraadt #define SUNOS_SC_OPEN_MAX	5
    964      1.33   deraadt #define SUNOS_SC_JOB_CONTROL	6
    965      1.33   deraadt #define SUNOS_SC_SAVED_IDS	7
    966      1.33   deraadt #define SUNOS_SC_VERSION	8
    967      1.12   deraadt 
    968      1.33   deraadt int
    969      1.55   mycroft sunos_sys_sysconf(p, v, retval)
    970      1.12   deraadt 	struct proc *p;
    971      1.54   thorpej 	void *v;
    972      1.32       cgd 	register_t *retval;
    973      1.12   deraadt {
    974      1.55   mycroft 	struct sunos_sys_sysconf_args *uap = v;
    975      1.24   deraadt 	extern int maxfiles;
    976      1.12   deraadt 
    977      1.33   deraadt 	switch(SCARG(uap, name)) {
    978      1.33   deraadt 	case SUNOS_SC_ARG_MAX:
    979      1.12   deraadt 		*retval = ARG_MAX;
    980      1.13   deraadt 		break;
    981      1.33   deraadt 	case SUNOS_SC_CHILD_MAX:
    982      1.12   deraadt 		*retval = maxproc;
    983      1.13   deraadt 		break;
    984      1.33   deraadt 	case SUNOS_SC_CLK_TCK:
    985      1.12   deraadt 		*retval = 60;		/* should this be `hz', ie. 100? */
    986      1.13   deraadt 		break;
    987      1.33   deraadt 	case SUNOS_SC_NGROUPS_MAX:
    988      1.12   deraadt 		*retval = NGROUPS_MAX;
    989      1.13   deraadt 		break;
    990      1.33   deraadt 	case SUNOS_SC_OPEN_MAX:
    991      1.24   deraadt 		*retval = maxfiles;
    992      1.13   deraadt 		break;
    993      1.33   deraadt 	case SUNOS_SC_JOB_CONTROL:
    994      1.12   deraadt 		*retval = 1;
    995      1.13   deraadt 		break;
    996      1.33   deraadt 	case SUNOS_SC_SAVED_IDS:
    997      1.12   deraadt #ifdef _POSIX_SAVED_IDS
    998      1.12   deraadt 		*retval = 1;
    999      1.12   deraadt #else
   1000      1.12   deraadt 		*retval = 0;
   1001      1.12   deraadt #endif
   1002      1.13   deraadt 		break;
   1003      1.33   deraadt 	case SUNOS_SC_VERSION:
   1004      1.12   deraadt 		*retval = 198808;
   1005      1.13   deraadt 		break;
   1006      1.12   deraadt 	default:
   1007      1.12   deraadt 		return EINVAL;
   1008      1.12   deraadt 	}
   1009      1.12   deraadt 	return 0;
   1010      1.17        pk }
   1011      1.17        pk 
   1012      1.33   deraadt #define SUNOS_RLIMIT_NOFILE	6	/* Other RLIMIT_* are the same */
   1013      1.33   deraadt #define SUNOS_RLIM_NLIMITS	7
   1014      1.17        pk 
   1015      1.33   deraadt int
   1016      1.55   mycroft sunos_sys_getrlimit(p, v, retval)
   1017      1.17        pk 	struct proc *p;
   1018      1.54   thorpej 	void *v;
   1019      1.32       cgd 	register_t *retval;
   1020      1.17        pk {
   1021      1.55   mycroft 	struct sunos_sys_getrlimit_args *uap = v;
   1022      1.54   thorpej 
   1023      1.33   deraadt 	if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
   1024      1.17        pk 		return EINVAL;
   1025      1.17        pk 
   1026      1.33   deraadt 	if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
   1027      1.33   deraadt 		SCARG(uap, which) = RLIMIT_NOFILE;
   1028      1.17        pk 
   1029      1.55   mycroft 	return compat_43_sys_getrlimit(p, uap, retval);
   1030      1.17        pk }
   1031      1.17        pk 
   1032      1.33   deraadt int
   1033      1.55   mycroft sunos_sys_setrlimit(p, v, retval)
   1034      1.17        pk 	struct proc *p;
   1035      1.54   thorpej 	void *v;
   1036      1.32       cgd 	register_t *retval;
   1037      1.17        pk {
   1038      1.55   mycroft 	struct sunos_sys_getrlimit_args *uap = v;
   1039      1.54   thorpej 
   1040      1.33   deraadt 	if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
   1041      1.17        pk 		return EINVAL;
   1042      1.17        pk 
   1043      1.33   deraadt 	if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
   1044      1.33   deraadt 		SCARG(uap, which) = RLIMIT_NOFILE;
   1045      1.17        pk 
   1046      1.55   mycroft 	return compat_43_sys_setrlimit(p, uap, retval);
   1047      1.35   deraadt }
   1048      1.36   deraadt 
   1049      1.36   deraadt /* for the m68k machines */
   1050      1.36   deraadt #ifndef PT_GETFPREGS
   1051      1.36   deraadt #define PT_GETFPREGS -1
   1052      1.36   deraadt #endif
   1053      1.36   deraadt #ifndef PT_SETFPREGS
   1054      1.36   deraadt #define PT_SETFPREGS -1
   1055      1.36   deraadt #endif
   1056      1.35   deraadt 
   1057      1.35   deraadt static int sreq2breq[] = {
   1058      1.35   deraadt 	PT_TRACE_ME,    PT_READ_I,      PT_READ_D,      -1,
   1059      1.35   deraadt 	PT_WRITE_I,     PT_WRITE_D,     -1,             PT_CONTINUE,
   1060      1.35   deraadt 	PT_KILL,        -1,             PT_ATTACH,      PT_DETACH,
   1061      1.35   deraadt 	PT_GETREGS,     PT_SETREGS,     PT_GETFPREGS,   PT_SETFPREGS
   1062      1.35   deraadt };
   1063      1.35   deraadt static int nreqs = sizeof(sreq2breq) / sizeof(sreq2breq[0]);
   1064      1.35   deraadt 
   1065      1.64  christos int
   1066      1.55   mycroft sunos_sys_ptrace(p, v, retval)
   1067      1.35   deraadt 	struct proc *p;
   1068      1.54   thorpej 	void *v;
   1069      1.55   mycroft 	register_t *retval;
   1070      1.35   deraadt {
   1071      1.55   mycroft 	struct sunos_sys_ptrace_args *uap = v;
   1072      1.55   mycroft 	struct sys_ptrace_args pa;
   1073      1.35   deraadt 	int req;
   1074      1.35   deraadt 
   1075      1.35   deraadt 	req = SCARG(uap, req);
   1076      1.35   deraadt 
   1077      1.35   deraadt 	if (req < 0 || req >= nreqs)
   1078      1.35   deraadt 		return (EINVAL);
   1079      1.35   deraadt 
   1080      1.35   deraadt 	req = sreq2breq[req];
   1081      1.35   deraadt 	if (req == -1)
   1082      1.35   deraadt 		return (EINVAL);
   1083      1.35   deraadt 
   1084      1.35   deraadt 	SCARG(&pa, req) = req;
   1085      1.35   deraadt 	SCARG(&pa, pid) = (pid_t)SCARG(uap, pid);
   1086      1.35   deraadt 	SCARG(&pa, addr) = (caddr_t)SCARG(uap, addr);
   1087      1.35   deraadt 	SCARG(&pa, data) = SCARG(uap, data);
   1088      1.35   deraadt 
   1089      1.55   mycroft 	return sys_ptrace(p, &pa, retval);
   1090      1.35   deraadt }
   1091      1.35   deraadt 
   1092      1.35   deraadt static void
   1093      1.35   deraadt sunos_pollscan(p, pl, nfd, retval)
   1094      1.35   deraadt 	struct proc *p;
   1095      1.35   deraadt 	struct sunos_pollfd *pl;
   1096      1.35   deraadt 	int nfd;
   1097      1.35   deraadt 	register_t *retval;
   1098      1.35   deraadt {
   1099      1.35   deraadt 	register struct filedesc *fdp = p->p_fd;
   1100      1.35   deraadt 	register int msk, i;
   1101      1.35   deraadt 	struct file *fp;
   1102      1.35   deraadt 	int n = 0;
   1103      1.35   deraadt 	static int flag[3] = { FREAD, FWRITE, 0 };
   1104      1.35   deraadt 	static int pflag[3] = { SUNOS_POLLIN|SUNOS_POLLRDNORM,
   1105      1.35   deraadt 				SUNOS_POLLOUT, SUNOS_POLLERR };
   1106      1.35   deraadt 
   1107      1.35   deraadt 	/*
   1108      1.35   deraadt 	 * XXX: We need to implement the rest of the flags.
   1109      1.35   deraadt 	 */
   1110      1.35   deraadt 	for (i = 0; i < nfd; i++) {
   1111      1.35   deraadt 		fp = fdp->fd_ofiles[pl[i].fd];
   1112      1.35   deraadt 		if (fp == NULL) {
   1113      1.35   deraadt 			if (pl[i].events & SUNOS_POLLNVAL) {
   1114      1.35   deraadt 				pl[i].revents |= SUNOS_POLLNVAL;
   1115      1.35   deraadt 				n++;
   1116      1.35   deraadt 			}
   1117      1.35   deraadt 			continue;
   1118      1.35   deraadt 		}
   1119      1.35   deraadt 		for (msk = 0; msk < 3; msk++) {
   1120      1.35   deraadt 			if (pl[i].events & pflag[msk]) {
   1121      1.35   deraadt 				if ((*fp->f_ops->fo_select)(fp, flag[msk], p)) {
   1122      1.35   deraadt 					pl[i].revents |=
   1123      1.35   deraadt 					    pflag[msk] & pl[i].events;
   1124      1.35   deraadt 					n++;
   1125      1.35   deraadt 				}
   1126      1.35   deraadt 			}
   1127      1.35   deraadt 		}
   1128      1.35   deraadt 	}
   1129      1.35   deraadt 	*retval = n;
   1130      1.35   deraadt }
   1131      1.35   deraadt 
   1132      1.35   deraadt 
   1133      1.35   deraadt /*
   1134      1.35   deraadt  * We are using the same mechanism as select only we encode/decode args
   1135      1.35   deraadt  * differently.
   1136      1.35   deraadt  */
   1137      1.35   deraadt int
   1138      1.55   mycroft sunos_sys_poll(p, v, retval)
   1139      1.35   deraadt 	struct proc *p;
   1140      1.54   thorpej 	void *v;
   1141      1.35   deraadt 	register_t *retval;
   1142      1.35   deraadt {
   1143      1.55   mycroft 	struct sunos_sys_poll_args *uap = v;
   1144      1.35   deraadt 	int i, s;
   1145      1.35   deraadt 	int error, error2;
   1146      1.35   deraadt 	size_t sz = sizeof(struct sunos_pollfd) * SCARG(uap, nfds);
   1147      1.35   deraadt 	struct sunos_pollfd *pl;
   1148      1.35   deraadt 	int msec = SCARG(uap, timeout);
   1149      1.35   deraadt 	struct timeval atv;
   1150      1.35   deraadt 	int timo;
   1151      1.35   deraadt 	int ncoll;
   1152      1.35   deraadt 	extern int nselcoll, selwait;
   1153      1.35   deraadt 
   1154      1.35   deraadt 	pl = (struct sunos_pollfd *) malloc(sz, M_TEMP, M_WAITOK);
   1155      1.35   deraadt 
   1156      1.64  christos 	if ((error = copyin(SCARG(uap, fds), pl, sz)) != 0)
   1157      1.35   deraadt 		goto bad;
   1158      1.35   deraadt 
   1159      1.35   deraadt 	for (i = 0; i < SCARG(uap, nfds); i++)
   1160      1.35   deraadt 		pl[i].revents = 0;
   1161      1.35   deraadt 
   1162      1.35   deraadt 	if (msec != -1) {
   1163      1.35   deraadt 		atv.tv_sec = msec / 1000;
   1164      1.35   deraadt 		atv.tv_usec = (msec - (atv.tv_sec * 1000)) * 1000;
   1165      1.35   deraadt 
   1166      1.35   deraadt 		if (itimerfix(&atv)) {
   1167      1.35   deraadt 			error = EINVAL;
   1168      1.35   deraadt 			goto done;
   1169      1.35   deraadt 		}
   1170      1.35   deraadt 		s = splclock();
   1171      1.43   mycroft 		timeradd(&atv, &time, &atv);
   1172      1.35   deraadt 		timo = hzto(&atv);
   1173      1.35   deraadt 		/*
   1174      1.35   deraadt 		 * Avoid inadvertently sleeping forever.
   1175      1.35   deraadt 		 */
   1176      1.35   deraadt 		if (timo == 0)
   1177      1.35   deraadt 			timo = 1;
   1178      1.35   deraadt 		splx(s);
   1179      1.35   deraadt 	} else
   1180      1.35   deraadt 		timo = 0;
   1181      1.35   deraadt 
   1182      1.35   deraadt retry:
   1183      1.35   deraadt 	ncoll = nselcoll;
   1184      1.35   deraadt 	p->p_flag |= P_SELECT;
   1185      1.35   deraadt 	sunos_pollscan(p, pl, SCARG(uap, nfds), retval);
   1186      1.35   deraadt 	if (*retval)
   1187      1.35   deraadt 		goto done;
   1188      1.35   deraadt 	s = splhigh();
   1189      1.35   deraadt 	if (timo && timercmp(&time, &atv, >=)) {
   1190      1.35   deraadt 		splx(s);
   1191      1.35   deraadt 		goto done;
   1192      1.35   deraadt 	}
   1193      1.35   deraadt 	if ((p->p_flag & P_SELECT) == 0 || nselcoll != ncoll) {
   1194      1.35   deraadt 		splx(s);
   1195      1.35   deraadt 		goto retry;
   1196      1.35   deraadt 	}
   1197      1.35   deraadt 	p->p_flag &= ~P_SELECT;
   1198      1.35   deraadt 	error = tsleep((caddr_t)&selwait, PSOCK | PCATCH, "sunos_poll", timo);
   1199      1.35   deraadt 	splx(s);
   1200      1.35   deraadt 	if (error == 0)
   1201      1.35   deraadt 		goto retry;
   1202      1.35   deraadt 
   1203      1.35   deraadt done:
   1204      1.35   deraadt 	p->p_flag &= ~P_SELECT;
   1205      1.35   deraadt 	/* poll is not restarted after signals... */
   1206      1.35   deraadt 	if (error == ERESTART)
   1207      1.35   deraadt 		error = EINTR;
   1208      1.35   deraadt 	if (error == EWOULDBLOCK)
   1209      1.35   deraadt 		error = 0;
   1210      1.35   deraadt 
   1211      1.64  christos 	if ((error2 = copyout(pl, SCARG(uap, fds), sz)) != 0)
   1212      1.35   deraadt 		error = error2;
   1213      1.35   deraadt 
   1214      1.35   deraadt bad:
   1215      1.35   deraadt 	free((char *) pl, M_TEMP);
   1216      1.35   deraadt 
   1217      1.35   deraadt 	return (error);
   1218      1.44  christos }
   1219      1.44  christos 
   1220      1.44  christos /*
   1221      1.44  christos  * SunOS reboot system call (for compatibility).
   1222      1.44  christos  * Sun lets you pass in a boot string which the PROM
   1223      1.44  christos  * saves and provides to the next boot program.
   1224      1.44  christos  */
   1225      1.44  christos static struct sunos_howto_conv {
   1226      1.46       gwr 	int sun_howto;
   1227      1.44  christos 	int bsd_howto;
   1228      1.44  christos } sunos_howto_conv[] = {
   1229      1.44  christos 	{ 0x001,	RB_ASKNAME },
   1230      1.44  christos 	{ 0x002,	RB_SINGLE },
   1231      1.44  christos 	{ 0x004,	RB_NOSYNC },
   1232      1.44  christos 	{ 0x008,	RB_HALT },
   1233      1.44  christos 	{ 0x080,	RB_DUMP },
   1234      1.44  christos 	{ 0x000,	0 },
   1235      1.44  christos };
   1236      1.46       gwr #define	SUNOS_RB_STRING	0x200
   1237      1.44  christos 
   1238      1.46       gwr int
   1239      1.55   mycroft sunos_sys_reboot(p, v, retval)
   1240      1.44  christos 	struct proc *p;
   1241      1.54   thorpej 	void *v;
   1242      1.46       gwr 	register_t *retval;
   1243      1.44  christos {
   1244      1.55   mycroft 	struct sunos_sys_reboot_args *uap = v;
   1245      1.44  christos 	struct sunos_howto_conv *convp;
   1246      1.46       gwr 	int error, bsd_howto, sun_howto;
   1247      1.44  christos 
   1248      1.64  christos 	if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
   1249      1.44  christos 		return (error);
   1250      1.44  christos 
   1251      1.44  christos 	/*
   1252      1.44  christos 	 * Convert howto bits to BSD format.
   1253      1.44  christos 	 */
   1254      1.46       gwr 	sun_howto = SCARG(uap, howto);
   1255      1.44  christos 	bsd_howto = 0;
   1256      1.44  christos 	convp = sunos_howto_conv;
   1257      1.46       gwr 	while (convp->sun_howto) {
   1258      1.46       gwr 		if (sun_howto &  convp->sun_howto)
   1259      1.44  christos 			bsd_howto |= convp->bsd_howto;
   1260      1.44  christos 		convp++;
   1261      1.44  christos 	}
   1262      1.44  christos 
   1263      1.47  christos #ifdef sun3
   1264      1.44  christos 	/*
   1265      1.44  christos 	 * Sun RB_STRING (Get user supplied bootstring.)
   1266      1.46       gwr 	 * If the machine supports passing a string to the
   1267      1.46       gwr 	 * next booted kernel, add the machine name above
   1268      1.46       gwr 	 * and provide a reboot2() function (see sun3).
   1269      1.44  christos 	 */
   1270      1.46       gwr 	if (sun_howto & SUNOS_RB_STRING) {
   1271      1.46       gwr 		char bs[128];
   1272      1.46       gwr 
   1273      1.47  christos 		error = copyinstr(SCARG(uap, bootstr), bs, sizeof(bs), 0);
   1274      1.47  christos 		if (error)
   1275      1.47  christos 			return error;
   1276      1.46       gwr 
   1277      1.46       gwr 		return (reboot2(bsd_howto, bs));
   1278      1.44  christos 	}
   1279      1.47  christos #endif	/* sun3 */
   1280      1.44  christos 
   1281      1.64  christos 	boot(bsd_howto);
   1282      1.64  christos 	return 0;
   1283      1.50  christos }
   1284      1.50  christos 
   1285      1.50  christos /*
   1286      1.50  christos  * Generalized interface signal handler, 4.3-compatible.
   1287      1.50  christos  */
   1288      1.50  christos /* ARGSUSED */
   1289      1.50  christos int
   1290      1.55   mycroft sunos_sys_sigvec(p, v, retval)
   1291      1.50  christos 	struct proc *p;
   1292      1.54   thorpej 	void *v;
   1293      1.54   thorpej 	register_t *retval;
   1294      1.54   thorpej {
   1295      1.55   mycroft 	register struct sunos_sys_sigvec_args /* {
   1296      1.50  christos 		syscallarg(int) signum;
   1297      1.50  christos 		syscallarg(struct sigvec *) nsv;
   1298      1.50  christos 		syscallarg(struct sigvec *) osv;
   1299      1.54   thorpej 	} */ *uap = v;
   1300      1.50  christos 	struct sigvec vec;
   1301      1.50  christos 	register struct sigacts *ps = p->p_sigacts;
   1302      1.50  christos 	register struct sigvec *sv;
   1303      1.50  christos 	register int signum;
   1304      1.50  christos 	int bit, error;
   1305      1.50  christos 
   1306      1.50  christos 	signum = SCARG(uap, signum);
   1307      1.50  christos 	if (signum <= 0 || signum >= NSIG ||
   1308      1.50  christos 	    signum == SIGKILL || signum == SIGSTOP)
   1309      1.50  christos 		return (EINVAL);
   1310      1.50  christos 	sv = &vec;
   1311      1.50  christos 	if (SCARG(uap, osv)) {
   1312      1.50  christos 		*(sig_t *)&sv->sv_handler = ps->ps_sigact[signum];
   1313      1.50  christos 		sv->sv_mask = ps->ps_catchmask[signum];
   1314      1.50  christos 		bit = sigmask(signum);
   1315      1.50  christos 		sv->sv_flags = 0;
   1316      1.50  christos 		if ((ps->ps_sigonstack & bit) != 0)
   1317      1.50  christos 			sv->sv_flags |= SV_ONSTACK;
   1318      1.50  christos 		if ((ps->ps_sigintr & bit) != 0)
   1319      1.50  christos 			sv->sv_flags |= SV_INTERRUPT;
   1320      1.55   mycroft 		if ((ps->ps_sigreset & bit) != 0)
   1321      1.55   mycroft 			sv->sv_flags |= SA_RESETHAND;
   1322      1.55   mycroft 		sv->sv_mask &= ~bit;
   1323      1.64  christos 		error = copyout((caddr_t)sv, (caddr_t)SCARG(uap, osv),
   1324      1.64  christos 		    sizeof (vec));
   1325      1.64  christos 		if (error)
   1326      1.50  christos 			return (error);
   1327      1.50  christos 	}
   1328      1.50  christos 	if (SCARG(uap, nsv)) {
   1329      1.64  christos 		error = copyin((caddr_t)SCARG(uap, nsv), (caddr_t)sv,
   1330      1.64  christos 		    sizeof (vec));
   1331      1.64  christos 		if (error)
   1332      1.50  christos 			return (error);
   1333      1.50  christos 		/*
   1334      1.53       gwr 		 * SunOS uses the mask 0x0004 as SV_RESETHAND
   1335      1.53       gwr 		 * meaning: `reset to SIG_DFL on delivery'.
   1336      1.53       gwr 		 * We support only the bits in: 0xF
   1337      1.53       gwr 		 * (those bits are the same as ours)
   1338      1.50  christos 		 */
   1339      1.53       gwr 		if (sv->sv_flags & ~0xF)
   1340      1.53       gwr 			return (EINVAL);
   1341      1.53       gwr 		/* SunOS binaries have a user-mode trampoline. */
   1342      1.53       gwr 		sv->sv_flags |= SA_USERTRAMP;
   1343      1.53       gwr 		/* Convert sigvec:SV_INTERRUPT to sigaction:SA_RESTART */
   1344      1.53       gwr 		sv->sv_flags ^= SA_RESTART;	/* same bit, inverted */
   1345      1.50  christos 		setsigvec(p, signum, (struct sigaction *)sv);
   1346      1.50  christos 	}
   1347      1.50  christos 	return (0);
   1348       1.1   deraadt }
   1349