xref: /illumos-gate/usr/src/uts/common/fs/proc/prdata.h (revision ed093b41a93e8563e6e1e5dae0768dda2a7bcc27)
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
5870619e9Sfrankho  * Common Development and Distribution License (the "License").
6870619e9Sfrankho  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
223348528fSdm120769  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
287c478bd9Sstevel@tonic-gate 
29f971a346SBryan Cantrill /*
30ab618543SJohn Levon  * Copyright 2018 Joyent, Inc.
31a02120c4SAndy Fiddaman  * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
32*ed093b41SRobert Mustacchi  * Copyright 2023 Oxide Computer Company
33f971a346SBryan Cantrill  */
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifndef _SYS_PROC_PRDATA_H
367c478bd9Sstevel@tonic-gate #define	_SYS_PROC_PRDATA_H
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
397c478bd9Sstevel@tonic-gate #include <sys/proc.h>
407c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
417c478bd9Sstevel@tonic-gate #include <sys/prsystm.h>
427c478bd9Sstevel@tonic-gate #include <sys/model.h>
437c478bd9Sstevel@tonic-gate #include <sys/poll.h>
44870619e9Sfrankho #include <sys/list.h>
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
477c478bd9Sstevel@tonic-gate extern "C" {
487c478bd9Sstevel@tonic-gate #endif
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate /*
517c478bd9Sstevel@tonic-gate  * Test for thread being stopped, not on an event of interest,
527c478bd9Sstevel@tonic-gate  * but with a directed stop in effect.
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate #define	DSTOPPED(t)	\
557c478bd9Sstevel@tonic-gate 	((t)->t_state == TS_STOPPED && \
567c478bd9Sstevel@tonic-gate 	((t)->t_proc_flag & TP_PRSTOP))
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate #define	round4(r)	(((r) + 3) & (~3))
597c478bd9Sstevel@tonic-gate #define	round8(r)	(((r) + 7) & (~7))
607c478bd9Sstevel@tonic-gate #define	round16(r)	(((r) + 15) & (~15))
617c478bd9Sstevel@tonic-gate #define	roundlong(r)	(((r) + sizeof (long) - 1) & (~(sizeof (long) - 1)))
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate #define	PNSIZ	10			/* max size of /proc name entries */
647c478bd9Sstevel@tonic-gate #define	PLNSIZ	10			/* max size of /proc lwp name entries */
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate  * Common file object to which all /proc vnodes for a specific process
687c478bd9Sstevel@tonic-gate  * or lwp refer.  One for the process, one for each lwp.
697c478bd9Sstevel@tonic-gate  */
707c478bd9Sstevel@tonic-gate typedef struct prcommon {
717c478bd9Sstevel@tonic-gate 	kmutex_t	prc_mutex;	/* to wait for the proc/lwp to stop */
727c478bd9Sstevel@tonic-gate 	kcondvar_t	prc_wait;	/* to wait for the proc/lwp to stop */
737c478bd9Sstevel@tonic-gate 	ushort_t	prc_flags;	/* flags */
747c478bd9Sstevel@tonic-gate 	uint_t		prc_writers;	/* number of write opens of prnodes */
757c478bd9Sstevel@tonic-gate 	uint_t		prc_selfopens;	/* number of write opens by self */
767c478bd9Sstevel@tonic-gate 	pid_t		prc_pid;	/* process id */
777c478bd9Sstevel@tonic-gate 	model_t		prc_datamodel;	/* data model of the process */
787c478bd9Sstevel@tonic-gate 	proc_t		*prc_proc;	/* process being traced */
797c478bd9Sstevel@tonic-gate 	kthread_t	*prc_thread;	/* thread (lwp) being traced */
807c478bd9Sstevel@tonic-gate 	int		prc_slot;	/* procdir slot number */
817c478bd9Sstevel@tonic-gate 	id_t		prc_tid;	/* thread (lwp) id */
827c478bd9Sstevel@tonic-gate 	int		prc_tslot;	/* lwpdir slot number, -1 if reaped */
837c478bd9Sstevel@tonic-gate 	int		prc_refcnt;	/* this structure's reference count */
847c478bd9Sstevel@tonic-gate 	struct pollhead	prc_pollhead;	/* list of all pollers */
857c478bd9Sstevel@tonic-gate } prcommon_t;
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate /* prc_flags */
887c478bd9Sstevel@tonic-gate #define	PRC_DESTROY	0x01	/* process or lwp is being destroyed */
897c478bd9Sstevel@tonic-gate #define	PRC_LWP		0x02	/* structure refers to an lwp */
907c478bd9Sstevel@tonic-gate #define	PRC_SYS		0x04	/* process is a system process */
917c478bd9Sstevel@tonic-gate #define	PRC_POLL	0x08	/* poll() in progress on this process/lwp */
927c478bd9Sstevel@tonic-gate #define	PRC_EXCL	0x10	/* exclusive access granted (old /proc) */
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate /*
957c478bd9Sstevel@tonic-gate  * Macros for mapping between i-numbers and pids.
967c478bd9Sstevel@tonic-gate  */
977c478bd9Sstevel@tonic-gate #define	pmkino(tslot, pslot, nodetype)		\
987c478bd9Sstevel@tonic-gate 	(((((ino_t)(tslot) << nproc_highbit) |	\
997c478bd9Sstevel@tonic-gate 	(ino_t)(pslot)) << 6) |			\
1007c478bd9Sstevel@tonic-gate 	(nodetype) + 2)
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /* for old /proc interface */
1037c478bd9Sstevel@tonic-gate #define	PRBIAS	64
1047c478bd9Sstevel@tonic-gate #define	ptoi(n) ((int)(((n) + PRBIAS)))		/* pid to i-number */
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate  * Node types for /proc files (directories and files contained therein).
1087c478bd9Sstevel@tonic-gate  */
1097c478bd9Sstevel@tonic-gate typedef enum prnodetype {
1107c478bd9Sstevel@tonic-gate 	PR_PROCDIR,		/* /proc				*/
1117c478bd9Sstevel@tonic-gate 	PR_SELF,		/* /proc/self				*/
1127c478bd9Sstevel@tonic-gate 	PR_PIDDIR,		/* /proc/<pid>				*/
1137c478bd9Sstevel@tonic-gate 	PR_AS,			/* /proc/<pid>/as			*/
1147c478bd9Sstevel@tonic-gate 	PR_CTL,			/* /proc/<pid>/ctl			*/
1157c478bd9Sstevel@tonic-gate 	PR_STATUS,		/* /proc/<pid>/status			*/
1167c478bd9Sstevel@tonic-gate 	PR_LSTATUS,		/* /proc/<pid>/lstatus			*/
1177c478bd9Sstevel@tonic-gate 	PR_PSINFO,		/* /proc/<pid>/psinfo			*/
1187c478bd9Sstevel@tonic-gate 	PR_LPSINFO,		/* /proc/<pid>/lpsinfo			*/
1197c478bd9Sstevel@tonic-gate 	PR_MAP,			/* /proc/<pid>/map			*/
1207c478bd9Sstevel@tonic-gate 	PR_RMAP,		/* /proc/<pid>/rmap			*/
1217c478bd9Sstevel@tonic-gate 	PR_XMAP,		/* /proc/<pid>/xmap			*/
1227c478bd9Sstevel@tonic-gate 	PR_CRED,		/* /proc/<pid>/cred			*/
1237c478bd9Sstevel@tonic-gate 	PR_SIGACT,		/* /proc/<pid>/sigact			*/
1247c478bd9Sstevel@tonic-gate 	PR_AUXV,		/* /proc/<pid>/auxv			*/
1257c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
1267c478bd9Sstevel@tonic-gate 	PR_LDT,			/* /proc/<pid>/ldt			*/
1277c478bd9Sstevel@tonic-gate #endif
1287c478bd9Sstevel@tonic-gate 	PR_USAGE,		/* /proc/<pid>/usage			*/
1297c478bd9Sstevel@tonic-gate 	PR_LUSAGE,		/* /proc/<pid>/lusage			*/
1307c478bd9Sstevel@tonic-gate 	PR_PAGEDATA,		/* /proc/<pid>/pagedata			*/
1317c478bd9Sstevel@tonic-gate 	PR_WATCH,		/* /proc/<pid>/watch			*/
1327c478bd9Sstevel@tonic-gate 	PR_CURDIR,		/* /proc/<pid>/cwd			*/
1337c478bd9Sstevel@tonic-gate 	PR_ROOTDIR,		/* /proc/<pid>/root			*/
1347c478bd9Sstevel@tonic-gate 	PR_FDDIR,		/* /proc/<pid>/fd			*/
1357c478bd9Sstevel@tonic-gate 	PR_FD,			/* /proc/<pid>/fd/nn			*/
136a02120c4SAndy Fiddaman 	PR_FDINFODIR,		/* /proc/<pid>/fdinfo			*/
137a02120c4SAndy Fiddaman 	PR_FDINFO,		/* /proc/<pid>/fdinfo/nn		*/
1387c478bd9Sstevel@tonic-gate 	PR_OBJECTDIR,		/* /proc/<pid>/object			*/
1397c478bd9Sstevel@tonic-gate 	PR_OBJECT,		/* /proc/<pid>/object/xxx		*/
1407c478bd9Sstevel@tonic-gate 	PR_LWPDIR,		/* /proc/<pid>/lwp			*/
1417c478bd9Sstevel@tonic-gate 	PR_LWPIDDIR,		/* /proc/<pid>/lwp/<lwpid>		*/
1427c478bd9Sstevel@tonic-gate 	PR_LWPCTL,		/* /proc/<pid>/lwp/<lwpid>/lwpctl	*/
143ab618543SJohn Levon 	PR_LWPNAME,		/* /proc/<pid>/lwp/<lwpid>/lwpname	*/
1447c478bd9Sstevel@tonic-gate 	PR_LWPSTATUS,		/* /proc/<pid>/lwp/<lwpid>/lwpstatus	*/
1457c478bd9Sstevel@tonic-gate 	PR_LWPSINFO,		/* /proc/<pid>/lwp/<lwpid>/lwpsinfo	*/
1467c478bd9Sstevel@tonic-gate 	PR_LWPUSAGE,		/* /proc/<pid>/lwp/<lwpid>/lwpusage	*/
1477c478bd9Sstevel@tonic-gate 	PR_XREGS,		/* /proc/<pid>/lwp/<lwpid>/xregs	*/
1487c478bd9Sstevel@tonic-gate 	PR_TMPLDIR,		/* /proc/<pid>/lwp/<lwpid>/templates	*/
1497c478bd9Sstevel@tonic-gate 	PR_TMPL,		/* /proc/<pid>/lwp/<lwpid>/templates/<id> */
150f971a346SBryan Cantrill 	PR_SPYMASTER,		/* /proc/<pid>/lwp/<lwpid>/spymaster	*/
1517c478bd9Sstevel@tonic-gate #if defined(__sparc)
1527c478bd9Sstevel@tonic-gate 	PR_GWINDOWS,		/* /proc/<pid>/lwp/<lwpid>/gwindows	*/
1537c478bd9Sstevel@tonic-gate 	PR_ASRS,		/* /proc/<pid>/lwp/<lwpid>/asrs		*/
1547c478bd9Sstevel@tonic-gate #endif
1557c478bd9Sstevel@tonic-gate 	PR_PRIV,		/* /proc/<pid>/priv			*/
1567c478bd9Sstevel@tonic-gate 	PR_PATHDIR,		/* /proc/<pid>/path			*/
1577c478bd9Sstevel@tonic-gate 	PR_PATH,		/* /proc/<pid>/path/xxx			*/
1587c478bd9Sstevel@tonic-gate 	PR_CTDIR,		/* /proc/<pid>/contracts		*/
1597c478bd9Sstevel@tonic-gate 	PR_CT,			/* /proc/<pid>/contracts/<ctid>		*/
160d2a70789SRichard Lowe 	PR_SECFLAGS,		/* /proc/<pid>/secflags			*/
1617c478bd9Sstevel@tonic-gate 	PR_PIDFILE,		/* old process file			*/
1627c478bd9Sstevel@tonic-gate 	PR_LWPIDFILE,		/* old lwp file				*/
1637c478bd9Sstevel@tonic-gate 	PR_OPAGEDATA,		/* old page data file			*/
1647c478bd9Sstevel@tonic-gate 	PR_NFILES		/* number of /proc node types		*/
1657c478bd9Sstevel@tonic-gate } prnodetype_t;
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate typedef struct prnode {
1687c478bd9Sstevel@tonic-gate 	vnode_t		*pr_next;	/* list of all vnodes for process */
1697c478bd9Sstevel@tonic-gate 	uint_t		pr_flags;	/* private flags */
1707c478bd9Sstevel@tonic-gate 	kmutex_t	pr_mutex;	/* locks pr_files and child pr_flags */
1717c478bd9Sstevel@tonic-gate 	prnodetype_t	pr_type;	/* node type */
1727c478bd9Sstevel@tonic-gate 	mode_t		pr_mode;	/* file mode */
1737c478bd9Sstevel@tonic-gate 	ino_t		pr_ino;		/* node id (for stat(2)) */
1747c478bd9Sstevel@tonic-gate 	uint_t		pr_hatid;	/* hat layer id for page data files */
1757c478bd9Sstevel@tonic-gate 	prcommon_t	*pr_common;	/* common data structure */
1767c478bd9Sstevel@tonic-gate 	prcommon_t	*pr_pcommon;	/* process common data structure */
1777c478bd9Sstevel@tonic-gate 	vnode_t		*pr_parent;	/* parent directory */
1787c478bd9Sstevel@tonic-gate 	vnode_t		**pr_files;	/* contained files array (directory) */
1797c478bd9Sstevel@tonic-gate 	uint_t		pr_index;	/* position within parent */
1807c478bd9Sstevel@tonic-gate 	vnode_t		*pr_pidfile;	/* substitute vnode for old /proc */
1817c478bd9Sstevel@tonic-gate 	vnode_t		*pr_realvp;	/* real vnode, file in object,fd dirs */
1827c478bd9Sstevel@tonic-gate 	proc_t		*pr_owner;	/* the process that created this node */
1837c478bd9Sstevel@tonic-gate 	vnode_t		*pr_vnode;	/* pointer to vnode */
1847c478bd9Sstevel@tonic-gate 	struct contract *pr_contract;	/* contract pointer */
1857c478bd9Sstevel@tonic-gate 	int		pr_cttype;	/* active template type */
1867c478bd9Sstevel@tonic-gate } prnode_t;
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate /*
1897c478bd9Sstevel@tonic-gate  * Values for pr_flags.
1907c478bd9Sstevel@tonic-gate  */
1917c478bd9Sstevel@tonic-gate #define	PR_INVAL	0x01		/* vnode is invalidated */
1927c478bd9Sstevel@tonic-gate #define	PR_ISSELF	0x02		/* vnode is a self-open */
1937c478bd9Sstevel@tonic-gate #define	PR_AOUT		0x04		/* vnode is for an a.out path */
194d1b18d1aSBryan Cantrill #define	PR_OFFMAX	0x08		/* vnode is a large file open */
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate /*
1977c478bd9Sstevel@tonic-gate  * Conversion macros.
1987c478bd9Sstevel@tonic-gate  */
1997c478bd9Sstevel@tonic-gate #define	VTOP(vp)	((struct prnode *)(vp)->v_data)
2007c478bd9Sstevel@tonic-gate #define	PTOV(pnp)	((pnp)->pr_vnode)
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate /*
2037c478bd9Sstevel@tonic-gate  * Flags to prlock().
2047c478bd9Sstevel@tonic-gate  */
2057c478bd9Sstevel@tonic-gate #define	ZNO	0	/* Fail on encountering a zombie process. */
2067c478bd9Sstevel@tonic-gate #define	ZYES	1	/* Allow zombies. */
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate /*
2097c478bd9Sstevel@tonic-gate  * Assign one set to another (possible different sizes).
2107c478bd9Sstevel@tonic-gate  *
2117c478bd9Sstevel@tonic-gate  * Assigning to a smaller set causes members to be lost.
2127c478bd9Sstevel@tonic-gate  * Assigning to a larger set causes extra members to be cleared.
2137c478bd9Sstevel@tonic-gate  */
2147c478bd9Sstevel@tonic-gate #define	prassignset(ap, sp)					\
2157c478bd9Sstevel@tonic-gate {								\
2167c478bd9Sstevel@tonic-gate 	register int _i_ = sizeof (*(ap))/sizeof (uint32_t);	\
2177c478bd9Sstevel@tonic-gate 	while (--_i_ >= 0)					\
2187c478bd9Sstevel@tonic-gate 		((uint32_t *)(ap))[_i_] =			\
2197c478bd9Sstevel@tonic-gate 		    (_i_ >= sizeof (*(sp))/sizeof (uint32_t)) ?	\
2207c478bd9Sstevel@tonic-gate 		    0 : ((uint32_t *)(sp))[_i_];		\
2217c478bd9Sstevel@tonic-gate }
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate /*
2247c478bd9Sstevel@tonic-gate  * Determine whether or not a set (of arbitrary size) is empty.
2257c478bd9Sstevel@tonic-gate  */
2267c478bd9Sstevel@tonic-gate #define	prisempty(sp) \
2277c478bd9Sstevel@tonic-gate 	setisempty((uint32_t *)(sp), \
2287c478bd9Sstevel@tonic-gate 		(uint_t)(sizeof (*(sp)) / sizeof (uint32_t)))
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate /*
2317c478bd9Sstevel@tonic-gate  * Resource usage with times as hrtime_t rather than timestruc_t.
2327c478bd9Sstevel@tonic-gate  * Each member exactly matches the corresponding member in prusage_t.
2337c478bd9Sstevel@tonic-gate  * This is for convenience of internal computation.
2347c478bd9Sstevel@tonic-gate  */
2357c478bd9Sstevel@tonic-gate typedef struct prhusage {
2367c478bd9Sstevel@tonic-gate 	id_t		pr_lwpid;	/* lwp id.  0: process or defunct */
2377c478bd9Sstevel@tonic-gate 	int		pr_count;	/* number of contributing lwps */
2387c478bd9Sstevel@tonic-gate 	hrtime_t	pr_tstamp;	/* current time stamp */
2397c478bd9Sstevel@tonic-gate 	hrtime_t	pr_create;	/* process/lwp creation time stamp */
2407c478bd9Sstevel@tonic-gate 	hrtime_t	pr_term;	/* process/lwp termination time stamp */
2417c478bd9Sstevel@tonic-gate 	hrtime_t	pr_rtime;	/* total lwp real (elapsed) time */
2427c478bd9Sstevel@tonic-gate 	hrtime_t	pr_utime;	/* user level CPU time */
2437c478bd9Sstevel@tonic-gate 	hrtime_t	pr_stime;	/* system call CPU time */
2447c478bd9Sstevel@tonic-gate 	hrtime_t	pr_ttime;	/* other system trap CPU time */
2457c478bd9Sstevel@tonic-gate 	hrtime_t	pr_tftime;	/* text page fault sleep time */
2467c478bd9Sstevel@tonic-gate 	hrtime_t	pr_dftime;	/* data page fault sleep time */
2477c478bd9Sstevel@tonic-gate 	hrtime_t	pr_kftime;	/* kernel page fault sleep time */
2487c478bd9Sstevel@tonic-gate 	hrtime_t	pr_ltime;	/* user lock wait sleep time */
2497c478bd9Sstevel@tonic-gate 	hrtime_t	pr_slptime;	/* all other sleep time */
2507c478bd9Sstevel@tonic-gate 	hrtime_t	pr_wtime;	/* wait-cpu (latency) time */
2517c478bd9Sstevel@tonic-gate 	hrtime_t	pr_stoptime;	/* stopped time */
2527c478bd9Sstevel@tonic-gate 	hrtime_t	filltime[6];	/* filler for future expansion */
2537c478bd9Sstevel@tonic-gate 	uint64_t	pr_minf;	/* minor page faults */
2547c478bd9Sstevel@tonic-gate 	uint64_t	pr_majf;	/* major page faults */
2557c478bd9Sstevel@tonic-gate 	uint64_t	pr_nswap;	/* swaps */
2567c478bd9Sstevel@tonic-gate 	uint64_t	pr_inblk;	/* input blocks */
2577c478bd9Sstevel@tonic-gate 	uint64_t	pr_oublk;	/* output blocks */
2587c478bd9Sstevel@tonic-gate 	uint64_t	pr_msnd;	/* messages sent */
2597c478bd9Sstevel@tonic-gate 	uint64_t	pr_mrcv;	/* messages received */
2607c478bd9Sstevel@tonic-gate 	uint64_t	pr_sigs;	/* signals received */
2617c478bd9Sstevel@tonic-gate 	uint64_t	pr_vctx;	/* voluntary context switches */
2627c478bd9Sstevel@tonic-gate 	uint64_t	pr_ictx;	/* involuntary context switches */
2637c478bd9Sstevel@tonic-gate 	uint64_t	pr_sysc;	/* system calls */
2647c478bd9Sstevel@tonic-gate 	uint64_t	pr_ioch;	/* chars read and written */
2657c478bd9Sstevel@tonic-gate 	uint64_t	filler[10];	/* filler for future expansion */
2667c478bd9Sstevel@tonic-gate } prhusage_t;
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate /* Exclude system processes from this test */
2717c478bd9Sstevel@tonic-gate #define	PROCESS_NOT_32BIT(p)	\
2727c478bd9Sstevel@tonic-gate 	(!((p)->p_flag & SSYS) && (p)->p_as != &kas && \
2737c478bd9Sstevel@tonic-gate 	(p)->p_model != DATAMODEL_ILP32)
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate extern	int	prnwatch;	/* number of supported watchpoints */
2767c478bd9Sstevel@tonic-gate extern	int	nproc_highbit;	/* highbit(v.v_nproc) */
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate extern	struct vnodeops	*prvnodeops;
2797c478bd9Sstevel@tonic-gate 
280870619e9Sfrankho /*
281870619e9Sfrankho  * Generic chained copyout buffers for procfs use.
282870619e9Sfrankho  * In order to prevent procfs from making huge oversize kmem_alloc calls,
283870619e9Sfrankho  * a list of smaller buffers can be concatenated and copied to userspace in
284870619e9Sfrankho  * sequence.
285870619e9Sfrankho  *
286870619e9Sfrankho  * The implementation is opaque.
287870619e9Sfrankho  *
288870619e9Sfrankho  * A user of this will perform the following steps:
289870619e9Sfrankho  *
290870619e9Sfrankho  *	list_t	listhead;
291870619e9Sfrankho  *	struct my *mp;
292870619e9Sfrankho  *
293870619e9Sfrankho  *	pr_iol_initlist(&listhead, sizeof (*mp), n);
294870619e9Sfrankho  *	while (whatever) {
295a02120c4SAndy Fiddaman  *		mp = pr_iol_newbuf(&listhead, sizeof (*mp));
296870619e9Sfrankho  *		...
297870619e9Sfrankho  *		error = ...
298870619e9Sfrankho  *	}
299870619e9Sfrankho  *
300870619e9Sfrankho  * When done, depending on whether copyout() or uiomove() is supposed to
301870619e9Sfrankho  * be used for transferring the buffered data to userspace, call either:
302870619e9Sfrankho  *
303870619e9Sfrankho  *	error = pr_iol_copyout_and_free(&listhead, &cmaddr, error);
304870619e9Sfrankho  *
305870619e9Sfrankho  * or else:
306870619e9Sfrankho  *
307870619e9Sfrankho  *	error = pr_iol_uiomove_and_free(&listhead, uiop, error);
308870619e9Sfrankho  *
309870619e9Sfrankho  * These two functions will in any case kmem_free() all list items, but
310870619e9Sfrankho  * if an error occurred before they will not perform the copyout/uiomove.
311870619e9Sfrankho  * If copyout/uiomove are done, the passed target address / uio_t
312870619e9Sfrankho  * are updated. The error returned will either be the one passed in, or
313870619e9Sfrankho  * the error that occurred during copyout/uiomove.
314870619e9Sfrankho  */
315870619e9Sfrankho 
316870619e9Sfrankho extern	void	pr_iol_initlist(list_t *head, size_t itemsize, int nitems);
317870619e9Sfrankho extern	void *	pr_iol_newbuf(list_t *head, size_t itemsize);
318870619e9Sfrankho extern	int	pr_iol_copyout_and_free(list_t *head, caddr_t *tgt, int errin);
319870619e9Sfrankho extern	int	pr_iol_uiomove_and_free(list_t *head, uio_t *uiop, int errin);
320a02120c4SAndy Fiddaman extern	void	pr_iol_freelist(list_t *);
321870619e9Sfrankho 
3227c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32_IMPL)
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate extern	int	prwritectl32(vnode_t *, struct uio *, cred_t *);
3257c478bd9Sstevel@tonic-gate extern	void	prgetaction32(proc_t *, user_t *, uint_t, struct sigaction32 *);
3267c478bd9Sstevel@tonic-gate extern	void	prcvtusage32(struct prhusage *, prusage32_t *);
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32_IMPL */
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate /* kludge to support old /proc interface */
3317c478bd9Sstevel@tonic-gate #if !defined(_SYS_OLD_PROCFS_H)
332870619e9Sfrankho extern	int	prgetmap(proc_t *, int, list_t *);
333870619e9Sfrankho extern	int	prgetxmap(proc_t *, list_t *);
3347c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32_IMPL)
335870619e9Sfrankho extern	int	prgetmap32(proc_t *, int, list_t *);
336870619e9Sfrankho extern	int	prgetxmap32(proc_t *, list_t *);
3377c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32_IMPL */
3387c478bd9Sstevel@tonic-gate #endif /* !_SYS_OLD_PROCFS_H */
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate extern	proc_t	*pr_p_lock(prnode_t *);
3417c478bd9Sstevel@tonic-gate extern	kthread_t *pr_thread(prnode_t *);
3427c478bd9Sstevel@tonic-gate extern	void	pr_stop(prnode_t *);
3437c478bd9Sstevel@tonic-gate extern	int	pr_wait_stop(prnode_t *, time_t);
3447c478bd9Sstevel@tonic-gate extern	int	pr_setrun(prnode_t *, ulong_t);
3453348528fSdm120769 extern	int	pr_wait(prcommon_t *, timestruc_t *, int);
3467c478bd9Sstevel@tonic-gate extern	void	pr_wait_die(prnode_t *);
3477c478bd9Sstevel@tonic-gate extern	int	pr_setsig(prnode_t *, siginfo_t *);
3487c478bd9Sstevel@tonic-gate extern	int	pr_kill(prnode_t *, int, cred_t *);
3497c478bd9Sstevel@tonic-gate extern	int	pr_unkill(prnode_t *, int);
3507c478bd9Sstevel@tonic-gate extern	int	pr_nice(proc_t *, int, cred_t *);
3517c478bd9Sstevel@tonic-gate extern	void	pr_setentryexit(proc_t *, sysset_t *, int);
3527c478bd9Sstevel@tonic-gate extern	int	pr_set(proc_t *, long);
3537c478bd9Sstevel@tonic-gate extern	int	pr_unset(proc_t *, long);
3547c478bd9Sstevel@tonic-gate extern	void	pr_sethold(prnode_t *, sigset_t *);
355a02120c4SAndy Fiddaman extern	file_t	*pr_getf(proc_t *, uint_t, short *);
35637e2cd25SPatrick Mooney extern	void	pr_releasef(file_t *);
3577c478bd9Sstevel@tonic-gate extern	void	pr_setfault(proc_t *, fltset_t *);
3587c478bd9Sstevel@tonic-gate extern	int	prusrio(proc_t *, enum uio_rw, struct uio *, int);
3597c478bd9Sstevel@tonic-gate extern	int	prwritectl(vnode_t *, struct uio *, cred_t *);
3607c478bd9Sstevel@tonic-gate extern	int	prlock(prnode_t *, int);
3617c478bd9Sstevel@tonic-gate extern	void	prunmark(proc_t *);
3627c478bd9Sstevel@tonic-gate extern	void	prunlock(prnode_t *);
3637c478bd9Sstevel@tonic-gate extern	size_t	prpdsize(struct as *);
3647c478bd9Sstevel@tonic-gate extern	int	prpdread(proc_t *, uint_t, struct uio *);
3657c478bd9Sstevel@tonic-gate extern	size_t	oprpdsize(struct as *);
3667c478bd9Sstevel@tonic-gate extern	int	oprpdread(struct as *, uint_t, struct uio *);
3677c478bd9Sstevel@tonic-gate extern	void	prgetaction(proc_t *, user_t *, uint_t, struct sigaction *);
3687c478bd9Sstevel@tonic-gate extern	void	prgetusage(kthread_t *, struct prhusage *);
3697c478bd9Sstevel@tonic-gate extern	void	praddusage(kthread_t *, struct prhusage *);
3707c478bd9Sstevel@tonic-gate extern	void	prcvtusage(struct prhusage *, prusage_t *);
3717c478bd9Sstevel@tonic-gate extern	void	prscaleusage(prhusage_t *);
3727c478bd9Sstevel@tonic-gate extern	kthread_t *prchoose(proc_t *);
3737c478bd9Sstevel@tonic-gate extern	void	allsetrun(proc_t *);
3747c478bd9Sstevel@tonic-gate extern	int	setisempty(uint32_t *, uint_t);
3757c478bd9Sstevel@tonic-gate extern	int	pr_u32tos(uint32_t, char *, int);
3767c478bd9Sstevel@tonic-gate extern	vnode_t	*prlwpnode(prnode_t *, uint_t);
3777c478bd9Sstevel@tonic-gate extern	prnode_t *prgetnode(vnode_t *, prnodetype_t);
3787c478bd9Sstevel@tonic-gate extern	void	prfreenode(prnode_t *);
3797c478bd9Sstevel@tonic-gate extern	void	pr_object_name(char *, vnode_t *, struct vattr *);
3807c478bd9Sstevel@tonic-gate extern	int	set_watched_area(proc_t *, struct watched_area *);
3817c478bd9Sstevel@tonic-gate extern	int	clear_watched_area(proc_t *, struct watched_area *);
3827c478bd9Sstevel@tonic-gate extern	void	pr_free_watchpoints(proc_t *);
3837c478bd9Sstevel@tonic-gate extern	proc_t	*pr_cancel_watch(prnode_t *);
3847c478bd9Sstevel@tonic-gate extern	struct seg *break_seg(proc_t *);
38572a6dc12SPatrick Mooney extern	void	prgethold(kthread_t *, sigset_t *);
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate /*
3887c478bd9Sstevel@tonic-gate  * Machine-dependent routines (defined in prmachdep.c).
3897c478bd9Sstevel@tonic-gate  */
3907c478bd9Sstevel@tonic-gate extern	void	prgetprregs(klwp_t *, prgregset_t);
3917c478bd9Sstevel@tonic-gate extern	void	prsetprregs(klwp_t *, prgregset_t, int);
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32_IMPL)
3947c478bd9Sstevel@tonic-gate extern	void	prgetprregs32(klwp_t *, prgregset32_t);
3957c478bd9Sstevel@tonic-gate extern	void	prgregset_32ton(klwp_t *, prgregset32_t, prgregset_t);
3967c478bd9Sstevel@tonic-gate extern	void	prgetprfpregs32(klwp_t *, prfpregset32_t *);
3977c478bd9Sstevel@tonic-gate extern	void	prsetprfpregs32(klwp_t *, prfpregset32_t *);
3987c478bd9Sstevel@tonic-gate extern	size_t	prpdsize32(struct as *);
3997c478bd9Sstevel@tonic-gate extern	int	prpdread32(proc_t *, uint_t, struct uio *);
4007c478bd9Sstevel@tonic-gate extern	size_t	oprpdsize32(struct as *);
4017c478bd9Sstevel@tonic-gate extern	int	oprpdread32(struct as *, uint_t, struct uio *);
4027c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32_IMPL */
4037c478bd9Sstevel@tonic-gate 
4047c478bd9Sstevel@tonic-gate extern	void	prpokethread(kthread_t *t);
4057c478bd9Sstevel@tonic-gate extern	int	prgetrvals(klwp_t *, long *, long *);
4067c478bd9Sstevel@tonic-gate extern	void	prgetprfpregs(klwp_t *, prfpregset_t *);
4077c478bd9Sstevel@tonic-gate extern	void	prsetprfpregs(klwp_t *, prfpregset_t *);
4087c478bd9Sstevel@tonic-gate extern	int	prhasfp(void);
4097c478bd9Sstevel@tonic-gate extern	caddr_t	prgetstackbase(proc_t *);
4107c478bd9Sstevel@tonic-gate extern	caddr_t	prgetpsaddr(proc_t *);
4117c478bd9Sstevel@tonic-gate extern	int	prisstep(klwp_t *);
4127c478bd9Sstevel@tonic-gate extern	void	prsvaddr(klwp_t *, caddr_t);
4137c478bd9Sstevel@tonic-gate extern	int	prfetchinstr(klwp_t *, ulong_t *);
4147c478bd9Sstevel@tonic-gate extern	ushort_t prgetpctcpu(uint64_t);
4157c478bd9Sstevel@tonic-gate 
416*ed093b41SRobert Mustacchi /*
417*ed093b41SRobert Mustacchi  * This set of routines is used by platforms to implement support for the
418*ed093b41SRobert Mustacchi  * 'xregs' or extended registers in /proc. Unlike other registers which
419*ed093b41SRobert Mustacchi  * generally have a well-defined value determined by the ABI that never changes,
420*ed093b41SRobert Mustacchi  * we expect these to change.
421*ed093b41SRobert Mustacchi  *
422*ed093b41SRobert Mustacchi  * An important thing to note is that you'll see we have moved away from a
423*ed093b41SRobert Mustacchi  * traditional version of a fixed size, non-opaque definition of the
424*ed093b41SRobert Mustacchi  * prxregset_t. This is because the size varies and we don't want applications
425*ed093b41SRobert Mustacchi  * to incorrectly bake a real definition in and cause problems where extending
426*ed093b41SRobert Mustacchi  * it becomes very hard to do (ala the prgregset_t and prfregset_t). This is a
427*ed093b41SRobert Mustacchi  * little more work for everyone implementing it, but it does ensure that we are
428*ed093b41SRobert Mustacchi  * generally in better shape.
429*ed093b41SRobert Mustacchi  *
430*ed093b41SRobert Mustacchi  * Here are the semantics of what these are required to do and how the fit
431*ed093b41SRobert Mustacchi  * together:
432*ed093b41SRobert Mustacchi  *
433*ed093b41SRobert Mustacchi  *   o prhasx		Determine if the process in question supports the
434*ed093b41SRobert Mustacchi  *			extended register sets. Note, this is may be a
435*ed093b41SRobert Mustacchi  *			process-specific setting due to things like whether or
436*ed093b41SRobert Mustacchi  *			not the FPU is enabled or other things.
437*ed093b41SRobert Mustacchi  *
438*ed093b41SRobert Mustacchi  *   o prgetxregsize	This returns the size of the actual xregs file for a
439*ed093b41SRobert Mustacchi  *			given process. This may change between processes because
440*ed093b41SRobert Mustacchi  *			not every process may have the same set of extended
441*ed093b41SRobert Mustacchi  *			features enabled (e.g. AMX on x86). If xregs is not
442*ed093b41SRobert Mustacchi  *			supported then this should return 0. If xregs are
443*ed093b41SRobert Mustacchi  *			supported, then returning zero will lead other
444*ed093b41SRobert Mustacchi  *			operations to fail.
445*ed093b41SRobert Mustacchi  *
446*ed093b41SRobert Mustacchi  *   o prwriteminxreg	This is used by the prwritectl() and related worlds to
447*ed093b41SRobert Mustacchi  *			determine the minimum amount of data that much be
448*ed093b41SRobert Mustacchi  *			present to determine if the actual size of a write is
449*ed093b41SRobert Mustacchi  *			valid. If xregs is not supported, then this should
450*ed093b41SRobert Mustacchi  *			return B_FALSE. If xregs is supported, this may return 0
451*ed093b41SRobert Mustacchi  *			if no additional information is required to determine
452*ed093b41SRobert Mustacchi  *			the appropriate size to copy in. This would be the case
453*ed093b41SRobert Mustacchi  *			if the xregs structure is a fixed size.
454*ed093b41SRobert Mustacchi  *
455*ed093b41SRobert Mustacchi  *   o prwritesizexreg	This is meant to indicate how much data is required to
456*ed093b41SRobert Mustacchi  *			be copied in for a given xregs write. The base data will
457*ed093b41SRobert Mustacchi  *			already be present from having called prwriteminxreg
458*ed093b41SRobert Mustacchi  *			previously. If xregs are not supported this should
459*ed093b41SRobert Mustacchi  *			return B_FALSE.
460*ed093b41SRobert Mustacchi  *
461*ed093b41SRobert Mustacchi  *			There is a wrinkle in this which is not true of other
462*ed093b41SRobert Mustacchi  *			callers. The data that we are given is not guaranteed to
463*ed093b41SRobert Mustacchi  *			be aligned in the slightest due to the need to support
464*ed093b41SRobert Mustacchi  *			both ILP32 and LP64!
465*ed093b41SRobert Mustacchi  *
466*ed093b41SRobert Mustacchi  *   o prgetprxregs	This is a request to fill in the xregs data. Right now
467*ed093b41SRobert Mustacchi  *			the system guarantees that the buffer size is at least
468*ed093b41SRobert Mustacchi  *			the result of the prgetprxregs() call for this process.
469*ed093b41SRobert Mustacchi  *			Callers may assume that the process remains locked
470*ed093b41SRobert Mustacchi  *			between the two so that the size doesn't change. This
471*ed093b41SRobert Mustacchi  *			will not be called for processes where prhasx() return
472*ed093b41SRobert Mustacchi  *			false.
473*ed093b41SRobert Mustacchi  *
474*ed093b41SRobert Mustacchi  *   o prsetprxregs	This is a request to set the xregs data. The only
475*ed093b41SRobert Mustacchi  *			assumption that should be made is that the validation of
476*ed093b41SRobert Mustacchi  *			the size in prwritesizexreg() has been performed. Users
477*ed093b41SRobert Mustacchi  *			can and will potentially try to trick us with invalid
478*ed093b41SRobert Mustacchi  *			values. Do not blindly apply the supplied xregs.
479*ed093b41SRobert Mustacchi  *
480*ed093b41SRobert Mustacchi  *			If xregs are not supported this should return EINVAL.
481*ed093b41SRobert Mustacchi  *			While yes other errnos may make more sense, that is what
482*ed093b41SRobert Mustacchi  *			we have always returned in /proc for this case.
483*ed093b41SRobert Mustacchi  */
484*ed093b41SRobert Mustacchi extern	int	prhasx(proc_t *);
485*ed093b41SRobert Mustacchi extern	size_t	prgetprxregsize(proc_t *);
486*ed093b41SRobert Mustacchi extern	void	prgetprxregs(klwp_t *, prxregset_t *);
487*ed093b41SRobert Mustacchi extern	boolean_t prwriteminxreg(size_t *);
488*ed093b41SRobert Mustacchi extern	boolean_t prwritesizexreg(const void *, size_t *);
489*ed093b41SRobert Mustacchi extern	int	prsetprxregs(klwp_t *, prxregset_t *);
490*ed093b41SRobert Mustacchi 
4917c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
4947c478bd9Sstevel@tonic-gate }
4957c478bd9Sstevel@tonic-gate #endif
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate #endif	/* _SYS_PROC_PRDATA_H */
498