xref: /illumos-gate/usr/src/uts/common/fs/proc/prioctl.c (revision fa9e4066f08beec538e775443c5be79dd423fcab)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*fa9e4066Sahrens  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All rights reserved.  	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.29	*/
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <sys/param.h>
357c478bd9Sstevel@tonic-gate #include <sys/vmparam.h>
367c478bd9Sstevel@tonic-gate #include <sys/var.h>
377c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
387c478bd9Sstevel@tonic-gate #include <sys/cred.h>
397c478bd9Sstevel@tonic-gate #include <sys/debug.h>
407c478bd9Sstevel@tonic-gate #include <sys/errno.h>
417c478bd9Sstevel@tonic-gate #include <sys/file.h>
427c478bd9Sstevel@tonic-gate #include <sys/inline.h>
437c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
447c478bd9Sstevel@tonic-gate #include <sys/proc.h>
457c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
467c478bd9Sstevel@tonic-gate #include <sys/systm.h>
477c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
487c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
497c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
507c478bd9Sstevel@tonic-gate #include <sys/session.h>
517c478bd9Sstevel@tonic-gate #include <sys/signal.h>
527c478bd9Sstevel@tonic-gate #include <sys/auxv.h>
537c478bd9Sstevel@tonic-gate #include <sys/user.h>
547c478bd9Sstevel@tonic-gate #include <sys/disp.h>
557c478bd9Sstevel@tonic-gate #include <sys/class.h>
567c478bd9Sstevel@tonic-gate #include <sys/ts.h>
577c478bd9Sstevel@tonic-gate #include <sys/mman.h>
587c478bd9Sstevel@tonic-gate #include <sys/fault.h>
597c478bd9Sstevel@tonic-gate #include <sys/syscall.h>
607c478bd9Sstevel@tonic-gate #include <sys/schedctl.h>
617c478bd9Sstevel@tonic-gate #include <sys/pset.h>
627c478bd9Sstevel@tonic-gate #include <sys/old_procfs.h>
637c478bd9Sstevel@tonic-gate #include <sys/zone.h>
647c478bd9Sstevel@tonic-gate #include <sys/time.h>
657c478bd9Sstevel@tonic-gate #include <sys/msacct.h>
667c478bd9Sstevel@tonic-gate #include <vm/rm.h>
677c478bd9Sstevel@tonic-gate #include <vm/as.h>
687c478bd9Sstevel@tonic-gate #include <vm/rm.h>
697c478bd9Sstevel@tonic-gate #include <vm/seg.h>
707c478bd9Sstevel@tonic-gate #include <vm/seg_vn.h>
717c478bd9Sstevel@tonic-gate #include <sys/contract_impl.h>
727c478bd9Sstevel@tonic-gate #include <sys/ctfs_impl.h>
737c478bd9Sstevel@tonic-gate #include <sys/ctfs.h>
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__i386_COMPAT)
767c478bd9Sstevel@tonic-gate #include <sys/sysi86.h>
777c478bd9Sstevel@tonic-gate #endif
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate #include <fs/proc/prdata.h>
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate static	int	isprwrioctl(int);
827c478bd9Sstevel@tonic-gate static	ulong_t	prmaprunflags(long);
837c478bd9Sstevel@tonic-gate static	long	prmapsetflags(long);
847c478bd9Sstevel@tonic-gate static	void	prsetrun(kthread_t *, prrun_t *);
857c478bd9Sstevel@tonic-gate static	int	propenm(prnode_t *, caddr_t, caddr_t, int *, cred_t *);
867c478bd9Sstevel@tonic-gate extern	void	oprgetstatus(kthread_t *, prstatus_t *, zone_t *);
877c478bd9Sstevel@tonic-gate extern	void	oprgetpsinfo(proc_t *, prpsinfo_t *, kthread_t *);
887c478bd9Sstevel@tonic-gate static	int	oprgetmap(proc_t *, prmap_t **, size_t *);
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate /*ARGSUSED*/
917c478bd9Sstevel@tonic-gate static int
927c478bd9Sstevel@tonic-gate prctioctl(prnode_t *pnp, int cmd, intptr_t arg, int flag, cred_t *cr)
937c478bd9Sstevel@tonic-gate {
947c478bd9Sstevel@tonic-gate 	int error = 0;
957c478bd9Sstevel@tonic-gate 	ct_param_t param;
967c478bd9Sstevel@tonic-gate 	ct_template_t *tmpl;
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate 	if (cmd != CT_TSET && cmd != CT_TGET)
997c478bd9Sstevel@tonic-gate 		return (EINVAL);
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 	if (copyin((void *)arg, &param, sizeof (ct_param_t)))
1027c478bd9Sstevel@tonic-gate 		return (EFAULT);
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 	if ((error = prlock(pnp, ZNO)) != 0)
1057c478bd9Sstevel@tonic-gate 		return (error);
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 	tmpl = pnp->pr_common->prc_thread->t_lwp->lwp_ct_active[pnp->pr_cttype];
1087c478bd9Sstevel@tonic-gate 	if (tmpl == NULL) {
1097c478bd9Sstevel@tonic-gate 		prunlock(pnp);
1107c478bd9Sstevel@tonic-gate 		return (ESTALE);
1117c478bd9Sstevel@tonic-gate 	}
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 	if (cmd == CT_TSET)
1147c478bd9Sstevel@tonic-gate 		error = ctmpl_set(tmpl, &param, cr);
1157c478bd9Sstevel@tonic-gate 	else
1167c478bd9Sstevel@tonic-gate 		error = ctmpl_get(tmpl, &param);
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 	prunlock(pnp);
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 	if (cmd == CT_TGET && error == 0 &&
1217c478bd9Sstevel@tonic-gate 	    copyout(&param, (void *)arg, sizeof (ct_param_t)))
1227c478bd9Sstevel@tonic-gate 		error = EFAULT;
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 	return (error);
1257c478bd9Sstevel@tonic-gate }
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate  * Control operations (lots).
1307c478bd9Sstevel@tonic-gate  */
1317c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
1327c478bd9Sstevel@tonic-gate static int
1337c478bd9Sstevel@tonic-gate prioctl64(struct vnode *vp, int cmd, intptr_t arg, int flag,
1347c478bd9Sstevel@tonic-gate     cred_t *cr, int *rvalp)
1357c478bd9Sstevel@tonic-gate #else
1367c478bd9Sstevel@tonic-gate int
1377c478bd9Sstevel@tonic-gate prioctl(struct vnode *vp, int cmd, intptr_t arg, int flag,
1387c478bd9Sstevel@tonic-gate     cred_t *cr, int *rvalp)
1397c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32_IMPL */
1407c478bd9Sstevel@tonic-gate {
1417c478bd9Sstevel@tonic-gate 	caddr_t cmaddr = (caddr_t)arg;
1427c478bd9Sstevel@tonic-gate 	proc_t *p;
1437c478bd9Sstevel@tonic-gate 	user_t *up;
1447c478bd9Sstevel@tonic-gate 	kthread_t *t;
1457c478bd9Sstevel@tonic-gate 	klwp_t *lwp;
1467c478bd9Sstevel@tonic-gate 	prnode_t *pnp = VTOP(vp);
1477c478bd9Sstevel@tonic-gate 	prcommon_t *pcp;
1487c478bd9Sstevel@tonic-gate 	prnode_t *xpnp = NULL;
1497c478bd9Sstevel@tonic-gate 	int error;
1507c478bd9Sstevel@tonic-gate 	int zdisp;
1517c478bd9Sstevel@tonic-gate 	void *thing = NULL;
1527c478bd9Sstevel@tonic-gate 	size_t thingsize = 0;
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 	/*
1557c478bd9Sstevel@tonic-gate 	 * For copyin()/copyout().
1567c478bd9Sstevel@tonic-gate 	 */
1577c478bd9Sstevel@tonic-gate 	union {
1587c478bd9Sstevel@tonic-gate 		caddr_t		va;
1597c478bd9Sstevel@tonic-gate 		int		signo;
1607c478bd9Sstevel@tonic-gate 		int		nice;
1617c478bd9Sstevel@tonic-gate 		uint_t		lwpid;
1627c478bd9Sstevel@tonic-gate 		long		flags;
1637c478bd9Sstevel@tonic-gate 		prstatus_t	prstat;
1647c478bd9Sstevel@tonic-gate 		prrun_t		prrun;
1657c478bd9Sstevel@tonic-gate 		sigset_t	smask;
1667c478bd9Sstevel@tonic-gate 		siginfo_t	info;
1677c478bd9Sstevel@tonic-gate 		sysset_t	prmask;
1687c478bd9Sstevel@tonic-gate 		prgregset_t	regs;
1697c478bd9Sstevel@tonic-gate 		prfpregset_t	fpregs;
1707c478bd9Sstevel@tonic-gate 		prpsinfo_t	prps;
1717c478bd9Sstevel@tonic-gate 		sigset_t	holdmask;
1727c478bd9Sstevel@tonic-gate 		fltset_t	fltmask;
1737c478bd9Sstevel@tonic-gate 		prcred_t	prcred;
1747c478bd9Sstevel@tonic-gate 		prhusage_t	prhusage;
1757c478bd9Sstevel@tonic-gate 		prmap_t		prmap;
1767c478bd9Sstevel@tonic-gate 		auxv_t		auxv[__KERN_NAUXV_IMPL];
1777c478bd9Sstevel@tonic-gate 	} un;
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 	if (pnp->pr_type == PR_TMPL)
1807c478bd9Sstevel@tonic-gate 		return (prctioctl(pnp, cmd, arg, flag, cr));
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate 	/*
1837c478bd9Sstevel@tonic-gate 	 * Support for old /proc interface.
1847c478bd9Sstevel@tonic-gate 	 */
1857c478bd9Sstevel@tonic-gate 	if (pnp->pr_pidfile != NULL) {
1867c478bd9Sstevel@tonic-gate 		ASSERT(pnp->pr_type == PR_PIDDIR);
1877c478bd9Sstevel@tonic-gate 		vp = pnp->pr_pidfile;
1887c478bd9Sstevel@tonic-gate 		pnp = VTOP(vp);
1897c478bd9Sstevel@tonic-gate 		ASSERT(pnp->pr_type == PR_PIDFILE);
1907c478bd9Sstevel@tonic-gate 	}
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate 	if (pnp->pr_type != PR_PIDFILE && pnp->pr_type != PR_LWPIDFILE)
1937c478bd9Sstevel@tonic-gate 		return (ENOTTY);
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate 	/*
1967c478bd9Sstevel@tonic-gate 	 * Fail ioctls which are logically "write" requests unless
1977c478bd9Sstevel@tonic-gate 	 * the user has write permission.
1987c478bd9Sstevel@tonic-gate 	 */
1997c478bd9Sstevel@tonic-gate 	if ((flag & FWRITE) == 0 && isprwrioctl(cmd))
2007c478bd9Sstevel@tonic-gate 		return (EBADF);
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 	/*
2037c478bd9Sstevel@tonic-gate 	 * Perform any necessary copyin() operations before
2047c478bd9Sstevel@tonic-gate 	 * locking the process.  Helps avoid deadlocks and
2057c478bd9Sstevel@tonic-gate 	 * improves performance.
2067c478bd9Sstevel@tonic-gate 	 *
2077c478bd9Sstevel@tonic-gate 	 * Also, detect invalid ioctl codes here to avoid
2087c478bd9Sstevel@tonic-gate 	 * locking a process unnnecessarily.
2097c478bd9Sstevel@tonic-gate 	 *
2107c478bd9Sstevel@tonic-gate 	 * Also, prepare to allocate space that will be needed below,
2117c478bd9Sstevel@tonic-gate 	 * case by case.
2127c478bd9Sstevel@tonic-gate 	 */
2137c478bd9Sstevel@tonic-gate 	error = 0;
2147c478bd9Sstevel@tonic-gate 	switch (cmd) {
2157c478bd9Sstevel@tonic-gate 	case PIOCGETPR:
2167c478bd9Sstevel@tonic-gate 		thingsize = sizeof (proc_t);
2177c478bd9Sstevel@tonic-gate 		break;
2187c478bd9Sstevel@tonic-gate 	case PIOCGETU:
2197c478bd9Sstevel@tonic-gate 		thingsize = sizeof (user_t);
2207c478bd9Sstevel@tonic-gate 		break;
2217c478bd9Sstevel@tonic-gate 	case PIOCSTOP:
2227c478bd9Sstevel@tonic-gate 	case PIOCWSTOP:
2237c478bd9Sstevel@tonic-gate 	case PIOCLWPIDS:
2247c478bd9Sstevel@tonic-gate 	case PIOCGTRACE:
2257c478bd9Sstevel@tonic-gate 	case PIOCGENTRY:
2267c478bd9Sstevel@tonic-gate 	case PIOCGEXIT:
2277c478bd9Sstevel@tonic-gate 	case PIOCSRLC:
2287c478bd9Sstevel@tonic-gate 	case PIOCRRLC:
2297c478bd9Sstevel@tonic-gate 	case PIOCSFORK:
2307c478bd9Sstevel@tonic-gate 	case PIOCRFORK:
2317c478bd9Sstevel@tonic-gate 	case PIOCGREG:
2327c478bd9Sstevel@tonic-gate 	case PIOCGFPREG:
2337c478bd9Sstevel@tonic-gate 	case PIOCSTATUS:
2347c478bd9Sstevel@tonic-gate 	case PIOCLSTATUS:
2357c478bd9Sstevel@tonic-gate 	case PIOCPSINFO:
2367c478bd9Sstevel@tonic-gate 	case PIOCMAXSIG:
2377c478bd9Sstevel@tonic-gate 	case PIOCGXREGSIZE:
2387c478bd9Sstevel@tonic-gate 		break;
2397c478bd9Sstevel@tonic-gate 	case PIOCSXREG:		/* set extra registers */
2407c478bd9Sstevel@tonic-gate 	case PIOCGXREG:		/* get extra registers */
2417c478bd9Sstevel@tonic-gate #if defined(__sparc)
2427c478bd9Sstevel@tonic-gate 		thingsize = sizeof (prxregset_t);
2437c478bd9Sstevel@tonic-gate #else
2447c478bd9Sstevel@tonic-gate 		thingsize = 0;
2457c478bd9Sstevel@tonic-gate #endif
2467c478bd9Sstevel@tonic-gate 		break;
2477c478bd9Sstevel@tonic-gate 	case PIOCACTION:
2487c478bd9Sstevel@tonic-gate 		thingsize = (NSIG-1) * sizeof (struct sigaction);
2497c478bd9Sstevel@tonic-gate 		break;
2507c478bd9Sstevel@tonic-gate 	case PIOCGHOLD:
2517c478bd9Sstevel@tonic-gate 	case PIOCNMAP:
2527c478bd9Sstevel@tonic-gate 	case PIOCMAP:
2537c478bd9Sstevel@tonic-gate 	case PIOCGFAULT:
2547c478bd9Sstevel@tonic-gate 	case PIOCCFAULT:
2557c478bd9Sstevel@tonic-gate 	case PIOCCRED:
2567c478bd9Sstevel@tonic-gate 	case PIOCGROUPS:
2577c478bd9Sstevel@tonic-gate 	case PIOCUSAGE:
2587c478bd9Sstevel@tonic-gate 	case PIOCLUSAGE:
2597c478bd9Sstevel@tonic-gate 		break;
2607c478bd9Sstevel@tonic-gate 	case PIOCOPENPD:
2617c478bd9Sstevel@tonic-gate 		/*
2627c478bd9Sstevel@tonic-gate 		 * We will need this below.
2637c478bd9Sstevel@tonic-gate 		 * Allocate it now, before locking the process.
2647c478bd9Sstevel@tonic-gate 		 */
2657c478bd9Sstevel@tonic-gate 		xpnp = prgetnode(vp, PR_OPAGEDATA);
2667c478bd9Sstevel@tonic-gate 		break;
2677c478bd9Sstevel@tonic-gate 	case PIOCNAUXV:
2687c478bd9Sstevel@tonic-gate 	case PIOCAUXV:
2697c478bd9Sstevel@tonic-gate 		break;
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
2727c478bd9Sstevel@tonic-gate 	case PIOCNLDT:
2737c478bd9Sstevel@tonic-gate 	case PIOCLDT:
2747c478bd9Sstevel@tonic-gate 		break;
2757c478bd9Sstevel@tonic-gate #endif	/* __i386 || __amd64 */
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate #if defined(__sparc)
2787c478bd9Sstevel@tonic-gate 	case PIOCGWIN:
2797c478bd9Sstevel@tonic-gate 		thingsize = sizeof (gwindows_t);
2807c478bd9Sstevel@tonic-gate 		break;
2817c478bd9Sstevel@tonic-gate #endif	/* __sparc */
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 	case PIOCOPENM:		/* open mapped object for reading */
2847c478bd9Sstevel@tonic-gate 		if (cmaddr == NULL)
2857c478bd9Sstevel@tonic-gate 			un.va = NULL;
2867c478bd9Sstevel@tonic-gate 		else if (copyin(cmaddr, &un.va, sizeof (un.va)))
2877c478bd9Sstevel@tonic-gate 			error = EFAULT;
2887c478bd9Sstevel@tonic-gate 		break;
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 	case PIOCRUN:		/* make lwp or process runnable */
2917c478bd9Sstevel@tonic-gate 		if (cmaddr == NULL)
2927c478bd9Sstevel@tonic-gate 			un.prrun.pr_flags = 0;
2937c478bd9Sstevel@tonic-gate 		else if (copyin(cmaddr, &un.prrun, sizeof (un.prrun)))
2947c478bd9Sstevel@tonic-gate 			error = EFAULT;
2957c478bd9Sstevel@tonic-gate 		break;
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate 	case PIOCOPENLWP:	/* return /proc lwp file descriptor */
2987c478bd9Sstevel@tonic-gate 		if (copyin(cmaddr, &un.lwpid, sizeof (un.lwpid)))
2997c478bd9Sstevel@tonic-gate 			error = EFAULT;
3007c478bd9Sstevel@tonic-gate 		break;
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate 	case PIOCSTRACE:	/* set signal trace mask */
3037c478bd9Sstevel@tonic-gate 		if (copyin(cmaddr, &un.smask, sizeof (un.smask)))
3047c478bd9Sstevel@tonic-gate 			error = EFAULT;
3057c478bd9Sstevel@tonic-gate 		break;
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 	case PIOCSSIG:		/* set current signal */
3087c478bd9Sstevel@tonic-gate 		if (cmaddr == NULL)
3097c478bd9Sstevel@tonic-gate 			un.info.si_signo = 0;
3107c478bd9Sstevel@tonic-gate 		else if (copyin(cmaddr, &un.info, sizeof (un.info)))
3117c478bd9Sstevel@tonic-gate 			error = EFAULT;
3127c478bd9Sstevel@tonic-gate 		break;
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate 	case PIOCKILL:		/* send signal */
3157c478bd9Sstevel@tonic-gate 	case PIOCUNKILL:	/* delete a signal */
3167c478bd9Sstevel@tonic-gate 		if (copyin(cmaddr, &un.signo, sizeof (un.signo)))
3177c478bd9Sstevel@tonic-gate 			error = EFAULT;
3187c478bd9Sstevel@tonic-gate 		break;
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 	case PIOCNICE:		/* set nice priority */
3217c478bd9Sstevel@tonic-gate 		if (copyin(cmaddr, &un.nice, sizeof (un.nice)))
3227c478bd9Sstevel@tonic-gate 			error = EFAULT;
3237c478bd9Sstevel@tonic-gate 		break;
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate 	case PIOCSENTRY:	/* set syscall entry bit mask */
3267c478bd9Sstevel@tonic-gate 	case PIOCSEXIT:		/* set syscall exit bit mask */
3277c478bd9Sstevel@tonic-gate 		if (copyin(cmaddr, &un.prmask, sizeof (un.prmask)))
3287c478bd9Sstevel@tonic-gate 			error = EFAULT;
3297c478bd9Sstevel@tonic-gate 		break;
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 	case PIOCSET:		/* set process flags */
3327c478bd9Sstevel@tonic-gate 	case PIOCRESET:		/* reset process flags */
3337c478bd9Sstevel@tonic-gate 		if (copyin(cmaddr, &un.flags, sizeof (un.flags)))
3347c478bd9Sstevel@tonic-gate 			error = EFAULT;
3357c478bd9Sstevel@tonic-gate 		break;
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate 	case PIOCSREG:		/* set general registers */
3387c478bd9Sstevel@tonic-gate 		if (copyin(cmaddr, un.regs, sizeof (un.regs)))
3397c478bd9Sstevel@tonic-gate 			error = EFAULT;
3407c478bd9Sstevel@tonic-gate 		break;
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate 	case PIOCSFPREG:	/* set floating-point registers */
3437c478bd9Sstevel@tonic-gate 		if (copyin(cmaddr, &un.fpregs, sizeof (un.fpregs)))
3447c478bd9Sstevel@tonic-gate 			error = EFAULT;
3457c478bd9Sstevel@tonic-gate 		break;
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate 	case PIOCSHOLD:		/* set signal-hold mask */
3487c478bd9Sstevel@tonic-gate 		if (copyin(cmaddr, &un.holdmask, sizeof (un.holdmask)))
3497c478bd9Sstevel@tonic-gate 			error = EFAULT;
3507c478bd9Sstevel@tonic-gate 		break;
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 	case PIOCSFAULT:	/* set mask of traced faults */
3537c478bd9Sstevel@tonic-gate 		if (copyin(cmaddr, &un.fltmask, sizeof (un.fltmask)))
3547c478bd9Sstevel@tonic-gate 			error = EFAULT;
3557c478bd9Sstevel@tonic-gate 		break;
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate 	default:
3587c478bd9Sstevel@tonic-gate 		error = EINVAL;
3597c478bd9Sstevel@tonic-gate 		break;
3607c478bd9Sstevel@tonic-gate 	}
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate 	if (error)
3637c478bd9Sstevel@tonic-gate 		return (error);
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate startover:
3667c478bd9Sstevel@tonic-gate 	/*
3677c478bd9Sstevel@tonic-gate 	 * If we need kmem_alloc()d space then we allocate it now, before
3687c478bd9Sstevel@tonic-gate 	 * grabbing the process lock.  Using kmem_alloc(KM_SLEEP) while
3697c478bd9Sstevel@tonic-gate 	 * holding the process lock leads to deadlock with the clock thread.
3707c478bd9Sstevel@tonic-gate 	 * (The clock thread wakes up the pageout daemon to free up space.
3717c478bd9Sstevel@tonic-gate 	 * If the clock thread blocks behind us and we are sleeping waiting
3727c478bd9Sstevel@tonic-gate 	 * for space, then space may never become available.)
3737c478bd9Sstevel@tonic-gate 	 */
3747c478bd9Sstevel@tonic-gate 	if (thingsize) {
3757c478bd9Sstevel@tonic-gate 		ASSERT(thing == NULL);
3767c478bd9Sstevel@tonic-gate 		thing = kmem_alloc(thingsize, KM_SLEEP);
3777c478bd9Sstevel@tonic-gate 	}
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate 	switch (cmd) {
3807c478bd9Sstevel@tonic-gate 	case PIOCPSINFO:
3817c478bd9Sstevel@tonic-gate 	case PIOCGETPR:
3827c478bd9Sstevel@tonic-gate 	case PIOCUSAGE:
3837c478bd9Sstevel@tonic-gate 	case PIOCLUSAGE:
3847c478bd9Sstevel@tonic-gate 		zdisp = ZYES;
3857c478bd9Sstevel@tonic-gate 		break;
3867c478bd9Sstevel@tonic-gate 	case PIOCSXREG:		/* set extra registers */
3877c478bd9Sstevel@tonic-gate 		/*
3887c478bd9Sstevel@tonic-gate 		 * perform copyin before grabbing the process lock
3897c478bd9Sstevel@tonic-gate 		 */
3907c478bd9Sstevel@tonic-gate 		if (thing) {
3917c478bd9Sstevel@tonic-gate 			if (copyin(cmaddr, thing, thingsize)) {
3927c478bd9Sstevel@tonic-gate 				kmem_free(thing, thingsize);
3937c478bd9Sstevel@tonic-gate 				return (EFAULT);
3947c478bd9Sstevel@tonic-gate 			}
3957c478bd9Sstevel@tonic-gate 		}
3967c478bd9Sstevel@tonic-gate 		/* fall through... */
3977c478bd9Sstevel@tonic-gate 	default:
3987c478bd9Sstevel@tonic-gate 		zdisp = ZNO;
3997c478bd9Sstevel@tonic-gate 		break;
4007c478bd9Sstevel@tonic-gate 	}
4017c478bd9Sstevel@tonic-gate 
4027c478bd9Sstevel@tonic-gate 	if ((error = prlock(pnp, zdisp)) != 0) {
4037c478bd9Sstevel@tonic-gate 		if (thing != NULL)
4047c478bd9Sstevel@tonic-gate 			kmem_free(thing, thingsize);
4057c478bd9Sstevel@tonic-gate 		if (xpnp)
4067c478bd9Sstevel@tonic-gate 			prfreenode(xpnp);
4077c478bd9Sstevel@tonic-gate 		return (error);
4087c478bd9Sstevel@tonic-gate 	}
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate 	pcp = pnp->pr_common;
4117c478bd9Sstevel@tonic-gate 	p = pcp->prc_proc;
4127c478bd9Sstevel@tonic-gate 	ASSERT(p != NULL);
4137c478bd9Sstevel@tonic-gate 
4147c478bd9Sstevel@tonic-gate 	/*
4157c478bd9Sstevel@tonic-gate 	 * Choose a thread/lwp for the operation.
4167c478bd9Sstevel@tonic-gate 	 */
4177c478bd9Sstevel@tonic-gate 	if (zdisp == ZNO && cmd != PIOCSTOP && cmd != PIOCWSTOP) {
4187c478bd9Sstevel@tonic-gate 		if (pnp->pr_type == PR_LWPIDFILE && cmd != PIOCLSTATUS) {
4197c478bd9Sstevel@tonic-gate 			t = pcp->prc_thread;
4207c478bd9Sstevel@tonic-gate 			ASSERT(t != NULL);
4217c478bd9Sstevel@tonic-gate 		} else {
4227c478bd9Sstevel@tonic-gate 			t = prchoose(p);	/* returns locked thread */
4237c478bd9Sstevel@tonic-gate 			ASSERT(t != NULL);
4247c478bd9Sstevel@tonic-gate 			thread_unlock(t);
4257c478bd9Sstevel@tonic-gate 		}
4267c478bd9Sstevel@tonic-gate 		lwp = ttolwp(t);
4277c478bd9Sstevel@tonic-gate 	}
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate 	error = 0;
4307c478bd9Sstevel@tonic-gate 	switch (cmd) {
4317c478bd9Sstevel@tonic-gate 
4327c478bd9Sstevel@tonic-gate 	case PIOCGETPR:		/* read struct proc */
4337c478bd9Sstevel@tonic-gate 	{
4347c478bd9Sstevel@tonic-gate 		proc_t *prp = thing;
4357c478bd9Sstevel@tonic-gate 
4367c478bd9Sstevel@tonic-gate 		*prp = *p;
4377c478bd9Sstevel@tonic-gate 		prunlock(pnp);
4387c478bd9Sstevel@tonic-gate 		if (copyout(prp, cmaddr, sizeof (proc_t)))
4397c478bd9Sstevel@tonic-gate 			error = EFAULT;
4407c478bd9Sstevel@tonic-gate 		kmem_free(prp, sizeof (proc_t));
4417c478bd9Sstevel@tonic-gate 		thing = NULL;
4427c478bd9Sstevel@tonic-gate 		break;
4437c478bd9Sstevel@tonic-gate 	}
4447c478bd9Sstevel@tonic-gate 
4457c478bd9Sstevel@tonic-gate 	case PIOCGETU:		/* read u-area */
4467c478bd9Sstevel@tonic-gate 	{
4477c478bd9Sstevel@tonic-gate 		user_t *userp = thing;
4487c478bd9Sstevel@tonic-gate 
4497c478bd9Sstevel@tonic-gate 		up = PTOU(p);
4507c478bd9Sstevel@tonic-gate 		*userp = *up;
4517c478bd9Sstevel@tonic-gate 		prunlock(pnp);
4527c478bd9Sstevel@tonic-gate 		if (copyout(userp, cmaddr, sizeof (user_t)))
4537c478bd9Sstevel@tonic-gate 			error = EFAULT;
4547c478bd9Sstevel@tonic-gate 		kmem_free(userp, sizeof (user_t));
4557c478bd9Sstevel@tonic-gate 		thing = NULL;
4567c478bd9Sstevel@tonic-gate 		break;
4577c478bd9Sstevel@tonic-gate 	}
4587c478bd9Sstevel@tonic-gate 
4597c478bd9Sstevel@tonic-gate 	case PIOCOPENM:		/* open mapped object for reading */
4607c478bd9Sstevel@tonic-gate 		error = propenm(pnp, cmaddr, un.va, rvalp, cr);
4617c478bd9Sstevel@tonic-gate 		/* propenm() called prunlock(pnp) */
4627c478bd9Sstevel@tonic-gate 		break;
4637c478bd9Sstevel@tonic-gate 
4647c478bd9Sstevel@tonic-gate 	case PIOCSTOP:		/* stop process or lwp from running */
4657c478bd9Sstevel@tonic-gate 	case PIOCWSTOP:		/* wait for process or lwp to stop */
4667c478bd9Sstevel@tonic-gate 		/*
4677c478bd9Sstevel@tonic-gate 		 * Can't apply to a system process.
4687c478bd9Sstevel@tonic-gate 		 */
4697c478bd9Sstevel@tonic-gate 		if ((p->p_flag & SSYS) || p->p_as == &kas) {
4707c478bd9Sstevel@tonic-gate 			prunlock(pnp);
4717c478bd9Sstevel@tonic-gate 			error = EBUSY;
4727c478bd9Sstevel@tonic-gate 			break;
4737c478bd9Sstevel@tonic-gate 		}
4747c478bd9Sstevel@tonic-gate 
4757c478bd9Sstevel@tonic-gate 		if (cmd == PIOCSTOP)
4767c478bd9Sstevel@tonic-gate 			pr_stop(pnp);
4777c478bd9Sstevel@tonic-gate 
4787c478bd9Sstevel@tonic-gate 		/*
4797c478bd9Sstevel@tonic-gate 		 * If an lwp is waiting for itself or its process, don't wait.
4807c478bd9Sstevel@tonic-gate 		 * The stopped lwp would never see the fact that it is stopped.
4817c478bd9Sstevel@tonic-gate 		 */
4827c478bd9Sstevel@tonic-gate 		if ((pnp->pr_type == PR_LWPIDFILE)?
4837c478bd9Sstevel@tonic-gate 		    (pcp->prc_thread == curthread) : (p == curproc)) {
4847c478bd9Sstevel@tonic-gate 			if (cmd == PIOCWSTOP)
4857c478bd9Sstevel@tonic-gate 				error = EBUSY;
4867c478bd9Sstevel@tonic-gate 			prunlock(pnp);
4877c478bd9Sstevel@tonic-gate 			break;
4887c478bd9Sstevel@tonic-gate 		}
4897c478bd9Sstevel@tonic-gate 
4907c478bd9Sstevel@tonic-gate 		if ((error = pr_wait_stop(pnp, (time_t)0)) != 0)
4917c478bd9Sstevel@tonic-gate 			break;	/* pr_wait_stop() unlocked the process */
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate 		if (cmaddr == NULL)
4947c478bd9Sstevel@tonic-gate 			prunlock(pnp);
4957c478bd9Sstevel@tonic-gate 		else {
4967c478bd9Sstevel@tonic-gate 			/*
4977c478bd9Sstevel@tonic-gate 			 * Return process/lwp status information.
4987c478bd9Sstevel@tonic-gate 			 */
4997c478bd9Sstevel@tonic-gate 			t = pr_thread(pnp);	/* returns locked thread */
5007c478bd9Sstevel@tonic-gate 			thread_unlock(t);
501*fa9e4066Sahrens 			oprgetstatus(t, &un.prstat, VTOZONE(vp));
5027c478bd9Sstevel@tonic-gate 			prunlock(pnp);
5037c478bd9Sstevel@tonic-gate 			if (copyout(&un.prstat, cmaddr, sizeof (un.prstat)))
5047c478bd9Sstevel@tonic-gate 				error = EFAULT;
5057c478bd9Sstevel@tonic-gate 		}
5067c478bd9Sstevel@tonic-gate 		break;
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate 	case PIOCRUN:		/* make lwp or process runnable */
5097c478bd9Sstevel@tonic-gate 	{
5107c478bd9Sstevel@tonic-gate 		long flags = un.prrun.pr_flags;
5117c478bd9Sstevel@tonic-gate 
5127c478bd9Sstevel@tonic-gate 		/*
5137c478bd9Sstevel@tonic-gate 		 * Cannot set an lwp running is it is not stopped.
5147c478bd9Sstevel@tonic-gate 		 * Also, no lwp other than the /proc agent lwp can
5157c478bd9Sstevel@tonic-gate 		 * be set running so long as the /proc agent lwp exists.
5167c478bd9Sstevel@tonic-gate 		 */
5177c478bd9Sstevel@tonic-gate 		if ((!ISTOPPED(t) && !VSTOPPED(t) &&
5187c478bd9Sstevel@tonic-gate 		    !(t->t_proc_flag & TP_PRSTOP)) ||
5197c478bd9Sstevel@tonic-gate 		    (p->p_agenttp != NULL &&
5207c478bd9Sstevel@tonic-gate 		    (t != p->p_agenttp || pnp->pr_type != PR_LWPIDFILE))) {
5217c478bd9Sstevel@tonic-gate 			prunlock(pnp);
5227c478bd9Sstevel@tonic-gate 			error = EBUSY;
5237c478bd9Sstevel@tonic-gate 			break;
5247c478bd9Sstevel@tonic-gate 		}
5257c478bd9Sstevel@tonic-gate 
5267c478bd9Sstevel@tonic-gate 		if (flags & (PRSHOLD|PRSTRACE|PRSFAULT|PRSVADDR))
5277c478bd9Sstevel@tonic-gate 			prsetrun(t, &un.prrun);
5287c478bd9Sstevel@tonic-gate 
5297c478bd9Sstevel@tonic-gate 		error = pr_setrun(pnp, prmaprunflags(flags));
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate 		prunlock(pnp);
5327c478bd9Sstevel@tonic-gate 		break;
5337c478bd9Sstevel@tonic-gate 	}
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate 	case PIOCLWPIDS:	/* get array of lwp identifiers */
5367c478bd9Sstevel@tonic-gate 	{
5377c478bd9Sstevel@tonic-gate 		int nlwp;
5387c478bd9Sstevel@tonic-gate 		int Nlwp;
5397c478bd9Sstevel@tonic-gate 		id_t *idp;
5407c478bd9Sstevel@tonic-gate 		id_t *Bidp;
5417c478bd9Sstevel@tonic-gate 
5427c478bd9Sstevel@tonic-gate 		Nlwp = nlwp = p->p_lwpcnt;
5437c478bd9Sstevel@tonic-gate 
5447c478bd9Sstevel@tonic-gate 		if (thing && thingsize != (Nlwp+1) * sizeof (id_t)) {
5457c478bd9Sstevel@tonic-gate 			kmem_free(thing, thingsize);
5467c478bd9Sstevel@tonic-gate 			thing = NULL;
5477c478bd9Sstevel@tonic-gate 		}
5487c478bd9Sstevel@tonic-gate 		if (thing == NULL) {
5497c478bd9Sstevel@tonic-gate 			thingsize = (Nlwp+1) * sizeof (id_t);
5507c478bd9Sstevel@tonic-gate 			thing = kmem_alloc(thingsize, KM_NOSLEEP);
5517c478bd9Sstevel@tonic-gate 		}
5527c478bd9Sstevel@tonic-gate 		if (thing == NULL) {
5537c478bd9Sstevel@tonic-gate 			prunlock(pnp);
5547c478bd9Sstevel@tonic-gate 			goto startover;
5557c478bd9Sstevel@tonic-gate 		}
5567c478bd9Sstevel@tonic-gate 
5577c478bd9Sstevel@tonic-gate 		idp = thing;
5587c478bd9Sstevel@tonic-gate 		thing = NULL;
5597c478bd9Sstevel@tonic-gate 		Bidp = idp;
5607c478bd9Sstevel@tonic-gate 		if ((t = p->p_tlist) != NULL) {
5617c478bd9Sstevel@tonic-gate 			do {
5627c478bd9Sstevel@tonic-gate 				ASSERT(!(t->t_proc_flag & TP_LWPEXIT));
5637c478bd9Sstevel@tonic-gate 				ASSERT(nlwp > 0);
5647c478bd9Sstevel@tonic-gate 				--nlwp;
5657c478bd9Sstevel@tonic-gate 				*idp++ = t->t_tid;
5667c478bd9Sstevel@tonic-gate 			} while ((t = t->t_forw) != p->p_tlist);
5677c478bd9Sstevel@tonic-gate 		}
5687c478bd9Sstevel@tonic-gate 		*idp = 0;
5697c478bd9Sstevel@tonic-gate 		ASSERT(nlwp == 0);
5707c478bd9Sstevel@tonic-gate 		prunlock(pnp);
5717c478bd9Sstevel@tonic-gate 		if (copyout(Bidp, cmaddr, (Nlwp+1) * sizeof (id_t)))
5727c478bd9Sstevel@tonic-gate 			error = EFAULT;
5737c478bd9Sstevel@tonic-gate 		kmem_free(Bidp, (Nlwp+1) * sizeof (id_t));
5747c478bd9Sstevel@tonic-gate 		break;
5757c478bd9Sstevel@tonic-gate 	}
5767c478bd9Sstevel@tonic-gate 
5777c478bd9Sstevel@tonic-gate 	case PIOCOPENLWP:	/* return /proc lwp file descriptor */
5787c478bd9Sstevel@tonic-gate 	{
5797c478bd9Sstevel@tonic-gate 		vnode_t *xvp;
5807c478bd9Sstevel@tonic-gate 		int n;
5817c478bd9Sstevel@tonic-gate 
5827c478bd9Sstevel@tonic-gate 		prunlock(pnp);
5837c478bd9Sstevel@tonic-gate 		if ((xvp = prlwpnode(pnp, un.lwpid)) == NULL)
5847c478bd9Sstevel@tonic-gate 			error = ENOENT;
5857c478bd9Sstevel@tonic-gate 		else if (error = fassign(&xvp, flag & (FREAD|FWRITE), &n)) {
5867c478bd9Sstevel@tonic-gate 			VN_RELE(xvp);
5877c478bd9Sstevel@tonic-gate 		} else
5887c478bd9Sstevel@tonic-gate 			*rvalp = n;
5897c478bd9Sstevel@tonic-gate 		break;
5907c478bd9Sstevel@tonic-gate 	}
5917c478bd9Sstevel@tonic-gate 
5927c478bd9Sstevel@tonic-gate 	case PIOCOPENPD:	/* return /proc page data file descriptor */
5937c478bd9Sstevel@tonic-gate 	{
5947c478bd9Sstevel@tonic-gate 		vnode_t *xvp = PTOV(xpnp);
5957c478bd9Sstevel@tonic-gate 		vnode_t *dp = pnp->pr_parent;
5967c478bd9Sstevel@tonic-gate 		int n;
5977c478bd9Sstevel@tonic-gate 
5987c478bd9Sstevel@tonic-gate 		if (pnp->pr_type == PR_LWPIDFILE) {
5997c478bd9Sstevel@tonic-gate 			dp = VTOP(dp)->pr_parent;
6007c478bd9Sstevel@tonic-gate 			dp = VTOP(dp)->pr_parent;
6017c478bd9Sstevel@tonic-gate 		}
6027c478bd9Sstevel@tonic-gate 		ASSERT(VTOP(dp)->pr_type == PR_PIDDIR);
6037c478bd9Sstevel@tonic-gate 
6047c478bd9Sstevel@tonic-gate 		VN_HOLD(dp);
6057c478bd9Sstevel@tonic-gate 		pcp = pnp->pr_pcommon;
6067c478bd9Sstevel@tonic-gate 		xpnp->pr_ino = ptoi(pcp->prc_pid);
6077c478bd9Sstevel@tonic-gate 		xpnp->pr_common = pcp;
6087c478bd9Sstevel@tonic-gate 		xpnp->pr_pcommon = pcp;
6097c478bd9Sstevel@tonic-gate 		xpnp->pr_parent = dp;
6107c478bd9Sstevel@tonic-gate 
6117c478bd9Sstevel@tonic-gate 		xpnp->pr_next = p->p_plist;
6127c478bd9Sstevel@tonic-gate 		p->p_plist = xvp;
6137c478bd9Sstevel@tonic-gate 
6147c478bd9Sstevel@tonic-gate 		prunlock(pnp);
6157c478bd9Sstevel@tonic-gate 		if (error = fassign(&xvp, FREAD, &n)) {
6167c478bd9Sstevel@tonic-gate 			VN_RELE(xvp);
6177c478bd9Sstevel@tonic-gate 		} else
6187c478bd9Sstevel@tonic-gate 			*rvalp = n;
6197c478bd9Sstevel@tonic-gate 
6207c478bd9Sstevel@tonic-gate 		xpnp = NULL;
6217c478bd9Sstevel@tonic-gate 		break;
6227c478bd9Sstevel@tonic-gate 	}
6237c478bd9Sstevel@tonic-gate 
6247c478bd9Sstevel@tonic-gate 	case PIOCGTRACE:	/* get signal trace mask */
6257c478bd9Sstevel@tonic-gate 		prassignset(&un.smask, &p->p_sigmask);
6267c478bd9Sstevel@tonic-gate 		prunlock(pnp);
6277c478bd9Sstevel@tonic-gate 		if (copyout(&un.smask, cmaddr, sizeof (un.smask)))
6287c478bd9Sstevel@tonic-gate 			error = EFAULT;
6297c478bd9Sstevel@tonic-gate 		break;
6307c478bd9Sstevel@tonic-gate 
6317c478bd9Sstevel@tonic-gate 	case PIOCSTRACE:	/* set signal trace mask */
6327c478bd9Sstevel@tonic-gate 		prdelset(&un.smask, SIGKILL);
6337c478bd9Sstevel@tonic-gate 		prassignset(&p->p_sigmask, &un.smask);
6347c478bd9Sstevel@tonic-gate 		if (!sigisempty(&p->p_sigmask))
6357c478bd9Sstevel@tonic-gate 			p->p_proc_flag |= P_PR_TRACE;
6367c478bd9Sstevel@tonic-gate 		else if (prisempty(&p->p_fltmask)) {
6377c478bd9Sstevel@tonic-gate 			up = PTOU(p);
6387c478bd9Sstevel@tonic-gate 			if (up->u_systrap == 0)
6397c478bd9Sstevel@tonic-gate 				p->p_proc_flag &= ~P_PR_TRACE;
6407c478bd9Sstevel@tonic-gate 		}
6417c478bd9Sstevel@tonic-gate 		prunlock(pnp);
6427c478bd9Sstevel@tonic-gate 		break;
6437c478bd9Sstevel@tonic-gate 
6447c478bd9Sstevel@tonic-gate 	case PIOCSSIG:		/* set current signal */
6457c478bd9Sstevel@tonic-gate 		error = pr_setsig(pnp, &un.info);
6467c478bd9Sstevel@tonic-gate 		prunlock(pnp);
6477c478bd9Sstevel@tonic-gate 		if (un.info.si_signo == SIGKILL && error == 0)
6487c478bd9Sstevel@tonic-gate 			pr_wait_die(pnp);
6497c478bd9Sstevel@tonic-gate 		break;
6507c478bd9Sstevel@tonic-gate 
6517c478bd9Sstevel@tonic-gate 	case PIOCKILL:		/* send signal */
6527c478bd9Sstevel@tonic-gate 	{
6537c478bd9Sstevel@tonic-gate 		int sig = (int)un.signo;
6547c478bd9Sstevel@tonic-gate 
6557c478bd9Sstevel@tonic-gate 		error = pr_kill(pnp, sig, cr);
6567c478bd9Sstevel@tonic-gate 		prunlock(pnp);
6577c478bd9Sstevel@tonic-gate 		if (sig == SIGKILL && error == 0)
6587c478bd9Sstevel@tonic-gate 			pr_wait_die(pnp);
6597c478bd9Sstevel@tonic-gate 		break;
6607c478bd9Sstevel@tonic-gate 	}
6617c478bd9Sstevel@tonic-gate 
6627c478bd9Sstevel@tonic-gate 	case PIOCUNKILL:	/* delete a signal */
6637c478bd9Sstevel@tonic-gate 		error = pr_unkill(pnp, (int)un.signo);
6647c478bd9Sstevel@tonic-gate 		prunlock(pnp);
6657c478bd9Sstevel@tonic-gate 		break;
6667c478bd9Sstevel@tonic-gate 
6677c478bd9Sstevel@tonic-gate 	case PIOCNICE:		/* set nice priority */
6687c478bd9Sstevel@tonic-gate 		error = pr_nice(p, (int)un.nice, cr);
6697c478bd9Sstevel@tonic-gate 		prunlock(pnp);
6707c478bd9Sstevel@tonic-gate 		break;
6717c478bd9Sstevel@tonic-gate 
6727c478bd9Sstevel@tonic-gate 	case PIOCGENTRY:	/* get syscall entry bit mask */
6737c478bd9Sstevel@tonic-gate 	case PIOCGEXIT:		/* get syscall exit bit mask */
6747c478bd9Sstevel@tonic-gate 		up = PTOU(p);
6757c478bd9Sstevel@tonic-gate 		if (cmd == PIOCGENTRY) {
6767c478bd9Sstevel@tonic-gate 			prassignset(&un.prmask, &up->u_entrymask);
6777c478bd9Sstevel@tonic-gate 		} else {
6787c478bd9Sstevel@tonic-gate 			prassignset(&un.prmask, &up->u_exitmask);
6797c478bd9Sstevel@tonic-gate 		}
6807c478bd9Sstevel@tonic-gate 		prunlock(pnp);
6817c478bd9Sstevel@tonic-gate 		if (copyout(&un.prmask, cmaddr, sizeof (un.prmask)))
6827c478bd9Sstevel@tonic-gate 			error = EFAULT;
6837c478bd9Sstevel@tonic-gate 		break;
6847c478bd9Sstevel@tonic-gate 
6857c478bd9Sstevel@tonic-gate 	case PIOCSENTRY:	/* set syscall entry bit mask */
6867c478bd9Sstevel@tonic-gate 	case PIOCSEXIT:		/* set syscall exit bit mask */
6877c478bd9Sstevel@tonic-gate 		pr_setentryexit(p, &un.prmask, cmd == PIOCSENTRY);
6887c478bd9Sstevel@tonic-gate 		prunlock(pnp);
6897c478bd9Sstevel@tonic-gate 		break;
6907c478bd9Sstevel@tonic-gate 
6917c478bd9Sstevel@tonic-gate 	case PIOCSRLC:		/* obsolete: set running on last /proc close */
6927c478bd9Sstevel@tonic-gate 		error = pr_set(p, prmapsetflags(PR_RLC));
6937c478bd9Sstevel@tonic-gate 		prunlock(pnp);
6947c478bd9Sstevel@tonic-gate 		break;
6957c478bd9Sstevel@tonic-gate 
6967c478bd9Sstevel@tonic-gate 	case PIOCRRLC:		/* obsolete: reset run-on-last-close flag */
6977c478bd9Sstevel@tonic-gate 		error = pr_unset(p, prmapsetflags(PR_RLC));
6987c478bd9Sstevel@tonic-gate 		prunlock(pnp);
6997c478bd9Sstevel@tonic-gate 		break;
7007c478bd9Sstevel@tonic-gate 
7017c478bd9Sstevel@tonic-gate 	case PIOCSFORK:		/* obsolete: set inherit-on-fork flag */
7027c478bd9Sstevel@tonic-gate 		error = pr_set(p, prmapsetflags(PR_FORK));
7037c478bd9Sstevel@tonic-gate 		prunlock(pnp);
7047c478bd9Sstevel@tonic-gate 		break;
7057c478bd9Sstevel@tonic-gate 
7067c478bd9Sstevel@tonic-gate 	case PIOCRFORK:		/* obsolete: reset inherit-on-fork flag */
7077c478bd9Sstevel@tonic-gate 		error = pr_unset(p, prmapsetflags(PR_FORK));
7087c478bd9Sstevel@tonic-gate 		prunlock(pnp);
7097c478bd9Sstevel@tonic-gate 		break;
7107c478bd9Sstevel@tonic-gate 
7117c478bd9Sstevel@tonic-gate 	case PIOCSET:		/* set process flags */
7127c478bd9Sstevel@tonic-gate 		error = pr_set(p, prmapsetflags(un.flags));
7137c478bd9Sstevel@tonic-gate 		prunlock(pnp);
7147c478bd9Sstevel@tonic-gate 		break;
7157c478bd9Sstevel@tonic-gate 
7167c478bd9Sstevel@tonic-gate 	case PIOCRESET:		/* reset process flags */
7177c478bd9Sstevel@tonic-gate 		error = pr_unset(p, prmapsetflags(un.flags));
7187c478bd9Sstevel@tonic-gate 		prunlock(pnp);
7197c478bd9Sstevel@tonic-gate 		break;
7207c478bd9Sstevel@tonic-gate 
7217c478bd9Sstevel@tonic-gate 	case PIOCGREG:		/* get general registers */
7227c478bd9Sstevel@tonic-gate 		if (t->t_state != TS_STOPPED && !VSTOPPED(t))
7237c478bd9Sstevel@tonic-gate 			bzero(un.regs, sizeof (un.regs));
7247c478bd9Sstevel@tonic-gate 		else {
7257c478bd9Sstevel@tonic-gate 			/* drop p_lock while touching the lwp's stack */
7267c478bd9Sstevel@tonic-gate 			mutex_exit(&p->p_lock);
7277c478bd9Sstevel@tonic-gate 			prgetprregs(lwp, un.regs);
7287c478bd9Sstevel@tonic-gate 			mutex_enter(&p->p_lock);
7297c478bd9Sstevel@tonic-gate 		}
7307c478bd9Sstevel@tonic-gate 		prunlock(pnp);
7317c478bd9Sstevel@tonic-gate 		if (copyout(un.regs, cmaddr, sizeof (un.regs)))
7327c478bd9Sstevel@tonic-gate 			error = EFAULT;
7337c478bd9Sstevel@tonic-gate 		break;
7347c478bd9Sstevel@tonic-gate 
7357c478bd9Sstevel@tonic-gate 	case PIOCSREG:		/* set general registers */
7367c478bd9Sstevel@tonic-gate 		if (!ISTOPPED(t) && !VSTOPPED(t) && !DSTOPPED(t))
7377c478bd9Sstevel@tonic-gate 			error = EBUSY;
7387c478bd9Sstevel@tonic-gate 		else {
7397c478bd9Sstevel@tonic-gate 			/* drop p_lock while touching the lwp's stack */
7407c478bd9Sstevel@tonic-gate 			mutex_exit(&p->p_lock);
7417c478bd9Sstevel@tonic-gate 			prsetprregs(lwp, un.regs, 0);
7427c478bd9Sstevel@tonic-gate 			mutex_enter(&p->p_lock);
7437c478bd9Sstevel@tonic-gate 		}
7447c478bd9Sstevel@tonic-gate 		prunlock(pnp);
7457c478bd9Sstevel@tonic-gate 		break;
7467c478bd9Sstevel@tonic-gate 
7477c478bd9Sstevel@tonic-gate 	case PIOCGFPREG:	/* get floating-point registers */
7487c478bd9Sstevel@tonic-gate 		if (!prhasfp()) {
7497c478bd9Sstevel@tonic-gate 			prunlock(pnp);
7507c478bd9Sstevel@tonic-gate 			error = EINVAL;	/* No FP support */
7517c478bd9Sstevel@tonic-gate 			break;
7527c478bd9Sstevel@tonic-gate 		}
7537c478bd9Sstevel@tonic-gate 
7547c478bd9Sstevel@tonic-gate 		if (t->t_state != TS_STOPPED && !VSTOPPED(t))
7557c478bd9Sstevel@tonic-gate 			bzero(&un.fpregs, sizeof (un.fpregs));
7567c478bd9Sstevel@tonic-gate 		else {
7577c478bd9Sstevel@tonic-gate 			/* drop p_lock while touching the lwp's stack */
7587c478bd9Sstevel@tonic-gate 			mutex_exit(&p->p_lock);
7597c478bd9Sstevel@tonic-gate 			prgetprfpregs(lwp, &un.fpregs);
7607c478bd9Sstevel@tonic-gate 			mutex_enter(&p->p_lock);
7617c478bd9Sstevel@tonic-gate 		}
7627c478bd9Sstevel@tonic-gate 		prunlock(pnp);
7637c478bd9Sstevel@tonic-gate 		if (copyout(&un.fpregs, cmaddr, sizeof (un.fpregs)))
7647c478bd9Sstevel@tonic-gate 			error = EFAULT;
7657c478bd9Sstevel@tonic-gate 		break;
7667c478bd9Sstevel@tonic-gate 
7677c478bd9Sstevel@tonic-gate 	case PIOCSFPREG:	/* set floating-point registers */
7687c478bd9Sstevel@tonic-gate 		if (!prhasfp())
7697c478bd9Sstevel@tonic-gate 			error = EINVAL;	/* No FP support */
7707c478bd9Sstevel@tonic-gate 		else if (!ISTOPPED(t) && !VSTOPPED(t) && !DSTOPPED(t))
7717c478bd9Sstevel@tonic-gate 			error = EBUSY;
7727c478bd9Sstevel@tonic-gate 		else {
7737c478bd9Sstevel@tonic-gate 			/* drop p_lock while touching the lwp's stack */
7747c478bd9Sstevel@tonic-gate 			mutex_exit(&p->p_lock);
7757c478bd9Sstevel@tonic-gate 			prsetprfpregs(lwp, &un.fpregs);
7767c478bd9Sstevel@tonic-gate 			mutex_enter(&p->p_lock);
7777c478bd9Sstevel@tonic-gate 		}
7787c478bd9Sstevel@tonic-gate 		prunlock(pnp);
7797c478bd9Sstevel@tonic-gate 		break;
7807c478bd9Sstevel@tonic-gate 
7817c478bd9Sstevel@tonic-gate 	case PIOCGXREGSIZE:	/* get the size of the extra registers */
7827c478bd9Sstevel@tonic-gate 	{
7837c478bd9Sstevel@tonic-gate 		int xregsize;
7847c478bd9Sstevel@tonic-gate 
7857c478bd9Sstevel@tonic-gate 		if (prhasx(p)) {
7867c478bd9Sstevel@tonic-gate 			xregsize = prgetprxregsize(p);
7877c478bd9Sstevel@tonic-gate 			prunlock(pnp);
7887c478bd9Sstevel@tonic-gate 			if (copyout(&xregsize, cmaddr, sizeof (xregsize)))
7897c478bd9Sstevel@tonic-gate 				error = EFAULT;
7907c478bd9Sstevel@tonic-gate 		} else {
7917c478bd9Sstevel@tonic-gate 			prunlock(pnp);
7927c478bd9Sstevel@tonic-gate 			error = EINVAL;	/* No extra register support */
7937c478bd9Sstevel@tonic-gate 		}
7947c478bd9Sstevel@tonic-gate 		break;
7957c478bd9Sstevel@tonic-gate 	}
7967c478bd9Sstevel@tonic-gate 
7977c478bd9Sstevel@tonic-gate 	case PIOCGXREG:		/* get extra registers */
7987c478bd9Sstevel@tonic-gate 		if (prhasx(p)) {
7997c478bd9Sstevel@tonic-gate 			bzero(thing, thingsize);
8007c478bd9Sstevel@tonic-gate 			if (t->t_state == TS_STOPPED || VSTOPPED(t)) {
8017c478bd9Sstevel@tonic-gate 				/* drop p_lock to touch the stack */
8027c478bd9Sstevel@tonic-gate 				mutex_exit(&p->p_lock);
8037c478bd9Sstevel@tonic-gate 				prgetprxregs(lwp, thing);
8047c478bd9Sstevel@tonic-gate 				mutex_enter(&p->p_lock);
8057c478bd9Sstevel@tonic-gate 			}
8067c478bd9Sstevel@tonic-gate 			prunlock(pnp);
8077c478bd9Sstevel@tonic-gate 			if (copyout(thing, cmaddr, thingsize))
8087c478bd9Sstevel@tonic-gate 				error = EFAULT;
8097c478bd9Sstevel@tonic-gate 		} else {
8107c478bd9Sstevel@tonic-gate 			prunlock(pnp);
8117c478bd9Sstevel@tonic-gate 			error = EINVAL;	/* No extra register support */
8127c478bd9Sstevel@tonic-gate 		}
8137c478bd9Sstevel@tonic-gate 		if (thing) {
8147c478bd9Sstevel@tonic-gate 			kmem_free(thing, thingsize);
8157c478bd9Sstevel@tonic-gate 			thing = NULL;
8167c478bd9Sstevel@tonic-gate 		}
8177c478bd9Sstevel@tonic-gate 		break;
8187c478bd9Sstevel@tonic-gate 
8197c478bd9Sstevel@tonic-gate 	case PIOCSXREG:		/* set extra registers */
8207c478bd9Sstevel@tonic-gate 		if (!ISTOPPED(t) && !VSTOPPED(t) && !DSTOPPED(t))
8217c478bd9Sstevel@tonic-gate 			error = EBUSY;
8227c478bd9Sstevel@tonic-gate 		else if (!prhasx(p))
8237c478bd9Sstevel@tonic-gate 			error = EINVAL;	/* No extra register support */
8247c478bd9Sstevel@tonic-gate 		else if (thing) {
8257c478bd9Sstevel@tonic-gate 			/* drop p_lock while touching the lwp's stack */
8267c478bd9Sstevel@tonic-gate 			mutex_exit(&p->p_lock);
8277c478bd9Sstevel@tonic-gate 			prsetprxregs(lwp, thing);
8287c478bd9Sstevel@tonic-gate 			mutex_enter(&p->p_lock);
8297c478bd9Sstevel@tonic-gate 		}
8307c478bd9Sstevel@tonic-gate 		prunlock(pnp);
8317c478bd9Sstevel@tonic-gate 		if (thing) {
8327c478bd9Sstevel@tonic-gate 			kmem_free(thing, thingsize);
8337c478bd9Sstevel@tonic-gate 			thing = NULL;
8347c478bd9Sstevel@tonic-gate 		}
8357c478bd9Sstevel@tonic-gate 		break;
8367c478bd9Sstevel@tonic-gate 
8377c478bd9Sstevel@tonic-gate 	case PIOCSTATUS:	/* get process/lwp status */
838*fa9e4066Sahrens 		oprgetstatus(t, &un.prstat, VTOZONE(vp));
8397c478bd9Sstevel@tonic-gate 		prunlock(pnp);
8407c478bd9Sstevel@tonic-gate 		if (copyout(&un.prstat, cmaddr, sizeof (un.prstat)))
8417c478bd9Sstevel@tonic-gate 			error = EFAULT;
8427c478bd9Sstevel@tonic-gate 		break;
8437c478bd9Sstevel@tonic-gate 
8447c478bd9Sstevel@tonic-gate 	case PIOCLSTATUS:	/* get status for process & all lwps */
8457c478bd9Sstevel@tonic-gate 	{
8467c478bd9Sstevel@tonic-gate 		int Nlwp;
8477c478bd9Sstevel@tonic-gate 		int nlwp;
8487c478bd9Sstevel@tonic-gate 		prstatus_t *Bprsp;
8497c478bd9Sstevel@tonic-gate 		prstatus_t *prsp;
8507c478bd9Sstevel@tonic-gate 
8517c478bd9Sstevel@tonic-gate 		nlwp = Nlwp = p->p_lwpcnt;
8527c478bd9Sstevel@tonic-gate 
8537c478bd9Sstevel@tonic-gate 		if (thing && thingsize != (Nlwp+1) * sizeof (prstatus_t)) {
8547c478bd9Sstevel@tonic-gate 			kmem_free(thing, thingsize);
8557c478bd9Sstevel@tonic-gate 			thing = NULL;
8567c478bd9Sstevel@tonic-gate 		}
8577c478bd9Sstevel@tonic-gate 		if (thing == NULL) {
8587c478bd9Sstevel@tonic-gate 			thingsize = (Nlwp+1) * sizeof (prstatus_t);
8597c478bd9Sstevel@tonic-gate 			thing = kmem_alloc(thingsize, KM_NOSLEEP);
8607c478bd9Sstevel@tonic-gate 		}
8617c478bd9Sstevel@tonic-gate 		if (thing == NULL) {
8627c478bd9Sstevel@tonic-gate 			prunlock(pnp);
8637c478bd9Sstevel@tonic-gate 			goto startover;
8647c478bd9Sstevel@tonic-gate 		}
8657c478bd9Sstevel@tonic-gate 
8667c478bd9Sstevel@tonic-gate 		Bprsp = thing;
8677c478bd9Sstevel@tonic-gate 		thing = NULL;
8687c478bd9Sstevel@tonic-gate 		prsp = Bprsp;
869*fa9e4066Sahrens 		oprgetstatus(t, prsp, VTOZONE(vp));
8707c478bd9Sstevel@tonic-gate 		t = p->p_tlist;
8717c478bd9Sstevel@tonic-gate 		do {
8727c478bd9Sstevel@tonic-gate 			ASSERT(!(t->t_proc_flag & TP_LWPEXIT));
8737c478bd9Sstevel@tonic-gate 			ASSERT(nlwp > 0);
8747c478bd9Sstevel@tonic-gate 			--nlwp;
875*fa9e4066Sahrens 			oprgetstatus(t, ++prsp, VTOZONE(vp));
8767c478bd9Sstevel@tonic-gate 		} while ((t = t->t_forw) != p->p_tlist);
8777c478bd9Sstevel@tonic-gate 		ASSERT(nlwp == 0);
8787c478bd9Sstevel@tonic-gate 		prunlock(pnp);
8797c478bd9Sstevel@tonic-gate 		if (copyout(Bprsp, cmaddr, (Nlwp+1) * sizeof (prstatus_t)))
8807c478bd9Sstevel@tonic-gate 			error = EFAULT;
8817c478bd9Sstevel@tonic-gate 
8827c478bd9Sstevel@tonic-gate 		kmem_free(Bprsp, (Nlwp+1) * sizeof (prstatus_t));
8837c478bd9Sstevel@tonic-gate 		break;
8847c478bd9Sstevel@tonic-gate 	}
8857c478bd9Sstevel@tonic-gate 
8867c478bd9Sstevel@tonic-gate 	case PIOCPSINFO:	/* get ps(1) information */
8877c478bd9Sstevel@tonic-gate 	{
8887c478bd9Sstevel@tonic-gate 		prpsinfo_t *psp = &un.prps;
8897c478bd9Sstevel@tonic-gate 
8907c478bd9Sstevel@tonic-gate 		oprgetpsinfo(p, psp,
8917c478bd9Sstevel@tonic-gate 		    (pnp->pr_type == PR_LWPIDFILE)? pcp->prc_thread : NULL);
8927c478bd9Sstevel@tonic-gate 
8937c478bd9Sstevel@tonic-gate 		prunlock(pnp);
8947c478bd9Sstevel@tonic-gate 		if (copyout(&un.prps, cmaddr, sizeof (un.prps)))
8957c478bd9Sstevel@tonic-gate 			error = EFAULT;
8967c478bd9Sstevel@tonic-gate 		break;
8977c478bd9Sstevel@tonic-gate 	}
8987c478bd9Sstevel@tonic-gate 
8997c478bd9Sstevel@tonic-gate 	case PIOCMAXSIG:	/* get maximum signal number */
9007c478bd9Sstevel@tonic-gate 	{
9017c478bd9Sstevel@tonic-gate 		int n = NSIG-1;
9027c478bd9Sstevel@tonic-gate 
9037c478bd9Sstevel@tonic-gate 		prunlock(pnp);
9047c478bd9Sstevel@tonic-gate 		if (copyout(&n, cmaddr, sizeof (n)))
9057c478bd9Sstevel@tonic-gate 			error = EFAULT;
9067c478bd9Sstevel@tonic-gate 		break;
9077c478bd9Sstevel@tonic-gate 	}
9087c478bd9Sstevel@tonic-gate 
9097c478bd9Sstevel@tonic-gate 	case PIOCACTION:	/* get signal action structures */
9107c478bd9Sstevel@tonic-gate 	{
9117c478bd9Sstevel@tonic-gate 		uint_t sig;
9127c478bd9Sstevel@tonic-gate 		struct sigaction *sap = thing;
9137c478bd9Sstevel@tonic-gate 
9147c478bd9Sstevel@tonic-gate 		up = PTOU(p);
9157c478bd9Sstevel@tonic-gate 		for (sig = 1; sig < NSIG; sig++)
9167c478bd9Sstevel@tonic-gate 			prgetaction(p, up, sig, &sap[sig-1]);
9177c478bd9Sstevel@tonic-gate 		prunlock(pnp);
9187c478bd9Sstevel@tonic-gate 		if (copyout(sap, cmaddr, (NSIG-1) * sizeof (struct sigaction)))
9197c478bd9Sstevel@tonic-gate 			error = EFAULT;
9207c478bd9Sstevel@tonic-gate 		kmem_free(sap, (NSIG-1) * sizeof (struct sigaction));
9217c478bd9Sstevel@tonic-gate 		thing = NULL;
9227c478bd9Sstevel@tonic-gate 		break;
9237c478bd9Sstevel@tonic-gate 	}
9247c478bd9Sstevel@tonic-gate 
9257c478bd9Sstevel@tonic-gate 	case PIOCGHOLD:		/* get signal-hold mask */
9267c478bd9Sstevel@tonic-gate 		schedctl_finish_sigblock(t);
9277c478bd9Sstevel@tonic-gate 		sigktou(&t->t_hold, &un.holdmask);
9287c478bd9Sstevel@tonic-gate 		prunlock(pnp);
9297c478bd9Sstevel@tonic-gate 		if (copyout(&un.holdmask, cmaddr, sizeof (un.holdmask)))
9307c478bd9Sstevel@tonic-gate 			error = EFAULT;
9317c478bd9Sstevel@tonic-gate 		break;
9327c478bd9Sstevel@tonic-gate 
9337c478bd9Sstevel@tonic-gate 	case PIOCSHOLD:		/* set signal-hold mask */
9347c478bd9Sstevel@tonic-gate 		pr_sethold(pnp, &un.holdmask);
9357c478bd9Sstevel@tonic-gate 		prunlock(pnp);
9367c478bd9Sstevel@tonic-gate 		break;
9377c478bd9Sstevel@tonic-gate 
9387c478bd9Sstevel@tonic-gate 	case PIOCNMAP:		/* get number of memory mappings */
9397c478bd9Sstevel@tonic-gate 	{
9407c478bd9Sstevel@tonic-gate 		int n;
9417c478bd9Sstevel@tonic-gate 		struct as *as = p->p_as;
9427c478bd9Sstevel@tonic-gate 
9437c478bd9Sstevel@tonic-gate 		if ((p->p_flag & SSYS) || as == &kas)
9447c478bd9Sstevel@tonic-gate 			n = 0;
9457c478bd9Sstevel@tonic-gate 		else {
9467c478bd9Sstevel@tonic-gate 			mutex_exit(&p->p_lock);
9477c478bd9Sstevel@tonic-gate 			AS_LOCK_ENTER(as, &as->a_lock, RW_WRITER);
9487c478bd9Sstevel@tonic-gate 			n = prnsegs(as, 0);
9497c478bd9Sstevel@tonic-gate 			AS_LOCK_EXIT(as, &as->a_lock);
9507c478bd9Sstevel@tonic-gate 			mutex_enter(&p->p_lock);
9517c478bd9Sstevel@tonic-gate 		}
9527c478bd9Sstevel@tonic-gate 		prunlock(pnp);
9537c478bd9Sstevel@tonic-gate 		if (copyout(&n, cmaddr, sizeof (int)))
9547c478bd9Sstevel@tonic-gate 			error = EFAULT;
9557c478bd9Sstevel@tonic-gate 		break;
9567c478bd9Sstevel@tonic-gate 	}
9577c478bd9Sstevel@tonic-gate 
9587c478bd9Sstevel@tonic-gate 	case PIOCMAP:		/* get memory map information */
9597c478bd9Sstevel@tonic-gate 	{
9607c478bd9Sstevel@tonic-gate 		int n;
9617c478bd9Sstevel@tonic-gate 		prmap_t *prmapp;
9627c478bd9Sstevel@tonic-gate 		size_t size;
9637c478bd9Sstevel@tonic-gate 		struct as *as = p->p_as;
9647c478bd9Sstevel@tonic-gate 		int issys = ((p->p_flag & SSYS) || as == &kas);
9657c478bd9Sstevel@tonic-gate 
9667c478bd9Sstevel@tonic-gate 		if (issys) {
9677c478bd9Sstevel@tonic-gate 			n = 1;
9687c478bd9Sstevel@tonic-gate 			prmapp = &un.prmap;
9697c478bd9Sstevel@tonic-gate 			bzero(prmapp, sizeof (*prmapp));
9707c478bd9Sstevel@tonic-gate 		} else {
9717c478bd9Sstevel@tonic-gate 			mutex_exit(&p->p_lock);
9727c478bd9Sstevel@tonic-gate 			AS_LOCK_ENTER(as, &as->a_lock, RW_WRITER);
9737c478bd9Sstevel@tonic-gate 			n = oprgetmap(p, &prmapp, &size);
9747c478bd9Sstevel@tonic-gate 			AS_LOCK_EXIT(as, &as->a_lock);
9757c478bd9Sstevel@tonic-gate 			mutex_enter(&p->p_lock);
9767c478bd9Sstevel@tonic-gate 		}
9777c478bd9Sstevel@tonic-gate 		prunlock(pnp);
9787c478bd9Sstevel@tonic-gate 
9797c478bd9Sstevel@tonic-gate 		if (copyout(prmapp, cmaddr, n * sizeof (prmap_t)))
9807c478bd9Sstevel@tonic-gate 			error = EFAULT;
9817c478bd9Sstevel@tonic-gate 		if (!issys)
9827c478bd9Sstevel@tonic-gate 			kmem_free(prmapp, size);
9837c478bd9Sstevel@tonic-gate 		break;
9847c478bd9Sstevel@tonic-gate 	}
9857c478bd9Sstevel@tonic-gate 
9867c478bd9Sstevel@tonic-gate 	case PIOCGFAULT:	/* get mask of traced faults */
9877c478bd9Sstevel@tonic-gate 		prassignset(&un.fltmask, &p->p_fltmask);
9887c478bd9Sstevel@tonic-gate 		prunlock(pnp);
9897c478bd9Sstevel@tonic-gate 		if (copyout(&un.fltmask, cmaddr, sizeof (un.fltmask)))
9907c478bd9Sstevel@tonic-gate 			error = EFAULT;
9917c478bd9Sstevel@tonic-gate 		break;
9927c478bd9Sstevel@tonic-gate 
9937c478bd9Sstevel@tonic-gate 	case PIOCSFAULT:	/* set mask of traced faults */
9947c478bd9Sstevel@tonic-gate 		pr_setfault(p, &un.fltmask);
9957c478bd9Sstevel@tonic-gate 		prunlock(pnp);
9967c478bd9Sstevel@tonic-gate 		break;
9977c478bd9Sstevel@tonic-gate 
9987c478bd9Sstevel@tonic-gate 	case PIOCCFAULT:	/* clear current fault */
9997c478bd9Sstevel@tonic-gate 		lwp->lwp_curflt = 0;
10007c478bd9Sstevel@tonic-gate 		prunlock(pnp);
10017c478bd9Sstevel@tonic-gate 		break;
10027c478bd9Sstevel@tonic-gate 
10037c478bd9Sstevel@tonic-gate 	case PIOCCRED:		/* get process credentials */
10047c478bd9Sstevel@tonic-gate 	{
10057c478bd9Sstevel@tonic-gate 		cred_t *cp;
10067c478bd9Sstevel@tonic-gate 
10077c478bd9Sstevel@tonic-gate 		mutex_enter(&p->p_crlock);
10087c478bd9Sstevel@tonic-gate 		cp = p->p_cred;
10097c478bd9Sstevel@tonic-gate 		un.prcred.pr_euid = crgetuid(cp);
10107c478bd9Sstevel@tonic-gate 		un.prcred.pr_ruid = crgetruid(cp);
10117c478bd9Sstevel@tonic-gate 		un.prcred.pr_suid = crgetsuid(cp);
10127c478bd9Sstevel@tonic-gate 		un.prcred.pr_egid = crgetgid(cp);
10137c478bd9Sstevel@tonic-gate 		un.prcred.pr_rgid = crgetrgid(cp);
10147c478bd9Sstevel@tonic-gate 		un.prcred.pr_sgid = crgetsgid(cp);
10157c478bd9Sstevel@tonic-gate 		un.prcred.pr_ngroups = crgetngroups(cp);
10167c478bd9Sstevel@tonic-gate 		mutex_exit(&p->p_crlock);
10177c478bd9Sstevel@tonic-gate 
10187c478bd9Sstevel@tonic-gate 		prunlock(pnp);
10197c478bd9Sstevel@tonic-gate 		if (copyout(&un.prcred, cmaddr, sizeof (un.prcred)))
10207c478bd9Sstevel@tonic-gate 			error = EFAULT;
10217c478bd9Sstevel@tonic-gate 		break;
10227c478bd9Sstevel@tonic-gate 	}
10237c478bd9Sstevel@tonic-gate 
10247c478bd9Sstevel@tonic-gate 	case PIOCGROUPS:	/* get supplementary groups */
10257c478bd9Sstevel@tonic-gate 	{
10267c478bd9Sstevel@tonic-gate 		cred_t *cp;
10277c478bd9Sstevel@tonic-gate 
10287c478bd9Sstevel@tonic-gate 		mutex_enter(&p->p_crlock);
10297c478bd9Sstevel@tonic-gate 		cp = p->p_cred;
10307c478bd9Sstevel@tonic-gate 		crhold(cp);
10317c478bd9Sstevel@tonic-gate 		mutex_exit(&p->p_crlock);
10327c478bd9Sstevel@tonic-gate 
10337c478bd9Sstevel@tonic-gate 		prunlock(pnp);
10347c478bd9Sstevel@tonic-gate 		if (copyout(crgetgroups(cp), cmaddr,
10357c478bd9Sstevel@tonic-gate 		    MAX(crgetngroups(cp), 1) * sizeof (gid_t)))
10367c478bd9Sstevel@tonic-gate 			error = EFAULT;
10377c478bd9Sstevel@tonic-gate 		crfree(cp);
10387c478bd9Sstevel@tonic-gate 		break;
10397c478bd9Sstevel@tonic-gate 	}
10407c478bd9Sstevel@tonic-gate 
10417c478bd9Sstevel@tonic-gate 	case PIOCUSAGE:		/* get usage info */
10427c478bd9Sstevel@tonic-gate 	{
10437c478bd9Sstevel@tonic-gate 		/*
10447c478bd9Sstevel@tonic-gate 		 * For an lwp file descriptor, return just the lwp usage.
10457c478bd9Sstevel@tonic-gate 		 * For a process file descriptor, return total usage,
10467c478bd9Sstevel@tonic-gate 		 * all current lwps plus all defunct lwps.
10477c478bd9Sstevel@tonic-gate 		 */
10487c478bd9Sstevel@tonic-gate 		prhusage_t *pup = &un.prhusage;
10497c478bd9Sstevel@tonic-gate 		prusage_t *upup;
10507c478bd9Sstevel@tonic-gate 
10517c478bd9Sstevel@tonic-gate 		bzero(pup, sizeof (*pup));
10527c478bd9Sstevel@tonic-gate 		pup->pr_tstamp = gethrtime();
10537c478bd9Sstevel@tonic-gate 
10547c478bd9Sstevel@tonic-gate 		if (pnp->pr_type == PR_LWPIDFILE) {
10557c478bd9Sstevel@tonic-gate 			t = pcp->prc_thread;
10567c478bd9Sstevel@tonic-gate 			if (t != NULL)
10577c478bd9Sstevel@tonic-gate 				prgetusage(t, pup);
10587c478bd9Sstevel@tonic-gate 			else
10597c478bd9Sstevel@tonic-gate 				error = ENOENT;
10607c478bd9Sstevel@tonic-gate 		} else {
10617c478bd9Sstevel@tonic-gate 			pup->pr_count  = p->p_defunct;
10627c478bd9Sstevel@tonic-gate 			pup->pr_create = p->p_mstart;
10637c478bd9Sstevel@tonic-gate 			pup->pr_term   = p->p_mterm;
10647c478bd9Sstevel@tonic-gate 
10657c478bd9Sstevel@tonic-gate 			pup->pr_rtime    = p->p_mlreal;
10667c478bd9Sstevel@tonic-gate 			pup->pr_utime    = p->p_acct[LMS_USER];
10677c478bd9Sstevel@tonic-gate 			pup->pr_stime    = p->p_acct[LMS_SYSTEM];
10687c478bd9Sstevel@tonic-gate 			pup->pr_ttime    = p->p_acct[LMS_TRAP];
10697c478bd9Sstevel@tonic-gate 			pup->pr_tftime   = p->p_acct[LMS_TFAULT];
10707c478bd9Sstevel@tonic-gate 			pup->pr_dftime   = p->p_acct[LMS_DFAULT];
10717c478bd9Sstevel@tonic-gate 			pup->pr_kftime   = p->p_acct[LMS_KFAULT];
10727c478bd9Sstevel@tonic-gate 			pup->pr_ltime    = p->p_acct[LMS_USER_LOCK];
10737c478bd9Sstevel@tonic-gate 			pup->pr_slptime  = p->p_acct[LMS_SLEEP];
10747c478bd9Sstevel@tonic-gate 			pup->pr_wtime    = p->p_acct[LMS_WAIT_CPU];
10757c478bd9Sstevel@tonic-gate 			pup->pr_stoptime = p->p_acct[LMS_STOPPED];
10767c478bd9Sstevel@tonic-gate 
10777c478bd9Sstevel@tonic-gate 			pup->pr_minf  = p->p_ru.minflt;
10787c478bd9Sstevel@tonic-gate 			pup->pr_majf  = p->p_ru.majflt;
10797c478bd9Sstevel@tonic-gate 			pup->pr_nswap = p->p_ru.nswap;
10807c478bd9Sstevel@tonic-gate 			pup->pr_inblk = p->p_ru.inblock;
10817c478bd9Sstevel@tonic-gate 			pup->pr_oublk = p->p_ru.oublock;
10827c478bd9Sstevel@tonic-gate 			pup->pr_msnd  = p->p_ru.msgsnd;
10837c478bd9Sstevel@tonic-gate 			pup->pr_mrcv  = p->p_ru.msgrcv;
10847c478bd9Sstevel@tonic-gate 			pup->pr_sigs  = p->p_ru.nsignals;
10857c478bd9Sstevel@tonic-gate 			pup->pr_vctx  = p->p_ru.nvcsw;
10867c478bd9Sstevel@tonic-gate 			pup->pr_ictx  = p->p_ru.nivcsw;
10877c478bd9Sstevel@tonic-gate 			pup->pr_sysc  = p->p_ru.sysc;
10887c478bd9Sstevel@tonic-gate 			pup->pr_ioch  = p->p_ru.ioch;
10897c478bd9Sstevel@tonic-gate 
10907c478bd9Sstevel@tonic-gate 			/*
10917c478bd9Sstevel@tonic-gate 			 * Add the usage information for each active lwp.
10927c478bd9Sstevel@tonic-gate 			 */
10937c478bd9Sstevel@tonic-gate 			if ((t = p->p_tlist) != NULL &&
10947c478bd9Sstevel@tonic-gate 			    !(pcp->prc_flags & PRC_DESTROY)) {
10957c478bd9Sstevel@tonic-gate 				do {
10967c478bd9Sstevel@tonic-gate 					ASSERT(!(t->t_proc_flag & TP_LWPEXIT));
10977c478bd9Sstevel@tonic-gate 					pup->pr_count++;
10987c478bd9Sstevel@tonic-gate 					praddusage(t, pup);
10997c478bd9Sstevel@tonic-gate 				} while ((t = t->t_forw) != p->p_tlist);
11007c478bd9Sstevel@tonic-gate 			}
11017c478bd9Sstevel@tonic-gate 		}
11027c478bd9Sstevel@tonic-gate 
11037c478bd9Sstevel@tonic-gate 		prunlock(pnp);
11047c478bd9Sstevel@tonic-gate 
11057c478bd9Sstevel@tonic-gate 		upup = kmem_zalloc(sizeof (*upup), KM_SLEEP);
11067c478bd9Sstevel@tonic-gate 		prcvtusage(&un.prhusage, upup);
11077c478bd9Sstevel@tonic-gate 		if (copyout(upup, cmaddr, sizeof (*upup)))
11087c478bd9Sstevel@tonic-gate 			error = EFAULT;
11097c478bd9Sstevel@tonic-gate 		kmem_free(upup, sizeof (*upup));
11107c478bd9Sstevel@tonic-gate 
11117c478bd9Sstevel@tonic-gate 		break;
11127c478bd9Sstevel@tonic-gate 	}
11137c478bd9Sstevel@tonic-gate 
11147c478bd9Sstevel@tonic-gate 	case PIOCLUSAGE:	/* get detailed usage info */
11157c478bd9Sstevel@tonic-gate 	{
11167c478bd9Sstevel@tonic-gate 		int Nlwp;
11177c478bd9Sstevel@tonic-gate 		int nlwp;
11187c478bd9Sstevel@tonic-gate 		prusage_t *upup;
11197c478bd9Sstevel@tonic-gate 		prusage_t *Bupup;
11207c478bd9Sstevel@tonic-gate 		prhusage_t *pup;
11217c478bd9Sstevel@tonic-gate 		hrtime_t curtime;
11227c478bd9Sstevel@tonic-gate 
11237c478bd9Sstevel@tonic-gate 		nlwp = Nlwp = (pcp->prc_flags & PRC_DESTROY)? 0 : p->p_lwpcnt;
11247c478bd9Sstevel@tonic-gate 
11257c478bd9Sstevel@tonic-gate 		if (thing && thingsize !=
11267c478bd9Sstevel@tonic-gate 		    sizeof (prhusage_t) + (Nlwp+1) * sizeof (prusage_t)) {
11277c478bd9Sstevel@tonic-gate 			kmem_free(thing, thingsize);
11287c478bd9Sstevel@tonic-gate 			thing = NULL;
11297c478bd9Sstevel@tonic-gate 		}
11307c478bd9Sstevel@tonic-gate 		if (thing == NULL) {
11317c478bd9Sstevel@tonic-gate 			thingsize = sizeof (prhusage_t) +
11327c478bd9Sstevel@tonic-gate 			    (Nlwp+1) * sizeof (prusage_t);
11337c478bd9Sstevel@tonic-gate 			thing = kmem_alloc(thingsize, KM_NOSLEEP);
11347c478bd9Sstevel@tonic-gate 		}
11357c478bd9Sstevel@tonic-gate 		if (thing == NULL) {
11367c478bd9Sstevel@tonic-gate 			prunlock(pnp);
11377c478bd9Sstevel@tonic-gate 			goto startover;
11387c478bd9Sstevel@tonic-gate 		}
11397c478bd9Sstevel@tonic-gate 
11407c478bd9Sstevel@tonic-gate 		pup = thing;
11417c478bd9Sstevel@tonic-gate 		upup = Bupup = (prusage_t *)(pup + 1);
11427c478bd9Sstevel@tonic-gate 
11437c478bd9Sstevel@tonic-gate 		ASSERT(p == pcp->prc_proc);
11447c478bd9Sstevel@tonic-gate 
11457c478bd9Sstevel@tonic-gate 		curtime = gethrtime();
11467c478bd9Sstevel@tonic-gate 
11477c478bd9Sstevel@tonic-gate 		/*
11487c478bd9Sstevel@tonic-gate 		 * First the summation over defunct lwps.
11497c478bd9Sstevel@tonic-gate 		 */
11507c478bd9Sstevel@tonic-gate 		bzero(pup, sizeof (*pup));
11517c478bd9Sstevel@tonic-gate 		pup->pr_count  = p->p_defunct;
11527c478bd9Sstevel@tonic-gate 		pup->pr_tstamp = curtime;
11537c478bd9Sstevel@tonic-gate 		pup->pr_create = p->p_mstart;
11547c478bd9Sstevel@tonic-gate 		pup->pr_term   = p->p_mterm;
11557c478bd9Sstevel@tonic-gate 
11567c478bd9Sstevel@tonic-gate 		pup->pr_rtime    = p->p_mlreal;
11577c478bd9Sstevel@tonic-gate 		pup->pr_utime    = p->p_acct[LMS_USER];
11587c478bd9Sstevel@tonic-gate 		pup->pr_stime    = p->p_acct[LMS_SYSTEM];
11597c478bd9Sstevel@tonic-gate 		pup->pr_ttime    = p->p_acct[LMS_TRAP];
11607c478bd9Sstevel@tonic-gate 		pup->pr_tftime   = p->p_acct[LMS_TFAULT];
11617c478bd9Sstevel@tonic-gate 		pup->pr_dftime   = p->p_acct[LMS_DFAULT];
11627c478bd9Sstevel@tonic-gate 		pup->pr_kftime   = p->p_acct[LMS_KFAULT];
11637c478bd9Sstevel@tonic-gate 		pup->pr_ltime    = p->p_acct[LMS_USER_LOCK];
11647c478bd9Sstevel@tonic-gate 		pup->pr_slptime  = p->p_acct[LMS_SLEEP];
11657c478bd9Sstevel@tonic-gate 		pup->pr_wtime    = p->p_acct[LMS_WAIT_CPU];
11667c478bd9Sstevel@tonic-gate 		pup->pr_stoptime = p->p_acct[LMS_STOPPED];
11677c478bd9Sstevel@tonic-gate 
11687c478bd9Sstevel@tonic-gate 		pup->pr_minf  = p->p_ru.minflt;
11697c478bd9Sstevel@tonic-gate 		pup->pr_majf  = p->p_ru.majflt;
11707c478bd9Sstevel@tonic-gate 		pup->pr_nswap = p->p_ru.nswap;
11717c478bd9Sstevel@tonic-gate 		pup->pr_inblk = p->p_ru.inblock;
11727c478bd9Sstevel@tonic-gate 		pup->pr_oublk = p->p_ru.oublock;
11737c478bd9Sstevel@tonic-gate 		pup->pr_msnd  = p->p_ru.msgsnd;
11747c478bd9Sstevel@tonic-gate 		pup->pr_mrcv  = p->p_ru.msgrcv;
11757c478bd9Sstevel@tonic-gate 		pup->pr_sigs  = p->p_ru.nsignals;
11767c478bd9Sstevel@tonic-gate 		pup->pr_vctx  = p->p_ru.nvcsw;
11777c478bd9Sstevel@tonic-gate 		pup->pr_ictx  = p->p_ru.nivcsw;
11787c478bd9Sstevel@tonic-gate 		pup->pr_sysc  = p->p_ru.sysc;
11797c478bd9Sstevel@tonic-gate 		pup->pr_ioch  = p->p_ru.ioch;
11807c478bd9Sstevel@tonic-gate 
11817c478bd9Sstevel@tonic-gate 		prcvtusage(pup, upup);
11827c478bd9Sstevel@tonic-gate 
11837c478bd9Sstevel@tonic-gate 		/*
11847c478bd9Sstevel@tonic-gate 		 * Fill one prusage struct for each active lwp.
11857c478bd9Sstevel@tonic-gate 		 */
11867c478bd9Sstevel@tonic-gate 		if ((t = p->p_tlist) != NULL &&
11877c478bd9Sstevel@tonic-gate 		    !(pcp->prc_flags & PRC_DESTROY)) {
11887c478bd9Sstevel@tonic-gate 			do {
11897c478bd9Sstevel@tonic-gate 				ASSERT(!(t->t_proc_flag & TP_LWPEXIT));
11907c478bd9Sstevel@tonic-gate 				ASSERT(nlwp > 0);
11917c478bd9Sstevel@tonic-gate 				--nlwp;
11927c478bd9Sstevel@tonic-gate 				upup++;
11937c478bd9Sstevel@tonic-gate 				prgetusage(t, pup);
11947c478bd9Sstevel@tonic-gate 				prcvtusage(pup, upup);
11957c478bd9Sstevel@tonic-gate 			} while ((t = t->t_forw) != p->p_tlist);
11967c478bd9Sstevel@tonic-gate 		}
11977c478bd9Sstevel@tonic-gate 		ASSERT(nlwp == 0);
11987c478bd9Sstevel@tonic-gate 
11997c478bd9Sstevel@tonic-gate 		prunlock(pnp);
12007c478bd9Sstevel@tonic-gate 		if (copyout(Bupup, cmaddr, (Nlwp+1) * sizeof (prusage_t)))
12017c478bd9Sstevel@tonic-gate 			error = EFAULT;
12027c478bd9Sstevel@tonic-gate 		kmem_free(thing, thingsize);
12037c478bd9Sstevel@tonic-gate 		thing = NULL;
12047c478bd9Sstevel@tonic-gate 		break;
12057c478bd9Sstevel@tonic-gate 	}
12067c478bd9Sstevel@tonic-gate 
12077c478bd9Sstevel@tonic-gate 	case PIOCNAUXV:		/* get number of aux vector entries */
12087c478bd9Sstevel@tonic-gate 	{
12097c478bd9Sstevel@tonic-gate 		int n = __KERN_NAUXV_IMPL;
12107c478bd9Sstevel@tonic-gate 
12117c478bd9Sstevel@tonic-gate 		prunlock(pnp);
12127c478bd9Sstevel@tonic-gate 		if (copyout(&n, cmaddr, sizeof (int)))
12137c478bd9Sstevel@tonic-gate 			error = EFAULT;
12147c478bd9Sstevel@tonic-gate 		break;
12157c478bd9Sstevel@tonic-gate 	}
12167c478bd9Sstevel@tonic-gate 
12177c478bd9Sstevel@tonic-gate 	case PIOCAUXV:		/* get aux vector (see sys/auxv.h) */
12187c478bd9Sstevel@tonic-gate 	{
12197c478bd9Sstevel@tonic-gate 		up = PTOU(p);
12207c478bd9Sstevel@tonic-gate 		bcopy(up->u_auxv, un.auxv,
12217c478bd9Sstevel@tonic-gate 		    __KERN_NAUXV_IMPL * sizeof (auxv_t));
12227c478bd9Sstevel@tonic-gate 		prunlock(pnp);
12237c478bd9Sstevel@tonic-gate 		if (copyout(un.auxv, cmaddr,
12247c478bd9Sstevel@tonic-gate 		    __KERN_NAUXV_IMPL * sizeof (auxv_t)))
12257c478bd9Sstevel@tonic-gate 			error = EFAULT;
12267c478bd9Sstevel@tonic-gate 		break;
12277c478bd9Sstevel@tonic-gate 	}
12287c478bd9Sstevel@tonic-gate 
12297c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
12307c478bd9Sstevel@tonic-gate 	case PIOCNLDT:		/* get number of LDT entries */
12317c478bd9Sstevel@tonic-gate 	{
12327c478bd9Sstevel@tonic-gate 		int n;
12337c478bd9Sstevel@tonic-gate 
12347c478bd9Sstevel@tonic-gate 		mutex_enter(&p->p_ldtlock);
12357c478bd9Sstevel@tonic-gate 		n = prnldt(p);
12367c478bd9Sstevel@tonic-gate 		mutex_exit(&p->p_ldtlock);
12377c478bd9Sstevel@tonic-gate 		prunlock(pnp);
12387c478bd9Sstevel@tonic-gate 		if (copyout(&n, cmaddr, sizeof (n)))
12397c478bd9Sstevel@tonic-gate 			error = EFAULT;
12407c478bd9Sstevel@tonic-gate 		break;
12417c478bd9Sstevel@tonic-gate 	}
12427c478bd9Sstevel@tonic-gate 
12437c478bd9Sstevel@tonic-gate 	case PIOCLDT:		/* get LDT entries */
12447c478bd9Sstevel@tonic-gate 	{
12457c478bd9Sstevel@tonic-gate 		struct ssd *ssd;
12467c478bd9Sstevel@tonic-gate 		int n;
12477c478bd9Sstevel@tonic-gate 
12487c478bd9Sstevel@tonic-gate 		mutex_enter(&p->p_ldtlock);
12497c478bd9Sstevel@tonic-gate 		n = prnldt(p);
12507c478bd9Sstevel@tonic-gate 
12517c478bd9Sstevel@tonic-gate 		if (thing && thingsize != (n+1) * sizeof (*ssd)) {
12527c478bd9Sstevel@tonic-gate 			kmem_free(thing, thingsize);
12537c478bd9Sstevel@tonic-gate 			thing = NULL;
12547c478bd9Sstevel@tonic-gate 		}
12557c478bd9Sstevel@tonic-gate 		if (thing == NULL) {
12567c478bd9Sstevel@tonic-gate 			thingsize = (n+1) * sizeof (*ssd);
12577c478bd9Sstevel@tonic-gate 			thing = kmem_alloc(thingsize, KM_NOSLEEP);
12587c478bd9Sstevel@tonic-gate 		}
12597c478bd9Sstevel@tonic-gate 		if (thing == NULL) {
12607c478bd9Sstevel@tonic-gate 			mutex_exit(&p->p_ldtlock);
12617c478bd9Sstevel@tonic-gate 			prunlock(pnp);
12627c478bd9Sstevel@tonic-gate 			goto startover;
12637c478bd9Sstevel@tonic-gate 		}
12647c478bd9Sstevel@tonic-gate 
12657c478bd9Sstevel@tonic-gate 		ssd = thing;
12667c478bd9Sstevel@tonic-gate 		thing = NULL;
12677c478bd9Sstevel@tonic-gate 		if (n != 0)
12687c478bd9Sstevel@tonic-gate 			prgetldt(p, ssd);
12697c478bd9Sstevel@tonic-gate 		mutex_exit(&p->p_ldtlock);
12707c478bd9Sstevel@tonic-gate 		prunlock(pnp);
12717c478bd9Sstevel@tonic-gate 
12727c478bd9Sstevel@tonic-gate 		/* mark the end of the list with a null entry */
12737c478bd9Sstevel@tonic-gate 		bzero(&ssd[n], sizeof (*ssd));
12747c478bd9Sstevel@tonic-gate 		if (copyout(ssd, cmaddr, (n+1) * sizeof (*ssd)))
12757c478bd9Sstevel@tonic-gate 			error = EFAULT;
12767c478bd9Sstevel@tonic-gate 		kmem_free(ssd, (n+1) * sizeof (*ssd));
12777c478bd9Sstevel@tonic-gate 		break;
12787c478bd9Sstevel@tonic-gate 	}
12797c478bd9Sstevel@tonic-gate #endif	/* __i386 || __amd64 */
12807c478bd9Sstevel@tonic-gate 
12817c478bd9Sstevel@tonic-gate #if defined(__sparc)
12827c478bd9Sstevel@tonic-gate 	case PIOCGWIN:		/* get gwindows_t (see sys/reg.h) */
12837c478bd9Sstevel@tonic-gate 	{
12847c478bd9Sstevel@tonic-gate 		gwindows_t *gwp = thing;
12857c478bd9Sstevel@tonic-gate 
12867c478bd9Sstevel@tonic-gate 		/* drop p->p_lock while touching the stack */
12877c478bd9Sstevel@tonic-gate 		mutex_exit(&p->p_lock);
12887c478bd9Sstevel@tonic-gate 		bzero(gwp, sizeof (*gwp));
12897c478bd9Sstevel@tonic-gate 		prgetwindows(lwp, gwp);
12907c478bd9Sstevel@tonic-gate 		mutex_enter(&p->p_lock);
12917c478bd9Sstevel@tonic-gate 		prunlock(pnp);
12927c478bd9Sstevel@tonic-gate 		if (copyout(gwp, cmaddr, sizeof (*gwp)))
12937c478bd9Sstevel@tonic-gate 			error = EFAULT;
12947c478bd9Sstevel@tonic-gate 		kmem_free(gwp, sizeof (gwindows_t));
12957c478bd9Sstevel@tonic-gate 		thing = NULL;
12967c478bd9Sstevel@tonic-gate 		break;
12977c478bd9Sstevel@tonic-gate 	}
12987c478bd9Sstevel@tonic-gate #endif	/* __sparc */
12997c478bd9Sstevel@tonic-gate 
13007c478bd9Sstevel@tonic-gate 	default:
13017c478bd9Sstevel@tonic-gate 		prunlock(pnp);
13027c478bd9Sstevel@tonic-gate 		error = EINVAL;
13037c478bd9Sstevel@tonic-gate 		break;
13047c478bd9Sstevel@tonic-gate 
13057c478bd9Sstevel@tonic-gate 	}
13067c478bd9Sstevel@tonic-gate 
13077c478bd9Sstevel@tonic-gate 	ASSERT(thing == NULL);
13087c478bd9Sstevel@tonic-gate 	ASSERT(xpnp == NULL);
13097c478bd9Sstevel@tonic-gate 	return (error);
13107c478bd9Sstevel@tonic-gate }
13117c478bd9Sstevel@tonic-gate 
13127c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
13137c478bd9Sstevel@tonic-gate 
13147c478bd9Sstevel@tonic-gate static int oprgetmap32(proc_t *, ioc_prmap32_t **, size_t *);
13157c478bd9Sstevel@tonic-gate 
13167c478bd9Sstevel@tonic-gate void
13177c478bd9Sstevel@tonic-gate oprgetstatus32(kthread_t *t, prstatus32_t *sp, zone_t *zp)
13187c478bd9Sstevel@tonic-gate {
13197c478bd9Sstevel@tonic-gate 	proc_t *p = ttoproc(t);
13207c478bd9Sstevel@tonic-gate 	klwp_t *lwp = ttolwp(t);
13217c478bd9Sstevel@tonic-gate 	int32_t flags;
13227c478bd9Sstevel@tonic-gate 	user_t *up;
13237c478bd9Sstevel@tonic-gate 	ulong_t instr;
13247c478bd9Sstevel@tonic-gate 
13257c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&p->p_lock));
13267c478bd9Sstevel@tonic-gate 
13277c478bd9Sstevel@tonic-gate 	up = PTOU(p);
13287c478bd9Sstevel@tonic-gate 	bzero(sp, sizeof (*sp));
13297c478bd9Sstevel@tonic-gate 	flags = 0L;
13307c478bd9Sstevel@tonic-gate 	if (t->t_state == TS_STOPPED) {
13317c478bd9Sstevel@tonic-gate 		flags |= PR_STOPPED;
13327c478bd9Sstevel@tonic-gate 		if ((t->t_schedflag & TS_PSTART) == 0)
13337c478bd9Sstevel@tonic-gate 			flags |= PR_ISTOP;
13347c478bd9Sstevel@tonic-gate 	} else if (VSTOPPED(t)) {
13357c478bd9Sstevel@tonic-gate 		flags |= PR_STOPPED|PR_ISTOP;
13367c478bd9Sstevel@tonic-gate 	}
13377c478bd9Sstevel@tonic-gate 	if (!(flags & PR_ISTOP) && (t->t_proc_flag & TP_PRSTOP))
13387c478bd9Sstevel@tonic-gate 		flags |= PR_DSTOP;
13397c478bd9Sstevel@tonic-gate 	if (lwp->lwp_asleep)
13407c478bd9Sstevel@tonic-gate 		flags |= PR_ASLEEP;
13417c478bd9Sstevel@tonic-gate 	if (p->p_proc_flag & P_PR_FORK)
13427c478bd9Sstevel@tonic-gate 		flags |= PR_FORK;
13437c478bd9Sstevel@tonic-gate 	if (p->p_proc_flag & P_PR_RUNLCL)
13447c478bd9Sstevel@tonic-gate 		flags |= PR_RLC;
13457c478bd9Sstevel@tonic-gate 	if (p->p_proc_flag & P_PR_KILLCL)
13467c478bd9Sstevel@tonic-gate 		flags |= PR_KLC;
13477c478bd9Sstevel@tonic-gate 	if (p->p_proc_flag & P_PR_ASYNC)
13487c478bd9Sstevel@tonic-gate 		flags |= PR_ASYNC;
13497c478bd9Sstevel@tonic-gate 	if (p->p_proc_flag & P_PR_BPTADJ)
13507c478bd9Sstevel@tonic-gate 		flags |= PR_BPTADJ;
13517c478bd9Sstevel@tonic-gate 	if (p->p_proc_flag & P_PR_PTRACE)
13527c478bd9Sstevel@tonic-gate 		flags |= PR_PCOMPAT;
13537c478bd9Sstevel@tonic-gate 	if (t->t_proc_flag & TP_MSACCT)
13547c478bd9Sstevel@tonic-gate 		flags |= PR_MSACCT;
13557c478bd9Sstevel@tonic-gate 	sp->pr_flags = flags;
13567c478bd9Sstevel@tonic-gate 	if (VSTOPPED(t)) {
13577c478bd9Sstevel@tonic-gate 		sp->pr_why   = PR_REQUESTED;
13587c478bd9Sstevel@tonic-gate 		sp->pr_what  = 0;
13597c478bd9Sstevel@tonic-gate 	} else {
13607c478bd9Sstevel@tonic-gate 		sp->pr_why   = t->t_whystop;
13617c478bd9Sstevel@tonic-gate 		sp->pr_what  = t->t_whatstop;
13627c478bd9Sstevel@tonic-gate 	}
13637c478bd9Sstevel@tonic-gate 
13647c478bd9Sstevel@tonic-gate 	if (t->t_whystop == PR_FAULTED) {
13657c478bd9Sstevel@tonic-gate 		siginfo_kto32(&lwp->lwp_siginfo, &sp->pr_info);
13667c478bd9Sstevel@tonic-gate 		if (t->t_whatstop == FLTPAGE)
13677c478bd9Sstevel@tonic-gate 			sp->pr_info.si_addr =
13687c478bd9Sstevel@tonic-gate 			    (caddr32_t)(uintptr_t)lwp->lwp_siginfo.si_addr;
13697c478bd9Sstevel@tonic-gate 	} else if (lwp->lwp_curinfo)
13707c478bd9Sstevel@tonic-gate 		siginfo_kto32(&lwp->lwp_curinfo->sq_info, &sp->pr_info);
13717c478bd9Sstevel@tonic-gate 
13727c478bd9Sstevel@tonic-gate 	if (SI_FROMUSER(&lwp->lwp_siginfo) && zp->zone_id != GLOBAL_ZONEID &&
13737c478bd9Sstevel@tonic-gate 	    sp->pr_info.si_zoneid != zp->zone_id) {
13747c478bd9Sstevel@tonic-gate 		sp->pr_info.si_pid = zp->zone_zsched->p_pid;
13757c478bd9Sstevel@tonic-gate 		sp->pr_info.si_uid = 0;
13767c478bd9Sstevel@tonic-gate 		sp->pr_info.si_ctid = -1;
13777c478bd9Sstevel@tonic-gate 		sp->pr_info.si_zoneid = zp->zone_id;
13787c478bd9Sstevel@tonic-gate 	}
13797c478bd9Sstevel@tonic-gate 
13807c478bd9Sstevel@tonic-gate 	sp->pr_cursig  = lwp->lwp_cursig;
13817c478bd9Sstevel@tonic-gate 	prassignset(&sp->pr_sigpend, &p->p_sig);
13827c478bd9Sstevel@tonic-gate 	prassignset(&sp->pr_lwppend, &t->t_sig);
13837c478bd9Sstevel@tonic-gate 	schedctl_finish_sigblock(t);
13847c478bd9Sstevel@tonic-gate 	prassignset(&sp->pr_sighold, &t->t_hold);
13857c478bd9Sstevel@tonic-gate 	sp->pr_altstack.ss_sp =
13867c478bd9Sstevel@tonic-gate 	    (caddr32_t)(uintptr_t)lwp->lwp_sigaltstack.ss_sp;
13877c478bd9Sstevel@tonic-gate 	sp->pr_altstack.ss_size = (size32_t)lwp->lwp_sigaltstack.ss_size;
13887c478bd9Sstevel@tonic-gate 	sp->pr_altstack.ss_flags = (int32_t)lwp->lwp_sigaltstack.ss_flags;
13897c478bd9Sstevel@tonic-gate 	prgetaction32(p, up, lwp->lwp_cursig, &sp->pr_action);
13907c478bd9Sstevel@tonic-gate 	sp->pr_pid   = p->p_pid;
13917c478bd9Sstevel@tonic-gate 	if (curproc->p_zone->zone_id != GLOBAL_ZONEID &&
13927c478bd9Sstevel@tonic-gate 	    (p->p_flag & SZONETOP)) {
13937c478bd9Sstevel@tonic-gate 		ASSERT(p->p_zone->zone_id != GLOBAL_ZONEID);
13947c478bd9Sstevel@tonic-gate 		/*
13957c478bd9Sstevel@tonic-gate 		 * Inside local zones, fake zsched's pid as parent pids for
13967c478bd9Sstevel@tonic-gate 		 * processes which reference processes outside of the zone.
13977c478bd9Sstevel@tonic-gate 		 */
13987c478bd9Sstevel@tonic-gate 		sp->pr_ppid = curproc->p_zone->zone_zsched->p_pid;
13997c478bd9Sstevel@tonic-gate 	} else {
14007c478bd9Sstevel@tonic-gate 		sp->pr_ppid = p->p_ppid;
14017c478bd9Sstevel@tonic-gate 	}
14027c478bd9Sstevel@tonic-gate 	sp->pr_pgrp  = p->p_pgrp;
14037c478bd9Sstevel@tonic-gate 	sp->pr_sid   = p->p_sessp->s_sid;
14047c478bd9Sstevel@tonic-gate 	hrt2ts32(mstate_aggr_state(p, LMS_USER), &sp->pr_utime);
14057c478bd9Sstevel@tonic-gate 	hrt2ts32(mstate_aggr_state(p, LMS_SYSTEM), &sp->pr_stime);
14067c478bd9Sstevel@tonic-gate 	TICK_TO_TIMESTRUC32(p->p_cutime, &sp->pr_cutime);
14077c478bd9Sstevel@tonic-gate 	TICK_TO_TIMESTRUC32(p->p_cstime, &sp->pr_cstime);
14087c478bd9Sstevel@tonic-gate 	(void) strncpy(sp->pr_clname, sclass[t->t_cid].cl_name,
14097c478bd9Sstevel@tonic-gate 		sizeof (sp->pr_clname) - 1);
14107c478bd9Sstevel@tonic-gate 	sp->pr_who = t->t_tid;
14117c478bd9Sstevel@tonic-gate 	sp->pr_nlwp = p->p_lwpcnt;
14127c478bd9Sstevel@tonic-gate 	sp->pr_brkbase = (caddr32_t)(uintptr_t)p->p_brkbase;
14137c478bd9Sstevel@tonic-gate 	sp->pr_brksize = (size32_t)p->p_brksize;
14147c478bd9Sstevel@tonic-gate 	sp->pr_stkbase = (caddr32_t)(uintptr_t)prgetstackbase(p);
14157c478bd9Sstevel@tonic-gate 	sp->pr_stksize = (size32_t)p->p_stksize;
14167c478bd9Sstevel@tonic-gate 	sp->pr_oldcontext = (caddr32_t)lwp->lwp_oldcontext;
14177c478bd9Sstevel@tonic-gate 	sp->pr_processor = t->t_cpu->cpu_id;
14187c478bd9Sstevel@tonic-gate 	sp->pr_bind = t->t_bind_cpu;
14197c478bd9Sstevel@tonic-gate 
14207c478bd9Sstevel@tonic-gate 	/*
14217c478bd9Sstevel@tonic-gate 	 * Fetch the current instruction, if not a system process.
14227c478bd9Sstevel@tonic-gate 	 * We don't attempt this unless the lwp is stopped.
14237c478bd9Sstevel@tonic-gate 	 */
14247c478bd9Sstevel@tonic-gate 	if ((p->p_flag & SSYS) || p->p_as == &kas)
14257c478bd9Sstevel@tonic-gate 		sp->pr_flags |= (PR_ISSYS|PR_PCINVAL);
14267c478bd9Sstevel@tonic-gate 	else if (!(flags & PR_STOPPED))
14277c478bd9Sstevel@tonic-gate 		sp->pr_flags |= PR_PCINVAL;
14287c478bd9Sstevel@tonic-gate 	else if (!prfetchinstr(lwp, &instr))
14297c478bd9Sstevel@tonic-gate 		sp->pr_flags |= PR_PCINVAL;
14307c478bd9Sstevel@tonic-gate 	else
14317c478bd9Sstevel@tonic-gate 		sp->pr_instr = (uint32_t)instr;
14327c478bd9Sstevel@tonic-gate 
14337c478bd9Sstevel@tonic-gate 	/*
14347c478bd9Sstevel@tonic-gate 	 * Drop p_lock while touching the lwp's stack.
14357c478bd9Sstevel@tonic-gate 	 */
14367c478bd9Sstevel@tonic-gate 	mutex_exit(&p->p_lock);
14377c478bd9Sstevel@tonic-gate 	if (prisstep(lwp))
14387c478bd9Sstevel@tonic-gate 		sp->pr_flags |= PR_STEP;
14397c478bd9Sstevel@tonic-gate 	if ((flags & (PR_STOPPED|PR_ASLEEP)) && t->t_sysnum) {
14407c478bd9Sstevel@tonic-gate 		int i;
14417c478bd9Sstevel@tonic-gate 		auxv_t *auxp;
14427c478bd9Sstevel@tonic-gate 
14437c478bd9Sstevel@tonic-gate 		sp->pr_syscall = get_syscall32_args(lwp,
14447c478bd9Sstevel@tonic-gate 			(int *)sp->pr_sysarg, &i);
14457c478bd9Sstevel@tonic-gate 		sp->pr_nsysarg = (short)i;
14467c478bd9Sstevel@tonic-gate 		if (t->t_whystop == PR_SYSEXIT &&
14477c478bd9Sstevel@tonic-gate 		    (t->t_sysnum == SYS_exec || t->t_sysnum == SYS_execve)) {
14487c478bd9Sstevel@tonic-gate 			sp->pr_sysarg[0] = 0;
14497c478bd9Sstevel@tonic-gate 			sp->pr_sysarg[1] = (caddr32_t)up->u_argv;
14507c478bd9Sstevel@tonic-gate 			sp->pr_sysarg[2] = (caddr32_t)up->u_envp;
14517c478bd9Sstevel@tonic-gate 			for (i = 0, auxp = up->u_auxv;
14527c478bd9Sstevel@tonic-gate 			    i < sizeof (up->u_auxv) / sizeof (up->u_auxv[0]);
14537c478bd9Sstevel@tonic-gate 			    i++, auxp++) {
14547c478bd9Sstevel@tonic-gate 				if (auxp->a_type == AT_SUN_EXECNAME) {
14557c478bd9Sstevel@tonic-gate 					sp->pr_sysarg[0] =
14567c478bd9Sstevel@tonic-gate 					(caddr32_t)(uintptr_t)auxp->a_un.a_ptr;
14577c478bd9Sstevel@tonic-gate 					break;
14587c478bd9Sstevel@tonic-gate 				}
14597c478bd9Sstevel@tonic-gate 			}
14607c478bd9Sstevel@tonic-gate 		}
14617c478bd9Sstevel@tonic-gate 	}
14627c478bd9Sstevel@tonic-gate 	if ((flags & PR_STOPPED) || t == curthread)
14637c478bd9Sstevel@tonic-gate 		prgetprregs32(lwp, sp->pr_reg);
14647c478bd9Sstevel@tonic-gate 	mutex_enter(&p->p_lock);
14657c478bd9Sstevel@tonic-gate }
14667c478bd9Sstevel@tonic-gate 
14677c478bd9Sstevel@tonic-gate void
14687c478bd9Sstevel@tonic-gate oprgetpsinfo32(proc_t *p, prpsinfo32_t *psp, kthread_t *tp)
14697c478bd9Sstevel@tonic-gate {
14707c478bd9Sstevel@tonic-gate 	kthread_t *t;
14717c478bd9Sstevel@tonic-gate 	char c, state;
14727c478bd9Sstevel@tonic-gate 	user_t *up;
14737c478bd9Sstevel@tonic-gate 	dev_t d;
14747c478bd9Sstevel@tonic-gate 	uint64_t pct;
14757c478bd9Sstevel@tonic-gate 	int retval, niceval;
14767c478bd9Sstevel@tonic-gate 	cred_t *cred;
14777c478bd9Sstevel@tonic-gate 	struct as *as;
14787c478bd9Sstevel@tonic-gate 	hrtime_t hrutime, hrstime, cur_time;
14797c478bd9Sstevel@tonic-gate 
14807c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&p->p_lock));
14817c478bd9Sstevel@tonic-gate 
14827c478bd9Sstevel@tonic-gate 	bzero(psp, sizeof (*psp));
14837c478bd9Sstevel@tonic-gate 
14847c478bd9Sstevel@tonic-gate 	if ((t = tp) == NULL)
14857c478bd9Sstevel@tonic-gate 		t = prchoose(p);	/* returns locked thread */
14867c478bd9Sstevel@tonic-gate 	else
14877c478bd9Sstevel@tonic-gate 		thread_lock(t);
14887c478bd9Sstevel@tonic-gate 
14897c478bd9Sstevel@tonic-gate 	/* kludge: map thread state enum into process state enum */
14907c478bd9Sstevel@tonic-gate 
14917c478bd9Sstevel@tonic-gate 	if (t == NULL) {
14927c478bd9Sstevel@tonic-gate 		state = TS_ZOMB;
14937c478bd9Sstevel@tonic-gate 	} else {
14947c478bd9Sstevel@tonic-gate 		state = VSTOPPED(t) ? TS_STOPPED : t->t_state;
14957c478bd9Sstevel@tonic-gate 		thread_unlock(t);
14967c478bd9Sstevel@tonic-gate 	}
14977c478bd9Sstevel@tonic-gate 
14987c478bd9Sstevel@tonic-gate 	switch (state) {
14997c478bd9Sstevel@tonic-gate 	case TS_SLEEP:		state = SSLEEP;		break;
15007c478bd9Sstevel@tonic-gate 	case TS_RUN:		state = SRUN;		break;
15017c478bd9Sstevel@tonic-gate 	case TS_ONPROC:		state = SONPROC;	break;
15027c478bd9Sstevel@tonic-gate 	case TS_ZOMB:		state = SZOMB;		break;
15037c478bd9Sstevel@tonic-gate 	case TS_STOPPED:	state = SSTOP;		break;
15047c478bd9Sstevel@tonic-gate 	default:		state = 0;		break;
15057c478bd9Sstevel@tonic-gate 	}
15067c478bd9Sstevel@tonic-gate 	switch (state) {
15077c478bd9Sstevel@tonic-gate 	case SSLEEP:	c = 'S';	break;
15087c478bd9Sstevel@tonic-gate 	case SRUN:	c = 'R';	break;
15097c478bd9Sstevel@tonic-gate 	case SZOMB:	c = 'Z';	break;
15107c478bd9Sstevel@tonic-gate 	case SSTOP:	c = 'T';	break;
15117c478bd9Sstevel@tonic-gate 	case SIDL:	c = 'I';	break;
15127c478bd9Sstevel@tonic-gate 	case SONPROC:	c = 'O';	break;
15137c478bd9Sstevel@tonic-gate #ifdef SXBRK
15147c478bd9Sstevel@tonic-gate 	case SXBRK:	c = 'X';	break;
15157c478bd9Sstevel@tonic-gate #endif
15167c478bd9Sstevel@tonic-gate 	default:	c = '?';	break;
15177c478bd9Sstevel@tonic-gate 	}
15187c478bd9Sstevel@tonic-gate 	psp->pr_state = state;
15197c478bd9Sstevel@tonic-gate 	psp->pr_sname = c;
15207c478bd9Sstevel@tonic-gate 	psp->pr_zomb = (state == SZOMB);
15217c478bd9Sstevel@tonic-gate 	/*
15227c478bd9Sstevel@tonic-gate 	 * only export SSYS and SMSACCT; everything else is off-limits to
15237c478bd9Sstevel@tonic-gate 	 * userland apps.
15247c478bd9Sstevel@tonic-gate 	 */
15257c478bd9Sstevel@tonic-gate 	psp->pr_flag = p->p_flag & (SSYS | SMSACCT);
15267c478bd9Sstevel@tonic-gate 
15277c478bd9Sstevel@tonic-gate 	mutex_enter(&p->p_crlock);
15287c478bd9Sstevel@tonic-gate 	cred = p->p_cred;
15297c478bd9Sstevel@tonic-gate 	psp->pr_uid = crgetruid(cred);
15307c478bd9Sstevel@tonic-gate 	psp->pr_gid = crgetrgid(cred);
15317c478bd9Sstevel@tonic-gate 	psp->pr_euid = crgetuid(cred);
15327c478bd9Sstevel@tonic-gate 	psp->pr_egid = crgetgid(cred);
15337c478bd9Sstevel@tonic-gate 	mutex_exit(&p->p_crlock);
15347c478bd9Sstevel@tonic-gate 
15357c478bd9Sstevel@tonic-gate 	psp->pr_pid = p->p_pid;
15367c478bd9Sstevel@tonic-gate 	if (curproc->p_zone->zone_id != GLOBAL_ZONEID &&
15377c478bd9Sstevel@tonic-gate 	    (p->p_flag & SZONETOP)) {
15387c478bd9Sstevel@tonic-gate 		ASSERT(p->p_zone->zone_id != GLOBAL_ZONEID);
15397c478bd9Sstevel@tonic-gate 		/*
15407c478bd9Sstevel@tonic-gate 		 * Inside local zones, fake zsched's pid as parent pids for
15417c478bd9Sstevel@tonic-gate 		 * processes which reference processes outside of the zone.
15427c478bd9Sstevel@tonic-gate 		 */
15437c478bd9Sstevel@tonic-gate 		psp->pr_ppid = curproc->p_zone->zone_zsched->p_pid;
15447c478bd9Sstevel@tonic-gate 	} else {
15457c478bd9Sstevel@tonic-gate 		psp->pr_ppid = p->p_ppid;
15467c478bd9Sstevel@tonic-gate 	}
15477c478bd9Sstevel@tonic-gate 	psp->pr_pgrp = p->p_pgrp;
15487c478bd9Sstevel@tonic-gate 	psp->pr_sid = p->p_sessp->s_sid;
15497c478bd9Sstevel@tonic-gate 	psp->pr_addr = 0;	/* cannot represent 64-bit addr in 32 bits */
15507c478bd9Sstevel@tonic-gate 	hrutime = mstate_aggr_state(p, LMS_USER);
15517c478bd9Sstevel@tonic-gate 	hrstime = mstate_aggr_state(p, LMS_SYSTEM);
15527c478bd9Sstevel@tonic-gate 	hrt2ts32(hrutime + hrstime, &psp->pr_time);
15537c478bd9Sstevel@tonic-gate 	TICK_TO_TIMESTRUC32(p->p_cutime + p->p_cstime, &psp->pr_ctime);
15547c478bd9Sstevel@tonic-gate 	switch (p->p_model) {
15557c478bd9Sstevel@tonic-gate 	case DATAMODEL_ILP32:
15567c478bd9Sstevel@tonic-gate 		psp->pr_dmodel = PR_MODEL_ILP32;
15577c478bd9Sstevel@tonic-gate 		break;
15587c478bd9Sstevel@tonic-gate 	case DATAMODEL_LP64:
15597c478bd9Sstevel@tonic-gate 		psp->pr_dmodel = PR_MODEL_LP64;
15607c478bd9Sstevel@tonic-gate 		break;
15617c478bd9Sstevel@tonic-gate 	}
15627c478bd9Sstevel@tonic-gate 	if (state == SZOMB || t == NULL) {
15637c478bd9Sstevel@tonic-gate 		int wcode = p->p_wcode;		/* must be atomic read */
15647c478bd9Sstevel@tonic-gate 
15657c478bd9Sstevel@tonic-gate 		if (wcode)
15667c478bd9Sstevel@tonic-gate 			psp->pr_wstat = wstat(wcode, p->p_wdata);
15677c478bd9Sstevel@tonic-gate 		psp->pr_lttydev = PRNODEV32;
15687c478bd9Sstevel@tonic-gate 		psp->pr_ottydev = (o_dev_t)PRNODEV32;
15697c478bd9Sstevel@tonic-gate 		psp->pr_size = 0;
15707c478bd9Sstevel@tonic-gate 		psp->pr_rssize = 0;
15717c478bd9Sstevel@tonic-gate 		psp->pr_pctmem = 0;
15727c478bd9Sstevel@tonic-gate 	} else {
15737c478bd9Sstevel@tonic-gate 		up = PTOU(p);
15747c478bd9Sstevel@tonic-gate 		psp->pr_wchan = 0;	/* cannot represent in 32 bits */
15757c478bd9Sstevel@tonic-gate 		psp->pr_pri = t->t_pri;
15767c478bd9Sstevel@tonic-gate 		(void) strncpy(psp->pr_clname, sclass[t->t_cid].cl_name,
15777c478bd9Sstevel@tonic-gate 			sizeof (psp->pr_clname) - 1);
15787c478bd9Sstevel@tonic-gate 		retval = CL_DONICE(t, NULL, 0, &niceval);
15797c478bd9Sstevel@tonic-gate 		if (retval == 0) {
15807c478bd9Sstevel@tonic-gate 			psp->pr_oldpri = v.v_maxsyspri - psp->pr_pri;
15817c478bd9Sstevel@tonic-gate 			psp->pr_nice = niceval + NZERO;
15827c478bd9Sstevel@tonic-gate 		} else {
15837c478bd9Sstevel@tonic-gate 			psp->pr_oldpri = 0;
15847c478bd9Sstevel@tonic-gate 			psp->pr_nice = 0;
15857c478bd9Sstevel@tonic-gate 		}
15867c478bd9Sstevel@tonic-gate 		d = cttydev(p);
15877c478bd9Sstevel@tonic-gate #ifdef sun
15887c478bd9Sstevel@tonic-gate 		{
15897c478bd9Sstevel@tonic-gate 			extern dev_t rwsconsdev, rconsdev, uconsdev;
15907c478bd9Sstevel@tonic-gate 			/*
15917c478bd9Sstevel@tonic-gate 			 * If the controlling terminal is the real
15927c478bd9Sstevel@tonic-gate 			 * or workstation console device, map to what the
15937c478bd9Sstevel@tonic-gate 			 * user thinks is the console device.
15947c478bd9Sstevel@tonic-gate 			 */
15957c478bd9Sstevel@tonic-gate 			if (d == rwsconsdev || d == rconsdev)
15967c478bd9Sstevel@tonic-gate 				d = uconsdev;
15977c478bd9Sstevel@tonic-gate 		}
15987c478bd9Sstevel@tonic-gate #endif
15997c478bd9Sstevel@tonic-gate 		(void) cmpldev(&psp->pr_lttydev, d);
16007c478bd9Sstevel@tonic-gate 		psp->pr_ottydev = cmpdev(d);
16017c478bd9Sstevel@tonic-gate 		TIMESPEC_TO_TIMESPEC32(&psp->pr_start, &up->u_start);
16027c478bd9Sstevel@tonic-gate 		bcopy(up->u_comm, psp->pr_fname,
16037c478bd9Sstevel@tonic-gate 		    MIN(sizeof (up->u_comm), sizeof (psp->pr_fname)-1));
16047c478bd9Sstevel@tonic-gate 		bcopy(up->u_psargs, psp->pr_psargs,
16057c478bd9Sstevel@tonic-gate 		    MIN(PRARGSZ-1, PSARGSZ));
16067c478bd9Sstevel@tonic-gate 		psp->pr_syscall = t->t_sysnum;
16077c478bd9Sstevel@tonic-gate 		psp->pr_argc = up->u_argc;
16087c478bd9Sstevel@tonic-gate 		psp->pr_argv = (caddr32_t)up->u_argv;
16097c478bd9Sstevel@tonic-gate 		psp->pr_envp = (caddr32_t)up->u_envp;
16107c478bd9Sstevel@tonic-gate 
16117c478bd9Sstevel@tonic-gate 		/* compute %cpu for the lwp or process */
16127c478bd9Sstevel@tonic-gate 		pct = 0;
16137c478bd9Sstevel@tonic-gate 		if ((t = tp) == NULL)
16147c478bd9Sstevel@tonic-gate 			t = p->p_tlist;
16157c478bd9Sstevel@tonic-gate 		cur_time = gethrtime_unscaled();
16167c478bd9Sstevel@tonic-gate 		do {
16177c478bd9Sstevel@tonic-gate 			pct += cpu_update_pct(t, cur_time);
16187c478bd9Sstevel@tonic-gate 			if (tp != NULL)		/* just do the one lwp */
16197c478bd9Sstevel@tonic-gate 				break;
16207c478bd9Sstevel@tonic-gate 		} while ((t = t->t_forw) != p->p_tlist);
16217c478bd9Sstevel@tonic-gate 
16227c478bd9Sstevel@tonic-gate 		psp->pr_pctcpu = prgetpctcpu(pct);
16237c478bd9Sstevel@tonic-gate 		psp->pr_cpu = (psp->pr_pctcpu*100 + 0x6000) >> 15; /* [0..99] */
16247c478bd9Sstevel@tonic-gate 		if (psp->pr_cpu > 99)
16257c478bd9Sstevel@tonic-gate 			psp->pr_cpu = 99;
16267c478bd9Sstevel@tonic-gate 
16277c478bd9Sstevel@tonic-gate 		if ((p->p_flag & SSYS) || (as = p->p_as) == &kas) {
16287c478bd9Sstevel@tonic-gate 			psp->pr_size = 0;
16297c478bd9Sstevel@tonic-gate 			psp->pr_rssize = 0;
16307c478bd9Sstevel@tonic-gate 			psp->pr_pctmem = 0;
16317c478bd9Sstevel@tonic-gate 		} else {
16327c478bd9Sstevel@tonic-gate 			mutex_exit(&p->p_lock);
16337c478bd9Sstevel@tonic-gate 			AS_LOCK_ENTER(as, &as->a_lock, RW_READER);
16347c478bd9Sstevel@tonic-gate 			psp->pr_size = (size32_t)btopr(rm_assize(as));
16357c478bd9Sstevel@tonic-gate 			psp->pr_rssize = (size32_t)rm_asrss(as);
16367c478bd9Sstevel@tonic-gate 			psp->pr_pctmem = rm_pctmemory(as);
16377c478bd9Sstevel@tonic-gate 			AS_LOCK_EXIT(as, &as->a_lock);
16387c478bd9Sstevel@tonic-gate 			mutex_enter(&p->p_lock);
16397c478bd9Sstevel@tonic-gate 		}
16407c478bd9Sstevel@tonic-gate 	}
16417c478bd9Sstevel@tonic-gate 	psp->pr_bysize = (size32_t)ptob(psp->pr_size);
16427c478bd9Sstevel@tonic-gate 	psp->pr_byrssize = (size32_t)ptob(psp->pr_rssize);
16437c478bd9Sstevel@tonic-gate 
16447c478bd9Sstevel@tonic-gate 	/*
16457c478bd9Sstevel@tonic-gate 	 * If we are looking at an LP64 process, zero out
16467c478bd9Sstevel@tonic-gate 	 * the fields that cannot be represented in ILP32.
16477c478bd9Sstevel@tonic-gate 	 */
16487c478bd9Sstevel@tonic-gate 	if (p->p_model != DATAMODEL_ILP32) {
16497c478bd9Sstevel@tonic-gate 		psp->pr_size = 0;
16507c478bd9Sstevel@tonic-gate 		psp->pr_rssize = 0;
16517c478bd9Sstevel@tonic-gate 		psp->pr_bysize = 0;
16527c478bd9Sstevel@tonic-gate 		psp->pr_byrssize = 0;
16537c478bd9Sstevel@tonic-gate 		psp->pr_argv = 0;
16547c478bd9Sstevel@tonic-gate 		psp->pr_envp = 0;
16557c478bd9Sstevel@tonic-gate 	}
16567c478bd9Sstevel@tonic-gate }
16577c478bd9Sstevel@tonic-gate 
16587c478bd9Sstevel@tonic-gate static int
16597c478bd9Sstevel@tonic-gate prioctl32(struct vnode *vp, int cmd, intptr_t arg, int flag,
16607c478bd9Sstevel@tonic-gate 	cred_t *cr, int *rvalp)
16617c478bd9Sstevel@tonic-gate {
16627c478bd9Sstevel@tonic-gate 	caddr_t cmaddr = (caddr_t)arg;
16637c478bd9Sstevel@tonic-gate 	proc_t *p;
16647c478bd9Sstevel@tonic-gate 	user_t *up;
16657c478bd9Sstevel@tonic-gate 	kthread_t *t;
16667c478bd9Sstevel@tonic-gate 	klwp_t *lwp;
16677c478bd9Sstevel@tonic-gate 	prnode_t *pnp = VTOP(vp);
16687c478bd9Sstevel@tonic-gate 	prcommon_t *pcp;
16697c478bd9Sstevel@tonic-gate 	prnode_t *xpnp = NULL;
16707c478bd9Sstevel@tonic-gate 	int error;
16717c478bd9Sstevel@tonic-gate 	int zdisp;
16727c478bd9Sstevel@tonic-gate 	void *thing = NULL;
16737c478bd9Sstevel@tonic-gate 	size_t thingsize = 0;
16747c478bd9Sstevel@tonic-gate 
16757c478bd9Sstevel@tonic-gate 	/*
16767c478bd9Sstevel@tonic-gate 	 * For copyin()/copyout().
16777c478bd9Sstevel@tonic-gate 	 */
16787c478bd9Sstevel@tonic-gate 	union {
16797c478bd9Sstevel@tonic-gate 		caddr32_t	va;
16807c478bd9Sstevel@tonic-gate 		int		signo;
16817c478bd9Sstevel@tonic-gate 		int		nice;
16827c478bd9Sstevel@tonic-gate 		uint_t		lwpid;
16837c478bd9Sstevel@tonic-gate 		int32_t		flags;
16847c478bd9Sstevel@tonic-gate 		prstatus32_t	prstat;
16857c478bd9Sstevel@tonic-gate 		prrun32_t	prrun;
16867c478bd9Sstevel@tonic-gate 		sigset_t	smask;
16877c478bd9Sstevel@tonic-gate 		siginfo32_t	info;
16887c478bd9Sstevel@tonic-gate 		sysset_t	prmask;
16897c478bd9Sstevel@tonic-gate 		prgregset32_t	regs;
16907c478bd9Sstevel@tonic-gate 		prfpregset32_t	fpregs;
16917c478bd9Sstevel@tonic-gate 		prpsinfo32_t	prps;
16927c478bd9Sstevel@tonic-gate 		sigset_t	holdmask;
16937c478bd9Sstevel@tonic-gate 		fltset_t	fltmask;
16947c478bd9Sstevel@tonic-gate 		prcred_t	prcred;
16957c478bd9Sstevel@tonic-gate 		prusage32_t	prusage;
16967c478bd9Sstevel@tonic-gate 		prhusage_t	prhusage;
16977c478bd9Sstevel@tonic-gate 		ioc_prmap32_t	prmap;
16987c478bd9Sstevel@tonic-gate 		auxv32_t	auxv[__KERN_NAUXV_IMPL];
16997c478bd9Sstevel@tonic-gate 	} un32;
17007c478bd9Sstevel@tonic-gate 
17017c478bd9Sstevel@tonic-gate 	/*
17027c478bd9Sstevel@tonic-gate 	 * Native objects for internal use.
17037c478bd9Sstevel@tonic-gate 	 */
17047c478bd9Sstevel@tonic-gate 	union {
17057c478bd9Sstevel@tonic-gate 		caddr_t		va;
17067c478bd9Sstevel@tonic-gate 		int		signo;
17077c478bd9Sstevel@tonic-gate 		int		nice;
17087c478bd9Sstevel@tonic-gate 		uint_t		lwpid;
17097c478bd9Sstevel@tonic-gate 		long		flags;
17107c478bd9Sstevel@tonic-gate 		prstatus_t	prstat;
17117c478bd9Sstevel@tonic-gate 		prrun_t		prrun;
17127c478bd9Sstevel@tonic-gate 		sigset_t	smask;
17137c478bd9Sstevel@tonic-gate 		siginfo_t	info;
17147c478bd9Sstevel@tonic-gate 		sysset_t	prmask;
17157c478bd9Sstevel@tonic-gate 		prgregset_t	regs;
17167c478bd9Sstevel@tonic-gate 		prpsinfo_t	prps;
17177c478bd9Sstevel@tonic-gate 		sigset_t	holdmask;
17187c478bd9Sstevel@tonic-gate 		fltset_t	fltmask;
17197c478bd9Sstevel@tonic-gate 		prcred_t	prcred;
17207c478bd9Sstevel@tonic-gate 		prusage_t	prusage;
17217c478bd9Sstevel@tonic-gate 		prhusage_t	prhusage;
17227c478bd9Sstevel@tonic-gate 		auxv_t		auxv[__KERN_NAUXV_IMPL];
17237c478bd9Sstevel@tonic-gate 	} un;
17247c478bd9Sstevel@tonic-gate 
17257c478bd9Sstevel@tonic-gate 	if (pnp->pr_type == PR_TMPL)
17267c478bd9Sstevel@tonic-gate 		return (prctioctl(pnp, cmd, arg, flag, cr));
17277c478bd9Sstevel@tonic-gate 
17287c478bd9Sstevel@tonic-gate 	/*
17297c478bd9Sstevel@tonic-gate 	 * Support for old /proc interface.
17307c478bd9Sstevel@tonic-gate 	 */
17317c478bd9Sstevel@tonic-gate 	if (pnp->pr_pidfile != NULL) {
17327c478bd9Sstevel@tonic-gate 		ASSERT(pnp->pr_type == PR_PIDDIR);
17337c478bd9Sstevel@tonic-gate 		vp = pnp->pr_pidfile;
17347c478bd9Sstevel@tonic-gate 		pnp = VTOP(vp);
17357c478bd9Sstevel@tonic-gate 		ASSERT(pnp->pr_type == PR_PIDFILE);
17367c478bd9Sstevel@tonic-gate 	}
17377c478bd9Sstevel@tonic-gate 
17387c478bd9Sstevel@tonic-gate 	if (pnp->pr_type != PR_PIDFILE && pnp->pr_type != PR_LWPIDFILE)
17397c478bd9Sstevel@tonic-gate 		return (ENOTTY);
17407c478bd9Sstevel@tonic-gate 
17417c478bd9Sstevel@tonic-gate 	/*
17427c478bd9Sstevel@tonic-gate 	 * Fail ioctls which are logically "write" requests unless
17437c478bd9Sstevel@tonic-gate 	 * the user has write permission.
17447c478bd9Sstevel@tonic-gate 	 */
17457c478bd9Sstevel@tonic-gate 	if ((flag & FWRITE) == 0 && isprwrioctl(cmd))
17467c478bd9Sstevel@tonic-gate 		return (EBADF);
17477c478bd9Sstevel@tonic-gate 
17487c478bd9Sstevel@tonic-gate 	/*
17497c478bd9Sstevel@tonic-gate 	 * Perform any necessary copyin() operations before
17507c478bd9Sstevel@tonic-gate 	 * locking the process.  Helps avoid deadlocks and
17517c478bd9Sstevel@tonic-gate 	 * improves performance.
17527c478bd9Sstevel@tonic-gate 	 *
17537c478bd9Sstevel@tonic-gate 	 * Also, detect invalid ioctl codes here to avoid
17547c478bd9Sstevel@tonic-gate 	 * locking a process unnnecessarily.
17557c478bd9Sstevel@tonic-gate 	 *
17567c478bd9Sstevel@tonic-gate 	 * Also, prepare to allocate space that will be needed below,
17577c478bd9Sstevel@tonic-gate 	 * case by case.
17587c478bd9Sstevel@tonic-gate 	 */
17597c478bd9Sstevel@tonic-gate 	error = 0;
17607c478bd9Sstevel@tonic-gate 	switch (cmd) {
17617c478bd9Sstevel@tonic-gate 	case PIOCGETPR:
17627c478bd9Sstevel@tonic-gate 		thingsize = sizeof (proc_t);
17637c478bd9Sstevel@tonic-gate 		break;
17647c478bd9Sstevel@tonic-gate 	case PIOCGETU:
17657c478bd9Sstevel@tonic-gate 		thingsize = sizeof (user_t);
17667c478bd9Sstevel@tonic-gate 		break;
17677c478bd9Sstevel@tonic-gate 	case PIOCSTOP:
17687c478bd9Sstevel@tonic-gate 	case PIOCWSTOP:
17697c478bd9Sstevel@tonic-gate 	case PIOCLWPIDS:
17707c478bd9Sstevel@tonic-gate 	case PIOCGTRACE:
17717c478bd9Sstevel@tonic-gate 	case PIOCGENTRY:
17727c478bd9Sstevel@tonic-gate 	case PIOCGEXIT:
17737c478bd9Sstevel@tonic-gate 	case PIOCSRLC:
17747c478bd9Sstevel@tonic-gate 	case PIOCRRLC:
17757c478bd9Sstevel@tonic-gate 	case PIOCSFORK:
17767c478bd9Sstevel@tonic-gate 	case PIOCRFORK:
17777c478bd9Sstevel@tonic-gate 	case PIOCGREG:
17787c478bd9Sstevel@tonic-gate 	case PIOCGFPREG:
17797c478bd9Sstevel@tonic-gate 	case PIOCSTATUS:
17807c478bd9Sstevel@tonic-gate 	case PIOCLSTATUS:
17817c478bd9Sstevel@tonic-gate 	case PIOCPSINFO:
17827c478bd9Sstevel@tonic-gate 	case PIOCMAXSIG:
17837c478bd9Sstevel@tonic-gate 	case PIOCGXREGSIZE:
17847c478bd9Sstevel@tonic-gate 		break;
17857c478bd9Sstevel@tonic-gate 	case PIOCSXREG:		/* set extra registers */
17867c478bd9Sstevel@tonic-gate 	case PIOCGXREG:		/* get extra registers */
17877c478bd9Sstevel@tonic-gate #if defined(__sparc)
17887c478bd9Sstevel@tonic-gate 		thingsize = sizeof (prxregset_t);
17897c478bd9Sstevel@tonic-gate #else
17907c478bd9Sstevel@tonic-gate 		thingsize = 0;
17917c478bd9Sstevel@tonic-gate #endif
17927c478bd9Sstevel@tonic-gate 		break;
17937c478bd9Sstevel@tonic-gate 	case PIOCACTION:
17947c478bd9Sstevel@tonic-gate 		thingsize = (NSIG-1) * sizeof (struct sigaction32);
17957c478bd9Sstevel@tonic-gate 		break;
17967c478bd9Sstevel@tonic-gate 	case PIOCGHOLD:
17977c478bd9Sstevel@tonic-gate 	case PIOCNMAP:
17987c478bd9Sstevel@tonic-gate 	case PIOCMAP:
17997c478bd9Sstevel@tonic-gate 	case PIOCGFAULT:
18007c478bd9Sstevel@tonic-gate 	case PIOCCFAULT:
18017c478bd9Sstevel@tonic-gate 	case PIOCCRED:
18027c478bd9Sstevel@tonic-gate 	case PIOCGROUPS:
18037c478bd9Sstevel@tonic-gate 	case PIOCUSAGE:
18047c478bd9Sstevel@tonic-gate 	case PIOCLUSAGE:
18057c478bd9Sstevel@tonic-gate 		break;
18067c478bd9Sstevel@tonic-gate 	case PIOCOPENPD:
18077c478bd9Sstevel@tonic-gate 		/*
18087c478bd9Sstevel@tonic-gate 		 * We will need this below.
18097c478bd9Sstevel@tonic-gate 		 * Allocate it now, before locking the process.
18107c478bd9Sstevel@tonic-gate 		 */
18117c478bd9Sstevel@tonic-gate 		xpnp = prgetnode(vp, PR_OPAGEDATA);
18127c478bd9Sstevel@tonic-gate 		break;
18137c478bd9Sstevel@tonic-gate 	case PIOCNAUXV:
18147c478bd9Sstevel@tonic-gate 	case PIOCAUXV:
18157c478bd9Sstevel@tonic-gate 		break;
18167c478bd9Sstevel@tonic-gate 
18177c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__i386_COMPAT)
18187c478bd9Sstevel@tonic-gate 	case PIOCNLDT:
18197c478bd9Sstevel@tonic-gate 	case PIOCLDT:
18207c478bd9Sstevel@tonic-gate 		break;
18217c478bd9Sstevel@tonic-gate #endif	/* __i386 || __i386_COMPAT */
18227c478bd9Sstevel@tonic-gate 
18237c478bd9Sstevel@tonic-gate #if defined(__sparc)
18247c478bd9Sstevel@tonic-gate 	case PIOCGWIN:
18257c478bd9Sstevel@tonic-gate 		thingsize = sizeof (gwindows32_t);
18267c478bd9Sstevel@tonic-gate 		break;
18277c478bd9Sstevel@tonic-gate #endif	/* __sparc */
18287c478bd9Sstevel@tonic-gate 
18297c478bd9Sstevel@tonic-gate 	case PIOCOPENM:		/* open mapped object for reading */
18307c478bd9Sstevel@tonic-gate 		if (cmaddr == NULL)
18317c478bd9Sstevel@tonic-gate 			un32.va = NULL;
18327c478bd9Sstevel@tonic-gate 		else if (copyin(cmaddr, &un32.va, sizeof (un32.va)))
18337c478bd9Sstevel@tonic-gate 			error = EFAULT;
18347c478bd9Sstevel@tonic-gate 		break;
18357c478bd9Sstevel@tonic-gate 
18367c478bd9Sstevel@tonic-gate 	case PIOCRUN:		/* make lwp or process runnable */
18377c478bd9Sstevel@tonic-gate 		if (cmaddr == NULL)
18387c478bd9Sstevel@tonic-gate 			un32.prrun.pr_flags = 0;
18397c478bd9Sstevel@tonic-gate 		else if (copyin(cmaddr, &un32.prrun, sizeof (un32.prrun)))
18407c478bd9Sstevel@tonic-gate 			error = EFAULT;
18417c478bd9Sstevel@tonic-gate 		break;
18427c478bd9Sstevel@tonic-gate 
18437c478bd9Sstevel@tonic-gate 	case PIOCOPENLWP:	/* return /proc lwp file descriptor */
18447c478bd9Sstevel@tonic-gate 		if (copyin(cmaddr, &un32.lwpid, sizeof (un32.lwpid)))
18457c478bd9Sstevel@tonic-gate 			error = EFAULT;
18467c478bd9Sstevel@tonic-gate 		break;
18477c478bd9Sstevel@tonic-gate 
18487c478bd9Sstevel@tonic-gate 	case PIOCSTRACE:	/* set signal trace mask */
18497c478bd9Sstevel@tonic-gate 		if (copyin(cmaddr, &un32.smask, sizeof (un32.smask)))
18507c478bd9Sstevel@tonic-gate 			error = EFAULT;
18517c478bd9Sstevel@tonic-gate 		break;
18527c478bd9Sstevel@tonic-gate 
18537c478bd9Sstevel@tonic-gate 	case PIOCSSIG:		/* set current signal */
18547c478bd9Sstevel@tonic-gate 		if (cmaddr == NULL)
18557c478bd9Sstevel@tonic-gate 			un32.info.si_signo = 0;
18567c478bd9Sstevel@tonic-gate 		else if (copyin(cmaddr, &un32.info, sizeof (un32.info)))
18577c478bd9Sstevel@tonic-gate 			error = EFAULT;
18587c478bd9Sstevel@tonic-gate 		break;
18597c478bd9Sstevel@tonic-gate 
18607c478bd9Sstevel@tonic-gate 	case PIOCKILL:		/* send signal */
18617c478bd9Sstevel@tonic-gate 	case PIOCUNKILL:	/* delete a signal */
18627c478bd9Sstevel@tonic-gate 		if (copyin(cmaddr, &un32.signo, sizeof (un32.signo)))
18637c478bd9Sstevel@tonic-gate 			error = EFAULT;
18647c478bd9Sstevel@tonic-gate 		break;
18657c478bd9Sstevel@tonic-gate 
18667c478bd9Sstevel@tonic-gate 	case PIOCNICE:		/* set nice priority */
18677c478bd9Sstevel@tonic-gate 		if (copyin(cmaddr, &un32.nice, sizeof (un32.nice)))
18687c478bd9Sstevel@tonic-gate 			error = EFAULT;
18697c478bd9Sstevel@tonic-gate 		break;
18707c478bd9Sstevel@tonic-gate 
18717c478bd9Sstevel@tonic-gate 	case PIOCSENTRY:	/* set syscall entry bit mask */
18727c478bd9Sstevel@tonic-gate 	case PIOCSEXIT:		/* set syscall exit bit mask */
18737c478bd9Sstevel@tonic-gate 		if (copyin(cmaddr, &un32.prmask, sizeof (un32.prmask)))
18747c478bd9Sstevel@tonic-gate 			error = EFAULT;
18757c478bd9Sstevel@tonic-gate 		break;
18767c478bd9Sstevel@tonic-gate 
18777c478bd9Sstevel@tonic-gate 	case PIOCSET:		/* set process flags */
18787c478bd9Sstevel@tonic-gate 	case PIOCRESET:		/* reset process flags */
18797c478bd9Sstevel@tonic-gate 		if (copyin(cmaddr, &un32.flags, sizeof (un32.flags)))
18807c478bd9Sstevel@tonic-gate 			error = EFAULT;
18817c478bd9Sstevel@tonic-gate 		break;
18827c478bd9Sstevel@tonic-gate 
18837c478bd9Sstevel@tonic-gate 	case PIOCSREG:		/* set general registers */
18847c478bd9Sstevel@tonic-gate 		if (copyin(cmaddr, un32.regs, sizeof (un32.regs)))
18857c478bd9Sstevel@tonic-gate 			error = EFAULT;
18867c478bd9Sstevel@tonic-gate 		break;
18877c478bd9Sstevel@tonic-gate 
18887c478bd9Sstevel@tonic-gate 	case PIOCSFPREG:	/* set floating-point registers */
18897c478bd9Sstevel@tonic-gate 		if (copyin(cmaddr, &un32.fpregs, sizeof (un32.fpregs)))
18907c478bd9Sstevel@tonic-gate 			error = EFAULT;
18917c478bd9Sstevel@tonic-gate 		break;
18927c478bd9Sstevel@tonic-gate 
18937c478bd9Sstevel@tonic-gate 	case PIOCSHOLD:		/* set signal-hold mask */
18947c478bd9Sstevel@tonic-gate 		if (copyin(cmaddr, &un32.holdmask, sizeof (un32.holdmask)))
18957c478bd9Sstevel@tonic-gate 			error = EFAULT;
18967c478bd9Sstevel@tonic-gate 		break;
18977c478bd9Sstevel@tonic-gate 
18987c478bd9Sstevel@tonic-gate 	case PIOCSFAULT:	/* set mask of traced faults */
18997c478bd9Sstevel@tonic-gate 		if (copyin(cmaddr, &un32.fltmask, sizeof (un32.fltmask)))
19007c478bd9Sstevel@tonic-gate 			error = EFAULT;
19017c478bd9Sstevel@tonic-gate 		break;
19027c478bd9Sstevel@tonic-gate 
19037c478bd9Sstevel@tonic-gate 	default:
19047c478bd9Sstevel@tonic-gate 		error = EINVAL;
19057c478bd9Sstevel@tonic-gate 		break;
19067c478bd9Sstevel@tonic-gate 	}
19077c478bd9Sstevel@tonic-gate 
19087c478bd9Sstevel@tonic-gate 	if (error)
19097c478bd9Sstevel@tonic-gate 		return (error);
19107c478bd9Sstevel@tonic-gate 
19117c478bd9Sstevel@tonic-gate startover:
19127c478bd9Sstevel@tonic-gate 	/*
19137c478bd9Sstevel@tonic-gate 	 * If we need kmem_alloc()d space then we allocate it now, before
19147c478bd9Sstevel@tonic-gate 	 * grabbing the process lock.  Using kmem_alloc(KM_SLEEP) while
19157c478bd9Sstevel@tonic-gate 	 * holding the process lock leads to deadlock with the clock thread.
19167c478bd9Sstevel@tonic-gate 	 * (The clock thread wakes up the pageout daemon to free up space.
19177c478bd9Sstevel@tonic-gate 	 * If the clock thread blocks behind us and we are sleeping waiting
19187c478bd9Sstevel@tonic-gate 	 * for space, then space may never become available.)
19197c478bd9Sstevel@tonic-gate 	 */
19207c478bd9Sstevel@tonic-gate 	if (thingsize) {
19217c478bd9Sstevel@tonic-gate 		ASSERT(thing == NULL);
19227c478bd9Sstevel@tonic-gate 		thing = kmem_alloc(thingsize, KM_SLEEP);
19237c478bd9Sstevel@tonic-gate 	}
19247c478bd9Sstevel@tonic-gate 
19257c478bd9Sstevel@tonic-gate 	switch (cmd) {
19267c478bd9Sstevel@tonic-gate 	case PIOCPSINFO:
19277c478bd9Sstevel@tonic-gate 	case PIOCGETPR:
19287c478bd9Sstevel@tonic-gate 	case PIOCUSAGE:
19297c478bd9Sstevel@tonic-gate 	case PIOCLUSAGE:
19307c478bd9Sstevel@tonic-gate 		zdisp = ZYES;
19317c478bd9Sstevel@tonic-gate 		break;
19327c478bd9Sstevel@tonic-gate 	case PIOCSXREG:		/* set extra registers */
19337c478bd9Sstevel@tonic-gate 		/*
19347c478bd9Sstevel@tonic-gate 		 * perform copyin before grabbing the process lock
19357c478bd9Sstevel@tonic-gate 		 */
19367c478bd9Sstevel@tonic-gate 		if (thing) {
19377c478bd9Sstevel@tonic-gate 			if (copyin(cmaddr, thing, thingsize)) {
19387c478bd9Sstevel@tonic-gate 				kmem_free(thing, thingsize);
19397c478bd9Sstevel@tonic-gate 				return (EFAULT);
19407c478bd9Sstevel@tonic-gate 			}
19417c478bd9Sstevel@tonic-gate 		}
19427c478bd9Sstevel@tonic-gate 		/* fall through... */
19437c478bd9Sstevel@tonic-gate 	default:
19447c478bd9Sstevel@tonic-gate 		zdisp = ZNO;
19457c478bd9Sstevel@tonic-gate 		break;
19467c478bd9Sstevel@tonic-gate 	}
19477c478bd9Sstevel@tonic-gate 
19487c478bd9Sstevel@tonic-gate 	if ((error = prlock(pnp, zdisp)) != 0) {
19497c478bd9Sstevel@tonic-gate 		if (thing != NULL)
19507c478bd9Sstevel@tonic-gate 			kmem_free(thing, thingsize);
19517c478bd9Sstevel@tonic-gate 		if (xpnp)
19527c478bd9Sstevel@tonic-gate 			prfreenode(xpnp);
19537c478bd9Sstevel@tonic-gate 		return (error);
19547c478bd9Sstevel@tonic-gate 	}
19557c478bd9Sstevel@tonic-gate 
19567c478bd9Sstevel@tonic-gate 	pcp = pnp->pr_common;
19577c478bd9Sstevel@tonic-gate 	p = pcp->prc_proc;
19587c478bd9Sstevel@tonic-gate 	ASSERT(p != NULL);
19597c478bd9Sstevel@tonic-gate 
19607c478bd9Sstevel@tonic-gate 	/*
19617c478bd9Sstevel@tonic-gate 	 * Choose a thread/lwp for the operation.
19627c478bd9Sstevel@tonic-gate 	 */
19637c478bd9Sstevel@tonic-gate 	if (zdisp == ZNO && cmd != PIOCSTOP && cmd != PIOCWSTOP) {
19647c478bd9Sstevel@tonic-gate 		if (pnp->pr_type == PR_LWPIDFILE && cmd != PIOCLSTATUS) {
19657c478bd9Sstevel@tonic-gate 			t = pcp->prc_thread;
19667c478bd9Sstevel@tonic-gate 			ASSERT(t != NULL);
19677c478bd9Sstevel@tonic-gate 		} else {
19687c478bd9Sstevel@tonic-gate 			t = prchoose(p);	/* returns locked thread */
19697c478bd9Sstevel@tonic-gate 			ASSERT(t != NULL);
19707c478bd9Sstevel@tonic-gate 			thread_unlock(t);
19717c478bd9Sstevel@tonic-gate 		}
19727c478bd9Sstevel@tonic-gate 		lwp = ttolwp(t);
19737c478bd9Sstevel@tonic-gate 	}
19747c478bd9Sstevel@tonic-gate 
19757c478bd9Sstevel@tonic-gate 	error = 0;
19767c478bd9Sstevel@tonic-gate 	switch (cmd) {
19777c478bd9Sstevel@tonic-gate 
19787c478bd9Sstevel@tonic-gate 	case PIOCGETPR:		/* read struct proc */
19797c478bd9Sstevel@tonic-gate 	{
19807c478bd9Sstevel@tonic-gate 		proc_t *prp = thing;
19817c478bd9Sstevel@tonic-gate 
19827c478bd9Sstevel@tonic-gate 		*prp = *p;
19837c478bd9Sstevel@tonic-gate 		prunlock(pnp);
19847c478bd9Sstevel@tonic-gate 		if (copyout(prp, cmaddr, sizeof (proc_t)))
19857c478bd9Sstevel@tonic-gate 			error = EFAULT;
19867c478bd9Sstevel@tonic-gate 		kmem_free(prp, sizeof (proc_t));
19877c478bd9Sstevel@tonic-gate 		thing = NULL;
19887c478bd9Sstevel@tonic-gate 		break;
19897c478bd9Sstevel@tonic-gate 	}
19907c478bd9Sstevel@tonic-gate 
19917c478bd9Sstevel@tonic-gate 	case PIOCGETU:		/* read u-area */
19927c478bd9Sstevel@tonic-gate 	{
19937c478bd9Sstevel@tonic-gate 		user_t *userp = thing;
19947c478bd9Sstevel@tonic-gate 
19957c478bd9Sstevel@tonic-gate 		up = PTOU(p);
19967c478bd9Sstevel@tonic-gate 		*userp = *up;
19977c478bd9Sstevel@tonic-gate 		prunlock(pnp);
19987c478bd9Sstevel@tonic-gate 		if (copyout(userp, cmaddr, sizeof (user_t)))
19997c478bd9Sstevel@tonic-gate 			error = EFAULT;
20007c478bd9Sstevel@tonic-gate 		kmem_free(userp, sizeof (user_t));
20017c478bd9Sstevel@tonic-gate 		thing = NULL;
20027c478bd9Sstevel@tonic-gate 		break;
20037c478bd9Sstevel@tonic-gate 	}
20047c478bd9Sstevel@tonic-gate 
20057c478bd9Sstevel@tonic-gate 	case PIOCOPENM:		/* open mapped object for reading */
20067c478bd9Sstevel@tonic-gate 		if (PROCESS_NOT_32BIT(p) && cmaddr != NULL) {
20077c478bd9Sstevel@tonic-gate 			prunlock(pnp);
20087c478bd9Sstevel@tonic-gate 			error = EOVERFLOW;
20097c478bd9Sstevel@tonic-gate 			break;
20107c478bd9Sstevel@tonic-gate 		}
20117c478bd9Sstevel@tonic-gate 		error = propenm(pnp, cmaddr,
20127c478bd9Sstevel@tonic-gate 		    (caddr_t)(uintptr_t)un32.va, rvalp, cr);
20137c478bd9Sstevel@tonic-gate 		/* propenm() called prunlock(pnp) */
20147c478bd9Sstevel@tonic-gate 		break;
20157c478bd9Sstevel@tonic-gate 
20167c478bd9Sstevel@tonic-gate 	case PIOCSTOP:		/* stop process or lwp from running */
20177c478bd9Sstevel@tonic-gate 	case PIOCWSTOP:		/* wait for process or lwp to stop */
20187c478bd9Sstevel@tonic-gate 		/*
20197c478bd9Sstevel@tonic-gate 		 * Can't apply to a system process.
20207c478bd9Sstevel@tonic-gate 		 */
20217c478bd9Sstevel@tonic-gate 		if ((p->p_flag & SSYS) || p->p_as == &kas) {
20227c478bd9Sstevel@tonic-gate 			prunlock(pnp);
20237c478bd9Sstevel@tonic-gate 			error = EBUSY;
20247c478bd9Sstevel@tonic-gate 			break;
20257c478bd9Sstevel@tonic-gate 		}
20267c478bd9Sstevel@tonic-gate 
20277c478bd9Sstevel@tonic-gate 		if (cmd == PIOCSTOP)
20287c478bd9Sstevel@tonic-gate 			pr_stop(pnp);
20297c478bd9Sstevel@tonic-gate 
20307c478bd9Sstevel@tonic-gate 		/*
20317c478bd9Sstevel@tonic-gate 		 * If an lwp is waiting for itself or its process, don't wait.
20327c478bd9Sstevel@tonic-gate 		 * The lwp will never see the fact that itself is stopped.
20337c478bd9Sstevel@tonic-gate 		 */
20347c478bd9Sstevel@tonic-gate 		if ((pnp->pr_type == PR_LWPIDFILE)?
20357c478bd9Sstevel@tonic-gate 		    (pcp->prc_thread == curthread) : (p == curproc)) {
20367c478bd9Sstevel@tonic-gate 			if (cmd == PIOCWSTOP)
20377c478bd9Sstevel@tonic-gate 				error = EBUSY;
20387c478bd9Sstevel@tonic-gate 			prunlock(pnp);
20397c478bd9Sstevel@tonic-gate 			break;
20407c478bd9Sstevel@tonic-gate 		}
20417c478bd9Sstevel@tonic-gate 
20427c478bd9Sstevel@tonic-gate 		if ((error = pr_wait_stop(pnp, (time_t)0)) != 0)
20437c478bd9Sstevel@tonic-gate 			break;	/* pr_wait_stop() unlocked the process */
20447c478bd9Sstevel@tonic-gate 
20457c478bd9Sstevel@tonic-gate 		if (cmaddr == NULL)
20467c478bd9Sstevel@tonic-gate 			prunlock(pnp);
20477c478bd9Sstevel@tonic-gate 		else if (PROCESS_NOT_32BIT(p)) {
20487c478bd9Sstevel@tonic-gate 			prunlock(pnp);
20497c478bd9Sstevel@tonic-gate 			error = EOVERFLOW;
20507c478bd9Sstevel@tonic-gate 		} else {
20517c478bd9Sstevel@tonic-gate 			/*
20527c478bd9Sstevel@tonic-gate 			 * Return process/lwp status information.
20537c478bd9Sstevel@tonic-gate 			 */
20547c478bd9Sstevel@tonic-gate 			t = pr_thread(pnp);	/* returns locked thread */
20557c478bd9Sstevel@tonic-gate 			thread_unlock(t);
2056*fa9e4066Sahrens 			oprgetstatus32(t, &un32.prstat, VTOZONE(vp));
20577c478bd9Sstevel@tonic-gate 			prunlock(pnp);
20587c478bd9Sstevel@tonic-gate 			if (copyout(&un32.prstat, cmaddr, sizeof (un32.prstat)))
20597c478bd9Sstevel@tonic-gate 				error = EFAULT;
20607c478bd9Sstevel@tonic-gate 		}
20617c478bd9Sstevel@tonic-gate 		break;
20627c478bd9Sstevel@tonic-gate 
20637c478bd9Sstevel@tonic-gate 	case PIOCRUN:		/* make lwp or process runnable */
20647c478bd9Sstevel@tonic-gate 	{
20657c478bd9Sstevel@tonic-gate 		long flags = un32.prrun.pr_flags;
20667c478bd9Sstevel@tonic-gate 
20677c478bd9Sstevel@tonic-gate 		/*
20687c478bd9Sstevel@tonic-gate 		 * Cannot set an lwp running is it is not stopped.
20697c478bd9Sstevel@tonic-gate 		 * Also, no lwp other than the /proc agent lwp can
20707c478bd9Sstevel@tonic-gate 		 * be set running so long as the /proc agent lwp exists.
20717c478bd9Sstevel@tonic-gate 		 */
20727c478bd9Sstevel@tonic-gate 		if ((!ISTOPPED(t) && !VSTOPPED(t) &&
20737c478bd9Sstevel@tonic-gate 		    !(t->t_proc_flag & TP_PRSTOP)) ||
20747c478bd9Sstevel@tonic-gate 		    (p->p_agenttp != NULL &&
20757c478bd9Sstevel@tonic-gate 		    (t != p->p_agenttp || pnp->pr_type != PR_LWPIDFILE))) {
20767c478bd9Sstevel@tonic-gate 			prunlock(pnp);
20777c478bd9Sstevel@tonic-gate 			error = EBUSY;
20787c478bd9Sstevel@tonic-gate 			break;
20797c478bd9Sstevel@tonic-gate 		}
20807c478bd9Sstevel@tonic-gate 
20817c478bd9Sstevel@tonic-gate 		if ((flags & PRSVADDR) && PROCESS_NOT_32BIT(p)) {
20827c478bd9Sstevel@tonic-gate 			prunlock(pnp);
20837c478bd9Sstevel@tonic-gate 			error = EOVERFLOW;
20847c478bd9Sstevel@tonic-gate 			break;
20857c478bd9Sstevel@tonic-gate 		}
20867c478bd9Sstevel@tonic-gate 
20877c478bd9Sstevel@tonic-gate 		if (flags & (PRSHOLD|PRSTRACE|PRSFAULT|PRSVADDR)) {
20887c478bd9Sstevel@tonic-gate 			un.prrun.pr_flags = (int)flags;
20897c478bd9Sstevel@tonic-gate 			un.prrun.pr_trace = un32.prrun.pr_trace;
20907c478bd9Sstevel@tonic-gate 			un.prrun.pr_sighold = un32.prrun.pr_sighold;
20917c478bd9Sstevel@tonic-gate 			un.prrun.pr_fault = un32.prrun.pr_fault;
20927c478bd9Sstevel@tonic-gate 			un.prrun.pr_vaddr =
20937c478bd9Sstevel@tonic-gate 			    (caddr_t)(uintptr_t)un32.prrun.pr_vaddr;
20947c478bd9Sstevel@tonic-gate 			prsetrun(t, &un.prrun);
20957c478bd9Sstevel@tonic-gate 		}
20967c478bd9Sstevel@tonic-gate 
20977c478bd9Sstevel@tonic-gate 		error = pr_setrun(pnp, prmaprunflags(flags));
20987c478bd9Sstevel@tonic-gate 
20997c478bd9Sstevel@tonic-gate 		prunlock(pnp);
21007c478bd9Sstevel@tonic-gate 		break;
21017c478bd9Sstevel@tonic-gate 	}
21027c478bd9Sstevel@tonic-gate 
21037c478bd9Sstevel@tonic-gate 	case PIOCLWPIDS:	/* get array of lwp identifiers */
21047c478bd9Sstevel@tonic-gate 	{
21057c478bd9Sstevel@tonic-gate 		int nlwp;
21067c478bd9Sstevel@tonic-gate 		int Nlwp;
21077c478bd9Sstevel@tonic-gate 		id_t *idp;
21087c478bd9Sstevel@tonic-gate 		id_t *Bidp;
21097c478bd9Sstevel@tonic-gate 
21107c478bd9Sstevel@tonic-gate 		Nlwp = nlwp = p->p_lwpcnt;
21117c478bd9Sstevel@tonic-gate 
21127c478bd9Sstevel@tonic-gate 		if (thing && thingsize != (Nlwp+1) * sizeof (id_t)) {
21137c478bd9Sstevel@tonic-gate 			kmem_free(thing, thingsize);
21147c478bd9Sstevel@tonic-gate 			thing = NULL;
21157c478bd9Sstevel@tonic-gate 		}
21167c478bd9Sstevel@tonic-gate 		if (thing == NULL) {
21177c478bd9Sstevel@tonic-gate 			thingsize = (Nlwp+1) * sizeof (id_t);
21187c478bd9Sstevel@tonic-gate 			thing = kmem_alloc(thingsize, KM_NOSLEEP);
21197c478bd9Sstevel@tonic-gate 		}
21207c478bd9Sstevel@tonic-gate 		if (thing == NULL) {
21217c478bd9Sstevel@tonic-gate 			prunlock(pnp);
21227c478bd9Sstevel@tonic-gate 			goto startover;
21237c478bd9Sstevel@tonic-gate 		}
21247c478bd9Sstevel@tonic-gate 
21257c478bd9Sstevel@tonic-gate 		idp = thing;
21267c478bd9Sstevel@tonic-gate 		thing = NULL;
21277c478bd9Sstevel@tonic-gate 		Bidp = idp;
21287c478bd9Sstevel@tonic-gate 		if ((t = p->p_tlist) != NULL) {
21297c478bd9Sstevel@tonic-gate 			do {
21307c478bd9Sstevel@tonic-gate 				ASSERT(!(t->t_proc_flag & TP_LWPEXIT));
21317c478bd9Sstevel@tonic-gate 				ASSERT(nlwp > 0);
21327c478bd9Sstevel@tonic-gate 				--nlwp;
21337c478bd9Sstevel@tonic-gate 				*idp++ = t->t_tid;
21347c478bd9Sstevel@tonic-gate 			} while ((t = t->t_forw) != p->p_tlist);
21357c478bd9Sstevel@tonic-gate 		}
21367c478bd9Sstevel@tonic-gate 		*idp = 0;
21377c478bd9Sstevel@tonic-gate 		ASSERT(nlwp == 0);
21387c478bd9Sstevel@tonic-gate 		prunlock(pnp);
21397c478bd9Sstevel@tonic-gate 		if (copyout(Bidp, cmaddr, (Nlwp+1) * sizeof (id_t)))
21407c478bd9Sstevel@tonic-gate 			error = EFAULT;
21417c478bd9Sstevel@tonic-gate 		kmem_free(Bidp, (Nlwp+1) * sizeof (id_t));
21427c478bd9Sstevel@tonic-gate 		break;
21437c478bd9Sstevel@tonic-gate 	}
21447c478bd9Sstevel@tonic-gate 
21457c478bd9Sstevel@tonic-gate 	case PIOCOPENLWP:	/* return /proc lwp file descriptor */
21467c478bd9Sstevel@tonic-gate 	{
21477c478bd9Sstevel@tonic-gate 		vnode_t *xvp;
21487c478bd9Sstevel@tonic-gate 		int n;
21497c478bd9Sstevel@tonic-gate 
21507c478bd9Sstevel@tonic-gate 		prunlock(pnp);
21517c478bd9Sstevel@tonic-gate 		if ((xvp = prlwpnode(pnp, un32.lwpid)) == NULL)
21527c478bd9Sstevel@tonic-gate 			error = ENOENT;
21537c478bd9Sstevel@tonic-gate 		else if (error = fassign(&xvp, flag & (FREAD|FWRITE), &n)) {
21547c478bd9Sstevel@tonic-gate 			VN_RELE(xvp);
21557c478bd9Sstevel@tonic-gate 		} else
21567c478bd9Sstevel@tonic-gate 			*rvalp = n;
21577c478bd9Sstevel@tonic-gate 		break;
21587c478bd9Sstevel@tonic-gate 	}
21597c478bd9Sstevel@tonic-gate 
21607c478bd9Sstevel@tonic-gate 	case PIOCOPENPD:	/* return /proc page data file descriptor */
21617c478bd9Sstevel@tonic-gate 	{
21627c478bd9Sstevel@tonic-gate 		vnode_t *xvp = PTOV(xpnp);
21637c478bd9Sstevel@tonic-gate 		vnode_t *dp = pnp->pr_parent;
21647c478bd9Sstevel@tonic-gate 		int n;
21657c478bd9Sstevel@tonic-gate 
21667c478bd9Sstevel@tonic-gate 		if (PROCESS_NOT_32BIT(p)) {
21677c478bd9Sstevel@tonic-gate 			prunlock(pnp);
21687c478bd9Sstevel@tonic-gate 			prfreenode(xpnp);
21697c478bd9Sstevel@tonic-gate 			xpnp = NULL;
21707c478bd9Sstevel@tonic-gate 			error = EOVERFLOW;
21717c478bd9Sstevel@tonic-gate 			break;
21727c478bd9Sstevel@tonic-gate 		}
21737c478bd9Sstevel@tonic-gate 
21747c478bd9Sstevel@tonic-gate 		if (pnp->pr_type == PR_LWPIDFILE) {
21757c478bd9Sstevel@tonic-gate 			dp = VTOP(dp)->pr_parent;
21767c478bd9Sstevel@tonic-gate 			dp = VTOP(dp)->pr_parent;
21777c478bd9Sstevel@tonic-gate 		}
21787c478bd9Sstevel@tonic-gate 		ASSERT(VTOP(dp)->pr_type == PR_PIDDIR);
21797c478bd9Sstevel@tonic-gate 
21807c478bd9Sstevel@tonic-gate 		VN_HOLD(dp);
21817c478bd9Sstevel@tonic-gate 		pcp = pnp->pr_pcommon;
21827c478bd9Sstevel@tonic-gate 		xpnp->pr_ino = ptoi(pcp->prc_pid);
21837c478bd9Sstevel@tonic-gate 		xpnp->pr_common = pcp;
21847c478bd9Sstevel@tonic-gate 		xpnp->pr_pcommon = pcp;
21857c478bd9Sstevel@tonic-gate 		xpnp->pr_parent = dp;
21867c478bd9Sstevel@tonic-gate 
21877c478bd9Sstevel@tonic-gate 		xpnp->pr_next = p->p_plist;
21887c478bd9Sstevel@tonic-gate 		p->p_plist = xvp;
21897c478bd9Sstevel@tonic-gate 
21907c478bd9Sstevel@tonic-gate 		prunlock(pnp);
21917c478bd9Sstevel@tonic-gate 		if (error = fassign(&xvp, FREAD, &n)) {
21927c478bd9Sstevel@tonic-gate 			VN_RELE(xvp);
21937c478bd9Sstevel@tonic-gate 		} else
21947c478bd9Sstevel@tonic-gate 			*rvalp = n;
21957c478bd9Sstevel@tonic-gate 
21967c478bd9Sstevel@tonic-gate 		xpnp = NULL;
21977c478bd9Sstevel@tonic-gate 		break;
21987c478bd9Sstevel@tonic-gate 	}
21997c478bd9Sstevel@tonic-gate 
22007c478bd9Sstevel@tonic-gate 	case PIOCGTRACE:	/* get signal trace mask */
22017c478bd9Sstevel@tonic-gate 		prassignset(&un32.smask, &p->p_sigmask);
22027c478bd9Sstevel@tonic-gate 		prunlock(pnp);
22037c478bd9Sstevel@tonic-gate 		if (copyout(&un32.smask, cmaddr, sizeof (un32.smask)))
22047c478bd9Sstevel@tonic-gate 			error = EFAULT;
22057c478bd9Sstevel@tonic-gate 		break;
22067c478bd9Sstevel@tonic-gate 
22077c478bd9Sstevel@tonic-gate 	case PIOCSTRACE:	/* set signal trace mask */
22087c478bd9Sstevel@tonic-gate 		prdelset(&un32.smask, SIGKILL);
22097c478bd9Sstevel@tonic-gate 		prassignset(&p->p_sigmask, &un32.smask);
22107c478bd9Sstevel@tonic-gate 		if (!sigisempty(&p->p_sigmask))
22117c478bd9Sstevel@tonic-gate 			p->p_proc_flag |= P_PR_TRACE;
22127c478bd9Sstevel@tonic-gate 		else if (prisempty(&p->p_fltmask)) {
22137c478bd9Sstevel@tonic-gate 			up = PTOU(p);
22147c478bd9Sstevel@tonic-gate 			if (up->u_systrap == 0)
22157c478bd9Sstevel@tonic-gate 				p->p_proc_flag &= ~P_PR_TRACE;
22167c478bd9Sstevel@tonic-gate 		}
22177c478bd9Sstevel@tonic-gate 		prunlock(pnp);
22187c478bd9Sstevel@tonic-gate 		break;
22197c478bd9Sstevel@tonic-gate 
22207c478bd9Sstevel@tonic-gate 	case PIOCSSIG:		/* set current signal */
22217c478bd9Sstevel@tonic-gate 		if (un32.info.si_signo != 0 && PROCESS_NOT_32BIT(p)) {
22227c478bd9Sstevel@tonic-gate 			prunlock(pnp);
22237c478bd9Sstevel@tonic-gate 			error = EOVERFLOW;
22247c478bd9Sstevel@tonic-gate 		} else {
22257c478bd9Sstevel@tonic-gate 			bzero(&un.info, sizeof (un.info));
22267c478bd9Sstevel@tonic-gate 			siginfo_32tok(&un32.info, (k_siginfo_t *)&un.info);
22277c478bd9Sstevel@tonic-gate 			error = pr_setsig(pnp, &un.info);
22287c478bd9Sstevel@tonic-gate 			prunlock(pnp);
22297c478bd9Sstevel@tonic-gate 			if (un32.info.si_signo == SIGKILL && error == 0)
22307c478bd9Sstevel@tonic-gate 				pr_wait_die(pnp);
22317c478bd9Sstevel@tonic-gate 		}
22327c478bd9Sstevel@tonic-gate 		break;
22337c478bd9Sstevel@tonic-gate 
22347c478bd9Sstevel@tonic-gate 	case PIOCKILL:		/* send signal */
22357c478bd9Sstevel@tonic-gate 		error = pr_kill(pnp, un32.signo, cr);
22367c478bd9Sstevel@tonic-gate 		prunlock(pnp);
22377c478bd9Sstevel@tonic-gate 		if (un32.signo == SIGKILL && error == 0)
22387c478bd9Sstevel@tonic-gate 			pr_wait_die(pnp);
22397c478bd9Sstevel@tonic-gate 		break;
22407c478bd9Sstevel@tonic-gate 
22417c478bd9Sstevel@tonic-gate 	case PIOCUNKILL:	/* delete a signal */
22427c478bd9Sstevel@tonic-gate 		error = pr_unkill(pnp, un32.signo);
22437c478bd9Sstevel@tonic-gate 		prunlock(pnp);
22447c478bd9Sstevel@tonic-gate 		break;
22457c478bd9Sstevel@tonic-gate 
22467c478bd9Sstevel@tonic-gate 	case PIOCNICE:		/* set nice priority */
22477c478bd9Sstevel@tonic-gate 		error = pr_nice(p, un32.nice, cr);
22487c478bd9Sstevel@tonic-gate 		prunlock(pnp);
22497c478bd9Sstevel@tonic-gate 		break;
22507c478bd9Sstevel@tonic-gate 
22517c478bd9Sstevel@tonic-gate 	case PIOCGENTRY:	/* get syscall entry bit mask */
22527c478bd9Sstevel@tonic-gate 	case PIOCGEXIT:		/* get syscall exit bit mask */
22537c478bd9Sstevel@tonic-gate 		up = PTOU(p);
22547c478bd9Sstevel@tonic-gate 		if (cmd == PIOCGENTRY) {
22557c478bd9Sstevel@tonic-gate 			prassignset(&un32.prmask, &up->u_entrymask);
22567c478bd9Sstevel@tonic-gate 		} else {
22577c478bd9Sstevel@tonic-gate 			prassignset(&un32.prmask, &up->u_exitmask);
22587c478bd9Sstevel@tonic-gate 		}
22597c478bd9Sstevel@tonic-gate 		prunlock(pnp);
22607c478bd9Sstevel@tonic-gate 		if (copyout(&un32.prmask, cmaddr, sizeof (un32.prmask)))
22617c478bd9Sstevel@tonic-gate 			error = EFAULT;
22627c478bd9Sstevel@tonic-gate 		break;
22637c478bd9Sstevel@tonic-gate 
22647c478bd9Sstevel@tonic-gate 	case PIOCSENTRY:	/* set syscall entry bit mask */
22657c478bd9Sstevel@tonic-gate 	case PIOCSEXIT:		/* set syscall exit bit mask */
22667c478bd9Sstevel@tonic-gate 		pr_setentryexit(p, &un32.prmask, cmd == PIOCSENTRY);
22677c478bd9Sstevel@tonic-gate 		prunlock(pnp);
22687c478bd9Sstevel@tonic-gate 		break;
22697c478bd9Sstevel@tonic-gate 
22707c478bd9Sstevel@tonic-gate 	case PIOCSRLC:		/* obsolete: set running on last /proc close */
22717c478bd9Sstevel@tonic-gate 		error = pr_set(p, prmapsetflags(PR_RLC));
22727c478bd9Sstevel@tonic-gate 		prunlock(pnp);
22737c478bd9Sstevel@tonic-gate 		break;
22747c478bd9Sstevel@tonic-gate 
22757c478bd9Sstevel@tonic-gate 	case PIOCRRLC:		/* obsolete: reset run-on-last-close flag */
22767c478bd9Sstevel@tonic-gate 		error = pr_unset(p, prmapsetflags(PR_RLC));
22777c478bd9Sstevel@tonic-gate 		prunlock(pnp);
22787c478bd9Sstevel@tonic-gate 		break;
22797c478bd9Sstevel@tonic-gate 
22807c478bd9Sstevel@tonic-gate 	case PIOCSFORK:		/* obsolete: set inherit-on-fork flag */
22817c478bd9Sstevel@tonic-gate 		error = pr_set(p, prmapsetflags(PR_FORK));
22827c478bd9Sstevel@tonic-gate 		prunlock(pnp);
22837c478bd9Sstevel@tonic-gate 		break;
22847c478bd9Sstevel@tonic-gate 
22857c478bd9Sstevel@tonic-gate 	case PIOCRFORK:		/* obsolete: reset inherit-on-fork flag */
22867c478bd9Sstevel@tonic-gate 		error = pr_unset(p, prmapsetflags(PR_FORK));
22877c478bd9Sstevel@tonic-gate 		prunlock(pnp);
22887c478bd9Sstevel@tonic-gate 		break;
22897c478bd9Sstevel@tonic-gate 
22907c478bd9Sstevel@tonic-gate 	case PIOCSET:		/* set process flags */
22917c478bd9Sstevel@tonic-gate 		error = pr_set(p, prmapsetflags((long)un32.flags));
22927c478bd9Sstevel@tonic-gate 		prunlock(pnp);
22937c478bd9Sstevel@tonic-gate 		break;
22947c478bd9Sstevel@tonic-gate 
22957c478bd9Sstevel@tonic-gate 	case PIOCRESET:		/* reset process flags */
22967c478bd9Sstevel@tonic-gate 		error = pr_unset(p, prmapsetflags((long)un32.flags));
22977c478bd9Sstevel@tonic-gate 		prunlock(pnp);
22987c478bd9Sstevel@tonic-gate 		break;
22997c478bd9Sstevel@tonic-gate 
23007c478bd9Sstevel@tonic-gate 	case PIOCGREG:		/* get general registers */
23017c478bd9Sstevel@tonic-gate 		if (PROCESS_NOT_32BIT(p))
23027c478bd9Sstevel@tonic-gate 			error = EOVERFLOW;
23037c478bd9Sstevel@tonic-gate 		else if (t->t_state != TS_STOPPED && !VSTOPPED(t))
23047c478bd9Sstevel@tonic-gate 			bzero(un32.regs, sizeof (un32.regs));
23057c478bd9Sstevel@tonic-gate 		else {
23067c478bd9Sstevel@tonic-gate 			/* drop p_lock while touching the lwp's stack */
23077c478bd9Sstevel@tonic-gate 			mutex_exit(&p->p_lock);
23087c478bd9Sstevel@tonic-gate 			prgetprregs32(lwp, un32.regs);
23097c478bd9Sstevel@tonic-gate 			mutex_enter(&p->p_lock);
23107c478bd9Sstevel@tonic-gate 		}
23117c478bd9Sstevel@tonic-gate 		prunlock(pnp);
23127c478bd9Sstevel@tonic-gate 		if (error == 0 &&
23137c478bd9Sstevel@tonic-gate 		    copyout(un32.regs, cmaddr, sizeof (un32.regs)))
23147c478bd9Sstevel@tonic-gate 			error = EFAULT;
23157c478bd9Sstevel@tonic-gate 		break;
23167c478bd9Sstevel@tonic-gate 
23177c478bd9Sstevel@tonic-gate 	case PIOCSREG:		/* set general registers */
23187c478bd9Sstevel@tonic-gate 		if (PROCESS_NOT_32BIT(p))
23197c478bd9Sstevel@tonic-gate 			error = EOVERFLOW;
23207c478bd9Sstevel@tonic-gate 		else if (!ISTOPPED(t) && !VSTOPPED(t) && !DSTOPPED(t))
23217c478bd9Sstevel@tonic-gate 			error = EBUSY;
23227c478bd9Sstevel@tonic-gate 		else {
23237c478bd9Sstevel@tonic-gate 			/* drop p_lock while touching the lwp's stack */
23247c478bd9Sstevel@tonic-gate 			mutex_exit(&p->p_lock);
23257c478bd9Sstevel@tonic-gate 			prgregset_32ton(lwp, un32.regs, un.regs);
23267c478bd9Sstevel@tonic-gate 			prsetprregs(lwp, un.regs, 0);
23277c478bd9Sstevel@tonic-gate 			mutex_enter(&p->p_lock);
23287c478bd9Sstevel@tonic-gate 		}
23297c478bd9Sstevel@tonic-gate 		prunlock(pnp);
23307c478bd9Sstevel@tonic-gate 		break;
23317c478bd9Sstevel@tonic-gate 
23327c478bd9Sstevel@tonic-gate 	case PIOCGFPREG:	/* get floating-point registers */
23337c478bd9Sstevel@tonic-gate 		if (!prhasfp())
23347c478bd9Sstevel@tonic-gate 			error = EINVAL;	/* No FP support */
23357c478bd9Sstevel@tonic-gate 		else if (PROCESS_NOT_32BIT(p))
23367c478bd9Sstevel@tonic-gate 			error = EOVERFLOW;
23377c478bd9Sstevel@tonic-gate 		else if (t->t_state != TS_STOPPED && !VSTOPPED(t))
23387c478bd9Sstevel@tonic-gate 			bzero(&un32.fpregs, sizeof (un32.fpregs));
23397c478bd9Sstevel@tonic-gate 		else {
23407c478bd9Sstevel@tonic-gate 			/* drop p_lock while touching the lwp's stack */
23417c478bd9Sstevel@tonic-gate 			mutex_exit(&p->p_lock);
23427c478bd9Sstevel@tonic-gate 			prgetprfpregs32(lwp, &un32.fpregs);
23437c478bd9Sstevel@tonic-gate 			mutex_enter(&p->p_lock);
23447c478bd9Sstevel@tonic-gate 		}
23457c478bd9Sstevel@tonic-gate 		prunlock(pnp);
23467c478bd9Sstevel@tonic-gate 		if (error == 0 &&
23477c478bd9Sstevel@tonic-gate 		    copyout(&un32.fpregs, cmaddr, sizeof (un32.fpregs)))
23487c478bd9Sstevel@tonic-gate 			error = EFAULT;
23497c478bd9Sstevel@tonic-gate 		break;
23507c478bd9Sstevel@tonic-gate 
23517c478bd9Sstevel@tonic-gate 	case PIOCSFPREG:	/* set floating-point registers */
23527c478bd9Sstevel@tonic-gate 		if (!prhasfp())
23537c478bd9Sstevel@tonic-gate 			error = EINVAL;	/* No FP support */
23547c478bd9Sstevel@tonic-gate 		else if (PROCESS_NOT_32BIT(p))
23557c478bd9Sstevel@tonic-gate 			error = EOVERFLOW;
23567c478bd9Sstevel@tonic-gate 		else if (!ISTOPPED(t) && !VSTOPPED(t) && !DSTOPPED(t))
23577c478bd9Sstevel@tonic-gate 			error = EBUSY;
23587c478bd9Sstevel@tonic-gate 		else {
23597c478bd9Sstevel@tonic-gate 			/* drop p_lock while touching the lwp's stack */
23607c478bd9Sstevel@tonic-gate 			mutex_exit(&p->p_lock);
23617c478bd9Sstevel@tonic-gate 			prsetprfpregs32(lwp, &un32.fpregs);
23627c478bd9Sstevel@tonic-gate 			mutex_enter(&p->p_lock);
23637c478bd9Sstevel@tonic-gate 		}
23647c478bd9Sstevel@tonic-gate 		prunlock(pnp);
23657c478bd9Sstevel@tonic-gate 		break;
23667c478bd9Sstevel@tonic-gate 
23677c478bd9Sstevel@tonic-gate 	case PIOCGXREGSIZE:	/* get the size of the extra registers */
23687c478bd9Sstevel@tonic-gate 	{
23697c478bd9Sstevel@tonic-gate 		int xregsize;
23707c478bd9Sstevel@tonic-gate 
23717c478bd9Sstevel@tonic-gate 		if (prhasx(p)) {
23727c478bd9Sstevel@tonic-gate 			xregsize = prgetprxregsize(p);
23737c478bd9Sstevel@tonic-gate 			prunlock(pnp);
23747c478bd9Sstevel@tonic-gate 			if (copyout(&xregsize, cmaddr, sizeof (xregsize)))
23757c478bd9Sstevel@tonic-gate 				error = EFAULT;
23767c478bd9Sstevel@tonic-gate 		} else {
23777c478bd9Sstevel@tonic-gate 			prunlock(pnp);
23787c478bd9Sstevel@tonic-gate 			error = EINVAL;	/* No extra register support */
23797c478bd9Sstevel@tonic-gate 		}
23807c478bd9Sstevel@tonic-gate 		break;
23817c478bd9Sstevel@tonic-gate 	}
23827c478bd9Sstevel@tonic-gate 
23837c478bd9Sstevel@tonic-gate 	case PIOCGXREG:		/* get extra registers */
23847c478bd9Sstevel@tonic-gate 		if (PROCESS_NOT_32BIT(p))
23857c478bd9Sstevel@tonic-gate 			error = EOVERFLOW;
23867c478bd9Sstevel@tonic-gate 		else if (!prhasx(p))
23877c478bd9Sstevel@tonic-gate 			error = EINVAL;	/* No extra register support */
23887c478bd9Sstevel@tonic-gate 		else {
23897c478bd9Sstevel@tonic-gate 			bzero(thing, thingsize);
23907c478bd9Sstevel@tonic-gate 			if (t->t_state == TS_STOPPED || VSTOPPED(t)) {
23917c478bd9Sstevel@tonic-gate 				/* drop p_lock to touch the stack */
23927c478bd9Sstevel@tonic-gate 				mutex_exit(&p->p_lock);
23937c478bd9Sstevel@tonic-gate 				prgetprxregs(lwp, thing);
23947c478bd9Sstevel@tonic-gate 				mutex_enter(&p->p_lock);
23957c478bd9Sstevel@tonic-gate 			}
23967c478bd9Sstevel@tonic-gate 		}
23977c478bd9Sstevel@tonic-gate 		prunlock(pnp);
23987c478bd9Sstevel@tonic-gate 		if (error == 0 &&
23997c478bd9Sstevel@tonic-gate 		    copyout(thing, cmaddr, thingsize))
24007c478bd9Sstevel@tonic-gate 			error = EFAULT;
24017c478bd9Sstevel@tonic-gate 		if (thing) {
24027c478bd9Sstevel@tonic-gate 			kmem_free(thing, thingsize);
24037c478bd9Sstevel@tonic-gate 			thing = NULL;
24047c478bd9Sstevel@tonic-gate 		}
24057c478bd9Sstevel@tonic-gate 		break;
24067c478bd9Sstevel@tonic-gate 
24077c478bd9Sstevel@tonic-gate 	case PIOCSXREG:		/* set extra registers */
24087c478bd9Sstevel@tonic-gate 		if (PROCESS_NOT_32BIT(p))
24097c478bd9Sstevel@tonic-gate 			error = EOVERFLOW;
24107c478bd9Sstevel@tonic-gate 		else if (!ISTOPPED(t) && !VSTOPPED(t) && !DSTOPPED(t))
24117c478bd9Sstevel@tonic-gate 			error = EBUSY;
24127c478bd9Sstevel@tonic-gate 		else if (!prhasx(p))
24137c478bd9Sstevel@tonic-gate 			error = EINVAL;	/* No extra register support */
24147c478bd9Sstevel@tonic-gate 		else if (thing) {
24157c478bd9Sstevel@tonic-gate 			/* drop p_lock while touching the lwp's stack */
24167c478bd9Sstevel@tonic-gate 			mutex_exit(&p->p_lock);
24177c478bd9Sstevel@tonic-gate 			prsetprxregs(lwp, thing);
24187c478bd9Sstevel@tonic-gate 			mutex_enter(&p->p_lock);
24197c478bd9Sstevel@tonic-gate 		}
24207c478bd9Sstevel@tonic-gate 		prunlock(pnp);
24217c478bd9Sstevel@tonic-gate 		if (thing) {
24227c478bd9Sstevel@tonic-gate 			kmem_free(thing, thingsize);
24237c478bd9Sstevel@tonic-gate 			thing = NULL;
24247c478bd9Sstevel@tonic-gate 		}
24257c478bd9Sstevel@tonic-gate 		break;
24267c478bd9Sstevel@tonic-gate 
24277c478bd9Sstevel@tonic-gate 	case PIOCSTATUS:	/* get process/lwp status */
24287c478bd9Sstevel@tonic-gate 		if (PROCESS_NOT_32BIT(p)) {
24297c478bd9Sstevel@tonic-gate 			prunlock(pnp);
24307c478bd9Sstevel@tonic-gate 			error = EOVERFLOW;
24317c478bd9Sstevel@tonic-gate 			break;
24327c478bd9Sstevel@tonic-gate 		}
2433*fa9e4066Sahrens 		oprgetstatus32(t, &un32.prstat, VTOZONE(vp));
24347c478bd9Sstevel@tonic-gate 		prunlock(pnp);
24357c478bd9Sstevel@tonic-gate 		if (copyout(&un32.prstat, cmaddr, sizeof (un32.prstat)))
24367c478bd9Sstevel@tonic-gate 			error = EFAULT;
24377c478bd9Sstevel@tonic-gate 		break;
24387c478bd9Sstevel@tonic-gate 
24397c478bd9Sstevel@tonic-gate 	case PIOCLSTATUS:	/* get status for process & all lwps */
24407c478bd9Sstevel@tonic-gate 	{
24417c478bd9Sstevel@tonic-gate 		int Nlwp;
24427c478bd9Sstevel@tonic-gate 		int nlwp;
24437c478bd9Sstevel@tonic-gate 		prstatus32_t *Bprsp;
24447c478bd9Sstevel@tonic-gate 		prstatus32_t *prsp;
24457c478bd9Sstevel@tonic-gate 
24467c478bd9Sstevel@tonic-gate 		if (PROCESS_NOT_32BIT(p)) {
24477c478bd9Sstevel@tonic-gate 			prunlock(pnp);
24487c478bd9Sstevel@tonic-gate 			if (thing) {
24497c478bd9Sstevel@tonic-gate 				kmem_free(thing, thingsize);
24507c478bd9Sstevel@tonic-gate 				thing = NULL;
24517c478bd9Sstevel@tonic-gate 			}
24527c478bd9Sstevel@tonic-gate 			error = EOVERFLOW;
24537c478bd9Sstevel@tonic-gate 			break;
24547c478bd9Sstevel@tonic-gate 		}
24557c478bd9Sstevel@tonic-gate 
24567c478bd9Sstevel@tonic-gate 		nlwp = Nlwp = p->p_lwpcnt;
24577c478bd9Sstevel@tonic-gate 
24587c478bd9Sstevel@tonic-gate 		if (thing && thingsize != (Nlwp+1) * sizeof (prstatus32_t)) {
24597c478bd9Sstevel@tonic-gate 			kmem_free(thing, thingsize);
24607c478bd9Sstevel@tonic-gate 			thing = NULL;
24617c478bd9Sstevel@tonic-gate 		}
24627c478bd9Sstevel@tonic-gate 		if (thing == NULL) {
24637c478bd9Sstevel@tonic-gate 			thingsize = (Nlwp+1) * sizeof (prstatus32_t);
24647c478bd9Sstevel@tonic-gate 			thing = kmem_alloc(thingsize, KM_NOSLEEP);
24657c478bd9Sstevel@tonic-gate 		}
24667c478bd9Sstevel@tonic-gate 		if (thing == NULL) {
24677c478bd9Sstevel@tonic-gate 			prunlock(pnp);
24687c478bd9Sstevel@tonic-gate 			goto startover;
24697c478bd9Sstevel@tonic-gate 		}
24707c478bd9Sstevel@tonic-gate 
24717c478bd9Sstevel@tonic-gate 		Bprsp = (prstatus32_t *)thing;
24727c478bd9Sstevel@tonic-gate 		thing = NULL;
24737c478bd9Sstevel@tonic-gate 		prsp = Bprsp;
2474*fa9e4066Sahrens 		oprgetstatus32(t, prsp, VTOZONE(vp));
24757c478bd9Sstevel@tonic-gate 		t = p->p_tlist;
24767c478bd9Sstevel@tonic-gate 		do {
24777c478bd9Sstevel@tonic-gate 			ASSERT(!(t->t_proc_flag & TP_LWPEXIT));
24787c478bd9Sstevel@tonic-gate 			ASSERT(nlwp > 0);
24797c478bd9Sstevel@tonic-gate 			--nlwp;
2480*fa9e4066Sahrens 			oprgetstatus32(t, ++prsp, VTOZONE(vp));
24817c478bd9Sstevel@tonic-gate 		} while ((t = t->t_forw) != p->p_tlist);
24827c478bd9Sstevel@tonic-gate 		ASSERT(nlwp == 0);
24837c478bd9Sstevel@tonic-gate 		prunlock(pnp);
24847c478bd9Sstevel@tonic-gate 		if (copyout(Bprsp, cmaddr, (Nlwp+1) * sizeof (prstatus32_t)))
24857c478bd9Sstevel@tonic-gate 			error = EFAULT;
24867c478bd9Sstevel@tonic-gate 
24877c478bd9Sstevel@tonic-gate 		kmem_free(Bprsp, (Nlwp + 1) * sizeof (prstatus32_t));
24887c478bd9Sstevel@tonic-gate 		break;
24897c478bd9Sstevel@tonic-gate 	}
24907c478bd9Sstevel@tonic-gate 
24917c478bd9Sstevel@tonic-gate 	case PIOCPSINFO:	/* get ps(1) information */
24927c478bd9Sstevel@tonic-gate 	{
24937c478bd9Sstevel@tonic-gate 		prpsinfo32_t *psp = &un32.prps;
24947c478bd9Sstevel@tonic-gate 
24957c478bd9Sstevel@tonic-gate 		oprgetpsinfo32(p, psp,
24967c478bd9Sstevel@tonic-gate 		    (pnp->pr_type == PR_LWPIDFILE)? pcp->prc_thread : NULL);
24977c478bd9Sstevel@tonic-gate 
24987c478bd9Sstevel@tonic-gate 		prunlock(pnp);
24997c478bd9Sstevel@tonic-gate 		if (copyout(&un32.prps, cmaddr, sizeof (un32.prps)))
25007c478bd9Sstevel@tonic-gate 			error = EFAULT;
25017c478bd9Sstevel@tonic-gate 		break;
25027c478bd9Sstevel@tonic-gate 	}
25037c478bd9Sstevel@tonic-gate 
25047c478bd9Sstevel@tonic-gate 	case PIOCMAXSIG:	/* get maximum signal number */
25057c478bd9Sstevel@tonic-gate 	{
25067c478bd9Sstevel@tonic-gate 		int n = NSIG-1;
25077c478bd9Sstevel@tonic-gate 
25087c478bd9Sstevel@tonic-gate 		prunlock(pnp);
25097c478bd9Sstevel@tonic-gate 		if (copyout(&n, cmaddr, sizeof (int)))
25107c478bd9Sstevel@tonic-gate 			error = EFAULT;
25117c478bd9Sstevel@tonic-gate 		break;
25127c478bd9Sstevel@tonic-gate 	}
25137c478bd9Sstevel@tonic-gate 
25147c478bd9Sstevel@tonic-gate 	case PIOCACTION:	/* get signal action structures */
25157c478bd9Sstevel@tonic-gate 	{
25167c478bd9Sstevel@tonic-gate 		uint_t sig;
25177c478bd9Sstevel@tonic-gate 		struct sigaction32 *sap = thing;
25187c478bd9Sstevel@tonic-gate 
25197c478bd9Sstevel@tonic-gate 		if (PROCESS_NOT_32BIT(p))
25207c478bd9Sstevel@tonic-gate 			error = EOVERFLOW;
25217c478bd9Sstevel@tonic-gate 		else {
25227c478bd9Sstevel@tonic-gate 			up = PTOU(p);
25237c478bd9Sstevel@tonic-gate 			for (sig = 1; sig < NSIG; sig++)
25247c478bd9Sstevel@tonic-gate 				prgetaction32(p, up, sig, &sap[sig-1]);
25257c478bd9Sstevel@tonic-gate 		}
25267c478bd9Sstevel@tonic-gate 		prunlock(pnp);
25277c478bd9Sstevel@tonic-gate 		if (error == 0 &&
25287c478bd9Sstevel@tonic-gate 		    copyout(sap, cmaddr, (NSIG-1)*sizeof (struct sigaction32)))
25297c478bd9Sstevel@tonic-gate 			error = EFAULT;
25307c478bd9Sstevel@tonic-gate 		kmem_free(sap, (NSIG-1)*sizeof (struct sigaction32));
25317c478bd9Sstevel@tonic-gate 		thing = NULL;
25327c478bd9Sstevel@tonic-gate 		break;
25337c478bd9Sstevel@tonic-gate 	}
25347c478bd9Sstevel@tonic-gate 
25357c478bd9Sstevel@tonic-gate 	case PIOCGHOLD:		/* get signal-hold mask */
25367c478bd9Sstevel@tonic-gate 		schedctl_finish_sigblock(t);
25377c478bd9Sstevel@tonic-gate 		sigktou(&t->t_hold, &un32.holdmask);
25387c478bd9Sstevel@tonic-gate 		prunlock(pnp);
25397c478bd9Sstevel@tonic-gate 		if (copyout(&un32.holdmask, cmaddr, sizeof (un32.holdmask)))
25407c478bd9Sstevel@tonic-gate 			error = EFAULT;
25417c478bd9Sstevel@tonic-gate 		break;
25427c478bd9Sstevel@tonic-gate 
25437c478bd9Sstevel@tonic-gate 	case PIOCSHOLD:		/* set signal-hold mask */
25447c478bd9Sstevel@tonic-gate 		pr_sethold(pnp, &un32.holdmask);
25457c478bd9Sstevel@tonic-gate 		prunlock(pnp);
25467c478bd9Sstevel@tonic-gate 		break;
25477c478bd9Sstevel@tonic-gate 
25487c478bd9Sstevel@tonic-gate 	case PIOCNMAP:		/* get number of memory mappings */
25497c478bd9Sstevel@tonic-gate 	{
25507c478bd9Sstevel@tonic-gate 		int n;
25517c478bd9Sstevel@tonic-gate 		struct as *as = p->p_as;
25527c478bd9Sstevel@tonic-gate 
25537c478bd9Sstevel@tonic-gate 		if ((p->p_flag & SSYS) || as == &kas)
25547c478bd9Sstevel@tonic-gate 			n = 0;
25557c478bd9Sstevel@tonic-gate 		else {
25567c478bd9Sstevel@tonic-gate 			mutex_exit(&p->p_lock);
25577c478bd9Sstevel@tonic-gate 			AS_LOCK_ENTER(as, &as->a_lock, RW_WRITER);
25587c478bd9Sstevel@tonic-gate 			n = prnsegs(as, 0);
25597c478bd9Sstevel@tonic-gate 			AS_LOCK_EXIT(as, &as->a_lock);
25607c478bd9Sstevel@tonic-gate 			mutex_enter(&p->p_lock);
25617c478bd9Sstevel@tonic-gate 		}
25627c478bd9Sstevel@tonic-gate 		prunlock(pnp);
25637c478bd9Sstevel@tonic-gate 		if (copyout(&n, cmaddr, sizeof (int)))
25647c478bd9Sstevel@tonic-gate 			error = EFAULT;
25657c478bd9Sstevel@tonic-gate 		break;
25667c478bd9Sstevel@tonic-gate 	}
25677c478bd9Sstevel@tonic-gate 
25687c478bd9Sstevel@tonic-gate 	case PIOCMAP:		/* get memory map information */
25697c478bd9Sstevel@tonic-gate 	{
25707c478bd9Sstevel@tonic-gate 		int n;
25717c478bd9Sstevel@tonic-gate 		ioc_prmap32_t *prmapp;
25727c478bd9Sstevel@tonic-gate 		size_t size;
25737c478bd9Sstevel@tonic-gate 		struct as *as = p->p_as;
25747c478bd9Sstevel@tonic-gate 		int issys = ((p->p_flag & SSYS) || as == &kas);
25757c478bd9Sstevel@tonic-gate 
25767c478bd9Sstevel@tonic-gate 		if (issys) {
25777c478bd9Sstevel@tonic-gate 			n = 1;
25787c478bd9Sstevel@tonic-gate 			prmapp = &un32.prmap;
25797c478bd9Sstevel@tonic-gate 			bzero(prmapp, sizeof (*prmapp));
25807c478bd9Sstevel@tonic-gate 		} else if (PROCESS_NOT_32BIT(p)) {
25817c478bd9Sstevel@tonic-gate 			error = EOVERFLOW;
25827c478bd9Sstevel@tonic-gate 			prunlock(pnp);
25837c478bd9Sstevel@tonic-gate 			break;
25847c478bd9Sstevel@tonic-gate 		} else {
25857c478bd9Sstevel@tonic-gate 			mutex_exit(&p->p_lock);
25867c478bd9Sstevel@tonic-gate 			AS_LOCK_ENTER(as, &as->a_lock, RW_WRITER);
25877c478bd9Sstevel@tonic-gate 			n = oprgetmap32(p, &prmapp, &size);
25887c478bd9Sstevel@tonic-gate 			AS_LOCK_EXIT(as, &as->a_lock);
25897c478bd9Sstevel@tonic-gate 			mutex_enter(&p->p_lock);
25907c478bd9Sstevel@tonic-gate 		}
25917c478bd9Sstevel@tonic-gate 		prunlock(pnp);
25927c478bd9Sstevel@tonic-gate 
25937c478bd9Sstevel@tonic-gate 		if (copyout(prmapp, cmaddr, n * sizeof (ioc_prmap32_t)))
25947c478bd9Sstevel@tonic-gate 			error = EFAULT;
25957c478bd9Sstevel@tonic-gate 		if (!issys)
25967c478bd9Sstevel@tonic-gate 			kmem_free(prmapp, size);
25977c478bd9Sstevel@tonic-gate 		break;
25987c478bd9Sstevel@tonic-gate 	}
25997c478bd9Sstevel@tonic-gate 
26007c478bd9Sstevel@tonic-gate 	case PIOCGFAULT:	/* get mask of traced faults */
26017c478bd9Sstevel@tonic-gate 		prassignset(&un32.fltmask, &p->p_fltmask);
26027c478bd9Sstevel@tonic-gate 		prunlock(pnp);
26037c478bd9Sstevel@tonic-gate 		if (copyout(&un32.fltmask, cmaddr, sizeof (un32.fltmask)))
26047c478bd9Sstevel@tonic-gate 			error = EFAULT;
26057c478bd9Sstevel@tonic-gate 		break;
26067c478bd9Sstevel@tonic-gate 
26077c478bd9Sstevel@tonic-gate 	case PIOCSFAULT:	/* set mask of traced faults */
26087c478bd9Sstevel@tonic-gate 		pr_setfault(p, &un32.fltmask);
26097c478bd9Sstevel@tonic-gate 		prunlock(pnp);
26107c478bd9Sstevel@tonic-gate 		break;
26117c478bd9Sstevel@tonic-gate 
26127c478bd9Sstevel@tonic-gate 	case PIOCCFAULT:	/* clear current fault */
26137c478bd9Sstevel@tonic-gate 		lwp->lwp_curflt = 0;
26147c478bd9Sstevel@tonic-gate 		prunlock(pnp);
26157c478bd9Sstevel@tonic-gate 		break;
26167c478bd9Sstevel@tonic-gate 
26177c478bd9Sstevel@tonic-gate 	case PIOCCRED:		/* get process credentials */
26187c478bd9Sstevel@tonic-gate 	{
26197c478bd9Sstevel@tonic-gate 		cred_t *cp;
26207c478bd9Sstevel@tonic-gate 
26217c478bd9Sstevel@tonic-gate 		mutex_enter(&p->p_crlock);
26227c478bd9Sstevel@tonic-gate 		cp = p->p_cred;
26237c478bd9Sstevel@tonic-gate 		un32.prcred.pr_euid = crgetuid(cp);
26247c478bd9Sstevel@tonic-gate 		un32.prcred.pr_ruid = crgetruid(cp);
26257c478bd9Sstevel@tonic-gate 		un32.prcred.pr_suid = crgetsuid(cp);
26267c478bd9Sstevel@tonic-gate 		un32.prcred.pr_egid = crgetgid(cp);
26277c478bd9Sstevel@tonic-gate 		un32.prcred.pr_rgid = crgetrgid(cp);
26287c478bd9Sstevel@tonic-gate 		un32.prcred.pr_sgid = crgetsgid(cp);
26297c478bd9Sstevel@tonic-gate 		un32.prcred.pr_ngroups = crgetngroups(cp);
26307c478bd9Sstevel@tonic-gate 		mutex_exit(&p->p_crlock);
26317c478bd9Sstevel@tonic-gate 
26327c478bd9Sstevel@tonic-gate 		prunlock(pnp);
26337c478bd9Sstevel@tonic-gate 		if (copyout(&un32.prcred, cmaddr, sizeof (un32.prcred)))
26347c478bd9Sstevel@tonic-gate 			error = EFAULT;
26357c478bd9Sstevel@tonic-gate 		break;
26367c478bd9Sstevel@tonic-gate 	}
26377c478bd9Sstevel@tonic-gate 
26387c478bd9Sstevel@tonic-gate 	case PIOCGROUPS:	/* get supplementary groups */
26397c478bd9Sstevel@tonic-gate 	{
26407c478bd9Sstevel@tonic-gate 		cred_t *cp;
26417c478bd9Sstevel@tonic-gate 
26427c478bd9Sstevel@tonic-gate 		mutex_enter(&p->p_crlock);
26437c478bd9Sstevel@tonic-gate 		cp = p->p_cred;
26447c478bd9Sstevel@tonic-gate 		crhold(cp);
26457c478bd9Sstevel@tonic-gate 		mutex_exit(&p->p_crlock);
26467c478bd9Sstevel@tonic-gate 
26477c478bd9Sstevel@tonic-gate 		prunlock(pnp);
26487c478bd9Sstevel@tonic-gate 		if (copyout(crgetgroups(cp), cmaddr,
26497c478bd9Sstevel@tonic-gate 		    MAX(crgetngroups(cp), 1) * sizeof (gid_t)))
26507c478bd9Sstevel@tonic-gate 			error = EFAULT;
26517c478bd9Sstevel@tonic-gate 		crfree(cp);
26527c478bd9Sstevel@tonic-gate 		break;
26537c478bd9Sstevel@tonic-gate 	}
26547c478bd9Sstevel@tonic-gate 
26557c478bd9Sstevel@tonic-gate 	case PIOCUSAGE:		/* get usage info */
26567c478bd9Sstevel@tonic-gate 	{
26577c478bd9Sstevel@tonic-gate 		/*
26587c478bd9Sstevel@tonic-gate 		 * For an lwp file descriptor, return just the lwp usage.
26597c478bd9Sstevel@tonic-gate 		 * For a process file descriptor, return total usage,
26607c478bd9Sstevel@tonic-gate 		 * all current lwps plus all defunct lwps.
26617c478bd9Sstevel@tonic-gate 		 */
26627c478bd9Sstevel@tonic-gate 		prhusage_t *pup = &un32.prhusage;
26637c478bd9Sstevel@tonic-gate 		prusage32_t *upup;
26647c478bd9Sstevel@tonic-gate 
26657c478bd9Sstevel@tonic-gate 		bzero(pup, sizeof (*pup));
26667c478bd9Sstevel@tonic-gate 		pup->pr_tstamp = gethrtime();
26677c478bd9Sstevel@tonic-gate 
26687c478bd9Sstevel@tonic-gate 		if (pnp->pr_type == PR_LWPIDFILE) {
26697c478bd9Sstevel@tonic-gate 			t = pcp->prc_thread;
26707c478bd9Sstevel@tonic-gate 			if (t != NULL)
26717c478bd9Sstevel@tonic-gate 				prgetusage(t, pup);
26727c478bd9Sstevel@tonic-gate 			else
26737c478bd9Sstevel@tonic-gate 				error = ENOENT;
26747c478bd9Sstevel@tonic-gate 		} else {
26757c478bd9Sstevel@tonic-gate 			pup->pr_count  = p->p_defunct;
26767c478bd9Sstevel@tonic-gate 			pup->pr_create = p->p_mstart;
26777c478bd9Sstevel@tonic-gate 			pup->pr_term   = p->p_mterm;
26787c478bd9Sstevel@tonic-gate 
26797c478bd9Sstevel@tonic-gate 			pup->pr_rtime    = p->p_mlreal;
26807c478bd9Sstevel@tonic-gate 			pup->pr_utime    = p->p_acct[LMS_USER];
26817c478bd9Sstevel@tonic-gate 			pup->pr_stime    = p->p_acct[LMS_SYSTEM];
26827c478bd9Sstevel@tonic-gate 			pup->pr_ttime    = p->p_acct[LMS_TRAP];
26837c478bd9Sstevel@tonic-gate 			pup->pr_tftime   = p->p_acct[LMS_TFAULT];
26847c478bd9Sstevel@tonic-gate 			pup->pr_dftime   = p->p_acct[LMS_DFAULT];
26857c478bd9Sstevel@tonic-gate 			pup->pr_kftime   = p->p_acct[LMS_KFAULT];
26867c478bd9Sstevel@tonic-gate 			pup->pr_ltime    = p->p_acct[LMS_USER_LOCK];
26877c478bd9Sstevel@tonic-gate 			pup->pr_slptime  = p->p_acct[LMS_SLEEP];
26887c478bd9Sstevel@tonic-gate 			pup->pr_wtime    = p->p_acct[LMS_WAIT_CPU];
26897c478bd9Sstevel@tonic-gate 			pup->pr_stoptime = p->p_acct[LMS_STOPPED];
26907c478bd9Sstevel@tonic-gate 
26917c478bd9Sstevel@tonic-gate 			pup->pr_minf  = p->p_ru.minflt;
26927c478bd9Sstevel@tonic-gate 			pup->pr_majf  = p->p_ru.majflt;
26937c478bd9Sstevel@tonic-gate 			pup->pr_nswap = p->p_ru.nswap;
26947c478bd9Sstevel@tonic-gate 			pup->pr_inblk = p->p_ru.inblock;
26957c478bd9Sstevel@tonic-gate 			pup->pr_oublk = p->p_ru.oublock;
26967c478bd9Sstevel@tonic-gate 			pup->pr_msnd  = p->p_ru.msgsnd;
26977c478bd9Sstevel@tonic-gate 			pup->pr_mrcv  = p->p_ru.msgrcv;
26987c478bd9Sstevel@tonic-gate 			pup->pr_sigs  = p->p_ru.nsignals;
26997c478bd9Sstevel@tonic-gate 			pup->pr_vctx  = p->p_ru.nvcsw;
27007c478bd9Sstevel@tonic-gate 			pup->pr_ictx  = p->p_ru.nivcsw;
27017c478bd9Sstevel@tonic-gate 			pup->pr_sysc  = p->p_ru.sysc;
27027c478bd9Sstevel@tonic-gate 			pup->pr_ioch  = p->p_ru.ioch;
27037c478bd9Sstevel@tonic-gate 
27047c478bd9Sstevel@tonic-gate 			/*
27057c478bd9Sstevel@tonic-gate 			 * Add the usage information for each active lwp.
27067c478bd9Sstevel@tonic-gate 			 */
27077c478bd9Sstevel@tonic-gate 			if ((t = p->p_tlist) != NULL &&
27087c478bd9Sstevel@tonic-gate 			    !(pcp->prc_flags & PRC_DESTROY)) {
27097c478bd9Sstevel@tonic-gate 				do {
27107c478bd9Sstevel@tonic-gate 					ASSERT(!(t->t_proc_flag & TP_LWPEXIT));
27117c478bd9Sstevel@tonic-gate 					pup->pr_count++;
27127c478bd9Sstevel@tonic-gate 					praddusage(t, pup);
27137c478bd9Sstevel@tonic-gate 				} while ((t = t->t_forw) != p->p_tlist);
27147c478bd9Sstevel@tonic-gate 			}
27157c478bd9Sstevel@tonic-gate 		}
27167c478bd9Sstevel@tonic-gate 
27177c478bd9Sstevel@tonic-gate 		prunlock(pnp);
27187c478bd9Sstevel@tonic-gate 
27197c478bd9Sstevel@tonic-gate 		upup = kmem_alloc(sizeof (*upup), KM_SLEEP);
27207c478bd9Sstevel@tonic-gate 		prcvtusage32(pup, upup);
27217c478bd9Sstevel@tonic-gate 		if (copyout(upup, cmaddr, sizeof (*upup)))
27227c478bd9Sstevel@tonic-gate 			error = EFAULT;
27237c478bd9Sstevel@tonic-gate 		kmem_free(upup, sizeof (*upup));
27247c478bd9Sstevel@tonic-gate 
27257c478bd9Sstevel@tonic-gate 		break;
27267c478bd9Sstevel@tonic-gate 	}
27277c478bd9Sstevel@tonic-gate 
27287c478bd9Sstevel@tonic-gate 	case PIOCLUSAGE:	/* get detailed usage info */
27297c478bd9Sstevel@tonic-gate 	{
27307c478bd9Sstevel@tonic-gate 		int Nlwp;
27317c478bd9Sstevel@tonic-gate 		int nlwp;
27327c478bd9Sstevel@tonic-gate 		prusage32_t *upup;
27337c478bd9Sstevel@tonic-gate 		prusage32_t *Bupup;
27347c478bd9Sstevel@tonic-gate 		prhusage_t *pup;
27357c478bd9Sstevel@tonic-gate 		hrtime_t curtime;
27367c478bd9Sstevel@tonic-gate 
27377c478bd9Sstevel@tonic-gate 		nlwp = Nlwp = (pcp->prc_flags & PRC_DESTROY)? 0 : p->p_lwpcnt;
27387c478bd9Sstevel@tonic-gate 
27397c478bd9Sstevel@tonic-gate 		if (thing && thingsize !=
27407c478bd9Sstevel@tonic-gate 		    sizeof (prhusage_t) + (Nlwp+1) * sizeof (prusage32_t)) {
27417c478bd9Sstevel@tonic-gate 			kmem_free(thing, thingsize);
27427c478bd9Sstevel@tonic-gate 			thing = NULL;
27437c478bd9Sstevel@tonic-gate 		}
27447c478bd9Sstevel@tonic-gate 		if (thing == NULL) {
27457c478bd9Sstevel@tonic-gate 			thingsize = sizeof (prhusage_t) +
27467c478bd9Sstevel@tonic-gate 			    (Nlwp+1) * sizeof (prusage32_t);
27477c478bd9Sstevel@tonic-gate 			thing = kmem_alloc(thingsize, KM_NOSLEEP);
27487c478bd9Sstevel@tonic-gate 		}
27497c478bd9Sstevel@tonic-gate 		if (thing == NULL) {
27507c478bd9Sstevel@tonic-gate 			prunlock(pnp);
27517c478bd9Sstevel@tonic-gate 			goto startover;
27527c478bd9Sstevel@tonic-gate 		}
27537c478bd9Sstevel@tonic-gate 
27547c478bd9Sstevel@tonic-gate 		pup = (prhusage_t *)thing;
27557c478bd9Sstevel@tonic-gate 		upup = Bupup = (prusage32_t *)(pup + 1);
27567c478bd9Sstevel@tonic-gate 
27577c478bd9Sstevel@tonic-gate 		ASSERT(p == pcp->prc_proc);
27587c478bd9Sstevel@tonic-gate 
27597c478bd9Sstevel@tonic-gate 		curtime = gethrtime();
27607c478bd9Sstevel@tonic-gate 
27617c478bd9Sstevel@tonic-gate 		/*
27627c478bd9Sstevel@tonic-gate 		 * First the summation over defunct lwps.
27637c478bd9Sstevel@tonic-gate 		 */
27647c478bd9Sstevel@tonic-gate 		bzero(pup, sizeof (*pup));
27657c478bd9Sstevel@tonic-gate 		pup->pr_count  = p->p_defunct;
27667c478bd9Sstevel@tonic-gate 		pup->pr_tstamp = curtime;
27677c478bd9Sstevel@tonic-gate 		pup->pr_create = p->p_mstart;
27687c478bd9Sstevel@tonic-gate 		pup->pr_term   = p->p_mterm;
27697c478bd9Sstevel@tonic-gate 
27707c478bd9Sstevel@tonic-gate 		pup->pr_rtime    = p->p_mlreal;
27717c478bd9Sstevel@tonic-gate 		pup->pr_utime    = p->p_acct[LMS_USER];
27727c478bd9Sstevel@tonic-gate 		pup->pr_stime    = p->p_acct[LMS_SYSTEM];
27737c478bd9Sstevel@tonic-gate 		pup->pr_ttime    = p->p_acct[LMS_TRAP];
27747c478bd9Sstevel@tonic-gate 		pup->pr_tftime   = p->p_acct[LMS_TFAULT];
27757c478bd9Sstevel@tonic-gate 		pup->pr_dftime   = p->p_acct[LMS_DFAULT];
27767c478bd9Sstevel@tonic-gate 		pup->pr_kftime   = p->p_acct[LMS_KFAULT];
27777c478bd9Sstevel@tonic-gate 		pup->pr_ltime    = p->p_acct[LMS_USER_LOCK];
27787c478bd9Sstevel@tonic-gate 		pup->pr_slptime  = p->p_acct[LMS_SLEEP];
27797c478bd9Sstevel@tonic-gate 		pup->pr_wtime    = p->p_acct[LMS_WAIT_CPU];
27807c478bd9Sstevel@tonic-gate 		pup->pr_stoptime = p->p_acct[LMS_STOPPED];
27817c478bd9Sstevel@tonic-gate 
27827c478bd9Sstevel@tonic-gate 		pup->pr_minf  = p->p_ru.minflt;
27837c478bd9Sstevel@tonic-gate 		pup->pr_majf  = p->p_ru.majflt;
27847c478bd9Sstevel@tonic-gate 		pup->pr_nswap = p->p_ru.nswap;
27857c478bd9Sstevel@tonic-gate 		pup->pr_inblk = p->p_ru.inblock;
27867c478bd9Sstevel@tonic-gate 		pup->pr_oublk = p->p_ru.oublock;
27877c478bd9Sstevel@tonic-gate 		pup->pr_msnd  = p->p_ru.msgsnd;
27887c478bd9Sstevel@tonic-gate 		pup->pr_mrcv  = p->p_ru.msgrcv;
27897c478bd9Sstevel@tonic-gate 		pup->pr_sigs  = p->p_ru.nsignals;
27907c478bd9Sstevel@tonic-gate 		pup->pr_vctx  = p->p_ru.nvcsw;
27917c478bd9Sstevel@tonic-gate 		pup->pr_ictx  = p->p_ru.nivcsw;
27927c478bd9Sstevel@tonic-gate 		pup->pr_sysc  = p->p_ru.sysc;
27937c478bd9Sstevel@tonic-gate 		pup->pr_ioch  = p->p_ru.ioch;
27947c478bd9Sstevel@tonic-gate 
27957c478bd9Sstevel@tonic-gate 		prcvtusage32(pup, upup);
27967c478bd9Sstevel@tonic-gate 
27977c478bd9Sstevel@tonic-gate 		/*
27987c478bd9Sstevel@tonic-gate 		 * Fill one prusage struct for each active lwp.
27997c478bd9Sstevel@tonic-gate 		 */
28007c478bd9Sstevel@tonic-gate 		if ((t = p->p_tlist) != NULL &&
28017c478bd9Sstevel@tonic-gate 		    !(pcp->prc_flags & PRC_DESTROY)) {
28027c478bd9Sstevel@tonic-gate 			do {
28037c478bd9Sstevel@tonic-gate 				ASSERT(!(t->t_proc_flag & TP_LWPEXIT));
28047c478bd9Sstevel@tonic-gate 				ASSERT(nlwp > 0);
28057c478bd9Sstevel@tonic-gate 				--nlwp;
28067c478bd9Sstevel@tonic-gate 				upup++;
28077c478bd9Sstevel@tonic-gate 				prgetusage(t, pup);
28087c478bd9Sstevel@tonic-gate 				prcvtusage32(pup, upup);
28097c478bd9Sstevel@tonic-gate 			} while ((t = t->t_forw) != p->p_tlist);
28107c478bd9Sstevel@tonic-gate 		}
28117c478bd9Sstevel@tonic-gate 		ASSERT(nlwp == 0);
28127c478bd9Sstevel@tonic-gate 
28137c478bd9Sstevel@tonic-gate 		prunlock(pnp);
28147c478bd9Sstevel@tonic-gate 		if (copyout(Bupup, cmaddr, (Nlwp+1) * sizeof (prusage32_t)))
28157c478bd9Sstevel@tonic-gate 			error = EFAULT;
28167c478bd9Sstevel@tonic-gate 		kmem_free(thing, thingsize);
28177c478bd9Sstevel@tonic-gate 		thing = NULL;
28187c478bd9Sstevel@tonic-gate 		break;
28197c478bd9Sstevel@tonic-gate 	}
28207c478bd9Sstevel@tonic-gate 
28217c478bd9Sstevel@tonic-gate 	case PIOCNAUXV:		/* get number of aux vector entries */
28227c478bd9Sstevel@tonic-gate 	{
28237c478bd9Sstevel@tonic-gate 		int n = __KERN_NAUXV_IMPL;
28247c478bd9Sstevel@tonic-gate 
28257c478bd9Sstevel@tonic-gate 		prunlock(pnp);
28267c478bd9Sstevel@tonic-gate 		if (copyout(&n, cmaddr, sizeof (int)))
28277c478bd9Sstevel@tonic-gate 			error = EFAULT;
28287c478bd9Sstevel@tonic-gate 		break;
28297c478bd9Sstevel@tonic-gate 	}
28307c478bd9Sstevel@tonic-gate 
28317c478bd9Sstevel@tonic-gate 	case PIOCAUXV:		/* get aux vector (see sys/auxv.h) */
28327c478bd9Sstevel@tonic-gate 	{
28337c478bd9Sstevel@tonic-gate 		int i;
28347c478bd9Sstevel@tonic-gate 
28357c478bd9Sstevel@tonic-gate 		if (PROCESS_NOT_32BIT(p)) {
28367c478bd9Sstevel@tonic-gate 			prunlock(pnp);
28377c478bd9Sstevel@tonic-gate 			error = EOVERFLOW;
28387c478bd9Sstevel@tonic-gate 		} else {
28397c478bd9Sstevel@tonic-gate 			up = PTOU(p);
28407c478bd9Sstevel@tonic-gate 			for (i = 0; i < __KERN_NAUXV_IMPL; i++) {
28417c478bd9Sstevel@tonic-gate 				un32.auxv[i].a_type = up->u_auxv[i].a_type;
28427c478bd9Sstevel@tonic-gate 				un32.auxv[i].a_un.a_val =
28437c478bd9Sstevel@tonic-gate 					(int32_t)up->u_auxv[i].a_un.a_val;
28447c478bd9Sstevel@tonic-gate 			}
28457c478bd9Sstevel@tonic-gate 			prunlock(pnp);
28467c478bd9Sstevel@tonic-gate 			if (copyout(un32.auxv, cmaddr,
28477c478bd9Sstevel@tonic-gate 			    __KERN_NAUXV_IMPL * sizeof (auxv32_t)))
28487c478bd9Sstevel@tonic-gate 				error = EFAULT;
28497c478bd9Sstevel@tonic-gate 		}
28507c478bd9Sstevel@tonic-gate 		break;
28517c478bd9Sstevel@tonic-gate 	}
28527c478bd9Sstevel@tonic-gate 
28537c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__i386_COMPAT)
28547c478bd9Sstevel@tonic-gate 	case PIOCNLDT:		/* get number of LDT entries */
28557c478bd9Sstevel@tonic-gate 	{
28567c478bd9Sstevel@tonic-gate 		int n;
28577c478bd9Sstevel@tonic-gate 
28587c478bd9Sstevel@tonic-gate 		mutex_enter(&p->p_ldtlock);
28597c478bd9Sstevel@tonic-gate 		n = prnldt(p);
28607c478bd9Sstevel@tonic-gate 		mutex_exit(&p->p_ldtlock);
28617c478bd9Sstevel@tonic-gate 		prunlock(pnp);
28627c478bd9Sstevel@tonic-gate 		if (copyout(&n, cmaddr, sizeof (n)))
28637c478bd9Sstevel@tonic-gate 			error = EFAULT;
28647c478bd9Sstevel@tonic-gate 		break;
28657c478bd9Sstevel@tonic-gate 	}
28667c478bd9Sstevel@tonic-gate 
28677c478bd9Sstevel@tonic-gate 	case PIOCLDT:		/* get LDT entries */
28687c478bd9Sstevel@tonic-gate 	{
28697c478bd9Sstevel@tonic-gate 		struct ssd *ssd;
28707c478bd9Sstevel@tonic-gate 		int n;
28717c478bd9Sstevel@tonic-gate 
28727c478bd9Sstevel@tonic-gate 		mutex_enter(&p->p_ldtlock);
28737c478bd9Sstevel@tonic-gate 		n = prnldt(p);
28747c478bd9Sstevel@tonic-gate 
28757c478bd9Sstevel@tonic-gate 		if (thing && thingsize != (n+1) * sizeof (*ssd)) {
28767c478bd9Sstevel@tonic-gate 			kmem_free(thing, thingsize);
28777c478bd9Sstevel@tonic-gate 			thing = NULL;
28787c478bd9Sstevel@tonic-gate 		}
28797c478bd9Sstevel@tonic-gate 		if (thing == NULL) {
28807c478bd9Sstevel@tonic-gate 			thingsize = (n+1) * sizeof (*ssd);
28817c478bd9Sstevel@tonic-gate 			thing = kmem_alloc(thingsize, KM_NOSLEEP);
28827c478bd9Sstevel@tonic-gate 		}
28837c478bd9Sstevel@tonic-gate 		if (thing == NULL) {
28847c478bd9Sstevel@tonic-gate 			mutex_exit(&p->p_ldtlock);
28857c478bd9Sstevel@tonic-gate 			prunlock(pnp);
28867c478bd9Sstevel@tonic-gate 			goto startover;
28877c478bd9Sstevel@tonic-gate 		}
28887c478bd9Sstevel@tonic-gate 
28897c478bd9Sstevel@tonic-gate 		ssd = thing;
28907c478bd9Sstevel@tonic-gate 		thing = NULL;
28917c478bd9Sstevel@tonic-gate 		if (n != 0)
28927c478bd9Sstevel@tonic-gate 			prgetldt(p, ssd);
28937c478bd9Sstevel@tonic-gate 		mutex_exit(&p->p_ldtlock);
28947c478bd9Sstevel@tonic-gate 		prunlock(pnp);
28957c478bd9Sstevel@tonic-gate 
28967c478bd9Sstevel@tonic-gate 		/* mark the end of the list with a null entry */
28977c478bd9Sstevel@tonic-gate 		bzero(&ssd[n], sizeof (*ssd));
28987c478bd9Sstevel@tonic-gate 		if (copyout(ssd, cmaddr, (n+1) * sizeof (*ssd)))
28997c478bd9Sstevel@tonic-gate 			error = EFAULT;
29007c478bd9Sstevel@tonic-gate 		kmem_free(ssd, (n+1) * sizeof (*ssd));
29017c478bd9Sstevel@tonic-gate 		break;
29027c478bd9Sstevel@tonic-gate 	}
29037c478bd9Sstevel@tonic-gate #endif	/* __i386 || __i386_COMPAT */
29047c478bd9Sstevel@tonic-gate 
29057c478bd9Sstevel@tonic-gate #if defined(__sparc)
29067c478bd9Sstevel@tonic-gate 	case PIOCGWIN:		/* get gwindows_t (see sys/reg.h) */
29077c478bd9Sstevel@tonic-gate 	{
29087c478bd9Sstevel@tonic-gate 		gwindows32_t *gwp = thing;
29097c478bd9Sstevel@tonic-gate 
29107c478bd9Sstevel@tonic-gate 		if (PROCESS_NOT_32BIT(p)) {
29117c478bd9Sstevel@tonic-gate 			prunlock(pnp);
29127c478bd9Sstevel@tonic-gate 			error = EOVERFLOW;
29137c478bd9Sstevel@tonic-gate 		} else {
29147c478bd9Sstevel@tonic-gate 			/* drop p->p_lock while touching the stack */
29157c478bd9Sstevel@tonic-gate 			mutex_exit(&p->p_lock);
29167c478bd9Sstevel@tonic-gate 			bzero(gwp, sizeof (*gwp));
29177c478bd9Sstevel@tonic-gate 			prgetwindows32(lwp, gwp);
29187c478bd9Sstevel@tonic-gate 			mutex_enter(&p->p_lock);
29197c478bd9Sstevel@tonic-gate 			prunlock(pnp);
29207c478bd9Sstevel@tonic-gate 			if (copyout(gwp, cmaddr, sizeof (*gwp)))
29217c478bd9Sstevel@tonic-gate 				error = EFAULT;
29227c478bd9Sstevel@tonic-gate 		}
29237c478bd9Sstevel@tonic-gate 		kmem_free(gwp, sizeof (*gwp));
29247c478bd9Sstevel@tonic-gate 		thing = NULL;
29257c478bd9Sstevel@tonic-gate 		break;
29267c478bd9Sstevel@tonic-gate 	}
29277c478bd9Sstevel@tonic-gate #endif	/* __sparc */
29287c478bd9Sstevel@tonic-gate 
29297c478bd9Sstevel@tonic-gate 	default:
29307c478bd9Sstevel@tonic-gate 		prunlock(pnp);
29317c478bd9Sstevel@tonic-gate 		error = EINVAL;
29327c478bd9Sstevel@tonic-gate 		break;
29337c478bd9Sstevel@tonic-gate 
29347c478bd9Sstevel@tonic-gate 	}
29357c478bd9Sstevel@tonic-gate 
29367c478bd9Sstevel@tonic-gate 	ASSERT(thing == NULL);
29377c478bd9Sstevel@tonic-gate 	ASSERT(xpnp == NULL);
29387c478bd9Sstevel@tonic-gate 	return (error);
29397c478bd9Sstevel@tonic-gate }
29407c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32_IMPL */
29417c478bd9Sstevel@tonic-gate 
29427c478bd9Sstevel@tonic-gate /*
29437c478bd9Sstevel@tonic-gate  * Distinguish "writeable" ioctl requests from others.
29447c478bd9Sstevel@tonic-gate  */
29457c478bd9Sstevel@tonic-gate static int
29467c478bd9Sstevel@tonic-gate isprwrioctl(int cmd)
29477c478bd9Sstevel@tonic-gate {
29487c478bd9Sstevel@tonic-gate 	switch (cmd) {
29497c478bd9Sstevel@tonic-gate 	case PIOCSTOP:
29507c478bd9Sstevel@tonic-gate 	case PIOCRUN:
29517c478bd9Sstevel@tonic-gate 	case PIOCSTRACE:
29527c478bd9Sstevel@tonic-gate 	case PIOCSSIG:
29537c478bd9Sstevel@tonic-gate 	case PIOCKILL:
29547c478bd9Sstevel@tonic-gate 	case PIOCUNKILL:
29557c478bd9Sstevel@tonic-gate 	case PIOCNICE:
29567c478bd9Sstevel@tonic-gate 	case PIOCSENTRY:
29577c478bd9Sstevel@tonic-gate 	case PIOCSEXIT:
29587c478bd9Sstevel@tonic-gate 	case PIOCSRLC:
29597c478bd9Sstevel@tonic-gate 	case PIOCRRLC:
29607c478bd9Sstevel@tonic-gate 	case PIOCSREG:
29617c478bd9Sstevel@tonic-gate 	case PIOCSFPREG:
29627c478bd9Sstevel@tonic-gate 	case PIOCSXREG:
29637c478bd9Sstevel@tonic-gate 	case PIOCSHOLD:
29647c478bd9Sstevel@tonic-gate 	case PIOCSFAULT:
29657c478bd9Sstevel@tonic-gate 	case PIOCCFAULT:
29667c478bd9Sstevel@tonic-gate 	case PIOCSFORK:
29677c478bd9Sstevel@tonic-gate 	case PIOCRFORK:
29687c478bd9Sstevel@tonic-gate 	case PIOCSET:
29697c478bd9Sstevel@tonic-gate 	case PIOCRESET:
29707c478bd9Sstevel@tonic-gate 		return (1);
29717c478bd9Sstevel@tonic-gate 	}
29727c478bd9Sstevel@tonic-gate 	return (0);
29737c478bd9Sstevel@tonic-gate }
29747c478bd9Sstevel@tonic-gate 
29757c478bd9Sstevel@tonic-gate /*
29767c478bd9Sstevel@tonic-gate  * Map the ioctl() interface run flags to the new interface run flags.
29777c478bd9Sstevel@tonic-gate  */
29787c478bd9Sstevel@tonic-gate static ulong_t
29797c478bd9Sstevel@tonic-gate prmaprunflags(long flags)
29807c478bd9Sstevel@tonic-gate {
29817c478bd9Sstevel@tonic-gate 	ulong_t newflags = 0;
29827c478bd9Sstevel@tonic-gate 
29837c478bd9Sstevel@tonic-gate 	if (flags & PRCSIG)
29847c478bd9Sstevel@tonic-gate 		newflags |= 0x01;
29857c478bd9Sstevel@tonic-gate 	if (flags & PRCFAULT)
29867c478bd9Sstevel@tonic-gate 		newflags |= 0x02;
29877c478bd9Sstevel@tonic-gate 	if (flags & PRSTEP)
29887c478bd9Sstevel@tonic-gate 		newflags |= 0x04;
29897c478bd9Sstevel@tonic-gate 	if (flags & PRSABORT)
29907c478bd9Sstevel@tonic-gate 		newflags |= 0x08;
29917c478bd9Sstevel@tonic-gate 	if (flags & PRSTOP)
29927c478bd9Sstevel@tonic-gate 		newflags |= 0x10;
29937c478bd9Sstevel@tonic-gate 	return (newflags);
29947c478bd9Sstevel@tonic-gate }
29957c478bd9Sstevel@tonic-gate 
29967c478bd9Sstevel@tonic-gate /*
29977c478bd9Sstevel@tonic-gate  * Map the ioctl() interface settable mode flags to the new interface flags.
29987c478bd9Sstevel@tonic-gate  */
29997c478bd9Sstevel@tonic-gate static long
30007c478bd9Sstevel@tonic-gate prmapsetflags(long flags)
30017c478bd9Sstevel@tonic-gate {
30027c478bd9Sstevel@tonic-gate 	long newflags = 0;
30037c478bd9Sstevel@tonic-gate 
30047c478bd9Sstevel@tonic-gate #define	ALLFLAGS	\
30057c478bd9Sstevel@tonic-gate 	(PR_FORK|PR_RLC|PR_KLC|PR_ASYNC|PR_BPTADJ|PR_MSACCT|PR_PCOMPAT)
30067c478bd9Sstevel@tonic-gate 
30077c478bd9Sstevel@tonic-gate 	if (flags & ~ALLFLAGS)
30087c478bd9Sstevel@tonic-gate 		newflags = 0xffff;	/* forces EINVAL */
30097c478bd9Sstevel@tonic-gate 	if (flags & PR_FORK)
30107c478bd9Sstevel@tonic-gate 		newflags |= (0x00100000 | 0x08000000);
30117c478bd9Sstevel@tonic-gate 	if (flags & PR_RLC)
30127c478bd9Sstevel@tonic-gate 		newflags |= 0x00200000;
30137c478bd9Sstevel@tonic-gate 	if (flags & PR_KLC)
30147c478bd9Sstevel@tonic-gate 		newflags |= 0x00400000;
30157c478bd9Sstevel@tonic-gate 	if (flags & PR_ASYNC)
30167c478bd9Sstevel@tonic-gate 		newflags |= 0x00800000;
30177c478bd9Sstevel@tonic-gate 	if (flags & PR_MSACCT)
30187c478bd9Sstevel@tonic-gate 		newflags |= 0x01000000;
30197c478bd9Sstevel@tonic-gate 	if (flags & PR_BPTADJ)
30207c478bd9Sstevel@tonic-gate 		newflags |= 0x02000000;
30217c478bd9Sstevel@tonic-gate 	if (flags & PR_PCOMPAT)
30227c478bd9Sstevel@tonic-gate 		newflags |= 0x04000000;
30237c478bd9Sstevel@tonic-gate 	return (newflags);
30247c478bd9Sstevel@tonic-gate }
30257c478bd9Sstevel@tonic-gate 
30267c478bd9Sstevel@tonic-gate /*
30277c478bd9Sstevel@tonic-gate  * Apply PIOCRUN options specific to the ioctl() interface.
30287c478bd9Sstevel@tonic-gate  */
30297c478bd9Sstevel@tonic-gate static void
30307c478bd9Sstevel@tonic-gate prsetrun(kthread_t *t, prrun_t *prp)
30317c478bd9Sstevel@tonic-gate {
30327c478bd9Sstevel@tonic-gate 	proc_t *p = ttoproc(t);
30337c478bd9Sstevel@tonic-gate 	klwp_t *lwp = ttolwp(t);
30347c478bd9Sstevel@tonic-gate 	long flags = prp->pr_flags;
30357c478bd9Sstevel@tonic-gate 	user_t *up = PTOU(p);
30367c478bd9Sstevel@tonic-gate 
30377c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&p->p_lock));
30387c478bd9Sstevel@tonic-gate 
30397c478bd9Sstevel@tonic-gate 	if (flags & PRSHOLD) {
30407c478bd9Sstevel@tonic-gate 		schedctl_finish_sigblock(t);
30417c478bd9Sstevel@tonic-gate 		sigutok(&prp->pr_sighold, &t->t_hold);
30427c478bd9Sstevel@tonic-gate 		t->t_sig_check = 1;	/* so ISSIG will be done */
30437c478bd9Sstevel@tonic-gate 	}
30447c478bd9Sstevel@tonic-gate 	if (flags & PRSTRACE) {
30457c478bd9Sstevel@tonic-gate 		prdelset(&prp->pr_trace, SIGKILL);
30467c478bd9Sstevel@tonic-gate 		prassignset(&p->p_sigmask, &prp->pr_trace);
30477c478bd9Sstevel@tonic-gate 		if (!sigisempty(&p->p_sigmask))
30487c478bd9Sstevel@tonic-gate 			p->p_proc_flag |= P_PR_TRACE;
30497c478bd9Sstevel@tonic-gate 		else if (prisempty(&p->p_fltmask)) {
30507c478bd9Sstevel@tonic-gate 			if (up->u_systrap == 0)
30517c478bd9Sstevel@tonic-gate 				p->p_proc_flag &= ~P_PR_TRACE;
30527c478bd9Sstevel@tonic-gate 		}
30537c478bd9Sstevel@tonic-gate 	}
30547c478bd9Sstevel@tonic-gate 	if (flags & PRSFAULT) {
30557c478bd9Sstevel@tonic-gate 		prassignset(&p->p_fltmask, &prp->pr_fault);
30567c478bd9Sstevel@tonic-gate 		if (!prisempty(&p->p_fltmask))
30577c478bd9Sstevel@tonic-gate 			p->p_proc_flag |= P_PR_TRACE;
30587c478bd9Sstevel@tonic-gate 		else if (sigisempty(&p->p_sigmask)) {
30597c478bd9Sstevel@tonic-gate 			if (up->u_systrap == 0)
30607c478bd9Sstevel@tonic-gate 				p->p_proc_flag &= ~P_PR_TRACE;
30617c478bd9Sstevel@tonic-gate 		}
30627c478bd9Sstevel@tonic-gate 	}
30637c478bd9Sstevel@tonic-gate 	/*
30647c478bd9Sstevel@tonic-gate 	 * prsvaddr() must be called before prstep() because
30657c478bd9Sstevel@tonic-gate 	 * stepping can depend on the current value of the PC.
30667c478bd9Sstevel@tonic-gate 	 * We drop p_lock while touching the lwp's registers (on stack).
30677c478bd9Sstevel@tonic-gate 	 */
30687c478bd9Sstevel@tonic-gate 	if (flags & PRSVADDR) {
30697c478bd9Sstevel@tonic-gate 		mutex_exit(&p->p_lock);
30707c478bd9Sstevel@tonic-gate 		prsvaddr(lwp, prp->pr_vaddr);
30717c478bd9Sstevel@tonic-gate 		mutex_enter(&p->p_lock);
30727c478bd9Sstevel@tonic-gate 	}
30737c478bd9Sstevel@tonic-gate }
30747c478bd9Sstevel@tonic-gate 
30757c478bd9Sstevel@tonic-gate /*
30767c478bd9Sstevel@tonic-gate  * Common code for PIOCOPENM
30777c478bd9Sstevel@tonic-gate  * Returns with the process unlocked.
30787c478bd9Sstevel@tonic-gate  */
30797c478bd9Sstevel@tonic-gate static int
30807c478bd9Sstevel@tonic-gate propenm(prnode_t *pnp, caddr_t cmaddr, caddr_t va, int *rvalp, cred_t *cr)
30817c478bd9Sstevel@tonic-gate {
30827c478bd9Sstevel@tonic-gate 	proc_t *p = pnp->pr_common->prc_proc;
30837c478bd9Sstevel@tonic-gate 	struct as *as = p->p_as;
30847c478bd9Sstevel@tonic-gate 	int error = 0;
30857c478bd9Sstevel@tonic-gate 	struct seg *seg;
30867c478bd9Sstevel@tonic-gate 	struct vnode *xvp;
30877c478bd9Sstevel@tonic-gate 	int n;
30887c478bd9Sstevel@tonic-gate 
30897c478bd9Sstevel@tonic-gate 	/*
30907c478bd9Sstevel@tonic-gate 	 * By fiat, a system process has no address space.
30917c478bd9Sstevel@tonic-gate 	 */
30927c478bd9Sstevel@tonic-gate 	if ((p->p_flag & SSYS) || as == &kas) {
30937c478bd9Sstevel@tonic-gate 		error = EINVAL;
30947c478bd9Sstevel@tonic-gate 	} else if (cmaddr) {
30957c478bd9Sstevel@tonic-gate 		/*
30967c478bd9Sstevel@tonic-gate 		 * We drop p_lock before grabbing the address
30977c478bd9Sstevel@tonic-gate 		 * space lock in order to avoid a deadlock with
30987c478bd9Sstevel@tonic-gate 		 * the clock thread.  The process will not
30997c478bd9Sstevel@tonic-gate 		 * disappear and its address space will not
31007c478bd9Sstevel@tonic-gate 		 * change because it is marked P_PR_LOCK.
31017c478bd9Sstevel@tonic-gate 		 */
31027c478bd9Sstevel@tonic-gate 		mutex_exit(&p->p_lock);
31037c478bd9Sstevel@tonic-gate 		AS_LOCK_ENTER(as, &as->a_lock, RW_READER);
31047c478bd9Sstevel@tonic-gate 		seg = as_segat(as, va);
31057c478bd9Sstevel@tonic-gate 		if (seg != NULL &&
31067c478bd9Sstevel@tonic-gate 		    seg->s_ops == &segvn_ops &&
31077c478bd9Sstevel@tonic-gate 		    SEGOP_GETVP(seg, va, &xvp) == 0 &&
31087c478bd9Sstevel@tonic-gate 		    xvp != NULL &&
31097c478bd9Sstevel@tonic-gate 		    xvp->v_type == VREG) {
31107c478bd9Sstevel@tonic-gate 			VN_HOLD(xvp);
31117c478bd9Sstevel@tonic-gate 		} else {
31127c478bd9Sstevel@tonic-gate 			error = EINVAL;
31137c478bd9Sstevel@tonic-gate 		}
31147c478bd9Sstevel@tonic-gate 		AS_LOCK_EXIT(as, &as->a_lock);
31157c478bd9Sstevel@tonic-gate 		mutex_enter(&p->p_lock);
31167c478bd9Sstevel@tonic-gate 	} else if ((xvp = p->p_exec) == NULL) {
31177c478bd9Sstevel@tonic-gate 		error = EINVAL;
31187c478bd9Sstevel@tonic-gate 	} else {
31197c478bd9Sstevel@tonic-gate 		VN_HOLD(xvp);
31207c478bd9Sstevel@tonic-gate 	}
31217c478bd9Sstevel@tonic-gate 
31227c478bd9Sstevel@tonic-gate 	prunlock(pnp);
31237c478bd9Sstevel@tonic-gate 
31247c478bd9Sstevel@tonic-gate 	if (error == 0) {
31257c478bd9Sstevel@tonic-gate 		if ((error = VOP_ACCESS(xvp, VREAD, 0, cr)) == 0)
31267c478bd9Sstevel@tonic-gate 			error = fassign(&xvp, FREAD, &n);
31277c478bd9Sstevel@tonic-gate 		if (error) {
31287c478bd9Sstevel@tonic-gate 			VN_RELE(xvp);
31297c478bd9Sstevel@tonic-gate 		} else {
31307c478bd9Sstevel@tonic-gate 			*rvalp = n;
31317c478bd9Sstevel@tonic-gate 		}
31327c478bd9Sstevel@tonic-gate 	}
31337c478bd9Sstevel@tonic-gate 
31347c478bd9Sstevel@tonic-gate 	return (error);
31357c478bd9Sstevel@tonic-gate }
31367c478bd9Sstevel@tonic-gate 
31377c478bd9Sstevel@tonic-gate /*
31387c478bd9Sstevel@tonic-gate  * Return old version of process/lwp status.
31397c478bd9Sstevel@tonic-gate  * The u-block is mapped in by this routine and unmapped at the end.
31407c478bd9Sstevel@tonic-gate  */
31417c478bd9Sstevel@tonic-gate void
31427c478bd9Sstevel@tonic-gate oprgetstatus(kthread_t *t, prstatus_t *sp, zone_t *zp)
31437c478bd9Sstevel@tonic-gate {
31447c478bd9Sstevel@tonic-gate 	proc_t *p = ttoproc(t);
31457c478bd9Sstevel@tonic-gate 	klwp_t *lwp = ttolwp(t);
31467c478bd9Sstevel@tonic-gate 	int flags;
31477c478bd9Sstevel@tonic-gate 	user_t *up;
31487c478bd9Sstevel@tonic-gate 	ulong_t instr;
31497c478bd9Sstevel@tonic-gate 
31507c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&p->p_lock));
31517c478bd9Sstevel@tonic-gate 
31527c478bd9Sstevel@tonic-gate 	up = PTOU(p);
31537c478bd9Sstevel@tonic-gate 	bzero(sp, sizeof (*sp));
31547c478bd9Sstevel@tonic-gate 	flags = 0;
31557c478bd9Sstevel@tonic-gate 	if (t->t_state == TS_STOPPED) {
31567c478bd9Sstevel@tonic-gate 		flags |= PR_STOPPED;
31577c478bd9Sstevel@tonic-gate 		if ((t->t_schedflag & TS_PSTART) == 0)
31587c478bd9Sstevel@tonic-gate 			flags |= PR_ISTOP;
31597c478bd9Sstevel@tonic-gate 	} else if (VSTOPPED(t)) {
31607c478bd9Sstevel@tonic-gate 		flags |= PR_STOPPED|PR_ISTOP;
31617c478bd9Sstevel@tonic-gate 	}
31627c478bd9Sstevel@tonic-gate 	if (!(flags & PR_ISTOP) && (t->t_proc_flag & TP_PRSTOP))
31637c478bd9Sstevel@tonic-gate 		flags |= PR_DSTOP;
31647c478bd9Sstevel@tonic-gate 	if (lwp->lwp_asleep)
31657c478bd9Sstevel@tonic-gate 		flags |= PR_ASLEEP;
31667c478bd9Sstevel@tonic-gate 	if (p->p_proc_flag & P_PR_FORK)
31677c478bd9Sstevel@tonic-gate 		flags |= PR_FORK;
31687c478bd9Sstevel@tonic-gate 	if (p->p_proc_flag & P_PR_RUNLCL)
31697c478bd9Sstevel@tonic-gate 		flags |= PR_RLC;
31707c478bd9Sstevel@tonic-gate 	if (p->p_proc_flag & P_PR_KILLCL)
31717c478bd9Sstevel@tonic-gate 		flags |= PR_KLC;
31727c478bd9Sstevel@tonic-gate 	if (p->p_proc_flag & P_PR_ASYNC)
31737c478bd9Sstevel@tonic-gate 		flags |= PR_ASYNC;
31747c478bd9Sstevel@tonic-gate 	if (p->p_proc_flag & P_PR_BPTADJ)
31757c478bd9Sstevel@tonic-gate 		flags |= PR_BPTADJ;
31767c478bd9Sstevel@tonic-gate 	if (p->p_proc_flag & P_PR_PTRACE)
31777c478bd9Sstevel@tonic-gate 		flags |= PR_PCOMPAT;
31787c478bd9Sstevel@tonic-gate 	if (t->t_proc_flag & TP_MSACCT)
31797c478bd9Sstevel@tonic-gate 		flags |= PR_MSACCT;
31807c478bd9Sstevel@tonic-gate 	sp->pr_flags = flags;
31817c478bd9Sstevel@tonic-gate 	if (VSTOPPED(t)) {
31827c478bd9Sstevel@tonic-gate 		sp->pr_why   = PR_REQUESTED;
31837c478bd9Sstevel@tonic-gate 		sp->pr_what  = 0;
31847c478bd9Sstevel@tonic-gate 	} else {
31857c478bd9Sstevel@tonic-gate 		sp->pr_why   = t->t_whystop;
31867c478bd9Sstevel@tonic-gate 		sp->pr_what  = t->t_whatstop;
31877c478bd9Sstevel@tonic-gate 	}
31887c478bd9Sstevel@tonic-gate 
31897c478bd9Sstevel@tonic-gate 	if (t->t_whystop == PR_FAULTED)
31907c478bd9Sstevel@tonic-gate 		bcopy(&lwp->lwp_siginfo,
31917c478bd9Sstevel@tonic-gate 		    &sp->pr_info, sizeof (k_siginfo_t));
31927c478bd9Sstevel@tonic-gate 	else if (lwp->lwp_curinfo)
31937c478bd9Sstevel@tonic-gate 		bcopy(&lwp->lwp_curinfo->sq_info,
31947c478bd9Sstevel@tonic-gate 		    &sp->pr_info, sizeof (k_siginfo_t));
31957c478bd9Sstevel@tonic-gate 
31967c478bd9Sstevel@tonic-gate 	if (SI_FROMUSER(&lwp->lwp_siginfo) && zp->zone_id != GLOBAL_ZONEID &&
31977c478bd9Sstevel@tonic-gate 	    sp->pr_info.si_zoneid != zp->zone_id) {
31987c478bd9Sstevel@tonic-gate 		sp->pr_info.si_pid = zp->zone_zsched->p_pid;
31997c478bd9Sstevel@tonic-gate 		sp->pr_info.si_uid = 0;
32007c478bd9Sstevel@tonic-gate 		sp->pr_info.si_ctid = -1;
32017c478bd9Sstevel@tonic-gate 		sp->pr_info.si_zoneid = zp->zone_id;
32027c478bd9Sstevel@tonic-gate 	}
32037c478bd9Sstevel@tonic-gate 
32047c478bd9Sstevel@tonic-gate 	sp->pr_cursig  = lwp->lwp_cursig;
32057c478bd9Sstevel@tonic-gate 	prassignset(&sp->pr_sigpend, &p->p_sig);
32067c478bd9Sstevel@tonic-gate 	prassignset(&sp->pr_lwppend, &t->t_sig);
32077c478bd9Sstevel@tonic-gate 	schedctl_finish_sigblock(t);
32087c478bd9Sstevel@tonic-gate 	prassignset(&sp->pr_sighold, &t->t_hold);
32097c478bd9Sstevel@tonic-gate 	sp->pr_altstack = lwp->lwp_sigaltstack;
32107c478bd9Sstevel@tonic-gate 	prgetaction(p, up, lwp->lwp_cursig, &sp->pr_action);
32117c478bd9Sstevel@tonic-gate 	sp->pr_pid   = p->p_pid;
32127c478bd9Sstevel@tonic-gate 	if (curproc->p_zone->zone_id != GLOBAL_ZONEID &&
32137c478bd9Sstevel@tonic-gate 	    (p->p_flag & SZONETOP)) {
32147c478bd9Sstevel@tonic-gate 		ASSERT(p->p_zone->zone_id != GLOBAL_ZONEID);
32157c478bd9Sstevel@tonic-gate 		/*
32167c478bd9Sstevel@tonic-gate 		 * Inside local zones, fake zsched's pid as parent pids for
32177c478bd9Sstevel@tonic-gate 		 * processes which reference processes outside of the zone.
32187c478bd9Sstevel@tonic-gate 		 */
32197c478bd9Sstevel@tonic-gate 		sp->pr_ppid = curproc->p_zone->zone_zsched->p_pid;
32207c478bd9Sstevel@tonic-gate 	} else {
32217c478bd9Sstevel@tonic-gate 		sp->pr_ppid = p->p_ppid;
32227c478bd9Sstevel@tonic-gate 	}
32237c478bd9Sstevel@tonic-gate 	sp->pr_pgrp  = p->p_pgrp;
32247c478bd9Sstevel@tonic-gate 	sp->pr_sid   = p->p_sessp->s_sid;
32257c478bd9Sstevel@tonic-gate 	hrt2ts(mstate_aggr_state(p, LMS_USER), &sp->pr_utime);
32267c478bd9Sstevel@tonic-gate 	hrt2ts(mstate_aggr_state(p, LMS_SYSTEM), &sp->pr_stime);
32277c478bd9Sstevel@tonic-gate 	TICK_TO_TIMESTRUC(p->p_cutime, &sp->pr_cutime);
32287c478bd9Sstevel@tonic-gate 	TICK_TO_TIMESTRUC(p->p_cstime, &sp->pr_cstime);
32297c478bd9Sstevel@tonic-gate 	(void) strncpy(sp->pr_clname, sclass[t->t_cid].cl_name,
32307c478bd9Sstevel@tonic-gate 		sizeof (sp->pr_clname) - 1);
32317c478bd9Sstevel@tonic-gate 	sp->pr_who = t->t_tid;
32327c478bd9Sstevel@tonic-gate 	sp->pr_nlwp = p->p_lwpcnt;
32337c478bd9Sstevel@tonic-gate 	sp->pr_brkbase = p->p_brkbase;
32347c478bd9Sstevel@tonic-gate 	sp->pr_brksize = p->p_brksize;
32357c478bd9Sstevel@tonic-gate 	sp->pr_stkbase = prgetstackbase(p);
32367c478bd9Sstevel@tonic-gate 	sp->pr_stksize = p->p_stksize;
32377c478bd9Sstevel@tonic-gate 	sp->pr_oldcontext = (struct ucontext *)lwp->lwp_oldcontext;
32387c478bd9Sstevel@tonic-gate 	sp->pr_processor = t->t_cpu->cpu_id;
32397c478bd9Sstevel@tonic-gate 	sp->pr_bind = t->t_bind_cpu;
32407c478bd9Sstevel@tonic-gate 
32417c478bd9Sstevel@tonic-gate 	/*
32427c478bd9Sstevel@tonic-gate 	 * Fetch the current instruction, if not a system process.
32437c478bd9Sstevel@tonic-gate 	 * We don't attempt this unless the lwp is stopped.
32447c478bd9Sstevel@tonic-gate 	 */
32457c478bd9Sstevel@tonic-gate 	if ((p->p_flag & SSYS) || p->p_as == &kas)
32467c478bd9Sstevel@tonic-gate 		sp->pr_flags |= (PR_ISSYS|PR_PCINVAL);
32477c478bd9Sstevel@tonic-gate 	else if (!(flags & PR_STOPPED))
32487c478bd9Sstevel@tonic-gate 		sp->pr_flags |= PR_PCINVAL;
32497c478bd9Sstevel@tonic-gate 	else if (!prfetchinstr(lwp, &instr))
32507c478bd9Sstevel@tonic-gate 		sp->pr_flags |= PR_PCINVAL;
32517c478bd9Sstevel@tonic-gate 	else
32527c478bd9Sstevel@tonic-gate 		sp->pr_instr = instr;
32537c478bd9Sstevel@tonic-gate 
32547c478bd9Sstevel@tonic-gate 	/*
32557c478bd9Sstevel@tonic-gate 	 * Drop p_lock while touching the lwp's stack.
32567c478bd9Sstevel@tonic-gate 	 */
32577c478bd9Sstevel@tonic-gate 	mutex_exit(&p->p_lock);
32587c478bd9Sstevel@tonic-gate 	if (prisstep(lwp))
32597c478bd9Sstevel@tonic-gate 		sp->pr_flags |= PR_STEP;
32607c478bd9Sstevel@tonic-gate 	if ((flags & (PR_STOPPED|PR_ASLEEP)) && t->t_sysnum) {
32617c478bd9Sstevel@tonic-gate 		int i;
32627c478bd9Sstevel@tonic-gate 		auxv_t *auxp;
32637c478bd9Sstevel@tonic-gate 
32647c478bd9Sstevel@tonic-gate 		sp->pr_syscall = get_syscall_args(lwp,
32657c478bd9Sstevel@tonic-gate 			(long *)sp->pr_sysarg, &i);
32667c478bd9Sstevel@tonic-gate 		sp->pr_nsysarg = (short)i;
32677c478bd9Sstevel@tonic-gate 		if (t->t_whystop == PR_SYSEXIT &&
32687c478bd9Sstevel@tonic-gate 		    (t->t_sysnum == SYS_exec || t->t_sysnum == SYS_execve)) {
32697c478bd9Sstevel@tonic-gate 			sp->pr_sysarg[0] = 0;
32707c478bd9Sstevel@tonic-gate 			sp->pr_sysarg[1] = (uintptr_t)up->u_argv;
32717c478bd9Sstevel@tonic-gate 			sp->pr_sysarg[2] = (uintptr_t)up->u_envp;
32727c478bd9Sstevel@tonic-gate 			for (i = 0, auxp = up->u_auxv;
32737c478bd9Sstevel@tonic-gate 			    i < sizeof (up->u_auxv) / sizeof (up->u_auxv[0]);
32747c478bd9Sstevel@tonic-gate 			    i++, auxp++) {
32757c478bd9Sstevel@tonic-gate 				if (auxp->a_type == AT_SUN_EXECNAME) {
32767c478bd9Sstevel@tonic-gate 					sp->pr_sysarg[0] =
32777c478bd9Sstevel@tonic-gate 						(uintptr_t)auxp->a_un.a_ptr;
32787c478bd9Sstevel@tonic-gate 					break;
32797c478bd9Sstevel@tonic-gate 				}
32807c478bd9Sstevel@tonic-gate 			}
32817c478bd9Sstevel@tonic-gate 		}
32827c478bd9Sstevel@tonic-gate 	}
32837c478bd9Sstevel@tonic-gate 	if ((flags & PR_STOPPED) || t == curthread)
32847c478bd9Sstevel@tonic-gate 		prgetprregs(lwp, sp->pr_reg);
32857c478bd9Sstevel@tonic-gate 	mutex_enter(&p->p_lock);
32867c478bd9Sstevel@tonic-gate }
32877c478bd9Sstevel@tonic-gate 
32887c478bd9Sstevel@tonic-gate /*
32897c478bd9Sstevel@tonic-gate  * Return old version of information used by ps(1).
32907c478bd9Sstevel@tonic-gate  */
32917c478bd9Sstevel@tonic-gate void
32927c478bd9Sstevel@tonic-gate oprgetpsinfo(proc_t *p, prpsinfo_t *psp, kthread_t *tp)
32937c478bd9Sstevel@tonic-gate {
32947c478bd9Sstevel@tonic-gate 	kthread_t *t;
32957c478bd9Sstevel@tonic-gate 	char c, state;
32967c478bd9Sstevel@tonic-gate 	user_t *up;
32977c478bd9Sstevel@tonic-gate 	dev_t d;
32987c478bd9Sstevel@tonic-gate 	uint64_t pct;
32997c478bd9Sstevel@tonic-gate 	int retval, niceval;
33007c478bd9Sstevel@tonic-gate 	cred_t *cred;
33017c478bd9Sstevel@tonic-gate 	struct as *as;
33027c478bd9Sstevel@tonic-gate 	hrtime_t hrutime, hrstime, cur_time;
33037c478bd9Sstevel@tonic-gate 
33047c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&p->p_lock));
33057c478bd9Sstevel@tonic-gate 
33067c478bd9Sstevel@tonic-gate 	bzero(psp, sizeof (*psp));
33077c478bd9Sstevel@tonic-gate 
33087c478bd9Sstevel@tonic-gate 	if ((t = tp) == NULL)
33097c478bd9Sstevel@tonic-gate 		t = prchoose(p);	/* returns locked thread */
33107c478bd9Sstevel@tonic-gate 	else
33117c478bd9Sstevel@tonic-gate 		thread_lock(t);
33127c478bd9Sstevel@tonic-gate 
33137c478bd9Sstevel@tonic-gate 	/* kludge: map thread state enum into process state enum */
33147c478bd9Sstevel@tonic-gate 
33157c478bd9Sstevel@tonic-gate 	if (t == NULL) {
33167c478bd9Sstevel@tonic-gate 		state = TS_ZOMB;
33177c478bd9Sstevel@tonic-gate 	} else {
33187c478bd9Sstevel@tonic-gate 		state = VSTOPPED(t) ? TS_STOPPED : t->t_state;
33197c478bd9Sstevel@tonic-gate 		thread_unlock(t);
33207c478bd9Sstevel@tonic-gate 	}
33217c478bd9Sstevel@tonic-gate 
33227c478bd9Sstevel@tonic-gate 	switch (state) {
33237c478bd9Sstevel@tonic-gate 	case TS_SLEEP:		state = SSLEEP;		break;
33247c478bd9Sstevel@tonic-gate 	case TS_RUN:		state = SRUN;		break;
33257c478bd9Sstevel@tonic-gate 	case TS_ONPROC:		state = SONPROC;	break;
33267c478bd9Sstevel@tonic-gate 	case TS_ZOMB:		state = SZOMB;		break;
33277c478bd9Sstevel@tonic-gate 	case TS_STOPPED:	state = SSTOP;		break;
33287c478bd9Sstevel@tonic-gate 	default:		state = 0;		break;
33297c478bd9Sstevel@tonic-gate 	}
33307c478bd9Sstevel@tonic-gate 	switch (state) {
33317c478bd9Sstevel@tonic-gate 	case SSLEEP:	c = 'S';	break;
33327c478bd9Sstevel@tonic-gate 	case SRUN:	c = 'R';	break;
33337c478bd9Sstevel@tonic-gate 	case SZOMB:	c = 'Z';	break;
33347c478bd9Sstevel@tonic-gate 	case SSTOP:	c = 'T';	break;
33357c478bd9Sstevel@tonic-gate 	case SIDL:	c = 'I';	break;
33367c478bd9Sstevel@tonic-gate 	case SONPROC:	c = 'O';	break;
33377c478bd9Sstevel@tonic-gate #ifdef SXBRK
33387c478bd9Sstevel@tonic-gate 	case SXBRK:	c = 'X';	break;
33397c478bd9Sstevel@tonic-gate #endif
33407c478bd9Sstevel@tonic-gate 	default:	c = '?';	break;
33417c478bd9Sstevel@tonic-gate 	}
33427c478bd9Sstevel@tonic-gate 	psp->pr_state = state;
33437c478bd9Sstevel@tonic-gate 	psp->pr_sname = c;
33447c478bd9Sstevel@tonic-gate 	psp->pr_zomb = (state == SZOMB);
33457c478bd9Sstevel@tonic-gate 	/*
33467c478bd9Sstevel@tonic-gate 	 * only export SSYS and SMSACCT; everything else is off-limits to
33477c478bd9Sstevel@tonic-gate 	 * userland apps.
33487c478bd9Sstevel@tonic-gate 	 */
33497c478bd9Sstevel@tonic-gate 	psp->pr_flag = p->p_flag & (SSYS | SMSACCT);
33507c478bd9Sstevel@tonic-gate 
33517c478bd9Sstevel@tonic-gate 	mutex_enter(&p->p_crlock);
33527c478bd9Sstevel@tonic-gate 	cred = p->p_cred;
33537c478bd9Sstevel@tonic-gate 	psp->pr_uid = crgetruid(cred);
33547c478bd9Sstevel@tonic-gate 	psp->pr_gid = crgetrgid(cred);
33557c478bd9Sstevel@tonic-gate 	psp->pr_euid = crgetuid(cred);
33567c478bd9Sstevel@tonic-gate 	psp->pr_egid = crgetgid(cred);
33577c478bd9Sstevel@tonic-gate 	mutex_exit(&p->p_crlock);
33587c478bd9Sstevel@tonic-gate 
33597c478bd9Sstevel@tonic-gate 	psp->pr_pid = p->p_pid;
33607c478bd9Sstevel@tonic-gate 	if (curproc->p_zone->zone_id != GLOBAL_ZONEID &&
33617c478bd9Sstevel@tonic-gate 	    (p->p_flag & SZONETOP)) {
33627c478bd9Sstevel@tonic-gate 		ASSERT(p->p_zone->zone_id != GLOBAL_ZONEID);
33637c478bd9Sstevel@tonic-gate 		/*
33647c478bd9Sstevel@tonic-gate 		 * Inside local zones, fake zsched's pid as parent pids for
33657c478bd9Sstevel@tonic-gate 		 * processes which reference processes outside of the zone.
33667c478bd9Sstevel@tonic-gate 		 */
33677c478bd9Sstevel@tonic-gate 		psp->pr_ppid = curproc->p_zone->zone_zsched->p_pid;
33687c478bd9Sstevel@tonic-gate 	} else {
33697c478bd9Sstevel@tonic-gate 		psp->pr_ppid = p->p_ppid;
33707c478bd9Sstevel@tonic-gate 	}
33717c478bd9Sstevel@tonic-gate 	psp->pr_pgrp = p->p_pgrp;
33727c478bd9Sstevel@tonic-gate 	psp->pr_sid = p->p_sessp->s_sid;
33737c478bd9Sstevel@tonic-gate 	psp->pr_addr = prgetpsaddr(p);
33747c478bd9Sstevel@tonic-gate 	hrutime = mstate_aggr_state(p, LMS_USER);
33757c478bd9Sstevel@tonic-gate 	hrstime = mstate_aggr_state(p, LMS_SYSTEM);
33767c478bd9Sstevel@tonic-gate 	hrt2ts(hrutime + hrstime, &psp->pr_time);
33777c478bd9Sstevel@tonic-gate 	TICK_TO_TIMESTRUC(p->p_cutime + p->p_cstime, &psp->pr_ctime);
33787c478bd9Sstevel@tonic-gate 	switch (p->p_model) {
33797c478bd9Sstevel@tonic-gate 	case DATAMODEL_ILP32:
33807c478bd9Sstevel@tonic-gate 		psp->pr_dmodel = PR_MODEL_ILP32;
33817c478bd9Sstevel@tonic-gate 		break;
33827c478bd9Sstevel@tonic-gate 	case DATAMODEL_LP64:
33837c478bd9Sstevel@tonic-gate 		psp->pr_dmodel = PR_MODEL_LP64;
33847c478bd9Sstevel@tonic-gate 		break;
33857c478bd9Sstevel@tonic-gate 	}
33867c478bd9Sstevel@tonic-gate 	if (state == SZOMB || t == NULL) {
33877c478bd9Sstevel@tonic-gate 		int wcode = p->p_wcode;		/* must be atomic read */
33887c478bd9Sstevel@tonic-gate 
33897c478bd9Sstevel@tonic-gate 		if (wcode)
33907c478bd9Sstevel@tonic-gate 			psp->pr_wstat = wstat(wcode, p->p_wdata);
33917c478bd9Sstevel@tonic-gate 		psp->pr_lttydev = PRNODEV;
33927c478bd9Sstevel@tonic-gate 		psp->pr_ottydev = (o_dev_t)PRNODEV;
33937c478bd9Sstevel@tonic-gate 		psp->pr_size = 0;
33947c478bd9Sstevel@tonic-gate 		psp->pr_rssize = 0;
33957c478bd9Sstevel@tonic-gate 		psp->pr_pctmem = 0;
33967c478bd9Sstevel@tonic-gate 	} else {
33977c478bd9Sstevel@tonic-gate 		up = PTOU(p);
33987c478bd9Sstevel@tonic-gate 		psp->pr_wchan = t->t_wchan;
33997c478bd9Sstevel@tonic-gate 		psp->pr_pri = t->t_pri;
34007c478bd9Sstevel@tonic-gate 		(void) strncpy(psp->pr_clname, sclass[t->t_cid].cl_name,
34017c478bd9Sstevel@tonic-gate 			sizeof (psp->pr_clname) - 1);
34027c478bd9Sstevel@tonic-gate 		retval = CL_DONICE(t, NULL, 0, &niceval);
34037c478bd9Sstevel@tonic-gate 		if (retval == 0) {
34047c478bd9Sstevel@tonic-gate 			psp->pr_oldpri = v.v_maxsyspri - psp->pr_pri;
34057c478bd9Sstevel@tonic-gate 			psp->pr_nice = niceval + NZERO;
34067c478bd9Sstevel@tonic-gate 		} else {
34077c478bd9Sstevel@tonic-gate 			psp->pr_oldpri = 0;
34087c478bd9Sstevel@tonic-gate 			psp->pr_nice = 0;
34097c478bd9Sstevel@tonic-gate 		}
34107c478bd9Sstevel@tonic-gate 		d = cttydev(p);
34117c478bd9Sstevel@tonic-gate #ifdef sun
34127c478bd9Sstevel@tonic-gate 		{
34137c478bd9Sstevel@tonic-gate 			extern dev_t rwsconsdev, rconsdev, uconsdev;
34147c478bd9Sstevel@tonic-gate 			/*
34157c478bd9Sstevel@tonic-gate 			 * If the controlling terminal is the real
34167c478bd9Sstevel@tonic-gate 			 * or workstation console device, map to what the
34177c478bd9Sstevel@tonic-gate 			 * user thinks is the console device.
34187c478bd9Sstevel@tonic-gate 			 */
34197c478bd9Sstevel@tonic-gate 			if (d == rwsconsdev || d == rconsdev)
34207c478bd9Sstevel@tonic-gate 				d = uconsdev;
34217c478bd9Sstevel@tonic-gate 		}
34227c478bd9Sstevel@tonic-gate #endif
34237c478bd9Sstevel@tonic-gate 		psp->pr_lttydev = (d == NODEV) ? PRNODEV : d;
34247c478bd9Sstevel@tonic-gate 		psp->pr_ottydev = cmpdev(d);
34257c478bd9Sstevel@tonic-gate 		psp->pr_start = up->u_start;
34267c478bd9Sstevel@tonic-gate 		bcopy(up->u_comm, psp->pr_fname,
34277c478bd9Sstevel@tonic-gate 		    MIN(sizeof (up->u_comm), sizeof (psp->pr_fname)-1));
34287c478bd9Sstevel@tonic-gate 		bcopy(up->u_psargs, psp->pr_psargs,
34297c478bd9Sstevel@tonic-gate 		    MIN(PRARGSZ-1, PSARGSZ));
34307c478bd9Sstevel@tonic-gate 		psp->pr_syscall = t->t_sysnum;
34317c478bd9Sstevel@tonic-gate 		psp->pr_argc = up->u_argc;
34327c478bd9Sstevel@tonic-gate 		psp->pr_argv = (char **)up->u_argv;
34337c478bd9Sstevel@tonic-gate 		psp->pr_envp = (char **)up->u_envp;
34347c478bd9Sstevel@tonic-gate 
34357c478bd9Sstevel@tonic-gate 		/* compute %cpu for the lwp or process */
34367c478bd9Sstevel@tonic-gate 		pct = 0;
34377c478bd9Sstevel@tonic-gate 		if ((t = tp) == NULL)
34387c478bd9Sstevel@tonic-gate 			t = p->p_tlist;
34397c478bd9Sstevel@tonic-gate 		cur_time = gethrtime_unscaled();
34407c478bd9Sstevel@tonic-gate 		do {
34417c478bd9Sstevel@tonic-gate 			pct += cpu_update_pct(t, cur_time);
34427c478bd9Sstevel@tonic-gate 			if (tp != NULL)		/* just do the one lwp */
34437c478bd9Sstevel@tonic-gate 				break;
34447c478bd9Sstevel@tonic-gate 		} while ((t = t->t_forw) != p->p_tlist);
34457c478bd9Sstevel@tonic-gate 
34467c478bd9Sstevel@tonic-gate 		psp->pr_pctcpu = prgetpctcpu(pct);
34477c478bd9Sstevel@tonic-gate 		psp->pr_cpu = (psp->pr_pctcpu*100 + 0x6000) >> 15; /* [0..99] */
34487c478bd9Sstevel@tonic-gate 		if (psp->pr_cpu > 99)
34497c478bd9Sstevel@tonic-gate 			psp->pr_cpu = 99;
34507c478bd9Sstevel@tonic-gate 
34517c478bd9Sstevel@tonic-gate 		if ((p->p_flag & SSYS) || (as = p->p_as) == &kas) {
34527c478bd9Sstevel@tonic-gate 			psp->pr_size = 0;
34537c478bd9Sstevel@tonic-gate 			psp->pr_rssize = 0;
34547c478bd9Sstevel@tonic-gate 			psp->pr_pctmem = 0;
34557c478bd9Sstevel@tonic-gate 		} else {
34567c478bd9Sstevel@tonic-gate 			mutex_exit(&p->p_lock);
34577c478bd9Sstevel@tonic-gate 			AS_LOCK_ENTER(as, &as->a_lock, RW_READER);
34587c478bd9Sstevel@tonic-gate 			psp->pr_size = btopr(rm_assize(as));
34597c478bd9Sstevel@tonic-gate 			psp->pr_rssize = rm_asrss(as);
34607c478bd9Sstevel@tonic-gate 			psp->pr_pctmem = rm_pctmemory(as);
34617c478bd9Sstevel@tonic-gate 			AS_LOCK_EXIT(as, &as->a_lock);
34627c478bd9Sstevel@tonic-gate 			mutex_enter(&p->p_lock);
34637c478bd9Sstevel@tonic-gate 		}
34647c478bd9Sstevel@tonic-gate 	}
34657c478bd9Sstevel@tonic-gate 	psp->pr_bysize = ptob(psp->pr_size);
34667c478bd9Sstevel@tonic-gate 	psp->pr_byrssize = ptob(psp->pr_rssize);
34677c478bd9Sstevel@tonic-gate }
34687c478bd9Sstevel@tonic-gate 
34697c478bd9Sstevel@tonic-gate /*
34707c478bd9Sstevel@tonic-gate  * Return an array of structures with memory map information.
34717c478bd9Sstevel@tonic-gate  * In addition to the "real" segments we need space for the
34727c478bd9Sstevel@tonic-gate  * zero-filled entry that terminates the list.
34737c478bd9Sstevel@tonic-gate  * We allocate here; the caller must deallocate.
34747c478bd9Sstevel@tonic-gate  */
34757c478bd9Sstevel@tonic-gate #define	MAPSIZE	8192
34767c478bd9Sstevel@tonic-gate static int
34777c478bd9Sstevel@tonic-gate oprgetmap(proc_t *p, prmap_t **prmapp, size_t *sizep)
34787c478bd9Sstevel@tonic-gate {
34797c478bd9Sstevel@tonic-gate 	struct as *as = p->p_as;
34807c478bd9Sstevel@tonic-gate 	int nmaps = 0;
34817c478bd9Sstevel@tonic-gate 	prmap_t *mp;
34827c478bd9Sstevel@tonic-gate 	size_t size;
34837c478bd9Sstevel@tonic-gate 	struct seg *seg;
34847c478bd9Sstevel@tonic-gate 	struct seg *brkseg, *stkseg;
34857c478bd9Sstevel@tonic-gate 	uint_t prot;
34867c478bd9Sstevel@tonic-gate 
34877c478bd9Sstevel@tonic-gate 	ASSERT(as != &kas && AS_WRITE_HELD(as, &as->a_lock));
34887c478bd9Sstevel@tonic-gate 
34897c478bd9Sstevel@tonic-gate 	/* initial allocation */
34907c478bd9Sstevel@tonic-gate 	*sizep = size = MAPSIZE;
34917c478bd9Sstevel@tonic-gate 	*prmapp = mp = kmem_alloc(MAPSIZE, KM_SLEEP);
34927c478bd9Sstevel@tonic-gate 
34937c478bd9Sstevel@tonic-gate 	if ((seg = AS_SEGFIRST(as)) == NULL) {
34947c478bd9Sstevel@tonic-gate 		bzero(mp, sizeof (*mp));
34957c478bd9Sstevel@tonic-gate 		return (1);
34967c478bd9Sstevel@tonic-gate 	}
34977c478bd9Sstevel@tonic-gate 
34987c478bd9Sstevel@tonic-gate 	brkseg = break_seg(p);
34997c478bd9Sstevel@tonic-gate 	stkseg = as_segat(as, prgetstackbase(p));
35007c478bd9Sstevel@tonic-gate 
35017c478bd9Sstevel@tonic-gate 	do {
35027c478bd9Sstevel@tonic-gate 		caddr_t eaddr = seg->s_base + pr_getsegsize(seg, 0);
35037c478bd9Sstevel@tonic-gate 		caddr_t saddr, naddr;
35047c478bd9Sstevel@tonic-gate 		void *tmp = NULL;
35057c478bd9Sstevel@tonic-gate 
35067c478bd9Sstevel@tonic-gate 		for (saddr = seg->s_base; saddr < eaddr; saddr = naddr) {
35077c478bd9Sstevel@tonic-gate 			prot = pr_getprot(seg, 0, &tmp, &saddr, &naddr, eaddr);
35087c478bd9Sstevel@tonic-gate 			if (saddr == naddr)
35097c478bd9Sstevel@tonic-gate 				continue;
35107c478bd9Sstevel@tonic-gate 			/* reallocate if necessary */
35117c478bd9Sstevel@tonic-gate 			if ((nmaps + 2) * sizeof (prmap_t) > size) {
35127c478bd9Sstevel@tonic-gate 				size_t newsize = size + MAPSIZE;
35137c478bd9Sstevel@tonic-gate 				prmap_t *newmp = kmem_alloc(newsize, KM_SLEEP);
35147c478bd9Sstevel@tonic-gate 
35157c478bd9Sstevel@tonic-gate 				bcopy(*prmapp, newmp, nmaps * sizeof (prmap_t));
35167c478bd9Sstevel@tonic-gate 				kmem_free(*prmapp, size);
35177c478bd9Sstevel@tonic-gate 				*sizep = size = newsize;
35187c478bd9Sstevel@tonic-gate 				*prmapp = newmp;
35197c478bd9Sstevel@tonic-gate 				mp = newmp + nmaps;
35207c478bd9Sstevel@tonic-gate 			}
35217c478bd9Sstevel@tonic-gate 			bzero(mp, sizeof (*mp));
35227c478bd9Sstevel@tonic-gate 			mp->pr_vaddr = saddr;
35237c478bd9Sstevel@tonic-gate 			mp->pr_size = naddr - saddr;
35247c478bd9Sstevel@tonic-gate 			mp->pr_off = SEGOP_GETOFFSET(seg, saddr);
35257c478bd9Sstevel@tonic-gate 			mp->pr_mflags = 0;
35267c478bd9Sstevel@tonic-gate 			if (prot & PROT_READ)
35277c478bd9Sstevel@tonic-gate 				mp->pr_mflags |= MA_READ;
35287c478bd9Sstevel@tonic-gate 			if (prot & PROT_WRITE)
35297c478bd9Sstevel@tonic-gate 				mp->pr_mflags |= MA_WRITE;
35307c478bd9Sstevel@tonic-gate 			if (prot & PROT_EXEC)
35317c478bd9Sstevel@tonic-gate 				mp->pr_mflags |= MA_EXEC;
35327c478bd9Sstevel@tonic-gate 			if (SEGOP_GETTYPE(seg, saddr) & MAP_SHARED)
35337c478bd9Sstevel@tonic-gate 				mp->pr_mflags |= MA_SHARED;
35347c478bd9Sstevel@tonic-gate 			if (seg == brkseg)
35357c478bd9Sstevel@tonic-gate 				mp->pr_mflags |= MA_BREAK;
35367c478bd9Sstevel@tonic-gate 			else if (seg == stkseg)
35377c478bd9Sstevel@tonic-gate 				mp->pr_mflags |= MA_STACK;
35387c478bd9Sstevel@tonic-gate 			mp->pr_pagesize = PAGESIZE;
35397c478bd9Sstevel@tonic-gate 			mp++;
35407c478bd9Sstevel@tonic-gate 			nmaps++;
35417c478bd9Sstevel@tonic-gate 		}
35427c478bd9Sstevel@tonic-gate 		ASSERT(tmp == NULL);
35437c478bd9Sstevel@tonic-gate 	} while ((seg = AS_SEGNEXT(as, seg)) != NULL);
35447c478bd9Sstevel@tonic-gate 
35457c478bd9Sstevel@tonic-gate 	bzero(mp, sizeof (*mp));
35467c478bd9Sstevel@tonic-gate 	return (nmaps + 1);
35477c478bd9Sstevel@tonic-gate }
35487c478bd9Sstevel@tonic-gate 
35497c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
35507c478bd9Sstevel@tonic-gate static int
35517c478bd9Sstevel@tonic-gate oprgetmap32(proc_t *p, ioc_prmap32_t **prmapp, size_t *sizep)
35527c478bd9Sstevel@tonic-gate {
35537c478bd9Sstevel@tonic-gate 	struct as *as = p->p_as;
35547c478bd9Sstevel@tonic-gate 	int nmaps = 0;
35557c478bd9Sstevel@tonic-gate 	ioc_prmap32_t *mp;
35567c478bd9Sstevel@tonic-gate 	size_t size;
35577c478bd9Sstevel@tonic-gate 	struct seg *seg;
35587c478bd9Sstevel@tonic-gate 	struct seg *brkseg, *stkseg;
35597c478bd9Sstevel@tonic-gate 	uint_t prot;
35607c478bd9Sstevel@tonic-gate 
35617c478bd9Sstevel@tonic-gate 	ASSERT(as != &kas && AS_WRITE_HELD(as, &as->a_lock));
35627c478bd9Sstevel@tonic-gate 
35637c478bd9Sstevel@tonic-gate 	/* initial allocation */
35647c478bd9Sstevel@tonic-gate 	*sizep = size = MAPSIZE;
35657c478bd9Sstevel@tonic-gate 	*prmapp = mp = kmem_alloc(MAPSIZE, KM_SLEEP);
35667c478bd9Sstevel@tonic-gate 
35677c478bd9Sstevel@tonic-gate 	if ((seg = AS_SEGFIRST(as)) == NULL) {
35687c478bd9Sstevel@tonic-gate 		bzero(mp, sizeof (*mp));
35697c478bd9Sstevel@tonic-gate 		return (1);
35707c478bd9Sstevel@tonic-gate 	}
35717c478bd9Sstevel@tonic-gate 
35727c478bd9Sstevel@tonic-gate 	brkseg = break_seg(p);
35737c478bd9Sstevel@tonic-gate 	stkseg = as_segat(as, prgetstackbase(p));
35747c478bd9Sstevel@tonic-gate 
35757c478bd9Sstevel@tonic-gate 	do {
35767c478bd9Sstevel@tonic-gate 		caddr_t eaddr = seg->s_base + pr_getsegsize(seg, 0);
35777c478bd9Sstevel@tonic-gate 		caddr_t saddr, naddr;
35787c478bd9Sstevel@tonic-gate 		void *tmp = NULL;
35797c478bd9Sstevel@tonic-gate 
35807c478bd9Sstevel@tonic-gate 		for (saddr = seg->s_base; saddr < eaddr; saddr = naddr) {
35817c478bd9Sstevel@tonic-gate 			prot = pr_getprot(seg, 0, &tmp, &saddr, &naddr, eaddr);
35827c478bd9Sstevel@tonic-gate 			if (saddr == naddr)
35837c478bd9Sstevel@tonic-gate 				continue;
35847c478bd9Sstevel@tonic-gate 			/* reallocate if necessary */
35857c478bd9Sstevel@tonic-gate 			if ((nmaps + 2) * sizeof (ioc_prmap32_t) > size) {
35867c478bd9Sstevel@tonic-gate 				size_t newsize = size + MAPSIZE;
35877c478bd9Sstevel@tonic-gate 				ioc_prmap32_t *newmp =
35887c478bd9Sstevel@tonic-gate 					kmem_alloc(newsize, KM_SLEEP);
35897c478bd9Sstevel@tonic-gate 
35907c478bd9Sstevel@tonic-gate 				bcopy(*prmapp, newmp,
35917c478bd9Sstevel@tonic-gate 					nmaps * sizeof (ioc_prmap32_t));
35927c478bd9Sstevel@tonic-gate 				kmem_free(*prmapp, size);
35937c478bd9Sstevel@tonic-gate 				*sizep = size = newsize;
35947c478bd9Sstevel@tonic-gate 				*prmapp = newmp;
35957c478bd9Sstevel@tonic-gate 				mp = newmp + nmaps;
35967c478bd9Sstevel@tonic-gate 			}
35977c478bd9Sstevel@tonic-gate 			bzero(mp, sizeof (*mp));
35987c478bd9Sstevel@tonic-gate 			mp->pr_vaddr = (caddr32_t)(uintptr_t)saddr;
35997c478bd9Sstevel@tonic-gate 			mp->pr_size = (size32_t)(naddr - saddr);
36007c478bd9Sstevel@tonic-gate 			mp->pr_off = (off32_t)SEGOP_GETOFFSET(seg, saddr);
36017c478bd9Sstevel@tonic-gate 			mp->pr_mflags = 0;
36027c478bd9Sstevel@tonic-gate 			if (prot & PROT_READ)
36037c478bd9Sstevel@tonic-gate 				mp->pr_mflags |= MA_READ;
36047c478bd9Sstevel@tonic-gate 			if (prot & PROT_WRITE)
36057c478bd9Sstevel@tonic-gate 				mp->pr_mflags |= MA_WRITE;
36067c478bd9Sstevel@tonic-gate 			if (prot & PROT_EXEC)
36077c478bd9Sstevel@tonic-gate 				mp->pr_mflags |= MA_EXEC;
36087c478bd9Sstevel@tonic-gate 			if (SEGOP_GETTYPE(seg, saddr) & MAP_SHARED)
36097c478bd9Sstevel@tonic-gate 				mp->pr_mflags |= MA_SHARED;
36107c478bd9Sstevel@tonic-gate 			if (seg == brkseg)
36117c478bd9Sstevel@tonic-gate 				mp->pr_mflags |= MA_BREAK;
36127c478bd9Sstevel@tonic-gate 			else if (seg == stkseg)
36137c478bd9Sstevel@tonic-gate 				mp->pr_mflags |= MA_STACK;
36147c478bd9Sstevel@tonic-gate 			mp->pr_pagesize = PAGESIZE;
36157c478bd9Sstevel@tonic-gate 			mp++;
36167c478bd9Sstevel@tonic-gate 			nmaps++;
36177c478bd9Sstevel@tonic-gate 		}
36187c478bd9Sstevel@tonic-gate 		ASSERT(tmp == NULL);
36197c478bd9Sstevel@tonic-gate 	} while ((seg = AS_SEGNEXT(as, seg)) != NULL);
36207c478bd9Sstevel@tonic-gate 
36217c478bd9Sstevel@tonic-gate 	bzero(mp, sizeof (*mp));
36227c478bd9Sstevel@tonic-gate 	return (nmaps + 1);
36237c478bd9Sstevel@tonic-gate }
36247c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32_IMPL */
36257c478bd9Sstevel@tonic-gate 
36267c478bd9Sstevel@tonic-gate /*
36277c478bd9Sstevel@tonic-gate  * Return the size of the old /proc page data file.
36287c478bd9Sstevel@tonic-gate  */
36297c478bd9Sstevel@tonic-gate size_t
36307c478bd9Sstevel@tonic-gate oprpdsize(struct as *as)
36317c478bd9Sstevel@tonic-gate {
36327c478bd9Sstevel@tonic-gate 	struct seg *seg;
36337c478bd9Sstevel@tonic-gate 	size_t size;
36347c478bd9Sstevel@tonic-gate 
36357c478bd9Sstevel@tonic-gate 	ASSERT(as != &kas && AS_WRITE_HELD(as, &as->a_lock));
36367c478bd9Sstevel@tonic-gate 
36377c478bd9Sstevel@tonic-gate 	if ((seg = AS_SEGFIRST(as)) == NULL)
36387c478bd9Sstevel@tonic-gate 		return (0);
36397c478bd9Sstevel@tonic-gate 
36407c478bd9Sstevel@tonic-gate 	size = sizeof (prpageheader_t);
36417c478bd9Sstevel@tonic-gate 	do {
36427c478bd9Sstevel@tonic-gate 		caddr_t eaddr = seg->s_base + pr_getsegsize(seg, 0);
36437c478bd9Sstevel@tonic-gate 		caddr_t saddr, naddr;
36447c478bd9Sstevel@tonic-gate 		void *tmp = NULL;
36457c478bd9Sstevel@tonic-gate 		size_t npage;
36467c478bd9Sstevel@tonic-gate 
36477c478bd9Sstevel@tonic-gate 		for (saddr = seg->s_base; saddr < eaddr; saddr = naddr) {
36487c478bd9Sstevel@tonic-gate 			(void) pr_getprot(seg, 0, &tmp, &saddr, &naddr, eaddr);
36497c478bd9Sstevel@tonic-gate 			if ((npage = (naddr - saddr) / PAGESIZE) != 0)
36507c478bd9Sstevel@tonic-gate 				size += sizeof (prasmap_t) + roundlong(npage);
36517c478bd9Sstevel@tonic-gate 		}
36527c478bd9Sstevel@tonic-gate 		ASSERT(tmp == NULL);
36537c478bd9Sstevel@tonic-gate 	} while ((seg = AS_SEGNEXT(as, seg)) != NULL);
36547c478bd9Sstevel@tonic-gate 
36557c478bd9Sstevel@tonic-gate 	return (size);
36567c478bd9Sstevel@tonic-gate }
36577c478bd9Sstevel@tonic-gate 
36587c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
36597c478bd9Sstevel@tonic-gate size_t
36607c478bd9Sstevel@tonic-gate oprpdsize32(struct as *as)
36617c478bd9Sstevel@tonic-gate {
36627c478bd9Sstevel@tonic-gate 	struct seg *seg;
36637c478bd9Sstevel@tonic-gate 	size_t size;
36647c478bd9Sstevel@tonic-gate 
36657c478bd9Sstevel@tonic-gate 	ASSERT(as != &kas && AS_WRITE_HELD(as, &as->a_lock));
36667c478bd9Sstevel@tonic-gate 
36677c478bd9Sstevel@tonic-gate 	if ((seg = AS_SEGFIRST(as)) == NULL)
36687c478bd9Sstevel@tonic-gate 		return (0);
36697c478bd9Sstevel@tonic-gate 
36707c478bd9Sstevel@tonic-gate 	size = sizeof (ioc_prpageheader32_t);
36717c478bd9Sstevel@tonic-gate 	do {
36727c478bd9Sstevel@tonic-gate 		caddr_t eaddr = seg->s_base + pr_getsegsize(seg, 0);
36737c478bd9Sstevel@tonic-gate 		caddr_t saddr, naddr;
36747c478bd9Sstevel@tonic-gate 		void *tmp = NULL;
36757c478bd9Sstevel@tonic-gate 		size_t npage;
36767c478bd9Sstevel@tonic-gate 
36777c478bd9Sstevel@tonic-gate 		for (saddr = seg->s_base; saddr < eaddr; saddr = naddr) {
36787c478bd9Sstevel@tonic-gate 			(void) pr_getprot(seg, 0, &tmp, &saddr, &naddr, eaddr);
36797c478bd9Sstevel@tonic-gate 			if ((npage = (naddr - saddr) / PAGESIZE) != 0)
36807c478bd9Sstevel@tonic-gate 				size += sizeof (ioc_prmap32_t) + round4(npage);
36817c478bd9Sstevel@tonic-gate 		}
36827c478bd9Sstevel@tonic-gate 		ASSERT(tmp == NULL);
36837c478bd9Sstevel@tonic-gate 	} while ((seg = AS_SEGNEXT(as, seg)) != NULL);
36847c478bd9Sstevel@tonic-gate 
36857c478bd9Sstevel@tonic-gate 	return (size);
36867c478bd9Sstevel@tonic-gate }
36877c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32_IMPL */
36887c478bd9Sstevel@tonic-gate 
36897c478bd9Sstevel@tonic-gate /*
36907c478bd9Sstevel@tonic-gate  * Read old /proc page data information.
36917c478bd9Sstevel@tonic-gate  */
36927c478bd9Sstevel@tonic-gate int
36937c478bd9Sstevel@tonic-gate oprpdread(struct as *as, uint_t hatid, struct uio *uiop)
36947c478bd9Sstevel@tonic-gate {
36957c478bd9Sstevel@tonic-gate 	caddr_t buf;
36967c478bd9Sstevel@tonic-gate 	size_t size;
36977c478bd9Sstevel@tonic-gate 	prpageheader_t *php;
36987c478bd9Sstevel@tonic-gate 	prasmap_t *pmp;
36997c478bd9Sstevel@tonic-gate 	struct seg *seg;
37007c478bd9Sstevel@tonic-gate 	int error;
37017c478bd9Sstevel@tonic-gate 
37027c478bd9Sstevel@tonic-gate again:
37037c478bd9Sstevel@tonic-gate 	AS_LOCK_ENTER(as, &as->a_lock, RW_WRITER);
37047c478bd9Sstevel@tonic-gate 
37057c478bd9Sstevel@tonic-gate 	if ((seg = AS_SEGFIRST(as)) == NULL) {
37067c478bd9Sstevel@tonic-gate 		AS_LOCK_EXIT(as, &as->a_lock);
37077c478bd9Sstevel@tonic-gate 		return (0);
37087c478bd9Sstevel@tonic-gate 	}
37097c478bd9Sstevel@tonic-gate 	size = oprpdsize(as);
37107c478bd9Sstevel@tonic-gate 	if (uiop->uio_resid < size) {
37117c478bd9Sstevel@tonic-gate 		AS_LOCK_EXIT(as, &as->a_lock);
37127c478bd9Sstevel@tonic-gate 		return (E2BIG);
37137c478bd9Sstevel@tonic-gate 	}
37147c478bd9Sstevel@tonic-gate 
37157c478bd9Sstevel@tonic-gate 	buf = kmem_zalloc(size, KM_SLEEP);
37167c478bd9Sstevel@tonic-gate 	php = (prpageheader_t *)buf;
37177c478bd9Sstevel@tonic-gate 	pmp = (prasmap_t *)(buf + sizeof (prpageheader_t));
37187c478bd9Sstevel@tonic-gate 
37197c478bd9Sstevel@tonic-gate 	hrt2ts(gethrtime(), &php->pr_tstamp);
37207c478bd9Sstevel@tonic-gate 	php->pr_nmap = 0;
37217c478bd9Sstevel@tonic-gate 	php->pr_npage = 0;
37227c478bd9Sstevel@tonic-gate 	do {
37237c478bd9Sstevel@tonic-gate 		caddr_t eaddr = seg->s_base + pr_getsegsize(seg, 0);
37247c478bd9Sstevel@tonic-gate 		caddr_t saddr, naddr;
37257c478bd9Sstevel@tonic-gate 		void *tmp = NULL;
37267c478bd9Sstevel@tonic-gate 
37277c478bd9Sstevel@tonic-gate 		for (saddr = seg->s_base; saddr < eaddr; saddr = naddr) {
37287c478bd9Sstevel@tonic-gate 			size_t len;
37297c478bd9Sstevel@tonic-gate 			size_t npage;
37307c478bd9Sstevel@tonic-gate 			uint_t prot;
37317c478bd9Sstevel@tonic-gate 			uintptr_t next;
37327c478bd9Sstevel@tonic-gate 
37337c478bd9Sstevel@tonic-gate 			prot = pr_getprot(seg, 0, &tmp, &saddr, &naddr, eaddr);
37347c478bd9Sstevel@tonic-gate 			if ((len = naddr - saddr) == 0)
37357c478bd9Sstevel@tonic-gate 				continue;
37367c478bd9Sstevel@tonic-gate 			npage = len / PAGESIZE;
37377c478bd9Sstevel@tonic-gate 			next = (uintptr_t)(pmp + 1) + roundlong(npage);
37387c478bd9Sstevel@tonic-gate 			/*
37397c478bd9Sstevel@tonic-gate 			 * It's possible that the address space can change
37407c478bd9Sstevel@tonic-gate 			 * subtlely even though we're holding as->a_lock
37417c478bd9Sstevel@tonic-gate 			 * due to the nondeterminism of page_exists() in
37427c478bd9Sstevel@tonic-gate 			 * the presence of asychronously flushed pages or
37437c478bd9Sstevel@tonic-gate 			 * mapped files whose sizes are changing.
37447c478bd9Sstevel@tonic-gate 			 * page_exists() may be called indirectly from
37457c478bd9Sstevel@tonic-gate 			 * pr_getprot() by a SEGOP_INCORE() routine.
37467c478bd9Sstevel@tonic-gate 			 * If this happens we need to make sure we don't
37477c478bd9Sstevel@tonic-gate 			 * overrun the buffer whose size we computed based
37487c478bd9Sstevel@tonic-gate 			 * on the initial iteration through the segments.
37497c478bd9Sstevel@tonic-gate 			 * Once we've detected an overflow, we need to clean
37507c478bd9Sstevel@tonic-gate 			 * up the temporary memory allocated in pr_getprot()
37517c478bd9Sstevel@tonic-gate 			 * and retry. If there's a pending signal, we return
37527c478bd9Sstevel@tonic-gate 			 * EINTR so that this thread can be dislodged if
37537c478bd9Sstevel@tonic-gate 			 * a latent bug causes us to spin indefinitely.
37547c478bd9Sstevel@tonic-gate 			 */
37557c478bd9Sstevel@tonic-gate 			if (next > (uintptr_t)buf + size) {
37567c478bd9Sstevel@tonic-gate 				pr_getprot_done(&tmp);
37577c478bd9Sstevel@tonic-gate 				AS_LOCK_EXIT(as, &as->a_lock);
37587c478bd9Sstevel@tonic-gate 
37597c478bd9Sstevel@tonic-gate 				kmem_free(buf, size);
37607c478bd9Sstevel@tonic-gate 
37617c478bd9Sstevel@tonic-gate 				if (ISSIG(curthread, JUSTLOOKING))
37627c478bd9Sstevel@tonic-gate 					return (EINTR);
37637c478bd9Sstevel@tonic-gate 
37647c478bd9Sstevel@tonic-gate 				goto again;
37657c478bd9Sstevel@tonic-gate 			}
37667c478bd9Sstevel@tonic-gate 
37677c478bd9Sstevel@tonic-gate 			php->pr_nmap++;
37687c478bd9Sstevel@tonic-gate 			php->pr_npage += npage;
37697c478bd9Sstevel@tonic-gate 			pmp->pr_vaddr = saddr;
37707c478bd9Sstevel@tonic-gate 			pmp->pr_npage = npage;
37717c478bd9Sstevel@tonic-gate 			pmp->pr_off = SEGOP_GETOFFSET(seg, saddr);
37727c478bd9Sstevel@tonic-gate 			pmp->pr_mflags = 0;
37737c478bd9Sstevel@tonic-gate 			if (prot & PROT_READ)
37747c478bd9Sstevel@tonic-gate 				pmp->pr_mflags |= MA_READ;
37757c478bd9Sstevel@tonic-gate 			if (prot & PROT_WRITE)
37767c478bd9Sstevel@tonic-gate 				pmp->pr_mflags |= MA_WRITE;
37777c478bd9Sstevel@tonic-gate 			if (prot & PROT_EXEC)
37787c478bd9Sstevel@tonic-gate 				pmp->pr_mflags |= MA_EXEC;
37797c478bd9Sstevel@tonic-gate 			if (SEGOP_GETTYPE(seg, saddr) & MAP_SHARED)
37807c478bd9Sstevel@tonic-gate 				pmp->pr_mflags |= MA_SHARED;
37817c478bd9Sstevel@tonic-gate 			pmp->pr_pagesize = PAGESIZE;
37827c478bd9Sstevel@tonic-gate 			hat_getstat(as, saddr, len, hatid,
37837c478bd9Sstevel@tonic-gate 			    (char *)(pmp + 1), HAT_SYNC_ZERORM);
37847c478bd9Sstevel@tonic-gate 			pmp = (prasmap_t *)next;
37857c478bd9Sstevel@tonic-gate 		}
37867c478bd9Sstevel@tonic-gate 		ASSERT(tmp == NULL);
37877c478bd9Sstevel@tonic-gate 	} while ((seg = AS_SEGNEXT(as, seg)) != NULL);
37887c478bd9Sstevel@tonic-gate 
37897c478bd9Sstevel@tonic-gate 	AS_LOCK_EXIT(as, &as->a_lock);
37907c478bd9Sstevel@tonic-gate 
37917c478bd9Sstevel@tonic-gate 	ASSERT((uintptr_t)pmp <= (uintptr_t)buf + size);
37927c478bd9Sstevel@tonic-gate 	error = uiomove(buf, (caddr_t)pmp - buf, UIO_READ, uiop);
37937c478bd9Sstevel@tonic-gate 	kmem_free(buf, size);
37947c478bd9Sstevel@tonic-gate 
37957c478bd9Sstevel@tonic-gate 	return (error);
37967c478bd9Sstevel@tonic-gate }
37977c478bd9Sstevel@tonic-gate 
37987c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
37997c478bd9Sstevel@tonic-gate int
38007c478bd9Sstevel@tonic-gate oprpdread32(struct as *as, uint_t hatid, struct uio *uiop)
38017c478bd9Sstevel@tonic-gate {
38027c478bd9Sstevel@tonic-gate 	caddr_t buf;
38037c478bd9Sstevel@tonic-gate 	size_t size;
38047c478bd9Sstevel@tonic-gate 	ioc_prpageheader32_t *php;
38057c478bd9Sstevel@tonic-gate 	ioc_prasmap32_t *pmp;
38067c478bd9Sstevel@tonic-gate 	struct seg *seg;
38077c478bd9Sstevel@tonic-gate 	int error;
38087c478bd9Sstevel@tonic-gate 
38097c478bd9Sstevel@tonic-gate again:
38107c478bd9Sstevel@tonic-gate 	AS_LOCK_ENTER(as, &as->a_lock, RW_WRITER);
38117c478bd9Sstevel@tonic-gate 
38127c478bd9Sstevel@tonic-gate 	if ((seg = AS_SEGFIRST(as)) == NULL) {
38137c478bd9Sstevel@tonic-gate 		AS_LOCK_EXIT(as, &as->a_lock);
38147c478bd9Sstevel@tonic-gate 		return (0);
38157c478bd9Sstevel@tonic-gate 	}
38167c478bd9Sstevel@tonic-gate 	size = oprpdsize32(as);
38177c478bd9Sstevel@tonic-gate 	if (uiop->uio_resid < size) {
38187c478bd9Sstevel@tonic-gate 		AS_LOCK_EXIT(as, &as->a_lock);
38197c478bd9Sstevel@tonic-gate 		return (E2BIG);
38207c478bd9Sstevel@tonic-gate 	}
38217c478bd9Sstevel@tonic-gate 
38227c478bd9Sstevel@tonic-gate 	buf = kmem_zalloc(size, KM_SLEEP);
38237c478bd9Sstevel@tonic-gate 	php = (ioc_prpageheader32_t *)buf;
38247c478bd9Sstevel@tonic-gate 	pmp = (ioc_prasmap32_t *)(buf + sizeof (ioc_prpageheader32_t));
38257c478bd9Sstevel@tonic-gate 
38267c478bd9Sstevel@tonic-gate 	hrt2ts32(gethrtime(), &php->pr_tstamp);
38277c478bd9Sstevel@tonic-gate 	php->pr_nmap = 0;
38287c478bd9Sstevel@tonic-gate 	php->pr_npage = 0;
38297c478bd9Sstevel@tonic-gate 	do {
38307c478bd9Sstevel@tonic-gate 		caddr_t eaddr = seg->s_base + pr_getsegsize(seg, 0);
38317c478bd9Sstevel@tonic-gate 		caddr_t saddr, naddr;
38327c478bd9Sstevel@tonic-gate 		void *tmp = NULL;
38337c478bd9Sstevel@tonic-gate 
38347c478bd9Sstevel@tonic-gate 		for (saddr = seg->s_base; saddr < eaddr; saddr = naddr) {
38357c478bd9Sstevel@tonic-gate 			size_t len;
38367c478bd9Sstevel@tonic-gate 			size_t npage;
38377c478bd9Sstevel@tonic-gate 			uint_t prot;
38387c478bd9Sstevel@tonic-gate 			uintptr_t next;
38397c478bd9Sstevel@tonic-gate 
38407c478bd9Sstevel@tonic-gate 			prot = pr_getprot(seg, 0, &tmp, &saddr, &naddr, eaddr);
38417c478bd9Sstevel@tonic-gate 			if ((len = naddr - saddr) == 0)
38427c478bd9Sstevel@tonic-gate 				continue;
38437c478bd9Sstevel@tonic-gate 			npage = len / PAGESIZE;
38447c478bd9Sstevel@tonic-gate 			next = (uintptr_t)(pmp + 1) + round4(npage);
38457c478bd9Sstevel@tonic-gate 			/*
38467c478bd9Sstevel@tonic-gate 			 * It's possible that the address space can change
38477c478bd9Sstevel@tonic-gate 			 * subtlely even though we're holding as->a_lock
38487c478bd9Sstevel@tonic-gate 			 * due to the nondeterminism of page_exists() in
38497c478bd9Sstevel@tonic-gate 			 * the presence of asychronously flushed pages or
38507c478bd9Sstevel@tonic-gate 			 * mapped files whose sizes are changing.
38517c478bd9Sstevel@tonic-gate 			 * page_exists() may be called indirectly from
38527c478bd9Sstevel@tonic-gate 			 * pr_getprot() by a SEGOP_INCORE() routine.
38537c478bd9Sstevel@tonic-gate 			 * If this happens we need to make sure we don't
38547c478bd9Sstevel@tonic-gate 			 * overrun the buffer whose size we computed based
38557c478bd9Sstevel@tonic-gate 			 * on the initial iteration through the segments.
38567c478bd9Sstevel@tonic-gate 			 * Once we've detected an overflow, we need to clean
38577c478bd9Sstevel@tonic-gate 			 * up the temporary memory allocated in pr_getprot()
38587c478bd9Sstevel@tonic-gate 			 * and retry. If there's a pending signal, we return
38597c478bd9Sstevel@tonic-gate 			 * EINTR so that this thread can be dislodged if
38607c478bd9Sstevel@tonic-gate 			 * a latent bug causes us to spin indefinitely.
38617c478bd9Sstevel@tonic-gate 			 */
38627c478bd9Sstevel@tonic-gate 			if (next > (uintptr_t)buf + size) {
38637c478bd9Sstevel@tonic-gate 				pr_getprot_done(&tmp);
38647c478bd9Sstevel@tonic-gate 				AS_LOCK_EXIT(as, &as->a_lock);
38657c478bd9Sstevel@tonic-gate 
38667c478bd9Sstevel@tonic-gate 				kmem_free(buf, size);
38677c478bd9Sstevel@tonic-gate 
38687c478bd9Sstevel@tonic-gate 				if (ISSIG(curthread, JUSTLOOKING))
38697c478bd9Sstevel@tonic-gate 					return (EINTR);
38707c478bd9Sstevel@tonic-gate 
38717c478bd9Sstevel@tonic-gate 				goto again;
38727c478bd9Sstevel@tonic-gate 			}
38737c478bd9Sstevel@tonic-gate 
38747c478bd9Sstevel@tonic-gate 			php->pr_nmap++;
38757c478bd9Sstevel@tonic-gate 			php->pr_npage += npage;
38767c478bd9Sstevel@tonic-gate 			pmp->pr_vaddr = (uint32_t)(uintptr_t)saddr;
38777c478bd9Sstevel@tonic-gate 			pmp->pr_npage = (uint32_t)npage;
38787c478bd9Sstevel@tonic-gate 			pmp->pr_off = (int32_t)SEGOP_GETOFFSET(seg, saddr);
38797c478bd9Sstevel@tonic-gate 			pmp->pr_mflags = 0;
38807c478bd9Sstevel@tonic-gate 			if (prot & PROT_READ)
38817c478bd9Sstevel@tonic-gate 				pmp->pr_mflags |= MA_READ;
38827c478bd9Sstevel@tonic-gate 			if (prot & PROT_WRITE)
38837c478bd9Sstevel@tonic-gate 				pmp->pr_mflags |= MA_WRITE;
38847c478bd9Sstevel@tonic-gate 			if (prot & PROT_EXEC)
38857c478bd9Sstevel@tonic-gate 				pmp->pr_mflags |= MA_EXEC;
38867c478bd9Sstevel@tonic-gate 			if (SEGOP_GETTYPE(seg, saddr) & MAP_SHARED)
38877c478bd9Sstevel@tonic-gate 				pmp->pr_mflags |= MA_SHARED;
38887c478bd9Sstevel@tonic-gate 			pmp->pr_pagesize = PAGESIZE;
38897c478bd9Sstevel@tonic-gate 			hat_getstat(as, saddr, len, hatid,
38907c478bd9Sstevel@tonic-gate 			    (char *)(pmp + 1), HAT_SYNC_ZERORM);
38917c478bd9Sstevel@tonic-gate 			pmp = (ioc_prasmap32_t *)next;
38927c478bd9Sstevel@tonic-gate 		}
38937c478bd9Sstevel@tonic-gate 		ASSERT(tmp == NULL);
38947c478bd9Sstevel@tonic-gate 	} while ((seg = AS_SEGNEXT(as, seg)) != NULL);
38957c478bd9Sstevel@tonic-gate 
38967c478bd9Sstevel@tonic-gate 	AS_LOCK_EXIT(as, &as->a_lock);
38977c478bd9Sstevel@tonic-gate 
38987c478bd9Sstevel@tonic-gate 	ASSERT((uintptr_t)pmp == (uintptr_t)buf + size);
38997c478bd9Sstevel@tonic-gate 	error = uiomove(buf, (caddr_t)pmp - buf, UIO_READ, uiop);
39007c478bd9Sstevel@tonic-gate 	kmem_free(buf, size);
39017c478bd9Sstevel@tonic-gate 
39027c478bd9Sstevel@tonic-gate 	return (error);
39037c478bd9Sstevel@tonic-gate }
39047c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32_IMPL */
39057c478bd9Sstevel@tonic-gate 
39067c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
39077c478bd9Sstevel@tonic-gate int
39087c478bd9Sstevel@tonic-gate prioctl(struct vnode *vp, int cmd, intptr_t arg, int flag,
39097c478bd9Sstevel@tonic-gate 	cred_t *cr, int *rvalp)
39107c478bd9Sstevel@tonic-gate {
39117c478bd9Sstevel@tonic-gate 	switch (curproc->p_model) {
39127c478bd9Sstevel@tonic-gate 	case DATAMODEL_ILP32:
39137c478bd9Sstevel@tonic-gate 		return (prioctl32(vp, cmd, arg, flag, cr, rvalp));
39147c478bd9Sstevel@tonic-gate 	case DATAMODEL_LP64:
39157c478bd9Sstevel@tonic-gate 		return (prioctl64(vp, cmd, arg, flag, cr, rvalp));
39167c478bd9Sstevel@tonic-gate 	default:
39177c478bd9Sstevel@tonic-gate 		return (ENOSYS);
39187c478bd9Sstevel@tonic-gate 	}
39197c478bd9Sstevel@tonic-gate }
39207c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32_IMPL */
3921