Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/dtrace/fbt.c
+++ new/usr/src/uts/intel/dtrace/fbt.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
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 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26
27 27 #include <sys/modctl.h>
28 28 #include <sys/dtrace.h>
29 29 #include <sys/kobj.h>
30 30 #include <sys/stat.h>
31 31 #include <sys/ddi.h>
32 32 #include <sys/sunddi.h>
33 33 #include <sys/conf.h>
34 34
35 35 #define FBT_PUSHL_EBP 0x55
36 36 #define FBT_MOVL_ESP_EBP0_V0 0x8b
37 37 #define FBT_MOVL_ESP_EBP1_V0 0xec
38 38 #define FBT_MOVL_ESP_EBP0_V1 0x89
39 39 #define FBT_MOVL_ESP_EBP1_V1 0xe5
40 40 #define FBT_REX_RSP_RBP 0x48
41 41
42 42 #define FBT_POPL_EBP 0x5d
43 43 #define FBT_RET 0xc3
44 44 #define FBT_RET_IMM16 0xc2
45 45 #define FBT_LEAVE 0xc9
46 46
47 47 #ifdef __amd64
48 48 #define FBT_PATCHVAL 0xcc
49 49 #else
50 50 #define FBT_PATCHVAL 0xf0
51 51 #endif
52 52
53 53 #define FBT_ENTRY "entry"
54 54 #define FBT_RETURN "return"
55 55 #define FBT_ADDR2NDX(addr) ((((uintptr_t)(addr)) >> 4) & fbt_probetab_mask)
56 56 #define FBT_PROBETAB_SIZE 0x8000 /* 32k entries -- 128K total */
57 57
58 58 typedef struct fbt_probe {
59 59 struct fbt_probe *fbtp_hashnext;
60 60 uint8_t *fbtp_patchpoint;
61 61 int8_t fbtp_rval;
62 62 uint8_t fbtp_patchval;
63 63 uint8_t fbtp_savedval;
64 64 uintptr_t fbtp_roffset;
65 65 dtrace_id_t fbtp_id;
66 66 char *fbtp_name;
67 67 struct modctl *fbtp_ctl;
68 68 int fbtp_loadcnt;
69 69 int fbtp_symndx;
70 70 int fbtp_primary;
71 71 struct fbt_probe *fbtp_next;
72 72 } fbt_probe_t;
73 73
74 74 static dev_info_t *fbt_devi;
75 75 static dtrace_provider_id_t fbt_id;
76 76 static fbt_probe_t **fbt_probetab;
77 77 static int fbt_probetab_size;
78 78 static int fbt_probetab_mask;
79 79 static int fbt_verbose = 0;
80 80
81 81 static int
82 82 fbt_invop(uintptr_t addr, uintptr_t *stack, uintptr_t rval)
83 83 {
84 84 uintptr_t stack0, stack1, stack2, stack3, stack4;
85 85 fbt_probe_t *fbt = fbt_probetab[FBT_ADDR2NDX(addr)];
86 86
87 87 for (; fbt != NULL; fbt = fbt->fbtp_hashnext) {
88 88 if ((uintptr_t)fbt->fbtp_patchpoint == addr) {
89 89 if (fbt->fbtp_roffset == 0) {
90 90 int i = 0;
91 91 /*
92 92 * When accessing the arguments on the stack,
93 93 * we must protect against accessing beyond
94 94 * the stack. We can safely set NOFAULT here
95 95 * -- we know that interrupts are already
96 96 * disabled.
97 97 */
98 98 DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
99 99 CPU->cpu_dtrace_caller = stack[i++];
100 100 #ifdef __amd64
101 101 /*
102 102 * On amd64, stack[0] contains the dereferenced
103 103 * stack pointer, stack[1] contains savfp,
104 104 * stack[2] contains savpc. We want to step
105 105 * over these entries.
106 106 */
107 107 i += 2;
108 108 #endif
109 109 stack0 = stack[i++];
110 110 stack1 = stack[i++];
111 111 stack2 = stack[i++];
112 112 stack3 = stack[i++];
113 113 stack4 = stack[i++];
114 114 DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT |
115 115 CPU_DTRACE_BADADDR);
116 116
117 117 dtrace_probe(fbt->fbtp_id, stack0, stack1,
118 118 stack2, stack3, stack4);
119 119
120 120 CPU->cpu_dtrace_caller = NULL;
121 121 } else {
122 122 #ifdef __amd64
123 123 /*
124 124 * On amd64, we instrument the ret, not the
125 125 * leave. We therefore need to set the caller
126 126 * to assure that the top frame of a stack()
127 127 * action is correct.
128 128 */
129 129 DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
130 130 CPU->cpu_dtrace_caller = stack[0];
131 131 DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT |
132 132 CPU_DTRACE_BADADDR);
133 133 #endif
134 134
135 135 dtrace_probe(fbt->fbtp_id, fbt->fbtp_roffset,
136 136 rval, 0, 0, 0);
137 137 CPU->cpu_dtrace_caller = NULL;
138 138 }
139 139
140 140 return (fbt->fbtp_rval);
141 141 }
142 142 }
143 143
144 144 return (0);
145 145 }
146 146
147 147 /*ARGSUSED*/
148 148 static void
149 149 fbt_provide_module(void *arg, struct modctl *ctl)
150 150 {
151 151 struct module *mp = ctl->mod_mp;
152 152 char *str = mp->strings;
153 153 int nsyms = mp->nsyms;
154 154 Shdr *symhdr = mp->symhdr;
155 155 char *modname = ctl->mod_modname;
156 156 char *name;
157 157 fbt_probe_t *fbt, *retfbt;
158 158 size_t symsize;
159 159 int i, size;
160 160
161 161 /*
162 162 * Employees of dtrace and their families are ineligible. Void
163 163 * where prohibited.
164 164 */
165 165 if (strcmp(modname, "dtrace") == 0)
166 166 return;
167 167
168 168 if (ctl->mod_requisites != NULL) {
169 169 struct modctl_list *list;
170 170
171 171 list = (struct modctl_list *)ctl->mod_requisites;
172 172
173 173 for (; list != NULL; list = list->modl_next) {
174 174 if (strcmp(list->modl_modp->mod_modname, "dtrace") == 0)
175 175 return;
176 176 }
177 177 }
178 178
179 179 /*
180 180 * KMDB is ineligible for instrumentation -- it may execute in
181 181 * any context, including probe context.
182 182 */
183 183 if (strcmp(modname, "kmdbmod") == 0)
184 184 return;
185 185
186 186 if (str == NULL || symhdr == NULL || symhdr->sh_addr == NULL) {
187 187 /*
188 188 * If this module doesn't (yet) have its string or symbol
189 189 * table allocated, clear out.
190 190 */
191 191 return;
192 192 }
193 193
194 194 symsize = symhdr->sh_entsize;
195 195
196 196 if (mp->fbt_nentries) {
197 197 /*
198 198 * This module has some FBT entries allocated; we're afraid
199 199 * to screw with it.
200 200 */
201 201 return;
202 202 }
203 203
204 204 for (i = 1; i < nsyms; i++) {
205 205 uint8_t *instr, *limit;
206 206 Sym *sym = (Sym *)(symhdr->sh_addr + i * symsize);
207 207 int j;
208 208
209 209 if (ELF_ST_TYPE(sym->st_info) != STT_FUNC)
210 210 continue;
211 211
212 212 /*
213 213 * Weak symbols are not candidates. This could be made to
214 214 * work (where weak functions and their underlying function
215 215 * appear as two disjoint probes), but it's not simple.
216 216 */
217 217 if (ELF_ST_BIND(sym->st_info) == STB_WEAK)
218 218 continue;
219 219
220 220 name = str + sym->st_name;
221 221
222 222 if (strstr(name, "dtrace_") == name &&
223 223 strstr(name, "dtrace_safe_") != name) {
224 224 /*
225 225 * Anything beginning with "dtrace_" may be called
226 226 * from probe context unless it explitly indicates
227 227 * that it won't be called from probe context by
228 228 * using the prefix "dtrace_safe_".
229 229 */
230 230 continue;
231 231 }
232 232
233 233 if (strstr(name, "kdi_") == name ||
234 234 strstr(name, "_kdi_") != NULL) {
235 235 /*
236 236 * Any function name beginning with "kdi_" or
237 237 * containing the string "_kdi_" is a part of the
238 238 * kernel debugger interface and may be called in
239 239 * arbitrary context -- including probe context.
240 240 */
241 241 continue;
242 242 }
243 243
244 244 /*
245 245 * Due to 4524008, _init and _fini may have a bloated st_size.
246 246 * While this bug was fixed quite some time ago, old drivers
247 247 * may be lurking. We need to develop a better solution to
248 248 * this problem, such that correct _init and _fini functions
249 249 * (the vast majority) may be correctly traced. One solution
250 250 * may be to scan through the entire symbol table to see if
251 251 * any symbol overlaps with _init. If none does, set a bit in
252 252 * the module structure that this module has correct _init and
253 253 * _fini sizes. This will cause some pain the first time a
254 254 * module is scanned, but at least it would be O(N) instead of
255 255 * O(N log N)...
256 256 */
257 257 if (strcmp(name, "_init") == 0)
258 258 continue;
259 259
260 260 if (strcmp(name, "_fini") == 0)
261 261 continue;
262 262
263 263 /*
264 264 * In order to be eligible, the function must begin with the
265 265 * following sequence:
266 266 *
267 267 * pushl %esp
268 268 * movl %esp, %ebp
269 269 *
270 270 * Note that there are two variants of encodings that generate
271 271 * the movl; we must check for both. For 64-bit, we would
272 272 * normally insist that a function begin with the following
273 273 * sequence:
274 274 *
275 275 * pushq %rbp
276 276 * movq %rsp, %rbp
277 277 *
278 278 * However, the compiler for 64-bit often splits these two
279 279 * instructions -- and the first instruction in the function
280 280 * is often not the pushq. As a result, on 64-bit we look
281 281 * for any "pushq %rbp" in the function and we instrument
282 282 * this with a breakpoint instruction.
283 283 */
284 284 instr = (uint8_t *)sym->st_value;
285 285 limit = (uint8_t *)(sym->st_value + sym->st_size);
286 286
287 287 #ifdef __amd64
288 288 while (instr < limit) {
289 289 if (*instr == FBT_PUSHL_EBP)
290 290 break;
291 291
292 292 if ((size = dtrace_instr_size(instr)) <= 0)
293 293 break;
294 294
295 295 instr += size;
296 296 }
297 297
298 298 if (instr >= limit || *instr != FBT_PUSHL_EBP) {
299 299 /*
300 300 * We either don't save the frame pointer in this
301 301 * function, or we ran into some disassembly
302 302 * screw-up. Either way, we bail.
303 303 */
304 304 continue;
305 305 }
306 306 #else
307 307 if (instr[0] != FBT_PUSHL_EBP)
308 308 continue;
309 309
310 310 if (!(instr[1] == FBT_MOVL_ESP_EBP0_V0 &&
311 311 instr[2] == FBT_MOVL_ESP_EBP1_V0) &&
312 312 !(instr[1] == FBT_MOVL_ESP_EBP0_V1 &&
313 313 instr[2] == FBT_MOVL_ESP_EBP1_V1))
314 314 continue;
315 315 #endif
316 316
317 317 fbt = kmem_zalloc(sizeof (fbt_probe_t), KM_SLEEP);
318 318 fbt->fbtp_name = name;
319 319 fbt->fbtp_id = dtrace_probe_create(fbt_id, modname,
320 320 name, FBT_ENTRY, 3, fbt);
321 321 fbt->fbtp_patchpoint = instr;
322 322 fbt->fbtp_ctl = ctl;
323 323 fbt->fbtp_loadcnt = ctl->mod_loadcnt;
324 324 fbt->fbtp_rval = DTRACE_INVOP_PUSHL_EBP;
325 325 fbt->fbtp_savedval = *instr;
326 326 fbt->fbtp_patchval = FBT_PATCHVAL;
327 327
328 328 fbt->fbtp_hashnext = fbt_probetab[FBT_ADDR2NDX(instr)];
329 329 fbt->fbtp_symndx = i;
330 330 fbt_probetab[FBT_ADDR2NDX(instr)] = fbt;
331 331
332 332 mp->fbt_nentries++;
333 333
334 334 retfbt = NULL;
335 335 again:
336 336 if (instr >= limit)
337 337 continue;
338 338
339 339 /*
340 340 * If this disassembly fails, then we've likely walked off into
341 341 * a jump table or some other unsuitable area. Bail out of the
342 342 * disassembly now.
343 343 */
344 344 if ((size = dtrace_instr_size(instr)) <= 0)
345 345 continue;
346 346
347 347 #ifdef __amd64
348 348 /*
349 349 * We only instrument "ret" on amd64 -- we don't yet instrument
350 350 * ret imm16, largely because the compiler doesn't seem to
351 351 * (yet) emit them in the kernel...
352 352 */
353 353 if (*instr != FBT_RET) {
354 354 instr += size;
355 355 goto again;
356 356 }
357 357 #else
358 358 if (!(size == 1 &&
359 359 (*instr == FBT_POPL_EBP || *instr == FBT_LEAVE) &&
360 360 (*(instr + 1) == FBT_RET ||
361 361 *(instr + 1) == FBT_RET_IMM16))) {
362 362 instr += size;
363 363 goto again;
364 364 }
365 365 #endif
366 366
367 367 /*
368 368 * We (desperately) want to avoid erroneously instrumenting a
369 369 * jump table, especially given that our markers are pretty
370 370 * short: two bytes on x86, and just one byte on amd64. To
371 371 * determine if we're looking at a true instruction sequence
372 372 * or an inline jump table that happens to contain the same
373 373 * byte sequences, we resort to some heuristic sleeze: we
374 374 * treat this instruction as being contained within a pointer,
375 375 * and see if that pointer points to within the body of the
376 376 * function. If it does, we refuse to instrument it.
377 377 */
378 378 for (j = 0; j < sizeof (uintptr_t); j++) {
379 379 uintptr_t check = (uintptr_t)instr - j;
380 380 uint8_t *ptr;
381 381
382 382 if (check < sym->st_value)
383 383 break;
384 384
385 385 if (check + sizeof (uintptr_t) > (uintptr_t)limit)
386 386 continue;
387 387
388 388 ptr = *(uint8_t **)check;
389 389
390 390 if (ptr >= (uint8_t *)sym->st_value && ptr < limit) {
391 391 instr += size;
392 392 goto again;
393 393 }
394 394 }
395 395
396 396 /*
397 397 * We have a winner!
398 398 */
399 399 fbt = kmem_zalloc(sizeof (fbt_probe_t), KM_SLEEP);
400 400 fbt->fbtp_name = name;
401 401
402 402 if (retfbt == NULL) {
403 403 fbt->fbtp_id = dtrace_probe_create(fbt_id, modname,
404 404 name, FBT_RETURN, 3, fbt);
405 405 } else {
406 406 retfbt->fbtp_next = fbt;
407 407 fbt->fbtp_id = retfbt->fbtp_id;
408 408 }
409 409
410 410 retfbt = fbt;
411 411 fbt->fbtp_patchpoint = instr;
412 412 fbt->fbtp_ctl = ctl;
413 413 fbt->fbtp_loadcnt = ctl->mod_loadcnt;
414 414
415 415 #ifndef __amd64
416 416 if (*instr == FBT_POPL_EBP) {
417 417 fbt->fbtp_rval = DTRACE_INVOP_POPL_EBP;
418 418 } else {
419 419 ASSERT(*instr == FBT_LEAVE);
420 420 fbt->fbtp_rval = DTRACE_INVOP_LEAVE;
421 421 }
422 422 fbt->fbtp_roffset =
423 423 (uintptr_t)(instr - (uint8_t *)sym->st_value) + 1;
424 424
425 425 #else
426 426 ASSERT(*instr == FBT_RET);
427 427 fbt->fbtp_rval = DTRACE_INVOP_RET;
428 428 fbt->fbtp_roffset =
429 429 (uintptr_t)(instr - (uint8_t *)sym->st_value);
430 430 #endif
431 431
432 432 fbt->fbtp_savedval = *instr;
433 433 fbt->fbtp_patchval = FBT_PATCHVAL;
434 434 fbt->fbtp_hashnext = fbt_probetab[FBT_ADDR2NDX(instr)];
435 435 fbt->fbtp_symndx = i;
436 436 fbt_probetab[FBT_ADDR2NDX(instr)] = fbt;
437 437
438 438 mp->fbt_nentries++;
439 439
440 440 instr += size;
441 441 goto again;
442 442 }
443 443 }
444 444
445 445 /*ARGSUSED*/
446 446 static void
447 447 fbt_destroy(void *arg, dtrace_id_t id, void *parg)
448 448 {
449 449 fbt_probe_t *fbt = parg, *next, *hash, *last;
450 450 struct modctl *ctl = fbt->fbtp_ctl;
451 451 int ndx;
452 452
453 453 do {
454 454 if (ctl != NULL && ctl->mod_loadcnt == fbt->fbtp_loadcnt) {
455 455 if ((ctl->mod_loadcnt == fbt->fbtp_loadcnt &&
456 456 ctl->mod_loaded)) {
457 457 ((struct module *)
458 458 (ctl->mod_mp))->fbt_nentries--;
459 459 }
460 460 }
461 461
462 462 /*
463 463 * Now we need to remove this probe from the fbt_probetab.
464 464 */
465 465 ndx = FBT_ADDR2NDX(fbt->fbtp_patchpoint);
466 466 last = NULL;
467 467 hash = fbt_probetab[ndx];
468 468
469 469 while (hash != fbt) {
470 470 ASSERT(hash != NULL);
471 471 last = hash;
472 472 hash = hash->fbtp_hashnext;
473 473 }
474 474
475 475 if (last != NULL) {
476 476 last->fbtp_hashnext = fbt->fbtp_hashnext;
477 477 } else {
478 478 fbt_probetab[ndx] = fbt->fbtp_hashnext;
479 479 }
480 480
481 481 next = fbt->fbtp_next;
482 482 kmem_free(fbt, sizeof (fbt_probe_t));
483 483
484 484 fbt = next;
485 485 } while (fbt != NULL);
486 486 }
487 487
488 488 /*ARGSUSED*/
489 489 static int
490 490 fbt_enable(void *arg, dtrace_id_t id, void *parg)
491 491 {
492 492 fbt_probe_t *fbt = parg;
493 493 struct modctl *ctl = fbt->fbtp_ctl;
494 494
495 495 ctl->mod_nenabled++;
496 496
497 497 if (!ctl->mod_loaded) {
498 498 if (fbt_verbose) {
499 499 cmn_err(CE_NOTE, "fbt is failing for probe %s "
500 500 "(module %s unloaded)",
501 501 fbt->fbtp_name, ctl->mod_modname);
502 502 }
503 503
504 504 return (0);
505 505 }
506 506
507 507 /*
508 508 * Now check that our modctl has the expected load count. If it
509 509 * doesn't, this module must have been unloaded and reloaded -- and
510 510 * we're not going to touch it.
511 511 */
512 512 if (ctl->mod_loadcnt != fbt->fbtp_loadcnt) {
513 513 if (fbt_verbose) {
514 514 cmn_err(CE_NOTE, "fbt is failing for probe %s "
515 515 "(module %s reloaded)",
516 516 fbt->fbtp_name, ctl->mod_modname);
517 517 }
518 518
519 519 return (0);
520 520 }
521 521
522 522 for (; fbt != NULL; fbt = fbt->fbtp_next)
523 523 *fbt->fbtp_patchpoint = fbt->fbtp_patchval;
524 524
525 525 return (0);
526 526 }
527 527
528 528 /*ARGSUSED*/
529 529 static void
530 530 fbt_disable(void *arg, dtrace_id_t id, void *parg)
531 531 {
532 532 fbt_probe_t *fbt = parg;
533 533 struct modctl *ctl = fbt->fbtp_ctl;
534 534
535 535 ASSERT(ctl->mod_nenabled > 0);
536 536 ctl->mod_nenabled--;
537 537
538 538 if (!ctl->mod_loaded || (ctl->mod_loadcnt != fbt->fbtp_loadcnt))
539 539 return;
540 540
541 541 for (; fbt != NULL; fbt = fbt->fbtp_next)
542 542 *fbt->fbtp_patchpoint = fbt->fbtp_savedval;
543 543 }
544 544
545 545 /*ARGSUSED*/
546 546 static void
547 547 fbt_suspend(void *arg, dtrace_id_t id, void *parg)
548 548 {
549 549 fbt_probe_t *fbt = parg;
550 550 struct modctl *ctl = fbt->fbtp_ctl;
551 551
552 552 ASSERT(ctl->mod_nenabled > 0);
553 553
554 554 if (!ctl->mod_loaded || (ctl->mod_loadcnt != fbt->fbtp_loadcnt))
555 555 return;
556 556
557 557 for (; fbt != NULL; fbt = fbt->fbtp_next)
558 558 *fbt->fbtp_patchpoint = fbt->fbtp_savedval;
559 559 }
560 560
561 561 /*ARGSUSED*/
562 562 static void
563 563 fbt_resume(void *arg, dtrace_id_t id, void *parg)
564 564 {
565 565 fbt_probe_t *fbt = parg;
566 566 struct modctl *ctl = fbt->fbtp_ctl;
567 567
568 568 ASSERT(ctl->mod_nenabled > 0);
569 569
570 570 if (!ctl->mod_loaded || (ctl->mod_loadcnt != fbt->fbtp_loadcnt))
571 571 return;
572 572
573 573 for (; fbt != NULL; fbt = fbt->fbtp_next)
574 574 *fbt->fbtp_patchpoint = fbt->fbtp_patchval;
575 575 }
576 576
577 577 /*ARGSUSED*/
578 578 static void
579 579 fbt_getargdesc(void *arg, dtrace_id_t id, void *parg, dtrace_argdesc_t *desc)
580 580 {
581 581 fbt_probe_t *fbt = parg;
582 582 struct modctl *ctl = fbt->fbtp_ctl;
583 583 struct module *mp = ctl->mod_mp;
584 584 ctf_file_t *fp = NULL, *pfp;
585 585 ctf_funcinfo_t f;
586 586 int error;
587 587 ctf_id_t argv[32], type;
588 588 int argc = sizeof (argv) / sizeof (ctf_id_t);
589 589 const char *parent;
590 590
591 591 if (!ctl->mod_loaded || (ctl->mod_loadcnt != fbt->fbtp_loadcnt))
592 592 goto err;
593 593
594 594 if (fbt->fbtp_roffset != 0 && desc->dtargd_ndx == 0) {
595 595 (void) strcpy(desc->dtargd_native, "int");
596 596 return;
597 597 }
598 598
599 599 if ((fp = ctf_modopen(mp, &error)) == NULL) {
600 600 /*
601 601 * We have no CTF information for this module -- and therefore
602 602 * no args[] information.
603 603 */
604 604 goto err;
605 605 }
606 606
607 607 /*
608 608 * If we have a parent container, we must manually import it.
609 609 */
610 610 if ((parent = ctf_parent_name(fp)) != NULL) {
611 611 struct modctl *mp = &modules;
612 612 struct modctl *mod = NULL;
613 613
614 614 /*
615 615 * We must iterate over all modules to find the module that
616 616 * is our parent.
617 617 */
618 618 do {
619 619 if (strcmp(mp->mod_modname, parent) == 0) {
620 620 mod = mp;
621 621 break;
622 622 }
623 623 } while ((mp = mp->mod_next) != &modules);
624 624
625 625 if (mod == NULL)
626 626 goto err;
627 627
628 628 if ((pfp = ctf_modopen(mod->mod_mp, &error)) == NULL) {
629 629 goto err;
630 630 }
631 631
632 632 if (ctf_import(fp, pfp) != 0) {
633 633 ctf_close(pfp);
634 634 goto err;
635 635 }
636 636
637 637 ctf_close(pfp);
638 638 }
639 639
640 640 if (ctf_func_info(fp, fbt->fbtp_symndx, &f) == CTF_ERR)
641 641 goto err;
642 642
643 643 if (fbt->fbtp_roffset != 0) {
644 644 if (desc->dtargd_ndx > 1)
645 645 goto err;
646 646
647 647 ASSERT(desc->dtargd_ndx == 1);
648 648 type = f.ctc_return;
649 649 } else {
650 650 if (desc->dtargd_ndx + 1 > f.ctc_argc)
651 651 goto err;
652 652
653 653 if (ctf_func_args(fp, fbt->fbtp_symndx, argc, argv) == CTF_ERR)
654 654 goto err;
655 655
656 656 type = argv[desc->dtargd_ndx];
657 657 }
658 658
659 659 if (ctf_type_name(fp, type, desc->dtargd_native,
660 660 DTRACE_ARGTYPELEN) != NULL) {
661 661 ctf_close(fp);
662 662 return;
663 663 }
664 664 err:
665 665 if (fp != NULL)
666 666 ctf_close(fp);
667 667
668 668 desc->dtargd_ndx = DTRACE_ARGNONE;
669 669 }
670 670
671 671 static dtrace_pattr_t fbt_attr = {
672 672 { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
673 673 { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
674 674 { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
675 675 { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
676 676 { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
677 677 };
678 678
679 679 static dtrace_pops_t fbt_pops = {
680 680 NULL,
681 681 fbt_provide_module,
682 682 fbt_enable,
683 683 fbt_disable,
684 684 fbt_suspend,
685 685 fbt_resume,
686 686 fbt_getargdesc,
687 687 NULL,
688 688 NULL,
689 689 fbt_destroy
690 690 };
691 691
692 692 static void
693 693 fbt_cleanup(dev_info_t *devi)
694 694 {
695 695 dtrace_invop_remove(fbt_invop);
696 696 ddi_remove_minor_node(devi, NULL);
697 697 kmem_free(fbt_probetab, fbt_probetab_size * sizeof (fbt_probe_t *));
698 698 fbt_probetab = NULL;
699 699 fbt_probetab_mask = 0;
700 700 }
701 701
702 702 static int
703 703 fbt_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
704 704 {
705 705 switch (cmd) {
706 706 case DDI_ATTACH:
707 707 break;
708 708 case DDI_RESUME:
709 709 return (DDI_SUCCESS);
710 710 default:
711 711 return (DDI_FAILURE);
712 712 }
713 713
714 714 if (fbt_probetab_size == 0)
715 715 fbt_probetab_size = FBT_PROBETAB_SIZE;
716 716
717 717 fbt_probetab_mask = fbt_probetab_size - 1;
718 718 fbt_probetab =
719 719 kmem_zalloc(fbt_probetab_size * sizeof (fbt_probe_t *), KM_SLEEP);
720 720
721 721 dtrace_invop_add(fbt_invop);
722 722
723 723 if (ddi_create_minor_node(devi, "fbt", S_IFCHR, 0,
724 724 DDI_PSEUDO, NULL) == DDI_FAILURE ||
725 725 dtrace_register("fbt", &fbt_attr, DTRACE_PRIV_KERNEL, NULL,
726 726 &fbt_pops, NULL, &fbt_id) != 0) {
727 727 fbt_cleanup(devi);
728 728 return (DDI_FAILURE);
729 729 }
730 730
731 731 ddi_report_dev(devi);
732 732 fbt_devi = devi;
733 733
734 734 return (DDI_SUCCESS);
735 735 }
736 736
737 737 static int
738 738 fbt_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
739 739 {
740 740 switch (cmd) {
741 741 case DDI_DETACH:
742 742 break;
743 743 case DDI_SUSPEND:
744 744 return (DDI_SUCCESS);
745 745 default:
746 746 return (DDI_FAILURE);
747 747 }
748 748
749 749 if (dtrace_unregister(fbt_id) != 0)
750 750 return (DDI_FAILURE);
751 751
752 752 fbt_cleanup(devi);
753 753
754 754 return (DDI_SUCCESS);
755 755 }
756 756
757 757 /*ARGSUSED*/
758 758 static int
759 759 fbt_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
760 760 {
761 761 int error;
762 762
763 763 switch (infocmd) {
764 764 case DDI_INFO_DEVT2DEVINFO:
765 765 *result = (void *)fbt_devi;
766 766 error = DDI_SUCCESS;
767 767 break;
768 768 case DDI_INFO_DEVT2INSTANCE:
769 769 *result = (void *)0;
770 770 error = DDI_SUCCESS;
771 771 break;
772 772 default:
773 773 error = DDI_FAILURE;
774 774 }
775 775 return (error);
776 776 }
777 777
778 778 /*ARGSUSED*/
779 779 static int
780 780 fbt_open(dev_t *devp, int flag, int otyp, cred_t *cred_p)
781 781 {
782 782 return (0);
783 783 }
784 784
785 785 static struct cb_ops fbt_cb_ops = {
786 786 fbt_open, /* open */
787 787 nodev, /* close */
788 788 nulldev, /* strategy */
789 789 nulldev, /* print */
790 790 nodev, /* dump */
791 791 nodev, /* read */
792 792 nodev, /* write */
793 793 nodev, /* ioctl */
794 794 nodev, /* devmap */
795 795 nodev, /* mmap */
796 796 nodev, /* segmap */
797 797 nochpoll, /* poll */
798 798 ddi_prop_op, /* cb_prop_op */
799 799 0, /* streamtab */
800 800 D_NEW | D_MP /* Driver compatibility flag */
801 801 };
802 802
803 803 static struct dev_ops fbt_ops = {
804 804 DEVO_REV, /* devo_rev */
805 805 0, /* refcnt */
806 806 fbt_info, /* get_dev_info */
807 807 nulldev, /* identify */
808 808 nulldev, /* probe */
809 809 fbt_attach, /* attach */
810 810 fbt_detach, /* detach */
811 811 nodev, /* reset */
812 812 &fbt_cb_ops, /* driver operations */
813 813 NULL, /* bus operations */
814 814 nodev, /* dev power */
815 815 ddi_quiesce_not_needed, /* quiesce */
816 816 };
817 817
818 818 /*
↓ open down ↓ |
818 lines elided |
↑ open up ↑ |
819 819 * Module linkage information for the kernel.
820 820 */
821 821 static struct modldrv modldrv = {
822 822 &mod_driverops, /* module type (this is a pseudo driver) */
823 823 "Function Boundary Tracing", /* name of module */
824 824 &fbt_ops, /* driver ops */
825 825 };
826 826
827 827 static struct modlinkage modlinkage = {
828 828 MODREV_1,
829 - (void *)&modldrv,
830 - NULL
829 + { (void *)&modldrv, NULL }
831 830 };
832 831
833 832 int
834 833 _init(void)
835 834 {
836 835 return (mod_install(&modlinkage));
837 836 }
838 837
839 838 int
840 839 _info(struct modinfo *modinfop)
841 840 {
842 841 return (mod_info(&modlinkage, modinfop));
843 842 }
844 843
845 844 int
846 845 _fini(void)
847 846 {
848 847 return (mod_remove(&modlinkage));
849 848 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX