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