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