38
39 #include <stdlib.h>
40 #include <unistd.h>
41 #include <fcntl.h>
42 #include <nlist.h>
43 #include <door.h>
44 #include <gelf.h>
45 #include <proc_service.h>
46 #include <rtld_db.h>
47 #include <procfs.h>
48 #include <ucred.h>
49 #include <rctl.h>
50 #include <libctf.h>
51 #include <sys/stat.h>
52 #include <sys/statvfs.h>
53 #include <sys/auxv.h>
54 #include <sys/resource.h>
55 #include <sys/socket.h>
56 #include <sys/utsname.h>
57 #include <sys/corectl.h>
58 #if defined(__i386) || defined(__amd64)
59 #include <sys/sysi86.h>
60 #endif
61
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65
66 /*
67 * Opaque structure tag reference to a process control structure.
68 * Clients of libproc cannot look inside the process control structure.
69 * The implementation of struct ps_prochandle can change w/o affecting clients.
70 */
71 struct ps_prochandle;
72
73 /*
74 * Opaque structure tag reference to an lwp control structure.
75 */
76 struct ps_lwphandle;
77
175 /* maximum number of syscall arguments */
176 #define MAXARGS 8
177
178 /* maximum size in bytes of a BYREF argument */
179 #define MAXARGL (4*1024)
180
181 /*
182 * Ops vector definition for the Pgrab_ops().
183 */
184 typedef ssize_t (*pop_pread_t)(struct ps_prochandle *, void *, size_t,
185 uintptr_t, void *);
186 typedef ssize_t (*pop_pwrite_t)(struct ps_prochandle *, const void *, size_t,
187 uintptr_t, void *);
188 typedef int (*pop_read_maps_t)(struct ps_prochandle *, prmap_t **, ssize_t *,
189 void *);
190 typedef void (*pop_read_aux_t)(struct ps_prochandle *, auxv_t **, int *,
191 void *);
192 typedef int (*pop_cred_t)(struct ps_prochandle *, prcred_t *, int,
193 void *);
194 typedef int (*pop_priv_t)(struct ps_prochandle *, prpriv_t **, void *);
195 typedef const psinfo_t *(*pop_psinfo_t)(struct ps_prochandle *, psinfo_t *,
196 void *);
197 typedef void (*pop_status_t)(struct ps_prochandle *, pstatus_t *, void *);
198 typedef prheader_t *(*pop_lstatus_t)(struct ps_prochandle *, void *);
199 typedef prheader_t *(*pop_lpsinfo_t)(struct ps_prochandle *, void *);
200 typedef void (*pop_fini_t)(struct ps_prochandle *, void *);
201 typedef char *(*pop_platform_t)(struct ps_prochandle *, char *, size_t, void *);
202 typedef int (*pop_uname_t)(struct ps_prochandle *, struct utsname *, void *);
203 typedef char *(*pop_zonename_t)(struct ps_prochandle *, char *, size_t, void *);
204 typedef char *(*pop_execname_t)(struct ps_prochandle *, char *, size_t, void *);
205 #if defined(__i386) || defined(__amd64)
206 typedef int (*pop_ldt_t)(struct ps_prochandle *, struct ssd *, int, void *);
207 #endif
208
209 typedef struct ps_ops {
210 pop_pread_t pop_pread;
211 pop_pwrite_t pop_pwrite;
212 pop_read_maps_t pop_read_maps;
213 pop_read_aux_t pop_read_aux;
214 pop_cred_t pop_cred;
215 pop_priv_t pop_priv;
216 pop_psinfo_t pop_psinfo;
217 pop_status_t pop_status;
218 pop_lstatus_t pop_lstatus;
219 pop_lpsinfo_t pop_lpsinfo;
220 pop_fini_t pop_fini;
221 pop_platform_t pop_platform;
222 pop_uname_t pop_uname;
223 pop_zonename_t pop_zonename;
224 pop_execname_t pop_execname;
225 #if defined(__i386) || defined(__amd64)
226 pop_ldt_t pop_ldt;
227 #endif
228 } ps_ops_t;
229
230 /*
231 * Function prototypes for routines in the process control package.
232 */
233 extern struct ps_prochandle *Pcreate(const char *, char *const *,
234 int *, char *, size_t);
235 extern struct ps_prochandle *Pxcreate(const char *, char *const *,
236 char *const *, int *, char *, size_t);
237
238 extern const char *Pcreate_error(int);
239
240 extern struct ps_prochandle *Pgrab(pid_t, int, int *);
241 extern struct ps_prochandle *Pgrab_core(const char *, const char *, int, int *);
242 extern struct ps_prochandle *Pfgrab_core(int, const char *, int *);
243 extern struct ps_prochandle *Pgrab_file(const char *, int *);
244 extern struct ps_prochandle *Pgrab_ops(pid_t, void *, const ps_ops_t *, int);
253 extern int Pctlfd(struct ps_prochandle *);
254 extern int Pcreate_agent(struct ps_prochandle *);
255 extern void Pdestroy_agent(struct ps_prochandle *);
256 extern int Pstopstatus(struct ps_prochandle *, long, uint_t);
257 extern int Pwait(struct ps_prochandle *, uint_t);
258 extern int Pstop(struct ps_prochandle *, uint_t);
259 extern int Pdstop(struct ps_prochandle *);
260 extern int Pstate(struct ps_prochandle *);
261 extern const psinfo_t *Ppsinfo(struct ps_prochandle *);
262 extern const pstatus_t *Pstatus(struct ps_prochandle *);
263 extern int Pcred(struct ps_prochandle *, prcred_t *, int);
264 extern int Psetcred(struct ps_prochandle *, const prcred_t *);
265 extern int Ppriv(struct ps_prochandle *, prpriv_t **);
266 extern void Ppriv_free(struct ps_prochandle *, prpriv_t *);
267 extern int Psetpriv(struct ps_prochandle *, prpriv_t *);
268 extern void *Pprivinfo(struct ps_prochandle *);
269 extern int Psetzoneid(struct ps_prochandle *, zoneid_t);
270 extern int Pgetareg(struct ps_prochandle *, int, prgreg_t *);
271 extern int Pputareg(struct ps_prochandle *, int, prgreg_t);
272 extern int Psetrun(struct ps_prochandle *, int, int);
273 extern ssize_t Pread(struct ps_prochandle *, void *, size_t, uintptr_t);
274 extern ssize_t Pread_string(struct ps_prochandle *, char *, size_t, uintptr_t);
275 extern ssize_t Pwrite(struct ps_prochandle *, const void *, size_t, uintptr_t);
276 extern int Pclearsig(struct ps_prochandle *);
277 extern int Pclearfault(struct ps_prochandle *);
278 extern int Psetbkpt(struct ps_prochandle *, uintptr_t, ulong_t *);
279 extern int Pdelbkpt(struct ps_prochandle *, uintptr_t, ulong_t);
280 extern int Pxecbkpt(struct ps_prochandle *, ulong_t);
281 extern int Psetwapt(struct ps_prochandle *, const prwatch_t *);
282 extern int Pdelwapt(struct ps_prochandle *, const prwatch_t *);
283 extern int Pxecwapt(struct ps_prochandle *, const prwatch_t *);
284 extern int Psetflags(struct ps_prochandle *, long);
285 extern int Punsetflags(struct ps_prochandle *, long);
286 extern int Psignal(struct ps_prochandle *, int, int);
287 extern int Pfault(struct ps_prochandle *, int, int);
288 extern int Psysentry(struct ps_prochandle *, int, int);
289 extern int Psysexit(struct ps_prochandle *, int, int);
290 extern void Psetsignal(struct ps_prochandle *, const sigset_t *);
291 extern void Psetfault(struct ps_prochandle *, const fltset_t *);
292 extern void Psetsysentry(struct ps_prochandle *, const sysset_t *);
679
680 #define PR_ARG_ANY (PR_ARG_PIDS | PR_ARG_CORES)
681
682 extern struct ps_prochandle *proc_arg_grab(const char *, int, int, int *);
683 extern struct ps_prochandle *proc_arg_xgrab(const char *, const char *, int,
684 int, int *, const char **);
685 extern pid_t proc_arg_psinfo(const char *, int, psinfo_t *, int *);
686 extern pid_t proc_arg_xpsinfo(const char *, int, psinfo_t *, int *,
687 const char **);
688
689 /*
690 * Utility functions for obtaining information via /proc without actually
691 * performing a Pcreate() or Pgrab():
692 */
693 extern int proc_get_auxv(pid_t, auxv_t *, int);
694 extern int proc_get_cred(pid_t, prcred_t *, int);
695 extern prpriv_t *proc_get_priv(pid_t);
696 extern void proc_free_priv(prpriv_t *);
697 extern int proc_get_psinfo(pid_t, psinfo_t *);
698 extern int proc_get_status(pid_t, pstatus_t *);
699
700 /*
701 * Utility functions for debugging tools to convert numeric fault,
702 * signal, and system call numbers to symbolic names:
703 */
704 #define FLT2STR_MAX 32 /* max. string length of faults (like SIG2STR_MAX) */
705 #define SYS2STR_MAX 32 /* max. string length of syscalls (like SIG2STR_MAX) */
706
707 extern char *proc_fltname(int, char *, size_t);
708 extern char *proc_signame(int, char *, size_t);
709 extern char *proc_sysname(int, char *, size_t);
710
711 /*
712 * Utility functions for debugging tools to convert fault, signal, and system
713 * call names back to the numeric constants:
714 */
715 extern int proc_str2flt(const char *, int *);
716 extern int proc_str2sig(const char *, int *);
717 extern int proc_str2sys(const char *, int *);
718
|
38
39 #include <stdlib.h>
40 #include <unistd.h>
41 #include <fcntl.h>
42 #include <nlist.h>
43 #include <door.h>
44 #include <gelf.h>
45 #include <proc_service.h>
46 #include <rtld_db.h>
47 #include <procfs.h>
48 #include <ucred.h>
49 #include <rctl.h>
50 #include <libctf.h>
51 #include <sys/stat.h>
52 #include <sys/statvfs.h>
53 #include <sys/auxv.h>
54 #include <sys/resource.h>
55 #include <sys/socket.h>
56 #include <sys/utsname.h>
57 #include <sys/corectl.h>
58 #include <sys/secflags.h>
59 #if defined(__i386) || defined(__amd64)
60 #include <sys/sysi86.h>
61 #endif
62
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66
67 /*
68 * Opaque structure tag reference to a process control structure.
69 * Clients of libproc cannot look inside the process control structure.
70 * The implementation of struct ps_prochandle can change w/o affecting clients.
71 */
72 struct ps_prochandle;
73
74 /*
75 * Opaque structure tag reference to an lwp control structure.
76 */
77 struct ps_lwphandle;
78
176 /* maximum number of syscall arguments */
177 #define MAXARGS 8
178
179 /* maximum size in bytes of a BYREF argument */
180 #define MAXARGL (4*1024)
181
182 /*
183 * Ops vector definition for the Pgrab_ops().
184 */
185 typedef ssize_t (*pop_pread_t)(struct ps_prochandle *, void *, size_t,
186 uintptr_t, void *);
187 typedef ssize_t (*pop_pwrite_t)(struct ps_prochandle *, const void *, size_t,
188 uintptr_t, void *);
189 typedef int (*pop_read_maps_t)(struct ps_prochandle *, prmap_t **, ssize_t *,
190 void *);
191 typedef void (*pop_read_aux_t)(struct ps_prochandle *, auxv_t **, int *,
192 void *);
193 typedef int (*pop_cred_t)(struct ps_prochandle *, prcred_t *, int,
194 void *);
195 typedef int (*pop_priv_t)(struct ps_prochandle *, prpriv_t **, void *);
196 typedef int (*pop_secflags_t)(struct ps_prochandle *, prsecflags_t **, void *);
197 typedef const psinfo_t *(*pop_psinfo_t)(struct ps_prochandle *, psinfo_t *,
198 void *);
199 typedef void (*pop_status_t)(struct ps_prochandle *, pstatus_t *, void *);
200 typedef prheader_t *(*pop_lstatus_t)(struct ps_prochandle *, void *);
201 typedef prheader_t *(*pop_lpsinfo_t)(struct ps_prochandle *, void *);
202 typedef void (*pop_fini_t)(struct ps_prochandle *, void *);
203 typedef char *(*pop_platform_t)(struct ps_prochandle *, char *, size_t, void *);
204 typedef int (*pop_uname_t)(struct ps_prochandle *, struct utsname *, void *);
205 typedef char *(*pop_zonename_t)(struct ps_prochandle *, char *, size_t, void *);
206 typedef char *(*pop_execname_t)(struct ps_prochandle *, char *, size_t, void *);
207 #if defined(__i386) || defined(__amd64)
208 typedef int (*pop_ldt_t)(struct ps_prochandle *, struct ssd *, int, void *);
209 #endif
210
211 typedef struct ps_ops {
212 pop_pread_t pop_pread;
213 pop_pwrite_t pop_pwrite;
214 pop_read_maps_t pop_read_maps;
215 pop_read_aux_t pop_read_aux;
216 pop_cred_t pop_cred;
217 pop_priv_t pop_priv;
218 pop_psinfo_t pop_psinfo;
219 pop_status_t pop_status;
220 pop_lstatus_t pop_lstatus;
221 pop_lpsinfo_t pop_lpsinfo;
222 pop_fini_t pop_fini;
223 pop_platform_t pop_platform;
224 pop_uname_t pop_uname;
225 pop_zonename_t pop_zonename;
226 pop_execname_t pop_execname;
227 pop_secflags_t pop_secflags;
228 #if defined(__i386) || defined(__amd64)
229 pop_ldt_t pop_ldt;
230 #endif
231 } ps_ops_t;
232
233 /*
234 * Function prototypes for routines in the process control package.
235 */
236 extern struct ps_prochandle *Pcreate(const char *, char *const *,
237 int *, char *, size_t);
238 extern struct ps_prochandle *Pxcreate(const char *, char *const *,
239 char *const *, int *, char *, size_t);
240
241 extern const char *Pcreate_error(int);
242
243 extern struct ps_prochandle *Pgrab(pid_t, int, int *);
244 extern struct ps_prochandle *Pgrab_core(const char *, const char *, int, int *);
245 extern struct ps_prochandle *Pfgrab_core(int, const char *, int *);
246 extern struct ps_prochandle *Pgrab_file(const char *, int *);
247 extern struct ps_prochandle *Pgrab_ops(pid_t, void *, const ps_ops_t *, int);
256 extern int Pctlfd(struct ps_prochandle *);
257 extern int Pcreate_agent(struct ps_prochandle *);
258 extern void Pdestroy_agent(struct ps_prochandle *);
259 extern int Pstopstatus(struct ps_prochandle *, long, uint_t);
260 extern int Pwait(struct ps_prochandle *, uint_t);
261 extern int Pstop(struct ps_prochandle *, uint_t);
262 extern int Pdstop(struct ps_prochandle *);
263 extern int Pstate(struct ps_prochandle *);
264 extern const psinfo_t *Ppsinfo(struct ps_prochandle *);
265 extern const pstatus_t *Pstatus(struct ps_prochandle *);
266 extern int Pcred(struct ps_prochandle *, prcred_t *, int);
267 extern int Psetcred(struct ps_prochandle *, const prcred_t *);
268 extern int Ppriv(struct ps_prochandle *, prpriv_t **);
269 extern void Ppriv_free(struct ps_prochandle *, prpriv_t *);
270 extern int Psetpriv(struct ps_prochandle *, prpriv_t *);
271 extern void *Pprivinfo(struct ps_prochandle *);
272 extern int Psetzoneid(struct ps_prochandle *, zoneid_t);
273 extern int Pgetareg(struct ps_prochandle *, int, prgreg_t *);
274 extern int Pputareg(struct ps_prochandle *, int, prgreg_t);
275 extern int Psetrun(struct ps_prochandle *, int, int);
276 extern int Psecflags(struct ps_prochandle *, prsecflags_t **);
277 extern void Psecflags_free(prsecflags_t *);
278 extern ssize_t Pread(struct ps_prochandle *, void *, size_t, uintptr_t);
279 extern ssize_t Pread_string(struct ps_prochandle *, char *, size_t, uintptr_t);
280 extern ssize_t Pwrite(struct ps_prochandle *, const void *, size_t, uintptr_t);
281 extern int Pclearsig(struct ps_prochandle *);
282 extern int Pclearfault(struct ps_prochandle *);
283 extern int Psetbkpt(struct ps_prochandle *, uintptr_t, ulong_t *);
284 extern int Pdelbkpt(struct ps_prochandle *, uintptr_t, ulong_t);
285 extern int Pxecbkpt(struct ps_prochandle *, ulong_t);
286 extern int Psetwapt(struct ps_prochandle *, const prwatch_t *);
287 extern int Pdelwapt(struct ps_prochandle *, const prwatch_t *);
288 extern int Pxecwapt(struct ps_prochandle *, const prwatch_t *);
289 extern int Psetflags(struct ps_prochandle *, long);
290 extern int Punsetflags(struct ps_prochandle *, long);
291 extern int Psignal(struct ps_prochandle *, int, int);
292 extern int Pfault(struct ps_prochandle *, int, int);
293 extern int Psysentry(struct ps_prochandle *, int, int);
294 extern int Psysexit(struct ps_prochandle *, int, int);
295 extern void Psetsignal(struct ps_prochandle *, const sigset_t *);
296 extern void Psetfault(struct ps_prochandle *, const fltset_t *);
297 extern void Psetsysentry(struct ps_prochandle *, const sysset_t *);
684
685 #define PR_ARG_ANY (PR_ARG_PIDS | PR_ARG_CORES)
686
687 extern struct ps_prochandle *proc_arg_grab(const char *, int, int, int *);
688 extern struct ps_prochandle *proc_arg_xgrab(const char *, const char *, int,
689 int, int *, const char **);
690 extern pid_t proc_arg_psinfo(const char *, int, psinfo_t *, int *);
691 extern pid_t proc_arg_xpsinfo(const char *, int, psinfo_t *, int *,
692 const char **);
693
694 /*
695 * Utility functions for obtaining information via /proc without actually
696 * performing a Pcreate() or Pgrab():
697 */
698 extern int proc_get_auxv(pid_t, auxv_t *, int);
699 extern int proc_get_cred(pid_t, prcred_t *, int);
700 extern prpriv_t *proc_get_priv(pid_t);
701 extern void proc_free_priv(prpriv_t *);
702 extern int proc_get_psinfo(pid_t, psinfo_t *);
703 extern int proc_get_status(pid_t, pstatus_t *);
704 extern int proc_get_secflags(pid_t, prsecflags_t **);
705
706 /*
707 * Utility functions for debugging tools to convert numeric fault,
708 * signal, and system call numbers to symbolic names:
709 */
710 #define FLT2STR_MAX 32 /* max. string length of faults (like SIG2STR_MAX) */
711 #define SYS2STR_MAX 32 /* max. string length of syscalls (like SIG2STR_MAX) */
712
713 extern char *proc_fltname(int, char *, size_t);
714 extern char *proc_signame(int, char *, size_t);
715 extern char *proc_sysname(int, char *, size_t);
716
717 /*
718 * Utility functions for debugging tools to convert fault, signal, and system
719 * call names back to the numeric constants:
720 */
721 extern int proc_str2flt(const char *, int *);
722 extern int proc_str2sig(const char *, int *);
723 extern int proc_str2sys(const char *, int *);
724
|