17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 59acbbeafSnn35248 * Common Development and Distribution License (the "License"). 69acbbeafSnn35248 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21ed9c9f97SRoger A. Faulkner 227c478bd9Sstevel@tonic-gate /* 23ed9c9f97SRoger A. Faulkner * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25cd11e192Sjhaslam * 26cd11e192Sjhaslam * Portions Copyright 2007 Chad Mynhier 277c478bd9Sstevel@tonic-gate */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * Interfaces available from the process control library, libproc. 317c478bd9Sstevel@tonic-gate * 327c478bd9Sstevel@tonic-gate * libproc provides process control functions for the /proc tools 337c478bd9Sstevel@tonic-gate * (commands in /usr/proc/bin), /usr/bin/truss, and /usr/bin/gcore. 347c478bd9Sstevel@tonic-gate * libproc is a private support library for these commands only. 357c478bd9Sstevel@tonic-gate * It is _not_ a public interface, although it might become one 367c478bd9Sstevel@tonic-gate * in the fullness of time, when the interfaces settle down. 377c478bd9Sstevel@tonic-gate * 387c478bd9Sstevel@tonic-gate * In the meantime, be aware that any program linked with libproc in this 397c478bd9Sstevel@tonic-gate * release of Solaris is almost guaranteed to break in the next release. 407c478bd9Sstevel@tonic-gate * 417c478bd9Sstevel@tonic-gate * In short, do not use this header file or libproc for any purpose. 427c478bd9Sstevel@tonic-gate */ 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #ifndef _LIBPROC_H 457c478bd9Sstevel@tonic-gate #define _LIBPROC_H 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate #include <stdlib.h> 487c478bd9Sstevel@tonic-gate #include <unistd.h> 497c478bd9Sstevel@tonic-gate #include <fcntl.h> 507c478bd9Sstevel@tonic-gate #include <nlist.h> 517c478bd9Sstevel@tonic-gate #include <door.h> 527c478bd9Sstevel@tonic-gate #include <gelf.h> 537c478bd9Sstevel@tonic-gate #include <proc_service.h> 547c478bd9Sstevel@tonic-gate #include <rtld_db.h> 557c478bd9Sstevel@tonic-gate #include <procfs.h> 567c478bd9Sstevel@tonic-gate #include <rctl.h> 577c478bd9Sstevel@tonic-gate #include <libctf.h> 587c478bd9Sstevel@tonic-gate #include <sys/stat.h> 597c478bd9Sstevel@tonic-gate #include <sys/statvfs.h> 607c478bd9Sstevel@tonic-gate #include <sys/auxv.h> 617c478bd9Sstevel@tonic-gate #include <sys/resource.h> 627c478bd9Sstevel@tonic-gate #include <sys/socket.h> 637c478bd9Sstevel@tonic-gate #include <sys/utsname.h> 647c478bd9Sstevel@tonic-gate #include <sys/corectl.h> 657c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64) 667c478bd9Sstevel@tonic-gate #include <sys/sysi86.h> 677c478bd9Sstevel@tonic-gate #endif 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate #ifdef __cplusplus 707c478bd9Sstevel@tonic-gate extern "C" { 717c478bd9Sstevel@tonic-gate #endif 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate /* 747c478bd9Sstevel@tonic-gate * Opaque structure tag reference to a process control structure. 757c478bd9Sstevel@tonic-gate * Clients of libproc cannot look inside the process control structure. 767c478bd9Sstevel@tonic-gate * The implementation of struct ps_prochandle can change w/o affecting clients. 777c478bd9Sstevel@tonic-gate */ 787c478bd9Sstevel@tonic-gate struct ps_prochandle; 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate /* 817c478bd9Sstevel@tonic-gate * Opaque structure tag reference to an lwp control structure. 827c478bd9Sstevel@tonic-gate */ 837c478bd9Sstevel@tonic-gate struct ps_lwphandle; 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate extern int _libproc_debug; /* set non-zero to enable debugging fprintfs */ 86d7755b5aSrh87107 extern int _libproc_no_qsort; /* set non-zero to inhibit sorting */ 87d7755b5aSrh87107 /* of symbol tables */ 88*d9452f23SEdward Pilatowicz extern int _libproc_incore_elf; /* only use in-core elf data */ 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate #if defined(__sparc) 917c478bd9Sstevel@tonic-gate #define R_RVAL1 R_O0 /* register holding a function return value */ 927c478bd9Sstevel@tonic-gate #define R_RVAL2 R_O1 /* 32 more bits for a 64-bit return value */ 937c478bd9Sstevel@tonic-gate #endif /* __sparc */ 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate #if defined(__amd64) 967c478bd9Sstevel@tonic-gate #define R_PC REG_RIP 977c478bd9Sstevel@tonic-gate #define R_SP REG_RSP 987c478bd9Sstevel@tonic-gate #define R_RVAL1 REG_RAX /* register holding a function return value */ 997c478bd9Sstevel@tonic-gate #define R_RVAL2 REG_RDX /* 32 more bits for a 64-bit return value */ 1007c478bd9Sstevel@tonic-gate #elif defined(__i386) 1017c478bd9Sstevel@tonic-gate #define R_PC EIP 1027c478bd9Sstevel@tonic-gate #define R_SP UESP 1037c478bd9Sstevel@tonic-gate #define R_RVAL1 EAX /* register holding a function return value */ 1047c478bd9Sstevel@tonic-gate #define R_RVAL2 EDX /* 32 more bits for a 64-bit return value */ 1057c478bd9Sstevel@tonic-gate #endif /* __amd64 || __i386 */ 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate #define R_RVAL R_RVAL1 /* simple function return value register */ 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate /* maximum sizes of things */ 1107c478bd9Sstevel@tonic-gate #define PRMAXSIG (32 * sizeof (sigset_t) / sizeof (uint32_t)) 1117c478bd9Sstevel@tonic-gate #define PRMAXFAULT (32 * sizeof (fltset_t) / sizeof (uint32_t)) 1127c478bd9Sstevel@tonic-gate #define PRMAXSYS (32 * sizeof (sysset_t) / sizeof (uint32_t)) 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate /* State values returned by Pstate() */ 1157c478bd9Sstevel@tonic-gate #define PS_RUN 1 /* process is running */ 1167c478bd9Sstevel@tonic-gate #define PS_STOP 2 /* process is stopped */ 1177c478bd9Sstevel@tonic-gate #define PS_LOST 3 /* process is lost to control (EAGAIN) */ 1187c478bd9Sstevel@tonic-gate #define PS_UNDEAD 4 /* process is terminated (zombie) */ 1197c478bd9Sstevel@tonic-gate #define PS_DEAD 5 /* process is terminated (core file) */ 1207c478bd9Sstevel@tonic-gate #define PS_IDLE 6 /* process has not been run */ 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate /* Flags accepted by Pgrab() */ 1237c478bd9Sstevel@tonic-gate #define PGRAB_RETAIN 0x01 /* Retain tracing flags, else clear flags */ 1247c478bd9Sstevel@tonic-gate #define PGRAB_FORCE 0x02 /* Open the process w/o O_EXCL */ 1257c478bd9Sstevel@tonic-gate #define PGRAB_RDONLY 0x04 /* Open the process or core w/ O_RDONLY */ 1267c478bd9Sstevel@tonic-gate #define PGRAB_NOSTOP 0x08 /* Open the process but do not stop it */ 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate /* Error codes from Pcreate() */ 1297c478bd9Sstevel@tonic-gate #define C_STRANGE -1 /* Unanticipated error, errno is meaningful */ 1307c478bd9Sstevel@tonic-gate #define C_FORK 1 /* Unable to fork */ 1317c478bd9Sstevel@tonic-gate #define C_PERM 2 /* No permission (file set-id or unreadable) */ 1327c478bd9Sstevel@tonic-gate #define C_NOEXEC 3 /* Cannot execute file */ 1337c478bd9Sstevel@tonic-gate #define C_INTR 4 /* Interrupt received while creating */ 1347c478bd9Sstevel@tonic-gate #define C_LP64 5 /* Program is _LP64, self is _ILP32 */ 1357c478bd9Sstevel@tonic-gate #define C_NOENT 6 /* Cannot find executable file */ 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate /* Error codes from Pgrab(), Pfgrab_core(), and Pgrab_core() */ 1387c478bd9Sstevel@tonic-gate #define G_STRANGE -1 /* Unanticipated error, errno is meaningful */ 1397c478bd9Sstevel@tonic-gate #define G_NOPROC 1 /* No such process */ 1407c478bd9Sstevel@tonic-gate #define G_NOCORE 2 /* No such core file */ 1417c478bd9Sstevel@tonic-gate #define G_NOPROCORCORE 3 /* No such proc or core (for proc_arg_grab) */ 1427c478bd9Sstevel@tonic-gate #define G_NOEXEC 4 /* Cannot locate executable file */ 1437c478bd9Sstevel@tonic-gate #define G_ZOMB 5 /* Zombie process */ 1447c478bd9Sstevel@tonic-gate #define G_PERM 6 /* No permission */ 1457c478bd9Sstevel@tonic-gate #define G_BUSY 7 /* Another process has control */ 1467c478bd9Sstevel@tonic-gate #define G_SYS 8 /* System process */ 1477c478bd9Sstevel@tonic-gate #define G_SELF 9 /* Process is self */ 1487c478bd9Sstevel@tonic-gate #define G_INTR 10 /* Interrupt received while grabbing */ 1497c478bd9Sstevel@tonic-gate #define G_LP64 11 /* Process is _LP64, self is ILP32 */ 1507c478bd9Sstevel@tonic-gate #define G_FORMAT 12 /* File is not an ELF format core file */ 1517c478bd9Sstevel@tonic-gate #define G_ELF 13 /* Libelf error, elf_errno() is meaningful */ 1527c478bd9Sstevel@tonic-gate #define G_NOTE 14 /* Required PT_NOTE Phdr not present in core */ 1537c478bd9Sstevel@tonic-gate #define G_ISAINVAL 15 /* Wrong ELF machine type */ 1547c478bd9Sstevel@tonic-gate #define G_BADLWPS 16 /* Bad '/lwps' specification */ 155cd11e192Sjhaslam #define G_NOFD 17 /* No more file descriptors */ 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate /* Flags accepted by Prelease */ 1597c478bd9Sstevel@tonic-gate #define PRELEASE_CLEAR 0x10 /* Clear all tracing flags */ 1607c478bd9Sstevel@tonic-gate #define PRELEASE_RETAIN 0x20 /* Retain final tracing flags */ 1617c478bd9Sstevel@tonic-gate #define PRELEASE_HANG 0x40 /* Leave the process stopped */ 1627c478bd9Sstevel@tonic-gate #define PRELEASE_KILL 0x80 /* Terminate the process */ 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate typedef struct { /* argument descriptor for system call (Psyscall) */ 1657c478bd9Sstevel@tonic-gate long arg_value; /* value of argument given to system call */ 1667c478bd9Sstevel@tonic-gate void *arg_object; /* pointer to object in controlling process */ 1677c478bd9Sstevel@tonic-gate char arg_type; /* AT_BYVAL, AT_BYREF */ 1687c478bd9Sstevel@tonic-gate char arg_inout; /* AI_INPUT, AI_OUTPUT, AI_INOUT */ 1697c478bd9Sstevel@tonic-gate ushort_t arg_size; /* if AT_BYREF, size of object in bytes */ 1707c478bd9Sstevel@tonic-gate } argdes_t; 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate /* values for type */ 1737c478bd9Sstevel@tonic-gate #define AT_BYVAL 1 1747c478bd9Sstevel@tonic-gate #define AT_BYREF 2 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate /* values for inout */ 1777c478bd9Sstevel@tonic-gate #define AI_INPUT 1 1787c478bd9Sstevel@tonic-gate #define AI_OUTPUT 2 1797c478bd9Sstevel@tonic-gate #define AI_INOUT 3 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate /* maximum number of syscall arguments */ 1827c478bd9Sstevel@tonic-gate #define MAXARGS 8 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate /* maximum size in bytes of a BYREF argument */ 1857c478bd9Sstevel@tonic-gate #define MAXARGL (4*1024) 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate /* 1887c478bd9Sstevel@tonic-gate * Function prototypes for routines in the process control package. 1897c478bd9Sstevel@tonic-gate */ 1907c478bd9Sstevel@tonic-gate extern struct ps_prochandle *Pcreate(const char *, char *const *, 1917c478bd9Sstevel@tonic-gate int *, char *, size_t); 1927c478bd9Sstevel@tonic-gate extern struct ps_prochandle *Pxcreate(const char *, char *const *, 1937c478bd9Sstevel@tonic-gate char *const *, int *, char *, size_t); 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate extern const char *Pcreate_error(int); 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate extern struct ps_prochandle *Pgrab(pid_t, int, int *); 1987c478bd9Sstevel@tonic-gate extern struct ps_prochandle *Pgrab_core(const char *, const char *, int, int *); 1997c478bd9Sstevel@tonic-gate extern struct ps_prochandle *Pfgrab_core(int, const char *, int *); 2007c478bd9Sstevel@tonic-gate extern struct ps_prochandle *Pgrab_file(const char *, int *); 2017c478bd9Sstevel@tonic-gate extern const char *Pgrab_error(int); 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate extern int Preopen(struct ps_prochandle *); 2047c478bd9Sstevel@tonic-gate extern void Prelease(struct ps_prochandle *, int); 2057c478bd9Sstevel@tonic-gate extern void Pfree(struct ps_prochandle *); 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate extern int Pasfd(struct ps_prochandle *); 2089acbbeafSnn35248 extern char *Pbrandname(struct ps_prochandle *, char *, size_t); 2097c478bd9Sstevel@tonic-gate extern int Pctlfd(struct ps_prochandle *); 2107c478bd9Sstevel@tonic-gate extern int Pcreate_agent(struct ps_prochandle *); 2117c478bd9Sstevel@tonic-gate extern void Pdestroy_agent(struct ps_prochandle *); 2127c478bd9Sstevel@tonic-gate extern int Pstopstatus(struct ps_prochandle *, long, uint_t); 2137c478bd9Sstevel@tonic-gate extern int Pwait(struct ps_prochandle *, uint_t); 2147c478bd9Sstevel@tonic-gate extern int Pstop(struct ps_prochandle *, uint_t); 2157c478bd9Sstevel@tonic-gate extern int Pdstop(struct ps_prochandle *); 2167c478bd9Sstevel@tonic-gate extern int Pstate(struct ps_prochandle *); 2177c478bd9Sstevel@tonic-gate extern const psinfo_t *Ppsinfo(struct ps_prochandle *); 2187c478bd9Sstevel@tonic-gate extern const pstatus_t *Pstatus(struct ps_prochandle *); 2197c478bd9Sstevel@tonic-gate extern int Pcred(struct ps_prochandle *, prcred_t *, int); 2207c478bd9Sstevel@tonic-gate extern int Psetcred(struct ps_prochandle *, const prcred_t *); 2217c478bd9Sstevel@tonic-gate extern ssize_t Ppriv(struct ps_prochandle *, prpriv_t *, size_t); 2227c478bd9Sstevel@tonic-gate extern int Psetpriv(struct ps_prochandle *, prpriv_t *); 2237c478bd9Sstevel@tonic-gate extern void *Pprivinfo(struct ps_prochandle *); 2247c478bd9Sstevel@tonic-gate extern int Psetzoneid(struct ps_prochandle *, zoneid_t); 2257c478bd9Sstevel@tonic-gate extern int Pgetareg(struct ps_prochandle *, int, prgreg_t *); 2267c478bd9Sstevel@tonic-gate extern int Pputareg(struct ps_prochandle *, int, prgreg_t); 2277c478bd9Sstevel@tonic-gate extern int Psetrun(struct ps_prochandle *, int, int); 2287c478bd9Sstevel@tonic-gate extern ssize_t Pread(struct ps_prochandle *, void *, size_t, uintptr_t); 2297c478bd9Sstevel@tonic-gate extern ssize_t Pread_string(struct ps_prochandle *, char *, size_t, uintptr_t); 2307c478bd9Sstevel@tonic-gate extern ssize_t Pwrite(struct ps_prochandle *, const void *, size_t, uintptr_t); 2317c478bd9Sstevel@tonic-gate extern int Pclearsig(struct ps_prochandle *); 2327c478bd9Sstevel@tonic-gate extern int Pclearfault(struct ps_prochandle *); 2337c478bd9Sstevel@tonic-gate extern int Psetbkpt(struct ps_prochandle *, uintptr_t, ulong_t *); 2347c478bd9Sstevel@tonic-gate extern int Pdelbkpt(struct ps_prochandle *, uintptr_t, ulong_t); 2357c478bd9Sstevel@tonic-gate extern int Pxecbkpt(struct ps_prochandle *, ulong_t); 2367c478bd9Sstevel@tonic-gate extern int Psetwapt(struct ps_prochandle *, const prwatch_t *); 2377c478bd9Sstevel@tonic-gate extern int Pdelwapt(struct ps_prochandle *, const prwatch_t *); 2387c478bd9Sstevel@tonic-gate extern int Pxecwapt(struct ps_prochandle *, const prwatch_t *); 2397c478bd9Sstevel@tonic-gate extern int Psetflags(struct ps_prochandle *, long); 2407c478bd9Sstevel@tonic-gate extern int Punsetflags(struct ps_prochandle *, long); 2417c478bd9Sstevel@tonic-gate extern int Psignal(struct ps_prochandle *, int, int); 2427c478bd9Sstevel@tonic-gate extern int Pfault(struct ps_prochandle *, int, int); 2437c478bd9Sstevel@tonic-gate extern int Psysentry(struct ps_prochandle *, int, int); 2447c478bd9Sstevel@tonic-gate extern int Psysexit(struct ps_prochandle *, int, int); 2457c478bd9Sstevel@tonic-gate extern void Psetsignal(struct ps_prochandle *, const sigset_t *); 2467c478bd9Sstevel@tonic-gate extern void Psetfault(struct ps_prochandle *, const fltset_t *); 2477c478bd9Sstevel@tonic-gate extern void Psetsysentry(struct ps_prochandle *, const sysset_t *); 2487c478bd9Sstevel@tonic-gate extern void Psetsysexit(struct ps_prochandle *, const sysset_t *); 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate extern void Psync(struct ps_prochandle *); 2517c478bd9Sstevel@tonic-gate extern int Psyscall(struct ps_prochandle *, sysret_t *, 2527c478bd9Sstevel@tonic-gate int, uint_t, argdes_t *); 2537c478bd9Sstevel@tonic-gate extern int Pisprocdir(struct ps_prochandle *, const char *); 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate /* 2567c478bd9Sstevel@tonic-gate * Function prototypes for lwp-specific operations. 2577c478bd9Sstevel@tonic-gate */ 2587c478bd9Sstevel@tonic-gate extern struct ps_lwphandle *Lgrab(struct ps_prochandle *, lwpid_t, int *); 2597c478bd9Sstevel@tonic-gate extern const char *Lgrab_error(int); 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate extern struct ps_prochandle *Lprochandle(struct ps_lwphandle *); 2627c478bd9Sstevel@tonic-gate extern void Lfree(struct ps_lwphandle *); 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate extern int Lctlfd(struct ps_lwphandle *); 2657c478bd9Sstevel@tonic-gate extern int Lwait(struct ps_lwphandle *, uint_t); 2667c478bd9Sstevel@tonic-gate extern int Lstop(struct ps_lwphandle *, uint_t); 2677c478bd9Sstevel@tonic-gate extern int Ldstop(struct ps_lwphandle *); 2687c478bd9Sstevel@tonic-gate extern int Lstate(struct ps_lwphandle *); 2697c478bd9Sstevel@tonic-gate extern const lwpsinfo_t *Lpsinfo(struct ps_lwphandle *); 2707c478bd9Sstevel@tonic-gate extern const lwpstatus_t *Lstatus(struct ps_lwphandle *); 2717c478bd9Sstevel@tonic-gate extern int Lgetareg(struct ps_lwphandle *, int, prgreg_t *); 2727c478bd9Sstevel@tonic-gate extern int Lputareg(struct ps_lwphandle *, int, prgreg_t); 2737c478bd9Sstevel@tonic-gate extern int Lsetrun(struct ps_lwphandle *, int, int); 2747c478bd9Sstevel@tonic-gate extern int Lclearsig(struct ps_lwphandle *); 2757c478bd9Sstevel@tonic-gate extern int Lclearfault(struct ps_lwphandle *); 2767c478bd9Sstevel@tonic-gate extern int Lxecbkpt(struct ps_lwphandle *, ulong_t); 2777c478bd9Sstevel@tonic-gate extern int Lxecwapt(struct ps_lwphandle *, const prwatch_t *); 2787c478bd9Sstevel@tonic-gate extern void Lsync(struct ps_lwphandle *); 2797c478bd9Sstevel@tonic-gate 2807c478bd9Sstevel@tonic-gate extern int Lstack(struct ps_lwphandle *, stack_t *); 2817c478bd9Sstevel@tonic-gate extern int Lmain_stack(struct ps_lwphandle *, stack_t *); 2827c478bd9Sstevel@tonic-gate extern int Lalt_stack(struct ps_lwphandle *, stack_t *); 2837c478bd9Sstevel@tonic-gate 2847c478bd9Sstevel@tonic-gate /* 2857c478bd9Sstevel@tonic-gate * Function prototypes for system calls forced on the victim process. 2867c478bd9Sstevel@tonic-gate */ 2877c478bd9Sstevel@tonic-gate extern int pr_open(struct ps_prochandle *, const char *, int, mode_t); 2887c478bd9Sstevel@tonic-gate extern int pr_creat(struct ps_prochandle *, const char *, mode_t); 2897c478bd9Sstevel@tonic-gate extern int pr_close(struct ps_prochandle *, int); 2907c478bd9Sstevel@tonic-gate extern int pr_access(struct ps_prochandle *, const char *, int); 2917c478bd9Sstevel@tonic-gate extern int pr_door_info(struct ps_prochandle *, int, struct door_info *); 2927c478bd9Sstevel@tonic-gate extern void *pr_mmap(struct ps_prochandle *, 2937c478bd9Sstevel@tonic-gate void *, size_t, int, int, int, off_t); 2947c478bd9Sstevel@tonic-gate extern void *pr_zmap(struct ps_prochandle *, 2957c478bd9Sstevel@tonic-gate void *, size_t, int, int); 2967c478bd9Sstevel@tonic-gate extern int pr_munmap(struct ps_prochandle *, void *, size_t); 2977c478bd9Sstevel@tonic-gate extern int pr_memcntl(struct ps_prochandle *, 2987c478bd9Sstevel@tonic-gate caddr_t, size_t, int, caddr_t, int, int); 2997c478bd9Sstevel@tonic-gate extern int pr_meminfo(struct ps_prochandle *, const uint64_t *addrs, 3007c478bd9Sstevel@tonic-gate int addr_count, const uint_t *info, int info_count, 3017c478bd9Sstevel@tonic-gate uint64_t *outdata, uint_t *validity); 3027c478bd9Sstevel@tonic-gate extern int pr_sigaction(struct ps_prochandle *, 3037c478bd9Sstevel@tonic-gate int, const struct sigaction *, struct sigaction *); 3047c478bd9Sstevel@tonic-gate extern int pr_getitimer(struct ps_prochandle *, 3057c478bd9Sstevel@tonic-gate int, struct itimerval *); 3067c478bd9Sstevel@tonic-gate extern int pr_setitimer(struct ps_prochandle *, 3077c478bd9Sstevel@tonic-gate int, const struct itimerval *, struct itimerval *); 3087c478bd9Sstevel@tonic-gate extern int pr_ioctl(struct ps_prochandle *, int, int, void *, size_t); 3097c478bd9Sstevel@tonic-gate extern int pr_fcntl(struct ps_prochandle *, int, int, void *); 3107c478bd9Sstevel@tonic-gate extern int pr_stat(struct ps_prochandle *, const char *, struct stat *); 3117c478bd9Sstevel@tonic-gate extern int pr_lstat(struct ps_prochandle *, const char *, struct stat *); 3127c478bd9Sstevel@tonic-gate extern int pr_fstat(struct ps_prochandle *, int, struct stat *); 3137c478bd9Sstevel@tonic-gate extern int pr_stat64(struct ps_prochandle *, const char *, 3147c478bd9Sstevel@tonic-gate struct stat64 *); 3157c478bd9Sstevel@tonic-gate extern int pr_lstat64(struct ps_prochandle *, const char *, 3167c478bd9Sstevel@tonic-gate struct stat64 *); 3177c478bd9Sstevel@tonic-gate extern int pr_fstat64(struct ps_prochandle *, int, struct stat64 *); 3187c478bd9Sstevel@tonic-gate extern int pr_statvfs(struct ps_prochandle *, const char *, statvfs_t *); 3197c478bd9Sstevel@tonic-gate extern int pr_fstatvfs(struct ps_prochandle *, int, statvfs_t *); 3207c478bd9Sstevel@tonic-gate extern projid_t pr_getprojid(struct ps_prochandle *Pr); 3217c478bd9Sstevel@tonic-gate extern taskid_t pr_gettaskid(struct ps_prochandle *Pr); 3227c478bd9Sstevel@tonic-gate extern taskid_t pr_settaskid(struct ps_prochandle *Pr, projid_t project, 3237c478bd9Sstevel@tonic-gate int flags); 3247c478bd9Sstevel@tonic-gate extern zoneid_t pr_getzoneid(struct ps_prochandle *Pr); 3257c478bd9Sstevel@tonic-gate extern int pr_getrctl(struct ps_prochandle *, 3267c478bd9Sstevel@tonic-gate const char *, rctlblk_t *, rctlblk_t *, int); 3277c478bd9Sstevel@tonic-gate extern int pr_setrctl(struct ps_prochandle *, 3287c478bd9Sstevel@tonic-gate const char *, rctlblk_t *, rctlblk_t *, int); 3297c478bd9Sstevel@tonic-gate extern int pr_getrlimit(struct ps_prochandle *, 3307c478bd9Sstevel@tonic-gate int, struct rlimit *); 3317c478bd9Sstevel@tonic-gate extern int pr_setrlimit(struct ps_prochandle *, 3327c478bd9Sstevel@tonic-gate int, const struct rlimit *); 333532877c4Srd117015 extern int pr_setprojrctl(struct ps_prochandle *, const char *, 334532877c4Srd117015 rctlblk_t *, size_t, int); 3357c478bd9Sstevel@tonic-gate #if defined(_LARGEFILE64_SOURCE) 3367c478bd9Sstevel@tonic-gate extern int pr_getrlimit64(struct ps_prochandle *, 3377c478bd9Sstevel@tonic-gate int, struct rlimit64 *); 3387c478bd9Sstevel@tonic-gate extern int pr_setrlimit64(struct ps_prochandle *, 3397c478bd9Sstevel@tonic-gate int, const struct rlimit64 *); 3407c478bd9Sstevel@tonic-gate #endif /* _LARGEFILE64_SOURCE */ 3417c478bd9Sstevel@tonic-gate extern int pr_lwp_exit(struct ps_prochandle *); 3427c478bd9Sstevel@tonic-gate extern int pr_exit(struct ps_prochandle *, int); 3437c478bd9Sstevel@tonic-gate extern int pr_waitid(struct ps_prochandle *, 3447c478bd9Sstevel@tonic-gate idtype_t, id_t, siginfo_t *, int); 3457c478bd9Sstevel@tonic-gate extern off_t pr_lseek(struct ps_prochandle *, int, off_t, int); 3467c478bd9Sstevel@tonic-gate extern offset_t pr_llseek(struct ps_prochandle *, int, offset_t, int); 3477c478bd9Sstevel@tonic-gate extern int pr_rename(struct ps_prochandle *, const char *, const char *); 3487c478bd9Sstevel@tonic-gate extern int pr_link(struct ps_prochandle *, const char *, const char *); 3497c478bd9Sstevel@tonic-gate extern int pr_unlink(struct ps_prochandle *, const char *); 3507c478bd9Sstevel@tonic-gate extern int pr_getpeername(struct ps_prochandle *, 3517c478bd9Sstevel@tonic-gate int, struct sockaddr *, socklen_t *); 3527c478bd9Sstevel@tonic-gate extern int pr_getsockname(struct ps_prochandle *, 3537c478bd9Sstevel@tonic-gate int, struct sockaddr *, socklen_t *); 3547c478bd9Sstevel@tonic-gate extern int pr_getsockopt(struct ps_prochandle *, 3557c478bd9Sstevel@tonic-gate int, int, int, void *, int *); 3567c478bd9Sstevel@tonic-gate extern int pr_processor_bind(struct ps_prochandle *, 3577c478bd9Sstevel@tonic-gate idtype_t, id_t, int, int *); 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate /* 3607c478bd9Sstevel@tonic-gate * Function prototypes for accessing per-LWP register information. 3617c478bd9Sstevel@tonic-gate */ 3627c478bd9Sstevel@tonic-gate extern int Plwp_getregs(struct ps_prochandle *, lwpid_t, prgregset_t); 3637c478bd9Sstevel@tonic-gate extern int Plwp_setregs(struct ps_prochandle *, lwpid_t, const prgregset_t); 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate extern int Plwp_getfpregs(struct ps_prochandle *, lwpid_t, prfpregset_t *); 3667c478bd9Sstevel@tonic-gate extern int Plwp_setfpregs(struct ps_prochandle *, lwpid_t, 3677c478bd9Sstevel@tonic-gate const prfpregset_t *); 3687c478bd9Sstevel@tonic-gate 3697c478bd9Sstevel@tonic-gate #if defined(__sparc) 3707c478bd9Sstevel@tonic-gate 3717c478bd9Sstevel@tonic-gate extern int Plwp_getxregs(struct ps_prochandle *, lwpid_t, prxregset_t *); 3727c478bd9Sstevel@tonic-gate extern int Plwp_setxregs(struct ps_prochandle *, lwpid_t, const prxregset_t *); 3737c478bd9Sstevel@tonic-gate 3747c478bd9Sstevel@tonic-gate extern int Plwp_getgwindows(struct ps_prochandle *, lwpid_t, gwindows_t *); 3757c478bd9Sstevel@tonic-gate 3767c478bd9Sstevel@tonic-gate #if defined(__sparcv9) 3777c478bd9Sstevel@tonic-gate extern int Plwp_getasrs(struct ps_prochandle *, lwpid_t, asrset_t); 3787c478bd9Sstevel@tonic-gate extern int Plwp_setasrs(struct ps_prochandle *, lwpid_t, const asrset_t); 3797c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */ 3807c478bd9Sstevel@tonic-gate 3817c478bd9Sstevel@tonic-gate #endif /* __sparc */ 3827c478bd9Sstevel@tonic-gate 3837c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64) 3847c478bd9Sstevel@tonic-gate extern int Pldt(struct ps_prochandle *, struct ssd *, int); 3857c478bd9Sstevel@tonic-gate extern int proc_get_ldt(pid_t, struct ssd *, int); 3867c478bd9Sstevel@tonic-gate #endif /* __i386 || __amd64 */ 3877c478bd9Sstevel@tonic-gate 3887c478bd9Sstevel@tonic-gate extern int Plwp_getpsinfo(struct ps_prochandle *, lwpid_t, lwpsinfo_t *); 3897c478bd9Sstevel@tonic-gate 3907c478bd9Sstevel@tonic-gate extern int Plwp_stack(struct ps_prochandle *, lwpid_t, stack_t *); 3917c478bd9Sstevel@tonic-gate extern int Plwp_main_stack(struct ps_prochandle *, lwpid_t, stack_t *); 3927c478bd9Sstevel@tonic-gate extern int Plwp_alt_stack(struct ps_prochandle *, lwpid_t, stack_t *); 3937c478bd9Sstevel@tonic-gate 3947c478bd9Sstevel@tonic-gate /* 3957c478bd9Sstevel@tonic-gate * LWP iteration interface; iterate over all active LWPs. 3967c478bd9Sstevel@tonic-gate */ 3977c478bd9Sstevel@tonic-gate typedef int proc_lwp_f(void *, const lwpstatus_t *); 3987c478bd9Sstevel@tonic-gate extern int Plwp_iter(struct ps_prochandle *, proc_lwp_f *, void *); 3997c478bd9Sstevel@tonic-gate 4007c478bd9Sstevel@tonic-gate /* 4017c478bd9Sstevel@tonic-gate * LWP iteration interface; iterate over all LWPs, active and zombie. 4027c478bd9Sstevel@tonic-gate */ 4037c478bd9Sstevel@tonic-gate typedef int proc_lwp_all_f(void *, const lwpstatus_t *, const lwpsinfo_t *); 4047c478bd9Sstevel@tonic-gate extern int Plwp_iter_all(struct ps_prochandle *, proc_lwp_all_f *, void *); 4057c478bd9Sstevel@tonic-gate 4067c478bd9Sstevel@tonic-gate /* 407ed9c9f97SRoger A. Faulkner * Process iteration interface; iterate over all non-system processes. 4087c478bd9Sstevel@tonic-gate */ 4097c478bd9Sstevel@tonic-gate typedef int proc_walk_f(psinfo_t *, lwpsinfo_t *, void *); 4107c478bd9Sstevel@tonic-gate extern int proc_walk(proc_walk_f *, void *, int); 4117c478bd9Sstevel@tonic-gate 4127c478bd9Sstevel@tonic-gate #define PR_WALK_PROC 0 /* walk processes only */ 4137c478bd9Sstevel@tonic-gate #define PR_WALK_LWP 1 /* walk all lwps */ 4147c478bd9Sstevel@tonic-gate 4157c478bd9Sstevel@tonic-gate /* 4167c478bd9Sstevel@tonic-gate * Determine if an lwp is in a set as returned from proc_arg_xgrab(). 4177c478bd9Sstevel@tonic-gate */ 4187c478bd9Sstevel@tonic-gate extern int proc_lwp_in_set(const char *, lwpid_t); 4197c478bd9Sstevel@tonic-gate extern int proc_lwp_range_valid(const char *); 4207c478bd9Sstevel@tonic-gate 4217c478bd9Sstevel@tonic-gate /* 4227c478bd9Sstevel@tonic-gate * Symbol table interfaces. 4237c478bd9Sstevel@tonic-gate */ 4247c478bd9Sstevel@tonic-gate 4257c478bd9Sstevel@tonic-gate /* 4267c478bd9Sstevel@tonic-gate * Pseudo-names passed to Plookup_by_name() for well-known load objects. 4277c478bd9Sstevel@tonic-gate * NOTE: It is required that PR_OBJ_EXEC and PR_OBJ_LDSO exactly match 4287c478bd9Sstevel@tonic-gate * the definitions of PS_OBJ_EXEC and PS_OBJ_LDSO from <proc_service.h>. 4297c478bd9Sstevel@tonic-gate */ 4307c478bd9Sstevel@tonic-gate #define PR_OBJ_EXEC ((const char *)0) /* search the executable file */ 4317c478bd9Sstevel@tonic-gate #define PR_OBJ_LDSO ((const char *)1) /* search ld.so.1 */ 4327c478bd9Sstevel@tonic-gate #define PR_OBJ_EVERY ((const char *)-1) /* search every load object */ 4337c478bd9Sstevel@tonic-gate 4347c478bd9Sstevel@tonic-gate /* 4357c478bd9Sstevel@tonic-gate * Special Lmid_t passed to Plookup_by_lmid() to search all link maps. The 4367c478bd9Sstevel@tonic-gate * special values LM_ID_BASE and LM_ID_LDSO from <link.h> may also be used. 4377c478bd9Sstevel@tonic-gate * If PR_OBJ_EXEC is used as the object name, the lmid must be PR_LMID_EVERY 4387c478bd9Sstevel@tonic-gate * or LM_ID_BASE in order to return a match. If PR_OBJ_LDSO is used as the 4397c478bd9Sstevel@tonic-gate * object name, the lmid must be PR_LMID_EVERY or LM_ID_LDSO to return a match. 4407c478bd9Sstevel@tonic-gate */ 4417c478bd9Sstevel@tonic-gate #define PR_LMID_EVERY ((Lmid_t)-1UL) /* search every link map */ 4427c478bd9Sstevel@tonic-gate 4437c478bd9Sstevel@tonic-gate /* 4447c478bd9Sstevel@tonic-gate * 'object_name' is the name of a load object obtained from an 4457c478bd9Sstevel@tonic-gate * iteration over the process's address space mappings (Pmapping_iter), 4467c478bd9Sstevel@tonic-gate * or an iteration over the process's mapped objects (Pobject_iter), 4477c478bd9Sstevel@tonic-gate * or else it is one of the special PR_OBJ_* values above. 4487c478bd9Sstevel@tonic-gate */ 4497c478bd9Sstevel@tonic-gate extern int Plookup_by_name(struct ps_prochandle *, 4507c478bd9Sstevel@tonic-gate const char *, const char *, GElf_Sym *); 4517c478bd9Sstevel@tonic-gate 4527c478bd9Sstevel@tonic-gate extern int Plookup_by_addr(struct ps_prochandle *, 4537c478bd9Sstevel@tonic-gate uintptr_t, char *, size_t, GElf_Sym *); 4547c478bd9Sstevel@tonic-gate 4557c478bd9Sstevel@tonic-gate typedef struct prsyminfo { 4567c478bd9Sstevel@tonic-gate const char *prs_object; /* object name */ 4577c478bd9Sstevel@tonic-gate const char *prs_name; /* symbol name */ 4587c478bd9Sstevel@tonic-gate Lmid_t prs_lmid; /* link map id */ 4597c478bd9Sstevel@tonic-gate uint_t prs_id; /* symbol id */ 4607c478bd9Sstevel@tonic-gate uint_t prs_table; /* symbol table id */ 4617c478bd9Sstevel@tonic-gate } prsyminfo_t; 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate extern int Pxlookup_by_name(struct ps_prochandle *, 4647c478bd9Sstevel@tonic-gate Lmid_t, const char *, const char *, GElf_Sym *, prsyminfo_t *); 4657c478bd9Sstevel@tonic-gate 4667c478bd9Sstevel@tonic-gate extern int Pxlookup_by_addr(struct ps_prochandle *, 4677c478bd9Sstevel@tonic-gate uintptr_t, char *, size_t, GElf_Sym *, prsyminfo_t *); 468186f7fbfSEdward Pilatowicz extern int Pxlookup_by_addr_resolved(struct ps_prochandle *, 469186f7fbfSEdward Pilatowicz uintptr_t, char *, size_t, GElf_Sym *, prsyminfo_t *); 4707c478bd9Sstevel@tonic-gate 4717c478bd9Sstevel@tonic-gate typedef int proc_map_f(void *, const prmap_t *, const char *); 4727c478bd9Sstevel@tonic-gate 4737c478bd9Sstevel@tonic-gate extern int Pmapping_iter(struct ps_prochandle *, proc_map_f *, void *); 474186f7fbfSEdward Pilatowicz extern int Pmapping_iter_resolved(struct ps_prochandle *, proc_map_f *, void *); 4757c478bd9Sstevel@tonic-gate extern int Pobject_iter(struct ps_prochandle *, proc_map_f *, void *); 476186f7fbfSEdward Pilatowicz extern int Pobject_iter_resolved(struct ps_prochandle *, proc_map_f *, void *); 4777c478bd9Sstevel@tonic-gate 4787c478bd9Sstevel@tonic-gate extern const prmap_t *Paddr_to_map(struct ps_prochandle *, uintptr_t); 4797c478bd9Sstevel@tonic-gate extern const prmap_t *Paddr_to_text_map(struct ps_prochandle *, uintptr_t); 4807c478bd9Sstevel@tonic-gate extern const prmap_t *Pname_to_map(struct ps_prochandle *, const char *); 4817c478bd9Sstevel@tonic-gate extern const prmap_t *Plmid_to_map(struct ps_prochandle *, 4827c478bd9Sstevel@tonic-gate Lmid_t, const char *); 4837c478bd9Sstevel@tonic-gate 4847c478bd9Sstevel@tonic-gate extern const rd_loadobj_t *Paddr_to_loadobj(struct ps_prochandle *, uintptr_t); 4857c478bd9Sstevel@tonic-gate extern const rd_loadobj_t *Pname_to_loadobj(struct ps_prochandle *, 4867c478bd9Sstevel@tonic-gate const char *); 4877c478bd9Sstevel@tonic-gate extern const rd_loadobj_t *Plmid_to_loadobj(struct ps_prochandle *, 4887c478bd9Sstevel@tonic-gate Lmid_t, const char *); 4897c478bd9Sstevel@tonic-gate 4907c478bd9Sstevel@tonic-gate extern ctf_file_t *Paddr_to_ctf(struct ps_prochandle *, uintptr_t); 4917c478bd9Sstevel@tonic-gate extern ctf_file_t *Pname_to_ctf(struct ps_prochandle *, const char *); 4927c478bd9Sstevel@tonic-gate 4937c478bd9Sstevel@tonic-gate extern char *Pplatform(struct ps_prochandle *, char *, size_t); 4947c478bd9Sstevel@tonic-gate extern int Puname(struct ps_prochandle *, struct utsname *); 4957c478bd9Sstevel@tonic-gate extern char *Pzonename(struct ps_prochandle *, char *, size_t); 496186f7fbfSEdward Pilatowicz extern char *Pfindobj(struct ps_prochandle *, const char *, char *, size_t); 4977c478bd9Sstevel@tonic-gate 4987c478bd9Sstevel@tonic-gate extern char *Pexecname(struct ps_prochandle *, char *, size_t); 4997c478bd9Sstevel@tonic-gate extern char *Pobjname(struct ps_prochandle *, uintptr_t, char *, size_t); 500186f7fbfSEdward Pilatowicz extern char *Pobjname_resolved(struct ps_prochandle *, uintptr_t, char *, 501186f7fbfSEdward Pilatowicz size_t); 5027c478bd9Sstevel@tonic-gate extern int Plmid(struct ps_prochandle *, uintptr_t, Lmid_t *); 5037c478bd9Sstevel@tonic-gate 5047c478bd9Sstevel@tonic-gate typedef int proc_env_f(void *, struct ps_prochandle *, uintptr_t, const char *); 5057c478bd9Sstevel@tonic-gate extern int Penv_iter(struct ps_prochandle *, proc_env_f *, void *); 5067c478bd9Sstevel@tonic-gate extern char *Pgetenv(struct ps_prochandle *, const char *, char *, size_t); 5077c478bd9Sstevel@tonic-gate extern long Pgetauxval(struct ps_prochandle *, int); 5087c478bd9Sstevel@tonic-gate extern const auxv_t *Pgetauxvec(struct ps_prochandle *); 5097c478bd9Sstevel@tonic-gate 5109acbbeafSnn35248 extern void Pset_procfs_path(const char *); 5119acbbeafSnn35248 5127c478bd9Sstevel@tonic-gate /* 5137c478bd9Sstevel@tonic-gate * Symbol table iteration interface. The special lmid constants LM_ID_BASE, 5147c478bd9Sstevel@tonic-gate * LM_ID_LDSO, and PR_LMID_EVERY may be used with Psymbol_iter_by_lmid. 5157c478bd9Sstevel@tonic-gate */ 5167c478bd9Sstevel@tonic-gate typedef int proc_sym_f(void *, const GElf_Sym *, const char *); 5177c478bd9Sstevel@tonic-gate typedef int proc_xsym_f(void *, const GElf_Sym *, const char *, 5187c478bd9Sstevel@tonic-gate const prsyminfo_t *); 5197c478bd9Sstevel@tonic-gate 5207c478bd9Sstevel@tonic-gate extern int Psymbol_iter(struct ps_prochandle *, 5217c478bd9Sstevel@tonic-gate const char *, int, int, proc_sym_f *, void *); 5227c478bd9Sstevel@tonic-gate extern int Psymbol_iter_by_addr(struct ps_prochandle *, 5237c478bd9Sstevel@tonic-gate const char *, int, int, proc_sym_f *, void *); 5247c478bd9Sstevel@tonic-gate extern int Psymbol_iter_by_name(struct ps_prochandle *, 5257c478bd9Sstevel@tonic-gate const char *, int, int, proc_sym_f *, void *); 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate extern int Psymbol_iter_by_lmid(struct ps_prochandle *, 5287c478bd9Sstevel@tonic-gate Lmid_t, const char *, int, int, proc_sym_f *, void *); 5297c478bd9Sstevel@tonic-gate 5307c478bd9Sstevel@tonic-gate extern int Pxsymbol_iter(struct ps_prochandle *, 5317c478bd9Sstevel@tonic-gate Lmid_t, const char *, int, int, proc_xsym_f *, void *); 5327c478bd9Sstevel@tonic-gate 5337c478bd9Sstevel@tonic-gate /* 5347c478bd9Sstevel@tonic-gate * 'which' selects which symbol table and can be one of the following. 5357c478bd9Sstevel@tonic-gate */ 5367c478bd9Sstevel@tonic-gate #define PR_SYMTAB 1 5377c478bd9Sstevel@tonic-gate #define PR_DYNSYM 2 5387c478bd9Sstevel@tonic-gate /* 5397c478bd9Sstevel@tonic-gate * 'type' selects the symbols of interest by binding and type. It is a bit- 5407c478bd9Sstevel@tonic-gate * mask of one or more of the following flags, whose order MUST match the 5417c478bd9Sstevel@tonic-gate * order of STB and STT constants in <sys/elf.h>. 5427c478bd9Sstevel@tonic-gate */ 5437c478bd9Sstevel@tonic-gate #define BIND_LOCAL 0x0001 5447c478bd9Sstevel@tonic-gate #define BIND_GLOBAL 0x0002 5457c478bd9Sstevel@tonic-gate #define BIND_WEAK 0x0004 5467c478bd9Sstevel@tonic-gate #define BIND_ANY (BIND_LOCAL|BIND_GLOBAL|BIND_WEAK) 5477c478bd9Sstevel@tonic-gate #define TYPE_NOTYPE 0x0100 5487c478bd9Sstevel@tonic-gate #define TYPE_OBJECT 0x0200 5497c478bd9Sstevel@tonic-gate #define TYPE_FUNC 0x0400 5507c478bd9Sstevel@tonic-gate #define TYPE_SECTION 0x0800 5517c478bd9Sstevel@tonic-gate #define TYPE_FILE 0x1000 5527c478bd9Sstevel@tonic-gate #define TYPE_ANY (TYPE_NOTYPE|TYPE_OBJECT|TYPE_FUNC|TYPE_SECTION|TYPE_FILE) 5537c478bd9Sstevel@tonic-gate 5547c478bd9Sstevel@tonic-gate /* 5557c478bd9Sstevel@tonic-gate * This returns the rtld_db agent handle for the process. 5567c478bd9Sstevel@tonic-gate * The handle will become invalid at the next successful exec() and 5577c478bd9Sstevel@tonic-gate * must not be used beyond that point (see Preset_maps(), below). 5587c478bd9Sstevel@tonic-gate */ 5597c478bd9Sstevel@tonic-gate extern rd_agent_t *Prd_agent(struct ps_prochandle *); 5607c478bd9Sstevel@tonic-gate 5617c478bd9Sstevel@tonic-gate /* 5627c478bd9Sstevel@tonic-gate * This should be called when an RD_DLACTIVITY event with the 5637c478bd9Sstevel@tonic-gate * RD_CONSISTENT state occurs via librtld_db's event mechanism. 5647c478bd9Sstevel@tonic-gate * This makes libproc's address space mappings and symbol tables current. 5657c478bd9Sstevel@tonic-gate * The variant Pupdate_syms() can be used to preload all symbol tables as well. 5667c478bd9Sstevel@tonic-gate */ 5677c478bd9Sstevel@tonic-gate extern void Pupdate_maps(struct ps_prochandle *); 5687c478bd9Sstevel@tonic-gate extern void Pupdate_syms(struct ps_prochandle *); 5697c478bd9Sstevel@tonic-gate 5707c478bd9Sstevel@tonic-gate /* 5717c478bd9Sstevel@tonic-gate * This must be called after the victim process performs a successful 5727c478bd9Sstevel@tonic-gate * exec() if any of the symbol table interface functions have been called 5737c478bd9Sstevel@tonic-gate * prior to that point. This is essential because an exec() invalidates 5747c478bd9Sstevel@tonic-gate * all previous symbol table and address space mapping information. 5757c478bd9Sstevel@tonic-gate * It is always safe to call, but if it is called other than after an 5767c478bd9Sstevel@tonic-gate * exec() by the victim process it just causes unnecessary overhead. 5777c478bd9Sstevel@tonic-gate * 5787c478bd9Sstevel@tonic-gate * The rtld_db agent handle obtained from a previous call to Prd_agent() is 5797c478bd9Sstevel@tonic-gate * made invalid by Preset_maps() and Prd_agent() must be called again to get 5807c478bd9Sstevel@tonic-gate * the new handle. 5817c478bd9Sstevel@tonic-gate */ 5827c478bd9Sstevel@tonic-gate extern void Preset_maps(struct ps_prochandle *); 5837c478bd9Sstevel@tonic-gate 5847c478bd9Sstevel@tonic-gate /* 5857c478bd9Sstevel@tonic-gate * Given an address, Ppltdest() determines if this is part of a PLT, and if 5867c478bd9Sstevel@tonic-gate * so returns a pointer to the symbol name that will be used for resolution. 5877c478bd9Sstevel@tonic-gate * If the specified address is not part of a PLT, the function returns NULL. 5887c478bd9Sstevel@tonic-gate */ 5897c478bd9Sstevel@tonic-gate extern const char *Ppltdest(struct ps_prochandle *, uintptr_t); 5907c478bd9Sstevel@tonic-gate 5917c478bd9Sstevel@tonic-gate /* 5927c478bd9Sstevel@tonic-gate * See comments for Pissyscall(), in Pisadep.h 5937c478bd9Sstevel@tonic-gate */ 5947c478bd9Sstevel@tonic-gate extern int Pissyscall_prev(struct ps_prochandle *, uintptr_t, uintptr_t *); 5957c478bd9Sstevel@tonic-gate 5967c478bd9Sstevel@tonic-gate /* 5977c478bd9Sstevel@tonic-gate * Stack frame iteration interface. 5987c478bd9Sstevel@tonic-gate */ 5997c478bd9Sstevel@tonic-gate typedef int proc_stack_f(void *, prgregset_t, uint_t, const long *); 6007c478bd9Sstevel@tonic-gate 6017c478bd9Sstevel@tonic-gate extern int Pstack_iter(struct ps_prochandle *, 6027c478bd9Sstevel@tonic-gate const prgregset_t, proc_stack_f *, void *); 6037c478bd9Sstevel@tonic-gate 6047c478bd9Sstevel@tonic-gate /* 6057c478bd9Sstevel@tonic-gate * The following functions define a set of passive interfaces: libproc provides 6067c478bd9Sstevel@tonic-gate * default, empty definitions that are called internally. If a client wishes 6077c478bd9Sstevel@tonic-gate * to override these definitions, it can simply provide its own version with 6087c478bd9Sstevel@tonic-gate * the same signature that interposes on the libproc definition. 6097c478bd9Sstevel@tonic-gate * 6107c478bd9Sstevel@tonic-gate * If the client program wishes to report additional error information, it 6117c478bd9Sstevel@tonic-gate * can provide its own version of Perror_printf. 6127c478bd9Sstevel@tonic-gate * 6137c478bd9Sstevel@tonic-gate * If the client program wishes to receive a callback after Pcreate forks 6147c478bd9Sstevel@tonic-gate * but before it execs, it can provide its own version of Pcreate_callback. 6157c478bd9Sstevel@tonic-gate */ 6167c478bd9Sstevel@tonic-gate extern void Perror_printf(struct ps_prochandle *P, const char *format, ...); 6177c478bd9Sstevel@tonic-gate extern void Pcreate_callback(struct ps_prochandle *); 6187c478bd9Sstevel@tonic-gate 6197c478bd9Sstevel@tonic-gate /* 6207c478bd9Sstevel@tonic-gate * Remove unprintable characters from psinfo.pr_psargs and replace with 6217c478bd9Sstevel@tonic-gate * whitespace characters so it is safe for printing. 6227c478bd9Sstevel@tonic-gate */ 6237c478bd9Sstevel@tonic-gate extern void proc_unctrl_psinfo(psinfo_t *); 6247c478bd9Sstevel@tonic-gate 6257c478bd9Sstevel@tonic-gate /* 6267c478bd9Sstevel@tonic-gate * Utility functions for processing arguments which should be /proc files, 6277c478bd9Sstevel@tonic-gate * pids, and/or core files. The returned error code can be passed to 6287c478bd9Sstevel@tonic-gate * Pgrab_error() in order to convert it to an error string. 6297c478bd9Sstevel@tonic-gate */ 6307c478bd9Sstevel@tonic-gate #define PR_ARG_PIDS 0x1 /* Allow pid and /proc file arguments */ 6317c478bd9Sstevel@tonic-gate #define PR_ARG_CORES 0x2 /* Allow core file arguments */ 6327c478bd9Sstevel@tonic-gate 6337c478bd9Sstevel@tonic-gate #define PR_ARG_ANY (PR_ARG_PIDS | PR_ARG_CORES) 6347c478bd9Sstevel@tonic-gate 6357c478bd9Sstevel@tonic-gate extern struct ps_prochandle *proc_arg_grab(const char *, int, int, int *); 6367c478bd9Sstevel@tonic-gate extern struct ps_prochandle *proc_arg_xgrab(const char *, const char *, int, 6377c478bd9Sstevel@tonic-gate int, int *, const char **); 6387c478bd9Sstevel@tonic-gate extern pid_t proc_arg_psinfo(const char *, int, psinfo_t *, int *); 6397c478bd9Sstevel@tonic-gate extern pid_t proc_arg_xpsinfo(const char *, int, psinfo_t *, int *, 6407c478bd9Sstevel@tonic-gate const char **); 6417c478bd9Sstevel@tonic-gate 6427c478bd9Sstevel@tonic-gate /* 6437c478bd9Sstevel@tonic-gate * Utility functions for obtaining information via /proc without actually 6447c478bd9Sstevel@tonic-gate * performing a Pcreate() or Pgrab(): 6457c478bd9Sstevel@tonic-gate */ 6467c478bd9Sstevel@tonic-gate extern int proc_get_auxv(pid_t, auxv_t *, int); 6477c478bd9Sstevel@tonic-gate extern int proc_get_cred(pid_t, prcred_t *, int); 6487c478bd9Sstevel@tonic-gate extern prpriv_t *proc_get_priv(pid_t); 6497c478bd9Sstevel@tonic-gate extern int proc_get_psinfo(pid_t, psinfo_t *); 6507c478bd9Sstevel@tonic-gate extern int proc_get_status(pid_t, pstatus_t *); 6517c478bd9Sstevel@tonic-gate 6527c478bd9Sstevel@tonic-gate /* 6537c478bd9Sstevel@tonic-gate * Utility functions for debugging tools to convert numeric fault, 6547c478bd9Sstevel@tonic-gate * signal, and system call numbers to symbolic names: 6557c478bd9Sstevel@tonic-gate */ 6567c478bd9Sstevel@tonic-gate #define FLT2STR_MAX 32 /* max. string length of faults (like SIG2STR_MAX) */ 6577c478bd9Sstevel@tonic-gate #define SYS2STR_MAX 32 /* max. string length of syscalls (like SIG2STR_MAX) */ 6587c478bd9Sstevel@tonic-gate 6597c478bd9Sstevel@tonic-gate extern char *proc_fltname(int, char *, size_t); 6607c478bd9Sstevel@tonic-gate extern char *proc_signame(int, char *, size_t); 6617c478bd9Sstevel@tonic-gate extern char *proc_sysname(int, char *, size_t); 6627c478bd9Sstevel@tonic-gate 6637c478bd9Sstevel@tonic-gate /* 6647c478bd9Sstevel@tonic-gate * Utility functions for debugging tools to convert fault, signal, and system 6657c478bd9Sstevel@tonic-gate * call names back to the numeric constants: 6667c478bd9Sstevel@tonic-gate */ 6677c478bd9Sstevel@tonic-gate extern int proc_str2flt(const char *, int *); 6687c478bd9Sstevel@tonic-gate extern int proc_str2sig(const char *, int *); 6697c478bd9Sstevel@tonic-gate extern int proc_str2sys(const char *, int *); 6707c478bd9Sstevel@tonic-gate 6717c478bd9Sstevel@tonic-gate /* 6727c478bd9Sstevel@tonic-gate * Utility functions for debugging tools to convert a fault, signal or system 6737c478bd9Sstevel@tonic-gate * call set to a string representation (e.g. "BUS,SEGV" or "open,close,read"). 6747c478bd9Sstevel@tonic-gate */ 6757c478bd9Sstevel@tonic-gate #define PRSIGBUFSZ 1024 /* buffer size for proc_sigset2str() */ 6767c478bd9Sstevel@tonic-gate 6777c478bd9Sstevel@tonic-gate extern char *proc_fltset2str(const fltset_t *, const char *, int, 6787c478bd9Sstevel@tonic-gate char *, size_t); 6797c478bd9Sstevel@tonic-gate extern char *proc_sigset2str(const sigset_t *, const char *, int, 6807c478bd9Sstevel@tonic-gate char *, size_t); 6817c478bd9Sstevel@tonic-gate extern char *proc_sysset2str(const sysset_t *, const char *, int, 6827c478bd9Sstevel@tonic-gate char *, size_t); 6837c478bd9Sstevel@tonic-gate 6847c478bd9Sstevel@tonic-gate extern int Pgcore(struct ps_prochandle *, const char *, core_content_t); 6857c478bd9Sstevel@tonic-gate extern int Pfgcore(struct ps_prochandle *, int, core_content_t); 6867c478bd9Sstevel@tonic-gate extern core_content_t Pcontent(struct ps_prochandle *); 6877c478bd9Sstevel@tonic-gate 6887c478bd9Sstevel@tonic-gate /* 6897c478bd9Sstevel@tonic-gate * Utility functions for debugging tools to convert a string representation of 6907c478bd9Sstevel@tonic-gate * a fault, signal or system call set back to the numeric value of the 6917c478bd9Sstevel@tonic-gate * corresponding set type. 6927c478bd9Sstevel@tonic-gate */ 6937c478bd9Sstevel@tonic-gate extern char *proc_str2fltset(const char *, const char *, int, fltset_t *); 6947c478bd9Sstevel@tonic-gate extern char *proc_str2sigset(const char *, const char *, int, sigset_t *); 6957c478bd9Sstevel@tonic-gate extern char *proc_str2sysset(const char *, const char *, int, sysset_t *); 6967c478bd9Sstevel@tonic-gate 6977c478bd9Sstevel@tonic-gate /* 6987c478bd9Sstevel@tonic-gate * Utility functions for converting between strings and core_content_t. 6997c478bd9Sstevel@tonic-gate */ 7007c478bd9Sstevel@tonic-gate #define PRCONTENTBUFSZ 80 /* buffer size for proc_content2str() */ 7017c478bd9Sstevel@tonic-gate 7027c478bd9Sstevel@tonic-gate extern int proc_str2content(const char *, core_content_t *); 7037c478bd9Sstevel@tonic-gate extern int proc_content2str(core_content_t, char *, size_t); 7047c478bd9Sstevel@tonic-gate 7057c478bd9Sstevel@tonic-gate /* 7067c478bd9Sstevel@tonic-gate * Utility functions for buffering output to stdout, stderr while 7077c478bd9Sstevel@tonic-gate * process is grabbed. Prevents deadlocks due to pfiles `pgrep xterm` 7087c478bd9Sstevel@tonic-gate * and other varients. 7097c478bd9Sstevel@tonic-gate */ 7107c478bd9Sstevel@tonic-gate extern int proc_initstdio(void); 7117c478bd9Sstevel@tonic-gate extern int proc_flushstdio(void); 7127c478bd9Sstevel@tonic-gate extern int proc_finistdio(void); 7137c478bd9Sstevel@tonic-gate 7147c478bd9Sstevel@tonic-gate #ifdef __cplusplus 7157c478bd9Sstevel@tonic-gate } 7167c478bd9Sstevel@tonic-gate #endif 7177c478bd9Sstevel@tonic-gate 7187c478bd9Sstevel@tonic-gate #endif /* _LIBPROC_H */ 719