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