xref: /onnv-gate/usr/src/lib/libproc/common/libproc.h (revision 10201:47013accbd9c)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52712Snn35248  * Common Development and Distribution License (the "License").
62712Snn35248  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
218509SRoger.Faulkner@Sun.COM 
220Sstevel@tonic-gate /*
238509SRoger.Faulkner@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
255272Sjhaslam  *
265272Sjhaslam  * Portions Copyright 2007 Chad Mynhier
270Sstevel@tonic-gate  */
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate  * Interfaces available from the process control library, libproc.
310Sstevel@tonic-gate  *
320Sstevel@tonic-gate  * libproc provides process control functions for the /proc tools
330Sstevel@tonic-gate  * (commands in /usr/proc/bin), /usr/bin/truss, and /usr/bin/gcore.
340Sstevel@tonic-gate  * libproc is a private support library for these commands only.
350Sstevel@tonic-gate  * It is _not_ a public interface, although it might become one
360Sstevel@tonic-gate  * in the fullness of time, when the interfaces settle down.
370Sstevel@tonic-gate  *
380Sstevel@tonic-gate  * In the meantime, be aware that any program linked with libproc in this
390Sstevel@tonic-gate  * release of Solaris is almost guaranteed to break in the next release.
400Sstevel@tonic-gate  *
410Sstevel@tonic-gate  * In short, do not use this header file or libproc for any purpose.
420Sstevel@tonic-gate  */
430Sstevel@tonic-gate 
440Sstevel@tonic-gate #ifndef	_LIBPROC_H
450Sstevel@tonic-gate #define	_LIBPROC_H
460Sstevel@tonic-gate 
470Sstevel@tonic-gate #include <stdlib.h>
480Sstevel@tonic-gate #include <unistd.h>
490Sstevel@tonic-gate #include <fcntl.h>
500Sstevel@tonic-gate #include <nlist.h>
510Sstevel@tonic-gate #include <door.h>
520Sstevel@tonic-gate #include <gelf.h>
530Sstevel@tonic-gate #include <proc_service.h>
540Sstevel@tonic-gate #include <rtld_db.h>
550Sstevel@tonic-gate #include <procfs.h>
560Sstevel@tonic-gate #include <rctl.h>
570Sstevel@tonic-gate #include <libctf.h>
580Sstevel@tonic-gate #include <sys/stat.h>
590Sstevel@tonic-gate #include <sys/statvfs.h>
600Sstevel@tonic-gate #include <sys/auxv.h>
610Sstevel@tonic-gate #include <sys/resource.h>
620Sstevel@tonic-gate #include <sys/socket.h>
630Sstevel@tonic-gate #include <sys/utsname.h>
640Sstevel@tonic-gate #include <sys/corectl.h>
650Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
660Sstevel@tonic-gate #include <sys/sysi86.h>
670Sstevel@tonic-gate #endif
680Sstevel@tonic-gate 
690Sstevel@tonic-gate #ifdef	__cplusplus
700Sstevel@tonic-gate extern "C" {
710Sstevel@tonic-gate #endif
720Sstevel@tonic-gate 
730Sstevel@tonic-gate /*
740Sstevel@tonic-gate  * Opaque structure tag reference to a process control structure.
750Sstevel@tonic-gate  * Clients of libproc cannot look inside the process control structure.
760Sstevel@tonic-gate  * The implementation of struct ps_prochandle can change w/o affecting clients.
770Sstevel@tonic-gate  */
780Sstevel@tonic-gate struct ps_prochandle;
790Sstevel@tonic-gate 
800Sstevel@tonic-gate /*
810Sstevel@tonic-gate  * Opaque structure tag reference to an lwp control structure.
820Sstevel@tonic-gate  */
830Sstevel@tonic-gate struct ps_lwphandle;
840Sstevel@tonic-gate 
850Sstevel@tonic-gate extern	int	_libproc_debug;	/* set non-zero to enable debugging fprintfs */
864753Srh87107 extern	int	_libproc_no_qsort;	/* set non-zero to inhibit sorting */
874753Srh87107 					/* of symbol tables */
88*10201SEdward.Pilatowicz@Sun.COM extern	int	_libproc_incore_elf;	/* only use in-core elf data */
890Sstevel@tonic-gate 
900Sstevel@tonic-gate #if defined(__sparc)
910Sstevel@tonic-gate #define	R_RVAL1	R_O0		/* register holding a function return value */
920Sstevel@tonic-gate #define	R_RVAL2	R_O1		/* 32 more bits for a 64-bit return value */
930Sstevel@tonic-gate #endif	/* __sparc */
940Sstevel@tonic-gate 
950Sstevel@tonic-gate #if defined(__amd64)
960Sstevel@tonic-gate #define	R_PC	REG_RIP
970Sstevel@tonic-gate #define	R_SP	REG_RSP
980Sstevel@tonic-gate #define	R_RVAL1	REG_RAX		/* register holding a function return value */
990Sstevel@tonic-gate #define	R_RVAL2	REG_RDX		/* 32 more bits for a 64-bit return value */
1000Sstevel@tonic-gate #elif defined(__i386)
1010Sstevel@tonic-gate #define	R_PC	EIP
1020Sstevel@tonic-gate #define	R_SP	UESP
1030Sstevel@tonic-gate #define	R_RVAL1	EAX		/* register holding a function return value */
1040Sstevel@tonic-gate #define	R_RVAL2	EDX		/* 32 more bits for a 64-bit return value */
1050Sstevel@tonic-gate #endif	/* __amd64 || __i386 */
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate #define	R_RVAL	R_RVAL1		/* simple function return value register */
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate /* maximum sizes of things */
1100Sstevel@tonic-gate #define	PRMAXSIG	(32 * sizeof (sigset_t) / sizeof (uint32_t))
1110Sstevel@tonic-gate #define	PRMAXFAULT	(32 * sizeof (fltset_t) / sizeof (uint32_t))
1120Sstevel@tonic-gate #define	PRMAXSYS	(32 * sizeof (sysset_t) / sizeof (uint32_t))
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate /* State values returned by Pstate() */
1150Sstevel@tonic-gate #define	PS_RUN		1	/* process is running */
1160Sstevel@tonic-gate #define	PS_STOP		2	/* process is stopped */
1170Sstevel@tonic-gate #define	PS_LOST		3	/* process is lost to control (EAGAIN) */
1180Sstevel@tonic-gate #define	PS_UNDEAD	4	/* process is terminated (zombie) */
1190Sstevel@tonic-gate #define	PS_DEAD		5	/* process is terminated (core file) */
1200Sstevel@tonic-gate #define	PS_IDLE		6	/* process has not been run */
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate /* Flags accepted by Pgrab() */
1230Sstevel@tonic-gate #define	PGRAB_RETAIN	0x01	/* Retain tracing flags, else clear flags */
1240Sstevel@tonic-gate #define	PGRAB_FORCE	0x02	/* Open the process w/o O_EXCL */
1250Sstevel@tonic-gate #define	PGRAB_RDONLY	0x04	/* Open the process or core w/ O_RDONLY */
1260Sstevel@tonic-gate #define	PGRAB_NOSTOP	0x08	/* Open the process but do not stop it */
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate /* Error codes from Pcreate() */
1290Sstevel@tonic-gate #define	C_STRANGE	-1	/* Unanticipated error, errno is meaningful */
1300Sstevel@tonic-gate #define	C_FORK		1	/* Unable to fork */
1310Sstevel@tonic-gate #define	C_PERM		2	/* No permission (file set-id or unreadable) */
1320Sstevel@tonic-gate #define	C_NOEXEC	3	/* Cannot execute file */
1330Sstevel@tonic-gate #define	C_INTR		4	/* Interrupt received while creating */
1340Sstevel@tonic-gate #define	C_LP64		5	/* Program is _LP64, self is _ILP32 */
1350Sstevel@tonic-gate #define	C_NOENT		6	/* Cannot find executable file */
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate /* Error codes from Pgrab(), Pfgrab_core(), and Pgrab_core() */
1380Sstevel@tonic-gate #define	G_STRANGE	-1	/* Unanticipated error, errno is meaningful */
1390Sstevel@tonic-gate #define	G_NOPROC	1	/* No such process */
1400Sstevel@tonic-gate #define	G_NOCORE	2	/* No such core file */
1410Sstevel@tonic-gate #define	G_NOPROCORCORE	3	/* No such proc or core (for proc_arg_grab) */
1420Sstevel@tonic-gate #define	G_NOEXEC	4	/* Cannot locate executable file */
1430Sstevel@tonic-gate #define	G_ZOMB		5	/* Zombie process */
1440Sstevel@tonic-gate #define	G_PERM		6	/* No permission */
1450Sstevel@tonic-gate #define	G_BUSY		7	/* Another process has control */
1460Sstevel@tonic-gate #define	G_SYS		8	/* System process */
1470Sstevel@tonic-gate #define	G_SELF		9	/* Process is self */
1480Sstevel@tonic-gate #define	G_INTR		10	/* Interrupt received while grabbing */
1490Sstevel@tonic-gate #define	G_LP64		11	/* Process is _LP64, self is ILP32 */
1500Sstevel@tonic-gate #define	G_FORMAT	12	/* File is not an ELF format core file */
1510Sstevel@tonic-gate #define	G_ELF		13	/* Libelf error, elf_errno() is meaningful */
1520Sstevel@tonic-gate #define	G_NOTE		14	/* Required PT_NOTE Phdr not present in core */
1530Sstevel@tonic-gate #define	G_ISAINVAL	15	/* Wrong ELF machine type */
1540Sstevel@tonic-gate #define	G_BADLWPS	16	/* Bad '/lwps' specification */
1555272Sjhaslam #define	G_NOFD		17	/* No more file descriptors */
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate /* Flags accepted by Prelease */
1590Sstevel@tonic-gate #define	PRELEASE_CLEAR	0x10	/* Clear all tracing flags */
1600Sstevel@tonic-gate #define	PRELEASE_RETAIN	0x20	/* Retain final tracing flags */
1610Sstevel@tonic-gate #define	PRELEASE_HANG	0x40	/* Leave the process stopped */
1620Sstevel@tonic-gate #define	PRELEASE_KILL	0x80	/* Terminate the process */
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate typedef	struct {	/* argument descriptor for system call (Psyscall) */
1650Sstevel@tonic-gate 	long	arg_value;	/* value of argument given to system call */
1660Sstevel@tonic-gate 	void	*arg_object;	/* pointer to object in controlling process */
1670Sstevel@tonic-gate 	char	arg_type;	/* AT_BYVAL, AT_BYREF */
1680Sstevel@tonic-gate 	char	arg_inout;	/* AI_INPUT, AI_OUTPUT, AI_INOUT */
1690Sstevel@tonic-gate 	ushort_t arg_size;	/* if AT_BYREF, size of object in bytes */
1700Sstevel@tonic-gate } argdes_t;
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate /* values for type */
1730Sstevel@tonic-gate #define	AT_BYVAL	1
1740Sstevel@tonic-gate #define	AT_BYREF	2
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate /* values for inout */
1770Sstevel@tonic-gate #define	AI_INPUT	1
1780Sstevel@tonic-gate #define	AI_OUTPUT	2
1790Sstevel@tonic-gate #define	AI_INOUT	3
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate /* maximum number of syscall arguments */
1820Sstevel@tonic-gate #define	MAXARGS		8
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate /* maximum size in bytes of a BYREF argument */
1850Sstevel@tonic-gate #define	MAXARGL		(4*1024)
1860Sstevel@tonic-gate 
1870Sstevel@tonic-gate /*
1880Sstevel@tonic-gate  * Function prototypes for routines in the process control package.
1890Sstevel@tonic-gate  */
1900Sstevel@tonic-gate extern struct ps_prochandle *Pcreate(const char *, char *const *,
1910Sstevel@tonic-gate     int *, char *, size_t);
1920Sstevel@tonic-gate extern struct ps_prochandle *Pxcreate(const char *, char *const *,
1930Sstevel@tonic-gate     char *const *, int *, char *, size_t);
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate extern const char *Pcreate_error(int);
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate extern struct ps_prochandle *Pgrab(pid_t, int, int *);
1980Sstevel@tonic-gate extern struct ps_prochandle *Pgrab_core(const char *, const char *, int, int *);
1990Sstevel@tonic-gate extern struct ps_prochandle *Pfgrab_core(int, const char *, int *);
2000Sstevel@tonic-gate extern struct ps_prochandle *Pgrab_file(const char *, int *);
2010Sstevel@tonic-gate extern const char *Pgrab_error(int);
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate extern	int	Preopen(struct ps_prochandle *);
2040Sstevel@tonic-gate extern	void	Prelease(struct ps_prochandle *, int);
2050Sstevel@tonic-gate extern	void	Pfree(struct ps_prochandle *);
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate extern	int	Pasfd(struct ps_prochandle *);
2082712Snn35248 extern	char   *Pbrandname(struct ps_prochandle *, char *, size_t);
2090Sstevel@tonic-gate extern	int	Pctlfd(struct ps_prochandle *);
2100Sstevel@tonic-gate extern	int	Pcreate_agent(struct ps_prochandle *);
2110Sstevel@tonic-gate extern	void	Pdestroy_agent(struct ps_prochandle *);
2120Sstevel@tonic-gate extern	int	Pstopstatus(struct ps_prochandle *, long, uint_t);
2130Sstevel@tonic-gate extern	int	Pwait(struct ps_prochandle *, uint_t);
2140Sstevel@tonic-gate extern	int	Pstop(struct ps_prochandle *, uint_t);
2150Sstevel@tonic-gate extern	int	Pdstop(struct ps_prochandle *);
2160Sstevel@tonic-gate extern	int	Pstate(struct ps_prochandle *);
2170Sstevel@tonic-gate extern	const psinfo_t *Ppsinfo(struct ps_prochandle *);
2180Sstevel@tonic-gate extern	const pstatus_t *Pstatus(struct ps_prochandle *);
2190Sstevel@tonic-gate extern	int	Pcred(struct ps_prochandle *, prcred_t *, int);
2200Sstevel@tonic-gate extern	int	Psetcred(struct ps_prochandle *, const prcred_t *);
2210Sstevel@tonic-gate extern	ssize_t	Ppriv(struct ps_prochandle *, prpriv_t *, size_t);
2220Sstevel@tonic-gate extern	int	Psetpriv(struct ps_prochandle *, prpriv_t *);
2230Sstevel@tonic-gate extern	void   *Pprivinfo(struct ps_prochandle *);
2240Sstevel@tonic-gate extern	int	Psetzoneid(struct ps_prochandle *, zoneid_t);
2250Sstevel@tonic-gate extern	int	Pgetareg(struct ps_prochandle *, int, prgreg_t *);
2260Sstevel@tonic-gate extern	int	Pputareg(struct ps_prochandle *, int, prgreg_t);
2270Sstevel@tonic-gate extern	int	Psetrun(struct ps_prochandle *, int, int);
2280Sstevel@tonic-gate extern	ssize_t	Pread(struct ps_prochandle *, void *, size_t, uintptr_t);
2290Sstevel@tonic-gate extern	ssize_t Pread_string(struct ps_prochandle *, char *, size_t, uintptr_t);
2300Sstevel@tonic-gate extern	ssize_t	Pwrite(struct ps_prochandle *, const void *, size_t, uintptr_t);
2310Sstevel@tonic-gate extern	int	Pclearsig(struct ps_prochandle *);
2320Sstevel@tonic-gate extern	int	Pclearfault(struct ps_prochandle *);
2330Sstevel@tonic-gate extern	int	Psetbkpt(struct ps_prochandle *, uintptr_t, ulong_t *);
2340Sstevel@tonic-gate extern	int	Pdelbkpt(struct ps_prochandle *, uintptr_t, ulong_t);
2350Sstevel@tonic-gate extern	int	Pxecbkpt(struct ps_prochandle *, ulong_t);
2360Sstevel@tonic-gate extern	int	Psetwapt(struct ps_prochandle *, const prwatch_t *);
2370Sstevel@tonic-gate extern	int	Pdelwapt(struct ps_prochandle *, const prwatch_t *);
2380Sstevel@tonic-gate extern	int	Pxecwapt(struct ps_prochandle *, const prwatch_t *);
2390Sstevel@tonic-gate extern	int	Psetflags(struct ps_prochandle *, long);
2400Sstevel@tonic-gate extern	int	Punsetflags(struct ps_prochandle *, long);
2410Sstevel@tonic-gate extern	int	Psignal(struct ps_prochandle *, int, int);
2420Sstevel@tonic-gate extern	int	Pfault(struct ps_prochandle *, int, int);
2430Sstevel@tonic-gate extern	int	Psysentry(struct ps_prochandle *, int, int);
2440Sstevel@tonic-gate extern	int	Psysexit(struct ps_prochandle *, int, int);
2450Sstevel@tonic-gate extern	void	Psetsignal(struct ps_prochandle *, const sigset_t *);
2460Sstevel@tonic-gate extern	void	Psetfault(struct ps_prochandle *, const fltset_t *);
2470Sstevel@tonic-gate extern	void	Psetsysentry(struct ps_prochandle *, const sysset_t *);
2480Sstevel@tonic-gate extern	void	Psetsysexit(struct ps_prochandle *, const sysset_t *);
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate extern	void	Psync(struct ps_prochandle *);
2510Sstevel@tonic-gate extern	int	Psyscall(struct ps_prochandle *, sysret_t *,
2520Sstevel@tonic-gate 			int, uint_t, argdes_t *);
2530Sstevel@tonic-gate extern	int	Pisprocdir(struct ps_prochandle *, const char *);
2540Sstevel@tonic-gate 
2550Sstevel@tonic-gate /*
2560Sstevel@tonic-gate  * Function prototypes for lwp-specific operations.
2570Sstevel@tonic-gate  */
2580Sstevel@tonic-gate extern	struct ps_lwphandle *Lgrab(struct ps_prochandle *, lwpid_t, int *);
2590Sstevel@tonic-gate extern	const char *Lgrab_error(int);
2600Sstevel@tonic-gate 
2610Sstevel@tonic-gate extern	struct ps_prochandle *Lprochandle(struct ps_lwphandle *);
2620Sstevel@tonic-gate extern	void	Lfree(struct ps_lwphandle *);
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate extern	int	Lctlfd(struct ps_lwphandle *);
2650Sstevel@tonic-gate extern	int	Lwait(struct ps_lwphandle *, uint_t);
2660Sstevel@tonic-gate extern	int	Lstop(struct ps_lwphandle *, uint_t);
2670Sstevel@tonic-gate extern	int	Ldstop(struct ps_lwphandle *);
2680Sstevel@tonic-gate extern	int	Lstate(struct ps_lwphandle *);
2690Sstevel@tonic-gate extern	const lwpsinfo_t *Lpsinfo(struct ps_lwphandle *);
2700Sstevel@tonic-gate extern	const lwpstatus_t *Lstatus(struct ps_lwphandle *);
2710Sstevel@tonic-gate extern	int	Lgetareg(struct ps_lwphandle *, int, prgreg_t *);
2720Sstevel@tonic-gate extern	int	Lputareg(struct ps_lwphandle *, int, prgreg_t);
2730Sstevel@tonic-gate extern	int	Lsetrun(struct ps_lwphandle *, int, int);
2740Sstevel@tonic-gate extern	int	Lclearsig(struct ps_lwphandle *);
2750Sstevel@tonic-gate extern	int	Lclearfault(struct ps_lwphandle *);
2760Sstevel@tonic-gate extern	int	Lxecbkpt(struct ps_lwphandle *, ulong_t);
2770Sstevel@tonic-gate extern	int	Lxecwapt(struct ps_lwphandle *, const prwatch_t *);
2780Sstevel@tonic-gate extern	void	Lsync(struct ps_lwphandle *);
2790Sstevel@tonic-gate 
2800Sstevel@tonic-gate extern	int	Lstack(struct ps_lwphandle *, stack_t *);
2810Sstevel@tonic-gate extern	int	Lmain_stack(struct ps_lwphandle *, stack_t *);
2820Sstevel@tonic-gate extern	int	Lalt_stack(struct ps_lwphandle *, stack_t *);
2830Sstevel@tonic-gate 
2840Sstevel@tonic-gate /*
2850Sstevel@tonic-gate  * Function prototypes for system calls forced on the victim process.
2860Sstevel@tonic-gate  */
2870Sstevel@tonic-gate extern	int	pr_open(struct ps_prochandle *, const char *, int, mode_t);
2880Sstevel@tonic-gate extern	int	pr_creat(struct ps_prochandle *, const char *, mode_t);
2890Sstevel@tonic-gate extern	int	pr_close(struct ps_prochandle *, int);
2900Sstevel@tonic-gate extern	int	pr_access(struct ps_prochandle *, const char *, int);
2910Sstevel@tonic-gate extern	int	pr_door_info(struct ps_prochandle *, int, struct door_info *);
2920Sstevel@tonic-gate extern	void	*pr_mmap(struct ps_prochandle *,
2930Sstevel@tonic-gate 			void *, size_t, int, int, int, off_t);
2940Sstevel@tonic-gate extern	void	*pr_zmap(struct ps_prochandle *,
2950Sstevel@tonic-gate 			void *, size_t, int, int);
2960Sstevel@tonic-gate extern	int	pr_munmap(struct ps_prochandle *, void *, size_t);
2970Sstevel@tonic-gate extern	int	pr_memcntl(struct ps_prochandle *,
2980Sstevel@tonic-gate 			caddr_t, size_t, int, caddr_t, int, int);
2990Sstevel@tonic-gate extern	int	pr_meminfo(struct ps_prochandle *, const uint64_t *addrs,
3000Sstevel@tonic-gate 			int addr_count, const uint_t *info, int info_count,
3010Sstevel@tonic-gate 			uint64_t *outdata, uint_t *validity);
3020Sstevel@tonic-gate extern	int	pr_sigaction(struct ps_prochandle *,
3030Sstevel@tonic-gate 			int, const struct sigaction *, struct sigaction *);
3040Sstevel@tonic-gate extern	int	pr_getitimer(struct ps_prochandle *,
3050Sstevel@tonic-gate 			int, struct itimerval *);
3060Sstevel@tonic-gate extern	int	pr_setitimer(struct ps_prochandle *,
3070Sstevel@tonic-gate 			int, const struct itimerval *, struct itimerval *);
3080Sstevel@tonic-gate extern	int	pr_ioctl(struct ps_prochandle *, int, int, void *, size_t);
3090Sstevel@tonic-gate extern	int	pr_fcntl(struct ps_prochandle *, int, int, void *);
3100Sstevel@tonic-gate extern	int	pr_stat(struct ps_prochandle *, const char *, struct stat *);
3110Sstevel@tonic-gate extern	int	pr_lstat(struct ps_prochandle *, const char *, struct stat *);
3120Sstevel@tonic-gate extern	int	pr_fstat(struct ps_prochandle *, int, struct stat *);
3130Sstevel@tonic-gate extern	int	pr_stat64(struct ps_prochandle *, const char *,
3140Sstevel@tonic-gate 			struct stat64 *);
3150Sstevel@tonic-gate extern	int	pr_lstat64(struct ps_prochandle *, const char *,
3160Sstevel@tonic-gate 			struct stat64 *);
3170Sstevel@tonic-gate extern	int	pr_fstat64(struct ps_prochandle *, int, struct stat64 *);
3180Sstevel@tonic-gate extern	int	pr_statvfs(struct ps_prochandle *, const char *, statvfs_t *);
3190Sstevel@tonic-gate extern	int	pr_fstatvfs(struct ps_prochandle *, int, statvfs_t *);
3200Sstevel@tonic-gate extern	projid_t pr_getprojid(struct ps_prochandle *Pr);
3210Sstevel@tonic-gate extern	taskid_t pr_gettaskid(struct ps_prochandle *Pr);
3220Sstevel@tonic-gate extern	taskid_t pr_settaskid(struct ps_prochandle *Pr, projid_t project,
3230Sstevel@tonic-gate 			int flags);
3240Sstevel@tonic-gate extern	zoneid_t pr_getzoneid(struct ps_prochandle *Pr);
3250Sstevel@tonic-gate extern	int	pr_getrctl(struct ps_prochandle *,
3260Sstevel@tonic-gate 			const char *, rctlblk_t *, rctlblk_t *, int);
3270Sstevel@tonic-gate extern	int	pr_setrctl(struct ps_prochandle *,
3280Sstevel@tonic-gate 			const char *, rctlblk_t *, rctlblk_t *, int);
3290Sstevel@tonic-gate extern	int	pr_getrlimit(struct ps_prochandle *,
3300Sstevel@tonic-gate 			int, struct rlimit *);
3310Sstevel@tonic-gate extern	int	pr_setrlimit(struct ps_prochandle *,
3320Sstevel@tonic-gate 			int, const struct rlimit *);
3333684Srd117015 extern	int	pr_setprojrctl(struct ps_prochandle *, const char *,
3343684Srd117015 			rctlblk_t *, size_t, int);
3350Sstevel@tonic-gate #if defined(_LARGEFILE64_SOURCE)
3360Sstevel@tonic-gate extern	int	pr_getrlimit64(struct ps_prochandle *,
3370Sstevel@tonic-gate 			int, struct rlimit64 *);
3380Sstevel@tonic-gate extern	int	pr_setrlimit64(struct ps_prochandle *,
3390Sstevel@tonic-gate 			int, const struct rlimit64 *);
3400Sstevel@tonic-gate #endif	/* _LARGEFILE64_SOURCE */
3410Sstevel@tonic-gate extern	int	pr_lwp_exit(struct ps_prochandle *);
3420Sstevel@tonic-gate extern	int	pr_exit(struct ps_prochandle *, int);
3430Sstevel@tonic-gate extern	int	pr_waitid(struct ps_prochandle *,
3440Sstevel@tonic-gate 			idtype_t, id_t, siginfo_t *, int);
3450Sstevel@tonic-gate extern	off_t	pr_lseek(struct ps_prochandle *, int, off_t, int);
3460Sstevel@tonic-gate extern	offset_t pr_llseek(struct ps_prochandle *, int, offset_t, int);
3470Sstevel@tonic-gate extern	int	pr_rename(struct ps_prochandle *, const char *, const char *);
3480Sstevel@tonic-gate extern	int	pr_link(struct ps_prochandle *, const char *, const char *);
3490Sstevel@tonic-gate extern	int	pr_unlink(struct ps_prochandle *, const char *);
3500Sstevel@tonic-gate extern	int	pr_getpeername(struct ps_prochandle *,
3510Sstevel@tonic-gate 			int, struct sockaddr *, socklen_t *);
3520Sstevel@tonic-gate extern	int	pr_getsockname(struct ps_prochandle *,
3530Sstevel@tonic-gate 			int, struct sockaddr *, socklen_t *);
3540Sstevel@tonic-gate extern	int	pr_getsockopt(struct ps_prochandle *,
3550Sstevel@tonic-gate 			int, int, int, void *, int *);
3560Sstevel@tonic-gate extern	int	pr_processor_bind(struct ps_prochandle *,
3570Sstevel@tonic-gate 			idtype_t, id_t, int, int *);
3580Sstevel@tonic-gate 
3590Sstevel@tonic-gate /*
3600Sstevel@tonic-gate  * Function prototypes for accessing per-LWP register information.
3610Sstevel@tonic-gate  */
3620Sstevel@tonic-gate extern int Plwp_getregs(struct ps_prochandle *, lwpid_t, prgregset_t);
3630Sstevel@tonic-gate extern int Plwp_setregs(struct ps_prochandle *, lwpid_t, const prgregset_t);
3640Sstevel@tonic-gate 
3650Sstevel@tonic-gate extern int Plwp_getfpregs(struct ps_prochandle *, lwpid_t, prfpregset_t *);
3660Sstevel@tonic-gate extern int Plwp_setfpregs(struct ps_prochandle *, lwpid_t,
3670Sstevel@tonic-gate     const prfpregset_t *);
3680Sstevel@tonic-gate 
3690Sstevel@tonic-gate #if defined(__sparc)
3700Sstevel@tonic-gate 
3710Sstevel@tonic-gate extern int Plwp_getxregs(struct ps_prochandle *, lwpid_t, prxregset_t *);
3720Sstevel@tonic-gate extern int Plwp_setxregs(struct ps_prochandle *, lwpid_t, const prxregset_t *);
3730Sstevel@tonic-gate 
3740Sstevel@tonic-gate extern int Plwp_getgwindows(struct ps_prochandle *, lwpid_t, gwindows_t *);
3750Sstevel@tonic-gate 
3760Sstevel@tonic-gate #if defined(__sparcv9)
3770Sstevel@tonic-gate extern int Plwp_getasrs(struct ps_prochandle *, lwpid_t, asrset_t);
3780Sstevel@tonic-gate extern int Plwp_setasrs(struct ps_prochandle *, lwpid_t, const asrset_t);
3790Sstevel@tonic-gate #endif	/* __sparcv9 */
3800Sstevel@tonic-gate 
3810Sstevel@tonic-gate #endif	/* __sparc */
3820Sstevel@tonic-gate 
3830Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
3840Sstevel@tonic-gate extern	int	Pldt(struct ps_prochandle *, struct ssd *, int);
3850Sstevel@tonic-gate extern	int	proc_get_ldt(pid_t, struct ssd *, int);
3860Sstevel@tonic-gate #endif	/* __i386 || __amd64 */
3870Sstevel@tonic-gate 
3880Sstevel@tonic-gate extern int Plwp_getpsinfo(struct ps_prochandle *, lwpid_t, lwpsinfo_t *);
3890Sstevel@tonic-gate 
3900Sstevel@tonic-gate extern int Plwp_stack(struct ps_prochandle *, lwpid_t, stack_t *);
3910Sstevel@tonic-gate extern int Plwp_main_stack(struct ps_prochandle *, lwpid_t, stack_t *);
3920Sstevel@tonic-gate extern int Plwp_alt_stack(struct ps_prochandle *, lwpid_t, stack_t *);
3930Sstevel@tonic-gate 
3940Sstevel@tonic-gate /*
3950Sstevel@tonic-gate  * LWP iteration interface; iterate over all active LWPs.
3960Sstevel@tonic-gate  */
3970Sstevel@tonic-gate typedef int proc_lwp_f(void *, const lwpstatus_t *);
3980Sstevel@tonic-gate extern int Plwp_iter(struct ps_prochandle *, proc_lwp_f *, void *);
3990Sstevel@tonic-gate 
4000Sstevel@tonic-gate /*
4010Sstevel@tonic-gate  * LWP iteration interface; iterate over all LWPs, active and zombie.
4020Sstevel@tonic-gate  */
4030Sstevel@tonic-gate typedef int proc_lwp_all_f(void *, const lwpstatus_t *, const lwpsinfo_t *);
4040Sstevel@tonic-gate extern int Plwp_iter_all(struct ps_prochandle *, proc_lwp_all_f *, void *);
4050Sstevel@tonic-gate 
4060Sstevel@tonic-gate /*
4078509SRoger.Faulkner@Sun.COM  * Process iteration interface; iterate over all non-system processes.
4080Sstevel@tonic-gate  */
4090Sstevel@tonic-gate typedef int proc_walk_f(psinfo_t *, lwpsinfo_t *, void *);
4100Sstevel@tonic-gate extern int proc_walk(proc_walk_f *, void *, int);
4110Sstevel@tonic-gate 
4120Sstevel@tonic-gate #define	PR_WALK_PROC	0		/* walk processes only */
4130Sstevel@tonic-gate #define	PR_WALK_LWP	1		/* walk all lwps */
4140Sstevel@tonic-gate 
4150Sstevel@tonic-gate /*
4160Sstevel@tonic-gate  * Determine if an lwp is in a set as returned from proc_arg_xgrab().
4170Sstevel@tonic-gate  */
4180Sstevel@tonic-gate extern int proc_lwp_in_set(const char *, lwpid_t);
4190Sstevel@tonic-gate extern int proc_lwp_range_valid(const char *);
4200Sstevel@tonic-gate 
4210Sstevel@tonic-gate /*
4220Sstevel@tonic-gate  * Symbol table interfaces.
4230Sstevel@tonic-gate  */
4240Sstevel@tonic-gate 
4250Sstevel@tonic-gate /*
4260Sstevel@tonic-gate  * Pseudo-names passed to Plookup_by_name() for well-known load objects.
4270Sstevel@tonic-gate  * NOTE: It is required that PR_OBJ_EXEC and PR_OBJ_LDSO exactly match
4280Sstevel@tonic-gate  * the definitions of PS_OBJ_EXEC and PS_OBJ_LDSO from <proc_service.h>.
4290Sstevel@tonic-gate  */
4300Sstevel@tonic-gate #define	PR_OBJ_EXEC	((const char *)0)	/* search the executable file */
4310Sstevel@tonic-gate #define	PR_OBJ_LDSO	((const char *)1)	/* search ld.so.1 */
4320Sstevel@tonic-gate #define	PR_OBJ_EVERY	((const char *)-1)	/* search every load object */
4330Sstevel@tonic-gate 
4340Sstevel@tonic-gate /*
4350Sstevel@tonic-gate  * Special Lmid_t passed to Plookup_by_lmid() to search all link maps.  The
4360Sstevel@tonic-gate  * special values LM_ID_BASE and LM_ID_LDSO from <link.h> may also be used.
4370Sstevel@tonic-gate  * If PR_OBJ_EXEC is used as the object name, the lmid must be PR_LMID_EVERY
4380Sstevel@tonic-gate  * or LM_ID_BASE in order to return a match.  If PR_OBJ_LDSO is used as the
4390Sstevel@tonic-gate  * object name, the lmid must be PR_LMID_EVERY or LM_ID_LDSO to return a match.
4400Sstevel@tonic-gate  */
4410Sstevel@tonic-gate #define	PR_LMID_EVERY	((Lmid_t)-1UL)		/* search every link map */
4420Sstevel@tonic-gate 
4430Sstevel@tonic-gate /*
4440Sstevel@tonic-gate  * 'object_name' is the name of a load object obtained from an
4450Sstevel@tonic-gate  * iteration over the process's address space mappings (Pmapping_iter),
4460Sstevel@tonic-gate  * or an iteration over the process's mapped objects (Pobject_iter),
4470Sstevel@tonic-gate  * or else it is one of the special PR_OBJ_* values above.
4480Sstevel@tonic-gate  */
4490Sstevel@tonic-gate extern int Plookup_by_name(struct ps_prochandle *,
4500Sstevel@tonic-gate     const char *, const char *, GElf_Sym *);
4510Sstevel@tonic-gate 
4520Sstevel@tonic-gate extern int Plookup_by_addr(struct ps_prochandle *,
4530Sstevel@tonic-gate     uintptr_t, char *, size_t, GElf_Sym *);
4540Sstevel@tonic-gate 
4550Sstevel@tonic-gate typedef struct prsyminfo {
4560Sstevel@tonic-gate 	const char	*prs_object;		/* object name */
4570Sstevel@tonic-gate 	const char	*prs_name;		/* symbol name */
4580Sstevel@tonic-gate 	Lmid_t		prs_lmid;		/* link map id */
4590Sstevel@tonic-gate 	uint_t		prs_id;			/* symbol id */
4600Sstevel@tonic-gate 	uint_t		prs_table;		/* symbol table id */
4610Sstevel@tonic-gate } prsyminfo_t;
4620Sstevel@tonic-gate 
4630Sstevel@tonic-gate extern int Pxlookup_by_name(struct ps_prochandle *,
4640Sstevel@tonic-gate     Lmid_t, const char *, const char *, GElf_Sym *, prsyminfo_t *);
4650Sstevel@tonic-gate 
4660Sstevel@tonic-gate extern int Pxlookup_by_addr(struct ps_prochandle *,
4670Sstevel@tonic-gate     uintptr_t, char *, size_t, GElf_Sym *, prsyminfo_t *);
4687675SEdward.Pilatowicz@Sun.COM extern int Pxlookup_by_addr_resolved(struct ps_prochandle *,
4697675SEdward.Pilatowicz@Sun.COM     uintptr_t, char *, size_t, GElf_Sym *, prsyminfo_t *);
4700Sstevel@tonic-gate 
4710Sstevel@tonic-gate typedef int proc_map_f(void *, const prmap_t *, const char *);
4720Sstevel@tonic-gate 
4730Sstevel@tonic-gate extern int Pmapping_iter(struct ps_prochandle *, proc_map_f *, void *);
4747675SEdward.Pilatowicz@Sun.COM extern int Pmapping_iter_resolved(struct ps_prochandle *, proc_map_f *, void *);
4750Sstevel@tonic-gate extern int Pobject_iter(struct ps_prochandle *, proc_map_f *, void *);
4767675SEdward.Pilatowicz@Sun.COM extern int Pobject_iter_resolved(struct ps_prochandle *, proc_map_f *, void *);
4770Sstevel@tonic-gate 
4780Sstevel@tonic-gate extern const prmap_t *Paddr_to_map(struct ps_prochandle *, uintptr_t);
4790Sstevel@tonic-gate extern const prmap_t *Paddr_to_text_map(struct ps_prochandle *, uintptr_t);
4800Sstevel@tonic-gate extern const prmap_t *Pname_to_map(struct ps_prochandle *, const char *);
4810Sstevel@tonic-gate extern const prmap_t *Plmid_to_map(struct ps_prochandle *,
4820Sstevel@tonic-gate     Lmid_t, const char *);
4830Sstevel@tonic-gate 
4840Sstevel@tonic-gate extern const rd_loadobj_t *Paddr_to_loadobj(struct ps_prochandle *, uintptr_t);
4850Sstevel@tonic-gate extern const rd_loadobj_t *Pname_to_loadobj(struct ps_prochandle *,
4860Sstevel@tonic-gate     const char *);
4870Sstevel@tonic-gate extern const rd_loadobj_t *Plmid_to_loadobj(struct ps_prochandle *,
4880Sstevel@tonic-gate     Lmid_t, const char *);
4890Sstevel@tonic-gate 
4900Sstevel@tonic-gate extern ctf_file_t *Paddr_to_ctf(struct ps_prochandle *, uintptr_t);
4910Sstevel@tonic-gate extern ctf_file_t *Pname_to_ctf(struct ps_prochandle *, const char *);
4920Sstevel@tonic-gate 
4930Sstevel@tonic-gate extern char *Pplatform(struct ps_prochandle *, char *, size_t);
4940Sstevel@tonic-gate extern int Puname(struct ps_prochandle *, struct utsname *);
4950Sstevel@tonic-gate extern char *Pzonename(struct ps_prochandle *, char *, size_t);
4967675SEdward.Pilatowicz@Sun.COM extern char *Pfindobj(struct ps_prochandle *, const char *, char *, size_t);
4970Sstevel@tonic-gate 
4980Sstevel@tonic-gate extern char *Pexecname(struct ps_prochandle *, char *, size_t);
4990Sstevel@tonic-gate extern char *Pobjname(struct ps_prochandle *, uintptr_t, char *, size_t);
5007675SEdward.Pilatowicz@Sun.COM extern char *Pobjname_resolved(struct ps_prochandle *, uintptr_t, char *,
5017675SEdward.Pilatowicz@Sun.COM     size_t);
5020Sstevel@tonic-gate extern int Plmid(struct ps_prochandle *, uintptr_t, Lmid_t *);
5030Sstevel@tonic-gate 
5040Sstevel@tonic-gate typedef int proc_env_f(void *, struct ps_prochandle *, uintptr_t, const char *);
5050Sstevel@tonic-gate extern	int Penv_iter(struct ps_prochandle *, proc_env_f *, void *);
5060Sstevel@tonic-gate extern char *Pgetenv(struct ps_prochandle *, const char *, char *, size_t);
5070Sstevel@tonic-gate extern long Pgetauxval(struct ps_prochandle *, int);
5080Sstevel@tonic-gate extern const auxv_t *Pgetauxvec(struct ps_prochandle *);
5090Sstevel@tonic-gate 
5102712Snn35248 extern void Pset_procfs_path(const char *);
5112712Snn35248 
5120Sstevel@tonic-gate /*
5130Sstevel@tonic-gate  * Symbol table iteration interface.  The special lmid constants LM_ID_BASE,
5140Sstevel@tonic-gate  * LM_ID_LDSO, and PR_LMID_EVERY may be used with Psymbol_iter_by_lmid.
5150Sstevel@tonic-gate  */
5160Sstevel@tonic-gate typedef int proc_sym_f(void *, const GElf_Sym *, const char *);
5170Sstevel@tonic-gate typedef int proc_xsym_f(void *, const GElf_Sym *, const char *,
5180Sstevel@tonic-gate     const prsyminfo_t *);
5190Sstevel@tonic-gate 
5200Sstevel@tonic-gate extern int Psymbol_iter(struct ps_prochandle *,
5210Sstevel@tonic-gate     const char *, int, int, proc_sym_f *, void *);
5220Sstevel@tonic-gate extern int Psymbol_iter_by_addr(struct ps_prochandle *,
5230Sstevel@tonic-gate     const char *, int, int, proc_sym_f *, void *);
5240Sstevel@tonic-gate extern int Psymbol_iter_by_name(struct ps_prochandle *,
5250Sstevel@tonic-gate     const char *, int, int, proc_sym_f *, void *);
5260Sstevel@tonic-gate 
5270Sstevel@tonic-gate extern int Psymbol_iter_by_lmid(struct ps_prochandle *,
5280Sstevel@tonic-gate     Lmid_t, const char *, int, int, proc_sym_f *, void *);
5290Sstevel@tonic-gate 
5300Sstevel@tonic-gate extern int Pxsymbol_iter(struct ps_prochandle *,
5310Sstevel@tonic-gate     Lmid_t, const char *, int, int, proc_xsym_f *, void *);
5320Sstevel@tonic-gate 
5330Sstevel@tonic-gate /*
5340Sstevel@tonic-gate  * 'which' selects which symbol table and can be one of the following.
5350Sstevel@tonic-gate  */
5360Sstevel@tonic-gate #define	PR_SYMTAB	1
5370Sstevel@tonic-gate #define	PR_DYNSYM	2
5380Sstevel@tonic-gate /*
5390Sstevel@tonic-gate  * 'type' selects the symbols of interest by binding and type.  It is a bit-
5400Sstevel@tonic-gate  * mask of one or more of the following flags, whose order MUST match the
5410Sstevel@tonic-gate  * order of STB and STT constants in <sys/elf.h>.
5420Sstevel@tonic-gate  */
5430Sstevel@tonic-gate #define	BIND_LOCAL	0x0001
5440Sstevel@tonic-gate #define	BIND_GLOBAL	0x0002
5450Sstevel@tonic-gate #define	BIND_WEAK	0x0004
5460Sstevel@tonic-gate #define	BIND_ANY (BIND_LOCAL|BIND_GLOBAL|BIND_WEAK)
5470Sstevel@tonic-gate #define	TYPE_NOTYPE	0x0100
5480Sstevel@tonic-gate #define	TYPE_OBJECT	0x0200
5490Sstevel@tonic-gate #define	TYPE_FUNC	0x0400
5500Sstevel@tonic-gate #define	TYPE_SECTION	0x0800
5510Sstevel@tonic-gate #define	TYPE_FILE	0x1000
5520Sstevel@tonic-gate #define	TYPE_ANY (TYPE_NOTYPE|TYPE_OBJECT|TYPE_FUNC|TYPE_SECTION|TYPE_FILE)
5530Sstevel@tonic-gate 
5540Sstevel@tonic-gate /*
5550Sstevel@tonic-gate  * This returns the rtld_db agent handle for the process.
5560Sstevel@tonic-gate  * The handle will become invalid at the next successful exec() and
5570Sstevel@tonic-gate  * must not be used beyond that point (see Preset_maps(), below).
5580Sstevel@tonic-gate  */
5590Sstevel@tonic-gate extern rd_agent_t *Prd_agent(struct ps_prochandle *);
5600Sstevel@tonic-gate 
5610Sstevel@tonic-gate /*
5620Sstevel@tonic-gate  * This should be called when an RD_DLACTIVITY event with the
5630Sstevel@tonic-gate  * RD_CONSISTENT state occurs via librtld_db's event mechanism.
5640Sstevel@tonic-gate  * This makes libproc's address space mappings and symbol tables current.
5650Sstevel@tonic-gate  * The variant Pupdate_syms() can be used to preload all symbol tables as well.
5660Sstevel@tonic-gate  */
5670Sstevel@tonic-gate extern void Pupdate_maps(struct ps_prochandle *);
5680Sstevel@tonic-gate extern void Pupdate_syms(struct ps_prochandle *);
5690Sstevel@tonic-gate 
5700Sstevel@tonic-gate /*
5710Sstevel@tonic-gate  * This must be called after the victim process performs a successful
5720Sstevel@tonic-gate  * exec() if any of the symbol table interface functions have been called
5730Sstevel@tonic-gate  * prior to that point.  This is essential because an exec() invalidates
5740Sstevel@tonic-gate  * all previous symbol table and address space mapping information.
5750Sstevel@tonic-gate  * It is always safe to call, but if it is called other than after an
5760Sstevel@tonic-gate  * exec() by the victim process it just causes unnecessary overhead.
5770Sstevel@tonic-gate  *
5780Sstevel@tonic-gate  * The rtld_db agent handle obtained from a previous call to Prd_agent() is
5790Sstevel@tonic-gate  * made invalid by Preset_maps() and Prd_agent() must be called again to get
5800Sstevel@tonic-gate  * the new handle.
5810Sstevel@tonic-gate  */
5820Sstevel@tonic-gate extern void Preset_maps(struct ps_prochandle *);
5830Sstevel@tonic-gate 
5840Sstevel@tonic-gate /*
5850Sstevel@tonic-gate  * Given an address, Ppltdest() determines if this is part of a PLT, and if
5860Sstevel@tonic-gate  * so returns a pointer to the symbol name that will be used for resolution.
5870Sstevel@tonic-gate  * If the specified address is not part of a PLT, the function returns NULL.
5880Sstevel@tonic-gate  */
5890Sstevel@tonic-gate extern const char *Ppltdest(struct ps_prochandle *, uintptr_t);
5900Sstevel@tonic-gate 
5910Sstevel@tonic-gate /*
5920Sstevel@tonic-gate  * See comments for Pissyscall(), in Pisadep.h
5930Sstevel@tonic-gate  */
5940Sstevel@tonic-gate extern int Pissyscall_prev(struct ps_prochandle *, uintptr_t, uintptr_t *);
5950Sstevel@tonic-gate 
5960Sstevel@tonic-gate /*
5970Sstevel@tonic-gate  * Stack frame iteration interface.
5980Sstevel@tonic-gate  */
5990Sstevel@tonic-gate typedef int proc_stack_f(void *, prgregset_t, uint_t, const long *);
6000Sstevel@tonic-gate 
6010Sstevel@tonic-gate extern int Pstack_iter(struct ps_prochandle *,
6020Sstevel@tonic-gate     const prgregset_t, proc_stack_f *, void *);
6030Sstevel@tonic-gate 
6040Sstevel@tonic-gate /*
6050Sstevel@tonic-gate  * The following functions define a set of passive interfaces: libproc provides
6060Sstevel@tonic-gate  * default, empty definitions that are called internally.  If a client wishes
6070Sstevel@tonic-gate  * to override these definitions, it can simply provide its own version with
6080Sstevel@tonic-gate  * the same signature that interposes on the libproc definition.
6090Sstevel@tonic-gate  *
6100Sstevel@tonic-gate  * If the client program wishes to report additional error information, it
6110Sstevel@tonic-gate  * can provide its own version of Perror_printf.
6120Sstevel@tonic-gate  *
6130Sstevel@tonic-gate  * If the client program wishes to receive a callback after Pcreate forks
6140Sstevel@tonic-gate  * but before it execs, it can provide its own version of Pcreate_callback.
6150Sstevel@tonic-gate  */
6160Sstevel@tonic-gate extern void Perror_printf(struct ps_prochandle *P, const char *format, ...);
6170Sstevel@tonic-gate extern void Pcreate_callback(struct ps_prochandle *);
6180Sstevel@tonic-gate 
6190Sstevel@tonic-gate /*
6200Sstevel@tonic-gate  * Remove unprintable characters from psinfo.pr_psargs and replace with
6210Sstevel@tonic-gate  * whitespace characters so it is safe for printing.
6220Sstevel@tonic-gate  */
6230Sstevel@tonic-gate extern void proc_unctrl_psinfo(psinfo_t *);
6240Sstevel@tonic-gate 
6250Sstevel@tonic-gate /*
6260Sstevel@tonic-gate  * Utility functions for processing arguments which should be /proc files,
6270Sstevel@tonic-gate  * pids, and/or core files.  The returned error code can be passed to
6280Sstevel@tonic-gate  * Pgrab_error() in order to convert it to an error string.
6290Sstevel@tonic-gate  */
6300Sstevel@tonic-gate #define	PR_ARG_PIDS	0x1	/* Allow pid and /proc file arguments */
6310Sstevel@tonic-gate #define	PR_ARG_CORES	0x2	/* Allow core file arguments */
6320Sstevel@tonic-gate 
6330Sstevel@tonic-gate #define	PR_ARG_ANY	(PR_ARG_PIDS | PR_ARG_CORES)
6340Sstevel@tonic-gate 
6350Sstevel@tonic-gate extern struct ps_prochandle *proc_arg_grab(const char *, int, int, int *);
6360Sstevel@tonic-gate extern struct ps_prochandle *proc_arg_xgrab(const char *, const char *, int,
6370Sstevel@tonic-gate     int, int *, const char **);
6380Sstevel@tonic-gate extern pid_t proc_arg_psinfo(const char *, int, psinfo_t *, int *);
6390Sstevel@tonic-gate extern pid_t proc_arg_xpsinfo(const char *, int, psinfo_t *, int *,
6400Sstevel@tonic-gate     const char **);
6410Sstevel@tonic-gate 
6420Sstevel@tonic-gate /*
6430Sstevel@tonic-gate  * Utility functions for obtaining information via /proc without actually
6440Sstevel@tonic-gate  * performing a Pcreate() or Pgrab():
6450Sstevel@tonic-gate  */
6460Sstevel@tonic-gate extern int proc_get_auxv(pid_t, auxv_t *, int);
6470Sstevel@tonic-gate extern int proc_get_cred(pid_t, prcred_t *, int);
6480Sstevel@tonic-gate extern prpriv_t *proc_get_priv(pid_t);
6490Sstevel@tonic-gate extern int proc_get_psinfo(pid_t, psinfo_t *);
6500Sstevel@tonic-gate extern int proc_get_status(pid_t, pstatus_t *);
6510Sstevel@tonic-gate 
6520Sstevel@tonic-gate /*
6530Sstevel@tonic-gate  * Utility functions for debugging tools to convert numeric fault,
6540Sstevel@tonic-gate  * signal, and system call numbers to symbolic names:
6550Sstevel@tonic-gate  */
6560Sstevel@tonic-gate #define	FLT2STR_MAX 32	/* max. string length of faults (like SIG2STR_MAX) */
6570Sstevel@tonic-gate #define	SYS2STR_MAX 32	/* max. string length of syscalls (like SIG2STR_MAX) */
6580Sstevel@tonic-gate 
6590Sstevel@tonic-gate extern char *proc_fltname(int, char *, size_t);
6600Sstevel@tonic-gate extern char *proc_signame(int, char *, size_t);
6610Sstevel@tonic-gate extern char *proc_sysname(int, char *, size_t);
6620Sstevel@tonic-gate 
6630Sstevel@tonic-gate /*
6640Sstevel@tonic-gate  * Utility functions for debugging tools to convert fault, signal, and system
6650Sstevel@tonic-gate  * call names back to the numeric constants:
6660Sstevel@tonic-gate  */
6670Sstevel@tonic-gate extern int proc_str2flt(const char *, int *);
6680Sstevel@tonic-gate extern int proc_str2sig(const char *, int *);
6690Sstevel@tonic-gate extern int proc_str2sys(const char *, int *);
6700Sstevel@tonic-gate 
6710Sstevel@tonic-gate /*
6720Sstevel@tonic-gate  * Utility functions for debugging tools to convert a fault, signal or system
6730Sstevel@tonic-gate  * call set to a string representation (e.g. "BUS,SEGV" or "open,close,read").
6740Sstevel@tonic-gate  */
6750Sstevel@tonic-gate #define	PRSIGBUFSZ	1024	/* buffer size for proc_sigset2str() */
6760Sstevel@tonic-gate 
6770Sstevel@tonic-gate extern char *proc_fltset2str(const fltset_t *, const char *, int,
6780Sstevel@tonic-gate     char *, size_t);
6790Sstevel@tonic-gate extern char *proc_sigset2str(const sigset_t *, const char *, int,
6800Sstevel@tonic-gate     char *, size_t);
6810Sstevel@tonic-gate extern char *proc_sysset2str(const sysset_t *, const char *, int,
6820Sstevel@tonic-gate     char *, size_t);
6830Sstevel@tonic-gate 
6840Sstevel@tonic-gate extern int Pgcore(struct ps_prochandle *, const char *, core_content_t);
6850Sstevel@tonic-gate extern int Pfgcore(struct ps_prochandle *, int, core_content_t);
6860Sstevel@tonic-gate extern core_content_t Pcontent(struct ps_prochandle *);
6870Sstevel@tonic-gate 
6880Sstevel@tonic-gate /*
6890Sstevel@tonic-gate  * Utility functions for debugging tools to convert a string representation of
6900Sstevel@tonic-gate  * a fault, signal or system call set back to the numeric value of the
6910Sstevel@tonic-gate  * corresponding set type.
6920Sstevel@tonic-gate  */
6930Sstevel@tonic-gate extern char *proc_str2fltset(const char *, const char *, int, fltset_t *);
6940Sstevel@tonic-gate extern char *proc_str2sigset(const char *, const char *, int, sigset_t *);
6950Sstevel@tonic-gate extern char *proc_str2sysset(const char *, const char *, int, sysset_t *);
6960Sstevel@tonic-gate 
6970Sstevel@tonic-gate /*
6980Sstevel@tonic-gate  * Utility functions for converting between strings and core_content_t.
6990Sstevel@tonic-gate  */
7000Sstevel@tonic-gate #define	PRCONTENTBUFSZ	80	/* buffer size for proc_content2str() */
7010Sstevel@tonic-gate 
7020Sstevel@tonic-gate extern int proc_str2content(const char *, core_content_t *);
7030Sstevel@tonic-gate extern int proc_content2str(core_content_t, char *, size_t);
7040Sstevel@tonic-gate 
7050Sstevel@tonic-gate /*
7060Sstevel@tonic-gate  * Utility functions for buffering output to stdout, stderr while
7070Sstevel@tonic-gate  * process is grabbed.  Prevents deadlocks due to pfiles `pgrep xterm`
7080Sstevel@tonic-gate  * and other varients.
7090Sstevel@tonic-gate  */
7100Sstevel@tonic-gate extern int proc_initstdio(void);
7110Sstevel@tonic-gate extern int proc_flushstdio(void);
7120Sstevel@tonic-gate extern int proc_finistdio(void);
7130Sstevel@tonic-gate 
7140Sstevel@tonic-gate #ifdef	__cplusplus
7150Sstevel@tonic-gate }
7160Sstevel@tonic-gate #endif
7170Sstevel@tonic-gate 
7180Sstevel@tonic-gate #endif	/* _LIBPROC_H */
719