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