Print this page
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/lib/libproc/common/Pcontrol.h
+++ new/usr/src/lib/libproc/common/Pcontrol.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25 /*
26 26 * Copyright 2012 DEY Storage Systems, Inc. All rights reserved.
27 27 * Copyright (c) 2013 by Delphix. All rights reserved.
28 28 * Copyright 2018 Joyent, Inc.
29 29 * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
30 30 * Copyright 2023 Oxide Computer Company
31 31 */
32 32
33 33 #ifndef _PCONTROL_H
34 34 #define _PCONTROL_H
35 35
36 36 /*
37 37 * Implemention-specific include file for libproc process management.
38 38 * This is not to be seen by the clients of libproc.
39 39 */
40 40
41 41 #include <stdio.h>
42 42 #include <gelf.h>
43 43 #include <synch.h>
44 44 #include <procfs.h>
45 45 #include <rtld_db.h>
46 46 #include <libproc.h>
47 47 #include <libctf.h>
48 48 #include <limits.h>
49 49 #include <libproc.h>
50 50 #include <thread.h>
51 51 #include <sys/secflags.h>
52 52 #include <sys/list.h>
53 53
54 54 #ifdef __cplusplus
55 55 extern "C" {
56 56 #endif
57 57
58 58 #include "Putil.h"
59 59
60 60 /*
61 61 * Definitions of the process control structures, internal to libproc.
62 62 * These may change without affecting clients of libproc.
63 63 */
64 64
65 65 /*
66 66 * sym_tbl_t contains a primary and an (optional) auxiliary symbol table, which
67 67 * we wish to treat as a single logical symbol table. In this logical table,
68 68 * the data from the auxiliary table preceeds that from the primary. Symbol
69 69 * indices start at [0], which is the first item in the auxiliary table
70 70 * if there is one. The sole purpose for this is so that we can treat the
71 71 * combination of .SUNW_ldynsym and .dynsym sections as a logically single
72 72 * entity without having to violate the public interface to libelf.
73 73 *
74 74 * Both tables must share the same string table section.
75 75 *
76 76 * The symtab_getsym() function serves as a gelf_getsym() replacement
77 77 * that is aware of the two tables and makes them look like a single table
78 78 * to the caller.
79 79 *
80 80 */
81 81 typedef struct sym_tbl { /* symbol table */
82 82 Elf_Data *sym_data_pri; /* primary table */
83 83 Elf_Data *sym_data_aux; /* auxiliary table */
84 84 size_t sym_symn_aux; /* number of entries in auxiliary table */
85 85 size_t sym_symn; /* total number of entries in both tables */
86 86 char *sym_strs; /* ptr to strings */
87 87 size_t sym_strsz; /* size of string table */
88 88 GElf_Shdr sym_hdr_pri; /* primary symbol table section header */
89 89 GElf_Shdr sym_hdr_aux; /* auxiliary symbol table section header */
90 90 GElf_Shdr sym_strhdr; /* string table section header */
91 91 Elf *sym_elf; /* faked-up ELF handle from core file */
92 92 void *sym_elfmem; /* data for faked-up ELF handle */
93 93 uint_t *sym_byname; /* symbols sorted by name */
94 94 uint_t *sym_byaddr; /* symbols sorted by addr */
95 95 size_t sym_count; /* number of symbols in each sorted list */
96 96 } sym_tbl_t;
97 97
98 98 typedef struct file_info { /* symbol information for a mapped file */
99 99 list_node_t file_list; /* linked list */
100 100 char file_pname[PATH_MAX]; /* name from prmap_t */
101 101 struct map_info *file_map; /* primary (text) mapping */
102 102 int file_ref; /* references from map_info_t structures */
103 103 int file_fd; /* file descriptor for the mapped file */
104 104 int file_dbgfile; /* file descriptor for the debug file */
105 105 int file_init; /* 0: initialization yet to be performed */
106 106 GElf_Half file_etype; /* ELF e_type from ehdr */
107 107 GElf_Half file_class; /* ELF e_ident[EI_CLASS] from ehdr */
108 108 rd_loadobj_t *file_lo; /* load object structure from rtld_db */
109 109 char *file_lname; /* load object name from rtld_db */
110 110 char *file_lbase; /* pointer to basename of file_lname */
111 111 char *file_rname; /* resolved on-disk object pathname */
112 112 char *file_rbase; /* pointer to basename of file_rname */
113 113 Elf *file_elf; /* ELF handle so we can close */
114 114 Elf *file_dbgelf; /* Debug ELF handle so we can close */
115 115 void *file_elfmem; /* data for faked-up ELF handle */
116 116 sym_tbl_t file_symtab; /* symbol table */
117 117 sym_tbl_t file_dynsym; /* dynamic symbol table */
118 118 uintptr_t file_dyn_base; /* load address for ET_DYN files */
119 119 uintptr_t file_plt_base; /* base address for PLT */
120 120 size_t file_plt_size; /* size of PLT region */
|
↓ open down ↓ |
120 lines elided |
↑ open up ↑ |
121 121 uintptr_t file_jmp_rel; /* base address of PLT relocations */
122 122 uintptr_t file_ctf_off; /* offset of CTF data in object file */
123 123 size_t file_ctf_size; /* size of CTF data in object file */
124 124 int file_ctf_dyn; /* does the CTF data reference the dynsym */
125 125 void *file_ctf_buf; /* CTF data for this file */
126 126 ctf_file_t *file_ctfp; /* CTF container for this file */
127 127 char *file_shstrs; /* section header string table */
128 128 size_t file_shstrsz; /* section header string table size */
129 129 uintptr_t *file_saddrs; /* section header addresses */
130 130 uint_t file_nsaddrs; /* number of section header addresses */
131 + boolean_t file_cvt; /* Have we tried to convert this? */
131 132 } file_info_t;
132 133
133 134 typedef struct map_info { /* description of an address space mapping */
134 135 prmap_t map_pmap; /* /proc description of this mapping */
135 136 file_info_t *map_file; /* pointer into list of mapped files */
136 137 off64_t map_offset; /* offset into core file (if core) */
137 138 int map_relocate; /* associated file_map needs to be relocated */
138 139 } map_info_t;
139 140
140 141 typedef struct lwp_info { /* per-lwp information from core file */
141 142 list_node_t lwp_list; /* linked list */
142 143 lwpid_t lwp_id; /* lwp identifier */
143 144 lwpsinfo_t lwp_psinfo; /* /proc/<pid>/lwp/<lwpid>/lwpsinfo data */
144 145 lwpstatus_t lwp_status; /* /proc/<pid>/lwp/<lwpid>/lwpstatus data */
145 146 char lwp_name[THREAD_NAME_MAX];
146 147 prxregset_t *lwp_xregs; /* /proc/<pid>/lwp/<lwpid>/xregs data */
147 148 size_t lwp_xregsize;
148 149 #if defined(sparc) || defined(__sparc)
149 150 gwindows_t *lwp_gwins; /* /proc/<pid>/lwp/<lwpid>/gwindows data */
150 151 int64_t *lwp_asrs; /* /proc/<pid>/lwp/<lwpid>/asrs data */
151 152 #endif
152 153 } lwp_info_t;
153 154
154 155 typedef struct fd_info {
155 156 list_node_t fd_list; /* linked list */
156 157 prfdinfo_t *fd_info; /* fd info */
157 158 } fd_info_t;
158 159
159 160 typedef struct core_info { /* information specific to core files */
160 161 char core_dmodel; /* data model for core file */
161 162 char core_osabi; /* ELF OS ABI */
162 163 int core_errno; /* error during initialization if != 0 */
163 164 list_t core_lwp_head; /* head of list of lwp info */
164 165 lwp_info_t *core_lwp; /* current lwp information */
165 166 off64_t core_size; /* size of core file in bytes */
166 167 char *core_platform; /* platform string from core file */
167 168 struct utsname *core_uts; /* uname(2) data from core file */
168 169 prcred_t *core_cred; /* process credential from core file */
169 170 core_content_t core_content; /* content dumped to core file */
170 171 prpriv_t *core_priv; /* process privileges from core file */
171 172 size_t core_priv_size; /* size of the privileges */
172 173 void *core_privinfo; /* system privileges info from core file */
173 174 priv_impl_info_t *core_ppii; /* NOTE entry for core_privinfo */
174 175 char *core_zonename; /* zone name from core file */
175 176 prsecflags_t *core_secflags; /* secflags from core file */
176 177 prupanic_t *core_upanic; /* upanic from core file */
177 178 #if defined(__i386) || defined(__amd64)
178 179 struct ssd *core_ldt; /* LDT entries from core file */
179 180 uint_t core_nldt; /* number of LDT entries in core file */
180 181 #endif
181 182 } core_info_t;
182 183
183 184 typedef struct elf_file_header { /* extended ELF header */
184 185 unsigned char e_ident[EI_NIDENT];
185 186 Elf64_Half e_type;
186 187 Elf64_Half e_machine;
187 188 Elf64_Word e_version;
188 189 Elf64_Addr e_entry;
189 190 Elf64_Off e_phoff;
190 191 Elf64_Off e_shoff;
191 192 Elf64_Word e_flags;
192 193 Elf64_Half e_ehsize;
193 194 Elf64_Half e_phentsize;
194 195 Elf64_Half e_shentsize;
195 196 Elf64_Word e_phnum; /* phdr count extended to 32 bits */
196 197 Elf64_Word e_shnum; /* shdr count extended to 32 bits */
197 198 Elf64_Word e_shstrndx; /* shdr string index extended to 32 bits */
198 199 } elf_file_header_t;
199 200
200 201 typedef struct elf_file { /* convenience for managing ELF files */
201 202 elf_file_header_t e_hdr; /* Extended ELF header */
202 203 Elf *e_elf; /* ELF library handle */
203 204 int e_fd; /* file descriptor */
204 205 } elf_file_t;
205 206
206 207 #define HASHSIZE 1024 /* hash table size, power of 2 */
207 208
208 209 struct ps_prochandle {
209 210 struct ps_lwphandle **hashtab; /* hash table for LWPs (Lgrab()) */
210 211 mutex_t proc_lock; /* protects hash table; serializes Lgrab() */
211 212 pstatus_t orig_status; /* remembered status on Pgrab() */
212 213 pstatus_t status; /* status when stopped */
213 214 psinfo_t psinfo; /* psinfo_t from last Ppsinfo() request */
214 215 uintptr_t sysaddr; /* address of most recent syscall instruction */
215 216 pid_t pid; /* process-ID */
216 217 int state; /* state of the process, see "libproc.h" */
217 218 uint_t flags; /* see defines below */
218 219 uint_t agentcnt; /* Pcreate_agent()/Pdestroy_agent() ref count */
219 220 int asfd; /* /proc/<pid>/as filedescriptor */
220 221 int ctlfd; /* /proc/<pid>/ctl filedescriptor */
221 222 int statfd; /* /proc/<pid>/status filedescriptor */
222 223 int agentctlfd; /* /proc/<pid>/lwp/agent/ctl */
223 224 int agentstatfd; /* /proc/<pid>/lwp/agent/status */
224 225 int info_valid; /* if zero, map and file info need updating */
225 226 map_info_t *mappings; /* cached process mappings */
226 227 size_t map_count; /* number of mappings */
227 228 size_t map_alloc; /* number of mappings allocated */
228 229 uint_t num_files; /* number of file elements in file_info */
229 230 list_t file_head; /* head of mapped files w/ symbol table info */
230 231 char *execname; /* name of the executable file */
231 232 auxv_t *auxv; /* the process's aux vector */
232 233 int nauxv; /* number of aux vector entries */
233 234 rd_agent_t *rap; /* cookie for rtld_db */
234 235 map_info_t *map_exec; /* the mapping for the executable file */
235 236 map_info_t *map_ldso; /* the mapping for ld.so.1 */
236 237 ps_ops_t ops; /* ops-vector */
237 238 uintptr_t *ucaddrs; /* ucontext-list addresses */
238 239 uint_t ucnelems; /* number of elements in the ucaddrs list */
239 240 char *zoneroot; /* cached path to zone root */
240 241 list_t fd_head; /* head of file desc info list */
241 242 uintptr_t map_missing; /* first missing mapping in core due to sig */
242 243 siginfo_t killinfo; /* signal that interrupted core dump */
243 244 psinfo_t spymaster; /* agent LWP's spymaster, if any */
244 245 void *data; /* private data */
245 246 };
246 247
247 248 /* flags */
248 249 #define CREATED 0x01 /* process was created by Pcreate() */
249 250 #define SETSIG 0x02 /* set signal trace mask before continuing */
250 251 #define SETFAULT 0x04 /* set fault trace mask before continuing */
251 252 #define SETENTRY 0x08 /* set sysentry trace mask before continuing */
252 253 #define SETEXIT 0x10 /* set sysexit trace mask before continuing */
253 254 #define SETHOLD 0x20 /* set signal hold mask before continuing */
254 255 #define SETREGS 0x40 /* set registers before continuing */
255 256 #define INCORE 0x80 /* use in-core data to build symbol tables */
256 257
257 258 struct ps_lwphandle {
258 259 struct ps_prochandle *lwp_proc; /* process to which this lwp belongs */
259 260 struct ps_lwphandle *lwp_hash; /* hash table linked list */
260 261 lwpstatus_t lwp_status; /* status when stopped */
261 262 lwpsinfo_t lwp_psinfo; /* lwpsinfo_t from last Lpsinfo() */
262 263 lwpid_t lwp_id; /* lwp identifier */
263 264 int lwp_state; /* state of the lwp, see "libproc.h" */
264 265 uint_t lwp_flags; /* SETHOLD and/or SETREGS */
265 266 int lwp_ctlfd; /* /proc/<pid>/lwp/<lwpid>/lwpctl */
266 267 int lwp_statfd; /* /proc/<pid>/lwp/<lwpid>/lwpstatus */
267 268 };
268 269
269 270 /*
270 271 * Implementation functions in the process control library.
271 272 * These are not exported to clients of the library.
272 273 */
273 274 extern void prldump(const char *, lwpstatus_t *);
274 275 extern int dupfd(int, int);
275 276 extern int set_minfd(void);
276 277 extern int Pscantext(struct ps_prochandle *);
277 278 extern void Pinitsym(struct ps_prochandle *);
278 279 extern void Pinitfd(struct ps_prochandle *);
279 280 extern void Preadauxvec(struct ps_prochandle *);
280 281 extern void optimize_symtab(sym_tbl_t *);
281 282 extern void Pbuild_file_symtab(struct ps_prochandle *, file_info_t *);
282 283 extern ctf_file_t *Pbuild_file_ctf(struct ps_prochandle *, file_info_t *);
283 284 extern map_info_t *Paddr2mptr(struct ps_prochandle *, uintptr_t);
284 285 extern char *Pfindexec(struct ps_prochandle *, const char *,
285 286 int (*)(const char *, void *), void *);
286 287 extern int getlwpstatus(struct ps_prochandle *, lwpid_t, lwpstatus_t *);
287 288 int Pstopstatus(struct ps_prochandle *, long, uint32_t);
288 289 extern file_info_t *file_info_new(struct ps_prochandle *, map_info_t *);
289 290 extern char *Plofspath(const char *, char *, size_t);
290 291 extern char *Pzoneroot(struct ps_prochandle *, char *, size_t);
291 292 extern char *Pzonepath(struct ps_prochandle *, const char *, char *,
292 293 size_t);
293 294 extern fd_info_t *Pfd2info(struct ps_prochandle *, int);
294 295
295 296 extern char *Pfindmap(struct ps_prochandle *, map_info_t *, char *,
296 297 size_t);
297 298
298 299 extern int Padd_mapping(struct ps_prochandle *, off64_t, file_info_t *,
299 300 prmap_t *);
300 301 extern void Psort_mappings(struct ps_prochandle *);
301 302 extern struct ps_lwphandle *Lfind(struct ps_prochandle *, lwpid_t);
302 303 extern int Lstopstatus(struct ps_lwphandle *, long, uint_t);
303 304
304 305 extern char procfs_path[PATH_MAX];
305 306
306 307 /*
307 308 * Architecture-dependent definition of the breakpoint instruction.
308 309 */
309 310 #if defined(sparc) || defined(__sparc)
310 311 #define BPT ((instr_t)0x91d02001)
311 312 #elif defined(__i386) || defined(__amd64)
312 313 #define BPT ((instr_t)0xcc)
313 314 #endif
314 315
315 316 /*
316 317 * Simple convenience.
317 318 */
318 319 #define TRUE 1
319 320 #define FALSE 0
320 321
321 322 #ifdef __cplusplus
322 323 }
323 324 #endif
324 325
325 326 #endif /* _PCONTROL_H */
|
↓ open down ↓ |
185 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX