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