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