4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * #pragma ident "@(#)fasttrap_isa.c 1.27 08/04/09 SMI"
33 #define _KERNEL /* Solaris vs. Darwin */
37 #include <sys/fasttrap_isa.h>
38 #include <sys/fasttrap_impl.h>
39 #include <sys/dtrace.h>
40 #include <sys/dtrace_impl.h>
41 extern dtrace_id_t dtrace_probeid_error
;
43 #include "fasttrap_regset.h"
45 #include <sys/dtrace_ptss.h>
46 #include <kern/debug.h>
48 /* Solaris proc_t is the struct. Darwin's proc_t is a pointer to it. */
49 #define proc_t struct proc /* Steer clear of the Darwin typedef for proc_t */
52 * Lossless User-Land Tracing on x86
53 * ---------------------------------
55 * The execution of most instructions is not dependent on the address; for
56 * these instructions it is sufficient to copy them into the user process's
57 * address space and execute them. To effectively single-step an instruction
58 * in user-land, we copy out the following sequence of instructions to scratch
59 * space in the user thread's ulwp_t structure.
61 * We then set the program counter (%eip or %rip) to point to this scratch
62 * space. Once execution resumes, the original instruction is executed and
63 * then control flow is redirected to what was originally the subsequent
64 * instruction. If the kernel attemps to deliver a signal while single-
65 * stepping, the signal is deferred and the program counter is moved into the
66 * second sequence of instructions. The second sequence ends in a trap into
67 * the kernel where the deferred signal is then properly handled and delivered.
69 * For instructions whose execute is position dependent, we perform simple
70 * emulation. These instructions are limited to control transfer
71 * instructions in 32-bit mode, but in 64-bit mode there's the added wrinkle
72 * of %rip-relative addressing that means that almost any instruction can be
73 * position dependent. For all the details on how we emulate generic
74 * instructions included %rip-relative instructions, see the code in
75 * fasttrap_pid_probe() below where we handle instructions of type
76 * FASTTRAP_T_COMMON (under the header: Generic Instruction Tracing).
79 #define FASTTRAP_MODRM_MOD(modrm) (((modrm) >> 6) & 0x3)
80 #define FASTTRAP_MODRM_REG(modrm) (((modrm) >> 3) & 0x7)
81 #define FASTTRAP_MODRM_RM(modrm) ((modrm) & 0x7)
82 #define FASTTRAP_MODRM(mod, reg, rm) (((mod) << 6) | ((reg) << 3) | (rm))
84 #define FASTTRAP_SIB_SCALE(sib) (((sib) >> 6) & 0x3)
85 #define FASTTRAP_SIB_INDEX(sib) (((sib) >> 3) & 0x7)
86 #define FASTTRAP_SIB_BASE(sib) ((sib) & 0x7)
88 #define FASTTRAP_REX_W(rex) (((rex) >> 3) & 1)
89 #define FASTTRAP_REX_R(rex) (((rex) >> 2) & 1)
90 #define FASTTRAP_REX_X(rex) (((rex) >> 1) & 1)
91 #define FASTTRAP_REX_B(rex) ((rex) & 1)
92 #define FASTTRAP_REX(w, r, x, b) \
93 (0x40 | ((w) << 3) | ((r) << 2) | ((x) << 1) | (b))
96 * Single-byte op-codes.
98 #define FASTTRAP_PUSHL_EBP 0x55
100 #define FASTTRAP_JO 0x70
101 #define FASTTRAP_JNO 0x71
102 #define FASTTRAP_JB 0x72
103 #define FASTTRAP_JAE 0x73
104 #define FASTTRAP_JE 0x74
105 #define FASTTRAP_JNE 0x75
106 #define FASTTRAP_JBE 0x76
107 #define FASTTRAP_JA 0x77
108 #define FASTTRAP_JS 0x78
109 #define FASTTRAP_JNS 0x79
110 #define FASTTRAP_JP 0x7a
111 #define FASTTRAP_JNP 0x7b
112 #define FASTTRAP_JL 0x7c
113 #define FASTTRAP_JGE 0x7d
114 #define FASTTRAP_JLE 0x7e
115 #define FASTTRAP_JG 0x7f
117 #define FASTTRAP_NOP 0x90
119 #define FASTTRAP_MOV_EAX 0xb8
120 #define FASTTRAP_MOV_ECX 0xb9
122 #define FASTTRAP_RET16 0xc2
123 #define FASTTRAP_RET 0xc3
125 #define FASTTRAP_LOOPNZ 0xe0
126 #define FASTTRAP_LOOPZ 0xe1
127 #define FASTTRAP_LOOP 0xe2
128 #define FASTTRAP_JCXZ 0xe3
130 #define FASTTRAP_CALL 0xe8
131 #define FASTTRAP_JMP32 0xe9
132 #define FASTTRAP_JMP8 0xeb
134 #define FASTTRAP_INT3 0xcc
135 #define FASTTRAP_INT 0xcd
136 #define T_DTRACE_RET 0x7f
138 #define FASTTRAP_2_BYTE_OP 0x0f
139 #define FASTTRAP_GROUP5_OP 0xff
142 * Two-byte op-codes (second byte only).
144 #define FASTTRAP_0F_JO 0x80
145 #define FASTTRAP_0F_JNO 0x81
146 #define FASTTRAP_0F_JB 0x82
147 #define FASTTRAP_0F_JAE 0x83
148 #define FASTTRAP_0F_JE 0x84
149 #define FASTTRAP_0F_JNE 0x85
150 #define FASTTRAP_0F_JBE 0x86
151 #define FASTTRAP_0F_JA 0x87
152 #define FASTTRAP_0F_JS 0x88
153 #define FASTTRAP_0F_JNS 0x89
154 #define FASTTRAP_0F_JP 0x8a
155 #define FASTTRAP_0F_JNP 0x8b
156 #define FASTTRAP_0F_JL 0x8c
157 #define FASTTRAP_0F_JGE 0x8d
158 #define FASTTRAP_0F_JLE 0x8e
159 #define FASTTRAP_0F_JG 0x8f
161 #define FASTTRAP_EFLAGS_OF 0x800
162 #define FASTTRAP_EFLAGS_DF 0x400
163 #define FASTTRAP_EFLAGS_SF 0x080
164 #define FASTTRAP_EFLAGS_ZF 0x040
165 #define FASTTRAP_EFLAGS_AF 0x010
166 #define FASTTRAP_EFLAGS_PF 0x004
167 #define FASTTRAP_EFLAGS_CF 0x001
170 * Instruction prefixes.
172 #define FASTTRAP_PREFIX_OPERAND 0x66
173 #define FASTTRAP_PREFIX_ADDRESS 0x67
174 #define FASTTRAP_PREFIX_CS 0x2E
175 #define FASTTRAP_PREFIX_DS 0x3E
176 #define FASTTRAP_PREFIX_ES 0x26
177 #define FASTTRAP_PREFIX_FS 0x64
178 #define FASTTRAP_PREFIX_GS 0x65
179 #define FASTTRAP_PREFIX_SS 0x36
180 #define FASTTRAP_PREFIX_LOCK 0xF0
181 #define FASTTRAP_PREFIX_REP 0xF3
182 #define FASTTRAP_PREFIX_REPNE 0xF2
184 #define FASTTRAP_NOREG 0xff
187 * Map between instruction register encodings and the kernel constants which
188 * correspond to indicies into struct regs.
192 * APPLE NOTE: We are cheating here. The regmap is used to decode which register
193 * a given instruction is trying to reference. OS X does not have extended registers
194 * for 32 bit apps, but the *order* is the same. So for 32 bit state, we will return:
201 * The fasttrap_getreg function knows how to make the correct transformation.
203 #if __sol64 || defined(__APPLE__)
204 static const uint8_t regmap
[16] = {
205 REG_RAX
, REG_RCX
, REG_RDX
, REG_RBX
, REG_RSP
, REG_RBP
, REG_RSI
, REG_RDI
,
206 REG_R8
, REG_R9
, REG_R10
, REG_R11
, REG_R12
, REG_R13
, REG_R14
, REG_R15
,
209 static const uint8_t regmap
[8] = {
210 EAX
, ECX
, EDX
, EBX
, UESP
, EBP
, ESI
, EDI
214 static user_addr_t
fasttrap_getreg(x86_saved_state_t
*, uint_t
);
217 fasttrap_anarg(x86_saved_state_t
*regs
, int function_entry
, int argno
)
220 int shift
= function_entry
? 1 : 0;
222 x86_saved_state64_t
*regs64
;
223 x86_saved_state32_t
*regs32
;
224 unsigned int p_model
;
226 if (is_saved_state64(regs
)) {
227 regs64
= saved_state64(regs
);
229 p_model
= DATAMODEL_LP64
;
232 regs32
= saved_state32(regs
);
233 p_model
= DATAMODEL_ILP32
;
236 if (p_model
== DATAMODEL_LP64
) {
240 * In 64-bit mode, the first six arguments are stored in
244 return ((®s64
->rdi
)[argno
]);
246 stack
= regs64
->isf
.rsp
+ sizeof(uint64_t) * (argno
- 6 + shift
);
247 DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT
);
248 value
= dtrace_fuword64(stack
);
249 DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT
| CPU_DTRACE_BADADDR
);
251 uint32_t *stack
= (uint32_t *)(uintptr_t)(regs32
->uesp
);
252 DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT
);
253 value
= dtrace_fuword32((user_addr_t
)(unsigned long)&stack
[argno
+ shift
]);
254 DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT
| CPU_DTRACE_BADADDR
);
262 fasttrap_tracepoint_init(proc_t
*p
, fasttrap_tracepoint_t
*tp
, user_addr_t pc
,
263 fasttrap_probe_type_t type
)
266 uint8_t instr
[FASTTRAP_MAX_INSTR_SIZE
+ 10];
267 size_t len
= FASTTRAP_MAX_INSTR_SIZE
;
268 size_t first
= MIN(len
, PAGE_SIZE
- (pc
& PAGE_MASK
));
272 uint8_t seg
, rex
= 0;
273 unsigned int p_model
= (p
->p_flag
& P_LP64
) ? DATAMODEL_LP64
: DATAMODEL_ILP32
;
276 * Read the instruction at the given address out of the process's
277 * address space. We don't have to worry about a debugger
278 * changing this instruction before we overwrite it with our trap
279 * instruction since P_PR_LOCK is set. Since instructions can span
280 * pages, we potentially read the instruction in two parts. If the
281 * second part fails, we just zero out that part of the instruction.
284 * APPLE NOTE: Of course, we do not have a P_PR_LOCK, so this is racey...
286 if (uread(p
, &instr
[0], first
, pc
) != 0)
289 uread(p
, &instr
[first
], len
- first
, pc
+ first
) != 0) {
290 bzero(&instr
[first
], len
- first
);
295 * If the disassembly fails, then we have a malformed instruction.
297 if ((size
= dtrace_instr_size_isa(instr
, p_model
, &rmindex
)) <= 0)
301 * Make sure the disassembler isn't completely broken.
303 ASSERT(-1 <= rmindex
&& rmindex
< (int)size
);
306 * If the computed size is greater than the number of bytes read,
307 * then it was a malformed instruction possibly because it fell on a
308 * page boundary and the subsequent page was missing or because of
309 * some malicious user.
314 tp
->ftt_size
= (uint8_t)size
;
315 tp
->ftt_segment
= FASTTRAP_SEG_NONE
;
318 * Find the start of the instruction's opcode by processing any
323 switch (instr
[start
]) {
324 case FASTTRAP_PREFIX_SS
:
327 case FASTTRAP_PREFIX_GS
:
330 case FASTTRAP_PREFIX_FS
:
333 case FASTTRAP_PREFIX_ES
:
336 case FASTTRAP_PREFIX_DS
:
339 case FASTTRAP_PREFIX_CS
:
342 case FASTTRAP_PREFIX_OPERAND
:
343 case FASTTRAP_PREFIX_ADDRESS
:
344 case FASTTRAP_PREFIX_LOCK
:
345 case FASTTRAP_PREFIX_REP
:
346 case FASTTRAP_PREFIX_REPNE
:
349 * It's illegal for an instruction to specify
350 * two segment prefixes -- give up on this
351 * illegal instruction.
353 if (tp
->ftt_segment
!= FASTTRAP_SEG_NONE
)
356 tp
->ftt_segment
= seg
;
364 #if __sol64 || defined(__APPLE__)
366 * Identify the REX prefix on 64-bit processes.
368 if (p_model
== DATAMODEL_LP64
&& (instr
[start
] & 0xf0) == 0x40)
369 rex
= instr
[start
++];
373 * Now that we're pretty sure that the instruction is okay, copy the
374 * valid part to the tracepoint.
376 bcopy(instr
, tp
->ftt_instr
, FASTTRAP_MAX_INSTR_SIZE
);
378 tp
->ftt_type
= FASTTRAP_T_COMMON
;
379 if (instr
[start
] == FASTTRAP_2_BYTE_OP
) {
380 switch (instr
[start
+ 1]) {
382 case FASTTRAP_0F_JNO
:
384 case FASTTRAP_0F_JAE
:
386 case FASTTRAP_0F_JNE
:
387 case FASTTRAP_0F_JBE
:
390 case FASTTRAP_0F_JNS
:
392 case FASTTRAP_0F_JNP
:
394 case FASTTRAP_0F_JGE
:
395 case FASTTRAP_0F_JLE
:
397 tp
->ftt_type
= FASTTRAP_T_JCC
;
398 tp
->ftt_code
= (instr
[start
+ 1] & 0x0f) | FASTTRAP_JO
;
399 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
400 /* LINTED - alignment */
401 *(int32_t *)&instr
[start
+ 2];
404 } else if (instr
[start
] == FASTTRAP_GROUP5_OP
) {
405 uint_t mod
= FASTTRAP_MODRM_MOD(instr
[start
+ 1]);
406 uint_t reg
= FASTTRAP_MODRM_REG(instr
[start
+ 1]);
407 uint_t rm
= FASTTRAP_MODRM_RM(instr
[start
+ 1]);
409 if (reg
== 2 || reg
== 4) {
413 tp
->ftt_type
= FASTTRAP_T_CALL
;
415 tp
->ftt_type
= FASTTRAP_T_JMP
;
422 ASSERT(p_model
== DATAMODEL_LP64
|| rex
== 0);
425 * See AMD x86-64 Architecture Programmer's Manual
426 * Volume 3, Section 1.2.7, Table 1-12, and
427 * Appendix A.3.1, Table A-15.
429 if (mod
!= 3 && rm
== 4) {
430 uint8_t sib
= instr
[start
+ 2];
431 uint_t index
= FASTTRAP_SIB_INDEX(sib
);
432 uint_t base
= FASTTRAP_SIB_BASE(sib
);
434 tp
->ftt_scale
= FASTTRAP_SIB_SCALE(sib
);
436 tp
->ftt_index
= (index
== 4) ?
438 regmap
[index
| (FASTTRAP_REX_X(rex
) << 3)];
439 tp
->ftt_base
= (mod
== 0 && base
== 5) ?
441 regmap
[base
| (FASTTRAP_REX_B(rex
) << 3)];
444 sz
= mod
== 1 ? 1 : 4;
447 * In 64-bit mode, mod == 0 and r/m == 5
448 * denotes %rip-relative addressing; in 32-bit
449 * mode, the base register isn't used. In both
450 * modes, there is a 32-bit operand.
452 if (mod
== 0 && rm
== 5) {
453 #if __sol64 || defined(__APPLE__)
454 if (p_model
== DATAMODEL_LP64
)
455 tp
->ftt_base
= REG_RIP
;
458 tp
->ftt_base
= FASTTRAP_NOREG
;
462 (FASTTRAP_REX_B(rex
) << 3);
464 tp
->ftt_base
= regmap
[base
];
465 sz
= mod
== 1 ? 1 : mod
== 2 ? 4 : 0;
467 tp
->ftt_index
= FASTTRAP_NOREG
;
472 tp
->ftt_dest
= *(int8_t *)&instr
[start
+ i
];
473 } else if (sz
== 4) {
474 /* LINTED - alignment */
475 tp
->ftt_dest
= *(int32_t *)&instr
[start
+ i
];
481 switch (instr
[start
]) {
483 tp
->ftt_type
= FASTTRAP_T_RET
;
487 tp
->ftt_type
= FASTTRAP_T_RET16
;
488 /* LINTED - alignment */
489 tp
->ftt_dest
= *(uint16_t *)&instr
[start
+ 1];
508 tp
->ftt_type
= FASTTRAP_T_JCC
;
509 tp
->ftt_code
= instr
[start
];
510 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
511 (int8_t)instr
[start
+ 1];
514 case FASTTRAP_LOOPNZ
:
517 tp
->ftt_type
= FASTTRAP_T_LOOP
;
518 tp
->ftt_code
= instr
[start
];
519 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
520 (int8_t)instr
[start
+ 1];
524 tp
->ftt_type
= FASTTRAP_T_JCXZ
;
525 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
526 (int8_t)instr
[start
+ 1];
530 tp
->ftt_type
= FASTTRAP_T_CALL
;
531 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
532 /* LINTED - alignment */
533 *(int32_t *)&instr
[start
+ 1];
538 tp
->ftt_type
= FASTTRAP_T_JMP
;
539 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
540 /* LINTED - alignment */
541 *(int32_t *)&instr
[start
+ 1];
544 tp
->ftt_type
= FASTTRAP_T_JMP
;
545 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
546 (int8_t)instr
[start
+ 1];
549 case FASTTRAP_PUSHL_EBP
:
551 tp
->ftt_type
= FASTTRAP_T_PUSHL_EBP
;
555 #if __sol64 || defined(__APPLE__)
556 ASSERT(p_model
== DATAMODEL_LP64
|| rex
== 0);
559 * On sol64 we have to be careful not to confuse a nop
560 * (actually xchgl %eax, %eax) with an instruction using
561 * the same opcode, but that does something different
562 * (e.g. xchgl %r8d, %eax or xcghq %r8, %rax).
564 if (FASTTRAP_REX_B(rex
) == 0)
566 tp
->ftt_type
= FASTTRAP_T_NOP
;
571 * The pid provider shares the int3 trap with debugger
572 * breakpoints so we can't instrument them.
574 ASSERT(instr
[start
] == FASTTRAP_INSTR
);
579 * Interrupts seem like they could be traced with
580 * no negative implications, but it's possible that
581 * a thread could be redirected by the trap handling
582 * code which would eventually return to the
583 * instruction after the interrupt. If the interrupt
584 * were in our scratch space, the subsequent
585 * instruction might be overwritten before we return.
586 * Accordingly we refuse to instrument any interrupt.
592 #if __sol64 || defined(__APPLE__)
593 if (p_model
== DATAMODEL_LP64
&& tp
->ftt_type
== FASTTRAP_T_COMMON
) {
595 * If the process is 64-bit and the instruction type is still
596 * FASTTRAP_T_COMMON -- meaning we're going to copy it out an
597 * execute it -- we need to watch for %rip-relative
598 * addressing mode. See the portion of fasttrap_pid_probe()
599 * below where we handle tracepoints with type
600 * FASTTRAP_T_COMMON for how we emulate instructions that
601 * employ %rip-relative addressing.
604 uint_t mod
= FASTTRAP_MODRM_MOD(instr
[rmindex
]);
605 uint_t reg
= FASTTRAP_MODRM_REG(instr
[rmindex
]);
606 uint_t rm
= FASTTRAP_MODRM_RM(instr
[rmindex
]);
608 ASSERT(rmindex
> (int)start
);
610 if (mod
== 0 && rm
== 5) {
612 * We need to be sure to avoid other
613 * registers used by this instruction. While
614 * the reg field may determine the op code
615 * rather than denoting a register, assuming
616 * that it denotes a register is always safe.
617 * We leave the REX field intact and use
618 * whatever value's there for simplicity.
621 tp
->ftt_ripmode
= FASTTRAP_RIP_1
|
623 FASTTRAP_REX_B(rex
));
626 tp
->ftt_ripmode
= FASTTRAP_RIP_2
|
628 FASTTRAP_REX_B(rex
));
632 tp
->ftt_modrm
= tp
->ftt_instr
[rmindex
];
633 tp
->ftt_instr
[rmindex
] =
634 FASTTRAP_MODRM(2, reg
, rm
);
644 fasttrap_tracepoint_install(proc_t
*p
, fasttrap_tracepoint_t
*tp
)
646 fasttrap_instr_t instr
= FASTTRAP_INSTR
;
648 if (uwrite(p
, &instr
, 1, tp
->ftt_pc
) != 0)
655 fasttrap_tracepoint_remove(proc_t
*p
, fasttrap_tracepoint_t
*tp
)
660 * Distinguish between read or write failures and a changed
663 if (uread(p
, &instr
, 1, tp
->ftt_pc
) != 0)
665 if (instr
!= FASTTRAP_INSTR
)
667 if (uwrite(p
, &tp
->ftt_instr
[0], 1, tp
->ftt_pc
) != 0)
674 fasttrap_return_common(x86_saved_state_t
*regs
, user_addr_t pc
, pid_t pid
,
677 x86_saved_state64_t
*regs64
;
678 x86_saved_state32_t
*regs32
;
679 unsigned int p_model
;
681 dtrace_icookie_t cookie
;
683 if (is_saved_state64(regs
)) {
684 regs64
= saved_state64(regs
);
686 p_model
= DATAMODEL_LP64
;
689 regs32
= saved_state32(regs
);
690 p_model
= DATAMODEL_ILP32
;
693 fasttrap_tracepoint_t
*tp
;
694 fasttrap_bucket_t
*bucket
;
698 pid_mtx
= &cpu_core
[CPU
->cpu_id
].cpuc_pid_lock
;
699 lck_mtx_lock(pid_mtx
);
700 bucket
= &fasttrap_tpoints
.fth_table
[FASTTRAP_TPOINTS_INDEX(pid
, pc
)];
702 for (tp
= bucket
->ftb_data
; tp
!= NULL
; tp
= tp
->ftt_next
) {
703 if (pid
== tp
->ftt_pid
&& pc
== tp
->ftt_pc
&&
704 tp
->ftt_proc
->ftpc_acount
!= 0)
709 * Don't sweat it if we can't find the tracepoint again; unlike
710 * when we're in fasttrap_pid_probe(), finding the tracepoint here
711 * is not essential to the correct execution of the process.
714 lck_mtx_unlock(pid_mtx
);
718 for (id
= tp
->ftt_retids
; id
!= NULL
; id
= id
->fti_next
) {
720 * If there's a branch that could act as a return site, we
721 * need to trace it, and check here if the program counter is
722 * external to the function.
724 if (tp
->ftt_type
!= FASTTRAP_T_RET
&&
725 tp
->ftt_type
!= FASTTRAP_T_RET16
&&
726 new_pc
- id
->fti_probe
->ftp_faddr
<
727 id
->fti_probe
->ftp_fsize
)
731 * Provide a hint to the stack trace functions to add the
732 * following pc to the top of the stack since it's missing
733 * on a return probe yet highly desirable for consistency.
735 cookie
= dtrace_interrupt_disable();
736 cpu_core
[CPU
->cpu_id
].cpuc_missing_tos
= pc
;
737 if (ISSET(current_proc()->p_lflag
, P_LNOATTACH
)) {
738 dtrace_probe(dtrace_probeid_error
, 0 /* state */, id
->fti_probe
->ftp_id
,
739 1 /* ndx */, -1 /* offset */, DTRACEFLT_UPRIV
);
740 } else if (p_model
== DATAMODEL_LP64
) {
741 dtrace_probe(id
->fti_probe
->ftp_id
,
742 pc
- id
->fti_probe
->ftp_faddr
,
743 regs64
->rax
, regs64
->rdx
, 0, 0);
745 dtrace_probe(id
->fti_probe
->ftp_id
,
746 pc
- id
->fti_probe
->ftp_faddr
,
747 regs32
->eax
, regs32
->edx
, 0, 0);
749 /* remove the hint */
750 cpu_core
[CPU
->cpu_id
].cpuc_missing_tos
= 0;
751 dtrace_interrupt_enable(cookie
);
754 lck_mtx_unlock(pid_mtx
);
758 fasttrap_sigsegv(proc_t
*p
, uthread_t t
, user_addr_t addr
)
762 /* Set fault address and mark signal */
764 t
->uu_siglist
|= sigmask(SIGSEGV
);
767 * XXX These two line may be redundant; if not, then we need
768 * XXX to potentially set the data address in the machine
769 * XXX specific thread state structure to indicate the address.
771 t
->uu_exception
= KERN_INVALID_ADDRESS
; /* SIGSEGV */
772 t
->uu_subcode
= 0; /* XXX pad */
777 signal_setast(t
->uu_context
.vc_thread
);
781 fasttrap_usdt_args64(fasttrap_probe_t
*probe
, x86_saved_state64_t
*regs64
, int argc
,
784 int i
, x
, cap
= MIN(argc
, probe
->ftp_nargs
);
785 user_addr_t stack
= (user_addr_t
)regs64
->isf
.rsp
;
787 for (i
= 0; i
< cap
; i
++) {
788 x
= probe
->ftp_argmap
[i
];
791 /* FIXME! This may be broken, needs testing */
792 argv
[i
] = (®s64
->rdi
)[x
];
794 fasttrap_fuword64_noerr(stack
+ (x
* sizeof(uint64_t)), &argv
[i
]);
798 for (; i
< argc
; i
++) {
804 fasttrap_usdt_args32(fasttrap_probe_t
*probe
, x86_saved_state32_t
*regs32
, int argc
,
807 int i
, x
, cap
= MIN(argc
, probe
->ftp_nargs
);
808 uint32_t *stack
= (uint32_t *)(uintptr_t)(regs32
->uesp
);
810 for (i
= 0; i
< cap
; i
++) {
811 x
= probe
->ftp_argmap
[i
];
813 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[x
], &argv
[i
]);
816 for (; i
< argc
; i
++) {
825 fasttrap_do_seg(fasttrap_tracepoint_t
*tp
, x86_saved_state_t
*rp
, user_addr_t
*addr
) // 64 bit
827 #pragma unused(tp, rp, addr)
828 printf("fasttrap_do_seg() called while unimplemented.\n");
832 uint16_t sel
, ndx
, type
;
835 switch (tp
->ftt_segment
) {
836 case FASTTRAP_SEG_CS
:
839 case FASTTRAP_SEG_DS
:
842 case FASTTRAP_SEG_ES
:
845 case FASTTRAP_SEG_FS
:
848 case FASTTRAP_SEG_GS
:
851 case FASTTRAP_SEG_SS
:
857 * Make sure the given segment register specifies a user priority
858 * selector rather than a kernel selector.
866 * Check the bounds and grab the descriptor out of the specified
870 if (ndx
> p
->p_ldtlimit
)
873 desc
= p
->p_ldt
+ ndx
;
879 desc
= cpu_get_gdt() + ndx
;
883 * The descriptor must have user privilege level and it must be
886 if (desc
->usd_dpl
!= SEL_UPL
|| desc
->usd_p
!= 1)
889 type
= desc
->usd_type
;
892 * If the S bit in the type field is not set, this descriptor can
893 * only be used in system context.
895 if ((type
& 0x10) != 0x10)
898 limit
= USEGD_GETLIMIT(desc
) * (desc
->usd_gran
? PAGESIZE
: 1);
900 if (tp
->ftt_segment
== FASTTRAP_SEG_CS
) {
902 * The code/data bit and readable bit must both be set.
904 if ((type
& 0xa) != 0xa)
911 * The code/data bit must be clear.
913 if ((type
& 0x8) != 0)
917 * If the expand-down bit is clear, we just check the limit as
918 * it would naturally be applied. Otherwise, we need to check
919 * that the address is the range [limit + 1 .. 0xffff] or
920 * [limit + 1 ... 0xffffffff] depending on if the default
921 * operand size bit is set.
923 if ((type
& 0x4) == 0) {
926 } else if (desc
->usd_def32
) {
927 if (*addr
< limit
+ 1 || 0xffff < *addr
)
930 if (*addr
< limit
+ 1 || 0xffffffff < *addr
)
935 *addr
+= USEGD_GETBASE(desc
);
941 * Due to variances between Solaris and xnu, I have split this into a 32 bit and 64 bit
942 * code path. It still takes an x86_saved_state_t* argument, because it must sometimes
943 * call other methods that require a x86_saved_state_t.
947 * Any changes made to this method must be echo'd in fasttrap_pid_probe64!
951 fasttrap_pid_probe32(x86_saved_state_t
*regs
)
953 ASSERT(is_saved_state32(regs
));
955 x86_saved_state32_t
*regs32
= saved_state32(regs
);
956 user_addr_t pc
= regs32
->eip
- 1;
957 proc_t
*p
= current_proc();
958 user_addr_t new_pc
= 0;
959 fasttrap_bucket_t
*bucket
;
961 fasttrap_tracepoint_t
*tp
, tp_local
;
963 dtrace_icookie_t cookie
;
964 uint_t is_enabled
= 0;
966 uthread_t uthread
= (uthread_t
)get_bsdthread_info(current_thread());
969 * It's possible that a user (in a veritable orgy of bad planning)
970 * could redirect this thread's flow of control before it reached the
971 * return probe fasttrap. In this case we need to kill the process
972 * since it's in a unrecoverable state.
974 if (uthread
->t_dtrace_step
) {
975 ASSERT(uthread
->t_dtrace_on
);
976 fasttrap_sigtrap(p
, uthread
, pc
);
981 * Clear all user tracing flags.
983 uthread
->t_dtrace_ft
= 0;
984 uthread
->t_dtrace_pc
= 0;
985 uthread
->t_dtrace_npc
= 0;
986 uthread
->t_dtrace_scrpc
= 0;
987 uthread
->t_dtrace_astpc
= 0;
990 * Treat a child created by a call to vfork(2) as if it were its
991 * parent. We know that there's only one thread of control in such a
995 * APPLE NOTE: Terry says: "You need to hold the process locks (currently: kernel funnel) for this traversal"
996 * FIXME: How do we assert this?
998 while (p
->p_lflag
& P_LINVFORK
)
1002 pid_mtx
= &cpu_core
[CPU
->cpu_id
].cpuc_pid_lock
;
1003 lck_mtx_lock(pid_mtx
);
1004 bucket
= &fasttrap_tpoints
.fth_table
[FASTTRAP_TPOINTS_INDEX(pid
, pc
)];
1007 * Lookup the tracepoint that the process just hit.
1009 for (tp
= bucket
->ftb_data
; tp
!= NULL
; tp
= tp
->ftt_next
) {
1010 if (pid
== tp
->ftt_pid
&& pc
== tp
->ftt_pc
&&
1011 tp
->ftt_proc
->ftpc_acount
!= 0)
1016 * If we couldn't find a matching tracepoint, either a tracepoint has
1017 * been inserted without using the pid<pid> ioctl interface (see
1018 * fasttrap_ioctl), or somehow we have mislaid this tracepoint.
1021 lck_mtx_unlock(pid_mtx
);
1026 * Set the program counter to the address of the traced instruction
1027 * so that it looks right in ustack() output.
1031 if (tp
->ftt_ids
!= NULL
) {
1034 uint32_t s0
, s1
, s2
, s3
, s4
, s5
;
1035 uint32_t *stack
= (uint32_t *)(uintptr_t)(regs32
->uesp
);
1038 * In 32-bit mode, all arguments are passed on the
1039 * stack. If this is a function entry probe, we need
1040 * to skip the first entry on the stack as it
1041 * represents the return address rather than a
1042 * parameter to the function.
1044 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[0], &s0
);
1045 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[1], &s1
);
1046 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[2], &s2
);
1047 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[3], &s3
);
1048 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[4], &s4
);
1049 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[5], &s5
);
1051 for (id
= tp
->ftt_ids
; id
!= NULL
; id
= id
->fti_next
) {
1052 fasttrap_probe_t
*probe
= id
->fti_probe
;
1054 if (ISSET(current_proc()->p_lflag
, P_LNOATTACH
)) {
1055 dtrace_probe(dtrace_probeid_error
, 0 /* state */, probe
->ftp_id
,
1056 1 /* ndx */, -1 /* offset */, DTRACEFLT_UPRIV
);
1057 } else if (id
->fti_ptype
== DTFTP_ENTRY
) {
1059 * We note that this was an entry
1060 * probe to help ustack() find the
1063 cookie
= dtrace_interrupt_disable();
1064 DTRACE_CPUFLAG_SET(CPU_DTRACE_ENTRY
);
1065 dtrace_probe(probe
->ftp_id
, s1
, s2
,
1067 DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_ENTRY
);
1068 dtrace_interrupt_enable(cookie
);
1069 } else if (id
->fti_ptype
== DTFTP_IS_ENABLED
) {
1071 * Note that in this case, we don't
1072 * call dtrace_probe() since it's only
1073 * an artificial probe meant to change
1074 * the flow of control so that it
1075 * encounters the true probe.
1078 } else if (probe
->ftp_argmap
== NULL
) {
1079 dtrace_probe(probe
->ftp_id
, s0
, s1
,
1084 fasttrap_usdt_args32(probe
, regs32
,
1085 sizeof (t
) / sizeof (t
[0]), t
);
1087 dtrace_probe(probe
->ftp_id
, t
[0], t
[1],
1091 /* APPLE NOTE: Oneshot probes get one and only one chance... */
1092 if (probe
->ftp_prov
->ftp_provider_type
== DTFTP_PROVIDER_ONESHOT
) {
1093 fasttrap_tracepoint_remove(p
, tp
);
1099 * We're about to do a bunch of work so we cache a local copy of
1100 * the tracepoint to emulate the instruction, and then find the
1101 * tracepoint again later if we need to light up any return probes.
1104 lck_mtx_unlock(pid_mtx
);
1108 * Set the program counter to appear as though the traced instruction
1109 * had completely executed. This ensures that fasttrap_getreg() will
1110 * report the expected value for REG_RIP.
1112 regs32
->eip
= pc
+ tp
->ftt_size
;
1115 * If there's an is-enabled probe connected to this tracepoint it
1116 * means that there was a 'xorl %eax, %eax' or 'xorq %rax, %rax'
1117 * instruction that was placed there by DTrace when the binary was
1118 * linked. As this probe is, in fact, enabled, we need to stuff 1
1119 * into %eax or %rax. Accordingly, we can bypass all the instruction
1120 * emulation logic since we know the inevitable result. It's possible
1121 * that a user could construct a scenario where the 'is-enabled'
1122 * probe was on some other instruction, but that would be a rather
1123 * exotic way to shoot oneself in the foot.
1127 new_pc
= regs32
->eip
;
1132 * We emulate certain types of instructions to ensure correctness
1133 * (in the case of position dependent instructions) or optimize
1134 * common cases. The rest we have the thread execute back in user-
1137 switch (tp
->ftt_type
) {
1138 case FASTTRAP_T_RET
:
1139 case FASTTRAP_T_RET16
:
1146 * We have to emulate _every_ facet of the behavior of a ret
1147 * instruction including what happens if the load from %esp
1148 * fails; in that case, we send a SIGSEGV.
1151 ret
= fasttrap_fuword32((user_addr_t
)regs32
->uesp
, &dst32
);
1153 addr
= regs32
->uesp
+ sizeof (uint32_t);
1156 fasttrap_sigsegv(p
, uthread
, (user_addr_t
)regs32
->uesp
);
1161 if (tp
->ftt_type
== FASTTRAP_T_RET16
)
1162 addr
+= tp
->ftt_dest
;
1164 regs32
->uesp
= addr
;
1169 case FASTTRAP_T_JCC
:
1173 switch (tp
->ftt_code
) {
1175 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_OF
) != 0;
1178 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_OF
) == 0;
1181 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_CF
) != 0;
1184 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_CF
) == 0;
1187 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) != 0;
1190 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) == 0;
1193 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_CF
) != 0 ||
1194 (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) != 0;
1197 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_CF
) == 0 &&
1198 (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) == 0;
1201 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_SF
) != 0;
1204 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_SF
) == 0;
1207 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_PF
) != 0;
1210 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_PF
) == 0;
1213 taken
= ((regs32
->efl
& FASTTRAP_EFLAGS_SF
) == 0) !=
1214 ((regs32
->efl
& FASTTRAP_EFLAGS_OF
) == 0);
1217 taken
= ((regs32
->efl
& FASTTRAP_EFLAGS_SF
) == 0) ==
1218 ((regs32
->efl
& FASTTRAP_EFLAGS_OF
) == 0);
1221 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) != 0 ||
1222 ((regs32
->efl
& FASTTRAP_EFLAGS_SF
) == 0) !=
1223 ((regs32
->efl
& FASTTRAP_EFLAGS_OF
) == 0);
1226 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) == 0 &&
1227 ((regs32
->efl
& FASTTRAP_EFLAGS_SF
) == 0) ==
1228 ((regs32
->efl
& FASTTRAP_EFLAGS_OF
) == 0);
1235 new_pc
= tp
->ftt_dest
;
1237 new_pc
= pc
+ tp
->ftt_size
;
1241 case FASTTRAP_T_LOOP
:
1244 greg_t cx
= regs32
->ecx
--;
1246 switch (tp
->ftt_code
) {
1247 case FASTTRAP_LOOPNZ
:
1248 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) == 0 &&
1251 case FASTTRAP_LOOPZ
:
1252 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) != 0 &&
1263 new_pc
= tp
->ftt_dest
;
1265 new_pc
= pc
+ tp
->ftt_size
;
1269 case FASTTRAP_T_JCXZ
:
1271 greg_t cx
= regs32
->ecx
;
1274 new_pc
= tp
->ftt_dest
;
1276 new_pc
= pc
+ tp
->ftt_size
;
1280 case FASTTRAP_T_PUSHL_EBP
:
1282 user_addr_t addr
= regs32
->uesp
- sizeof (uint32_t);
1283 int ret
= fasttrap_suword32(addr
, (uint32_t)regs32
->ebp
);
1286 fasttrap_sigsegv(p
, uthread
, addr
);
1291 regs32
->uesp
= addr
;
1292 new_pc
= pc
+ tp
->ftt_size
;
1296 case FASTTRAP_T_NOP
:
1297 new_pc
= pc
+ tp
->ftt_size
;
1300 case FASTTRAP_T_JMP
:
1301 case FASTTRAP_T_CALL
:
1302 if (tp
->ftt_code
== 0) {
1303 new_pc
= tp
->ftt_dest
;
1305 user_addr_t
/* value ,*/ addr
= tp
->ftt_dest
;
1307 if (tp
->ftt_base
!= FASTTRAP_NOREG
)
1308 addr
+= fasttrap_getreg(regs
, tp
->ftt_base
);
1309 if (tp
->ftt_index
!= FASTTRAP_NOREG
)
1310 addr
+= fasttrap_getreg(regs
, tp
->ftt_index
) <<
1313 if (tp
->ftt_code
== 1) {
1315 * If there's a segment prefix for this
1316 * instruction, we'll need to check permissions
1317 * and bounds on the given selector, and adjust
1318 * the address accordingly.
1320 if (tp
->ftt_segment
!= FASTTRAP_SEG_NONE
&&
1321 fasttrap_do_seg(tp
, regs
, &addr
) != 0) {
1322 fasttrap_sigsegv(p
, uthread
, addr
);
1328 addr
= (user_addr_t
)(uint32_t)addr
;
1329 if (fasttrap_fuword32(addr
, &value32
) == -1) {
1330 fasttrap_sigsegv(p
, uthread
, addr
);
1341 * If this is a call instruction, we need to push the return
1342 * address onto the stack. If this fails, we send the process
1343 * a SIGSEGV and reset the pc to emulate what would happen if
1344 * this instruction weren't traced.
1346 if (tp
->ftt_type
== FASTTRAP_T_CALL
) {
1347 user_addr_t addr
= regs32
->uesp
- sizeof (uint32_t);
1348 int ret
= fasttrap_suword32(addr
, (uint32_t)(pc
+ tp
->ftt_size
));
1351 fasttrap_sigsegv(p
, uthread
, addr
);
1356 regs32
->uesp
= addr
;
1360 case FASTTRAP_T_COMMON
:
1363 uint8_t scratch
[2 * FASTTRAP_MAX_INSTR_SIZE
+ 7];
1367 * Generic Instruction Tracing
1368 * ---------------------------
1370 * This is the layout of the scratch space in the user-land
1371 * thread structure for our generated instructions.
1374 * ------------------------ -----
1375 * a: <original instruction> <= 15
1376 * jmp <pc + tp->ftt_size> 5
1377 * b: <original instrction> <= 15
1378 * int T_DTRACE_RET 2
1383 * ------------------------ -----
1384 * a: <original instruction> <= 15
1386 * <pc + tp->ftt_size> 8
1387 * b: <original instruction> <= 15
1388 * int T_DTRACE_RET 2
1392 * The %pc is set to a, and curthread->t_dtrace_astpc is set
1393 * to b. If we encounter a signal on the way out of the
1394 * kernel, trap() will set %pc to curthread->t_dtrace_astpc
1395 * so that we execute the original instruction and re-enter
1396 * the kernel rather than redirecting to the next instruction.
1398 * If there are return probes (so we know that we're going to
1399 * need to reenter the kernel after executing the original
1400 * instruction), the scratch space will just contain the
1401 * original instruction followed by an interrupt -- the same
1405 addr
= uthread
->t_dtrace_scratch
->addr
;
1408 fasttrap_sigtrap(p
, uthread
, pc
); // Should be killing target proc
1413 ASSERT(tp
->ftt_size
< FASTTRAP_MAX_INSTR_SIZE
);
1415 uthread
->t_dtrace_scrpc
= addr
;
1416 bcopy(tp
->ftt_instr
, &scratch
[i
], tp
->ftt_size
);
1420 * Set up the jmp to the next instruction; note that
1421 * the size of the traced instruction cancels out.
1423 scratch
[i
++] = FASTTRAP_JMP32
;
1424 /* LINTED - alignment */
1425 *(uint32_t *)&scratch
[i
] = pc
- addr
- 5;
1426 i
+= sizeof (uint32_t);
1428 uthread
->t_dtrace_astpc
= addr
+ i
;
1429 bcopy(tp
->ftt_instr
, &scratch
[i
], tp
->ftt_size
);
1431 scratch
[i
++] = FASTTRAP_INT
;
1432 scratch
[i
++] = T_DTRACE_RET
;
1434 ASSERT(i
<= sizeof (scratch
));
1436 if (fasttrap_copyout(scratch
, addr
, i
)) {
1437 fasttrap_sigtrap(p
, uthread
, pc
);
1442 if (tp
->ftt_retids
!= NULL
) {
1443 uthread
->t_dtrace_step
= 1;
1444 uthread
->t_dtrace_ret
= 1;
1445 new_pc
= uthread
->t_dtrace_astpc
;
1447 new_pc
= uthread
->t_dtrace_scrpc
;
1450 uthread
->t_dtrace_pc
= pc
;
1451 uthread
->t_dtrace_npc
= pc
+ tp
->ftt_size
;
1452 uthread
->t_dtrace_on
= 1;
1457 panic("fasttrap: mishandled an instruction");
1464 * We're setting this earlier than Solaris does, to get a "correct"
1465 * ustack() output. In the Sun code, a() -> b() -> c() -> d() is
1466 * reported at: d, b, a. The new way gives c, b, a, which is closer
1467 * to correct, as the return instruction has already exectued.
1469 regs32
->eip
= new_pc
;
1472 * If there were no return probes when we first found the tracepoint,
1473 * we should feel no obligation to honor any return probes that were
1474 * subsequently enabled -- they'll just have to wait until the next
1477 if (tp
->ftt_retids
!= NULL
) {
1479 * We need to wait until the results of the instruction are
1480 * apparent before invoking any return probes. If this
1481 * instruction was emulated we can just call
1482 * fasttrap_return_common(); if it needs to be executed, we
1483 * need to wait until the user thread returns to the kernel.
1485 if (tp
->ftt_type
!= FASTTRAP_T_COMMON
) {
1486 fasttrap_return_common(regs
, pc
, pid
, new_pc
);
1488 ASSERT(uthread
->t_dtrace_ret
!= 0);
1489 ASSERT(uthread
->t_dtrace_pc
== pc
);
1490 ASSERT(uthread
->t_dtrace_scrpc
!= 0);
1491 ASSERT(new_pc
== uthread
->t_dtrace_astpc
);
1499 * Due to variances between Solaris and xnu, I have split this into a 32 bit and 64 bit
1500 * code path. It still takes an x86_saved_state_t* argument, because it must sometimes
1501 * call other methods that require a x86_saved_state_t.
1505 * Any changes made to this method must be echo'd in fasttrap_pid_probe32!
1509 fasttrap_pid_probe64(x86_saved_state_t
*regs
)
1511 ASSERT(is_saved_state64(regs
));
1513 x86_saved_state64_t
*regs64
= saved_state64(regs
);
1514 user_addr_t pc
= regs64
->isf
.rip
- 1;
1515 proc_t
*p
= current_proc();
1516 user_addr_t new_pc
= 0;
1517 fasttrap_bucket_t
*bucket
;
1519 fasttrap_tracepoint_t
*tp
, tp_local
;
1521 dtrace_icookie_t cookie
;
1522 uint_t is_enabled
= 0;
1524 uthread_t uthread
= (uthread_t
)get_bsdthread_info(current_thread());
1527 * It's possible that a user (in a veritable orgy of bad planning)
1528 * could redirect this thread's flow of control before it reached the
1529 * return probe fasttrap. In this case we need to kill the process
1530 * since it's in a unrecoverable state.
1532 if (uthread
->t_dtrace_step
) {
1533 ASSERT(uthread
->t_dtrace_on
);
1534 fasttrap_sigtrap(p
, uthread
, pc
);
1539 * Clear all user tracing flags.
1541 uthread
->t_dtrace_ft
= 0;
1542 uthread
->t_dtrace_pc
= 0;
1543 uthread
->t_dtrace_npc
= 0;
1544 uthread
->t_dtrace_scrpc
= 0;
1545 uthread
->t_dtrace_astpc
= 0;
1546 uthread
->t_dtrace_regv
= 0;
1549 * Treat a child created by a call to vfork(2) as if it were its
1550 * parent. We know that there's only one thread of control in such a
1551 * process: this one.
1554 * APPLE NOTE: Terry says: "You need to hold the process locks (currently: kernel funnel) for this traversal"
1555 * FIXME: How do we assert this?
1557 while (p
->p_lflag
& P_LINVFORK
)
1561 pid_mtx
= &cpu_core
[CPU
->cpu_id
].cpuc_pid_lock
;
1562 lck_mtx_lock(pid_mtx
);
1563 bucket
= &fasttrap_tpoints
.fth_table
[FASTTRAP_TPOINTS_INDEX(pid
, pc
)];
1566 * Lookup the tracepoint that the process just hit.
1568 for (tp
= bucket
->ftb_data
; tp
!= NULL
; tp
= tp
->ftt_next
) {
1569 if (pid
== tp
->ftt_pid
&& pc
== tp
->ftt_pc
&&
1570 tp
->ftt_proc
->ftpc_acount
!= 0)
1575 * If we couldn't find a matching tracepoint, either a tracepoint has
1576 * been inserted without using the pid<pid> ioctl interface (see
1577 * fasttrap_ioctl), or somehow we have mislaid this tracepoint.
1580 lck_mtx_unlock(pid_mtx
);
1585 * Set the program counter to the address of the traced instruction
1586 * so that it looks right in ustack() output.
1588 regs64
->isf
.rip
= pc
;
1590 if (tp
->ftt_ids
!= NULL
) {
1593 for (id
= tp
->ftt_ids
; id
!= NULL
; id
= id
->fti_next
) {
1594 fasttrap_probe_t
*probe
= id
->fti_probe
;
1596 if (ISSET(current_proc()->p_lflag
, P_LNOATTACH
)) {
1597 dtrace_probe(dtrace_probeid_error
, 0 /* state */, probe
->ftp_id
,
1598 1 /* ndx */, -1 /* offset */, DTRACEFLT_UPRIV
);
1599 } else if (id
->fti_ptype
== DTFTP_ENTRY
) {
1601 * We note that this was an entry
1602 * probe to help ustack() find the
1605 cookie
= dtrace_interrupt_disable();
1606 DTRACE_CPUFLAG_SET(CPU_DTRACE_ENTRY
);
1607 dtrace_probe(probe
->ftp_id
, regs64
->rdi
,
1608 regs64
->rsi
, regs64
->rdx
, regs64
->rcx
,
1610 DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_ENTRY
);
1611 dtrace_interrupt_enable(cookie
);
1612 } else if (id
->fti_ptype
== DTFTP_IS_ENABLED
) {
1614 * Note that in this case, we don't
1615 * call dtrace_probe() since it's only
1616 * an artificial probe meant to change
1617 * the flow of control so that it
1618 * encounters the true probe.
1621 } else if (probe
->ftp_argmap
== NULL
) {
1622 dtrace_probe(probe
->ftp_id
, regs64
->rdi
,
1623 regs64
->rsi
, regs64
->rdx
, regs64
->rcx
,
1628 fasttrap_usdt_args64(probe
, regs64
,
1629 sizeof (t
) / sizeof (t
[0]), t
);
1631 dtrace_probe(probe
->ftp_id
, t
[0], t
[1],
1635 /* APPLE NOTE: Oneshot probes get one and only one chance... */
1636 if (probe
->ftp_prov
->ftp_provider_type
== DTFTP_PROVIDER_ONESHOT
) {
1637 fasttrap_tracepoint_remove(p
, tp
);
1643 * We're about to do a bunch of work so we cache a local copy of
1644 * the tracepoint to emulate the instruction, and then find the
1645 * tracepoint again later if we need to light up any return probes.
1648 lck_mtx_unlock(pid_mtx
);
1652 * Set the program counter to appear as though the traced instruction
1653 * had completely executed. This ensures that fasttrap_getreg() will
1654 * report the expected value for REG_RIP.
1656 regs64
->isf
.rip
= pc
+ tp
->ftt_size
;
1659 * If there's an is-enabled probe connected to this tracepoint it
1660 * means that there was a 'xorl %eax, %eax' or 'xorq %rax, %rax'
1661 * instruction that was placed there by DTrace when the binary was
1662 * linked. As this probe is, in fact, enabled, we need to stuff 1
1663 * into %eax or %rax. Accordingly, we can bypass all the instruction
1664 * emulation logic since we know the inevitable result. It's possible
1665 * that a user could construct a scenario where the 'is-enabled'
1666 * probe was on some other instruction, but that would be a rather
1667 * exotic way to shoot oneself in the foot.
1671 new_pc
= regs64
->isf
.rip
;
1676 * We emulate certain types of instructions to ensure correctness
1677 * (in the case of position dependent instructions) or optimize
1678 * common cases. The rest we have the thread execute back in user-
1681 switch (tp
->ftt_type
) {
1682 case FASTTRAP_T_RET
:
1683 case FASTTRAP_T_RET16
:
1690 * We have to emulate _every_ facet of the behavior of a ret
1691 * instruction including what happens if the load from %esp
1692 * fails; in that case, we send a SIGSEGV.
1694 ret
= fasttrap_fuword64((user_addr_t
)regs64
->isf
.rsp
, &dst
);
1695 addr
= regs64
->isf
.rsp
+ sizeof (uint64_t);
1698 fasttrap_sigsegv(p
, uthread
, (user_addr_t
)regs64
->isf
.rsp
);
1703 if (tp
->ftt_type
== FASTTRAP_T_RET16
)
1704 addr
+= tp
->ftt_dest
;
1706 regs64
->isf
.rsp
= addr
;
1711 case FASTTRAP_T_JCC
:
1715 switch (tp
->ftt_code
) {
1717 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) != 0;
1720 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) == 0;
1723 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_CF
) != 0;
1726 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_CF
) == 0;
1729 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) != 0;
1732 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) == 0;
1735 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_CF
) != 0 ||
1736 (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) != 0;
1739 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_CF
) == 0 &&
1740 (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) == 0;
1743 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) != 0;
1746 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) == 0;
1749 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_PF
) != 0;
1752 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_PF
) == 0;
1755 taken
= ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) == 0) !=
1756 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) == 0);
1759 taken
= ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) == 0) ==
1760 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) == 0);
1763 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) != 0 ||
1764 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) == 0) !=
1765 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) == 0);
1768 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) == 0 &&
1769 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) == 0) ==
1770 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) == 0);
1777 new_pc
= tp
->ftt_dest
;
1779 new_pc
= pc
+ tp
->ftt_size
;
1783 case FASTTRAP_T_LOOP
:
1786 uint64_t cx
= regs64
->rcx
--;
1788 switch (tp
->ftt_code
) {
1789 case FASTTRAP_LOOPNZ
:
1790 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) == 0 &&
1793 case FASTTRAP_LOOPZ
:
1794 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) != 0 &&
1805 new_pc
= tp
->ftt_dest
;
1807 new_pc
= pc
+ tp
->ftt_size
;
1811 case FASTTRAP_T_JCXZ
:
1813 uint64_t cx
= regs64
->rcx
;
1816 new_pc
= tp
->ftt_dest
;
1818 new_pc
= pc
+ tp
->ftt_size
;
1822 case FASTTRAP_T_PUSHL_EBP
:
1824 user_addr_t addr
= regs64
->isf
.rsp
- sizeof (uint64_t);
1825 int ret
= fasttrap_suword64(addr
, (uint64_t)regs64
->rbp
);
1828 fasttrap_sigsegv(p
, uthread
, addr
);
1833 regs64
->isf
.rsp
= addr
;
1834 new_pc
= pc
+ tp
->ftt_size
;
1838 case FASTTRAP_T_NOP
:
1839 new_pc
= pc
+ tp
->ftt_size
;
1842 case FASTTRAP_T_JMP
:
1843 case FASTTRAP_T_CALL
:
1844 if (tp
->ftt_code
== 0) {
1845 new_pc
= tp
->ftt_dest
;
1847 user_addr_t value
, addr
= tp
->ftt_dest
;
1849 if (tp
->ftt_base
!= FASTTRAP_NOREG
)
1850 addr
+= fasttrap_getreg(regs
, tp
->ftt_base
);
1851 if (tp
->ftt_index
!= FASTTRAP_NOREG
)
1852 addr
+= fasttrap_getreg(regs
, tp
->ftt_index
) <<
1855 if (tp
->ftt_code
== 1) {
1857 * If there's a segment prefix for this
1858 * instruction, we'll need to check permissions
1859 * and bounds on the given selector, and adjust
1860 * the address accordingly.
1862 if (tp
->ftt_segment
!= FASTTRAP_SEG_NONE
&&
1863 fasttrap_do_seg(tp
, regs
, &addr
) != 0) {
1864 fasttrap_sigsegv(p
, uthread
, addr
);
1869 if (fasttrap_fuword64(addr
, &value
) == -1) {
1870 fasttrap_sigsegv(p
, uthread
, addr
);
1881 * If this is a call instruction, we need to push the return
1882 * address onto the stack. If this fails, we send the process
1883 * a SIGSEGV and reset the pc to emulate what would happen if
1884 * this instruction weren't traced.
1886 if (tp
->ftt_type
== FASTTRAP_T_CALL
) {
1887 user_addr_t addr
= regs64
->isf
.rsp
- sizeof (uint64_t);
1888 int ret
= fasttrap_suword64(addr
, pc
+ tp
->ftt_size
);
1891 fasttrap_sigsegv(p
, uthread
, addr
);
1896 regs64
->isf
.rsp
= addr
;
1900 case FASTTRAP_T_COMMON
:
1903 uint8_t scratch
[2 * FASTTRAP_MAX_INSTR_SIZE
+ 22];
1907 * Generic Instruction Tracing
1908 * ---------------------------
1910 * This is the layout of the scratch space in the user-land
1911 * thread structure for our generated instructions.
1914 * ------------------------ -----
1915 * a: <original instruction> <= 15
1916 * jmp <pc + tp->ftt_size> 5
1917 * b: <original instrction> <= 15
1918 * int T_DTRACE_RET 2
1923 * ------------------------ -----
1924 * a: <original instruction> <= 15
1926 * <pc + tp->ftt_size> 8
1927 * b: <original instruction> <= 15
1928 * int T_DTRACE_RET 2
1932 * The %pc is set to a, and curthread->t_dtrace_astpc is set
1933 * to b. If we encounter a signal on the way out of the
1934 * kernel, trap() will set %pc to curthread->t_dtrace_astpc
1935 * so that we execute the original instruction and re-enter
1936 * the kernel rather than redirecting to the next instruction.
1938 * If there are return probes (so we know that we're going to
1939 * need to reenter the kernel after executing the original
1940 * instruction), the scratch space will just contain the
1941 * original instruction followed by an interrupt -- the same
1944 * %rip-relative Addressing
1945 * ------------------------
1947 * There's a further complication in 64-bit mode due to %rip-
1948 * relative addressing. While this is clearly a beneficial
1949 * architectural decision for position independent code, it's
1950 * hard not to see it as a personal attack against the pid
1951 * provider since before there was a relatively small set of
1952 * instructions to emulate; with %rip-relative addressing,
1953 * almost every instruction can potentially depend on the
1954 * address at which it's executed. Rather than emulating
1955 * the broad spectrum of instructions that can now be
1956 * position dependent, we emulate jumps and others as in
1957 * 32-bit mode, and take a different tack for instructions
1958 * using %rip-relative addressing.
1960 * For every instruction that uses the ModRM byte, the
1961 * in-kernel disassembler reports its location. We use the
1962 * ModRM byte to identify that an instruction uses
1963 * %rip-relative addressing and to see what other registers
1964 * the instruction uses. To emulate those instructions,
1965 * we modify the instruction to be %rax-relative rather than
1966 * %rip-relative (or %rcx-relative if the instruction uses
1967 * %rax; or %r8- or %r9-relative if the REX.B is present so
1968 * we don't have to rewrite the REX prefix). We then load
1969 * the value that %rip would have been into the scratch
1970 * register and generate an instruction to reset the scratch
1971 * register back to its original value. The instruction
1972 * sequence looks like this:
1974 * 64-mode %rip-relative bytes
1975 * ------------------------ -----
1976 * a: <modified instruction> <= 15
1977 * movq $<value>, %<scratch> 6
1979 * <pc + tp->ftt_size> 8
1980 * b: <modified instruction> <= 15
1981 * int T_DTRACE_RET 2
1985 * We set curthread->t_dtrace_regv so that upon receiving
1986 * a signal we can reset the value of the scratch register.
1989 addr
= uthread
->t_dtrace_scratch
->addr
;
1992 fasttrap_sigtrap(p
, uthread
, pc
); // Should be killing target proc
1997 ASSERT(tp
->ftt_size
< FASTTRAP_MAX_INSTR_SIZE
);
1999 uthread
->t_dtrace_scrpc
= addr
;
2000 bcopy(tp
->ftt_instr
, &scratch
[i
], tp
->ftt_size
);
2003 if (tp
->ftt_ripmode
!= 0) {
2006 ASSERT(tp
->ftt_ripmode
&
2007 (FASTTRAP_RIP_1
| FASTTRAP_RIP_2
));
2010 * If this was a %rip-relative instruction, we change
2011 * it to be either a %rax- or %rcx-relative
2012 * instruction (depending on whether those registers
2013 * are used as another operand; or %r8- or %r9-
2014 * relative depending on the value of REX.B). We then
2015 * set that register and generate a movq instruction
2016 * to reset the value.
2018 if (tp
->ftt_ripmode
& FASTTRAP_RIP_X
)
2019 scratch
[i
++] = FASTTRAP_REX(1, 0, 0, 1);
2021 scratch
[i
++] = FASTTRAP_REX(1, 0, 0, 0);
2023 if (tp
->ftt_ripmode
& FASTTRAP_RIP_1
)
2024 scratch
[i
++] = FASTTRAP_MOV_EAX
;
2026 scratch
[i
++] = FASTTRAP_MOV_ECX
;
2028 switch (tp
->ftt_ripmode
) {
2029 case FASTTRAP_RIP_1
:
2031 uthread
->t_dtrace_reg
= REG_RAX
;
2033 case FASTTRAP_RIP_2
:
2035 uthread
->t_dtrace_reg
= REG_RCX
;
2037 case FASTTRAP_RIP_1
| FASTTRAP_RIP_X
:
2039 uthread
->t_dtrace_reg
= REG_R8
;
2041 case FASTTRAP_RIP_2
| FASTTRAP_RIP_X
:
2043 uthread
->t_dtrace_reg
= REG_R9
;
2047 panic("unhandled ripmode in fasttrap_pid_probe64");
2050 /* LINTED - alignment */
2051 *(uint64_t *)&scratch
[i
] = *reg
;
2052 uthread
->t_dtrace_regv
= *reg
;
2053 *reg
= pc
+ tp
->ftt_size
;
2054 i
+= sizeof (uint64_t);
2058 * Generate the branch instruction to what would have
2059 * normally been the subsequent instruction. In 32-bit mode,
2060 * this is just a relative branch; in 64-bit mode this is a
2061 * %rip-relative branch that loads the 64-bit pc value
2062 * immediately after the jmp instruction.
2064 scratch
[i
++] = FASTTRAP_GROUP5_OP
;
2065 scratch
[i
++] = FASTTRAP_MODRM(0, 4, 5);
2066 /* LINTED - alignment */
2067 *(uint32_t *)&scratch
[i
] = 0;
2068 i
+= sizeof (uint32_t);
2069 /* LINTED - alignment */
2070 *(uint64_t *)&scratch
[i
] = pc
+ tp
->ftt_size
;
2071 i
+= sizeof (uint64_t);
2073 uthread
->t_dtrace_astpc
= addr
+ i
;
2074 bcopy(tp
->ftt_instr
, &scratch
[i
], tp
->ftt_size
);
2076 scratch
[i
++] = FASTTRAP_INT
;
2077 scratch
[i
++] = T_DTRACE_RET
;
2079 ASSERT(i
<= sizeof (scratch
));
2081 if (fasttrap_copyout(scratch
, addr
, i
)) {
2082 fasttrap_sigtrap(p
, uthread
, pc
);
2087 if (tp
->ftt_retids
!= NULL
) {
2088 uthread
->t_dtrace_step
= 1;
2089 uthread
->t_dtrace_ret
= 1;
2090 new_pc
= uthread
->t_dtrace_astpc
;
2092 new_pc
= uthread
->t_dtrace_scrpc
;
2095 uthread
->t_dtrace_pc
= pc
;
2096 uthread
->t_dtrace_npc
= pc
+ tp
->ftt_size
;
2097 uthread
->t_dtrace_on
= 1;
2102 panic("fasttrap: mishandled an instruction");
2109 * We're setting this earlier than Solaris does, to get a "correct"
2110 * ustack() output. In the Sun code, a() -> b() -> c() -> d() is
2111 * reported at: d, b, a. The new way gives c, b, a, which is closer
2112 * to correct, as the return instruction has already exectued.
2114 regs64
->isf
.rip
= new_pc
;
2118 * If there were no return probes when we first found the tracepoint,
2119 * we should feel no obligation to honor any return probes that were
2120 * subsequently enabled -- they'll just have to wait until the next
2123 if (tp
->ftt_retids
!= NULL
) {
2125 * We need to wait until the results of the instruction are
2126 * apparent before invoking any return probes. If this
2127 * instruction was emulated we can just call
2128 * fasttrap_return_common(); if it needs to be executed, we
2129 * need to wait until the user thread returns to the kernel.
2131 if (tp
->ftt_type
!= FASTTRAP_T_COMMON
) {
2132 fasttrap_return_common(regs
, pc
, pid
, new_pc
);
2134 ASSERT(uthread
->t_dtrace_ret
!= 0);
2135 ASSERT(uthread
->t_dtrace_pc
== pc
);
2136 ASSERT(uthread
->t_dtrace_scrpc
!= 0);
2137 ASSERT(new_pc
== uthread
->t_dtrace_astpc
);
2145 fasttrap_pid_probe(x86_saved_state_t
*regs
)
2147 if (is_saved_state64(regs
))
2148 return fasttrap_pid_probe64(regs
);
2150 return fasttrap_pid_probe32(regs
);
2154 fasttrap_return_probe(x86_saved_state_t
*regs
)
2156 x86_saved_state64_t
*regs64
;
2157 x86_saved_state32_t
*regs32
;
2158 unsigned int p_model
;
2160 if (is_saved_state64(regs
)) {
2161 regs64
= saved_state64(regs
);
2163 p_model
= DATAMODEL_LP64
;
2166 regs32
= saved_state32(regs
);
2167 p_model
= DATAMODEL_ILP32
;
2170 proc_t
*p
= current_proc();
2171 uthread_t uthread
= (uthread_t
)get_bsdthread_info(current_thread());
2172 user_addr_t pc
= uthread
->t_dtrace_pc
;
2173 user_addr_t npc
= uthread
->t_dtrace_npc
;
2175 uthread
->t_dtrace_pc
= 0;
2176 uthread
->t_dtrace_npc
= 0;
2177 uthread
->t_dtrace_scrpc
= 0;
2178 uthread
->t_dtrace_astpc
= 0;
2181 * Treat a child created by a call to vfork(2) as if it were its
2182 * parent. We know that there's only one thread of control in such a
2183 * process: this one.
2186 * APPLE NOTE: Terry says: "You need to hold the process locks (currently: kernel funnel) for this traversal"
2187 * How do we assert this?
2189 while (p
->p_lflag
& P_LINVFORK
) {
2194 * We set rp->r_pc to the address of the traced instruction so
2195 * that it appears to dtrace_probe() that we're on the original
2196 * instruction, and so that the user can't easily detect our
2197 * complex web of lies. dtrace_return_probe() (our caller)
2198 * will correctly set %pc after we return.
2200 if (p_model
== DATAMODEL_LP64
)
2201 regs64
->isf
.rip
= pc
;
2205 fasttrap_return_common(regs
, pc
, p
->p_pid
, npc
);
2212 fasttrap_pid_getarg(void *arg
, dtrace_id_t id
, void *parg
, int argno
,
2215 #pragma unused(arg, id, parg, aframes)
2216 return (fasttrap_anarg((x86_saved_state_t
*)find_user_regs(current_thread()), 1, argno
));
2220 fasttrap_usdt_getarg(void *arg
, dtrace_id_t id
, void *parg
, int argno
,
2223 #pragma unused(arg, id, parg, aframes)
2224 return (fasttrap_anarg((x86_saved_state_t
*)find_user_regs(current_thread()), 0, argno
));
2228 * APPLE NOTE: See comments by regmap array definition. We are cheating
2229 * when returning 32 bit registers.
2232 fasttrap_getreg(x86_saved_state_t
*regs
, uint_t reg
)
2234 if (is_saved_state64(regs
)) {
2235 x86_saved_state64_t
*regs64
= saved_state64(regs
);
2238 case REG_RAX
: return regs64
->rax
;
2239 case REG_RCX
: return regs64
->rcx
;
2240 case REG_RDX
: return regs64
->rdx
;
2241 case REG_RBX
: return regs64
->rbx
;
2242 case REG_RSP
: return regs64
->isf
.rsp
;
2243 case REG_RBP
: return regs64
->rbp
;
2244 case REG_RSI
: return regs64
->rsi
;
2245 case REG_RDI
: return regs64
->rdi
;
2246 case REG_R8
: return regs64
->r8
;
2247 case REG_R9
: return regs64
->r9
;
2248 case REG_R10
: return regs64
->r10
;
2249 case REG_R11
: return regs64
->r11
;
2250 case REG_R12
: return regs64
->r12
;
2251 case REG_R13
: return regs64
->r13
;
2252 case REG_R14
: return regs64
->r14
;
2253 case REG_R15
: return regs64
->r15
;
2254 case REG_TRAPNO
: return regs64
->isf
.trapno
;
2255 case REG_ERR
: return regs64
->isf
.err
;
2256 case REG_RIP
: return regs64
->isf
.rip
;
2257 case REG_CS
: return regs64
->isf
.cs
;
2258 case REG_RFL
: return regs64
->isf
.rflags
;
2259 case REG_SS
: return regs64
->isf
.ss
;
2260 case REG_FS
: return regs64
->fs
;
2261 case REG_GS
: return regs64
->gs
;
2266 // Important to distinguish these requests (which should be legal) from other values.
2267 panic("dtrace: unimplemented x86_64 getreg()");
2270 panic("dtrace: unhandled x86_64 getreg() constant");
2272 x86_saved_state32_t
*regs32
= saved_state32(regs
);
2275 case REG_RAX
: return regs32
->eax
;
2276 case REG_RCX
: return regs32
->ecx
;
2277 case REG_RDX
: return regs32
->edx
;
2278 case REG_RBX
: return regs32
->ebx
;
2279 case REG_RSP
: return regs32
->uesp
;
2280 case REG_RBP
: return regs32
->ebp
;
2281 case REG_RSI
: return regs32
->esi
;
2282 case REG_RDI
: return regs32
->edi
;
2285 panic("dtrace: unhandled i386 getreg() constant");