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