Home | History | Annotate | Line # | Download | only in sunos32
sunos32_misc.c revision 1.7.2.2
      1  1.7.2.2  bouyer /*	$NetBSD: sunos32_misc.c,v 1.7.2.2 2001/02/11 19:14:32 bouyer Exp $	*/
      2  1.7.2.2  bouyer /* from :NetBSD: sunos_misc.c,v 1.107 2000/12/01 19:25:10 jdolecek Exp	*/
      3  1.7.2.2  bouyer 
      4  1.7.2.2  bouyer /*
      5  1.7.2.2  bouyer  * Copyright (c) 2001 Matthew R. Green
      6  1.7.2.2  bouyer  * All rights reserved.
      7  1.7.2.2  bouyer  *
      8  1.7.2.2  bouyer  * Redistribution and use in source and binary forms, with or without
      9  1.7.2.2  bouyer  * modification, are permitted provided that the following conditions
     10  1.7.2.2  bouyer  * are met:
     11  1.7.2.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     12  1.7.2.2  bouyer  *    notice, this list of conditions and the following disclaimer.
     13  1.7.2.2  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.7.2.2  bouyer  *    notice, this list of conditions and the following disclaimer in the
     15  1.7.2.2  bouyer  *    documentation and/or other materials provided with the distribution.
     16  1.7.2.2  bouyer  * 3. The name of the author may not be used to endorse or promote products
     17  1.7.2.2  bouyer  *    derived from this software without specific prior written permission.
     18  1.7.2.2  bouyer  *
     19  1.7.2.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20  1.7.2.2  bouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21  1.7.2.2  bouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22  1.7.2.2  bouyer  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23  1.7.2.2  bouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     24  1.7.2.2  bouyer  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     25  1.7.2.2  bouyer  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     26  1.7.2.2  bouyer  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     27  1.7.2.2  bouyer  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  1.7.2.2  bouyer  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  1.7.2.2  bouyer  * SUCH DAMAGE.
     30  1.7.2.2  bouyer  */
     31  1.7.2.2  bouyer 
     32  1.7.2.2  bouyer /*
     33  1.7.2.2  bouyer  * Copyright (c) 1992, 1993
     34  1.7.2.2  bouyer  *	The Regents of the University of California.  All rights reserved.
     35  1.7.2.2  bouyer  *
     36  1.7.2.2  bouyer  * This software was developed by the Computer Systems Engineering group
     37  1.7.2.2  bouyer  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     38  1.7.2.2  bouyer  * contributed to Berkeley.
     39  1.7.2.2  bouyer  *
     40  1.7.2.2  bouyer  * All advertising materials mentioning features or use of this software
     41  1.7.2.2  bouyer  * must display the following acknowledgement:
     42  1.7.2.2  bouyer  *	This product includes software developed by the University of
     43  1.7.2.2  bouyer  *	California, Lawrence Berkeley Laboratory.
     44  1.7.2.2  bouyer  *
     45  1.7.2.2  bouyer  * Redistribution and use in source and binary forms, with or without
     46  1.7.2.2  bouyer  * modification, are permitted provided that the following conditions
     47  1.7.2.2  bouyer  * are met:
     48  1.7.2.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     49  1.7.2.2  bouyer  *    notice, this list of conditions and the following disclaimer.
     50  1.7.2.2  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     51  1.7.2.2  bouyer  *    notice, this list of conditions and the following disclaimer in the
     52  1.7.2.2  bouyer  *    documentation and/or other materials provided with the distribution.
     53  1.7.2.2  bouyer  * 3. All advertising materials mentioning features or use of this software
     54  1.7.2.2  bouyer  *    must display the following acknowledgement:
     55  1.7.2.2  bouyer  *	This product includes software developed by the University of
     56  1.7.2.2  bouyer  *	California, Berkeley and its contributors.
     57  1.7.2.2  bouyer  * 4. Neither the name of the University nor the names of its contributors
     58  1.7.2.2  bouyer  *    may be used to endorse or promote products derived from this software
     59  1.7.2.2  bouyer  *    without specific prior written permission.
     60  1.7.2.2  bouyer  *
     61  1.7.2.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     62  1.7.2.2  bouyer  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     63  1.7.2.2  bouyer  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     64  1.7.2.2  bouyer  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     65  1.7.2.2  bouyer  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     66  1.7.2.2  bouyer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     67  1.7.2.2  bouyer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     68  1.7.2.2  bouyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     69  1.7.2.2  bouyer  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     70  1.7.2.2  bouyer  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     71  1.7.2.2  bouyer  * SUCH DAMAGE.
     72  1.7.2.2  bouyer  *
     73  1.7.2.2  bouyer  *	@(#)sunos_misc.c	8.1 (Berkeley) 6/18/93
     74  1.7.2.2  bouyer  *
     75  1.7.2.2  bouyer  *	Header: sunos_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
     76  1.7.2.2  bouyer  */
     77  1.7.2.2  bouyer 
     78  1.7.2.2  bouyer /*
     79  1.7.2.2  bouyer  * SunOS compatibility module, 64-bit kernel version
     80  1.7.2.2  bouyer  *
     81  1.7.2.2  bouyer  * SunOS system calls that are implemented differently in BSD are
     82  1.7.2.2  bouyer  * handled here.
     83  1.7.2.2  bouyer  */
     84  1.7.2.2  bouyer 
     85  1.7.2.2  bouyer #define COMPAT_SUNOS 1
     86  1.7.2.2  bouyer 
     87  1.7.2.2  bouyer #if defined(_KERNEL) && !defined(_LKM)
     88  1.7.2.2  bouyer #include "opt_nfsserver.h"
     89  1.7.2.2  bouyer #include "opt_compat_43.h"
     90  1.7.2.2  bouyer #include "opt_compat_netbsd.h"
     91  1.7.2.2  bouyer #include "fs_nfs.h"
     92  1.7.2.2  bouyer #endif
     93  1.7.2.2  bouyer 
     94  1.7.2.2  bouyer #include <sys/param.h>
     95  1.7.2.2  bouyer #include <sys/systm.h>
     96  1.7.2.2  bouyer #include <sys/namei.h>
     97  1.7.2.2  bouyer #include <sys/proc.h>
     98  1.7.2.2  bouyer #include <sys/dirent.h>
     99  1.7.2.2  bouyer #include <sys/file.h>
    100  1.7.2.2  bouyer #include <sys/stat.h>
    101  1.7.2.2  bouyer #include <sys/filedesc.h>
    102  1.7.2.2  bouyer #include <sys/ioctl.h>
    103  1.7.2.2  bouyer #include <sys/kernel.h>
    104  1.7.2.2  bouyer #include <sys/reboot.h>
    105  1.7.2.2  bouyer #include <sys/malloc.h>
    106  1.7.2.2  bouyer #include <sys/mbuf.h>
    107  1.7.2.2  bouyer #include <sys/mman.h>
    108  1.7.2.2  bouyer #include <sys/mount.h>
    109  1.7.2.2  bouyer #include <sys/ptrace.h>
    110  1.7.2.2  bouyer #include <sys/resource.h>
    111  1.7.2.2  bouyer #include <sys/resourcevar.h>
    112  1.7.2.2  bouyer #include <sys/signal.h>
    113  1.7.2.2  bouyer #include <sys/signalvar.h>
    114  1.7.2.2  bouyer #include <sys/socket.h>
    115  1.7.2.2  bouyer #include <sys/tty.h>
    116  1.7.2.2  bouyer #include <sys/vnode.h>
    117  1.7.2.2  bouyer #include <sys/uio.h>
    118  1.7.2.2  bouyer #include <sys/wait.h>
    119  1.7.2.2  bouyer #include <sys/utsname.h>
    120  1.7.2.2  bouyer #include <sys/unistd.h>
    121  1.7.2.2  bouyer #include <sys/syscallargs.h>
    122  1.7.2.2  bouyer #include <sys/conf.h>
    123  1.7.2.2  bouyer #include <sys/socketvar.h>
    124  1.7.2.2  bouyer #include <sys/exec.h>
    125  1.7.2.2  bouyer #include <sys/swap.h>
    126  1.7.2.2  bouyer 
    127  1.7.2.2  bouyer #include <compat/netbsd32/netbsd32.h>
    128  1.7.2.2  bouyer #include <compat/netbsd32/netbsd32_syscallargs.h>
    129  1.7.2.2  bouyer #include <compat/sunos32/sunos32.h>
    130  1.7.2.2  bouyer #include <compat/sunos32/sunos32_dirent.h>
    131  1.7.2.2  bouyer #include <compat/sunos32/sunos32_syscallargs.h>
    132  1.7.2.2  bouyer #include <compat/common/compat_util.h>
    133  1.7.2.2  bouyer 
    134  1.7.2.2  bouyer #include <netinet/in.h>
    135  1.7.2.2  bouyer 
    136  1.7.2.2  bouyer #include <miscfs/specfs/specdev.h>
    137  1.7.2.2  bouyer 
    138  1.7.2.2  bouyer #include <nfs/rpcv2.h>
    139  1.7.2.2  bouyer #include <nfs/nfsproto.h>
    140  1.7.2.2  bouyer #include <nfs/nfs.h>
    141  1.7.2.2  bouyer #include <nfs/nfsmount.h>
    142  1.7.2.2  bouyer 
    143  1.7.2.2  bouyer static void sunos32_sigvec_to_sigaction(const struct netbsd32_sigvec *, struct sigaction *);
    144  1.7.2.2  bouyer static void sunos32_sigvec_from_sigaction(struct netbsd32_sigvec *, const struct sigaction *);
    145  1.7.2.2  bouyer 
    146  1.7.2.2  bouyer static int sunstatfs __P((struct statfs *, caddr_t));
    147  1.7.2.2  bouyer 
    148  1.7.2.2  bouyer static void
    149  1.7.2.2  bouyer sunos32_sigvec_to_sigaction(sv, sa)
    150  1.7.2.2  bouyer 	const struct netbsd32_sigvec *sv;
    151  1.7.2.2  bouyer 	struct sigaction *sa;
    152  1.7.2.2  bouyer {
    153  1.7.2.2  bouyer /*XXX*/ extern void compat_43_sigmask_to_sigset __P((const int *, sigset_t *));
    154  1.7.2.2  bouyer 
    155  1.7.2.2  bouyer 	sa->sa_handler = (void *)(u_long)sv->sv_handler;
    156  1.7.2.2  bouyer 	compat_43_sigmask_to_sigset(&sv->sv_mask, &sa->sa_mask);
    157  1.7.2.2  bouyer 	sa->sa_flags = sv->sv_flags ^ SA_RESTART;
    158  1.7.2.2  bouyer }
    159  1.7.2.2  bouyer 
    160  1.7.2.2  bouyer static
    161  1.7.2.2  bouyer void sunos32_sigvec_from_sigaction(sv, sa)
    162  1.7.2.2  bouyer 	struct netbsd32_sigvec *sv;
    163  1.7.2.2  bouyer 	const struct sigaction *sa;
    164  1.7.2.2  bouyer {
    165  1.7.2.2  bouyer /*XXX*/ extern void compat_43_sigset_to_sigmask __P((const sigset_t *, int *));
    166  1.7.2.2  bouyer 
    167  1.7.2.2  bouyer 	sv->sv_handler = (netbsd32_voidp)(u_long)sa->sa_handler;
    168  1.7.2.2  bouyer 	compat_43_sigset_to_sigmask(&sa->sa_mask, &sv->sv_mask);
    169  1.7.2.2  bouyer 	sv->sv_flags = sa->sa_flags ^ SA_RESTART;
    170  1.7.2.2  bouyer }
    171  1.7.2.2  bouyer 
    172  1.7.2.2  bouyer int
    173  1.7.2.2  bouyer sunos32_sys_stime(p, v, retval)
    174  1.7.2.2  bouyer 	struct proc *p;
    175  1.7.2.2  bouyer 	void *v;
    176  1.7.2.2  bouyer 	register_t *retval;
    177  1.7.2.2  bouyer {
    178  1.7.2.2  bouyer 	struct sunos32_sys_stime_args /* {
    179  1.7.2.2  bouyer 		syscallarg(sunos32_time_tp) tp;
    180  1.7.2.2  bouyer 	} */ *uap = v;
    181  1.7.2.2  bouyer 	struct sys_settimeofday_args ap;
    182  1.7.2.2  bouyer 	caddr_t sg = stackgap_init(p->p_emul);
    183  1.7.2.2  bouyer 	struct netbsd32_timeval ntv;
    184  1.7.2.2  bouyer 	struct timeval tv, *sgtvp;
    185  1.7.2.2  bouyer 	int error;
    186  1.7.2.2  bouyer 
    187  1.7.2.2  bouyer 	error = copyin((caddr_t)(u_long)SCARG(uap, tp), &ntv.tv_sec, sizeof(ntv.tv_sec));
    188  1.7.2.2  bouyer 	if (error)
    189  1.7.2.2  bouyer 		return error;
    190  1.7.2.2  bouyer 	tv.tv_sec = ntv.tv_sec;
    191  1.7.2.2  bouyer 	tv.tv_usec = 0;
    192  1.7.2.2  bouyer 
    193  1.7.2.2  bouyer 	SCARG(&ap, tv) = sgtvp = stackgap_alloc(&sg, sizeof(struct timeval));
    194  1.7.2.2  bouyer 	SCARG(&ap, tzp) = NULL;
    195  1.7.2.2  bouyer 
    196  1.7.2.2  bouyer 	error = copyout(&tv, sgtvp, sizeof(struct timeval));
    197  1.7.2.2  bouyer 	if (error)
    198  1.7.2.2  bouyer 		return error;
    199  1.7.2.2  bouyer 
    200  1.7.2.2  bouyer 	return sys_settimeofday(p, &ap, retval);
    201  1.7.2.2  bouyer }
    202  1.7.2.2  bouyer 
    203  1.7.2.2  bouyer int
    204  1.7.2.2  bouyer sunos32_sys_wait4(p, v, retval)
    205  1.7.2.2  bouyer 	struct proc *p;
    206  1.7.2.2  bouyer 	void *v;
    207  1.7.2.2  bouyer 	register_t *retval;
    208  1.7.2.2  bouyer {
    209  1.7.2.2  bouyer 	struct sunos32_sys_wait4_args /* {
    210  1.7.2.2  bouyer 		syscallarg(int) pid;
    211  1.7.2.2  bouyer 		syscallarg(netbsd32_intp) status;
    212  1.7.2.2  bouyer 		syscallarg(int) options;
    213  1.7.2.2  bouyer 		syscallarg(netbsd32_rusagep_t) rusage;
    214  1.7.2.2  bouyer 	} */ *uap = v;
    215  1.7.2.2  bouyer 
    216  1.7.2.2  bouyer 	if (SCARG(uap, pid) == 0)
    217  1.7.2.2  bouyer 		SCARG(uap, pid) = WAIT_ANY;
    218  1.7.2.2  bouyer 	return (netbsd32_wait4(p, uap, retval));
    219  1.7.2.2  bouyer }
    220  1.7.2.2  bouyer 
    221  1.7.2.2  bouyer int
    222  1.7.2.2  bouyer sunos32_sys_creat(p, v, retval)
    223  1.7.2.2  bouyer 	struct proc *p;
    224  1.7.2.2  bouyer 	void *v;
    225  1.7.2.2  bouyer 	register_t *retval;
    226  1.7.2.2  bouyer {
    227  1.7.2.2  bouyer 	struct sunos32_sys_creat_args /* {
    228  1.7.2.2  bouyer 		syscallarg(const netbsd32_charp) path;
    229  1.7.2.2  bouyer 		syscallarg(int) mode;
    230  1.7.2.2  bouyer 	} */ *uap = v;
    231  1.7.2.2  bouyer 	struct sys_open_args ua;
    232  1.7.2.2  bouyer 	caddr_t sg = stackgap_init(p->p_emul);
    233  1.7.2.2  bouyer 
    234  1.7.2.2  bouyer 	SUNOS32TOP_UAP(path, const char);
    235  1.7.2.2  bouyer 	SCARG(&ua, flags) = O_WRONLY | O_CREAT | O_TRUNC;
    236  1.7.2.2  bouyer 	SUNOS32TO64_UAP(mode);
    237  1.7.2.2  bouyer 
    238  1.7.2.2  bouyer 	SUNOS32_CHECK_ALT_CREAT(p, &sg, SCARG(&ua, path));
    239  1.7.2.2  bouyer 
    240  1.7.2.2  bouyer 	return (sys_open(p, &ua, retval));
    241  1.7.2.2  bouyer }
    242  1.7.2.2  bouyer 
    243  1.7.2.2  bouyer int
    244  1.7.2.2  bouyer sunos32_sys_access(p, v, retval)
    245  1.7.2.2  bouyer 	struct proc *p;
    246  1.7.2.2  bouyer 	void *v;
    247  1.7.2.2  bouyer 	register_t *retval;
    248  1.7.2.2  bouyer {
    249  1.7.2.2  bouyer 	struct sunos32_sys_access_args /* {
    250  1.7.2.2  bouyer 		syscallarg(const netbsd32_charp) path;
    251  1.7.2.2  bouyer 		syscallarg(int) flags;
    252  1.7.2.2  bouyer 	} */ *uap = v;
    253  1.7.2.2  bouyer 	struct sys_access_args ua;
    254  1.7.2.2  bouyer 	caddr_t sg = stackgap_init(p->p_emul);
    255  1.7.2.2  bouyer 
    256  1.7.2.2  bouyer 	SUNOS32TOP_UAP(path, const char);
    257  1.7.2.2  bouyer 	SUNOS32TO64_UAP(flags);
    258  1.7.2.2  bouyer 	SUNOS32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
    259  1.7.2.2  bouyer 
    260  1.7.2.2  bouyer 	return (sys_access(p, &ua, retval));
    261  1.7.2.2  bouyer }
    262  1.7.2.2  bouyer 
    263  1.7.2.2  bouyer static __inline void sunos32_from___stat13 __P((struct stat *, struct netbsd32_stat43 *));
    264  1.7.2.2  bouyer 
    265  1.7.2.2  bouyer static __inline void
    266  1.7.2.2  bouyer sunos32_from___stat13(sbp, sb32p)
    267  1.7.2.2  bouyer 	struct stat *sbp;
    268  1.7.2.2  bouyer 	struct netbsd32_stat43 *sb32p;
    269  1.7.2.2  bouyer {
    270  1.7.2.2  bouyer 	sb32p->st_dev = sbp->st_dev;
    271  1.7.2.2  bouyer 	sb32p->st_ino = sbp->st_ino;
    272  1.7.2.2  bouyer 	sb32p->st_mode = sbp->st_mode;
    273  1.7.2.2  bouyer 	sb32p->st_nlink = sbp->st_nlink;
    274  1.7.2.2  bouyer 	sb32p->st_uid = sbp->st_uid;
    275  1.7.2.2  bouyer 	sb32p->st_gid = sbp->st_gid;
    276  1.7.2.2  bouyer 	sb32p->st_rdev = sbp->st_rdev;
    277  1.7.2.2  bouyer 	if (sbp->st_size < (quad_t)1 << 32)
    278  1.7.2.2  bouyer 		sb32p->st_size = sbp->st_size;
    279  1.7.2.2  bouyer 	else
    280  1.7.2.2  bouyer 		sb32p->st_size = -2;
    281  1.7.2.2  bouyer 	sb32p->st_atimespec.tv_sec = (netbsd32_time_t)sbp->st_atimespec.tv_sec;
    282  1.7.2.2  bouyer 	sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec;
    283  1.7.2.2  bouyer 	sb32p->st_mtimespec.tv_sec = (netbsd32_time_t)sbp->st_mtimespec.tv_sec;
    284  1.7.2.2  bouyer 	sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec;
    285  1.7.2.2  bouyer 	sb32p->st_ctimespec.tv_sec = (netbsd32_time_t)sbp->st_ctimespec.tv_sec;
    286  1.7.2.2  bouyer 	sb32p->st_ctimespec.tv_nsec = (netbsd32_long)sbp->st_ctimespec.tv_nsec;
    287  1.7.2.2  bouyer 	sb32p->st_blksize = sbp->st_blksize;
    288  1.7.2.2  bouyer 	sb32p->st_blocks = sbp->st_blocks;
    289  1.7.2.2  bouyer 	sb32p->st_flags = sbp->st_flags;
    290  1.7.2.2  bouyer 	sb32p->st_gen = sbp->st_gen;
    291  1.7.2.2  bouyer }
    292  1.7.2.2  bouyer 
    293  1.7.2.2  bouyer 
    294  1.7.2.2  bouyer int
    295  1.7.2.2  bouyer sunos32_sys_stat(p, v, retval)
    296  1.7.2.2  bouyer 	struct proc *p;
    297  1.7.2.2  bouyer 	void *v;
    298  1.7.2.2  bouyer 	register_t *retval;
    299  1.7.2.2  bouyer {
    300  1.7.2.2  bouyer 	struct sunos32_sys_stat_args /* {
    301  1.7.2.2  bouyer 		syscallarg(const netbsd32_charp) path;
    302  1.7.2.2  bouyer 		syscallarg(netbsd32_stat43p_t) ub;
    303  1.7.2.2  bouyer 	} */ *uap = v;
    304  1.7.2.2  bouyer 	struct netbsd32_stat43 sb32;
    305  1.7.2.2  bouyer 	struct stat sb;
    306  1.7.2.2  bouyer 	struct nameidata nd;
    307  1.7.2.2  bouyer 	caddr_t sg;
    308  1.7.2.2  bouyer 	const char *path;
    309  1.7.2.2  bouyer 	int error;
    310  1.7.2.2  bouyer 
    311  1.7.2.2  bouyer 	path = (char *)(u_long)SCARG(uap, path);
    312  1.7.2.2  bouyer 	sg = stackgap_init(p->p_emul);
    313  1.7.2.2  bouyer 	SUNOS32_CHECK_ALT_EXIST(p, &sg, path);
    314  1.7.2.2  bouyer 
    315  1.7.2.2  bouyer 	NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, path, p);
    316  1.7.2.2  bouyer 	if ((error = namei(&nd)) != 0)
    317  1.7.2.2  bouyer 		return (error);
    318  1.7.2.2  bouyer 	error = vn_stat(nd.ni_vp, &sb, p);
    319  1.7.2.2  bouyer 	vput(nd.ni_vp);
    320  1.7.2.2  bouyer 	if (error)
    321  1.7.2.2  bouyer 		return (error);
    322  1.7.2.2  bouyer 	sunos32_from___stat13(&sb, &sb32);
    323  1.7.2.2  bouyer 	error = copyout((caddr_t)&sb32, (caddr_t)(u_long)SCARG(uap, ub), sizeof (sb32));
    324  1.7.2.2  bouyer 	return (error);
    325  1.7.2.2  bouyer }
    326  1.7.2.2  bouyer 
    327  1.7.2.2  bouyer int
    328  1.7.2.2  bouyer sunos32_sys_lstat(p, v, retval)
    329  1.7.2.2  bouyer 	struct proc *p;
    330  1.7.2.2  bouyer 	void *v;
    331  1.7.2.2  bouyer 	register_t *retval;
    332  1.7.2.2  bouyer {
    333  1.7.2.2  bouyer 	struct sunos32_sys_lstat_args /* {
    334  1.7.2.2  bouyer 		syscallarg(const netbsd32_charp) path;
    335  1.7.2.2  bouyer 		syscallarg(netbsd32_stat43p_t) ub;
    336  1.7.2.2  bouyer 	} */ *uap = v;
    337  1.7.2.2  bouyer 	struct vnode *vp, *dvp;
    338  1.7.2.2  bouyer 	struct stat sb, sb1;
    339  1.7.2.2  bouyer 	struct netbsd32_stat43 sb32;
    340  1.7.2.2  bouyer 	int error;
    341  1.7.2.2  bouyer 	struct nameidata nd;
    342  1.7.2.2  bouyer 	int ndflags;
    343  1.7.2.2  bouyer 	const char *path;
    344  1.7.2.2  bouyer 	caddr_t sg;
    345  1.7.2.2  bouyer 
    346  1.7.2.2  bouyer 	path = (char *)(u_long)SCARG(uap, path);
    347  1.7.2.2  bouyer 	sg = stackgap_init(p->p_emul);
    348  1.7.2.2  bouyer 	SUNOS32_CHECK_ALT_EXIST(p, &sg, path);
    349  1.7.2.2  bouyer 
    350  1.7.2.2  bouyer 	ndflags = NOFOLLOW | LOCKLEAF | LOCKPARENT;
    351  1.7.2.2  bouyer again:
    352  1.7.2.2  bouyer 	NDINIT(&nd, LOOKUP, ndflags, UIO_USERSPACE, path, p);
    353  1.7.2.2  bouyer 	if ((error = namei(&nd))) {
    354  1.7.2.2  bouyer 		if (error == EISDIR && (ndflags & LOCKPARENT) != 0) {
    355  1.7.2.2  bouyer 			/*
    356  1.7.2.2  bouyer 			 * Should only happen on '/'. Retry without LOCKPARENT;
    357  1.7.2.2  bouyer 			 * this is safe since the vnode won't be a VLNK.
    358  1.7.2.2  bouyer 			 */
    359  1.7.2.2  bouyer 			ndflags &= ~LOCKPARENT;
    360  1.7.2.2  bouyer 			goto again;
    361  1.7.2.2  bouyer 		}
    362  1.7.2.2  bouyer 		return (error);
    363  1.7.2.2  bouyer 	}
    364  1.7.2.2  bouyer 	/*
    365  1.7.2.2  bouyer 	 * For symbolic links, always return the attributes of its
    366  1.7.2.2  bouyer 	 * containing directory, except for mode, size, and links.
    367  1.7.2.2  bouyer 	 */
    368  1.7.2.2  bouyer 	vp = nd.ni_vp;
    369  1.7.2.2  bouyer 	dvp = nd.ni_dvp;
    370  1.7.2.2  bouyer 	if (vp->v_type != VLNK) {
    371  1.7.2.2  bouyer 		if ((ndflags & LOCKPARENT) != 0) {
    372  1.7.2.2  bouyer 			if (dvp == vp)
    373  1.7.2.2  bouyer 				vrele(dvp);
    374  1.7.2.2  bouyer 			else
    375  1.7.2.2  bouyer 				vput(dvp);
    376  1.7.2.2  bouyer 		}
    377  1.7.2.2  bouyer 		error = vn_stat(vp, &sb, p);
    378  1.7.2.2  bouyer 		vput(vp);
    379  1.7.2.2  bouyer 		if (error)
    380  1.7.2.2  bouyer 			return (error);
    381  1.7.2.2  bouyer 	} else {
    382  1.7.2.2  bouyer 		error = vn_stat(dvp, &sb, p);
    383  1.7.2.2  bouyer 		vput(dvp);
    384  1.7.2.2  bouyer 		if (error) {
    385  1.7.2.2  bouyer 			vput(vp);
    386  1.7.2.2  bouyer 			return (error);
    387  1.7.2.2  bouyer 		}
    388  1.7.2.2  bouyer 		error = vn_stat(vp, &sb1, p);
    389  1.7.2.2  bouyer 		vput(vp);
    390  1.7.2.2  bouyer 		if (error)
    391  1.7.2.2  bouyer 			return (error);
    392  1.7.2.2  bouyer 		sb.st_mode &= ~S_IFDIR;
    393  1.7.2.2  bouyer 		sb.st_mode |= S_IFLNK;
    394  1.7.2.2  bouyer 		sb.st_nlink = sb1.st_nlink;
    395  1.7.2.2  bouyer 		sb.st_size = sb1.st_size;
    396  1.7.2.2  bouyer 		sb.st_blocks = sb1.st_blocks;
    397  1.7.2.2  bouyer 	}
    398  1.7.2.2  bouyer 	sunos32_from___stat13(&sb, &sb32);
    399  1.7.2.2  bouyer 	error = copyout((caddr_t)&sb32, (caddr_t)(u_long)SCARG(uap, ub), sizeof (sb32));
    400  1.7.2.2  bouyer 	return (error);
    401  1.7.2.2  bouyer }
    402  1.7.2.2  bouyer 
    403  1.7.2.2  bouyer int
    404  1.7.2.2  bouyer sunos32_sys_execv(p, v, retval)
    405  1.7.2.2  bouyer 	struct proc *p;
    406  1.7.2.2  bouyer 	void *v;
    407  1.7.2.2  bouyer 	register_t *retval;
    408  1.7.2.2  bouyer {
    409  1.7.2.2  bouyer 	struct sunos32_sys_execv_args /* {
    410  1.7.2.2  bouyer 		syscallarg(const char *) path;
    411  1.7.2.2  bouyer 		syscallarg(char **) argv;
    412  1.7.2.2  bouyer 	} */ *uap = v;
    413  1.7.2.2  bouyer 	struct sys_execve_args ua;
    414  1.7.2.2  bouyer 	caddr_t sg;
    415  1.7.2.2  bouyer 
    416  1.7.2.2  bouyer 	SUNOS32TOP_UAP(path, const char);
    417  1.7.2.2  bouyer 	SUNOS32TOP_UAP(argp, char *);
    418  1.7.2.2  bouyer 	SCARG(&ua, envp) = NULL;
    419  1.7.2.2  bouyer 	sg = stackgap_init(p->p_emul);
    420  1.7.2.2  bouyer 	SUNOS32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
    421  1.7.2.2  bouyer 
    422  1.7.2.2  bouyer 	return netbsd32_execve2(p, &ua, retval);
    423  1.7.2.2  bouyer }
    424  1.7.2.2  bouyer 
    425  1.7.2.2  bouyer int
    426  1.7.2.2  bouyer sunos32_sys_execve(p, v, retval)
    427  1.7.2.2  bouyer 	struct proc *p;
    428  1.7.2.2  bouyer 	void *v;
    429  1.7.2.2  bouyer 	register_t *retval;
    430  1.7.2.2  bouyer {
    431  1.7.2.2  bouyer 	struct sunos32_sys_execve_args /* {
    432  1.7.2.2  bouyer 		syscallarg(const char *) path;
    433  1.7.2.2  bouyer 		syscallarg(char **) argv;
    434  1.7.2.2  bouyer 		syscallarg(char **) envp;
    435  1.7.2.2  bouyer 	} */ *uap = v;
    436  1.7.2.2  bouyer 	struct sys_execve_args ua;
    437  1.7.2.2  bouyer 	caddr_t sg;
    438  1.7.2.2  bouyer 
    439  1.7.2.2  bouyer 	SUNOS32TOP_UAP(path, const char);
    440  1.7.2.2  bouyer 	SUNOS32TOP_UAP(argp, char *);
    441  1.7.2.2  bouyer 	SUNOS32TOP_UAP(envp, char *);
    442  1.7.2.2  bouyer 	sg = stackgap_init(p->p_emul);
    443  1.7.2.2  bouyer 	SUNOS32_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    444  1.7.2.2  bouyer 
    445  1.7.2.2  bouyer 	return netbsd32_execve2(p, &ua, retval);
    446  1.7.2.2  bouyer }
    447  1.7.2.2  bouyer 
    448  1.7.2.2  bouyer int
    449  1.7.2.2  bouyer sunos32_sys_omsync(p, v, retval)
    450  1.7.2.2  bouyer 	struct proc *p;
    451  1.7.2.2  bouyer 	void *v;
    452  1.7.2.2  bouyer 	register_t *retval;
    453  1.7.2.2  bouyer {
    454  1.7.2.2  bouyer 	struct sunos32_sys_omsync_args /* {
    455  1.7.2.2  bouyer 		syscallarg(netbsd32_caddr_t) addr;
    456  1.7.2.2  bouyer 		syscallarg(netbsd32_size_t) len;
    457  1.7.2.2  bouyer 		syscallarg(int) flags;
    458  1.7.2.2  bouyer 	} */ *uap = v;
    459  1.7.2.2  bouyer 	struct netbsd32___msync13_args ouap;
    460  1.7.2.2  bouyer 
    461  1.7.2.2  bouyer 	SCARG(&ouap, addr) = SCARG(uap, addr);
    462  1.7.2.2  bouyer 	SCARG(&ouap, len) = SCARG(uap, len);
    463  1.7.2.2  bouyer 	SCARG(&ouap, flags) = SCARG(uap, flags);
    464  1.7.2.2  bouyer 
    465  1.7.2.2  bouyer 	return (netbsd32___msync13(p, &ouap, retval));
    466  1.7.2.2  bouyer }
    467  1.7.2.2  bouyer 
    468  1.7.2.2  bouyer int
    469  1.7.2.2  bouyer sunos32_sys_unmount(p, v, retval)
    470  1.7.2.2  bouyer 	struct proc *p;
    471  1.7.2.2  bouyer 	void *v;
    472  1.7.2.2  bouyer 	register_t *retval;
    473  1.7.2.2  bouyer {
    474  1.7.2.2  bouyer 	struct sunos32_sys_unmount_args /* {
    475  1.7.2.2  bouyer 		syscallarg(netbsd32_charp) path;
    476  1.7.2.2  bouyer 	} */ *uap = v;
    477  1.7.2.2  bouyer 	struct sys_unmount_args ua;
    478  1.7.2.2  bouyer 
    479  1.7.2.2  bouyer 	SUNOS32TOP_UAP(path, const char);
    480  1.7.2.2  bouyer 	SCARG(&ua, flags) = 0;
    481  1.7.2.2  bouyer 
    482  1.7.2.2  bouyer 	return (sys_unmount(p, &ua, retval));
    483  1.7.2.2  bouyer }
    484  1.7.2.2  bouyer 
    485  1.7.2.2  bouyer /*
    486  1.7.2.2  bouyer  * Conversion table for SunOS NFS mount flags.
    487  1.7.2.2  bouyer  */
    488  1.7.2.2  bouyer static struct {
    489  1.7.2.2  bouyer 	int	sun_flg;
    490  1.7.2.2  bouyer 	int	bsd_flg;
    491  1.7.2.2  bouyer } sunnfs_flgtab[] = {
    492  1.7.2.2  bouyer 	{ SUNNFS_SOFT,		NFSMNT_SOFT },
    493  1.7.2.2  bouyer 	{ SUNNFS_WSIZE,		NFSMNT_WSIZE },
    494  1.7.2.2  bouyer 	{ SUNNFS_RSIZE,		NFSMNT_RSIZE },
    495  1.7.2.2  bouyer 	{ SUNNFS_TIMEO,		NFSMNT_TIMEO },
    496  1.7.2.2  bouyer 	{ SUNNFS_RETRANS,	NFSMNT_RETRANS },
    497  1.7.2.2  bouyer 	{ SUNNFS_HOSTNAME,	0 },			/* Ignored */
    498  1.7.2.2  bouyer 	{ SUNNFS_INT,		NFSMNT_INT },
    499  1.7.2.2  bouyer 	{ SUNNFS_NOAC,		0 },			/* Ignored */
    500  1.7.2.2  bouyer 	{ SUNNFS_ACREGMIN,	0 },			/* Ignored */
    501  1.7.2.2  bouyer 	{ SUNNFS_ACREGMAX,	0 },			/* Ignored */
    502  1.7.2.2  bouyer 	{ SUNNFS_ACDIRMIN,	0 },			/* Ignored */
    503  1.7.2.2  bouyer 	{ SUNNFS_ACDIRMAX,	0 },			/* Ignored */
    504  1.7.2.2  bouyer 	{ SUNNFS_SECURE,	0 },			/* Ignored */
    505  1.7.2.2  bouyer 	{ SUNNFS_NOCTO,		0 },			/* Ignored */
    506  1.7.2.2  bouyer 	{ SUNNFS_POSIX,		0 }			/* Ignored */
    507  1.7.2.2  bouyer };
    508  1.7.2.2  bouyer 
    509  1.7.2.2  bouyer int
    510  1.7.2.2  bouyer sunos32_sys_mount(p, v, retval)
    511  1.7.2.2  bouyer 	struct proc *p;
    512  1.7.2.2  bouyer 	void *v;
    513  1.7.2.2  bouyer 	register_t *retval;
    514  1.7.2.2  bouyer {
    515  1.7.2.2  bouyer 	struct sunos32_sys_mount_args /* {
    516  1.7.2.2  bouyer 		syscallarg(netbsd32_charp) type;
    517  1.7.2.2  bouyer 		syscallarg(netbsd32_charp) path;
    518  1.7.2.2  bouyer 		syscallarg(int) flags;
    519  1.7.2.2  bouyer 		syscallarg(netbsd32_caddr_t) data;
    520  1.7.2.2  bouyer 	} */ *uap = v;
    521  1.7.2.2  bouyer 	struct sys_mount_args ua;
    522  1.7.2.2  bouyer 	int oflags = SCARG(uap, flags), nflags, error;
    523  1.7.2.2  bouyer 	char fsname[MFSNAMELEN];
    524  1.7.2.2  bouyer 	caddr_t sg = stackgap_init(p->p_emul);
    525  1.7.2.2  bouyer 
    526  1.7.2.2  bouyer 	if (oflags & (SUNM_NOSUB | SUNM_SYS5))
    527  1.7.2.2  bouyer 		return (EINVAL);
    528  1.7.2.2  bouyer 	if ((oflags & SUNM_NEWTYPE) == 0)
    529  1.7.2.2  bouyer 		return (EINVAL);
    530  1.7.2.2  bouyer 	nflags = 0;
    531  1.7.2.2  bouyer 	if (oflags & SUNM_RDONLY)
    532  1.7.2.2  bouyer 		nflags |= MNT_RDONLY;
    533  1.7.2.2  bouyer 	if (oflags & SUNM_NOSUID)
    534  1.7.2.2  bouyer 		nflags |= MNT_NOSUID;
    535  1.7.2.2  bouyer 	if (oflags & SUNM_REMOUNT)
    536  1.7.2.2  bouyer 		nflags |= MNT_UPDATE;
    537  1.7.2.2  bouyer 	SCARG(uap, flags) = nflags;
    538  1.7.2.2  bouyer 
    539  1.7.2.2  bouyer 	error = copyinstr((caddr_t)(u_long)SCARG(uap, type), fsname,
    540  1.7.2.2  bouyer 	    sizeof fsname, (size_t *)0);
    541  1.7.2.2  bouyer 	if (error)
    542  1.7.2.2  bouyer 		return (error);
    543  1.7.2.2  bouyer 
    544  1.7.2.2  bouyer 	if (strncmp(fsname, "4.2", sizeof fsname) == 0) {
    545  1.7.2.2  bouyer 		SCARG(uap, type) = (netbsd32_charp)(u_long)stackgap_alloc(&sg, sizeof("ffs"));
    546  1.7.2.2  bouyer 		error = copyout("ffs", (caddr_t)(u_long)SCARG(uap, type), sizeof("ffs"));
    547  1.7.2.2  bouyer 		if (error)
    548  1.7.2.2  bouyer 			return (error);
    549  1.7.2.2  bouyer 	} else if (strncmp(fsname, "nfs", sizeof fsname) == 0) {
    550  1.7.2.2  bouyer 		struct sunos_nfs_args sna;
    551  1.7.2.2  bouyer 		struct sockaddr_in sain;
    552  1.7.2.2  bouyer 		struct nfs_args na;	/* XXX */
    553  1.7.2.2  bouyer 		struct sockaddr sa;
    554  1.7.2.2  bouyer 		int n;
    555  1.7.2.2  bouyer 
    556  1.7.2.2  bouyer 		error = copyin((caddr_t)(u_long)SCARG(uap, data), &sna, sizeof sna);
    557  1.7.2.2  bouyer 		if (error)
    558  1.7.2.2  bouyer 			return (error);
    559  1.7.2.2  bouyer 		error = copyin(sna.addr, &sain, sizeof sain);
    560  1.7.2.2  bouyer 		if (error)
    561  1.7.2.2  bouyer 			return (error);
    562  1.7.2.2  bouyer 		memcpy(&sa, &sain, sizeof sa);
    563  1.7.2.2  bouyer 		sa.sa_len = sizeof(sain);
    564  1.7.2.2  bouyer 		SCARG(uap, data) = (netbsd32_charp)(u_long)stackgap_alloc(&sg, sizeof(na));
    565  1.7.2.2  bouyer 		na.version = NFS_ARGSVERSION;
    566  1.7.2.2  bouyer 		na.addr = stackgap_alloc(&sg, sizeof(struct sockaddr));
    567  1.7.2.2  bouyer 		na.addrlen = sizeof(struct sockaddr);
    568  1.7.2.2  bouyer 		na.sotype = SOCK_DGRAM;
    569  1.7.2.2  bouyer 		na.proto = IPPROTO_UDP;
    570  1.7.2.2  bouyer 		na.fh = (void *)sna.fh;
    571  1.7.2.2  bouyer 		na.fhsize = NFSX_V2FH;
    572  1.7.2.2  bouyer 		na.flags = 0;
    573  1.7.2.2  bouyer 		n = sizeof(sunnfs_flgtab) / sizeof(sunnfs_flgtab[0]);
    574  1.7.2.2  bouyer 		while (--n >= 0)
    575  1.7.2.2  bouyer 			if (sna.flags & sunnfs_flgtab[n].sun_flg)
    576  1.7.2.2  bouyer 				na.flags |= sunnfs_flgtab[n].bsd_flg;
    577  1.7.2.2  bouyer 		na.wsize = sna.wsize;
    578  1.7.2.2  bouyer 		na.rsize = sna.rsize;
    579  1.7.2.2  bouyer 		if (na.flags & NFSMNT_RSIZE) {
    580  1.7.2.2  bouyer 			na.flags |= NFSMNT_READDIRSIZE;
    581  1.7.2.2  bouyer 			na.readdirsize = na.rsize;
    582  1.7.2.2  bouyer 		}
    583  1.7.2.2  bouyer 		na.timeo = sna.timeo;
    584  1.7.2.2  bouyer 		na.retrans = sna.retrans;
    585  1.7.2.2  bouyer 		na.hostname = (char *)(u_long)sna.hostname;
    586  1.7.2.2  bouyer 
    587  1.7.2.2  bouyer 		error = copyout(&sa, na.addr, sizeof sa);
    588  1.7.2.2  bouyer 		if (error)
    589  1.7.2.2  bouyer 			return (error);
    590  1.7.2.2  bouyer 		error = copyout(&na, (caddr_t)(u_long)SCARG(uap, data), sizeof na);
    591  1.7.2.2  bouyer 		if (error)
    592  1.7.2.2  bouyer 			return (error);
    593  1.7.2.2  bouyer 	}
    594  1.7.2.2  bouyer 	SUNOS32TOP_UAP(type, const char);
    595  1.7.2.2  bouyer 	SUNOS32TOP_UAP(path, const char);
    596  1.7.2.2  bouyer 	SUNOS32TO64_UAP(flags);
    597  1.7.2.2  bouyer 	SUNOS32TOP_UAP(data, void);
    598  1.7.2.2  bouyer 	return (sys_mount(p, &ua, retval));
    599  1.7.2.2  bouyer }
    600  1.7.2.2  bouyer 
    601  1.7.2.2  bouyer #if defined(NFS)
    602  1.7.2.2  bouyer int
    603  1.7.2.2  bouyer async_daemon(p, v, retval)
    604  1.7.2.2  bouyer 	struct proc *p;
    605  1.7.2.2  bouyer 	void *v;
    606  1.7.2.2  bouyer 	register_t *retval;
    607  1.7.2.2  bouyer {
    608  1.7.2.2  bouyer 	struct netbsd32_nfssvc_args ouap;
    609  1.7.2.2  bouyer 
    610  1.7.2.2  bouyer 	SCARG(&ouap, flag) = NFSSVC_BIOD;
    611  1.7.2.2  bouyer 	SCARG(&ouap, argp) = NULL;
    612  1.7.2.2  bouyer 
    613  1.7.2.2  bouyer 	return (netbsd32_nfssvc(p, &ouap, retval));
    614  1.7.2.2  bouyer }
    615  1.7.2.2  bouyer #endif /* NFS */
    616  1.7.2.2  bouyer 
    617  1.7.2.2  bouyer void	native_to_sunos_sigset __P((const sigset_t *, int *));
    618  1.7.2.2  bouyer void	sunos_to_native_sigset __P((const int, sigset_t *));
    619  1.7.2.2  bouyer 
    620  1.7.2.2  bouyer __inline__ void
    621  1.7.2.2  bouyer native_to_sunos_sigset(ss, mask)
    622  1.7.2.2  bouyer 	const sigset_t *ss;
    623  1.7.2.2  bouyer 	int *mask;
    624  1.7.2.2  bouyer {
    625  1.7.2.2  bouyer 	*mask = ss->__bits[0];
    626  1.7.2.2  bouyer }
    627  1.7.2.2  bouyer 
    628  1.7.2.2  bouyer __inline__ void
    629  1.7.2.2  bouyer sunos_to_native_sigset(mask, ss)
    630  1.7.2.2  bouyer 	const int mask;
    631  1.7.2.2  bouyer 	sigset_t *ss;
    632  1.7.2.2  bouyer {
    633  1.7.2.2  bouyer 
    634  1.7.2.2  bouyer 	ss->__bits[0] = mask;
    635  1.7.2.2  bouyer 	ss->__bits[1] = 0;
    636  1.7.2.2  bouyer 	ss->__bits[2] = 0;
    637  1.7.2.2  bouyer 	ss->__bits[3] = 0;
    638  1.7.2.2  bouyer }
    639  1.7.2.2  bouyer 
    640  1.7.2.2  bouyer int
    641  1.7.2.2  bouyer sunos32_sys_sigpending(p, v, retval)
    642  1.7.2.2  bouyer 	struct proc *p;
    643  1.7.2.2  bouyer 	void *v;
    644  1.7.2.2  bouyer 	register_t *retval;
    645  1.7.2.2  bouyer {
    646  1.7.2.2  bouyer 	struct sunos32_sys_sigpending_args /* {
    647  1.7.2.2  bouyer 		syscallarg(netbsd32_intp) mask;
    648  1.7.2.2  bouyer 	} */ *uap = v;
    649  1.7.2.2  bouyer 	sigset_t ss;
    650  1.7.2.2  bouyer 	int mask;
    651  1.7.2.2  bouyer 
    652  1.7.2.2  bouyer 	sigpending1(p, &ss);
    653  1.7.2.2  bouyer 	native_to_sunos_sigset(&ss, &mask);
    654  1.7.2.2  bouyer 
    655  1.7.2.2  bouyer 	return (copyout((caddr_t)(u_long)&mask, (caddr_t)(u_long)SCARG(uap, mask), sizeof(int)));
    656  1.7.2.2  bouyer }
    657  1.7.2.2  bouyer 
    658  1.7.2.2  bouyer int
    659  1.7.2.2  bouyer sunos32_sys_sigsuspend(p, v, retval)
    660  1.7.2.2  bouyer 	struct proc *p;
    661  1.7.2.2  bouyer 	void *v;
    662  1.7.2.2  bouyer 	register_t *retval;
    663  1.7.2.2  bouyer {
    664  1.7.2.2  bouyer 	struct sunos32_sys_sigsuspend_args /* {
    665  1.7.2.2  bouyer 		syscallarg(int) mask;
    666  1.7.2.2  bouyer 	} */ *uap = v;
    667  1.7.2.2  bouyer 	int mask;
    668  1.7.2.2  bouyer 	sigset_t ss;
    669  1.7.2.2  bouyer 
    670  1.7.2.2  bouyer 	mask = SCARG(uap, mask);
    671  1.7.2.2  bouyer 	sunos_to_native_sigset(mask, &ss);
    672  1.7.2.2  bouyer 	return (sigsuspend1(p, &ss));
    673  1.7.2.2  bouyer }
    674  1.7.2.2  bouyer 
    675  1.7.2.2  bouyer /*
    676  1.7.2.2  bouyer  * Read Sun-style directory entries.  We suck them into kernel space so
    677  1.7.2.2  bouyer  * that they can be massaged before being copied out to user code.  Like
    678  1.7.2.2  bouyer  * SunOS, we squish out `empty' entries.
    679  1.7.2.2  bouyer  *
    680  1.7.2.2  bouyer  * This is quite ugly, but what do you expect from compatibility code?
    681  1.7.2.2  bouyer  */
    682  1.7.2.2  bouyer int
    683  1.7.2.2  bouyer sunos32_sys_getdents(p, v, retval)
    684  1.7.2.2  bouyer 	struct proc *p;
    685  1.7.2.2  bouyer 	void *v;
    686  1.7.2.2  bouyer 	register_t *retval;
    687  1.7.2.2  bouyer {
    688  1.7.2.2  bouyer 	struct sunos32_sys_getdents_args /* {
    689  1.7.2.2  bouyer 		syscallarg(int) fd;
    690  1.7.2.2  bouyer 		syscallarg(netbsd32_charp) buf;
    691  1.7.2.2  bouyer 		syscallarg(int) nbytes;
    692  1.7.2.2  bouyer 	} */ *uap = v;
    693  1.7.2.2  bouyer 	struct dirent *bdp;
    694  1.7.2.2  bouyer 	struct vnode *vp;
    695  1.7.2.2  bouyer 	caddr_t inp, buf;	/* BSD-format */
    696  1.7.2.2  bouyer 	int len, reclen;	/* BSD-format */
    697  1.7.2.2  bouyer 	caddr_t outp;		/* Sun-format */
    698  1.7.2.2  bouyer 	int resid, sunos_reclen;/* Sun-format */
    699  1.7.2.2  bouyer 	struct file *fp;
    700  1.7.2.2  bouyer 	struct uio auio;
    701  1.7.2.2  bouyer 	struct iovec aiov;
    702  1.7.2.2  bouyer 	struct sunos32_dirent idb;
    703  1.7.2.2  bouyer 	off_t off;			/* true file offset */
    704  1.7.2.2  bouyer 	int buflen, error, eofflag;
    705  1.7.2.2  bouyer 	off_t *cookiebuf, *cookie;
    706  1.7.2.2  bouyer 	int ncookies;
    707  1.7.2.2  bouyer 
    708  1.7.2.2  bouyer 	/* getvnode() will use the descriptor for us */
    709  1.7.2.2  bouyer 	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
    710  1.7.2.2  bouyer 		return (error);
    711  1.7.2.2  bouyer 
    712  1.7.2.2  bouyer 	if ((fp->f_flag & FREAD) == 0) {
    713  1.7.2.2  bouyer 		error = EBADF;
    714  1.7.2.2  bouyer 		goto out1;
    715  1.7.2.2  bouyer 	}
    716  1.7.2.2  bouyer 
    717  1.7.2.2  bouyer 	vp = (struct vnode *)fp->f_data;
    718  1.7.2.2  bouyer 	if (vp->v_type != VDIR) {
    719  1.7.2.2  bouyer 		error = EINVAL;
    720  1.7.2.2  bouyer 		goto out1;
    721  1.7.2.2  bouyer 	}
    722  1.7.2.2  bouyer 
    723  1.7.2.2  bouyer 	buflen = min(MAXBSIZE, SCARG(uap, nbytes));
    724  1.7.2.2  bouyer 	buf = malloc(buflen, M_TEMP, M_WAITOK);
    725  1.7.2.2  bouyer 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    726  1.7.2.2  bouyer 	off = fp->f_offset;
    727  1.7.2.2  bouyer again:
    728  1.7.2.2  bouyer 	aiov.iov_base = buf;
    729  1.7.2.2  bouyer 	aiov.iov_len = buflen;
    730  1.7.2.2  bouyer 	auio.uio_iov = &aiov;
    731  1.7.2.2  bouyer 	auio.uio_iovcnt = 1;
    732  1.7.2.2  bouyer 	auio.uio_rw = UIO_READ;
    733  1.7.2.2  bouyer 	auio.uio_segflg = UIO_SYSSPACE;
    734  1.7.2.2  bouyer 	auio.uio_procp = p;
    735  1.7.2.2  bouyer 	auio.uio_resid = buflen;
    736  1.7.2.2  bouyer 	auio.uio_offset = off;
    737  1.7.2.2  bouyer 	/*
    738  1.7.2.2  bouyer 	 * First we read into the malloc'ed buffer, then
    739  1.7.2.2  bouyer 	 * we massage it into user space, one record at a time.
    740  1.7.2.2  bouyer 	 */
    741  1.7.2.2  bouyer 	error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &cookiebuf,
    742  1.7.2.2  bouyer 	    &ncookies);
    743  1.7.2.2  bouyer 	if (error)
    744  1.7.2.2  bouyer 		goto out;
    745  1.7.2.2  bouyer 
    746  1.7.2.2  bouyer 	inp = buf;
    747  1.7.2.2  bouyer 	outp = (caddr_t)(u_long)SCARG(uap, buf);
    748  1.7.2.2  bouyer 	resid = SCARG(uap, nbytes);
    749  1.7.2.2  bouyer 	if ((len = buflen - auio.uio_resid) == 0)
    750  1.7.2.2  bouyer 		goto eof;
    751  1.7.2.2  bouyer 
    752  1.7.2.2  bouyer 	for (cookie = cookiebuf; len > 0; len -= reclen) {
    753  1.7.2.2  bouyer 		bdp = (struct dirent *)inp;
    754  1.7.2.2  bouyer 		reclen = bdp->d_reclen;
    755  1.7.2.2  bouyer 		if (reclen & 3)
    756  1.7.2.2  bouyer 			panic("sunos_getdents");
    757  1.7.2.2  bouyer 		if ((*cookie >> 32) != 0) {
    758  1.7.2.2  bouyer 			compat_offseterr(vp, "sunos_getdents");
    759  1.7.2.2  bouyer 			error = EINVAL;
    760  1.7.2.2  bouyer 			goto out;
    761  1.7.2.2  bouyer 		}
    762  1.7.2.2  bouyer 		if (bdp->d_fileno == 0) {
    763  1.7.2.2  bouyer 			inp += reclen;	/* it is a hole; squish it out */
    764  1.7.2.2  bouyer 			off = *cookie++;
    765  1.7.2.2  bouyer 			continue;
    766  1.7.2.2  bouyer 		}
    767  1.7.2.2  bouyer 		sunos_reclen = SUNOS32_RECLEN(&idb, bdp->d_namlen);
    768  1.7.2.2  bouyer 		if (reclen > len || resid < sunos_reclen) {
    769  1.7.2.2  bouyer 			/* entry too big for buffer, so just stop */
    770  1.7.2.2  bouyer 			outp++;
    771  1.7.2.2  bouyer 			break;
    772  1.7.2.2  bouyer 		}
    773  1.7.2.2  bouyer 		off = *cookie++;	/* each entry points to next */
    774  1.7.2.2  bouyer 		/*
    775  1.7.2.2  bouyer 		 * Massage in place to make a Sun-shaped dirent (otherwise
    776  1.7.2.2  bouyer 		 * we have to worry about touching user memory outside of
    777  1.7.2.2  bouyer 		 * the copyout() call).
    778  1.7.2.2  bouyer 		 */
    779  1.7.2.2  bouyer 		idb.d_fileno = bdp->d_fileno;
    780  1.7.2.2  bouyer 		idb.d_off = off;
    781  1.7.2.2  bouyer 		idb.d_reclen = sunos_reclen;
    782  1.7.2.2  bouyer 		idb.d_namlen = bdp->d_namlen;
    783  1.7.2.2  bouyer 		strcpy(idb.d_name, bdp->d_name);
    784  1.7.2.2  bouyer 		if ((error = copyout((caddr_t)&idb, outp, sunos_reclen)) != 0)
    785  1.7.2.2  bouyer 			goto out;
    786  1.7.2.2  bouyer 		/* advance past this real entry */
    787  1.7.2.2  bouyer 		inp += reclen;
    788  1.7.2.2  bouyer 		/* advance output past Sun-shaped entry */
    789  1.7.2.2  bouyer 		outp += sunos_reclen;
    790  1.7.2.2  bouyer 		resid -= sunos_reclen;
    791  1.7.2.2  bouyer 	}
    792  1.7.2.2  bouyer 
    793  1.7.2.2  bouyer 	/* if we squished out the whole block, try again */
    794  1.7.2.2  bouyer 	if (outp == (caddr_t)(u_long)SCARG(uap, buf))
    795  1.7.2.2  bouyer 		goto again;
    796  1.7.2.2  bouyer 	fp->f_offset = off;		/* update the vnode offset */
    797  1.7.2.2  bouyer 
    798  1.7.2.2  bouyer eof:
    799  1.7.2.2  bouyer 	*retval = SCARG(uap, nbytes) - resid;
    800  1.7.2.2  bouyer out:
    801  1.7.2.2  bouyer 	VOP_UNLOCK(vp, 0);
    802  1.7.2.2  bouyer 	free(cookiebuf, M_TEMP);
    803  1.7.2.2  bouyer 	free(buf, M_TEMP);
    804  1.7.2.2  bouyer  out1:
    805  1.7.2.2  bouyer 	FILE_UNUSE(fp, p);
    806  1.7.2.2  bouyer 	return (error);
    807  1.7.2.2  bouyer }
    808  1.7.2.2  bouyer 
    809  1.7.2.2  bouyer #define	SUNOS32__MAP_NEW	0x80000000	/* if not, old mmap & cannot handle */
    810  1.7.2.2  bouyer 
    811  1.7.2.2  bouyer int
    812  1.7.2.2  bouyer sunos32_sys_mmap(p, v, retval)
    813  1.7.2.2  bouyer 	struct proc *p;
    814  1.7.2.2  bouyer 	void *v;
    815  1.7.2.2  bouyer 	register_t *retval;
    816  1.7.2.2  bouyer {
    817  1.7.2.2  bouyer 	struct sunos32_sys_mmap_args /* {
    818  1.7.2.2  bouyer 		syscallarg(netbsd32_voidp) addr;
    819  1.7.2.2  bouyer 		syscallarg(netbsd32_size_t) len;
    820  1.7.2.2  bouyer 		syscallarg(int) prot;
    821  1.7.2.2  bouyer 		syscallarg(int) flags;
    822  1.7.2.2  bouyer 		syscallarg(int) fd;
    823  1.7.2.2  bouyer 		syscallarg(netbsd32_long) pos;
    824  1.7.2.2  bouyer 	} */ *uap = v;
    825  1.7.2.2  bouyer 	struct sys_mmap_args ua;
    826  1.7.2.2  bouyer 	struct filedesc *fdp;
    827  1.7.2.2  bouyer 	struct file *fp;
    828  1.7.2.2  bouyer 	struct vnode *vp;
    829  1.7.2.2  bouyer 	void *rt;
    830  1.7.2.2  bouyer 	int error;
    831  1.7.2.2  bouyer 
    832  1.7.2.2  bouyer 	/*
    833  1.7.2.2  bouyer 	 * Verify the arguments.
    834  1.7.2.2  bouyer 	 */
    835  1.7.2.2  bouyer 	if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
    836  1.7.2.2  bouyer 		return (EINVAL);			/* XXX still needed? */
    837  1.7.2.2  bouyer 
    838  1.7.2.2  bouyer 	if ((SCARG(uap, flags) & SUNOS32__MAP_NEW) == 0)
    839  1.7.2.2  bouyer 		return (EINVAL);
    840  1.7.2.2  bouyer 
    841  1.7.2.2  bouyer 	SUNOS32TOP_UAP(addr, void);
    842  1.7.2.2  bouyer 	SUNOS32TOX_UAP(len, size_t);
    843  1.7.2.2  bouyer 	SUNOS32TO64_UAP(prot);
    844  1.7.2.2  bouyer 	SCARG(&ua, flags) = SCARG(uap, flags) & ~SUNOS32__MAP_NEW;
    845  1.7.2.2  bouyer 	SUNOS32TO64_UAP(fd);
    846  1.7.2.2  bouyer 	SCARG(&ua, pad) = 0;
    847  1.7.2.2  bouyer 	SUNOS32TOX_UAP(pos, off_t);
    848  1.7.2.2  bouyer 
    849  1.7.2.2  bouyer 	if ((SCARG(&ua, flags) & MAP_FIXED) == 0 &&
    850  1.7.2.2  bouyer 	    SCARG(&ua, addr) != 0 &&
    851  1.7.2.2  bouyer 	    SCARG(&ua, addr) < (void *)round_page((vaddr_t)p->p_vmspace->vm_daddr+MAXDSIZ))
    852  1.7.2.2  bouyer 		SCARG(&ua, addr) = (void *)round_page((vaddr_t)p->p_vmspace->vm_daddr+MAXDSIZ);
    853  1.7.2.2  bouyer 
    854  1.7.2.2  bouyer 	/*
    855  1.7.2.2  bouyer 	 * Special case: if fd refers to /dev/zero, map as MAP_ANON.  (XXX)
    856  1.7.2.2  bouyer 	 */
    857  1.7.2.2  bouyer 	fdp = p->p_fd;
    858  1.7.2.2  bouyer 	if ((unsigned)SCARG(&ua, fd) < fdp->fd_nfiles &&		/*XXX*/
    859  1.7.2.2  bouyer 	    (fp = fdp->fd_ofiles[SCARG(&ua, fd)]) != NULL &&		/*XXX*/
    860  1.7.2.2  bouyer 	    fp->f_type == DTYPE_VNODE &&				/*XXX*/
    861  1.7.2.2  bouyer 	    (vp = (struct vnode *)fp->f_data)->v_type == VCHR &&	/*XXX*/
    862  1.7.2.2  bouyer 	    iszerodev(vp->v_rdev)) {					/*XXX*/
    863  1.7.2.2  bouyer 		SCARG(&ua, flags) |= MAP_ANON;
    864  1.7.2.2  bouyer 		SCARG(&ua, fd) = -1;
    865  1.7.2.2  bouyer 	}
    866  1.7.2.2  bouyer 
    867  1.7.2.2  bouyer 	error = sys_mmap(p, &ua, (register_t *)&rt);
    868  1.7.2.2  bouyer 	if ((long)rt > (long)UINT_MAX)
    869  1.7.2.2  bouyer 		printf("sunos32_mmap: retval out of range: %p", rt);
    870  1.7.2.2  bouyer 	*retval = (netbsd32_voidp)(u_long)rt;
    871  1.7.2.2  bouyer 	return (error);
    872  1.7.2.2  bouyer }
    873  1.7.2.2  bouyer 
    874  1.7.2.2  bouyer #define	MC_SYNC		1
    875  1.7.2.2  bouyer #define	MC_LOCK		2
    876  1.7.2.2  bouyer #define	MC_UNLOCK	3
    877  1.7.2.2  bouyer #define	MC_ADVISE	4
    878  1.7.2.2  bouyer #define	MC_LOCKAS	5
    879  1.7.2.2  bouyer #define	MC_UNLOCKAS	6
    880  1.7.2.2  bouyer 
    881  1.7.2.2  bouyer int
    882  1.7.2.2  bouyer sunos32_sys_mctl(p, v, retval)
    883  1.7.2.2  bouyer 	struct proc *p;
    884  1.7.2.2  bouyer 	void *v;
    885  1.7.2.2  bouyer 	register_t *retval;
    886  1.7.2.2  bouyer {
    887  1.7.2.2  bouyer 	struct sunos32_sys_mctl_args /* {
    888  1.7.2.2  bouyer 		syscallarg(netbsd32_voidp) addr;
    889  1.7.2.2  bouyer 		syscallarg(int) len;
    890  1.7.2.2  bouyer 		syscallarg(int) func;
    891  1.7.2.2  bouyer 		syscallarg(netbsd32_voidp) arg;
    892  1.7.2.2  bouyer 	} */ *uap = v;
    893  1.7.2.2  bouyer 
    894  1.7.2.2  bouyer 	switch (SCARG(uap, func)) {
    895  1.7.2.2  bouyer 	case MC_ADVISE:		/* ignore for now */
    896  1.7.2.2  bouyer 		return (0);
    897  1.7.2.2  bouyer 	case MC_SYNC:		/* translate to msync */
    898  1.7.2.2  bouyer 		return (netbsd32___msync13(p, uap, retval));
    899  1.7.2.2  bouyer 	default:
    900  1.7.2.2  bouyer 		return (EINVAL);
    901  1.7.2.2  bouyer 	}
    902  1.7.2.2  bouyer }
    903  1.7.2.2  bouyer 
    904  1.7.2.2  bouyer int
    905  1.7.2.2  bouyer sunos32_sys_setsockopt(p, v, retval)
    906  1.7.2.2  bouyer 	struct proc *p;
    907  1.7.2.2  bouyer 	void *v;
    908  1.7.2.2  bouyer 	register_t *retval;
    909  1.7.2.2  bouyer {
    910  1.7.2.2  bouyer 	struct sunos32_sys_setsockopt_args /* {
    911  1.7.2.2  bouyer 		syscallarg(int) s;
    912  1.7.2.2  bouyer 		syscallarg(int) level;
    913  1.7.2.2  bouyer 		syscallarg(int) name;
    914  1.7.2.2  bouyer 		syscallarg(netbsd32_caddr_t) val;
    915  1.7.2.2  bouyer 		syscallarg(int) valsize;
    916  1.7.2.2  bouyer 	} */ *uap = v;
    917  1.7.2.2  bouyer 	struct file *fp;
    918  1.7.2.2  bouyer 	struct mbuf *m = NULL;
    919  1.7.2.2  bouyer 	int error;
    920  1.7.2.2  bouyer 
    921  1.7.2.2  bouyer 	/* getsock() will use the descriptor for us */
    922  1.7.2.2  bouyer 	if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0)
    923  1.7.2.2  bouyer 		return (error);
    924  1.7.2.2  bouyer #define	SO_DONTLINGER (~SO_LINGER)
    925  1.7.2.2  bouyer 	if (SCARG(uap, name) == SO_DONTLINGER) {
    926  1.7.2.2  bouyer 		m = m_get(M_WAIT, MT_SOOPTS);
    927  1.7.2.2  bouyer 		mtod(m, struct linger *)->l_onoff = 0;
    928  1.7.2.2  bouyer 		m->m_len = sizeof(struct linger);
    929  1.7.2.2  bouyer 		error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
    930  1.7.2.2  bouyer 		    SO_LINGER, m);
    931  1.7.2.2  bouyer 		goto out;
    932  1.7.2.2  bouyer 	}
    933  1.7.2.2  bouyer 	if (SCARG(uap, level) == IPPROTO_IP) {
    934  1.7.2.2  bouyer #define		SUNOS_IP_MULTICAST_IF		2
    935  1.7.2.2  bouyer #define		SUNOS_IP_MULTICAST_TTL		3
    936  1.7.2.2  bouyer #define		SUNOS_IP_MULTICAST_LOOP		4
    937  1.7.2.2  bouyer #define		SUNOS_IP_ADD_MEMBERSHIP		5
    938  1.7.2.2  bouyer #define		SUNOS_IP_DROP_MEMBERSHIP	6
    939  1.7.2.2  bouyer 		static int ipoptxlat[] = {
    940  1.7.2.2  bouyer 			IP_MULTICAST_IF,
    941  1.7.2.2  bouyer 			IP_MULTICAST_TTL,
    942  1.7.2.2  bouyer 			IP_MULTICAST_LOOP,
    943  1.7.2.2  bouyer 			IP_ADD_MEMBERSHIP,
    944  1.7.2.2  bouyer 			IP_DROP_MEMBERSHIP
    945  1.7.2.2  bouyer 		};
    946  1.7.2.2  bouyer 		if (SCARG(uap, name) >= SUNOS_IP_MULTICAST_IF &&
    947  1.7.2.2  bouyer 		    SCARG(uap, name) <= SUNOS_IP_DROP_MEMBERSHIP) {
    948  1.7.2.2  bouyer 			SCARG(uap, name) =
    949  1.7.2.2  bouyer 			    ipoptxlat[SCARG(uap, name) - SUNOS_IP_MULTICAST_IF];
    950  1.7.2.2  bouyer 		}
    951  1.7.2.2  bouyer 	}
    952  1.7.2.2  bouyer 	if (SCARG(uap, valsize) > MLEN) {
    953  1.7.2.2  bouyer 		error = EINVAL;
    954  1.7.2.2  bouyer 		goto out;
    955  1.7.2.2  bouyer 	}
    956  1.7.2.2  bouyer 	if (SCARG(uap, val)) {
    957  1.7.2.2  bouyer 		m = m_get(M_WAIT, MT_SOOPTS);
    958  1.7.2.2  bouyer 		error = copyin((caddr_t)(u_long)SCARG(uap, val), mtod(m, caddr_t),
    959  1.7.2.2  bouyer 		    (u_int)SCARG(uap, valsize));
    960  1.7.2.2  bouyer 		if (error) {
    961  1.7.2.2  bouyer 			(void) m_free(m);
    962  1.7.2.2  bouyer 			goto out;
    963  1.7.2.2  bouyer 		}
    964  1.7.2.2  bouyer 		m->m_len = SCARG(uap, valsize);
    965  1.7.2.2  bouyer 	}
    966  1.7.2.2  bouyer 	error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
    967  1.7.2.2  bouyer 	    SCARG(uap, name), m);
    968  1.7.2.2  bouyer  out:
    969  1.7.2.2  bouyer 	FILE_UNUSE(fp, p);
    970  1.7.2.2  bouyer 	return (error);
    971  1.7.2.2  bouyer }
    972  1.7.2.2  bouyer 
    973  1.7.2.2  bouyer /*
    974  1.7.2.2  bouyer  * XXX: This needs cleaning up.
    975  1.7.2.2  bouyer  */
    976  1.7.2.2  bouyer int
    977  1.7.2.2  bouyer sunos32_sys_auditsys(p, v, retval)
    978  1.7.2.2  bouyer 	struct proc *p;
    979  1.7.2.2  bouyer 	void *v;
    980  1.7.2.2  bouyer 	register_t *retval;
    981  1.7.2.2  bouyer {
    982  1.7.2.2  bouyer 	return 0;
    983  1.7.2.2  bouyer }
    984  1.7.2.2  bouyer 
    985  1.7.2.2  bouyer int
    986  1.7.2.2  bouyer sunos32_sys_uname(p, v, retval)
    987  1.7.2.2  bouyer 	struct proc *p;
    988  1.7.2.2  bouyer 	void *v;
    989  1.7.2.2  bouyer 	register_t *retval;
    990  1.7.2.2  bouyer {
    991  1.7.2.2  bouyer 	struct sunos32_sys_uname_args /* {
    992  1.7.2.2  bouyer 		syscallarg(sunos32_utsnamep_t) name;
    993  1.7.2.2  bouyer 	} */ *uap = v;
    994  1.7.2.2  bouyer 	struct sunos_utsname sut;
    995  1.7.2.2  bouyer 
    996  1.7.2.2  bouyer 	memset(&sut, 0, sizeof(sut));
    997  1.7.2.2  bouyer 
    998  1.7.2.2  bouyer 	memcpy(sut.sysname, ostype, sizeof(sut.sysname) - 1);
    999  1.7.2.2  bouyer 	memcpy(sut.nodename, hostname, sizeof(sut.nodename));
   1000  1.7.2.2  bouyer 	sut.nodename[sizeof(sut.nodename)-1] = '\0';
   1001  1.7.2.2  bouyer 	memcpy(sut.release, osrelease, sizeof(sut.release) - 1);
   1002  1.7.2.2  bouyer 	memcpy(sut.version, "1", sizeof(sut.version) - 1);
   1003  1.7.2.2  bouyer 	memcpy(sut.machine, machine, sizeof(sut.machine) - 1);
   1004  1.7.2.2  bouyer 
   1005  1.7.2.2  bouyer 	return copyout((caddr_t)&sut, (caddr_t)(u_long)SCARG(uap, name),
   1006  1.7.2.2  bouyer 	    sizeof(struct sunos_utsname));
   1007  1.7.2.2  bouyer }
   1008  1.7.2.2  bouyer 
   1009  1.7.2.2  bouyer int
   1010  1.7.2.2  bouyer sunos32_sys_setpgrp(p, v, retval)
   1011  1.7.2.2  bouyer 	struct proc *p;
   1012  1.7.2.2  bouyer 	void *v;
   1013  1.7.2.2  bouyer 	register_t *retval;
   1014  1.7.2.2  bouyer {
   1015  1.7.2.2  bouyer 	struct sunos32_sys_setpgrp_args /* {
   1016  1.7.2.2  bouyer 		syscallarg(int) pid;
   1017  1.7.2.2  bouyer 		syscallarg(int) pgid;
   1018  1.7.2.2  bouyer 	} */ *uap = v;
   1019  1.7.2.2  bouyer 
   1020  1.7.2.2  bouyer 	/*
   1021  1.7.2.2  bouyer 	 * difference to our setpgid call is to include backwards
   1022  1.7.2.2  bouyer 	 * compatibility to pre-setsid() binaries. Do setsid()
   1023  1.7.2.2  bouyer 	 * instead of setpgid() in those cases where the process
   1024  1.7.2.2  bouyer 	 * tries to create a new session the old way.
   1025  1.7.2.2  bouyer 	 */
   1026  1.7.2.2  bouyer 	if (!SCARG(uap, pgid) &&
   1027  1.7.2.2  bouyer 	    (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
   1028  1.7.2.2  bouyer 		return sys_setsid(p, uap, retval);
   1029  1.7.2.2  bouyer 	else
   1030  1.7.2.2  bouyer 		return netbsd32_setpgid(p, uap, retval);
   1031  1.7.2.2  bouyer }
   1032  1.7.2.2  bouyer 
   1033  1.7.2.2  bouyer int
   1034  1.7.2.2  bouyer sunos32_sys_open(p, v, retval)
   1035  1.7.2.2  bouyer 	struct proc *p;
   1036  1.7.2.2  bouyer 	void *v;
   1037  1.7.2.2  bouyer 	register_t *retval;
   1038  1.7.2.2  bouyer {
   1039  1.7.2.2  bouyer 	struct sunos32_sys_open_args /* {
   1040  1.7.2.2  bouyer 		syscallarg(const netbsd32_charp) path;
   1041  1.7.2.2  bouyer 		syscallarg(int) flags;
   1042  1.7.2.2  bouyer 		syscallarg(int) mode;
   1043  1.7.2.2  bouyer 	} */ *uap = v;
   1044  1.7.2.2  bouyer 	struct sys_open_args ua;
   1045  1.7.2.2  bouyer 	int l, r;
   1046  1.7.2.2  bouyer 	int noctty;
   1047  1.7.2.2  bouyer 	int ret;
   1048  1.7.2.2  bouyer 	caddr_t sg = stackgap_init(p->p_emul);
   1049  1.7.2.2  bouyer 
   1050  1.7.2.2  bouyer 	/* convert mode into NetBSD mode */
   1051  1.7.2.2  bouyer 	l = SCARG(uap, flags);
   1052  1.7.2.2  bouyer 	noctty = l & 0x8000;
   1053  1.7.2.2  bouyer 	r =	(l & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800));
   1054  1.7.2.2  bouyer 	r |=	((l & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
   1055  1.7.2.2  bouyer 	r |=	((l & 0x0080) ? O_SHLOCK : 0);
   1056  1.7.2.2  bouyer 	r |=	((l & 0x0100) ? O_EXLOCK : 0);
   1057  1.7.2.2  bouyer 	r |=	((l & 0x2000) ? O_FSYNC : 0);
   1058  1.7.2.2  bouyer 
   1059  1.7.2.2  bouyer 	SUNOS32TOP_UAP(path, const char);
   1060  1.7.2.2  bouyer 	SCARG(&ua, flags) = r;
   1061  1.7.2.2  bouyer 	SUNOS32TO64_UAP(mode);
   1062  1.7.2.2  bouyer 
   1063  1.7.2.2  bouyer 	if (r & O_CREAT)
   1064  1.7.2.2  bouyer 		SUNOS32_CHECK_ALT_CREAT(p, &sg, SCARG(&ua, path));
   1065  1.7.2.2  bouyer 	else
   1066  1.7.2.2  bouyer 		SUNOS32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
   1067  1.7.2.2  bouyer 
   1068  1.7.2.2  bouyer 	ret = sys_open(p, &ua, retval);
   1069  1.7.2.2  bouyer 
   1070  1.7.2.2  bouyer 	if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
   1071  1.7.2.2  bouyer 		struct filedesc *fdp = p->p_fd;
   1072  1.7.2.2  bouyer 		struct file *fp = fdp->fd_ofiles[*retval];
   1073  1.7.2.2  bouyer 
   1074  1.7.2.2  bouyer 		/* ignore any error, just give it a try */
   1075  1.7.2.2  bouyer 		if (fp->f_type == DTYPE_VNODE)
   1076  1.7.2.2  bouyer 			(fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t)0, p);
   1077  1.7.2.2  bouyer 	}
   1078  1.7.2.2  bouyer 	return ret;
   1079  1.7.2.2  bouyer }
   1080  1.7.2.2  bouyer 
   1081  1.7.2.2  bouyer #if defined (NFSSERVER)
   1082  1.7.2.2  bouyer int
   1083  1.7.2.2  bouyer sunos32_sys_nfssvc(p, v, retval)
   1084  1.7.2.2  bouyer 	struct proc *p;
   1085  1.7.2.2  bouyer 	void *v;
   1086  1.7.2.2  bouyer 	register_t *retval;
   1087  1.7.2.2  bouyer {
   1088  1.7.2.2  bouyer #if 0
   1089  1.7.2.2  bouyer 	struct sunos32_sys_nfssvc_args *uap = v;
   1090  1.7.2.2  bouyer 	struct emul *e = p->p_emul;
   1091  1.7.2.2  bouyer 	struct sys_nfssvc_args outuap;
   1092  1.7.2.2  bouyer 	struct sockaddr sa;
   1093  1.7.2.2  bouyer 	int error;
   1094  1.7.2.2  bouyer 	caddr_t sg = stackgap_init(p->p_emul);
   1095  1.7.2.2  bouyer 
   1096  1.7.2.2  bouyer 	memset(&outuap, 0, sizeof outuap);
   1097  1.7.2.2  bouyer 	SCARG(&outuap, fd) = SCARG(uap, fd);
   1098  1.7.2.2  bouyer 	SCARG(&outuap, mskval) = stackgap_alloc(&sg, sizeof(sa));
   1099  1.7.2.2  bouyer 	SCARG(&outuap, msklen) = sizeof(sa);
   1100  1.7.2.2  bouyer 	SCARG(&outuap, mtchval) = stackgap_alloc(&sg, sizeof(sa));
   1101  1.7.2.2  bouyer 	SCARG(&outuap, mtchlen) = sizeof(sa);
   1102  1.7.2.2  bouyer 
   1103  1.7.2.2  bouyer 	memset(&sa, 0, sizeof sa);
   1104  1.7.2.2  bouyer 	if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
   1105  1.7.2.2  bouyer 		return (error);
   1106  1.7.2.2  bouyer 	if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
   1107  1.7.2.2  bouyer 		return (error);
   1108  1.7.2.2  bouyer 
   1109  1.7.2.2  bouyer 	return nfssvc(p, &outuap, retval);
   1110  1.7.2.2  bouyer #else
   1111  1.7.2.2  bouyer 	return (ENOSYS);
   1112  1.7.2.2  bouyer #endif
   1113  1.7.2.2  bouyer }
   1114  1.7.2.2  bouyer #endif /* NFSSERVER */
   1115  1.7.2.2  bouyer 
   1116  1.7.2.2  bouyer int
   1117  1.7.2.2  bouyer sunos32_sys_ustat(p, v, retval)
   1118  1.7.2.2  bouyer 	struct proc *p;
   1119  1.7.2.2  bouyer 	void *v;
   1120  1.7.2.2  bouyer 	register_t *retval;
   1121  1.7.2.2  bouyer {
   1122  1.7.2.2  bouyer 	struct sunos32_sys_ustat_args /* {
   1123  1.7.2.2  bouyer 		syscallarg(int) dev;
   1124  1.7.2.2  bouyer 		syscallarg(sunos32_ustatp_t) buf;
   1125  1.7.2.2  bouyer 	} */ *uap = v;
   1126  1.7.2.2  bouyer 	struct sunos_ustat us;
   1127  1.7.2.2  bouyer 	int error;
   1128  1.7.2.2  bouyer 
   1129  1.7.2.2  bouyer 	memset(&us, 0, sizeof us);
   1130  1.7.2.2  bouyer 
   1131  1.7.2.2  bouyer 	/*
   1132  1.7.2.2  bouyer 	 * XXX: should set f_tfree and f_tinode at least
   1133  1.7.2.2  bouyer 	 * How do we translate dev -> fstat? (and then to sunos_ustat)
   1134  1.7.2.2  bouyer 	 */
   1135  1.7.2.2  bouyer 
   1136  1.7.2.2  bouyer 	if ((error = copyout(&us, (caddr_t)(u_long)SCARG(uap, buf), sizeof us)) != 0)
   1137  1.7.2.2  bouyer 		return (error);
   1138  1.7.2.2  bouyer 	return 0;
   1139  1.7.2.2  bouyer }
   1140  1.7.2.2  bouyer 
   1141  1.7.2.2  bouyer int
   1142  1.7.2.2  bouyer sunos32_sys_quotactl(p, v, retval)
   1143  1.7.2.2  bouyer 	struct proc *p;
   1144  1.7.2.2  bouyer 	void *v;
   1145  1.7.2.2  bouyer 	register_t *retval;
   1146  1.7.2.2  bouyer {
   1147  1.7.2.2  bouyer 
   1148  1.7.2.2  bouyer 	return EINVAL;
   1149  1.7.2.2  bouyer }
   1150  1.7.2.2  bouyer 
   1151  1.7.2.2  bouyer int
   1152  1.7.2.2  bouyer sunos32_sys_vhangup(p, v, retval)
   1153  1.7.2.2  bouyer 	struct proc *p;
   1154  1.7.2.2  bouyer 	void *v;
   1155  1.7.2.2  bouyer 	register_t *retval;
   1156  1.7.2.2  bouyer {
   1157  1.7.2.2  bouyer 	struct session *sp = p->p_session;
   1158  1.7.2.2  bouyer 
   1159  1.7.2.2  bouyer 	if (sp->s_ttyvp == 0)
   1160  1.7.2.2  bouyer 		return 0;
   1161  1.7.2.2  bouyer 
   1162  1.7.2.2  bouyer 	if (sp->s_ttyp && sp->s_ttyp->t_session == sp && sp->s_ttyp->t_pgrp)
   1163  1.7.2.2  bouyer 		pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1);
   1164  1.7.2.2  bouyer 
   1165  1.7.2.2  bouyer 	(void) ttywait(sp->s_ttyp);
   1166  1.7.2.2  bouyer 	if (sp->s_ttyvp)
   1167  1.7.2.2  bouyer 		VOP_REVOKE(sp->s_ttyvp, REVOKEALL);
   1168  1.7.2.2  bouyer 	if (sp->s_ttyvp)
   1169  1.7.2.2  bouyer 		vrele(sp->s_ttyvp);
   1170  1.7.2.2  bouyer 	sp->s_ttyvp = NULL;
   1171  1.7.2.2  bouyer 
   1172  1.7.2.2  bouyer 	return 0;
   1173  1.7.2.2  bouyer }
   1174  1.7.2.2  bouyer 
   1175  1.7.2.2  bouyer static int
   1176  1.7.2.2  bouyer sunstatfs(sp, buf)
   1177  1.7.2.2  bouyer 	struct statfs *sp;
   1178  1.7.2.2  bouyer 	caddr_t buf;
   1179  1.7.2.2  bouyer {
   1180  1.7.2.2  bouyer 	struct sunos_statfs ssfs;
   1181  1.7.2.2  bouyer 
   1182  1.7.2.2  bouyer 	memset(&ssfs, 0, sizeof ssfs);
   1183  1.7.2.2  bouyer 	ssfs.f_type = 0;
   1184  1.7.2.2  bouyer 	ssfs.f_bsize = sp->f_bsize;
   1185  1.7.2.2  bouyer 	ssfs.f_blocks = sp->f_blocks;
   1186  1.7.2.2  bouyer 	ssfs.f_bfree = sp->f_bfree;
   1187  1.7.2.2  bouyer 	ssfs.f_bavail = sp->f_bavail;
   1188  1.7.2.2  bouyer 	ssfs.f_files = sp->f_files;
   1189  1.7.2.2  bouyer 	ssfs.f_ffree = sp->f_ffree;
   1190  1.7.2.2  bouyer 	ssfs.f_fsid = sp->f_fsid;
   1191  1.7.2.2  bouyer 	return copyout((caddr_t)&ssfs, buf, sizeof ssfs);
   1192  1.7.2.2  bouyer }
   1193  1.7.2.2  bouyer 
   1194  1.7.2.2  bouyer int
   1195  1.7.2.2  bouyer sunos32_sys_statfs(p, v, retval)
   1196  1.7.2.2  bouyer 	struct proc *p;
   1197  1.7.2.2  bouyer 	void *v;
   1198  1.7.2.2  bouyer 	register_t *retval;
   1199  1.7.2.2  bouyer {
   1200  1.7.2.2  bouyer 	struct sunos32_sys_statfs_args /* {
   1201  1.7.2.2  bouyer 		syscallarg(const netbsd32_charp) path;
   1202  1.7.2.2  bouyer 		syscallarg(sunos32_statfsp_t) buf;
   1203  1.7.2.2  bouyer 	} */ *uap = v;
   1204  1.7.2.2  bouyer 	struct mount *mp;
   1205  1.7.2.2  bouyer 	struct statfs *sp;
   1206  1.7.2.2  bouyer 	int error;
   1207  1.7.2.2  bouyer 	struct nameidata nd;
   1208  1.7.2.2  bouyer 
   1209  1.7.2.2  bouyer 	caddr_t sg = stackgap_init(p->p_emul);
   1210  1.7.2.2  bouyer 	SUNOS32_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
   1211  1.7.2.2  bouyer 
   1212  1.7.2.2  bouyer 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, (caddr_t)(u_long)SCARG(uap, path), p);
   1213  1.7.2.2  bouyer 	if ((error = namei(&nd)) != 0)
   1214  1.7.2.2  bouyer 		return (error);
   1215  1.7.2.2  bouyer 	mp = nd.ni_vp->v_mount;
   1216  1.7.2.2  bouyer 	sp = &mp->mnt_stat;
   1217  1.7.2.2  bouyer 	vrele(nd.ni_vp);
   1218  1.7.2.2  bouyer 	if ((error = VFS_STATFS(mp, sp, p)) != 0)
   1219  1.7.2.2  bouyer 		return (error);
   1220  1.7.2.2  bouyer 	sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
   1221  1.7.2.2  bouyer 	return sunstatfs(sp, (caddr_t)(u_long)SCARG(uap, buf));
   1222  1.7.2.2  bouyer }
   1223  1.7.2.2  bouyer 
   1224  1.7.2.2  bouyer int
   1225  1.7.2.2  bouyer sunos32_sys_fstatfs(p, v, retval)
   1226  1.7.2.2  bouyer 	struct proc *p;
   1227  1.7.2.2  bouyer 	void *v;
   1228  1.7.2.2  bouyer 	register_t *retval;
   1229  1.7.2.2  bouyer {
   1230  1.7.2.2  bouyer 	struct sunos32_sys_fstatfs_args /* {
   1231  1.7.2.2  bouyer 		syscallarg(int) fd;
   1232  1.7.2.2  bouyer 		syscallarg(sunos32_statfsp_t) buf;
   1233  1.7.2.2  bouyer 	} */ *uap = v;
   1234  1.7.2.2  bouyer 	struct file *fp;
   1235  1.7.2.2  bouyer 	struct mount *mp;
   1236  1.7.2.2  bouyer 	struct statfs *sp;
   1237  1.7.2.2  bouyer 	int error;
   1238  1.7.2.2  bouyer 
   1239  1.7.2.2  bouyer 	/* getvnode() will use the descriptor for us */
   1240  1.7.2.2  bouyer 	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
   1241  1.7.2.2  bouyer 		return (error);
   1242  1.7.2.2  bouyer 	mp = ((struct vnode *)fp->f_data)->v_mount;
   1243  1.7.2.2  bouyer 	sp = &mp->mnt_stat;
   1244  1.7.2.2  bouyer 	if ((error = VFS_STATFS(mp, sp, p)) != 0)
   1245  1.7.2.2  bouyer 		goto out;
   1246  1.7.2.2  bouyer 	sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
   1247  1.7.2.2  bouyer 	error = sunstatfs(sp, (caddr_t)(u_long)SCARG(uap, buf));
   1248  1.7.2.2  bouyer  out:
   1249  1.7.2.2  bouyer 	FILE_UNUSE(fp, p);
   1250  1.7.2.2  bouyer 	return (error);
   1251  1.7.2.2  bouyer }
   1252  1.7.2.2  bouyer 
   1253  1.7.2.2  bouyer int
   1254  1.7.2.2  bouyer sunos32_sys_exportfs(p, v, retval)
   1255  1.7.2.2  bouyer 	struct proc *p;
   1256  1.7.2.2  bouyer 	void *v;
   1257  1.7.2.2  bouyer 	register_t *retval;
   1258  1.7.2.2  bouyer {
   1259  1.7.2.2  bouyer 	/*
   1260  1.7.2.2  bouyer 	 * XXX: should perhaps translate into a mount(2)
   1261  1.7.2.2  bouyer 	 * with MOUNT_EXPORT?
   1262  1.7.2.2  bouyer 	 */
   1263  1.7.2.2  bouyer 	return 0;
   1264  1.7.2.2  bouyer }
   1265  1.7.2.2  bouyer 
   1266  1.7.2.2  bouyer int
   1267  1.7.2.2  bouyer sunos32_sys_mknod(p, v, retval)
   1268  1.7.2.2  bouyer 	struct proc *p;
   1269  1.7.2.2  bouyer 	void *v;
   1270  1.7.2.2  bouyer 	register_t *retval;
   1271  1.7.2.2  bouyer {
   1272  1.7.2.2  bouyer 	struct sunos32_sys_mknod_args /* {
   1273  1.7.2.2  bouyer 		syscallarg(const netbsd32_charp) path;
   1274  1.7.2.2  bouyer 		syscallarg(int) mode;
   1275  1.7.2.2  bouyer 		syscallarg(int) dev;
   1276  1.7.2.2  bouyer 	} */ *uap = v;
   1277  1.7.2.2  bouyer 
   1278  1.7.2.2  bouyer 	caddr_t sg = stackgap_init(p->p_emul);
   1279  1.7.2.2  bouyer 	SUNOS32_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
   1280  1.7.2.2  bouyer 
   1281  1.7.2.2  bouyer 	/* netbsd32_mkfifo/mknod to not do alt checking */
   1282  1.7.2.2  bouyer 	if (S_ISFIFO(SCARG(uap, mode)))
   1283  1.7.2.2  bouyer 		return netbsd32_mkfifo(p, (struct netbsd32_mkfifo_args *)uap, retval);
   1284  1.7.2.2  bouyer 
   1285  1.7.2.2  bouyer 	return netbsd32_mknod(p, (struct netbsd32_mknod_args *)uap, retval);
   1286  1.7.2.2  bouyer }
   1287  1.7.2.2  bouyer 
   1288  1.7.2.2  bouyer #define SUNOS_SC_ARG_MAX	1
   1289  1.7.2.2  bouyer #define SUNOS_SC_CHILD_MAX	2
   1290  1.7.2.2  bouyer #define SUNOS_SC_CLK_TCK	3
   1291  1.7.2.2  bouyer #define SUNOS_SC_NGROUPS_MAX	4
   1292  1.7.2.2  bouyer #define SUNOS_SC_OPEN_MAX	5
   1293  1.7.2.2  bouyer #define SUNOS_SC_JOB_CONTROL	6
   1294  1.7.2.2  bouyer #define SUNOS_SC_SAVED_IDS	7
   1295  1.7.2.2  bouyer #define SUNOS_SC_VERSION	8
   1296  1.7.2.2  bouyer 
   1297  1.7.2.2  bouyer int
   1298  1.7.2.2  bouyer sunos32_sys_sysconf(p, v, retval)
   1299  1.7.2.2  bouyer 	struct proc *p;
   1300  1.7.2.2  bouyer 	void *v;
   1301  1.7.2.2  bouyer 	register_t *retval;
   1302  1.7.2.2  bouyer {
   1303  1.7.2.2  bouyer 	struct sunos32_sys_sysconf_args /* {
   1304  1.7.2.2  bouyer 		syscallarg(int) name;
   1305  1.7.2.2  bouyer 	} */ *uap = v;
   1306  1.7.2.2  bouyer 	extern int maxfiles;
   1307  1.7.2.2  bouyer 
   1308  1.7.2.2  bouyer 	switch(SCARG(uap, name)) {
   1309  1.7.2.2  bouyer 	case SUNOS_SC_ARG_MAX:
   1310  1.7.2.2  bouyer 		*retval = ARG_MAX;
   1311  1.7.2.2  bouyer 		break;
   1312  1.7.2.2  bouyer 	case SUNOS_SC_CHILD_MAX:
   1313  1.7.2.2  bouyer 		*retval = maxproc;
   1314  1.7.2.2  bouyer 		break;
   1315  1.7.2.2  bouyer 	case SUNOS_SC_CLK_TCK:
   1316  1.7.2.2  bouyer 		*retval = 60;		/* should this be `hz', ie. 100? */
   1317  1.7.2.2  bouyer 		break;
   1318  1.7.2.2  bouyer 	case SUNOS_SC_NGROUPS_MAX:
   1319  1.7.2.2  bouyer 		*retval = NGROUPS_MAX;
   1320  1.7.2.2  bouyer 		break;
   1321  1.7.2.2  bouyer 	case SUNOS_SC_OPEN_MAX:
   1322  1.7.2.2  bouyer 		*retval = maxfiles;
   1323  1.7.2.2  bouyer 		break;
   1324  1.7.2.2  bouyer 	case SUNOS_SC_JOB_CONTROL:
   1325  1.7.2.2  bouyer 		*retval = 1;
   1326  1.7.2.2  bouyer 		break;
   1327  1.7.2.2  bouyer 	case SUNOS_SC_SAVED_IDS:
   1328  1.7.2.2  bouyer #ifdef _POSIX_SAVED_IDS
   1329  1.7.2.2  bouyer 		*retval = 1;
   1330  1.7.2.2  bouyer #else
   1331  1.7.2.2  bouyer 		*retval = 0;
   1332  1.7.2.2  bouyer #endif
   1333  1.7.2.2  bouyer 		break;
   1334  1.7.2.2  bouyer 	case SUNOS_SC_VERSION:
   1335  1.7.2.2  bouyer 		*retval = 198808;
   1336  1.7.2.2  bouyer 		break;
   1337  1.7.2.2  bouyer 	default:
   1338  1.7.2.2  bouyer 		return EINVAL;
   1339  1.7.2.2  bouyer 	}
   1340  1.7.2.2  bouyer 	return 0;
   1341  1.7.2.2  bouyer }
   1342  1.7.2.2  bouyer 
   1343  1.7.2.2  bouyer #define SUNOS_RLIMIT_NOFILE	6	/* Other RLIMIT_* are the same */
   1344  1.7.2.2  bouyer #define SUNOS_RLIM_NLIMITS	7
   1345  1.7.2.2  bouyer 
   1346  1.7.2.2  bouyer int
   1347  1.7.2.2  bouyer sunos32_sys_getrlimit(p, v, retval)
   1348  1.7.2.2  bouyer 	struct proc *p;
   1349  1.7.2.2  bouyer 	void *v;
   1350  1.7.2.2  bouyer 	register_t *retval;
   1351  1.7.2.2  bouyer {
   1352  1.7.2.2  bouyer 	struct sunos32_sys_getrlimit_args /* {
   1353  1.7.2.2  bouyer 		syscallarg(u_int) which;
   1354  1.7.2.2  bouyer 		syscallarg(netbsd32_orlimitp_t) rlp;
   1355  1.7.2.2  bouyer 	} */ *uap = v;
   1356  1.7.2.2  bouyer 
   1357  1.7.2.2  bouyer 	if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
   1358  1.7.2.2  bouyer 		return EINVAL;
   1359  1.7.2.2  bouyer 
   1360  1.7.2.2  bouyer 	if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
   1361  1.7.2.2  bouyer 		SCARG(uap, which) = RLIMIT_NOFILE;
   1362  1.7.2.2  bouyer 
   1363  1.7.2.2  bouyer 	return compat_43_netbsd32_ogetrlimit(p, uap, retval);
   1364  1.7.2.2  bouyer }
   1365  1.7.2.2  bouyer 
   1366  1.7.2.2  bouyer int
   1367  1.7.2.2  bouyer sunos32_sys_setrlimit(p, v, retval)
   1368  1.7.2.2  bouyer 	struct proc *p;
   1369  1.7.2.2  bouyer 	void *v;
   1370  1.7.2.2  bouyer 	register_t *retval;
   1371  1.7.2.2  bouyer {
   1372  1.7.2.2  bouyer 	struct sunos32_sys_setrlimit_args /* {
   1373  1.7.2.2  bouyer 		syscallarg(u_int) which;
   1374  1.7.2.2  bouyer 		syscallarg(netbsd32_orlimitp_t) rlp;
   1375  1.7.2.2  bouyer 	} */ *uap = v;
   1376  1.7.2.2  bouyer 
   1377  1.7.2.2  bouyer 	if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
   1378  1.7.2.2  bouyer 		return EINVAL;
   1379  1.7.2.2  bouyer 
   1380  1.7.2.2  bouyer 	if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
   1381  1.7.2.2  bouyer 		SCARG(uap, which) = RLIMIT_NOFILE;
   1382  1.7.2.2  bouyer 
   1383  1.7.2.2  bouyer 	return compat_43_netbsd32_osetrlimit(p, uap, retval);
   1384  1.7.2.2  bouyer }
   1385  1.7.2.2  bouyer 
   1386  1.7.2.2  bouyer /* for the m68k machines */
   1387  1.7.2.2  bouyer #ifndef PT_GETFPREGS
   1388  1.7.2.2  bouyer #define PT_GETFPREGS -1
   1389  1.7.2.2  bouyer #endif
   1390  1.7.2.2  bouyer #ifndef PT_SETFPREGS
   1391  1.7.2.2  bouyer #define PT_SETFPREGS -1
   1392  1.7.2.2  bouyer #endif
   1393  1.7.2.2  bouyer 
   1394  1.7.2.2  bouyer static int sreq2breq[] = {
   1395  1.7.2.2  bouyer 	PT_TRACE_ME,    PT_READ_I,      PT_READ_D,      -1,
   1396  1.7.2.2  bouyer 	PT_WRITE_I,     PT_WRITE_D,     -1,             PT_CONTINUE,
   1397  1.7.2.2  bouyer 	PT_KILL,        -1,             PT_ATTACH,      PT_DETACH,
   1398  1.7.2.2  bouyer 	PT_GETREGS,     PT_SETREGS,     PT_GETFPREGS,   PT_SETFPREGS
   1399  1.7.2.2  bouyer };
   1400  1.7.2.2  bouyer static int nreqs = sizeof(sreq2breq) / sizeof(sreq2breq[0]);
   1401  1.7.2.2  bouyer 
   1402  1.7.2.2  bouyer int
   1403  1.7.2.2  bouyer sunos32_sys_ptrace(p, v, retval)
   1404  1.7.2.2  bouyer 	struct proc *p;
   1405  1.7.2.2  bouyer 	void *v;
   1406  1.7.2.2  bouyer 	register_t *retval;
   1407  1.7.2.2  bouyer {
   1408  1.7.2.2  bouyer 	struct sunos32_sys_ptrace_args /* {
   1409  1.7.2.2  bouyer 		syscallarg(int) req;
   1410  1.7.2.2  bouyer 		syscallarg(pid_t) pid;
   1411  1.7.2.2  bouyer 		syscallarg(netbsd32_caddr_t) addr;
   1412  1.7.2.2  bouyer 		syscallarg(int) data;
   1413  1.7.2.2  bouyer 		syscallarg(netbsd32_charp) addr2;
   1414  1.7.2.2  bouyer 	} */ *uap = v;
   1415  1.7.2.2  bouyer 	struct netbsd32_ptrace_args pa;
   1416  1.7.2.2  bouyer 	int req;
   1417  1.7.2.2  bouyer 
   1418  1.7.2.2  bouyer 	req = SCARG(uap, req);
   1419  1.7.2.2  bouyer 
   1420  1.7.2.2  bouyer 	if (req < 0 || req >= nreqs)
   1421  1.7.2.2  bouyer 		return (EINVAL);
   1422  1.7.2.2  bouyer 
   1423  1.7.2.2  bouyer 	req = sreq2breq[req];
   1424  1.7.2.2  bouyer 	if (req == -1)
   1425  1.7.2.2  bouyer 		return (EINVAL);
   1426  1.7.2.2  bouyer 
   1427  1.7.2.2  bouyer 	SCARG(&pa, req) = req;
   1428  1.7.2.2  bouyer 	SCARG(&pa, pid) = (pid_t)SCARG(uap, pid);
   1429  1.7.2.2  bouyer 	SCARG(&pa, addr) = SCARG(uap, addr);
   1430  1.7.2.2  bouyer 	SCARG(&pa, data) = SCARG(uap, data);
   1431  1.7.2.2  bouyer 
   1432  1.7.2.2  bouyer 	return netbsd32_ptrace(p, &pa, retval);
   1433  1.7.2.2  bouyer }
   1434  1.7.2.2  bouyer 
   1435  1.7.2.2  bouyer /*
   1436  1.7.2.2  bouyer  * SunOS reboot system call (for compatibility).
   1437  1.7.2.2  bouyer  * Sun lets you pass in a boot string which the PROM
   1438  1.7.2.2  bouyer  * saves and provides to the next boot program.
   1439  1.7.2.2  bouyer  */
   1440  1.7.2.2  bouyer 
   1441  1.7.2.2  bouyer #define SUNOS_RB_ASKNAME	0x001
   1442  1.7.2.2  bouyer #define SUNOS_RB_SINGLE 	0x002
   1443  1.7.2.2  bouyer #define SUNOS_RB_NOSYNC		0x004
   1444  1.7.2.2  bouyer #define SUNOS_RB_HALT		0x008
   1445  1.7.2.2  bouyer #define SUNOS_RB_DUMP		0x080
   1446  1.7.2.2  bouyer #define	SUNOS_RB_STRING		0x200
   1447  1.7.2.2  bouyer 
   1448  1.7.2.2  bouyer static struct sunos_howto_conv {
   1449  1.7.2.2  bouyer 	int sun_howto;
   1450  1.7.2.2  bouyer 	int bsd_howto;
   1451  1.7.2.2  bouyer } sunos_howto_conv[] = {
   1452  1.7.2.2  bouyer 	{ SUNOS_RB_ASKNAME,	RB_ASKNAME },
   1453  1.7.2.2  bouyer 	{ SUNOS_RB_SINGLE,	RB_SINGLE },
   1454  1.7.2.2  bouyer 	{ SUNOS_RB_NOSYNC,	RB_NOSYNC },
   1455  1.7.2.2  bouyer 	{ SUNOS_RB_HALT,	RB_HALT },
   1456  1.7.2.2  bouyer 	{ SUNOS_RB_DUMP,	RB_DUMP },
   1457  1.7.2.2  bouyer 	{ SUNOS_RB_STRING,	RB_STRING },
   1458  1.7.2.2  bouyer 	{ 0x000,		0 },
   1459  1.7.2.2  bouyer };
   1460  1.7.2.2  bouyer 
   1461  1.7.2.2  bouyer int
   1462  1.7.2.2  bouyer sunos32_sys_reboot(p, v, retval)
   1463  1.7.2.2  bouyer 	struct proc *p;
   1464  1.7.2.2  bouyer 	void *v;
   1465  1.7.2.2  bouyer 	register_t *retval;
   1466  1.7.2.2  bouyer {
   1467  1.7.2.2  bouyer 	struct sunos32_sys_reboot_args /* {
   1468  1.7.2.2  bouyer 		syscallarg(int) howto;
   1469  1.7.2.2  bouyer 		syscallarg(netbsd32_charp) bootstr;
   1470  1.7.2.2  bouyer 	} */ *uap = v;
   1471  1.7.2.2  bouyer 	struct sys_reboot_args ua;
   1472  1.7.2.2  bouyer 	struct sunos_howto_conv *convp;
   1473  1.7.2.2  bouyer 	int error, bsd_howto, sun_howto;
   1474  1.7.2.2  bouyer 	char *bootstr;
   1475  1.7.2.2  bouyer 
   1476  1.7.2.2  bouyer 	if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
   1477  1.7.2.2  bouyer 		return (error);
   1478  1.7.2.2  bouyer 
   1479  1.7.2.2  bouyer 	/*
   1480  1.7.2.2  bouyer 	 * Convert howto bits to BSD format.
   1481  1.7.2.2  bouyer 	 */
   1482  1.7.2.2  bouyer 	sun_howto = SCARG(uap, howto);
   1483  1.7.2.2  bouyer 	bsd_howto = 0;
   1484  1.7.2.2  bouyer 	convp = sunos_howto_conv;
   1485  1.7.2.2  bouyer 	while (convp->sun_howto) {
   1486  1.7.2.2  bouyer 		if (sun_howto & convp->sun_howto)
   1487  1.7.2.2  bouyer 			bsd_howto |= convp->bsd_howto;
   1488  1.7.2.2  bouyer 		convp++;
   1489  1.7.2.2  bouyer 	}
   1490  1.7.2.2  bouyer 
   1491  1.7.2.2  bouyer 	/*
   1492  1.7.2.2  bouyer 	 * Sun RB_STRING (Get user supplied bootstring.)
   1493  1.7.2.2  bouyer 	 * If the machine supports passing a string to the
   1494  1.7.2.2  bouyer 	 * next booted kernel.
   1495  1.7.2.2  bouyer 	 */
   1496  1.7.2.2  bouyer 	if (sun_howto & SUNOS_RB_STRING)
   1497  1.7.2.2  bouyer 		bootstr = (char *)(u_long)SCARG(uap, bootstr);
   1498  1.7.2.2  bouyer 	else
   1499  1.7.2.2  bouyer 		bootstr = NULL;
   1500  1.7.2.2  bouyer 
   1501  1.7.2.2  bouyer 	SCARG(&ua, opt) = bsd_howto;
   1502  1.7.2.2  bouyer 	SCARG(&ua, bootstr) = bootstr;
   1503  1.7.2.2  bouyer 	return (sys_reboot(p, &ua, retval));
   1504  1.7.2.2  bouyer }
   1505  1.7.2.2  bouyer 
   1506  1.7.2.2  bouyer /*
   1507  1.7.2.2  bouyer  * Generalized interface signal handler, 4.3-compatible.
   1508  1.7.2.2  bouyer  */
   1509  1.7.2.2  bouyer /* ARGSUSED */
   1510  1.7.2.2  bouyer int
   1511  1.7.2.2  bouyer sunos32_sys_sigvec(p, v, retval)
   1512  1.7.2.2  bouyer 	struct proc *p;
   1513  1.7.2.2  bouyer 	void *v;
   1514  1.7.2.2  bouyer 	register_t *retval;
   1515  1.7.2.2  bouyer {
   1516  1.7.2.2  bouyer 	struct sunos32_sys_sigvec_args /* {
   1517  1.7.2.2  bouyer 		syscallarg(int) signum;
   1518  1.7.2.2  bouyer 		syscallarg(struct sigvec *) nsv;
   1519  1.7.2.2  bouyer 		syscallarg(struct sigvec *) osv;
   1520  1.7.2.2  bouyer 	} */ *uap = v;
   1521  1.7.2.2  bouyer 	struct netbsd32_sigvec sv;
   1522  1.7.2.2  bouyer 	struct sigaction nsa, osa;
   1523  1.7.2.2  bouyer 	int error;
   1524  1.7.2.2  bouyer 
   1525  1.7.2.2  bouyer 	if (SCARG(uap, nsv)) {
   1526  1.7.2.2  bouyer 		error = copyin((caddr_t)(u_long)SCARG(uap, nsv), &sv, sizeof(sv));
   1527  1.7.2.2  bouyer 		if (error != 0)
   1528  1.7.2.2  bouyer 			return (error);
   1529  1.7.2.2  bouyer 
   1530  1.7.2.2  bouyer 		/*
   1531  1.7.2.2  bouyer 		 * SunOS uses the mask 0x0004 as SV_RESETHAND
   1532  1.7.2.2  bouyer 		 * meaning: `reset to SIG_DFL on delivery'.
   1533  1.7.2.2  bouyer 		 * We support only the bits in: 0xF
   1534  1.7.2.2  bouyer 		 * (those bits are the same as ours)
   1535  1.7.2.2  bouyer 		 */
   1536  1.7.2.2  bouyer 		if (sv.sv_flags & ~0xF)
   1537  1.7.2.2  bouyer 			return (EINVAL);
   1538  1.7.2.2  bouyer 
   1539  1.7.2.2  bouyer 		sunos32_sigvec_to_sigaction(&sv, &nsa);
   1540  1.7.2.2  bouyer 	}
   1541  1.7.2.2  bouyer 	error = sigaction1(p, SCARG(uap, signum),
   1542  1.7.2.2  bouyer 			   SCARG(uap, nsv) ? &nsa : 0,
   1543  1.7.2.2  bouyer 			   SCARG(uap, osv) ? &osa : 0);
   1544  1.7.2.2  bouyer 	if (error != 0)
   1545  1.7.2.2  bouyer 		return (error);
   1546  1.7.2.2  bouyer 
   1547  1.7.2.2  bouyer 	if (SCARG(uap, osv)) {
   1548  1.7.2.2  bouyer 		sunos32_sigvec_from_sigaction(&sv, &osa);
   1549  1.7.2.2  bouyer 		error = copyout(&sv, (caddr_t)(u_long)SCARG(uap, osv), sizeof(sv));
   1550  1.7.2.2  bouyer 		if (error != 0)
   1551  1.7.2.2  bouyer 			return (error);
   1552  1.7.2.2  bouyer 	}
   1553  1.7.2.2  bouyer 
   1554  1.7.2.2  bouyer 	return (0);
   1555  1.7.2.2  bouyer }
   1556