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