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