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