1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate /*
28*0Sstevel@tonic-gate  * Interfaces available from the process control library, libproc.
29*0Sstevel@tonic-gate  *
30*0Sstevel@tonic-gate  * libproc provides process control functions for the /proc tools
31*0Sstevel@tonic-gate  * (commands in /usr/proc/bin), /usr/bin/truss, and /usr/bin/gcore.
32*0Sstevel@tonic-gate  * libproc is a private support library for these commands only.
33*0Sstevel@tonic-gate  * It is _not_ a public interface, although it might become one
34*0Sstevel@tonic-gate  * in the fullness of time, when the interfaces settle down.
35*0Sstevel@tonic-gate  *
36*0Sstevel@tonic-gate  * In the meantime, be aware that any program linked with libproc in this
37*0Sstevel@tonic-gate  * release of Solaris is almost guaranteed to break in the next release.
38*0Sstevel@tonic-gate  *
39*0Sstevel@tonic-gate  * In short, do not use this header file or libproc for any purpose.
40*0Sstevel@tonic-gate  */
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate #ifndef	_LIBPROC_H
43*0Sstevel@tonic-gate #define	_LIBPROC_H
44*0Sstevel@tonic-gate 
45*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
46*0Sstevel@tonic-gate 
47*0Sstevel@tonic-gate #include <stdlib.h>
48*0Sstevel@tonic-gate #include <unistd.h>
49*0Sstevel@tonic-gate #include <fcntl.h>
50*0Sstevel@tonic-gate #include <nlist.h>
51*0Sstevel@tonic-gate #include <door.h>
52*0Sstevel@tonic-gate #include <gelf.h>
53*0Sstevel@tonic-gate #include <proc_service.h>
54*0Sstevel@tonic-gate #include <rtld_db.h>
55*0Sstevel@tonic-gate #include <procfs.h>
56*0Sstevel@tonic-gate #include <rctl.h>
57*0Sstevel@tonic-gate #include <libctf.h>
58*0Sstevel@tonic-gate #include <sys/stat.h>
59*0Sstevel@tonic-gate #include <sys/statvfs.h>
60*0Sstevel@tonic-gate #include <sys/auxv.h>
61*0Sstevel@tonic-gate #include <sys/resource.h>
62*0Sstevel@tonic-gate #include <sys/socket.h>
63*0Sstevel@tonic-gate #include <sys/utsname.h>
64*0Sstevel@tonic-gate #include <sys/corectl.h>
65*0Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
66*0Sstevel@tonic-gate #include <sys/sysi86.h>
67*0Sstevel@tonic-gate #endif
68*0Sstevel@tonic-gate 
69*0Sstevel@tonic-gate #ifdef	__cplusplus
70*0Sstevel@tonic-gate extern "C" {
71*0Sstevel@tonic-gate #endif
72*0Sstevel@tonic-gate 
73*0Sstevel@tonic-gate /*
74*0Sstevel@tonic-gate  * Opaque structure tag reference to a process control structure.
75*0Sstevel@tonic-gate  * Clients of libproc cannot look inside the process control structure.
76*0Sstevel@tonic-gate  * The implementation of struct ps_prochandle can change w/o affecting clients.
77*0Sstevel@tonic-gate  */
78*0Sstevel@tonic-gate struct ps_prochandle;
79*0Sstevel@tonic-gate 
80*0Sstevel@tonic-gate /*
81*0Sstevel@tonic-gate  * Opaque structure tag reference to an lwp control structure.
82*0Sstevel@tonic-gate  */
83*0Sstevel@tonic-gate struct ps_lwphandle;
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate extern	int	_libproc_debug;	/* set non-zero to enable debugging fprintfs */
86*0Sstevel@tonic-gate 
87*0Sstevel@tonic-gate #if defined(__sparc)
88*0Sstevel@tonic-gate #define	R_RVAL1	R_O0		/* register holding a function return value */
89*0Sstevel@tonic-gate #define	R_RVAL2	R_O1		/* 32 more bits for a 64-bit return value */
90*0Sstevel@tonic-gate #endif	/* __sparc */
91*0Sstevel@tonic-gate 
92*0Sstevel@tonic-gate #if defined(__amd64)
93*0Sstevel@tonic-gate #define	R_PC	REG_RIP
94*0Sstevel@tonic-gate #define	R_SP	REG_RSP
95*0Sstevel@tonic-gate #define	R_RVAL1	REG_RAX		/* register holding a function return value */
96*0Sstevel@tonic-gate #define	R_RVAL2	REG_RDX		/* 32 more bits for a 64-bit return value */
97*0Sstevel@tonic-gate #elif defined(__i386)
98*0Sstevel@tonic-gate #define	R_PC	EIP
99*0Sstevel@tonic-gate #define	R_SP	UESP
100*0Sstevel@tonic-gate #define	R_RVAL1	EAX		/* register holding a function return value */
101*0Sstevel@tonic-gate #define	R_RVAL2	EDX		/* 32 more bits for a 64-bit return value */
102*0Sstevel@tonic-gate #endif	/* __amd64 || __i386 */
103*0Sstevel@tonic-gate 
104*0Sstevel@tonic-gate #define	R_RVAL	R_RVAL1		/* simple function return value register */
105*0Sstevel@tonic-gate 
106*0Sstevel@tonic-gate /* maximum sizes of things */
107*0Sstevel@tonic-gate #define	PRMAXSIG	(32 * sizeof (sigset_t) / sizeof (uint32_t))
108*0Sstevel@tonic-gate #define	PRMAXFAULT	(32 * sizeof (fltset_t) / sizeof (uint32_t))
109*0Sstevel@tonic-gate #define	PRMAXSYS	(32 * sizeof (sysset_t) / sizeof (uint32_t))
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate /* State values returned by Pstate() */
112*0Sstevel@tonic-gate #define	PS_RUN		1	/* process is running */
113*0Sstevel@tonic-gate #define	PS_STOP		2	/* process is stopped */
114*0Sstevel@tonic-gate #define	PS_LOST		3	/* process is lost to control (EAGAIN) */
115*0Sstevel@tonic-gate #define	PS_UNDEAD	4	/* process is terminated (zombie) */
116*0Sstevel@tonic-gate #define	PS_DEAD		5	/* process is terminated (core file) */
117*0Sstevel@tonic-gate #define	PS_IDLE		6	/* process has not been run */
118*0Sstevel@tonic-gate 
119*0Sstevel@tonic-gate /* Flags accepted by Pgrab() */
120*0Sstevel@tonic-gate #define	PGRAB_RETAIN	0x01	/* Retain tracing flags, else clear flags */
121*0Sstevel@tonic-gate #define	PGRAB_FORCE	0x02	/* Open the process w/o O_EXCL */
122*0Sstevel@tonic-gate #define	PGRAB_RDONLY	0x04	/* Open the process or core w/ O_RDONLY */
123*0Sstevel@tonic-gate #define	PGRAB_NOSTOP	0x08	/* Open the process but do not stop it */
124*0Sstevel@tonic-gate 
125*0Sstevel@tonic-gate /* Error codes from Pcreate() */
126*0Sstevel@tonic-gate #define	C_STRANGE	-1	/* Unanticipated error, errno is meaningful */
127*0Sstevel@tonic-gate #define	C_FORK		1	/* Unable to fork */
128*0Sstevel@tonic-gate #define	C_PERM		2	/* No permission (file set-id or unreadable) */
129*0Sstevel@tonic-gate #define	C_NOEXEC	3	/* Cannot execute file */
130*0Sstevel@tonic-gate #define	C_INTR		4	/* Interrupt received while creating */
131*0Sstevel@tonic-gate #define	C_LP64		5	/* Program is _LP64, self is _ILP32 */
132*0Sstevel@tonic-gate #define	C_NOENT		6	/* Cannot find executable file */
133*0Sstevel@tonic-gate 
134*0Sstevel@tonic-gate /* Error codes from Pgrab(), Pfgrab_core(), and Pgrab_core() */
135*0Sstevel@tonic-gate #define	G_STRANGE	-1	/* Unanticipated error, errno is meaningful */
136*0Sstevel@tonic-gate #define	G_NOPROC	1	/* No such process */
137*0Sstevel@tonic-gate #define	G_NOCORE	2	/* No such core file */
138*0Sstevel@tonic-gate #define	G_NOPROCORCORE	3	/* No such proc or core (for proc_arg_grab) */
139*0Sstevel@tonic-gate #define	G_NOEXEC	4	/* Cannot locate executable file */
140*0Sstevel@tonic-gate #define	G_ZOMB		5	/* Zombie process */
141*0Sstevel@tonic-gate #define	G_PERM		6	/* No permission */
142*0Sstevel@tonic-gate #define	G_BUSY		7	/* Another process has control */
143*0Sstevel@tonic-gate #define	G_SYS		8	/* System process */
144*0Sstevel@tonic-gate #define	G_SELF		9	/* Process is self */
145*0Sstevel@tonic-gate #define	G_INTR		10	/* Interrupt received while grabbing */
146*0Sstevel@tonic-gate #define	G_LP64		11	/* Process is _LP64, self is ILP32 */
147*0Sstevel@tonic-gate #define	G_FORMAT	12	/* File is not an ELF format core file */
148*0Sstevel@tonic-gate #define	G_ELF		13	/* Libelf error, elf_errno() is meaningful */
149*0Sstevel@tonic-gate #define	G_NOTE		14	/* Required PT_NOTE Phdr not present in core */
150*0Sstevel@tonic-gate #define	G_ISAINVAL	15	/* Wrong ELF machine type */
151*0Sstevel@tonic-gate #define	G_BADLWPS	16	/* Bad '/lwps' specification */
152*0Sstevel@tonic-gate 
153*0Sstevel@tonic-gate 
154*0Sstevel@tonic-gate /* Flags accepted by Prelease */
155*0Sstevel@tonic-gate #define	PRELEASE_CLEAR	0x10	/* Clear all tracing flags */
156*0Sstevel@tonic-gate #define	PRELEASE_RETAIN	0x20	/* Retain final tracing flags */
157*0Sstevel@tonic-gate #define	PRELEASE_HANG	0x40	/* Leave the process stopped */
158*0Sstevel@tonic-gate #define	PRELEASE_KILL	0x80	/* Terminate the process */
159*0Sstevel@tonic-gate 
160*0Sstevel@tonic-gate typedef	struct {	/* argument descriptor for system call (Psyscall) */
161*0Sstevel@tonic-gate 	long	arg_value;	/* value of argument given to system call */
162*0Sstevel@tonic-gate 	void	*arg_object;	/* pointer to object in controlling process */
163*0Sstevel@tonic-gate 	char	arg_type;	/* AT_BYVAL, AT_BYREF */
164*0Sstevel@tonic-gate 	char	arg_inout;	/* AI_INPUT, AI_OUTPUT, AI_INOUT */
165*0Sstevel@tonic-gate 	ushort_t arg_size;	/* if AT_BYREF, size of object in bytes */
166*0Sstevel@tonic-gate } argdes_t;
167*0Sstevel@tonic-gate 
168*0Sstevel@tonic-gate /* values for type */
169*0Sstevel@tonic-gate #define	AT_BYVAL	1
170*0Sstevel@tonic-gate #define	AT_BYREF	2
171*0Sstevel@tonic-gate 
172*0Sstevel@tonic-gate /* values for inout */
173*0Sstevel@tonic-gate #define	AI_INPUT	1
174*0Sstevel@tonic-gate #define	AI_OUTPUT	2
175*0Sstevel@tonic-gate #define	AI_INOUT	3
176*0Sstevel@tonic-gate 
177*0Sstevel@tonic-gate /* maximum number of syscall arguments */
178*0Sstevel@tonic-gate #define	MAXARGS		8
179*0Sstevel@tonic-gate 
180*0Sstevel@tonic-gate /* maximum size in bytes of a BYREF argument */
181*0Sstevel@tonic-gate #define	MAXARGL		(4*1024)
182*0Sstevel@tonic-gate 
183*0Sstevel@tonic-gate /*
184*0Sstevel@tonic-gate  * Function prototypes for routines in the process control package.
185*0Sstevel@tonic-gate  */
186*0Sstevel@tonic-gate extern struct ps_prochandle *Pcreate(const char *, char *const *,
187*0Sstevel@tonic-gate     int *, char *, size_t);
188*0Sstevel@tonic-gate extern struct ps_prochandle *Pxcreate(const char *, char *const *,
189*0Sstevel@tonic-gate     char *const *, int *, char *, size_t);
190*0Sstevel@tonic-gate 
191*0Sstevel@tonic-gate extern const char *Pcreate_error(int);
192*0Sstevel@tonic-gate 
193*0Sstevel@tonic-gate extern struct ps_prochandle *Pgrab(pid_t, int, int *);
194*0Sstevel@tonic-gate extern struct ps_prochandle *Pgrab_core(const char *, const char *, int, int *);
195*0Sstevel@tonic-gate extern struct ps_prochandle *Pfgrab_core(int, const char *, int *);
196*0Sstevel@tonic-gate extern struct ps_prochandle *Pgrab_file(const char *, int *);
197*0Sstevel@tonic-gate extern const char *Pgrab_error(int);
198*0Sstevel@tonic-gate 
199*0Sstevel@tonic-gate extern	int	Preopen(struct ps_prochandle *);
200*0Sstevel@tonic-gate extern	void	Prelease(struct ps_prochandle *, int);
201*0Sstevel@tonic-gate extern	void	Pfree(struct ps_prochandle *);
202*0Sstevel@tonic-gate 
203*0Sstevel@tonic-gate extern	int	Pasfd(struct ps_prochandle *);
204*0Sstevel@tonic-gate extern	int	Pctlfd(struct ps_prochandle *);
205*0Sstevel@tonic-gate extern	int	Pcreate_agent(struct ps_prochandle *);
206*0Sstevel@tonic-gate extern	void	Pdestroy_agent(struct ps_prochandle *);
207*0Sstevel@tonic-gate extern	int	Pstopstatus(struct ps_prochandle *, long, uint_t);
208*0Sstevel@tonic-gate extern	int	Pwait(struct ps_prochandle *, uint_t);
209*0Sstevel@tonic-gate extern	int	Pstop(struct ps_prochandle *, uint_t);
210*0Sstevel@tonic-gate extern	int	Pdstop(struct ps_prochandle *);
211*0Sstevel@tonic-gate extern	int	Pstate(struct ps_prochandle *);
212*0Sstevel@tonic-gate extern	const psinfo_t *Ppsinfo(struct ps_prochandle *);
213*0Sstevel@tonic-gate extern	const pstatus_t *Pstatus(struct ps_prochandle *);
214*0Sstevel@tonic-gate extern	int	Pcred(struct ps_prochandle *, prcred_t *, int);
215*0Sstevel@tonic-gate extern	int	Psetcred(struct ps_prochandle *, const prcred_t *);
216*0Sstevel@tonic-gate extern	ssize_t	Ppriv(struct ps_prochandle *, prpriv_t *, size_t);
217*0Sstevel@tonic-gate extern	int	Psetpriv(struct ps_prochandle *, prpriv_t *);
218*0Sstevel@tonic-gate extern	void   *Pprivinfo(struct ps_prochandle *);
219*0Sstevel@tonic-gate extern	int	Psetzoneid(struct ps_prochandle *, zoneid_t);
220*0Sstevel@tonic-gate extern	int	Pgetareg(struct ps_prochandle *, int, prgreg_t *);
221*0Sstevel@tonic-gate extern	int	Pputareg(struct ps_prochandle *, int, prgreg_t);
222*0Sstevel@tonic-gate extern	int	Psetrun(struct ps_prochandle *, int, int);
223*0Sstevel@tonic-gate extern	ssize_t	Pread(struct ps_prochandle *, void *, size_t, uintptr_t);
224*0Sstevel@tonic-gate extern	ssize_t Pread_string(struct ps_prochandle *, char *, size_t, uintptr_t);
225*0Sstevel@tonic-gate extern	ssize_t	Pwrite(struct ps_prochandle *, const void *, size_t, uintptr_t);
226*0Sstevel@tonic-gate extern	int	Pclearsig(struct ps_prochandle *);
227*0Sstevel@tonic-gate extern	int	Pclearfault(struct ps_prochandle *);
228*0Sstevel@tonic-gate extern	int	Psetbkpt(struct ps_prochandle *, uintptr_t, ulong_t *);
229*0Sstevel@tonic-gate extern	int	Pdelbkpt(struct ps_prochandle *, uintptr_t, ulong_t);
230*0Sstevel@tonic-gate extern	int	Pxecbkpt(struct ps_prochandle *, ulong_t);
231*0Sstevel@tonic-gate extern	int	Psetwapt(struct ps_prochandle *, const prwatch_t *);
232*0Sstevel@tonic-gate extern	int	Pdelwapt(struct ps_prochandle *, const prwatch_t *);
233*0Sstevel@tonic-gate extern	int	Pxecwapt(struct ps_prochandle *, const prwatch_t *);
234*0Sstevel@tonic-gate extern	int	Psetflags(struct ps_prochandle *, long);
235*0Sstevel@tonic-gate extern	int	Punsetflags(struct ps_prochandle *, long);
236*0Sstevel@tonic-gate extern	int	Psignal(struct ps_prochandle *, int, int);
237*0Sstevel@tonic-gate extern	int	Pfault(struct ps_prochandle *, int, int);
238*0Sstevel@tonic-gate extern	int	Psysentry(struct ps_prochandle *, int, int);
239*0Sstevel@tonic-gate extern	int	Psysexit(struct ps_prochandle *, int, int);
240*0Sstevel@tonic-gate extern	void	Psetsignal(struct ps_prochandle *, const sigset_t *);
241*0Sstevel@tonic-gate extern	void	Psetfault(struct ps_prochandle *, const fltset_t *);
242*0Sstevel@tonic-gate extern	void	Psetsysentry(struct ps_prochandle *, const sysset_t *);
243*0Sstevel@tonic-gate extern	void	Psetsysexit(struct ps_prochandle *, const sysset_t *);
244*0Sstevel@tonic-gate 
245*0Sstevel@tonic-gate extern	void	Psync(struct ps_prochandle *);
246*0Sstevel@tonic-gate extern	int	Psyscall(struct ps_prochandle *, sysret_t *,
247*0Sstevel@tonic-gate 			int, uint_t, argdes_t *);
248*0Sstevel@tonic-gate extern	int	Pisprocdir(struct ps_prochandle *, const char *);
249*0Sstevel@tonic-gate 
250*0Sstevel@tonic-gate /*
251*0Sstevel@tonic-gate  * Function prototypes for lwp-specific operations.
252*0Sstevel@tonic-gate  */
253*0Sstevel@tonic-gate extern	struct ps_lwphandle *Lgrab(struct ps_prochandle *, lwpid_t, int *);
254*0Sstevel@tonic-gate extern	const char *Lgrab_error(int);
255*0Sstevel@tonic-gate 
256*0Sstevel@tonic-gate extern	struct ps_prochandle *Lprochandle(struct ps_lwphandle *);
257*0Sstevel@tonic-gate extern	void	Lfree(struct ps_lwphandle *);
258*0Sstevel@tonic-gate 
259*0Sstevel@tonic-gate extern	int	Lctlfd(struct ps_lwphandle *);
260*0Sstevel@tonic-gate extern	int	Lwait(struct ps_lwphandle *, uint_t);
261*0Sstevel@tonic-gate extern	int	Lstop(struct ps_lwphandle *, uint_t);
262*0Sstevel@tonic-gate extern	int	Ldstop(struct ps_lwphandle *);
263*0Sstevel@tonic-gate extern	int	Lstate(struct ps_lwphandle *);
264*0Sstevel@tonic-gate extern	const lwpsinfo_t *Lpsinfo(struct ps_lwphandle *);
265*0Sstevel@tonic-gate extern	const lwpstatus_t *Lstatus(struct ps_lwphandle *);
266*0Sstevel@tonic-gate extern	int	Lgetareg(struct ps_lwphandle *, int, prgreg_t *);
267*0Sstevel@tonic-gate extern	int	Lputareg(struct ps_lwphandle *, int, prgreg_t);
268*0Sstevel@tonic-gate extern	int	Lsetrun(struct ps_lwphandle *, int, int);
269*0Sstevel@tonic-gate extern	int	Lclearsig(struct ps_lwphandle *);
270*0Sstevel@tonic-gate extern	int	Lclearfault(struct ps_lwphandle *);
271*0Sstevel@tonic-gate extern	int	Lxecbkpt(struct ps_lwphandle *, ulong_t);
272*0Sstevel@tonic-gate extern	int	Lxecwapt(struct ps_lwphandle *, const prwatch_t *);
273*0Sstevel@tonic-gate extern	void	Lsync(struct ps_lwphandle *);
274*0Sstevel@tonic-gate 
275*0Sstevel@tonic-gate extern	int	Lstack(struct ps_lwphandle *, stack_t *);
276*0Sstevel@tonic-gate extern	int	Lmain_stack(struct ps_lwphandle *, stack_t *);
277*0Sstevel@tonic-gate extern	int	Lalt_stack(struct ps_lwphandle *, stack_t *);
278*0Sstevel@tonic-gate 
279*0Sstevel@tonic-gate /*
280*0Sstevel@tonic-gate  * Function prototypes for system calls forced on the victim process.
281*0Sstevel@tonic-gate  */
282*0Sstevel@tonic-gate extern	int	pr_open(struct ps_prochandle *, const char *, int, mode_t);
283*0Sstevel@tonic-gate extern	int	pr_creat(struct ps_prochandle *, const char *, mode_t);
284*0Sstevel@tonic-gate extern	int	pr_close(struct ps_prochandle *, int);
285*0Sstevel@tonic-gate extern	int	pr_access(struct ps_prochandle *, const char *, int);
286*0Sstevel@tonic-gate extern	int	pr_door_info(struct ps_prochandle *, int, struct door_info *);
287*0Sstevel@tonic-gate extern	void	*pr_mmap(struct ps_prochandle *,
288*0Sstevel@tonic-gate 			void *, size_t, int, int, int, off_t);
289*0Sstevel@tonic-gate extern	void	*pr_zmap(struct ps_prochandle *,
290*0Sstevel@tonic-gate 			void *, size_t, int, int);
291*0Sstevel@tonic-gate extern	int	pr_munmap(struct ps_prochandle *, void *, size_t);
292*0Sstevel@tonic-gate extern	int	pr_memcntl(struct ps_prochandle *,
293*0Sstevel@tonic-gate 			caddr_t, size_t, int, caddr_t, int, int);
294*0Sstevel@tonic-gate extern	int	pr_meminfo(struct ps_prochandle *, const uint64_t *addrs,
295*0Sstevel@tonic-gate 			int addr_count, const uint_t *info, int info_count,
296*0Sstevel@tonic-gate 			uint64_t *outdata, uint_t *validity);
297*0Sstevel@tonic-gate extern	int	pr_sigaction(struct ps_prochandle *,
298*0Sstevel@tonic-gate 			int, const struct sigaction *, struct sigaction *);
299*0Sstevel@tonic-gate extern	int	pr_getitimer(struct ps_prochandle *,
300*0Sstevel@tonic-gate 			int, struct itimerval *);
301*0Sstevel@tonic-gate extern	int	pr_setitimer(struct ps_prochandle *,
302*0Sstevel@tonic-gate 			int, const struct itimerval *, struct itimerval *);
303*0Sstevel@tonic-gate extern	int	pr_ioctl(struct ps_prochandle *, int, int, void *, size_t);
304*0Sstevel@tonic-gate extern	int	pr_fcntl(struct ps_prochandle *, int, int, void *);
305*0Sstevel@tonic-gate extern	int	pr_stat(struct ps_prochandle *, const char *, struct stat *);
306*0Sstevel@tonic-gate extern	int	pr_lstat(struct ps_prochandle *, const char *, struct stat *);
307*0Sstevel@tonic-gate extern	int	pr_fstat(struct ps_prochandle *, int, struct stat *);
308*0Sstevel@tonic-gate extern	int	pr_stat64(struct ps_prochandle *, const char *,
309*0Sstevel@tonic-gate 			struct stat64 *);
310*0Sstevel@tonic-gate extern	int	pr_lstat64(struct ps_prochandle *, const char *,
311*0Sstevel@tonic-gate 			struct stat64 *);
312*0Sstevel@tonic-gate extern	int	pr_fstat64(struct ps_prochandle *, int, struct stat64 *);
313*0Sstevel@tonic-gate extern	int	pr_statvfs(struct ps_prochandle *, const char *, statvfs_t *);
314*0Sstevel@tonic-gate extern	int	pr_fstatvfs(struct ps_prochandle *, int, statvfs_t *);
315*0Sstevel@tonic-gate extern	projid_t pr_getprojid(struct ps_prochandle *Pr);
316*0Sstevel@tonic-gate extern	taskid_t pr_gettaskid(struct ps_prochandle *Pr);
317*0Sstevel@tonic-gate extern	taskid_t pr_settaskid(struct ps_prochandle *Pr, projid_t project,
318*0Sstevel@tonic-gate 			int flags);
319*0Sstevel@tonic-gate extern	zoneid_t pr_getzoneid(struct ps_prochandle *Pr);
320*0Sstevel@tonic-gate extern	int	pr_getrctl(struct ps_prochandle *,
321*0Sstevel@tonic-gate 			const char *, rctlblk_t *, rctlblk_t *, int);
322*0Sstevel@tonic-gate extern	int	pr_setrctl(struct ps_prochandle *,
323*0Sstevel@tonic-gate 			const char *, rctlblk_t *, rctlblk_t *, int);
324*0Sstevel@tonic-gate extern	int	pr_getrlimit(struct ps_prochandle *,
325*0Sstevel@tonic-gate 			int, struct rlimit *);
326*0Sstevel@tonic-gate extern	int	pr_setrlimit(struct ps_prochandle *,
327*0Sstevel@tonic-gate 			int, const struct rlimit *);
328*0Sstevel@tonic-gate #if defined(_LARGEFILE64_SOURCE)
329*0Sstevel@tonic-gate extern	int	pr_getrlimit64(struct ps_prochandle *,
330*0Sstevel@tonic-gate 			int, struct rlimit64 *);
331*0Sstevel@tonic-gate extern	int	pr_setrlimit64(struct ps_prochandle *,
332*0Sstevel@tonic-gate 			int, const struct rlimit64 *);
333*0Sstevel@tonic-gate #endif	/* _LARGEFILE64_SOURCE */
334*0Sstevel@tonic-gate extern	int	pr_lwp_exit(struct ps_prochandle *);
335*0Sstevel@tonic-gate extern	int	pr_exit(struct ps_prochandle *, int);
336*0Sstevel@tonic-gate extern	int	pr_waitid(struct ps_prochandle *,
337*0Sstevel@tonic-gate 			idtype_t, id_t, siginfo_t *, int);
338*0Sstevel@tonic-gate extern	off_t	pr_lseek(struct ps_prochandle *, int, off_t, int);
339*0Sstevel@tonic-gate extern	offset_t pr_llseek(struct ps_prochandle *, int, offset_t, int);
340*0Sstevel@tonic-gate extern	int	pr_rename(struct ps_prochandle *, const char *, const char *);
341*0Sstevel@tonic-gate extern	int	pr_link(struct ps_prochandle *, const char *, const char *);
342*0Sstevel@tonic-gate extern	int	pr_unlink(struct ps_prochandle *, const char *);
343*0Sstevel@tonic-gate extern	int	pr_getpeername(struct ps_prochandle *,
344*0Sstevel@tonic-gate 			int, struct sockaddr *, socklen_t *);
345*0Sstevel@tonic-gate extern	int	pr_getsockname(struct ps_prochandle *,
346*0Sstevel@tonic-gate 			int, struct sockaddr *, socklen_t *);
347*0Sstevel@tonic-gate extern	int	pr_getsockopt(struct ps_prochandle *,
348*0Sstevel@tonic-gate 			int, int, int, void *, int *);
349*0Sstevel@tonic-gate extern	int	pr_processor_bind(struct ps_prochandle *,
350*0Sstevel@tonic-gate 			idtype_t, id_t, int, int *);
351*0Sstevel@tonic-gate extern	int	pr_pset_bind(struct ps_prochandle *,
352*0Sstevel@tonic-gate 			int, idtype_t, id_t, int *);
353*0Sstevel@tonic-gate 
354*0Sstevel@tonic-gate /*
355*0Sstevel@tonic-gate  * Function prototypes for accessing per-LWP register information.
356*0Sstevel@tonic-gate  */
357*0Sstevel@tonic-gate extern int Plwp_getregs(struct ps_prochandle *, lwpid_t, prgregset_t);
358*0Sstevel@tonic-gate extern int Plwp_setregs(struct ps_prochandle *, lwpid_t, const prgregset_t);
359*0Sstevel@tonic-gate 
360*0Sstevel@tonic-gate extern int Plwp_getfpregs(struct ps_prochandle *, lwpid_t, prfpregset_t *);
361*0Sstevel@tonic-gate extern int Plwp_setfpregs(struct ps_prochandle *, lwpid_t,
362*0Sstevel@tonic-gate     const prfpregset_t *);
363*0Sstevel@tonic-gate 
364*0Sstevel@tonic-gate #if defined(__sparc)
365*0Sstevel@tonic-gate 
366*0Sstevel@tonic-gate extern int Plwp_getxregs(struct ps_prochandle *, lwpid_t, prxregset_t *);
367*0Sstevel@tonic-gate extern int Plwp_setxregs(struct ps_prochandle *, lwpid_t, const prxregset_t *);
368*0Sstevel@tonic-gate 
369*0Sstevel@tonic-gate extern int Plwp_getgwindows(struct ps_prochandle *, lwpid_t, gwindows_t *);
370*0Sstevel@tonic-gate 
371*0Sstevel@tonic-gate #if defined(__sparcv9)
372*0Sstevel@tonic-gate extern int Plwp_getasrs(struct ps_prochandle *, lwpid_t, asrset_t);
373*0Sstevel@tonic-gate extern int Plwp_setasrs(struct ps_prochandle *, lwpid_t, const asrset_t);
374*0Sstevel@tonic-gate #endif	/* __sparcv9 */
375*0Sstevel@tonic-gate 
376*0Sstevel@tonic-gate #endif	/* __sparc */
377*0Sstevel@tonic-gate 
378*0Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
379*0Sstevel@tonic-gate extern	int	Pldt(struct ps_prochandle *, struct ssd *, int);
380*0Sstevel@tonic-gate extern	int	proc_get_ldt(pid_t, struct ssd *, int);
381*0Sstevel@tonic-gate #endif	/* __i386 || __amd64 */
382*0Sstevel@tonic-gate 
383*0Sstevel@tonic-gate extern int Plwp_getpsinfo(struct ps_prochandle *, lwpid_t, lwpsinfo_t *);
384*0Sstevel@tonic-gate 
385*0Sstevel@tonic-gate extern int Plwp_stack(struct ps_prochandle *, lwpid_t, stack_t *);
386*0Sstevel@tonic-gate extern int Plwp_main_stack(struct ps_prochandle *, lwpid_t, stack_t *);
387*0Sstevel@tonic-gate extern int Plwp_alt_stack(struct ps_prochandle *, lwpid_t, stack_t *);
388*0Sstevel@tonic-gate 
389*0Sstevel@tonic-gate /*
390*0Sstevel@tonic-gate  * LWP iteration interface; iterate over all active LWPs.
391*0Sstevel@tonic-gate  */
392*0Sstevel@tonic-gate typedef int proc_lwp_f(void *, const lwpstatus_t *);
393*0Sstevel@tonic-gate extern int Plwp_iter(struct ps_prochandle *, proc_lwp_f *, void *);
394*0Sstevel@tonic-gate 
395*0Sstevel@tonic-gate /*
396*0Sstevel@tonic-gate  * LWP iteration interface; iterate over all LWPs, active and zombie.
397*0Sstevel@tonic-gate  */
398*0Sstevel@tonic-gate typedef int proc_lwp_all_f(void *, const lwpstatus_t *, const lwpsinfo_t *);
399*0Sstevel@tonic-gate extern int Plwp_iter_all(struct ps_prochandle *, proc_lwp_all_f *, void *);
400*0Sstevel@tonic-gate 
401*0Sstevel@tonic-gate /*
402*0Sstevel@tonic-gate  * Process iteration interface; iterate over all active processes.
403*0Sstevel@tonic-gate  */
404*0Sstevel@tonic-gate typedef int proc_walk_f(psinfo_t *, lwpsinfo_t *, void *);
405*0Sstevel@tonic-gate extern int proc_walk(proc_walk_f *, void *, int);
406*0Sstevel@tonic-gate 
407*0Sstevel@tonic-gate #define	PR_WALK_PROC	0		/* walk processes only */
408*0Sstevel@tonic-gate #define	PR_WALK_LWP	1		/* walk all lwps */
409*0Sstevel@tonic-gate 
410*0Sstevel@tonic-gate /*
411*0Sstevel@tonic-gate  * Determine if an lwp is in a set as returned from proc_arg_xgrab().
412*0Sstevel@tonic-gate  */
413*0Sstevel@tonic-gate extern int proc_lwp_in_set(const char *, lwpid_t);
414*0Sstevel@tonic-gate extern int proc_lwp_range_valid(const char *);
415*0Sstevel@tonic-gate 
416*0Sstevel@tonic-gate /*
417*0Sstevel@tonic-gate  * Symbol table interfaces.
418*0Sstevel@tonic-gate  */
419*0Sstevel@tonic-gate 
420*0Sstevel@tonic-gate /*
421*0Sstevel@tonic-gate  * Pseudo-names passed to Plookup_by_name() for well-known load objects.
422*0Sstevel@tonic-gate  * NOTE: It is required that PR_OBJ_EXEC and PR_OBJ_LDSO exactly match
423*0Sstevel@tonic-gate  * the definitions of PS_OBJ_EXEC and PS_OBJ_LDSO from <proc_service.h>.
424*0Sstevel@tonic-gate  */
425*0Sstevel@tonic-gate #define	PR_OBJ_EXEC	((const char *)0)	/* search the executable file */
426*0Sstevel@tonic-gate #define	PR_OBJ_LDSO	((const char *)1)	/* search ld.so.1 */
427*0Sstevel@tonic-gate #define	PR_OBJ_EVERY	((const char *)-1)	/* search every load object */
428*0Sstevel@tonic-gate 
429*0Sstevel@tonic-gate /*
430*0Sstevel@tonic-gate  * Special Lmid_t passed to Plookup_by_lmid() to search all link maps.  The
431*0Sstevel@tonic-gate  * special values LM_ID_BASE and LM_ID_LDSO from <link.h> may also be used.
432*0Sstevel@tonic-gate  * If PR_OBJ_EXEC is used as the object name, the lmid must be PR_LMID_EVERY
433*0Sstevel@tonic-gate  * or LM_ID_BASE in order to return a match.  If PR_OBJ_LDSO is used as the
434*0Sstevel@tonic-gate  * object name, the lmid must be PR_LMID_EVERY or LM_ID_LDSO to return a match.
435*0Sstevel@tonic-gate  */
436*0Sstevel@tonic-gate #define	PR_LMID_EVERY	((Lmid_t)-1UL)		/* search every link map */
437*0Sstevel@tonic-gate 
438*0Sstevel@tonic-gate /*
439*0Sstevel@tonic-gate  * 'object_name' is the name of a load object obtained from an
440*0Sstevel@tonic-gate  * iteration over the process's address space mappings (Pmapping_iter),
441*0Sstevel@tonic-gate  * or an iteration over the process's mapped objects (Pobject_iter),
442*0Sstevel@tonic-gate  * or else it is one of the special PR_OBJ_* values above.
443*0Sstevel@tonic-gate  */
444*0Sstevel@tonic-gate extern int Plookup_by_name(struct ps_prochandle *,
445*0Sstevel@tonic-gate     const char *, const char *, GElf_Sym *);
446*0Sstevel@tonic-gate 
447*0Sstevel@tonic-gate extern int Plookup_by_addr(struct ps_prochandle *,
448*0Sstevel@tonic-gate     uintptr_t, char *, size_t, GElf_Sym *);
449*0Sstevel@tonic-gate 
450*0Sstevel@tonic-gate typedef struct prsyminfo {
451*0Sstevel@tonic-gate 	const char	*prs_object;		/* object name */
452*0Sstevel@tonic-gate 	const char	*prs_name;		/* symbol name */
453*0Sstevel@tonic-gate 	Lmid_t		prs_lmid;		/* link map id */
454*0Sstevel@tonic-gate 	uint_t		prs_id;			/* symbol id */
455*0Sstevel@tonic-gate 	uint_t		prs_table;		/* symbol table id */
456*0Sstevel@tonic-gate } prsyminfo_t;
457*0Sstevel@tonic-gate 
458*0Sstevel@tonic-gate extern int Pxlookup_by_name(struct ps_prochandle *,
459*0Sstevel@tonic-gate     Lmid_t, const char *, const char *, GElf_Sym *, prsyminfo_t *);
460*0Sstevel@tonic-gate 
461*0Sstevel@tonic-gate extern int Pxlookup_by_addr(struct ps_prochandle *,
462*0Sstevel@tonic-gate     uintptr_t, char *, size_t, GElf_Sym *, prsyminfo_t *);
463*0Sstevel@tonic-gate 
464*0Sstevel@tonic-gate typedef int proc_map_f(void *, const prmap_t *, const char *);
465*0Sstevel@tonic-gate 
466*0Sstevel@tonic-gate extern int Pmapping_iter(struct ps_prochandle *, proc_map_f *, void *);
467*0Sstevel@tonic-gate extern int Pobject_iter(struct ps_prochandle *, proc_map_f *, void *);
468*0Sstevel@tonic-gate 
469*0Sstevel@tonic-gate extern const prmap_t *Paddr_to_map(struct ps_prochandle *, uintptr_t);
470*0Sstevel@tonic-gate extern const prmap_t *Paddr_to_text_map(struct ps_prochandle *, uintptr_t);
471*0Sstevel@tonic-gate extern const prmap_t *Pname_to_map(struct ps_prochandle *, const char *);
472*0Sstevel@tonic-gate extern const prmap_t *Plmid_to_map(struct ps_prochandle *,
473*0Sstevel@tonic-gate     Lmid_t, const char *);
474*0Sstevel@tonic-gate 
475*0Sstevel@tonic-gate extern const rd_loadobj_t *Paddr_to_loadobj(struct ps_prochandle *, uintptr_t);
476*0Sstevel@tonic-gate extern const rd_loadobj_t *Pname_to_loadobj(struct ps_prochandle *,
477*0Sstevel@tonic-gate     const char *);
478*0Sstevel@tonic-gate extern const rd_loadobj_t *Plmid_to_loadobj(struct ps_prochandle *,
479*0Sstevel@tonic-gate     Lmid_t, const char *);
480*0Sstevel@tonic-gate 
481*0Sstevel@tonic-gate extern ctf_file_t *Paddr_to_ctf(struct ps_prochandle *, uintptr_t);
482*0Sstevel@tonic-gate extern ctf_file_t *Pname_to_ctf(struct ps_prochandle *, const char *);
483*0Sstevel@tonic-gate 
484*0Sstevel@tonic-gate extern char *Pplatform(struct ps_prochandle *, char *, size_t);
485*0Sstevel@tonic-gate extern int Puname(struct ps_prochandle *, struct utsname *);
486*0Sstevel@tonic-gate extern char *Pzonename(struct ps_prochandle *, char *, size_t);
487*0Sstevel@tonic-gate 
488*0Sstevel@tonic-gate extern char *Pexecname(struct ps_prochandle *, char *, size_t);
489*0Sstevel@tonic-gate extern char *Pobjname(struct ps_prochandle *, uintptr_t, char *, size_t);
490*0Sstevel@tonic-gate extern int Plmid(struct ps_prochandle *, uintptr_t, Lmid_t *);
491*0Sstevel@tonic-gate 
492*0Sstevel@tonic-gate typedef int proc_env_f(void *, struct ps_prochandle *, uintptr_t, const char *);
493*0Sstevel@tonic-gate extern	int Penv_iter(struct ps_prochandle *, proc_env_f *, void *);
494*0Sstevel@tonic-gate extern char *Pgetenv(struct ps_prochandle *, const char *, char *, size_t);
495*0Sstevel@tonic-gate extern long Pgetauxval(struct ps_prochandle *, int);
496*0Sstevel@tonic-gate extern const auxv_t *Pgetauxvec(struct ps_prochandle *);
497*0Sstevel@tonic-gate 
498*0Sstevel@tonic-gate /*
499*0Sstevel@tonic-gate  * Symbol table iteration interface.  The special lmid constants LM_ID_BASE,
500*0Sstevel@tonic-gate  * LM_ID_LDSO, and PR_LMID_EVERY may be used with Psymbol_iter_by_lmid.
501*0Sstevel@tonic-gate  */
502*0Sstevel@tonic-gate typedef int proc_sym_f(void *, const GElf_Sym *, const char *);
503*0Sstevel@tonic-gate typedef int proc_xsym_f(void *, const GElf_Sym *, const char *,
504*0Sstevel@tonic-gate     const prsyminfo_t *);
505*0Sstevel@tonic-gate 
506*0Sstevel@tonic-gate extern int Psymbol_iter(struct ps_prochandle *,
507*0Sstevel@tonic-gate     const char *, int, int, proc_sym_f *, void *);
508*0Sstevel@tonic-gate extern int Psymbol_iter_by_addr(struct ps_prochandle *,
509*0Sstevel@tonic-gate     const char *, int, int, proc_sym_f *, void *);
510*0Sstevel@tonic-gate extern int Psymbol_iter_by_name(struct ps_prochandle *,
511*0Sstevel@tonic-gate     const char *, int, int, proc_sym_f *, void *);
512*0Sstevel@tonic-gate 
513*0Sstevel@tonic-gate extern int Psymbol_iter_by_lmid(struct ps_prochandle *,
514*0Sstevel@tonic-gate     Lmid_t, const char *, int, int, proc_sym_f *, void *);
515*0Sstevel@tonic-gate 
516*0Sstevel@tonic-gate extern int Pxsymbol_iter(struct ps_prochandle *,
517*0Sstevel@tonic-gate     Lmid_t, const char *, int, int, proc_xsym_f *, void *);
518*0Sstevel@tonic-gate 
519*0Sstevel@tonic-gate /*
520*0Sstevel@tonic-gate  * 'which' selects which symbol table and can be one of the following.
521*0Sstevel@tonic-gate  */
522*0Sstevel@tonic-gate #define	PR_SYMTAB	1
523*0Sstevel@tonic-gate #define	PR_DYNSYM	2
524*0Sstevel@tonic-gate /*
525*0Sstevel@tonic-gate  * 'type' selects the symbols of interest by binding and type.  It is a bit-
526*0Sstevel@tonic-gate  * mask of one or more of the following flags, whose order MUST match the
527*0Sstevel@tonic-gate  * order of STB and STT constants in <sys/elf.h>.
528*0Sstevel@tonic-gate  */
529*0Sstevel@tonic-gate #define	BIND_LOCAL	0x0001
530*0Sstevel@tonic-gate #define	BIND_GLOBAL	0x0002
531*0Sstevel@tonic-gate #define	BIND_WEAK	0x0004
532*0Sstevel@tonic-gate #define	BIND_ANY (BIND_LOCAL|BIND_GLOBAL|BIND_WEAK)
533*0Sstevel@tonic-gate #define	TYPE_NOTYPE	0x0100
534*0Sstevel@tonic-gate #define	TYPE_OBJECT	0x0200
535*0Sstevel@tonic-gate #define	TYPE_FUNC	0x0400
536*0Sstevel@tonic-gate #define	TYPE_SECTION	0x0800
537*0Sstevel@tonic-gate #define	TYPE_FILE	0x1000
538*0Sstevel@tonic-gate #define	TYPE_ANY (TYPE_NOTYPE|TYPE_OBJECT|TYPE_FUNC|TYPE_SECTION|TYPE_FILE)
539*0Sstevel@tonic-gate 
540*0Sstevel@tonic-gate /*
541*0Sstevel@tonic-gate  * This returns the rtld_db agent handle for the process.
542*0Sstevel@tonic-gate  * The handle will become invalid at the next successful exec() and
543*0Sstevel@tonic-gate  * must not be used beyond that point (see Preset_maps(), below).
544*0Sstevel@tonic-gate  */
545*0Sstevel@tonic-gate extern rd_agent_t *Prd_agent(struct ps_prochandle *);
546*0Sstevel@tonic-gate 
547*0Sstevel@tonic-gate /*
548*0Sstevel@tonic-gate  * This should be called when an RD_DLACTIVITY event with the
549*0Sstevel@tonic-gate  * RD_CONSISTENT state occurs via librtld_db's event mechanism.
550*0Sstevel@tonic-gate  * This makes libproc's address space mappings and symbol tables current.
551*0Sstevel@tonic-gate  * The variant Pupdate_syms() can be used to preload all symbol tables as well.
552*0Sstevel@tonic-gate  */
553*0Sstevel@tonic-gate extern void Pupdate_maps(struct ps_prochandle *);
554*0Sstevel@tonic-gate extern void Pupdate_syms(struct ps_prochandle *);
555*0Sstevel@tonic-gate 
556*0Sstevel@tonic-gate /*
557*0Sstevel@tonic-gate  * This must be called after the victim process performs a successful
558*0Sstevel@tonic-gate  * exec() if any of the symbol table interface functions have been called
559*0Sstevel@tonic-gate  * prior to that point.  This is essential because an exec() invalidates
560*0Sstevel@tonic-gate  * all previous symbol table and address space mapping information.
561*0Sstevel@tonic-gate  * It is always safe to call, but if it is called other than after an
562*0Sstevel@tonic-gate  * exec() by the victim process it just causes unnecessary overhead.
563*0Sstevel@tonic-gate  *
564*0Sstevel@tonic-gate  * The rtld_db agent handle obtained from a previous call to Prd_agent() is
565*0Sstevel@tonic-gate  * made invalid by Preset_maps() and Prd_agent() must be called again to get
566*0Sstevel@tonic-gate  * the new handle.
567*0Sstevel@tonic-gate  */
568*0Sstevel@tonic-gate extern void Preset_maps(struct ps_prochandle *);
569*0Sstevel@tonic-gate 
570*0Sstevel@tonic-gate /*
571*0Sstevel@tonic-gate  * Given an address, Ppltdest() determines if this is part of a PLT, and if
572*0Sstevel@tonic-gate  * so returns a pointer to the symbol name that will be used for resolution.
573*0Sstevel@tonic-gate  * If the specified address is not part of a PLT, the function returns NULL.
574*0Sstevel@tonic-gate  */
575*0Sstevel@tonic-gate extern const char *Ppltdest(struct ps_prochandle *, uintptr_t);
576*0Sstevel@tonic-gate 
577*0Sstevel@tonic-gate /*
578*0Sstevel@tonic-gate  * See comments for Pissyscall(), in Pisadep.h
579*0Sstevel@tonic-gate  */
580*0Sstevel@tonic-gate extern int Pissyscall_prev(struct ps_prochandle *, uintptr_t, uintptr_t *);
581*0Sstevel@tonic-gate 
582*0Sstevel@tonic-gate /*
583*0Sstevel@tonic-gate  * Stack frame iteration interface.
584*0Sstevel@tonic-gate  */
585*0Sstevel@tonic-gate typedef int proc_stack_f(void *, prgregset_t, uint_t, const long *);
586*0Sstevel@tonic-gate 
587*0Sstevel@tonic-gate extern int Pstack_iter(struct ps_prochandle *,
588*0Sstevel@tonic-gate     const prgregset_t, proc_stack_f *, void *);
589*0Sstevel@tonic-gate 
590*0Sstevel@tonic-gate /*
591*0Sstevel@tonic-gate  * The following functions define a set of passive interfaces: libproc provides
592*0Sstevel@tonic-gate  * default, empty definitions that are called internally.  If a client wishes
593*0Sstevel@tonic-gate  * to override these definitions, it can simply provide its own version with
594*0Sstevel@tonic-gate  * the same signature that interposes on the libproc definition.
595*0Sstevel@tonic-gate  *
596*0Sstevel@tonic-gate  * If the client program wishes to report additional error information, it
597*0Sstevel@tonic-gate  * can provide its own version of Perror_printf.
598*0Sstevel@tonic-gate  *
599*0Sstevel@tonic-gate  * If the client program wishes to receive a callback after Pcreate forks
600*0Sstevel@tonic-gate  * but before it execs, it can provide its own version of Pcreate_callback.
601*0Sstevel@tonic-gate  */
602*0Sstevel@tonic-gate extern void Perror_printf(struct ps_prochandle *P, const char *format, ...);
603*0Sstevel@tonic-gate extern void Pcreate_callback(struct ps_prochandle *);
604*0Sstevel@tonic-gate 
605*0Sstevel@tonic-gate /*
606*0Sstevel@tonic-gate  * Remove unprintable characters from psinfo.pr_psargs and replace with
607*0Sstevel@tonic-gate  * whitespace characters so it is safe for printing.
608*0Sstevel@tonic-gate  */
609*0Sstevel@tonic-gate extern void proc_unctrl_psinfo(psinfo_t *);
610*0Sstevel@tonic-gate 
611*0Sstevel@tonic-gate /*
612*0Sstevel@tonic-gate  * Utility functions for processing arguments which should be /proc files,
613*0Sstevel@tonic-gate  * pids, and/or core files.  The returned error code can be passed to
614*0Sstevel@tonic-gate  * Pgrab_error() in order to convert it to an error string.
615*0Sstevel@tonic-gate  */
616*0Sstevel@tonic-gate #define	PR_ARG_PIDS	0x1	/* Allow pid and /proc file arguments */
617*0Sstevel@tonic-gate #define	PR_ARG_CORES	0x2	/* Allow core file arguments */
618*0Sstevel@tonic-gate 
619*0Sstevel@tonic-gate #define	PR_ARG_ANY	(PR_ARG_PIDS | PR_ARG_CORES)
620*0Sstevel@tonic-gate 
621*0Sstevel@tonic-gate extern struct ps_prochandle *proc_arg_grab(const char *, int, int, int *);
622*0Sstevel@tonic-gate extern struct ps_prochandle *proc_arg_xgrab(const char *, const char *, int,
623*0Sstevel@tonic-gate     int, int *, const char **);
624*0Sstevel@tonic-gate extern pid_t proc_arg_psinfo(const char *, int, psinfo_t *, int *);
625*0Sstevel@tonic-gate extern pid_t proc_arg_xpsinfo(const char *, int, psinfo_t *, int *,
626*0Sstevel@tonic-gate     const char **);
627*0Sstevel@tonic-gate 
628*0Sstevel@tonic-gate /*
629*0Sstevel@tonic-gate  * Utility functions for obtaining information via /proc without actually
630*0Sstevel@tonic-gate  * performing a Pcreate() or Pgrab():
631*0Sstevel@tonic-gate  */
632*0Sstevel@tonic-gate extern int proc_get_auxv(pid_t, auxv_t *, int);
633*0Sstevel@tonic-gate extern int proc_get_cred(pid_t, prcred_t *, int);
634*0Sstevel@tonic-gate extern prpriv_t *proc_get_priv(pid_t);
635*0Sstevel@tonic-gate extern int proc_get_psinfo(pid_t, psinfo_t *);
636*0Sstevel@tonic-gate extern int proc_get_status(pid_t, pstatus_t *);
637*0Sstevel@tonic-gate 
638*0Sstevel@tonic-gate /*
639*0Sstevel@tonic-gate  * Utility functions for debugging tools to convert numeric fault,
640*0Sstevel@tonic-gate  * signal, and system call numbers to symbolic names:
641*0Sstevel@tonic-gate  */
642*0Sstevel@tonic-gate #define	FLT2STR_MAX 32	/* max. string length of faults (like SIG2STR_MAX) */
643*0Sstevel@tonic-gate #define	SYS2STR_MAX 32	/* max. string length of syscalls (like SIG2STR_MAX) */
644*0Sstevel@tonic-gate 
645*0Sstevel@tonic-gate extern char *proc_fltname(int, char *, size_t);
646*0Sstevel@tonic-gate extern char *proc_signame(int, char *, size_t);
647*0Sstevel@tonic-gate extern char *proc_sysname(int, char *, size_t);
648*0Sstevel@tonic-gate 
649*0Sstevel@tonic-gate /*
650*0Sstevel@tonic-gate  * Utility functions for debugging tools to convert fault, signal, and system
651*0Sstevel@tonic-gate  * call names back to the numeric constants:
652*0Sstevel@tonic-gate  */
653*0Sstevel@tonic-gate extern int proc_str2flt(const char *, int *);
654*0Sstevel@tonic-gate extern int proc_str2sig(const char *, int *);
655*0Sstevel@tonic-gate extern int proc_str2sys(const char *, int *);
656*0Sstevel@tonic-gate 
657*0Sstevel@tonic-gate /*
658*0Sstevel@tonic-gate  * Utility functions for debugging tools to convert a fault, signal or system
659*0Sstevel@tonic-gate  * call set to a string representation (e.g. "BUS,SEGV" or "open,close,read").
660*0Sstevel@tonic-gate  */
661*0Sstevel@tonic-gate #define	PRSIGBUFSZ	1024	/* buffer size for proc_sigset2str() */
662*0Sstevel@tonic-gate 
663*0Sstevel@tonic-gate extern char *proc_fltset2str(const fltset_t *, const char *, int,
664*0Sstevel@tonic-gate     char *, size_t);
665*0Sstevel@tonic-gate extern char *proc_sigset2str(const sigset_t *, const char *, int,
666*0Sstevel@tonic-gate     char *, size_t);
667*0Sstevel@tonic-gate extern char *proc_sysset2str(const sysset_t *, const char *, int,
668*0Sstevel@tonic-gate     char *, size_t);
669*0Sstevel@tonic-gate 
670*0Sstevel@tonic-gate extern int Pgcore(struct ps_prochandle *, const char *, core_content_t);
671*0Sstevel@tonic-gate extern int Pfgcore(struct ps_prochandle *, int, core_content_t);
672*0Sstevel@tonic-gate extern core_content_t Pcontent(struct ps_prochandle *);
673*0Sstevel@tonic-gate 
674*0Sstevel@tonic-gate /*
675*0Sstevel@tonic-gate  * Utility functions for debugging tools to convert a string representation of
676*0Sstevel@tonic-gate  * a fault, signal or system call set back to the numeric value of the
677*0Sstevel@tonic-gate  * corresponding set type.
678*0Sstevel@tonic-gate  */
679*0Sstevel@tonic-gate extern char *proc_str2fltset(const char *, const char *, int, fltset_t *);
680*0Sstevel@tonic-gate extern char *proc_str2sigset(const char *, const char *, int, sigset_t *);
681*0Sstevel@tonic-gate extern char *proc_str2sysset(const char *, const char *, int, sysset_t *);
682*0Sstevel@tonic-gate 
683*0Sstevel@tonic-gate /*
684*0Sstevel@tonic-gate  * Utility functions for converting between strings and core_content_t.
685*0Sstevel@tonic-gate  */
686*0Sstevel@tonic-gate #define	PRCONTENTBUFSZ	80	/* buffer size for proc_content2str() */
687*0Sstevel@tonic-gate 
688*0Sstevel@tonic-gate extern int proc_str2content(const char *, core_content_t *);
689*0Sstevel@tonic-gate extern int proc_content2str(core_content_t, char *, size_t);
690*0Sstevel@tonic-gate 
691*0Sstevel@tonic-gate /*
692*0Sstevel@tonic-gate  * Utility functions for buffering output to stdout, stderr while
693*0Sstevel@tonic-gate  * process is grabbed.  Prevents deadlocks due to pfiles `pgrep xterm`
694*0Sstevel@tonic-gate  * and other varients.
695*0Sstevel@tonic-gate  */
696*0Sstevel@tonic-gate extern int proc_initstdio(void);
697*0Sstevel@tonic-gate extern int proc_flushstdio(void);
698*0Sstevel@tonic-gate extern int proc_finistdio(void);
699*0Sstevel@tonic-gate 
700*0Sstevel@tonic-gate #ifdef	__cplusplus
701*0Sstevel@tonic-gate }
702*0Sstevel@tonic-gate #endif
703*0Sstevel@tonic-gate 
704*0Sstevel@tonic-gate #endif	/* _LIBPROC_H */
705