/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* bos72L src/bos/usr/include/procinfo.h 1.71.1.8                         */
/*                                                                        */
/* Licensed Materials - Property of IBM                                   */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 1988,2018              */
/* All Rights Reserved                                                    */
/*                                                                        */
/* US Government Users Restricted Rights - Use, duplication or            */
/* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.      */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/* @(#)19       1.71.1.8  src/bos/usr/include/procinfo.h, sysproc, bos72L, l2018_28A6 7/6/18 16:59:17 */
/*
 *   COMPONENT_NAME: SYSPROC
 *
 *   FUNCTIONS: 
 *
 *   ORIGINS: 27, 83
 *
 *
 */
/*
 * LEVEL 1,  5 Years Bull Confidential Information
 */

#ifndef	_H_PROCINFO
#define	_H_PROCINFO

/*
 * You really can't use a header like this one without specifying
 * _ALL_SOURCE.  If you didn't, we try to let you get away with it,
 * but there are no guarantees!
 */
#ifndef _ALL_SOURCE
#define _ALL_SOURCE	/* to get rlimit64, rusage64 defs from resource.h */
#define _ALL_SOURCE_DEFINED
#endif

#include <sys/resource.h>
#include <sys/proc.h>
#include <sys/user.h>
#include <sys/wlm.h>
#include <sys/corralid.h>

#ifdef _ALL_SOURCE_DEFINED
#undef _ALL_SOURCE
#endif

/*
 * Warning: the procinfo, userinfo, and uicredinfo structures represent
 * obsolete interfaces.  These would not compile correctly in 64-bit mode.
 */

#ifndef __64BIT__
struct	procinfo
{
	/* identification/authentication */
	unsigned long	pi_pid;		/* process ID */
	unsigned long	pi_ppid;	/* parent process ID */
	unsigned long	pi_sid;		/* session identifier */
	unsigned long	pi_pgrp;	/* process group */
	unsigned long	pi_uid;		/* real user ID	*/
	unsigned long	pi_suid;	/* saved user ID */

	/* scheduler information */
	unsigned long	pi_pri;		/* priority, 0 high, 31 low */
	unsigned long	pi_nice;	/* nice for priority, 0 to 39 */
	unsigned long	pi_cpu;		/* processor usage, 0 to 80 */

	/* process states are defined in <sys/proc.h>: */
	unsigned long	pi_stat;	/* process state */

	/* process flags: same as pi_flags, except as noted */
	unsigned long	pi_flag;
	/* 0x00000400 SOMASK */
	/* 0x00000800 SWAKEONSIG */
	/* 0x00001000 SUSR */
	/* 0x00020000 SSEL */
	/* 0x01000000 PSIGDELIVER */
	/* 0x10000000 SPSEARLYALLOC */

	/* dispatcher fields */
	char		*pi_wchan;	/* wait channel */
	unsigned long	pi_wtype;	/* the wait type */

	/* miscellaneous */
	unsigned long	pi_adspace;	/* process address space */
	unsigned long	pi_majflt;	/* i/o page faults	 */
	unsigned long	pi_minflt;	/* non i/o page faults   */

	/* valid when the process is a zombie only */
	unsigned long	pi_utime;	/* this process user time */
	unsigned long	pi_stime;	/* this process system time */

	/* process statistics */
	unsigned long	pi_size;	/* size of image (pages) */
};

struct	userinfo
{
	/* credentials information */
	unsigned long	ui_luid;	/* login user id */
	unsigned long	ui_uid;		/* effective user identifier */
	unsigned long	ui_gid;		/* effective group identifier */

	/* accounting and profiling data */
	unsigned long	ui_start;	/* time at which process began */
	struct rusage	ui_ru;		/* this process' rusage info */
	struct rusage	ui_cru;		/* children's rusage info */

	/* resource limits info */
	struct rlimit	ui_rlimit[RLIM_NLIMITS];	/* resource limits */

	/* size of text */
	unsigned long	ui_tsize;	/* size of text */

	/* controlling tty info */
	unsigned long	ui_ttyp;	/* has a controlling terminal */
	unsigned long	ui_ttyd;	/* controlling terminal */
	unsigned long	ui_ttympx;	/*     "          "     channel */
	char	ui_comm[ MAXCOMLEN+1 ];		/* (truncated) program name */

	/* memory usage info */
	unsigned long	ui_drss;	/* data resident set size */
	unsigned long	ui_trss;	/* text resident set size */
	unsigned long	ui_dvm;		/* data virtual memory size */
	unsigned long	ui_prm;		/* percent real memory usage */
};

struct uicredinfo
{
	struct userinfo  uici_ui;	/* userinfo structure */
	struct ucred	 uici_cred;	/* cred structure */
};
#endif /* __64BIT__ */


#define SSLEEP		1
#define SRUN		3

#define SNOWAIT		0
#define SWEVENT		1
#define SWLOCK		2
#define SWTIMER		3
#define SWCPU		4
#define SWPGIN		5
#define SWPGOUT		6
#define SWPLOCK		7
#define SWFREEF		8
#define SWMEM		9

/*
 *	****	procsinfo, procsinfo64, procentry64 structures	****
 *
 * The procsinfo structure can be passed to the deprecated getprocs()
 * subroutine.  In 32-bit programs, the structure has fewer fields than in
 * 64-bit programs, and some of the fields are too narrow to represent values
 * used by 64-bit processes.
 *
 * The procsinfo64 structure can also be passed to the getprocs() subroutine.
 * It has size-invariant fields, so the structure size and fields are the same
 * in both 32-bit and 64-bit programs. The 64-bit ABI was updated in AIX V5, and
 * so some of the fields in procsinfo64 are too narrow for 64-bit processes. 
 *
 * The procentry64 structure can be passed to the preferred getprocs64()
 * subroutine. Like the procsinfo64 structure, it has size-invariant fields,
 * so the structure size and fields are the same in both 32-bit and 64-bit
 * programs. New applications should use getprocs64() rather than getprocs().
 */

#ifdef __64BIT__
/*
 * In 64-bit programs, procsinfo and procsinfo64 have the same layout.
 */
struct procsinfo
{
	/* identification/authentication */
	pid_t 		pi_pid;		/* process ID */
	pid_t		pi_ppid;	/* parent process ID */
	pid_t 		pi_sid;		/* session identifier */
	pid_t 		pi_pgrp;	/* process group */
	uid_t 		pi_uid;		/* real user ID */
	uid_t 		pi_suid;	/* saved user ID */

	/* controlling tty info */
	pid_t 		pi_ttyp;	/* has a controlling terminal */
	dev32_t		pi_ttyd;	/* controlling terminal */
	uint 		pi_ttympx;	/*      "         "     channel */

	/* scheduler information */
	uint 		pi_nice;	/* nice for priority */
	uint 		pi_state;	/* process state -- from proc.h */
	uint 		pi_flags;	/* process flags -- see below */
	uint 		pi_flags2;	/* process flags ext -- see below */
	uint 		pi_thcount;	/* thread count */
	uint		pi_cpu;		/* first thread's tick count */
	uint		pi_pri;		/* first thread's priority */

	/* memory */
	uint		pi_adspace;	/* process address space */
	long long 	pi_majflt;	/* i/o page faults */
	long long 	pi_minflt;	/* non i/o page faults */
	long long 	pi_repage;	/* repaging count */
	long long 	pi_size;	/* size of image (pages) */

	/* valid when the process is a zombie only */
	uint		pi_r1;		/* reserved field */
	uint 		pi_utime;	/* this process user time */
	uint		pi_r2;		/* reserved field */
	uint		pi_stime;	/* this process system time */

	/* credentials information */
	struct ucred	pi_cred;

	/* accounting and profiling data */
	struct rusage64	pi_ru;		/* this process' rusage info */
	struct rusage64	pi_cru;		/* children's rusage info */
	long long	pi_ioch;	/* I/O character count  */
	long long 	pi_irss;	/* accumulator for memory integral */
	long long 	pi_start;	/* time at which process began */

	/* resource limits info */
	struct rlimit   pi_rlimit[RLIM_NLIMITS];	/* resource limits */

	/* file management */
	short		pi_cmask;	/* mask for file creation */
	unsigned int	pi_cdir;	/* current directory of process */
	unsigned int	pi_rdir;	/* root directory of process */
	unsigned int	pi_maxofile;	/* maximum u_ofile index in use */

	/* program name */
	char		pi_comm[MAXCOMLEN+1];	/* (truncated) program name */

	/* memory usage info */
	unsigned long long pi_drss;	/* data resident set size */
	unsigned long long pi_trss;	/* text resident set size */
	unsigned long long pi_dvm;	/* data virtual memory size */
	unsigned long long pi_prm;	/* percent real memory usage */
	unsigned long long pi_tsize;	/* size of text */
	unsigned long long pi_dsize;	/* current break value */
	unsigned long long pi_sdsize;	/* data size from shared library*/

	/* signal management */
	unsigned long long pi_signal[NSIG32];	/* disposition of sigs */
	char		   pi_sigflags[NSIG32];	/* sig action flags */
	sigset32_t	   pi_sig;	/* pending sigs */
	/* WLM information. 34+31=65 bytes, padded to 72 */
	char		   pi_classname[2*(WLM_CLASSNAME_LENGTH+1)];
	char		   pi_tag[WLM_TAG_LENGTH+1];

	/* pagesize information */
	char		pi_data_l2psize;     /* log2 of a proc's data pg sz */
	char		pi_text_l2psize;     /* log2 of a proc's text pg sz */
	char		pi_stack_l2psize;    /* log2 of a proc's stack pg sz */

	cid_t		pi_cid;		   /* configured wpar id */
	char		pi_shm_l2psize;	   /* log2 of a proc's shared mem pg sz */
	char		pi_pad4;

	/* other scheduler information */
	uint		   pi_policy;		/* process policy */
	uint		   pi_ppri;		/* process priority */

	/* project information */
	unsigned long long pi_subproj;
	int		   pi_projid;
	short		   pi_acctflags;
	/* struct size rounded to 1.5 K */
	char 		   pi_resvd[10];	/* reserve space for future use */
};

#else /* __64BIT__ */
/*
 * In 32-bit programs, the procsinfo structure is obsolete, because it cannot
 * represent full values for 64-bit processes.
 */
struct procsinfo
{
	/* identification/authentication */
	unsigned long	pi_pid;		/* process ID */
	unsigned long	pi_ppid;	/* parent process ID */
	unsigned long	pi_sid;		/* session identifier */
	unsigned long	pi_pgrp;	/* process group */
	unsigned long	pi_uid;		/* real user ID */
	unsigned long	pi_suid;	/* saved user ID */

	/* scheduler information */
	unsigned long	pi_nice;	/* nice for priority */
	unsigned long	pi_state;	/* process state -- from proc.h */
	unsigned long	pi_flags;	/* process flags -- see below */
	unsigned long	pi_thcount;	/* thread count */

	/* memory */
	unsigned long	pi_adspace;	/* process address space */
	unsigned long	pi_majflt;	/* i/o page faults */
	unsigned long	pi_minflt;	/* non i/o page faults */
	unsigned long	pi_repage;	/* repaging count */
	unsigned long	pi_size;	/* size of image (pages) */

	/* valid when the process is a zombie only */
	unsigned long	pi_utime;	/* this process user time */
	unsigned long	pi_stime;	/* this process system time */

	/* credentials information */
	struct ucred	pi_cred;

	/* accounting and profiling data */
	unsigned long	pi_start;	/* time at which process began */
	struct rusage	pi_ru;		/* this process' rusage info */
	struct rusage	pi_cru;		/* children's rusage info */

	/* resource limits info */
	struct rlimit	pi_rlimit[RLIM_NLIMITS]; /* resource limits */

	/* size of text */
	unsigned long	pi_tsize;	/* size of text */

	/* controlling tty info */
	unsigned long	pi_ttyp;	/* has a controlling terminal */
	unsigned long	pi_ttyd;	/* controlling terminal */
	unsigned long	pi_ttympx;	/*	"	  "	channel */
	unsigned long	pi_dsize;	/* current break value */
	unsigned long	pi_sdsize;	/* data size from shared library */
	char		pi_comm[MAXCOMLEN+1]; /* (truncated) program name */

	/* memory usage info */
	unsigned long	pi_drss;	/* data resident set size */
	unsigned long	pi_trss;	/* text resident set size */
	unsigned long	pi_dvm;		/* data virtual memory size */
	unsigned long	pi_prm;		/* percent real memory usage */

	/* signal management */
	unsigned long	pi_signal[NSIG];/* disposition of sigs */
	char		pi_sigflags[NSIG];/* sig action flags */
	sigset_t	pi_sig;		/* pending sigs */

	/* file management */
	unsigned long	pi_cdir;	/* current directory of process */
	unsigned long	pi_rdir;	/* root directory of process */
	unsigned long	pi_maxofile;	/* maximum u_ofile index in use */

	long		pi_ioch;	/* I/O character count	*/

	/* project information */
	unsigned long long pi_subproj;
	int		   pi_projid;
	short		   pi_acctflags;
	short		   pi_pad5;
};
#endif /* __64BIT__ */

/* pi_flags */
#define SLOAD		0x00000001	/* user and uthread struct. pinned */
#define SNOSWAP		0x00000002	/* process can't be swapped out    */
#define SFORKSTACK	0x00000004	/* special fork stack is allocated */
#define STRC		0x00000008	/* process being traced		   */
#define SWTED		0x00000010	/* stopped while traced		   */
#define SFWTED		0x00000020	/* stopped after fork while traced */
#define SEWTED		0x00000040	/* stopped after exec while traced */
#define SLWTED		0x00000080	/* stopped after load/unload while */
#define SFIXPRI		0x00000100	/* fixed priority, ignoring p_cpu  */
#define SKPROC		0x00000200	/* Kernel processes		   */
#define SSIGNOCHLD	0x00000400	/* do send SIGCHLD on child's death*/
#define SSIGSET		0x00000800	/* process uses the SVID sigset int*/
#define SXPG1170	0x00001000	/* XPG SPEC1170 behavior assumed   */
#define SGETUREGS	0x00002000	/* save user regs on SVC	   */
#define STRACING	0x00004000	/* process is a debugger	   */
#define SMPTRACE	0x00008000	/* multi-process debugging	   */
#define SEXIT		0x00010000	/* process is exiting		   */
#define SLPDATA		0x00020000	/* large page data process	   */
#define SORPHANPGRP	0x00040000	/* orphaned process group	   */
#define STRCME		0x00080000	/* trace myself			   */
#define SPPNOCLDSTOP	0x00100000	/* Do not send parent process	   */
#define SEXECED		0x00200000	/* process has exec'd		   */
#define SHIGHRES	0x00400000	/* High resolution timer for thread*/
#define SRRMEMAFF	0x00800000	/* Strict round robin mem alloc	   */
#define SEXECING	0x01000000	/* process is execing		   */
#define SETRACE		0x02000000	/* dynamic tracing process	   */
#define SPSEARLYALLOC	0x04000000	/* allocates paging space early	   */
#define SCONTINUED	0x08000000	/* process continued after stop	   */
#define SPLOCK		0x10000000	/* process has plock'ed	memory	   */
#define SFASTWATCH	0x20000000	/* fast watchpoint enabled	   */
#define SMOBILE		0x40000000	/* process is in mobile corral	   */
#define SLATENCY	0x80000000	/* process is latency sensitive	   */

/* pi_flags2 */
#define S64BIT		0x00000001	/* this is a 64-bit process	   */
#define SWAITPROC	0x00000002	/* This is waitproc (one per cpu)  */
#define SFASTTRAP	0x00000004	/* fast trap capability enabled	   */
#define SSCHEDPROC	0x00000008	/* Slave scheduler (one per srad)  */
#define SRESTART	0x00000010	/* restart in progress		   */
#define SPRIMARY	0x00000020	/* Primary checkpoint process	   */
#define SCHKPNTABLE	0x00000040	/* Checkpointable process (env var)*/
#define SRESTARTED	0x00000080	/* Restarted process		   */
#define SRESTARTING	0x00000100	/* Restarting process		   */
#define SCHKTRC		0x00000200	/* traced at checkpoint		   */
#define	SRT_MPC		0x00000400	/* RT kernel: send MPC to preempt  */
#define	SRT_GRQ		0x00000800	/* process stays on global run queue */
#define	SWP_SIGNALED	0x00001000	/* sig posted for watchpoint hit   */
#define	SCRED		0x00002000	/* Per-thread credentials	   */
#define SCOREFILE	0x00004000	/* Core file created		   */
#define SCHKHANDLER	0x00008000	/* Has a checkpoint handler	   */
#define SDSA		0x00010000	/* 32-bit Dynamic Segment Allocation */
#define SCORENAME	0x00020000	/* Use new-style core name	   */
#define SPTHREADED	0x00040000	/* this is a pthreaded process	   */
#define SLPDATAMUST	0x00080000	/* mandatory large page data proc  */
#define SMCMMEMAFF	0x00100000	/* mcm local memory allocation	   */
#define SPIDCRIT	0x00200000	/* Critical process - UE GARD	   */
#define SFORKCRIT	0x00400000	/* Critical process - UE GARD	   */
#define SFCONTINUED	0x00800000	/* was force continued		   */
#define SNOCKPTSHM	0x01000000	/* NEVER checkpoint shared memory  */
#define SINHERITED	0x02000000	/* init inherited on parent exit   */
#define SCORE_MMAP	0x04000000	/* dump non-anonymous mmap regions */
#define SCORE_NOSHM	0x08000000	/* do NOT dump SHM to corefile	   */
#define SPV_HOLD	0x10000000	/* freeproc will free this slot	   */
#define SUKEYAWARE	0x20000000	/* process has user keys enabled   */
#define SMPIJOB		0x40000000	/* MPI job (can use local RQ)	   */
#define STRAPSIG	0x80000000	/* ptrace trap handling		   */

/* ti_flag3 */
#define TLATENCY	    0x0040	/* Latency sensitive thread flag   */
#define TBOOSTED_LATENCY    0x0080	/* Thread boost latency dispatch   */

/*
 * The procsinfo64 structure has the same layout in both 32-bit and
 * 64-bit programs.  In 64-bit programs, the structure is the same as
 * the procsinfo structure.
 */
struct procsinfo64
{
	/* identification/authentication */
	pid_t 		pi_pid;		/* process ID */
	pid_t		pi_ppid;	/* parent process ID */
	pid_t 		pi_sid;		/* session identifier */
	pid_t 		pi_pgrp;	/* process group */
	uid_t 		pi_uid;		/* real user ID */
	uid_t 		pi_suid;	/* saved user ID */

	/* controlling tty info */
	pid_t 		pi_ttyp;	/* has a controlling terminal */
#ifdef __64BIT__
	dev32_t		pi_ttyd;	/* controlling terminal */
#else
	dev_t		pi_ttyd;	/* controlling terminal */
#endif
	uint 		pi_ttympx;	/*      "         "     channel */

	/* scheduler information */
	uint 		pi_nice;	/* nice for priority */
	uint 		pi_state;	/* process state -- from proc.h */
	uint 		pi_flags;	/* process flags -- see above */
	uint 		pi_flags2;	/* process flags ext -- see above */
	uint 		pi_thcount;	/* thread count */
	uint		pi_cpu;		/* first thread's tick count */
	uint		pi_pri;		/* first thread's priority */

	/* memory */
	uint		pi_adspace;	/* process address space */
	__INTPAD(pi_pad1)		/* padding if required */
	long long 	pi_majflt;	/* i/o page faults */
	long long 	pi_minflt;	/* non i/o page faults */
	long long 	pi_repage;	/* repaging count */
	long long 	pi_size;	/* size of image (pages) */

	/* valid when the process is a zombie only */
	uint		pi_r1;		/* reserved field */
	uint 		pi_utime;	/* this process user time */
	uint		pi_r2;		/* reserved field */
	uint		pi_stime;	/* this process system time */

	/* credentials information */
	struct ucred	pi_cred;
	__INTPAD(pi_pad2)		/* padding if required */

	/* accounting and profiling data */
	struct rusage64	pi_ru;		/* this process' rusage info */
	struct rusage64	pi_cru;		/* children's rusage info */
	long long	pi_ioch;	/* I/O character count  */
	long long 	pi_irss;	/* accumulator for memory integral */
	long long 	pi_start;	/* time at which process began */

	/* resource limits info */
	struct rlimit64 pi_rlimit[RLIM_NLIMITS];	/* resource limits */
	
	/* file management */
	short		pi_cmask;	/* mask for file creation */
	unsigned int	pi_cdir;	/* current directory of process */
	unsigned int	pi_rdir;	/* root directory of process */
	unsigned int	pi_maxofile;	/* maximum u_ofile index in use */

	/* program name */
	char		pi_comm[MAXCOMLEN+1];	/* (truncated) program name */
	__INTPAD(pi_pad3)		/* padding if required */

	/* memory usage info */
	unsigned long long pi_drss;	/* data resident set size */
	unsigned long long pi_trss;	/* text resident set size */
	unsigned long long pi_dvm;	/* data virtual memory size */
	unsigned long long pi_prm;	/* percent real memory usage */
	unsigned long long pi_tsize;	/* size of text */
	unsigned long long pi_dsize;	/* current break value */
	unsigned long long pi_sdsize;	/* data size from shared library*/

	/* signal management */
#ifdef __64BIT__
	unsigned long long pi_signal[NSIG32];	/* disposition of sigs */
	char		   pi_sigflags[NSIG32];	/* sig action flags */
	sigset32_t	   pi_sig;	/* pending sigs */
#else
	unsigned long long pi_signal[NSIG];	/* disposition of sigs */
	char		   pi_sigflags[NSIG];	/* sig action flags */
	sigset_t	   pi_sig;	/* pending sigs */
#endif
	/* WLM information. 34+31=65 bytes, padded to 72 */
	char		   pi_classname[2*(WLM_CLASSNAME_LENGTH+1)];
	char		   pi_tag[WLM_TAG_LENGTH+1];

	/* pagesize information */
	char		pi_data_l2psize;     /* log2 of a proc's data pg sz */
	char		pi_text_l2psize;     /* log2 of a proc's text pg sz */
	char		pi_stack_l2psize;    /* log2 of a proc's stack pg sz */

	cid_t		pi_cid;		     /* configured wpar id */
	char		pi_shm_l2psize;	   /* log2 of a proc's shared mem pg sz */
	char		pi_pad4;

	/* other scheduler information */
	uint		   pi_policy;		/* process policy */
	uint		   pi_ppri;		/* process priority */

	/* project information */
	unsigned long long pi_subproj;
	int		   pi_projid;
	short		   pi_acctflags;
	
	/* struct size rounded to 1.5 K */
	char 		   pi_resvd[10];	/* reserve space for future use */
};

#define IS_PROC64(x)	((x)->pi_flags2 & S64BIT)

/*
 * The size of the fdsinfox section in core file can be obtained by
 * either  1] FD_HW_MARK(&(c_u.U_proc)) * sizeof(fdsinfox)
 * or      2] c_loader - c_fdsinfox
 * NOTE: c_xxxx fields are in core_dumpx structure in core.h.
 */
#define FD_HW_MARK(x)	((x)->pi_maxofile)

/*
 * For backward compatibility purpose, define OPEN_SHRT_MAX to have the 
 * same value of the old OPEN_MAX.
 * This allows the existing applications that use struct fdsinfo/fdsinfo64
 * to continue to work in AIX 520 or later releases as long as the number of 
 * open file descriptors per process does not > SHRT_MAX.
 */ 
#define OPEN_SHRT_MAX   SHRT_MAX 


/* Struct fdsinfo_100K and fdsinfo64_100K are to allow information of more
 * than 32K file descriptors returned. 
 */
#define OPEN_100K_MAX   OPEN_MAX

struct fdsinfox
{
	unsigned int	fp;
	unsigned short	flags;
	unsigned short	count;
};

struct fdsinfo
{
	struct fdsinfox pi_ufd[OPEN_SHRT_MAX];
};

/*
 * The fdsinfo_100K structure is identical to the fdsinfo structure above,
 * except that the number of possible file descriptor entries can grow up
 * to the new value of OPEN_MAX (>32K) in AIX 520.
 */
struct fdsinfo_100K
{
	struct fdsinfox pi_ufd[OPEN_100K_MAX];
};

/*
 * The fdsinfo_2000 structure is identical to the fdsinfo structure above,
 * except that the number of possible file descriptor entries is hard coded
 * to 2000 to match the limit from earlier releases of AIX.
 *
 * This structure may be used when recompiling a getprocs()
 * application that requests fdsinfo output to avoid the costs of the
 * larger fdsinfo structure defined above.  Note that getprocs() will
 * fail (errno EMFILE) if the fdsinfo_2000 structure is used, but the
 * process being examined has more than 2000 open file descriptors.
 */
struct fdsinfo_2000
{
	struct fdsinfox pi_ufd[2000];
};

/*
 * The procentry64 structure is the same in both 32-bit and 64-bit programs.
 * This structure is used with the getprocs64() subroutine.
 */
struct procentry64
{
	/* identification/authentication */
	pid32_t		pi_pid;		/* process ID */
	pid32_t		pi_ppid;	/* parent process ID */
	pid32_t		pi_sid;		/* session identifier */
	pid32_t		pi_pgrp;	/* process group */
	uid_t 		pi_uid;		/* real user ID */
	uid_t 		pi_suid;	/* saved user ID */

	/* controlling tty info */
	pid32_t		pi_ttyp;	/* has a controlling terminal */
	uint		pi_pad0;	/* alignment padding */
	dev64_t		pi_ttyd;	/* controlling terminal */
	longlong_t	pi_ttympx;	/*      "         "     channel */

	/* scheduler information */
	uint 		pi_nice;	/* nice for priority */
	uint 		pi_state;	/* process state -- from proc.h */
	uint 		pi_flags;	/* process flags -- see above */
	uint 		pi_flags2;	/* process flags ext -- see above */
	uint 		pi_thcount;	/* thread count */
	uint		pi_cpu;		/* first thread's tick count */
	uint		pi_pri;		/* first thread's priority */

	/* file management */
	uint		pi_maxofile;	/* maximum u_ofile index in use */
	u_longlong_t	pi_cdir;	/* current directory of process */
	u_longlong_t	pi_rdir;	/* root directory of process */
	short		pi_cmask;	/* mask for file creation */
	short		pi_pad1;	/* alignment padding */

	/* program name */
	char		pi_comm[MAXCOMLEN+1];	/* (truncated) program name */

	/* memory */
	u_longlong_t 	pi_adspace;	/* process address space */
	longlong_t 	pi_majflt;	/* i/o page faults */
	longlong_t 	pi_minflt;	/* non i/o page faults */
	longlong_t 	pi_repage;	/* repaging count */
	longlong_t 	pi_size;	/* size of image (pages) */

	/* valid when the process is a zombie only */
	time64_t	pi_utime;	/* this process user time */
	time64_t	pi_stime;	/* this process system time */

	/* credentials information */
	cred_ext_t 	pi_cred;

	/* accounting and profiling data */
	struct trusage64 pi_ru;		/* this process' rusage info */
	struct trusage64 pi_cru;	/* children's rusage info */
	longlong_t	pi_ioch;	/* I/O character count  */
	longlong_t 	pi_irss;	/* accumulator for memory integral */
	time64_t 	pi_start;	/* time at which process began */

	/* resource limits info */
	struct rlimit64 pi_rlimit[RLIM_NLIMITS];	/* resource limits */

	/* memory usage info */
	u_longlong_t 	pi_drss;	/* data resident set size */
	u_longlong_t 	pi_trss;	/* text resident set size */
	u_longlong_t 	pi_dvm;		/* data virtual memory size */
	u_longlong_t 	pi_prm;		/* percent real memory usage */
	u_longlong_t 	pi_tsize;	/* size of text */
	u_longlong_t 	pi_dsize;	/* current break value */
	u_longlong_t 	pi_sdsize;	/* data size from shared library*/

	/* signal management */
	u_longlong_t 	pi_signal[NSIG64];/* disposition of sigs */
	uint		pi_sigflags[NSIG64];/* sig action flags */
	sigset64_t	pi_sig;		/* pending sigs */

	/* WLM information. 34+31=65 bytes, padded to 72 */
	char		pi_classname[2*(WLM_CLASSNAME_LENGTH+1)];
	char		pi_tag[WLM_TAG_LENGTH+1];

	/* pagesize information */
	char		pi_data_l2psize;     /* log2 of a proc's data pg sz */
	char		pi_text_l2psize;     /* log2 of a proc's text pg sz */
	char		pi_stack_l2psize;    /* log2 of a proc's stack pg sz */

	cid_t		pi_cid;		     /* configured wpar id */
	char		pi_shm_l2psize;	     /* log2 of a proc's shared mem pg sz */
	char		pi_aslr;	/* non-zero if process is randomized */

	suseconds_t	pi_chk_utime;	/* user time at checkpoint  */
	suseconds_t	pi_chk_ctime;	/* child time at checkpoint  */

	/* other scheduler information */
	uint		pi_policy;	     /* process policy */
	uint		pi_ppri;	     /* process priority */

	/* loader segment for 64bit process */
	u_longlong_t	pi_adspace_ldr;

	/* project information */
	unsigned long long pi_subproj;
	int		   pi_projid;
	short		   pi_acctflags;
	char		   pi_boost_type;  /* flexctl process boost type  */
	char		   pi_boost_level; /* flexctl process boost level */
	unsigned long long pi_cvmem;	 /* size of compressed virt mem (bytes)	 */
	
	unsigned int	pi_stkorigsz;	/* Randomization values */
	unsigned int	pi_stkdelta;
	unsigned int	pi_aslr1;
	unsigned int	pi_aslr2;

	unsigned long long pi_resvd[5];
};

/*
 * The fdsinfo64 and fdsinfo64_100K structures both contain an array of
 * fdsinfox64 structure, which are used with the getprocs64()
 * subroutine, available to both 32- and 64-bit programs.
 */
struct fdsinfox64
{
	u_longlong_t	fp;		/* pointer to struct file	*/
	unsigned short  flags;		/* user fd table flags		*/
	unsigned short  count;		/* user fd reference count	*/
	unsigned int	pad;		/* reserved 			*/
};

struct fdsinfo64
{
	struct fdsinfox64 pi_ufd[OPEN_SHRT_MAX];
};

/*
 * The fdsinfo64_100K structure is identical to the fdsinfo64 structure above,
 * except that the number of array elements is larger.
 */
struct fdsinfo64_100K
{
	struct fdsinfox64 pi_ufd[OPEN_100K_MAX];
};

/* 
 * ***	thrdsinfo, thrdsinfo64, thrdentry64, thrdentry64_v2 structures	****
 *
 * The thrdsinfo structure can be passed by a 32-bit programs to the deprecated
 * getthrds() subroutine, but some of the fields are too narrow for examining
 * 64-bit threads.
 *
 * The thrdsinfo64 structure has size-invariant fields, and can be passed by
 * both 32- and 64-bit programs to the deprecated getthrds() subroutine.
 *
 * The thrdentry64 structure is also size-invariant and can be passed to the
 * preferred getthrds64() subroutine. This structure is also used to describe
 * the core file format for 64-bit processes.
 *
 * The thrdentry64_v2 structure is an extension of the thrdentry64 structure.
 * It can also be used with the getthrds64() subroutine.  The extra fields
 * in the thrdentry64_v2 structure are not found in the core file.
 */

struct thrdsinfo
{
	/* identification */
	unsigned long	ti_tid;		/* thread ID */
	unsigned long	ti_pid;		/* process ID */

	/* scheduler information */
	unsigned long	ti_policy;	/* scheduling policy */
	unsigned long	ti_pri;		/* priority */
	unsigned long	ti_state;	/* thread state -- from thread.h */
	unsigned long	ti_flag;	/* thread flags -- from thread.h */
	unsigned long	ti_scount;	/* suspend count */
	unsigned long	ti_wtype;	/* type of thread wait */
	unsigned long	ti_wchan;	/* wait channel */
	unsigned long	ti_cpu;		/* processor usage */
	unsigned long	ti_cpuid;	/* processor on which I'm bound */

	/* signal management */
	sigset_t	ti_sigmask;	/* sigs to be blocked */
	sigset_t	ti_sig;		/* pending sigs */
	unsigned long	ti_code;	/* iar of exception */
	struct sigcontext *ti_scp;	/* sigctx location in user space */
	char		ti_cursig;	/* current/last signal taken */
	char		ti_pad1[3];	/* pad to word boundary */

	/* miscellaneous */
	unsigned long	ti_ticks;	/* # of ticks since dispatched */
	unsigned long	ti_dispct;	/* number of dispatches */
	unsigned long	ti_fpuct;	/* number of FP unavail ints. */
	unsigned long	ti_ustk;	/* user stack pointer */
	unsigned long	ti_resvd[5];	/* reserve space for future use */
};

/*
 * The thrdsinfo64 structure is size-invariant.
 */
struct thrdsinfo64 {
	/* identification */
#ifdef __64BIT__
	tid32_t		   ti_tid;	/* thread identifier */
#else
	tid_t		   ti_tid;	/* thread identifier */
#endif
	pid_t		   ti_pid;	/* process identifier */

	/* scheduler information */
	uint		   ti_pri;	/* current effective priority */
	uint		   ti_policy;	/* scheduling policy */
	uint		   ti_state;	/* thread state -- from thread.h */
	uint 		   ti_flag;	/* thread flags -- from thread.h */
	uint 		   ti_scount;	/* suspend count */
	uint 		   ti_wtype;	/* type of thread wait */
	unsigned long long ti_wchan;	/* wait channel */
	uint 		   ti_cpu;	/* processor usage */
	cpu_t 		   ti_cpuid;	/* processor on which I'm bound */
	cpu_t 		   ti_affinity;	/* processor on which I last ran */

	/* signal management */
#ifdef __64BIT__
	sigset32_t 	   ti_sigmask;	/* thread signal mask */
	sigset32_t 	   ti_sig;	/* pending signals */
#else
	sigset_t 	   ti_sigmask;	/* thread signal mask */
	sigset_t 	   ti_sig;	/* pending signals */
#endif
	unsigned long long ti_code;	/* iar of exception */
	unsigned long long ti_scp;	/* sigctx location in user space */
	char		   ti_cursig;	/* current/last signal taken */
	char		   ti_pad[7];	/* spare fields */
#ifdef __64BIT__
	sigset32_t	   ti_oldmask;	/* mask from before sigpause */
#else
	sigset_t	   ti_oldmask;	/* mask from before sigpause */
#endif
	unsigned long long ti_stkb;	/* current execution stack base */
	unsigned long long ti_ucontext;	/* current ucontext ptr */
	unsigned long long ti_sigsp;	/* special signal stack */
	unsigned long long ti_sigssz;	/* size of alternate signal stack */

	/* User thread management */
	unsigned long long ti_userdata;	/* user-owned data */
	unsigned long long ti_errnopp;	/* address of pointer to errno */
	unsigned long long ti_ustk;	/* user stack pointer from last sc */

	/* miscellaneous */
	uint 		   ti_ticks;	/* # of ticks since dispatched */
	uint		   ti_dispct;	/* number of dispatches */
	uint		   ti_fpuct;	/* number of FP unavail ints. */
	uint		   ti_watch;	/* ptrace watchpoint information */

	/* other scheduler information */
	uint		   ti_nice;     /* thread nice value */

	uint 		   ti_resvd[6];	/* reserve space for future use */
	__INTPAD(ti_pad1)		/* padding if required */
};

/*
 * thrdentry64 provides size-invariant thread information.
 * This structure is to be used with getthrds64() interface.
 */
struct thrdentry64 {
	/* identification */
	tid64_t		   ti_tid;	/* thread identifier */
	pid32_t		   ti_pid;	/* process identifier */

	/* scheduler information */
	uint		   ti_pri;	/* current effective priority */
	uint		   ti_policy;	/* scheduling policy */
	uint		   ti_state;	/* thread state -- from thread.h */
	uint 		   ti_flag;	/* thread flags -- from thread.h */
	uint 		   ti_scount;	/* suspend count */
	uint 		   ti_wtype;	/* type of thread wait */
	uint 		   ti_cpu;	/* processor usage */
	cpu_t 		   ti_cpuid;	/* processor on which I'm bound */
	cpu_t 		   ti_affinity;	/* processor on which I last ran */
	uint		   ti_pad0;	/* alignment padding */
	unsigned long long ti_wchan;	/* wait channel */

	/* signal management */
	sigset64_t 	   ti_sigmask;	/* thread signal mask */
	sigset64_t 	   ti_sig;	/* pending signals */
	unsigned long long ti_code;	/* iar of exception */
	unsigned long long ti_scp;	/* sigctx location in user space */
	char		   ti_cursig;	/* current/last signal taken */
	char		   ti_pad;	/* spare field */
	sradid_t	   ti_home_sradid; /* thread home sradid */
	uint		   ti_flag2;	/* more flags */
	sigset64_t	   ti_oldmask;	/* mask from before sigpause */
	unsigned long long ti_stkb;	/* current execution stack base */
	unsigned long long ti_ucontext;	/* current ucontext ptr */
	unsigned long long ti_sigsp;	/* special signal stack */
	unsigned long long ti_sigssz;	/* size of alternate signal stack */

	/* User thread management */
	unsigned long long ti_userdata;	/* user-owned data */
	unsigned long long ti_errnopp;	/* address of pointer to errno */
	unsigned long long ti_ustk;	/* user stack pointer from last sc */

	/* miscellaneous */
	uint 		   ti_ticks;	/* # of ticks since dispatched */
	uint		   ti_dispct;	/* number of dispatches */
	uint		   ti_fpuct;	/* number of FP unavail ints. */
	uint		   ti_watch;	/* ptrace watchpoint information */

	/* accounting data */
	struct trusage64   ti_ru;	/* this thread's rusage info */

	/* other scheduler information */
	uint		   ti_nice;	/* thread nice value */
	uint		   ti_size;	/* size of struct returned to user */
	struct timestruc64_t ti_start;	/* thread start time */
	unsigned long long ti_local_dispct; /* thread dispatch local CPU */
};

/*
 * thrdentry64_v2:  Increased size thrdentry64_v2 struct.  
 *
 * The thrdentry64_v2 structure is an extension of the thrdentry64
 * structure.  The getthrds64() subroutine contains support for
 * callers passing either a thrdentry64 or a thrdentry64_v2 structure.
 *
 */
struct thrdentry64_v2 {
	/* identification */
	tid64_t		   ti_tid;	/* thread identifier */
	pid32_t		   ti_pid;	/* process identifier */

	/* scheduler information */
	uint		   ti_pri;	/* current effective priority */
	uint		   ti_policy;	/* scheduling policy */
	uint		   ti_state;	/* thread state -- from thread.h */
	uint 		   ti_flag;	/* thread flags -- from thread.h */
	uint 		   ti_scount;	/* suspend count */
	uint 		   ti_wtype;	/* type of thread wait */
	uint 		   ti_cpu;	/* processor usage */
	cpu_t 		   ti_cpuid;	/* processor on which I'm bound */
	cpu_t 		   ti_affinity;	/* processor on which I last ran */
	uint		   ti_pad0;	/* alignment padding */
	unsigned long long ti_wchan;	/* wait channel */

	/* signal management */
	sigset64_t 	   ti_sigmask;	/* thread signal mask */
	sigset64_t 	   ti_sig;	/* pending signals */
	unsigned long long ti_code;	/* iar of exception */
	unsigned long long ti_scp;	/* sigctx location in user space */
	char		   ti_cursig;	/* current/last signal taken */
	char		   ti_pad;	/* spare field */
	sradid_t	   ti_home_sradid; /* thread home sradid */
	uint		   ti_flag2;	/* more flags */
	sigset64_t	   ti_oldmask;	/* mask from before sigpause */
	unsigned long long ti_stkb;	/* current execution stack base */
	unsigned long long ti_ucontext;	/* current ucontext ptr */
	unsigned long long ti_sigsp;	/* special signal stack */
	unsigned long long ti_sigssz;	/* size of alternate signal stack */

	/* User thread management */
	unsigned long long ti_userdata;	/* user-owned data */
	unsigned long long ti_errnopp;	/* address of pointer to errno */
	unsigned long long ti_ustk;	/* user stack pointer from last sc */

	/* miscellaneous */
	uint 		   ti_ticks;	/* # of ticks since dispatched */
	uint		   ti_dispct;	/* number of dispatches */
	uint		   ti_fpuct;	/* number of FP unavail ints. */
	uint		   ti_watch;	/* ptrace watchpoint information */

	/* accounting data */
	struct trusage64   ti_ru;	/* this thread's rusage info */

	/* other scheduler information */
	uint		   ti_nice;	/* thread nice value */
	uint		   ti_size;	/* size of struct returned to user */
	struct timestruc64_t ti_start;	/* thread start time */
	unsigned long long ti_local_dispct; /* thread dispatch local CPU */
/*------------------ End of version 1, 424 bytes ---------------------------*/
	unsigned long long ti_near_dispct;/* thread dispatch near CPU */
	unsigned long long ti_far_dispct; /* thread dispatch far CPU */ 
	unsigned long long ti_latency_dispct; /* thread latency boosted dispatch */
	char		   ti_boost_type;  /* thread flexctl boost type	 */
	char		   ti_boost_level; /* thread flexctl boost level */
	short		   pad;
	uint		   ti_flag3;	/* more flags */
	long long	   t1_v2pad3[7];/* reserved for future use */ 
/*------------------ End of version 2, 512 bytes ---------------------------*/
};

#define THRDENTRY64_V1_SIZE (sizeof(struct thrdentry64))
#define THRDENTRY64_V2_SIZE (sizeof(struct thrdentry64_v2))

/*
 * ti_watch flags
 */
#define T_WP			0x1
#define T_WP_SVC		0x2
#define T_WP_FAST		0x4


#ifdef __cplusplus
extern "C" {
#endif

/* 
 * Prototypes for getprocs / getprocs64 
 *
 * The following prototypes use 'void *' to allow generic usage of these
 * functions with several different types. See the notes above each 
 * prototype (as well as the man pages) for more information.
 */

/* 
 * getprocs prototype
 *
 * 'procsinfo': struct procsinfo *procsinfo 	or 
 *              struct procsinfo64 *procsinfo
 *
 * 'fdsinfo'  : struct fdsinfo *fdsinfo
 */
int	getprocs (void *procsinfo, int sizproc, void *fdsinfo, int sizfd,
		  pid_t *index, int count);

/* 
 * getprocs64 prototype
 *
 * 'procsinfo': struct procentry64 *procsinfo
 *
 * 'fdsinfo'  : struct fdsinfo64 *fdsinfo
 */
int	getprocs64 (void *procsinfo, int sizproc, void *fdsinfo, int sizfd,
		    pid_t *index, int count);

#ifdef _KERNEL

/* kget_proc_info commands */
/* Determine if a given PID is valid */
#define VALIDATE_PID		1
/* Given a PGRP PID, return members of the process group */
#define GET_PGRP		2
/* Given a PID, return members of the same process group as PID is in */
#define GET_PGRP_BY_MEMBER	3
/* Given a PID, return procentry64 structure */
#define GET_PROCENTRY64		4

/* Error codes returned by kget_proc_info */
#define ESRCH_INVALID_PID		KERROR(ESRCH, sysalloc_BLOCK_00, 0x300)
#define EINVAL_NULL_SIZE		KERROR(EINVAL, sysalloc_BLOCK_00, 0x301)
#define EINVAL_NULL_DATA		KERROR(EINVAL, sysalloc_BLOCK_00, 0x302)
#define ERANGE_INSUFFICIENT_SIZE	KERROR(ERANGE, sysalloc_BLOCK_00, 0x303)
#define EPERM_INSUFFICIENT_PRIVS	KERROR(EPERM, sysalloc_BLOCK_00, 0x304)
#define EINVAL_INVALID_COMMAND		KERROR(EINVAL, sysalloc_BLOCK_00, 0x305)
#define EFAULT_INVALID_POINTER		KERROR(EINVAL, sysalloc_BLOCK_00, 0x306)

/* 
 * kget_procinfo prototype
 *
 * 'cmd'      : Command to run
 * 'id'       : PID or process group PID to retrieve information about
 * 'data'     : Pointer to storage space
 * 'size'     : Pointer to size of storage space
 */
    kerrno_t	kget_proc_info (int cmd, pid_t id, void *data, size_t *size);
#endif

/*
 * The 2nd parameter of getthrds() is a pointer to an array of either a
 * thrdsinfo or thrdsinfo64 structure.
 *
 * The 2nd parameter of getthrds64() is a pointer to an array of either a
 * thrdentry64 or thrdentry64_v2 structure.
 *
 */
extern  int     getthrds( pid_t, void *, int,  tid_t *, int );
extern  int     getthrds64( pid_t, void *, int, tid64_t *, int );

/*
 * 1st parameter of getargs() and getevars() may be either
 * struct procsinfo * or struct procentry64 *.
 */
extern  int     getargs( void *, int, char *, int );
extern  int     getevars( void *, int, char *, int );

#ifdef __cplusplus
}
#endif

#endif	/* _H_PROCINFO */
