Print this page
XXX AVX procfs
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libproc/common/Pservice.c
+++ new/usr/src/lib/libproc/common/Pservice.c
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
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
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 2006 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 -#pragma ident "%Z%%M% %I% %E% SMI"
27 -
28 26 #include <stdarg.h>
29 27 #include <string.h>
30 28 #include "Pcontrol.h"
31 29
32 30 /*
33 31 * This file implements the process services declared in <proc_service.h>.
34 32 * This enables libproc to be used in conjunction with libc_db and
35 33 * librtld_db. As most of these facilities are already provided by
36 34 * (more elegant) interfaces in <libproc.h>, we can just call those.
37 35 *
38 36 * NOTE: We explicitly do *not* implement the functions ps_kill() and
39 37 * ps_lrolltoaddr() in this library. The very existence of these functions
40 38 * causes libc_db to create an "agent thread" in the target process.
41 39 * The only way to turn off this behavior is to omit these functions.
42 40 */
43 41
44 42 #pragma weak ps_pdread = ps_pread
45 43 #pragma weak ps_ptread = ps_pread
46 44 #pragma weak ps_pdwrite = ps_pwrite
47 45 #pragma weak ps_ptwrite = ps_pwrite
48 46
49 47 ps_err_e
50 48 ps_pdmodel(struct ps_prochandle *P, int *modelp)
51 49 {
52 50 *modelp = P->status.pr_dmodel;
53 51 return (PS_OK);
54 52 }
55 53
56 54 ps_err_e
57 55 ps_pread(struct ps_prochandle *P, psaddr_t addr, void *buf, size_t size)
58 56 {
59 57 if (P->ops->p_pread(P, buf, size, addr) != size)
60 58 return (PS_BADADDR);
61 59 return (PS_OK);
62 60 }
63 61
64 62 ps_err_e
65 63 ps_pwrite(struct ps_prochandle *P, psaddr_t addr, const void *buf, size_t size)
66 64 {
67 65 if (P->ops->p_pwrite(P, buf, size, addr) != size)
68 66 return (PS_BADADDR);
69 67 return (PS_OK);
70 68 }
71 69
72 70 /*
73 71 * libc_db calls matched pairs of ps_pstop()/ps_pcontinue()
74 72 * in the belief that the client may have left the process
75 73 * running while calling in to the libc_db interfaces.
76 74 *
77 75 * We interpret the meaning of these functions to be an inquiry
78 76 * as to whether the process is stopped, not an action to be
79 77 * performed to make it stopped. For similar reasons, we also
80 78 * return PS_OK for core files in order to allow libc_db to
81 79 * operate on these as well.
82 80 */
83 81 ps_err_e
84 82 ps_pstop(struct ps_prochandle *P)
85 83 {
86 84 if (P->state != PS_STOP && P->state != PS_DEAD)
87 85 return (PS_ERR);
88 86 return (PS_OK);
89 87 }
90 88
91 89 ps_err_e
92 90 ps_pcontinue(struct ps_prochandle *P)
93 91 {
94 92 if (P->state != PS_STOP && P->state != PS_DEAD)
95 93 return (PS_ERR);
96 94 return (PS_OK);
97 95 }
98 96
99 97 /*
100 98 * ps_lstop() and ps_lcontinue() are not called by any code in libc_db
101 99 * or librtld_db. We make them behave like ps_pstop() and ps_pcontinue().
102 100 */
103 101 /* ARGSUSED1 */
104 102 ps_err_e
105 103 ps_lstop(struct ps_prochandle *P, lwpid_t lwpid)
106 104 {
107 105 if (P->state != PS_STOP && P->state != PS_DEAD)
108 106 return (PS_ERR);
109 107 return (PS_OK);
110 108 }
111 109
112 110 /* ARGSUSED1 */
113 111 ps_err_e
114 112 ps_lcontinue(struct ps_prochandle *P, lwpid_t lwpid)
115 113 {
116 114 if (P->state != PS_STOP && P->state != PS_DEAD)
117 115 return (PS_ERR);
118 116 return (PS_OK);
119 117 }
120 118
121 119 ps_err_e
122 120 ps_lgetregs(struct ps_prochandle *P, lwpid_t lwpid, prgregset_t regs)
123 121 {
124 122 if (P->state != PS_STOP && P->state != PS_DEAD)
125 123 return (PS_ERR);
126 124
127 125 if (Plwp_getregs(P, lwpid, regs) == 0)
128 126 return (PS_OK);
129 127
130 128 return (PS_BADLID);
131 129 }
132 130
133 131 ps_err_e
134 132 ps_lsetregs(struct ps_prochandle *P, lwpid_t lwpid, const prgregset_t regs)
135 133 {
136 134 if (P->state != PS_STOP)
137 135 return (PS_ERR);
138 136
139 137 if (Plwp_setregs(P, lwpid, regs) == 0)
140 138 return (PS_OK);
141 139
142 140 return (PS_BADLID);
143 141 }
144 142
145 143 ps_err_e
146 144 ps_lgetfpregs(struct ps_prochandle *P, lwpid_t lwpid, prfpregset_t *regs)
147 145 {
148 146 if (P->state != PS_STOP && P->state != PS_DEAD)
149 147 return (PS_ERR);
150 148
151 149 if (Plwp_getfpregs(P, lwpid, regs) == 0)
152 150 return (PS_OK);
153 151
154 152 return (PS_BADLID);
155 153 }
156 154
157 155 ps_err_e
158 156 ps_lsetfpregs(struct ps_prochandle *P, lwpid_t lwpid, const prfpregset_t *regs)
↓ open down ↓ |
121 lines elided |
↑ open up ↑ |
159 157 {
160 158 if (P->state != PS_STOP)
161 159 return (PS_ERR);
162 160
163 161 if (Plwp_setfpregs(P, lwpid, regs) == 0)
164 162 return (PS_OK);
165 163
166 164 return (PS_BADLID);
167 165 }
168 166
169 -#if defined(sparc) || defined(__sparc)
170 -
171 167 ps_err_e
172 168 ps_lgetxregsize(struct ps_prochandle *P, lwpid_t lwpid, int *xrsize)
173 169 {
174 170 char fname[PATH_MAX];
175 171 struct stat statb;
176 172
177 173 if (P->state == PS_DEAD) {
178 174 lwp_info_t *lwp = list_next(&P->core->core_lwp_head);
179 175 uint_t i;
180 176
181 177 for (i = 0; i < P->core->core_nlwp; i++, lwp = list_next(lwp)) {
182 178 if (lwp->lwp_id == lwpid) {
183 179 if (lwp->lwp_xregs != NULL)
184 180 *xrsize = sizeof (prxregset_t);
185 181 else
186 182 *xrsize = 0;
187 183 return (PS_OK);
188 184 }
189 185 }
190 186
191 187 return (PS_BADLID);
192 188 }
193 189
194 190 (void) snprintf(fname, sizeof (fname), "%s/%d/lwp/%d/xregs",
195 191 procfs_path, (int)P->status.pr_pid, (int)lwpid);
196 192
197 193 if (stat(fname, &statb) != 0)
198 194 return (PS_BADLID);
199 195
200 196 *xrsize = (int)statb.st_size;
201 197 return (PS_OK);
202 198 }
203 199
204 200 ps_err_e
205 201 ps_lgetxregs(struct ps_prochandle *P, lwpid_t lwpid, caddr_t xregs)
206 202 {
207 203 if (P->state != PS_STOP && P->state != PS_DEAD)
208 204 return (PS_ERR);
209 205
210 206 /* LINTED - alignment */
211 207 if (Plwp_getxregs(P, lwpid, (prxregset_t *)xregs) == 0)
212 208 return (PS_OK);
213 209
214 210 return (PS_BADLID);
215 211 }
216 212
217 213 ps_err_e
218 214 ps_lsetxregs(struct ps_prochandle *P, lwpid_t lwpid, caddr_t xregs)
219 215 {
↓ open down ↓ |
39 lines elided |
↑ open up ↑ |
220 216 if (P->state != PS_STOP)
221 217 return (PS_ERR);
222 218
223 219 /* LINTED - alignment */
224 220 if (Plwp_setxregs(P, lwpid, (prxregset_t *)xregs) == 0)
225 221 return (PS_OK);
226 222
227 223 return (PS_BADLID);
228 224 }
229 225
230 -#endif /* sparc */
231 -
232 226 #if defined(__i386) || defined(__amd64)
233 227
234 228 ps_err_e
235 229 ps_lgetLDT(struct ps_prochandle *P, lwpid_t lwpid, struct ssd *ldt)
236 230 {
237 231 #if defined(__amd64) && defined(_LP64)
238 232 if (P->status.pr_dmodel != PR_MODEL_NATIVE) {
239 233 #endif
240 234 prgregset_t regs;
241 235 struct ssd *ldtarray;
242 236 ps_err_e error;
243 237 uint_t gs;
244 238 int nldt;
245 239 int i;
246 240
247 241 if (P->state != PS_STOP && P->state != PS_DEAD)
248 242 return (PS_ERR);
249 243
250 244 /*
251 245 * We need to get the ldt entry that matches the
252 246 * value in the lwp's GS register.
253 247 */
254 248 if ((error = ps_lgetregs(P, lwpid, regs)) != PS_OK)
255 249 return (error);
256 250
257 251 gs = regs[GS];
258 252
259 253 if ((nldt = Pldt(P, NULL, 0)) <= 0 ||
260 254 (ldtarray = malloc(nldt * sizeof (struct ssd))) == NULL)
261 255 return (PS_ERR);
262 256 if ((nldt = Pldt(P, ldtarray, nldt)) <= 0) {
263 257 free(ldtarray);
264 258 return (PS_ERR);
265 259 }
266 260
267 261 for (i = 0; i < nldt; i++) {
268 262 if (gs == ldtarray[i].sel) {
269 263 *ldt = ldtarray[i];
270 264 break;
271 265 }
272 266 }
273 267 free(ldtarray);
274 268
275 269 if (i < nldt)
276 270 return (PS_OK);
277 271 #if defined(__amd64) && defined(_LP64)
278 272 }
279 273 #endif
280 274
281 275 return (PS_ERR);
282 276 }
283 277
284 278 #endif /* __i386 || __amd64 */
285 279
286 280 /*
287 281 * Libthread_db doesn't use this function currently, but librtld_db uses
288 282 * it for its debugging output. We turn this on via rd_log if our debugging
289 283 * switch is on, and then echo the messages sent to ps_plog to stderr.
290 284 */
291 285 void
292 286 ps_plog(const char *fmt, ...)
293 287 {
294 288 va_list ap;
295 289
296 290 if (_libproc_debug && fmt != NULL && *fmt != '\0') {
297 291 va_start(ap, fmt);
298 292 (void) vfprintf(stderr, fmt, ap);
299 293 va_end(ap);
300 294 if (fmt[strlen(fmt) - 1] != '\n')
301 295 (void) fputc('\n', stderr);
302 296 }
303 297 }
304 298
305 299 /*
306 300 * Store a pointer to our internal copy of the aux vector at the address
307 301 * specified by the caller. It should not hold on to this data for too long.
308 302 */
309 303 ps_err_e
310 304 ps_pauxv(struct ps_prochandle *P, const auxv_t **aux)
311 305 {
312 306 if (P->auxv == NULL)
313 307 Preadauxvec(P);
314 308
315 309 if (P->auxv == NULL)
316 310 return (PS_ERR);
317 311
318 312 *aux = (const auxv_t *)P->auxv;
319 313 return (PS_OK);
320 314 }
321 315
322 316 ps_err_e
323 317 ps_pbrandname(struct ps_prochandle *P, char *buf, size_t len)
324 318 {
325 319 return (Pbrandname(P, buf, len) ? PS_OK : PS_ERR);
326 320 }
327 321
328 322 /*
329 323 * Search for a symbol by name and return the corresponding address.
330 324 */
331 325 ps_err_e
332 326 ps_pglobal_lookup(struct ps_prochandle *P, const char *object_name,
333 327 const char *sym_name, psaddr_t *sym_addr)
334 328 {
335 329 GElf_Sym sym;
336 330
337 331 if (Plookup_by_name(P, object_name, sym_name, &sym) == 0) {
338 332 dprintf("pglobal_lookup <%s> -> %p\n",
339 333 sym_name, (void *)(uintptr_t)sym.st_value);
340 334 *sym_addr = (psaddr_t)sym.st_value;
341 335 return (PS_OK);
342 336 }
343 337
344 338 return (PS_NOSYM);
345 339 }
346 340
347 341 /*
348 342 * Search for a symbol by name and return the corresponding symbol
349 343 * information. If we're compiled _LP64, we just call Plookup_by_name
350 344 * and return because ps_sym_t is defined to be an Elf64_Sym, which
351 345 * is the same as a GElf_Sym. In the _ILP32 case, we have to convert
352 346 * Plookup_by_name's result back to a ps_sym_t (which is an Elf32_Sym).
353 347 */
354 348 ps_err_e
355 349 ps_pglobal_sym(struct ps_prochandle *P, const char *object_name,
356 350 const char *sym_name, ps_sym_t *symp)
357 351 {
358 352 #if defined(_ILP32)
359 353 GElf_Sym sym;
360 354
361 355 if (Plookup_by_name(P, object_name, sym_name, &sym) == 0) {
362 356 symp->st_name = (Elf32_Word)sym.st_name;
363 357 symp->st_value = (Elf32_Addr)sym.st_value;
364 358 symp->st_size = (Elf32_Word)sym.st_size;
365 359 symp->st_info = ELF32_ST_INFO(
366 360 GELF_ST_BIND(sym.st_info), GELF_ST_TYPE(sym.st_info));
367 361 symp->st_other = sym.st_other;
368 362 symp->st_shndx = sym.st_shndx;
369 363 return (PS_OK);
370 364 }
371 365
372 366 #elif defined(_LP64)
373 367 if (Plookup_by_name(P, object_name, sym_name, symp) == 0)
374 368 return (PS_OK);
375 369 #endif
376 370 return (PS_NOSYM);
377 371 }
↓ open down ↓ |
136 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX