1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _PCONTROL_H 28*7c478bd9Sstevel@tonic-gate #define _PCONTROL_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate /* 33*7c478bd9Sstevel@tonic-gate * Implemention-specific include file for libproc process management. 34*7c478bd9Sstevel@tonic-gate * This is not to be seen by the clients of libproc. 35*7c478bd9Sstevel@tonic-gate */ 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #include <stdio.h> 38*7c478bd9Sstevel@tonic-gate #include <gelf.h> 39*7c478bd9Sstevel@tonic-gate #include <synch.h> 40*7c478bd9Sstevel@tonic-gate #include <procfs.h> 41*7c478bd9Sstevel@tonic-gate #include <rtld_db.h> 42*7c478bd9Sstevel@tonic-gate #include <libproc.h> 43*7c478bd9Sstevel@tonic-gate #include <libctf.h> 44*7c478bd9Sstevel@tonic-gate 45*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 46*7c478bd9Sstevel@tonic-gate extern "C" { 47*7c478bd9Sstevel@tonic-gate #endif 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate #include "Putil.h" 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate /* 52*7c478bd9Sstevel@tonic-gate * Definitions of the process control structures, internal to libproc. 53*7c478bd9Sstevel@tonic-gate * These may change without affecting clients of libproc. 54*7c478bd9Sstevel@tonic-gate */ 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate typedef struct { /* symbol table */ 57*7c478bd9Sstevel@tonic-gate Elf_Data *sym_data; /* start of table */ 58*7c478bd9Sstevel@tonic-gate size_t sym_symn; /* number of entries */ 59*7c478bd9Sstevel@tonic-gate char *sym_strs; /* ptr to strings */ 60*7c478bd9Sstevel@tonic-gate size_t sym_strsz; /* size of string table */ 61*7c478bd9Sstevel@tonic-gate GElf_Shdr sym_hdr; /* symbol table section header */ 62*7c478bd9Sstevel@tonic-gate GElf_Shdr sym_strhdr; /* string table section header */ 63*7c478bd9Sstevel@tonic-gate Elf *sym_elf; /* faked-up elf handle from core file */ 64*7c478bd9Sstevel@tonic-gate void *sym_elfmem; /* data for faked-up elf handle */ 65*7c478bd9Sstevel@tonic-gate uint_t *sym_byname; /* symbols sorted by name */ 66*7c478bd9Sstevel@tonic-gate uint_t *sym_byaddr; /* symbols sorted by addr */ 67*7c478bd9Sstevel@tonic-gate size_t sym_count; /* number of symbols in each sorted list */ 68*7c478bd9Sstevel@tonic-gate } sym_tbl_t; 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate typedef struct file_info { /* symbol information for a mapped file */ 71*7c478bd9Sstevel@tonic-gate list_t file_list; /* linked list */ 72*7c478bd9Sstevel@tonic-gate char file_pname[PRMAPSZ]; /* name from prmap_t */ 73*7c478bd9Sstevel@tonic-gate struct map_info *file_map; /* primary (text) mapping */ 74*7c478bd9Sstevel@tonic-gate int file_ref; /* references from map_info_t structures */ 75*7c478bd9Sstevel@tonic-gate int file_fd; /* file descriptor for the mapped file */ 76*7c478bd9Sstevel@tonic-gate int file_init; /* 0: initialization yet to be performed */ 77*7c478bd9Sstevel@tonic-gate GElf_Half file_etype; /* ELF e_type from ehdr */ 78*7c478bd9Sstevel@tonic-gate GElf_Half file_class; /* ELF e_ident[EI_CLASS] from ehdr */ 79*7c478bd9Sstevel@tonic-gate rd_loadobj_t *file_lo; /* load object structure from rtld_db */ 80*7c478bd9Sstevel@tonic-gate char *file_lname; /* load object name from rtld_db */ 81*7c478bd9Sstevel@tonic-gate char *file_lbase; /* pointer to basename of file_lname */ 82*7c478bd9Sstevel@tonic-gate Elf *file_elf; /* elf handle so we can close */ 83*7c478bd9Sstevel@tonic-gate void *file_elfmem; /* data for faked-up elf handle */ 84*7c478bd9Sstevel@tonic-gate sym_tbl_t file_symtab; /* symbol table */ 85*7c478bd9Sstevel@tonic-gate sym_tbl_t file_dynsym; /* dynamic symbol table */ 86*7c478bd9Sstevel@tonic-gate uintptr_t file_dyn_base; /* load address for ET_DYN files */ 87*7c478bd9Sstevel@tonic-gate uintptr_t file_plt_base; /* base address for PLT */ 88*7c478bd9Sstevel@tonic-gate size_t file_plt_size; /* size of PLT region */ 89*7c478bd9Sstevel@tonic-gate uintptr_t file_jmp_rel; /* base address of PLT relocations */ 90*7c478bd9Sstevel@tonic-gate uintptr_t file_ctf_off; /* offset of CTF data in object file */ 91*7c478bd9Sstevel@tonic-gate size_t file_ctf_size; /* size of CTF data in object file */ 92*7c478bd9Sstevel@tonic-gate int file_ctf_dyn; /* does the CTF data reference the dynsym */ 93*7c478bd9Sstevel@tonic-gate void *file_ctf_buf; /* CTF data for this file */ 94*7c478bd9Sstevel@tonic-gate ctf_file_t *file_ctfp; /* CTF container for this file */ 95*7c478bd9Sstevel@tonic-gate } file_info_t; 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate typedef struct map_info { /* description of an address space mapping */ 98*7c478bd9Sstevel@tonic-gate prmap_t map_pmap; /* /proc description of this mapping */ 99*7c478bd9Sstevel@tonic-gate file_info_t *map_file; /* pointer into list of mapped files */ 100*7c478bd9Sstevel@tonic-gate off64_t map_offset; /* offset into core file (if core) */ 101*7c478bd9Sstevel@tonic-gate int map_relocate; /* associated file_map needs to be relocated */ 102*7c478bd9Sstevel@tonic-gate } map_info_t; 103*7c478bd9Sstevel@tonic-gate 104*7c478bd9Sstevel@tonic-gate typedef struct lwp_info { /* per-lwp information from core file */ 105*7c478bd9Sstevel@tonic-gate list_t lwp_list; /* linked list */ 106*7c478bd9Sstevel@tonic-gate lwpid_t lwp_id; /* lwp identifier */ 107*7c478bd9Sstevel@tonic-gate lwpsinfo_t lwp_psinfo; /* /proc/<pid>/lwp/<lwpid>/lwpsinfo data */ 108*7c478bd9Sstevel@tonic-gate lwpstatus_t lwp_status; /* /proc/<pid>/lwp/<lwpid>/lwpstatus data */ 109*7c478bd9Sstevel@tonic-gate #if defined(sparc) || defined(__sparc) 110*7c478bd9Sstevel@tonic-gate gwindows_t *lwp_gwins; /* /proc/<pid>/lwp/<lwpid>/gwindows data */ 111*7c478bd9Sstevel@tonic-gate prxregset_t *lwp_xregs; /* /proc/<pid>/lwp/<lwpid>/xregs data */ 112*7c478bd9Sstevel@tonic-gate int64_t *lwp_asrs; /* /proc/<pid>/lwp/<lwpid>/asrs data */ 113*7c478bd9Sstevel@tonic-gate #endif 114*7c478bd9Sstevel@tonic-gate } lwp_info_t; 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate typedef struct core_info { /* information specific to core files */ 117*7c478bd9Sstevel@tonic-gate char core_dmodel; /* data model for core file */ 118*7c478bd9Sstevel@tonic-gate int core_errno; /* error during initialization if != 0 */ 119*7c478bd9Sstevel@tonic-gate list_t core_lwp_head; /* head of list of lwp info */ 120*7c478bd9Sstevel@tonic-gate lwp_info_t *core_lwp; /* current lwp information */ 121*7c478bd9Sstevel@tonic-gate uint_t core_nlwp; /* number of lwp's in list */ 122*7c478bd9Sstevel@tonic-gate off64_t core_size; /* size of core file in bytes */ 123*7c478bd9Sstevel@tonic-gate char *core_platform; /* platform string from core file */ 124*7c478bd9Sstevel@tonic-gate struct utsname *core_uts; /* uname(2) data from core file */ 125*7c478bd9Sstevel@tonic-gate prcred_t *core_cred; /* process credential from core file */ 126*7c478bd9Sstevel@tonic-gate core_content_t core_content; /* content dumped to core file */ 127*7c478bd9Sstevel@tonic-gate prpriv_t *core_priv; /* process privileges from core file */ 128*7c478bd9Sstevel@tonic-gate size_t core_priv_size; /* size of the privileges */ 129*7c478bd9Sstevel@tonic-gate void *core_privinfo; /* system privileges info from core file */ 130*7c478bd9Sstevel@tonic-gate priv_impl_info_t *core_ppii; /* NOTE entry for core_privinfo */ 131*7c478bd9Sstevel@tonic-gate char *core_zonename; /* zone name from core file */ 132*7c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64) 133*7c478bd9Sstevel@tonic-gate struct ssd *core_ldt; /* LDT entries from core file */ 134*7c478bd9Sstevel@tonic-gate uint_t core_nldt; /* number of LDT entries in core file */ 135*7c478bd9Sstevel@tonic-gate #endif 136*7c478bd9Sstevel@tonic-gate } core_info_t; 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate typedef struct elf_file { /* convenience for managing ELF files */ 139*7c478bd9Sstevel@tonic-gate GElf_Ehdr e_hdr; /* ELF file header information */ 140*7c478bd9Sstevel@tonic-gate Elf *e_elf; /* ELF library handle */ 141*7c478bd9Sstevel@tonic-gate int e_fd; /* file descriptor */ 142*7c478bd9Sstevel@tonic-gate } elf_file_t; 143*7c478bd9Sstevel@tonic-gate 144*7c478bd9Sstevel@tonic-gate typedef struct ps_rwops { /* ops vector for Pread() and Pwrite() */ 145*7c478bd9Sstevel@tonic-gate ssize_t (*p_pread)(struct ps_prochandle *, 146*7c478bd9Sstevel@tonic-gate void *, size_t, uintptr_t); 147*7c478bd9Sstevel@tonic-gate ssize_t (*p_pwrite)(struct ps_prochandle *, 148*7c478bd9Sstevel@tonic-gate const void *, size_t, uintptr_t); 149*7c478bd9Sstevel@tonic-gate } ps_rwops_t; 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate #define HASHSIZE 1024 /* hash table size, power of 2 */ 152*7c478bd9Sstevel@tonic-gate 153*7c478bd9Sstevel@tonic-gate struct ps_prochandle { 154*7c478bd9Sstevel@tonic-gate struct ps_lwphandle **hashtab; /* hash table for LWPs (Lgrab()) */ 155*7c478bd9Sstevel@tonic-gate mutex_t proc_lock; /* protects hash table; serializes Lgrab() */ 156*7c478bd9Sstevel@tonic-gate pstatus_t orig_status; /* remembered status on Pgrab() */ 157*7c478bd9Sstevel@tonic-gate pstatus_t status; /* status when stopped */ 158*7c478bd9Sstevel@tonic-gate psinfo_t psinfo; /* psinfo_t from last Ppsinfo() request */ 159*7c478bd9Sstevel@tonic-gate uintptr_t sysaddr; /* address of most recent syscall instruction */ 160*7c478bd9Sstevel@tonic-gate pid_t pid; /* process-ID */ 161*7c478bd9Sstevel@tonic-gate int state; /* state of the process, see "libproc.h" */ 162*7c478bd9Sstevel@tonic-gate uint_t flags; /* see defines below */ 163*7c478bd9Sstevel@tonic-gate uint_t agentcnt; /* Pcreate_agent()/Pdestroy_agent() ref count */ 164*7c478bd9Sstevel@tonic-gate int asfd; /* /proc/<pid>/as filedescriptor */ 165*7c478bd9Sstevel@tonic-gate int ctlfd; /* /proc/<pid>/ctl filedescriptor */ 166*7c478bd9Sstevel@tonic-gate int statfd; /* /proc/<pid>/status filedescriptor */ 167*7c478bd9Sstevel@tonic-gate int agentctlfd; /* /proc/<pid>/lwp/agent/ctl */ 168*7c478bd9Sstevel@tonic-gate int agentstatfd; /* /proc/<pid>/lwp/agent/status */ 169*7c478bd9Sstevel@tonic-gate int info_valid; /* if zero, map and file info need updating */ 170*7c478bd9Sstevel@tonic-gate map_info_t *mappings; /* cached process mappings */ 171*7c478bd9Sstevel@tonic-gate size_t map_count; /* number of mappings */ 172*7c478bd9Sstevel@tonic-gate size_t map_alloc; /* number of mappings allocated */ 173*7c478bd9Sstevel@tonic-gate uint_t num_files; /* number of file elements in file_info */ 174*7c478bd9Sstevel@tonic-gate list_t file_head; /* head of mapped files w/ symbol table info */ 175*7c478bd9Sstevel@tonic-gate char *execname; /* name of the executable file */ 176*7c478bd9Sstevel@tonic-gate auxv_t *auxv; /* the process's aux vector */ 177*7c478bd9Sstevel@tonic-gate int nauxv; /* number of aux vector entries */ 178*7c478bd9Sstevel@tonic-gate rd_agent_t *rap; /* cookie for rtld_db */ 179*7c478bd9Sstevel@tonic-gate map_info_t *map_exec; /* the mapping for the executable file */ 180*7c478bd9Sstevel@tonic-gate map_info_t *map_ldso; /* the mapping for ld.so.1 */ 181*7c478bd9Sstevel@tonic-gate const ps_rwops_t *ops; /* pointer to ops-vector for read and write */ 182*7c478bd9Sstevel@tonic-gate core_info_t *core; /* information specific to core (if PS_DEAD) */ 183*7c478bd9Sstevel@tonic-gate uintptr_t *ucaddrs; /* ucontext-list addresses */ 184*7c478bd9Sstevel@tonic-gate uint_t ucnelems; /* number of elements in the ucaddrs list */ 185*7c478bd9Sstevel@tonic-gate }; 186*7c478bd9Sstevel@tonic-gate 187*7c478bd9Sstevel@tonic-gate /* flags */ 188*7c478bd9Sstevel@tonic-gate #define CREATED 0x01 /* process was created by Pcreate() */ 189*7c478bd9Sstevel@tonic-gate #define SETSIG 0x02 /* set signal trace mask before continuing */ 190*7c478bd9Sstevel@tonic-gate #define SETFAULT 0x04 /* set fault trace mask before continuing */ 191*7c478bd9Sstevel@tonic-gate #define SETENTRY 0x08 /* set sysentry trace mask before continuing */ 192*7c478bd9Sstevel@tonic-gate #define SETEXIT 0x10 /* set sysexit trace mask before continuing */ 193*7c478bd9Sstevel@tonic-gate #define SETHOLD 0x20 /* set signal hold mask before continuing */ 194*7c478bd9Sstevel@tonic-gate #define SETREGS 0x40 /* set registers before continuing */ 195*7c478bd9Sstevel@tonic-gate 196*7c478bd9Sstevel@tonic-gate struct ps_lwphandle { 197*7c478bd9Sstevel@tonic-gate struct ps_prochandle *lwp_proc; /* process to which this lwp belongs */ 198*7c478bd9Sstevel@tonic-gate struct ps_lwphandle *lwp_hash; /* hash table linked list */ 199*7c478bd9Sstevel@tonic-gate lwpstatus_t lwp_status; /* status when stopped */ 200*7c478bd9Sstevel@tonic-gate lwpsinfo_t lwp_psinfo; /* lwpsinfo_t from last Lpsinfo() */ 201*7c478bd9Sstevel@tonic-gate lwpid_t lwp_id; /* lwp identifier */ 202*7c478bd9Sstevel@tonic-gate int lwp_state; /* state of the lwp, see "libproc.h" */ 203*7c478bd9Sstevel@tonic-gate uint_t lwp_flags; /* SETHOLD and/or SETREGS */ 204*7c478bd9Sstevel@tonic-gate int lwp_ctlfd; /* /proc/<pid>/lwp/<lwpid>/lwpctl */ 205*7c478bd9Sstevel@tonic-gate int lwp_statfd; /* /proc/<pid>/lwp/<lwpid>/lwpstatus */ 206*7c478bd9Sstevel@tonic-gate }; 207*7c478bd9Sstevel@tonic-gate 208*7c478bd9Sstevel@tonic-gate /* 209*7c478bd9Sstevel@tonic-gate * Implementation functions in the process control library. 210*7c478bd9Sstevel@tonic-gate * These are not exported to clients of the library. 211*7c478bd9Sstevel@tonic-gate */ 212*7c478bd9Sstevel@tonic-gate extern void prldump(const char *, lwpstatus_t *); 213*7c478bd9Sstevel@tonic-gate extern int dupfd(int, int); 214*7c478bd9Sstevel@tonic-gate extern int set_minfd(void); 215*7c478bd9Sstevel@tonic-gate extern int Pscantext(struct ps_prochandle *); 216*7c478bd9Sstevel@tonic-gate extern void Pinitsym(struct ps_prochandle *); 217*7c478bd9Sstevel@tonic-gate extern void Preadauxvec(struct ps_prochandle *); 218*7c478bd9Sstevel@tonic-gate extern void optimize_symtab(sym_tbl_t *); 219*7c478bd9Sstevel@tonic-gate extern void Pbuild_file_symtab(struct ps_prochandle *, file_info_t *); 220*7c478bd9Sstevel@tonic-gate extern ctf_file_t *Pbuild_file_ctf(struct ps_prochandle *, file_info_t *); 221*7c478bd9Sstevel@tonic-gate extern map_info_t *Paddr2mptr(struct ps_prochandle *, uintptr_t); 222*7c478bd9Sstevel@tonic-gate extern char *Pfindexec(struct ps_prochandle *, const char *, 223*7c478bd9Sstevel@tonic-gate int (*)(const char *, void *), void *); 224*7c478bd9Sstevel@tonic-gate extern int getlwpstatus(struct ps_prochandle *, lwpid_t, lwpstatus_t *); 225*7c478bd9Sstevel@tonic-gate int Pstopstatus(struct ps_prochandle *, long, uint32_t); 226*7c478bd9Sstevel@tonic-gate 227*7c478bd9Sstevel@tonic-gate extern int Padd_mapping(struct ps_prochandle *, off64_t, file_info_t *, 228*7c478bd9Sstevel@tonic-gate prmap_t *); 229*7c478bd9Sstevel@tonic-gate extern void Psort_mappings(struct ps_prochandle *); 230*7c478bd9Sstevel@tonic-gate 231*7c478bd9Sstevel@tonic-gate /* 232*7c478bd9Sstevel@tonic-gate * Architecture-dependent definition of the breakpoint instruction. 233*7c478bd9Sstevel@tonic-gate */ 234*7c478bd9Sstevel@tonic-gate #if defined(sparc) || defined(__sparc) 235*7c478bd9Sstevel@tonic-gate #define BPT ((instr_t)0x91d02001) 236*7c478bd9Sstevel@tonic-gate #elif defined(__i386) || defined(__amd64) 237*7c478bd9Sstevel@tonic-gate #define BPT ((instr_t)0xcc) 238*7c478bd9Sstevel@tonic-gate #endif 239*7c478bd9Sstevel@tonic-gate 240*7c478bd9Sstevel@tonic-gate /* 241*7c478bd9Sstevel@tonic-gate * Simple convenience. 242*7c478bd9Sstevel@tonic-gate */ 243*7c478bd9Sstevel@tonic-gate #define TRUE 1 244*7c478bd9Sstevel@tonic-gate #define FALSE 0 245*7c478bd9Sstevel@tonic-gate 246*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 247*7c478bd9Sstevel@tonic-gate } 248*7c478bd9Sstevel@tonic-gate #endif 249*7c478bd9Sstevel@tonic-gate 250*7c478bd9Sstevel@tonic-gate #endif /* _PCONTROL_H */ 251