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