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 #include <machine/pal_routines.h>
50 /* Solaris proc_t is the struct. Darwin's proc_t is a pointer to it. */
51 #define proc_t struct proc /* Steer clear of the Darwin typedef for proc_t */
54 * Lossless User-Land Tracing on x86
55 * ---------------------------------
57 * The execution of most instructions is not dependent on the address; for
58 * these instructions it is sufficient to copy them into the user process's
59 * address space and execute them. To effectively single-step an instruction
60 * in user-land, we copy out the following sequence of instructions to scratch
61 * space in the user thread's ulwp_t structure.
63 * We then set the program counter (%eip or %rip) to point to this scratch
64 * space. Once execution resumes, the original instruction is executed and
65 * then control flow is redirected to what was originally the subsequent
66 * instruction. If the kernel attemps to deliver a signal while single-
67 * stepping, the signal is deferred and the program counter is moved into the
68 * second sequence of instructions. The second sequence ends in a trap into
69 * the kernel where the deferred signal is then properly handled and delivered.
71 * For instructions whose execute is position dependent, we perform simple
72 * emulation. These instructions are limited to control transfer
73 * instructions in 32-bit mode, but in 64-bit mode there's the added wrinkle
74 * of %rip-relative addressing that means that almost any instruction can be
75 * position dependent. For all the details on how we emulate generic
76 * instructions included %rip-relative instructions, see the code in
77 * fasttrap_pid_probe() below where we handle instructions of type
78 * FASTTRAP_T_COMMON (under the header: Generic Instruction Tracing).
81 #define FASTTRAP_MODRM_MOD(modrm) (((modrm) >> 6) & 0x3)
82 #define FASTTRAP_MODRM_REG(modrm) (((modrm) >> 3) & 0x7)
83 #define FASTTRAP_MODRM_RM(modrm) ((modrm) & 0x7)
84 #define FASTTRAP_MODRM(mod, reg, rm) (((mod) << 6) | ((reg) << 3) | (rm))
86 #define FASTTRAP_SIB_SCALE(sib) (((sib) >> 6) & 0x3)
87 #define FASTTRAP_SIB_INDEX(sib) (((sib) >> 3) & 0x7)
88 #define FASTTRAP_SIB_BASE(sib) ((sib) & 0x7)
90 #define FASTTRAP_REX_W(rex) (((rex) >> 3) & 1)
91 #define FASTTRAP_REX_R(rex) (((rex) >> 2) & 1)
92 #define FASTTRAP_REX_X(rex) (((rex) >> 1) & 1)
93 #define FASTTRAP_REX_B(rex) ((rex) & 1)
94 #define FASTTRAP_REX(w, r, x, b) \
95 (0x40 | ((w) << 3) | ((r) << 2) | ((x) << 1) | (b))
98 * Single-byte op-codes.
100 #define FASTTRAP_PUSHL_EBP 0x55
102 #define FASTTRAP_JO 0x70
103 #define FASTTRAP_JNO 0x71
104 #define FASTTRAP_JB 0x72
105 #define FASTTRAP_JAE 0x73
106 #define FASTTRAP_JE 0x74
107 #define FASTTRAP_JNE 0x75
108 #define FASTTRAP_JBE 0x76
109 #define FASTTRAP_JA 0x77
110 #define FASTTRAP_JS 0x78
111 #define FASTTRAP_JNS 0x79
112 #define FASTTRAP_JP 0x7a
113 #define FASTTRAP_JNP 0x7b
114 #define FASTTRAP_JL 0x7c
115 #define FASTTRAP_JGE 0x7d
116 #define FASTTRAP_JLE 0x7e
117 #define FASTTRAP_JG 0x7f
119 #define FASTTRAP_NOP 0x90
121 #define FASTTRAP_MOV_EAX 0xb8
122 #define FASTTRAP_MOV_ECX 0xb9
124 #define FASTTRAP_RET16 0xc2
125 #define FASTTRAP_RET 0xc3
127 #define FASTTRAP_LOOPNZ 0xe0
128 #define FASTTRAP_LOOPZ 0xe1
129 #define FASTTRAP_LOOP 0xe2
130 #define FASTTRAP_JCXZ 0xe3
132 #define FASTTRAP_CALL 0xe8
133 #define FASTTRAP_JMP32 0xe9
134 #define FASTTRAP_JMP8 0xeb
136 #define FASTTRAP_INT3 0xcc
137 #define FASTTRAP_INT 0xcd
138 #define T_DTRACE_RET 0x7f
140 #define FASTTRAP_2_BYTE_OP 0x0f
141 #define FASTTRAP_GROUP5_OP 0xff
144 * Two-byte op-codes (second byte only).
146 #define FASTTRAP_0F_JO 0x80
147 #define FASTTRAP_0F_JNO 0x81
148 #define FASTTRAP_0F_JB 0x82
149 #define FASTTRAP_0F_JAE 0x83
150 #define FASTTRAP_0F_JE 0x84
151 #define FASTTRAP_0F_JNE 0x85
152 #define FASTTRAP_0F_JBE 0x86
153 #define FASTTRAP_0F_JA 0x87
154 #define FASTTRAP_0F_JS 0x88
155 #define FASTTRAP_0F_JNS 0x89
156 #define FASTTRAP_0F_JP 0x8a
157 #define FASTTRAP_0F_JNP 0x8b
158 #define FASTTRAP_0F_JL 0x8c
159 #define FASTTRAP_0F_JGE 0x8d
160 #define FASTTRAP_0F_JLE 0x8e
161 #define FASTTRAP_0F_JG 0x8f
163 #define FASTTRAP_EFLAGS_OF 0x800
164 #define FASTTRAP_EFLAGS_DF 0x400
165 #define FASTTRAP_EFLAGS_SF 0x080
166 #define FASTTRAP_EFLAGS_ZF 0x040
167 #define FASTTRAP_EFLAGS_AF 0x010
168 #define FASTTRAP_EFLAGS_PF 0x004
169 #define FASTTRAP_EFLAGS_CF 0x001
172 * Instruction prefixes.
174 #define FASTTRAP_PREFIX_OPERAND 0x66
175 #define FASTTRAP_PREFIX_ADDRESS 0x67
176 #define FASTTRAP_PREFIX_CS 0x2E
177 #define FASTTRAP_PREFIX_DS 0x3E
178 #define FASTTRAP_PREFIX_ES 0x26
179 #define FASTTRAP_PREFIX_FS 0x64
180 #define FASTTRAP_PREFIX_GS 0x65
181 #define FASTTRAP_PREFIX_SS 0x36
182 #define FASTTRAP_PREFIX_LOCK 0xF0
183 #define FASTTRAP_PREFIX_REP 0xF3
184 #define FASTTRAP_PREFIX_REPNE 0xF2
186 #define FASTTRAP_NOREG 0xff
189 * Map between instruction register encodings and the kernel constants which
190 * correspond to indicies into struct regs.
194 * APPLE NOTE: We are cheating here. The regmap is used to decode which register
195 * a given instruction is trying to reference. OS X does not have extended registers
196 * for 32 bit apps, but the *order* is the same. So for 32 bit state, we will return:
203 * The fasttrap_getreg function knows how to make the correct transformation.
205 #if __sol64 || defined(__APPLE__)
206 static const uint8_t regmap
[16] = {
207 REG_RAX
, REG_RCX
, REG_RDX
, REG_RBX
, REG_RSP
, REG_RBP
, REG_RSI
, REG_RDI
,
208 REG_R8
, REG_R9
, REG_R10
, REG_R11
, REG_R12
, REG_R13
, REG_R14
, REG_R15
,
211 static const uint8_t regmap
[8] = {
212 EAX
, ECX
, EDX
, EBX
, UESP
, EBP
, ESI
, EDI
216 static user_addr_t
fasttrap_getreg(x86_saved_state_t
*, uint_t
);
219 fasttrap_anarg(x86_saved_state_t
*regs
, int function_entry
, int argno
)
222 int shift
= function_entry
? 1 : 0;
224 x86_saved_state64_t
*regs64
;
225 x86_saved_state32_t
*regs32
;
226 unsigned int p_model
;
228 if (is_saved_state64(regs
)) {
229 regs64
= saved_state64(regs
);
231 p_model
= DATAMODEL_LP64
;
234 regs32
= saved_state32(regs
);
235 p_model
= DATAMODEL_ILP32
;
238 if (p_model
== DATAMODEL_LP64
) {
242 * In 64-bit mode, the first six arguments are stored in
246 return ((®s64
->rdi
)[argno
]);
248 stack
= regs64
->isf
.rsp
+ sizeof(uint64_t) * (argno
- 6 + shift
);
249 DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT
);
250 value
= dtrace_fuword64(stack
);
251 DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT
| CPU_DTRACE_BADADDR
);
253 uint32_t *stack
= (uint32_t *)(uintptr_t)(regs32
->uesp
);
254 DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT
);
255 value
= dtrace_fuword32((user_addr_t
)(unsigned long)&stack
[argno
+ shift
]);
256 DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT
| CPU_DTRACE_BADADDR
);
264 fasttrap_tracepoint_init(proc_t
*p
, fasttrap_tracepoint_t
*tp
, user_addr_t pc
,
265 fasttrap_probe_type_t type
)
268 uint8_t instr
[FASTTRAP_MAX_INSTR_SIZE
+ 10];
269 size_t len
= FASTTRAP_MAX_INSTR_SIZE
;
270 size_t first
= MIN(len
, PAGE_SIZE
- (pc
& PAGE_MASK
));
274 uint8_t seg
, rex
= 0;
275 unsigned int p_model
= (p
->p_flag
& P_LP64
) ? DATAMODEL_LP64
: DATAMODEL_ILP32
;
278 * Read the instruction at the given address out of the process's
279 * address space. We don't have to worry about a debugger
280 * changing this instruction before we overwrite it with our trap
281 * instruction since P_PR_LOCK is set. Since instructions can span
282 * pages, we potentially read the instruction in two parts. If the
283 * second part fails, we just zero out that part of the instruction.
286 * APPLE NOTE: Of course, we do not have a P_PR_LOCK, so this is racey...
288 if (uread(p
, &instr
[0], first
, pc
) != 0)
291 uread(p
, &instr
[first
], len
- first
, pc
+ first
) != 0) {
292 bzero(&instr
[first
], len
- first
);
297 * If the disassembly fails, then we have a malformed instruction.
299 if ((size
= dtrace_instr_size_isa(instr
, p_model
, &rmindex
)) <= 0)
303 * Make sure the disassembler isn't completely broken.
305 ASSERT(-1 <= rmindex
&& rmindex
< (int)size
);
308 * If the computed size is greater than the number of bytes read,
309 * then it was a malformed instruction possibly because it fell on a
310 * page boundary and the subsequent page was missing or because of
311 * some malicious user.
316 tp
->ftt_size
= (uint8_t)size
;
317 tp
->ftt_segment
= FASTTRAP_SEG_NONE
;
320 * Find the start of the instruction's opcode by processing any
325 switch (instr
[start
]) {
326 case FASTTRAP_PREFIX_SS
:
329 case FASTTRAP_PREFIX_GS
:
332 case FASTTRAP_PREFIX_FS
:
335 case FASTTRAP_PREFIX_ES
:
338 case FASTTRAP_PREFIX_DS
:
341 case FASTTRAP_PREFIX_CS
:
344 case FASTTRAP_PREFIX_OPERAND
:
345 case FASTTRAP_PREFIX_ADDRESS
:
346 case FASTTRAP_PREFIX_LOCK
:
347 case FASTTRAP_PREFIX_REP
:
348 case FASTTRAP_PREFIX_REPNE
:
351 * It's illegal for an instruction to specify
352 * two segment prefixes -- give up on this
353 * illegal instruction.
355 if (tp
->ftt_segment
!= FASTTRAP_SEG_NONE
)
358 tp
->ftt_segment
= seg
;
366 #if __sol64 || defined(__APPLE__)
368 * Identify the REX prefix on 64-bit processes.
370 if (p_model
== DATAMODEL_LP64
&& (instr
[start
] & 0xf0) == 0x40)
371 rex
= instr
[start
++];
375 * Now that we're pretty sure that the instruction is okay, copy the
376 * valid part to the tracepoint.
378 bcopy(instr
, tp
->ftt_instr
, FASTTRAP_MAX_INSTR_SIZE
);
380 tp
->ftt_type
= FASTTRAP_T_COMMON
;
381 if (instr
[start
] == FASTTRAP_2_BYTE_OP
) {
382 switch (instr
[start
+ 1]) {
384 case FASTTRAP_0F_JNO
:
386 case FASTTRAP_0F_JAE
:
388 case FASTTRAP_0F_JNE
:
389 case FASTTRAP_0F_JBE
:
392 case FASTTRAP_0F_JNS
:
394 case FASTTRAP_0F_JNP
:
396 case FASTTRAP_0F_JGE
:
397 case FASTTRAP_0F_JLE
:
399 tp
->ftt_type
= FASTTRAP_T_JCC
;
400 tp
->ftt_code
= (instr
[start
+ 1] & 0x0f) | FASTTRAP_JO
;
401 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
402 /* LINTED - alignment */
403 *(int32_t *)&instr
[start
+ 2];
406 } else if (instr
[start
] == FASTTRAP_GROUP5_OP
) {
407 uint_t mod
= FASTTRAP_MODRM_MOD(instr
[start
+ 1]);
408 uint_t reg
= FASTTRAP_MODRM_REG(instr
[start
+ 1]);
409 uint_t rm
= FASTTRAP_MODRM_RM(instr
[start
+ 1]);
411 if (reg
== 2 || reg
== 4) {
415 tp
->ftt_type
= FASTTRAP_T_CALL
;
417 tp
->ftt_type
= FASTTRAP_T_JMP
;
424 ASSERT(p_model
== DATAMODEL_LP64
|| rex
== 0);
427 * See AMD x86-64 Architecture Programmer's Manual
428 * Volume 3, Section 1.2.7, Table 1-12, and
429 * Appendix A.3.1, Table A-15.
431 if (mod
!= 3 && rm
== 4) {
432 uint8_t sib
= instr
[start
+ 2];
433 uint_t index
= FASTTRAP_SIB_INDEX(sib
);
434 uint_t base
= FASTTRAP_SIB_BASE(sib
);
436 tp
->ftt_scale
= FASTTRAP_SIB_SCALE(sib
);
438 tp
->ftt_index
= (index
== 4) ?
440 regmap
[index
| (FASTTRAP_REX_X(rex
) << 3)];
441 tp
->ftt_base
= (mod
== 0 && base
== 5) ?
443 regmap
[base
| (FASTTRAP_REX_B(rex
) << 3)];
446 sz
= mod
== 1 ? 1 : 4;
449 * In 64-bit mode, mod == 0 and r/m == 5
450 * denotes %rip-relative addressing; in 32-bit
451 * mode, the base register isn't used. In both
452 * modes, there is a 32-bit operand.
454 if (mod
== 0 && rm
== 5) {
455 #if __sol64 || defined(__APPLE__)
456 if (p_model
== DATAMODEL_LP64
)
457 tp
->ftt_base
= REG_RIP
;
460 tp
->ftt_base
= FASTTRAP_NOREG
;
464 (FASTTRAP_REX_B(rex
) << 3);
466 tp
->ftt_base
= regmap
[base
];
467 sz
= mod
== 1 ? 1 : mod
== 2 ? 4 : 0;
469 tp
->ftt_index
= FASTTRAP_NOREG
;
474 tp
->ftt_dest
= *(int8_t *)&instr
[start
+ i
];
475 } else if (sz
== 4) {
476 /* LINTED - alignment */
477 tp
->ftt_dest
= *(int32_t *)&instr
[start
+ i
];
483 switch (instr
[start
]) {
485 tp
->ftt_type
= FASTTRAP_T_RET
;
489 tp
->ftt_type
= FASTTRAP_T_RET16
;
490 /* LINTED - alignment */
491 tp
->ftt_dest
= *(uint16_t *)&instr
[start
+ 1];
510 tp
->ftt_type
= FASTTRAP_T_JCC
;
511 tp
->ftt_code
= instr
[start
];
512 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
513 (int8_t)instr
[start
+ 1];
516 case FASTTRAP_LOOPNZ
:
519 tp
->ftt_type
= FASTTRAP_T_LOOP
;
520 tp
->ftt_code
= instr
[start
];
521 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
522 (int8_t)instr
[start
+ 1];
526 tp
->ftt_type
= FASTTRAP_T_JCXZ
;
527 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
528 (int8_t)instr
[start
+ 1];
532 tp
->ftt_type
= FASTTRAP_T_CALL
;
533 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
534 /* LINTED - alignment */
535 *(int32_t *)&instr
[start
+ 1];
540 tp
->ftt_type
= FASTTRAP_T_JMP
;
541 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
542 /* LINTED - alignment */
543 *(int32_t *)&instr
[start
+ 1];
546 tp
->ftt_type
= FASTTRAP_T_JMP
;
547 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
548 (int8_t)instr
[start
+ 1];
551 case FASTTRAP_PUSHL_EBP
:
553 tp
->ftt_type
= FASTTRAP_T_PUSHL_EBP
;
557 #if __sol64 || defined(__APPLE__)
558 ASSERT(p_model
== DATAMODEL_LP64
|| rex
== 0);
561 * On sol64 we have to be careful not to confuse a nop
562 * (actually xchgl %eax, %eax) with an instruction using
563 * the same opcode, but that does something different
564 * (e.g. xchgl %r8d, %eax or xcghq %r8, %rax).
566 if (FASTTRAP_REX_B(rex
) == 0)
568 tp
->ftt_type
= FASTTRAP_T_NOP
;
573 * The pid provider shares the int3 trap with debugger
574 * breakpoints so we can't instrument them.
576 ASSERT(instr
[start
] == FASTTRAP_INSTR
);
581 * Interrupts seem like they could be traced with
582 * no negative implications, but it's possible that
583 * a thread could be redirected by the trap handling
584 * code which would eventually return to the
585 * instruction after the interrupt. If the interrupt
586 * were in our scratch space, the subsequent
587 * instruction might be overwritten before we return.
588 * Accordingly we refuse to instrument any interrupt.
594 #if __sol64 || defined(__APPLE__)
595 if (p_model
== DATAMODEL_LP64
&& tp
->ftt_type
== FASTTRAP_T_COMMON
) {
597 * If the process is 64-bit and the instruction type is still
598 * FASTTRAP_T_COMMON -- meaning we're going to copy it out an
599 * execute it -- we need to watch for %rip-relative
600 * addressing mode. See the portion of fasttrap_pid_probe()
601 * below where we handle tracepoints with type
602 * FASTTRAP_T_COMMON for how we emulate instructions that
603 * employ %rip-relative addressing.
606 uint_t mod
= FASTTRAP_MODRM_MOD(instr
[rmindex
]);
607 uint_t reg
= FASTTRAP_MODRM_REG(instr
[rmindex
]);
608 uint_t rm
= FASTTRAP_MODRM_RM(instr
[rmindex
]);
610 ASSERT(rmindex
> (int)start
);
612 if (mod
== 0 && rm
== 5) {
614 * We need to be sure to avoid other
615 * registers used by this instruction. While
616 * the reg field may determine the op code
617 * rather than denoting a register, assuming
618 * that it denotes a register is always safe.
619 * We leave the REX field intact and use
620 * whatever value's there for simplicity.
623 tp
->ftt_ripmode
= FASTTRAP_RIP_1
|
625 FASTTRAP_REX_B(rex
));
628 tp
->ftt_ripmode
= FASTTRAP_RIP_2
|
630 FASTTRAP_REX_B(rex
));
634 tp
->ftt_modrm
= tp
->ftt_instr
[rmindex
];
635 tp
->ftt_instr
[rmindex
] =
636 FASTTRAP_MODRM(2, reg
, rm
);
646 fasttrap_tracepoint_install(proc_t
*p
, fasttrap_tracepoint_t
*tp
)
648 fasttrap_instr_t instr
= FASTTRAP_INSTR
;
650 if (uwrite(p
, &instr
, 1, tp
->ftt_pc
) != 0)
657 fasttrap_tracepoint_remove(proc_t
*p
, fasttrap_tracepoint_t
*tp
)
662 * Distinguish between read or write failures and a changed
665 if (uread(p
, &instr
, 1, tp
->ftt_pc
) != 0)
667 if (instr
!= FASTTRAP_INSTR
)
669 if (uwrite(p
, &tp
->ftt_instr
[0], 1, tp
->ftt_pc
) != 0)
676 fasttrap_return_common(x86_saved_state_t
*regs
, user_addr_t pc
, pid_t pid
,
679 x86_saved_state64_t
*regs64
;
680 x86_saved_state32_t
*regs32
;
681 unsigned int p_model
;
683 dtrace_icookie_t cookie
;
685 if (is_saved_state64(regs
)) {
686 regs64
= saved_state64(regs
);
688 p_model
= DATAMODEL_LP64
;
691 regs32
= saved_state32(regs
);
692 p_model
= DATAMODEL_ILP32
;
695 fasttrap_tracepoint_t
*tp
;
696 fasttrap_bucket_t
*bucket
;
700 pid_mtx
= &cpu_core
[CPU
->cpu_id
].cpuc_pid_lock
;
701 lck_mtx_lock(pid_mtx
);
702 bucket
= &fasttrap_tpoints
.fth_table
[FASTTRAP_TPOINTS_INDEX(pid
, pc
)];
704 for (tp
= bucket
->ftb_data
; tp
!= NULL
; tp
= tp
->ftt_next
) {
705 if (pid
== tp
->ftt_pid
&& pc
== tp
->ftt_pc
&&
706 tp
->ftt_proc
->ftpc_acount
!= 0)
711 * Don't sweat it if we can't find the tracepoint again; unlike
712 * when we're in fasttrap_pid_probe(), finding the tracepoint here
713 * is not essential to the correct execution of the process.
716 lck_mtx_unlock(pid_mtx
);
720 for (id
= tp
->ftt_retids
; id
!= NULL
; id
= id
->fti_next
) {
722 * If there's a branch that could act as a return site, we
723 * need to trace it, and check here if the program counter is
724 * external to the function.
726 if (tp
->ftt_type
!= FASTTRAP_T_RET
&&
727 tp
->ftt_type
!= FASTTRAP_T_RET16
&&
728 new_pc
- id
->fti_probe
->ftp_faddr
<
729 id
->fti_probe
->ftp_fsize
)
733 * Provide a hint to the stack trace functions to add the
734 * following pc to the top of the stack since it's missing
735 * on a return probe yet highly desirable for consistency.
737 cookie
= dtrace_interrupt_disable();
738 cpu_core
[CPU
->cpu_id
].cpuc_missing_tos
= pc
;
739 if (ISSET(current_proc()->p_lflag
, P_LNOATTACH
)) {
740 dtrace_probe(dtrace_probeid_error
, 0 /* state */, id
->fti_probe
->ftp_id
,
741 1 /* ndx */, -1 /* offset */, DTRACEFLT_UPRIV
);
742 } else if (p_model
== DATAMODEL_LP64
) {
743 dtrace_probe(id
->fti_probe
->ftp_id
,
744 pc
- id
->fti_probe
->ftp_faddr
,
745 regs64
->rax
, regs64
->rdx
, 0, 0);
747 dtrace_probe(id
->fti_probe
->ftp_id
,
748 pc
- id
->fti_probe
->ftp_faddr
,
749 regs32
->eax
, regs32
->edx
, 0, 0);
751 /* remove the hint */
752 cpu_core
[CPU
->cpu_id
].cpuc_missing_tos
= 0;
753 dtrace_interrupt_enable(cookie
);
756 lck_mtx_unlock(pid_mtx
);
760 fasttrap_sigsegv(proc_t
*p
, uthread_t t
, user_addr_t addr
)
764 /* Set fault address and mark signal */
766 t
->uu_siglist
|= sigmask(SIGSEGV
);
769 * XXX These two line may be redundant; if not, then we need
770 * XXX to potentially set the data address in the machine
771 * XXX specific thread state structure to indicate the address.
773 t
->uu_exception
= KERN_INVALID_ADDRESS
; /* SIGSEGV */
774 t
->uu_subcode
= 0; /* XXX pad */
779 signal_setast(t
->uu_context
.vc_thread
);
783 fasttrap_usdt_args64(fasttrap_probe_t
*probe
, x86_saved_state64_t
*regs64
, int argc
,
786 int i
, x
, cap
= MIN(argc
, probe
->ftp_nargs
);
787 user_addr_t stack
= (user_addr_t
)regs64
->isf
.rsp
;
789 for (i
= 0; i
< cap
; i
++) {
790 x
= probe
->ftp_argmap
[i
];
793 /* FIXME! This may be broken, needs testing */
794 argv
[i
] = (®s64
->rdi
)[x
];
796 fasttrap_fuword64_noerr(stack
+ (x
* sizeof(uint64_t)), &argv
[i
]);
800 for (; i
< argc
; i
++) {
806 fasttrap_usdt_args32(fasttrap_probe_t
*probe
, x86_saved_state32_t
*regs32
, int argc
,
809 int i
, x
, cap
= MIN(argc
, probe
->ftp_nargs
);
810 uint32_t *stack
= (uint32_t *)(uintptr_t)(regs32
->uesp
);
812 for (i
= 0; i
< cap
; i
++) {
813 x
= probe
->ftp_argmap
[i
];
815 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[x
], &argv
[i
]);
818 for (; i
< argc
; i
++) {
827 fasttrap_do_seg(fasttrap_tracepoint_t
*tp
, x86_saved_state_t
*rp
, user_addr_t
*addr
) // 64 bit
829 #pragma unused(tp, rp, addr)
830 printf("fasttrap_do_seg() called while unimplemented.\n");
834 uint16_t sel
, ndx
, type
;
837 switch (tp
->ftt_segment
) {
838 case FASTTRAP_SEG_CS
:
841 case FASTTRAP_SEG_DS
:
844 case FASTTRAP_SEG_ES
:
847 case FASTTRAP_SEG_FS
:
850 case FASTTRAP_SEG_GS
:
853 case FASTTRAP_SEG_SS
:
859 * Make sure the given segment register specifies a user priority
860 * selector rather than a kernel selector.
868 * Check the bounds and grab the descriptor out of the specified
872 if (ndx
> p
->p_ldtlimit
)
875 desc
= p
->p_ldt
+ ndx
;
881 desc
= cpu_get_gdt() + ndx
;
885 * The descriptor must have user privilege level and it must be
888 if (desc
->usd_dpl
!= SEL_UPL
|| desc
->usd_p
!= 1)
891 type
= desc
->usd_type
;
894 * If the S bit in the type field is not set, this descriptor can
895 * only be used in system context.
897 if ((type
& 0x10) != 0x10)
900 limit
= USEGD_GETLIMIT(desc
) * (desc
->usd_gran
? PAGESIZE
: 1);
902 if (tp
->ftt_segment
== FASTTRAP_SEG_CS
) {
904 * The code/data bit and readable bit must both be set.
906 if ((type
& 0xa) != 0xa)
913 * The code/data bit must be clear.
915 if ((type
& 0x8) != 0)
919 * If the expand-down bit is clear, we just check the limit as
920 * it would naturally be applied. Otherwise, we need to check
921 * that the address is the range [limit + 1 .. 0xffff] or
922 * [limit + 1 ... 0xffffffff] depending on if the default
923 * operand size bit is set.
925 if ((type
& 0x4) == 0) {
928 } else if (desc
->usd_def32
) {
929 if (*addr
< limit
+ 1 || 0xffff < *addr
)
932 if (*addr
< limit
+ 1 || 0xffffffff < *addr
)
937 *addr
+= USEGD_GETBASE(desc
);
943 * Due to variances between Solaris and xnu, I have split this into a 32 bit and 64 bit
944 * code path. It still takes an x86_saved_state_t* argument, because it must sometimes
945 * call other methods that require a x86_saved_state_t.
949 * Any changes made to this method must be echo'd in fasttrap_pid_probe64!
953 fasttrap_pid_probe32(x86_saved_state_t
*regs
)
955 ASSERT(is_saved_state32(regs
));
957 x86_saved_state32_t
*regs32
= saved_state32(regs
);
958 user_addr_t pc
= regs32
->eip
- 1;
959 proc_t
*p
= current_proc();
960 user_addr_t new_pc
= 0;
961 fasttrap_bucket_t
*bucket
;
963 fasttrap_tracepoint_t
*tp
, tp_local
;
965 dtrace_icookie_t cookie
;
966 uint_t is_enabled
= 0;
968 uthread_t uthread
= (uthread_t
)get_bsdthread_info(current_thread());
971 * It's possible that a user (in a veritable orgy of bad planning)
972 * could redirect this thread's flow of control before it reached the
973 * return probe fasttrap. In this case we need to kill the process
974 * since it's in a unrecoverable state.
976 if (uthread
->t_dtrace_step
) {
977 ASSERT(uthread
->t_dtrace_on
);
978 fasttrap_sigtrap(p
, uthread
, pc
);
983 * Clear all user tracing flags.
985 uthread
->t_dtrace_ft
= 0;
986 uthread
->t_dtrace_pc
= 0;
987 uthread
->t_dtrace_npc
= 0;
988 uthread
->t_dtrace_scrpc
= 0;
989 uthread
->t_dtrace_astpc
= 0;
992 * Treat a child created by a call to vfork(2) as if it were its
993 * parent. We know that there's only one thread of control in such a
997 * APPLE NOTE: Terry says: "You need to hold the process locks (currently: kernel funnel) for this traversal"
998 * FIXME: How do we assert this?
1000 while (p
->p_lflag
& P_LINVFORK
)
1004 pid_mtx
= &cpu_core
[CPU
->cpu_id
].cpuc_pid_lock
;
1005 lck_mtx_lock(pid_mtx
);
1006 bucket
= &fasttrap_tpoints
.fth_table
[FASTTRAP_TPOINTS_INDEX(pid
, pc
)];
1009 * Lookup the tracepoint that the process just hit.
1011 for (tp
= bucket
->ftb_data
; tp
!= NULL
; tp
= tp
->ftt_next
) {
1012 if (pid
== tp
->ftt_pid
&& pc
== tp
->ftt_pc
&&
1013 tp
->ftt_proc
->ftpc_acount
!= 0)
1018 * If we couldn't find a matching tracepoint, either a tracepoint has
1019 * been inserted without using the pid<pid> ioctl interface (see
1020 * fasttrap_ioctl), or somehow we have mislaid this tracepoint.
1023 lck_mtx_unlock(pid_mtx
);
1028 * Set the program counter to the address of the traced instruction
1029 * so that it looks right in ustack() output.
1033 if (tp
->ftt_ids
!= NULL
) {
1036 uint32_t s0
, s1
, s2
, s3
, s4
, s5
;
1037 uint32_t *stack
= (uint32_t *)(uintptr_t)(regs32
->uesp
);
1040 * In 32-bit mode, all arguments are passed on the
1041 * stack. If this is a function entry probe, we need
1042 * to skip the first entry on the stack as it
1043 * represents the return address rather than a
1044 * parameter to the function.
1046 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[0], &s0
);
1047 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[1], &s1
);
1048 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[2], &s2
);
1049 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[3], &s3
);
1050 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[4], &s4
);
1051 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[5], &s5
);
1053 for (id
= tp
->ftt_ids
; id
!= NULL
; id
= id
->fti_next
) {
1054 fasttrap_probe_t
*probe
= id
->fti_probe
;
1056 if (ISSET(current_proc()->p_lflag
, P_LNOATTACH
)) {
1057 dtrace_probe(dtrace_probeid_error
, 0 /* state */, probe
->ftp_id
,
1058 1 /* ndx */, -1 /* offset */, DTRACEFLT_UPRIV
);
1059 } else if (id
->fti_ptype
== DTFTP_ENTRY
) {
1061 * We note that this was an entry
1062 * probe to help ustack() find the
1065 cookie
= dtrace_interrupt_disable();
1066 DTRACE_CPUFLAG_SET(CPU_DTRACE_ENTRY
);
1067 dtrace_probe(probe
->ftp_id
, s1
, s2
,
1069 DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_ENTRY
);
1070 dtrace_interrupt_enable(cookie
);
1071 } else if (id
->fti_ptype
== DTFTP_IS_ENABLED
) {
1073 * Note that in this case, we don't
1074 * call dtrace_probe() since it's only
1075 * an artificial probe meant to change
1076 * the flow of control so that it
1077 * encounters the true probe.
1080 } else if (probe
->ftp_argmap
== NULL
) {
1081 dtrace_probe(probe
->ftp_id
, s0
, s1
,
1086 fasttrap_usdt_args32(probe
, regs32
,
1087 sizeof (t
) / sizeof (t
[0]), t
);
1089 dtrace_probe(probe
->ftp_id
, t
[0], t
[1],
1093 /* APPLE NOTE: Oneshot probes get one and only one chance... */
1094 if (probe
->ftp_prov
->ftp_provider_type
== DTFTP_PROVIDER_ONESHOT
) {
1095 fasttrap_tracepoint_remove(p
, tp
);
1101 * We're about to do a bunch of work so we cache a local copy of
1102 * the tracepoint to emulate the instruction, and then find the
1103 * tracepoint again later if we need to light up any return probes.
1106 lck_mtx_unlock(pid_mtx
);
1110 * Set the program counter to appear as though the traced instruction
1111 * had completely executed. This ensures that fasttrap_getreg() will
1112 * report the expected value for REG_RIP.
1114 regs32
->eip
= pc
+ tp
->ftt_size
;
1117 * If there's an is-enabled probe connected to this tracepoint it
1118 * means that there was a 'xorl %eax, %eax' or 'xorq %rax, %rax'
1119 * instruction that was placed there by DTrace when the binary was
1120 * linked. As this probe is, in fact, enabled, we need to stuff 1
1121 * into %eax or %rax. Accordingly, we can bypass all the instruction
1122 * emulation logic since we know the inevitable result. It's possible
1123 * that a user could construct a scenario where the 'is-enabled'
1124 * probe was on some other instruction, but that would be a rather
1125 * exotic way to shoot oneself in the foot.
1129 new_pc
= regs32
->eip
;
1134 * We emulate certain types of instructions to ensure correctness
1135 * (in the case of position dependent instructions) or optimize
1136 * common cases. The rest we have the thread execute back in user-
1139 switch (tp
->ftt_type
) {
1140 case FASTTRAP_T_RET
:
1141 case FASTTRAP_T_RET16
:
1148 * We have to emulate _every_ facet of the behavior of a ret
1149 * instruction including what happens if the load from %esp
1150 * fails; in that case, we send a SIGSEGV.
1153 ret
= fasttrap_fuword32((user_addr_t
)regs32
->uesp
, &dst32
);
1155 addr
= regs32
->uesp
+ sizeof (uint32_t);
1158 fasttrap_sigsegv(p
, uthread
, (user_addr_t
)regs32
->uesp
);
1163 if (tp
->ftt_type
== FASTTRAP_T_RET16
)
1164 addr
+= tp
->ftt_dest
;
1166 regs32
->uesp
= addr
;
1171 case FASTTRAP_T_JCC
:
1175 switch (tp
->ftt_code
) {
1177 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_OF
) != 0;
1180 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_OF
) == 0;
1183 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_CF
) != 0;
1186 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_CF
) == 0;
1189 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) != 0;
1192 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) == 0;
1195 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_CF
) != 0 ||
1196 (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) != 0;
1199 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_CF
) == 0 &&
1200 (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) == 0;
1203 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_SF
) != 0;
1206 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_SF
) == 0;
1209 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_PF
) != 0;
1212 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_PF
) == 0;
1215 taken
= ((regs32
->efl
& FASTTRAP_EFLAGS_SF
) == 0) !=
1216 ((regs32
->efl
& FASTTRAP_EFLAGS_OF
) == 0);
1219 taken
= ((regs32
->efl
& FASTTRAP_EFLAGS_SF
) == 0) ==
1220 ((regs32
->efl
& FASTTRAP_EFLAGS_OF
) == 0);
1223 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) != 0 ||
1224 ((regs32
->efl
& FASTTRAP_EFLAGS_SF
) == 0) !=
1225 ((regs32
->efl
& FASTTRAP_EFLAGS_OF
) == 0);
1228 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) == 0 &&
1229 ((regs32
->efl
& FASTTRAP_EFLAGS_SF
) == 0) ==
1230 ((regs32
->efl
& FASTTRAP_EFLAGS_OF
) == 0);
1237 new_pc
= tp
->ftt_dest
;
1239 new_pc
= pc
+ tp
->ftt_size
;
1243 case FASTTRAP_T_LOOP
:
1246 greg_t cx
= regs32
->ecx
--;
1248 switch (tp
->ftt_code
) {
1249 case FASTTRAP_LOOPNZ
:
1250 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) == 0 &&
1253 case FASTTRAP_LOOPZ
:
1254 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) != 0 &&
1265 new_pc
= tp
->ftt_dest
;
1267 new_pc
= pc
+ tp
->ftt_size
;
1271 case FASTTRAP_T_JCXZ
:
1273 greg_t cx
= regs32
->ecx
;
1276 new_pc
= tp
->ftt_dest
;
1278 new_pc
= pc
+ tp
->ftt_size
;
1282 case FASTTRAP_T_PUSHL_EBP
:
1284 user_addr_t addr
= regs32
->uesp
- sizeof (uint32_t);
1285 int ret
= fasttrap_suword32(addr
, (uint32_t)regs32
->ebp
);
1288 fasttrap_sigsegv(p
, uthread
, addr
);
1293 regs32
->uesp
= addr
;
1294 new_pc
= pc
+ tp
->ftt_size
;
1298 case FASTTRAP_T_NOP
:
1299 new_pc
= pc
+ tp
->ftt_size
;
1302 case FASTTRAP_T_JMP
:
1303 case FASTTRAP_T_CALL
:
1304 if (tp
->ftt_code
== 0) {
1305 new_pc
= tp
->ftt_dest
;
1307 user_addr_t
/* value ,*/ addr
= tp
->ftt_dest
;
1309 if (tp
->ftt_base
!= FASTTRAP_NOREG
)
1310 addr
+= fasttrap_getreg(regs
, tp
->ftt_base
);
1311 if (tp
->ftt_index
!= FASTTRAP_NOREG
)
1312 addr
+= fasttrap_getreg(regs
, tp
->ftt_index
) <<
1315 if (tp
->ftt_code
== 1) {
1317 * If there's a segment prefix for this
1318 * instruction, we'll need to check permissions
1319 * and bounds on the given selector, and adjust
1320 * the address accordingly.
1322 if (tp
->ftt_segment
!= FASTTRAP_SEG_NONE
&&
1323 fasttrap_do_seg(tp
, regs
, &addr
) != 0) {
1324 fasttrap_sigsegv(p
, uthread
, addr
);
1330 addr
= (user_addr_t
)(uint32_t)addr
;
1331 if (fasttrap_fuword32(addr
, &value32
) == -1) {
1332 fasttrap_sigsegv(p
, uthread
, addr
);
1343 * If this is a call instruction, we need to push the return
1344 * address onto the stack. If this fails, we send the process
1345 * a SIGSEGV and reset the pc to emulate what would happen if
1346 * this instruction weren't traced.
1348 if (tp
->ftt_type
== FASTTRAP_T_CALL
) {
1349 user_addr_t addr
= regs32
->uesp
- sizeof (uint32_t);
1350 int ret
= fasttrap_suword32(addr
, (uint32_t)(pc
+ tp
->ftt_size
));
1353 fasttrap_sigsegv(p
, uthread
, addr
);
1358 regs32
->uesp
= addr
;
1362 case FASTTRAP_T_COMMON
:
1365 uint8_t scratch
[2 * FASTTRAP_MAX_INSTR_SIZE
+ 7];
1369 * Generic Instruction Tracing
1370 * ---------------------------
1372 * This is the layout of the scratch space in the user-land
1373 * thread structure for our generated instructions.
1376 * ------------------------ -----
1377 * a: <original instruction> <= 15
1378 * jmp <pc + tp->ftt_size> 5
1379 * b: <original instrction> <= 15
1380 * int T_DTRACE_RET 2
1385 * ------------------------ -----
1386 * a: <original instruction> <= 15
1388 * <pc + tp->ftt_size> 8
1389 * b: <original instruction> <= 15
1390 * int T_DTRACE_RET 2
1394 * The %pc is set to a, and curthread->t_dtrace_astpc is set
1395 * to b. If we encounter a signal on the way out of the
1396 * kernel, trap() will set %pc to curthread->t_dtrace_astpc
1397 * so that we execute the original instruction and re-enter
1398 * the kernel rather than redirecting to the next instruction.
1400 * If there are return probes (so we know that we're going to
1401 * need to reenter the kernel after executing the original
1402 * instruction), the scratch space will just contain the
1403 * original instruction followed by an interrupt -- the same
1407 addr
= uthread
->t_dtrace_scratch
->addr
;
1410 fasttrap_sigtrap(p
, uthread
, pc
); // Should be killing target proc
1415 ASSERT(tp
->ftt_size
< FASTTRAP_MAX_INSTR_SIZE
);
1417 uthread
->t_dtrace_scrpc
= addr
;
1418 bcopy(tp
->ftt_instr
, &scratch
[i
], tp
->ftt_size
);
1422 * Set up the jmp to the next instruction; note that
1423 * the size of the traced instruction cancels out.
1425 scratch
[i
++] = FASTTRAP_JMP32
;
1426 /* LINTED - alignment */
1427 *(uint32_t *)&scratch
[i
] = pc
- addr
- 5;
1428 i
+= sizeof (uint32_t);
1430 uthread
->t_dtrace_astpc
= addr
+ i
;
1431 bcopy(tp
->ftt_instr
, &scratch
[i
], tp
->ftt_size
);
1433 scratch
[i
++] = FASTTRAP_INT
;
1434 scratch
[i
++] = T_DTRACE_RET
;
1436 ASSERT(i
<= sizeof (scratch
));
1438 if (fasttrap_copyout(scratch
, addr
, i
)) {
1439 fasttrap_sigtrap(p
, uthread
, pc
);
1444 if (tp
->ftt_retids
!= NULL
) {
1445 uthread
->t_dtrace_step
= 1;
1446 uthread
->t_dtrace_ret
= 1;
1447 new_pc
= uthread
->t_dtrace_astpc
;
1449 new_pc
= uthread
->t_dtrace_scrpc
;
1452 uthread
->t_dtrace_pc
= pc
;
1453 uthread
->t_dtrace_npc
= pc
+ tp
->ftt_size
;
1454 uthread
->t_dtrace_on
= 1;
1459 panic("fasttrap: mishandled an instruction");
1466 * We're setting this earlier than Solaris does, to get a "correct"
1467 * ustack() output. In the Sun code, a() -> b() -> c() -> d() is
1468 * reported at: d, b, a. The new way gives c, b, a, which is closer
1469 * to correct, as the return instruction has already exectued.
1471 regs32
->eip
= new_pc
;
1474 * If there were no return probes when we first found the tracepoint,
1475 * we should feel no obligation to honor any return probes that were
1476 * subsequently enabled -- they'll just have to wait until the next
1479 if (tp
->ftt_retids
!= NULL
) {
1481 * We need to wait until the results of the instruction are
1482 * apparent before invoking any return probes. If this
1483 * instruction was emulated we can just call
1484 * fasttrap_return_common(); if it needs to be executed, we
1485 * need to wait until the user thread returns to the kernel.
1487 if (tp
->ftt_type
!= FASTTRAP_T_COMMON
) {
1488 fasttrap_return_common(regs
, pc
, pid
, new_pc
);
1490 ASSERT(uthread
->t_dtrace_ret
!= 0);
1491 ASSERT(uthread
->t_dtrace_pc
== pc
);
1492 ASSERT(uthread
->t_dtrace_scrpc
!= 0);
1493 ASSERT(new_pc
== uthread
->t_dtrace_astpc
);
1501 * Due to variances between Solaris and xnu, I have split this into a 32 bit and 64 bit
1502 * code path. It still takes an x86_saved_state_t* argument, because it must sometimes
1503 * call other methods that require a x86_saved_state_t.
1507 * Any changes made to this method must be echo'd in fasttrap_pid_probe32!
1511 fasttrap_pid_probe64(x86_saved_state_t
*regs
)
1513 ASSERT(is_saved_state64(regs
));
1515 x86_saved_state64_t
*regs64
= saved_state64(regs
);
1516 user_addr_t pc
= regs64
->isf
.rip
- 1;
1517 proc_t
*p
= current_proc();
1518 user_addr_t new_pc
= 0;
1519 fasttrap_bucket_t
*bucket
;
1521 fasttrap_tracepoint_t
*tp
, tp_local
;
1523 dtrace_icookie_t cookie
;
1524 uint_t is_enabled
= 0;
1526 uthread_t uthread
= (uthread_t
)get_bsdthread_info(current_thread());
1529 * It's possible that a user (in a veritable orgy of bad planning)
1530 * could redirect this thread's flow of control before it reached the
1531 * return probe fasttrap. In this case we need to kill the process
1532 * since it's in a unrecoverable state.
1534 if (uthread
->t_dtrace_step
) {
1535 ASSERT(uthread
->t_dtrace_on
);
1536 fasttrap_sigtrap(p
, uthread
, pc
);
1541 * Clear all user tracing flags.
1543 uthread
->t_dtrace_ft
= 0;
1544 uthread
->t_dtrace_pc
= 0;
1545 uthread
->t_dtrace_npc
= 0;
1546 uthread
->t_dtrace_scrpc
= 0;
1547 uthread
->t_dtrace_astpc
= 0;
1548 uthread
->t_dtrace_regv
= 0;
1551 * Treat a child created by a call to vfork(2) as if it were its
1552 * parent. We know that there's only one thread of control in such a
1553 * process: this one.
1556 * APPLE NOTE: Terry says: "You need to hold the process locks (currently: kernel funnel) for this traversal"
1557 * FIXME: How do we assert this?
1559 while (p
->p_lflag
& P_LINVFORK
)
1563 pid_mtx
= &cpu_core
[CPU
->cpu_id
].cpuc_pid_lock
;
1564 lck_mtx_lock(pid_mtx
);
1565 bucket
= &fasttrap_tpoints
.fth_table
[FASTTRAP_TPOINTS_INDEX(pid
, pc
)];
1568 * Lookup the tracepoint that the process just hit.
1570 for (tp
= bucket
->ftb_data
; tp
!= NULL
; tp
= tp
->ftt_next
) {
1571 if (pid
== tp
->ftt_pid
&& pc
== tp
->ftt_pc
&&
1572 tp
->ftt_proc
->ftpc_acount
!= 0)
1577 * If we couldn't find a matching tracepoint, either a tracepoint has
1578 * been inserted without using the pid<pid> ioctl interface (see
1579 * fasttrap_ioctl), or somehow we have mislaid this tracepoint.
1582 lck_mtx_unlock(pid_mtx
);
1587 * Set the program counter to the address of the traced instruction
1588 * so that it looks right in ustack() output.
1590 regs64
->isf
.rip
= pc
;
1592 if (tp
->ftt_ids
!= NULL
) {
1595 for (id
= tp
->ftt_ids
; id
!= NULL
; id
= id
->fti_next
) {
1596 fasttrap_probe_t
*probe
= id
->fti_probe
;
1598 if (ISSET(current_proc()->p_lflag
, P_LNOATTACH
)) {
1599 dtrace_probe(dtrace_probeid_error
, 0 /* state */, probe
->ftp_id
,
1600 1 /* ndx */, -1 /* offset */, DTRACEFLT_UPRIV
);
1601 } else if (id
->fti_ptype
== DTFTP_ENTRY
) {
1603 * We note that this was an entry
1604 * probe to help ustack() find the
1607 cookie
= dtrace_interrupt_disable();
1608 DTRACE_CPUFLAG_SET(CPU_DTRACE_ENTRY
);
1609 dtrace_probe(probe
->ftp_id
, regs64
->rdi
,
1610 regs64
->rsi
, regs64
->rdx
, regs64
->rcx
,
1612 DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_ENTRY
);
1613 dtrace_interrupt_enable(cookie
);
1614 } else if (id
->fti_ptype
== DTFTP_IS_ENABLED
) {
1616 * Note that in this case, we don't
1617 * call dtrace_probe() since it's only
1618 * an artificial probe meant to change
1619 * the flow of control so that it
1620 * encounters the true probe.
1623 } else if (probe
->ftp_argmap
== NULL
) {
1624 dtrace_probe(probe
->ftp_id
, regs64
->rdi
,
1625 regs64
->rsi
, regs64
->rdx
, regs64
->rcx
,
1630 fasttrap_usdt_args64(probe
, regs64
,
1631 sizeof (t
) / sizeof (t
[0]), t
);
1633 dtrace_probe(probe
->ftp_id
, t
[0], t
[1],
1637 /* APPLE NOTE: Oneshot probes get one and only one chance... */
1638 if (probe
->ftp_prov
->ftp_provider_type
== DTFTP_PROVIDER_ONESHOT
) {
1639 fasttrap_tracepoint_remove(p
, tp
);
1645 * We're about to do a bunch of work so we cache a local copy of
1646 * the tracepoint to emulate the instruction, and then find the
1647 * tracepoint again later if we need to light up any return probes.
1650 lck_mtx_unlock(pid_mtx
);
1654 * Set the program counter to appear as though the traced instruction
1655 * had completely executed. This ensures that fasttrap_getreg() will
1656 * report the expected value for REG_RIP.
1658 regs64
->isf
.rip
= pc
+ tp
->ftt_size
;
1661 * If there's an is-enabled probe connected to this tracepoint it
1662 * means that there was a 'xorl %eax, %eax' or 'xorq %rax, %rax'
1663 * instruction that was placed there by DTrace when the binary was
1664 * linked. As this probe is, in fact, enabled, we need to stuff 1
1665 * into %eax or %rax. Accordingly, we can bypass all the instruction
1666 * emulation logic since we know the inevitable result. It's possible
1667 * that a user could construct a scenario where the 'is-enabled'
1668 * probe was on some other instruction, but that would be a rather
1669 * exotic way to shoot oneself in the foot.
1673 new_pc
= regs64
->isf
.rip
;
1678 * We emulate certain types of instructions to ensure correctness
1679 * (in the case of position dependent instructions) or optimize
1680 * common cases. The rest we have the thread execute back in user-
1683 switch (tp
->ftt_type
) {
1684 case FASTTRAP_T_RET
:
1685 case FASTTRAP_T_RET16
:
1692 * We have to emulate _every_ facet of the behavior of a ret
1693 * instruction including what happens if the load from %esp
1694 * fails; in that case, we send a SIGSEGV.
1696 ret
= fasttrap_fuword64((user_addr_t
)regs64
->isf
.rsp
, &dst
);
1697 addr
= regs64
->isf
.rsp
+ sizeof (uint64_t);
1700 fasttrap_sigsegv(p
, uthread
, (user_addr_t
)regs64
->isf
.rsp
);
1705 if (tp
->ftt_type
== FASTTRAP_T_RET16
)
1706 addr
+= tp
->ftt_dest
;
1708 regs64
->isf
.rsp
= addr
;
1713 case FASTTRAP_T_JCC
:
1717 switch (tp
->ftt_code
) {
1719 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) != 0;
1722 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) == 0;
1725 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_CF
) != 0;
1728 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_CF
) == 0;
1731 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) != 0;
1734 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) == 0;
1737 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_CF
) != 0 ||
1738 (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) != 0;
1741 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_CF
) == 0 &&
1742 (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) == 0;
1745 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) != 0;
1748 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) == 0;
1751 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_PF
) != 0;
1754 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_PF
) == 0;
1757 taken
= ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) == 0) !=
1758 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) == 0);
1761 taken
= ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) == 0) ==
1762 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) == 0);
1765 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) != 0 ||
1766 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) == 0) !=
1767 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) == 0);
1770 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) == 0 &&
1771 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) == 0) ==
1772 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) == 0);
1779 new_pc
= tp
->ftt_dest
;
1781 new_pc
= pc
+ tp
->ftt_size
;
1785 case FASTTRAP_T_LOOP
:
1788 uint64_t cx
= regs64
->rcx
--;
1790 switch (tp
->ftt_code
) {
1791 case FASTTRAP_LOOPNZ
:
1792 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) == 0 &&
1795 case FASTTRAP_LOOPZ
:
1796 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) != 0 &&
1807 new_pc
= tp
->ftt_dest
;
1809 new_pc
= pc
+ tp
->ftt_size
;
1813 case FASTTRAP_T_JCXZ
:
1815 uint64_t cx
= regs64
->rcx
;
1818 new_pc
= tp
->ftt_dest
;
1820 new_pc
= pc
+ tp
->ftt_size
;
1824 case FASTTRAP_T_PUSHL_EBP
:
1826 user_addr_t addr
= regs64
->isf
.rsp
- sizeof (uint64_t);
1827 int ret
= fasttrap_suword64(addr
, (uint64_t)regs64
->rbp
);
1830 fasttrap_sigsegv(p
, uthread
, addr
);
1835 regs64
->isf
.rsp
= addr
;
1836 new_pc
= pc
+ tp
->ftt_size
;
1840 case FASTTRAP_T_NOP
:
1841 new_pc
= pc
+ tp
->ftt_size
;
1844 case FASTTRAP_T_JMP
:
1845 case FASTTRAP_T_CALL
:
1846 if (tp
->ftt_code
== 0) {
1847 new_pc
= tp
->ftt_dest
;
1849 user_addr_t value
, addr
= tp
->ftt_dest
;
1851 if (tp
->ftt_base
!= FASTTRAP_NOREG
)
1852 addr
+= fasttrap_getreg(regs
, tp
->ftt_base
);
1853 if (tp
->ftt_index
!= FASTTRAP_NOREG
)
1854 addr
+= fasttrap_getreg(regs
, tp
->ftt_index
) <<
1857 if (tp
->ftt_code
== 1) {
1859 * If there's a segment prefix for this
1860 * instruction, we'll need to check permissions
1861 * and bounds on the given selector, and adjust
1862 * the address accordingly.
1864 if (tp
->ftt_segment
!= FASTTRAP_SEG_NONE
&&
1865 fasttrap_do_seg(tp
, regs
, &addr
) != 0) {
1866 fasttrap_sigsegv(p
, uthread
, addr
);
1871 if (fasttrap_fuword64(addr
, &value
) == -1) {
1872 fasttrap_sigsegv(p
, uthread
, addr
);
1883 * If this is a call instruction, we need to push the return
1884 * address onto the stack. If this fails, we send the process
1885 * a SIGSEGV and reset the pc to emulate what would happen if
1886 * this instruction weren't traced.
1888 if (tp
->ftt_type
== FASTTRAP_T_CALL
) {
1889 user_addr_t addr
= regs64
->isf
.rsp
- sizeof (uint64_t);
1890 int ret
= fasttrap_suword64(addr
, pc
+ tp
->ftt_size
);
1893 fasttrap_sigsegv(p
, uthread
, addr
);
1898 regs64
->isf
.rsp
= addr
;
1902 case FASTTRAP_T_COMMON
:
1905 uint8_t scratch
[2 * FASTTRAP_MAX_INSTR_SIZE
+ 22];
1909 * Generic Instruction Tracing
1910 * ---------------------------
1912 * This is the layout of the scratch space in the user-land
1913 * thread structure for our generated instructions.
1916 * ------------------------ -----
1917 * a: <original instruction> <= 15
1918 * jmp <pc + tp->ftt_size> 5
1919 * b: <original instrction> <= 15
1920 * int T_DTRACE_RET 2
1925 * ------------------------ -----
1926 * a: <original instruction> <= 15
1928 * <pc + tp->ftt_size> 8
1929 * b: <original instruction> <= 15
1930 * int T_DTRACE_RET 2
1934 * The %pc is set to a, and curthread->t_dtrace_astpc is set
1935 * to b. If we encounter a signal on the way out of the
1936 * kernel, trap() will set %pc to curthread->t_dtrace_astpc
1937 * so that we execute the original instruction and re-enter
1938 * the kernel rather than redirecting to the next instruction.
1940 * If there are return probes (so we know that we're going to
1941 * need to reenter the kernel after executing the original
1942 * instruction), the scratch space will just contain the
1943 * original instruction followed by an interrupt -- the same
1946 * %rip-relative Addressing
1947 * ------------------------
1949 * There's a further complication in 64-bit mode due to %rip-
1950 * relative addressing. While this is clearly a beneficial
1951 * architectural decision for position independent code, it's
1952 * hard not to see it as a personal attack against the pid
1953 * provider since before there was a relatively small set of
1954 * instructions to emulate; with %rip-relative addressing,
1955 * almost every instruction can potentially depend on the
1956 * address at which it's executed. Rather than emulating
1957 * the broad spectrum of instructions that can now be
1958 * position dependent, we emulate jumps and others as in
1959 * 32-bit mode, and take a different tack for instructions
1960 * using %rip-relative addressing.
1962 * For every instruction that uses the ModRM byte, the
1963 * in-kernel disassembler reports its location. We use the
1964 * ModRM byte to identify that an instruction uses
1965 * %rip-relative addressing and to see what other registers
1966 * the instruction uses. To emulate those instructions,
1967 * we modify the instruction to be %rax-relative rather than
1968 * %rip-relative (or %rcx-relative if the instruction uses
1969 * %rax; or %r8- or %r9-relative if the REX.B is present so
1970 * we don't have to rewrite the REX prefix). We then load
1971 * the value that %rip would have been into the scratch
1972 * register and generate an instruction to reset the scratch
1973 * register back to its original value. The instruction
1974 * sequence looks like this:
1976 * 64-mode %rip-relative bytes
1977 * ------------------------ -----
1978 * a: <modified instruction> <= 15
1979 * movq $<value>, %<scratch> 6
1981 * <pc + tp->ftt_size> 8
1982 * b: <modified instruction> <= 15
1983 * int T_DTRACE_RET 2
1987 * We set curthread->t_dtrace_regv so that upon receiving
1988 * a signal we can reset the value of the scratch register.
1991 addr
= uthread
->t_dtrace_scratch
->addr
;
1994 fasttrap_sigtrap(p
, uthread
, pc
); // Should be killing target proc
1999 ASSERT(tp
->ftt_size
< FASTTRAP_MAX_INSTR_SIZE
);
2001 uthread
->t_dtrace_scrpc
= addr
;
2002 bcopy(tp
->ftt_instr
, &scratch
[i
], tp
->ftt_size
);
2005 if (tp
->ftt_ripmode
!= 0) {
2008 ASSERT(tp
->ftt_ripmode
&
2009 (FASTTRAP_RIP_1
| FASTTRAP_RIP_2
));
2012 * If this was a %rip-relative instruction, we change
2013 * it to be either a %rax- or %rcx-relative
2014 * instruction (depending on whether those registers
2015 * are used as another operand; or %r8- or %r9-
2016 * relative depending on the value of REX.B). We then
2017 * set that register and generate a movq instruction
2018 * to reset the value.
2020 if (tp
->ftt_ripmode
& FASTTRAP_RIP_X
)
2021 scratch
[i
++] = FASTTRAP_REX(1, 0, 0, 1);
2023 scratch
[i
++] = FASTTRAP_REX(1, 0, 0, 0);
2025 if (tp
->ftt_ripmode
& FASTTRAP_RIP_1
)
2026 scratch
[i
++] = FASTTRAP_MOV_EAX
;
2028 scratch
[i
++] = FASTTRAP_MOV_ECX
;
2030 switch (tp
->ftt_ripmode
) {
2031 case FASTTRAP_RIP_1
:
2033 uthread
->t_dtrace_reg
= REG_RAX
;
2035 case FASTTRAP_RIP_2
:
2037 uthread
->t_dtrace_reg
= REG_RCX
;
2039 case FASTTRAP_RIP_1
| FASTTRAP_RIP_X
:
2041 uthread
->t_dtrace_reg
= REG_R8
;
2043 case FASTTRAP_RIP_2
| FASTTRAP_RIP_X
:
2045 uthread
->t_dtrace_reg
= REG_R9
;
2049 panic("unhandled ripmode in fasttrap_pid_probe64");
2052 /* LINTED - alignment */
2053 *(uint64_t *)&scratch
[i
] = *reg
;
2054 uthread
->t_dtrace_regv
= *reg
;
2055 *reg
= pc
+ tp
->ftt_size
;
2056 i
+= sizeof (uint64_t);
2060 * Generate the branch instruction to what would have
2061 * normally been the subsequent instruction. In 32-bit mode,
2062 * this is just a relative branch; in 64-bit mode this is a
2063 * %rip-relative branch that loads the 64-bit pc value
2064 * immediately after the jmp instruction.
2066 scratch
[i
++] = FASTTRAP_GROUP5_OP
;
2067 scratch
[i
++] = FASTTRAP_MODRM(0, 4, 5);
2068 /* LINTED - alignment */
2069 *(uint32_t *)&scratch
[i
] = 0;
2070 i
+= sizeof (uint32_t);
2071 /* LINTED - alignment */
2072 *(uint64_t *)&scratch
[i
] = pc
+ tp
->ftt_size
;
2073 i
+= sizeof (uint64_t);
2075 uthread
->t_dtrace_astpc
= addr
+ i
;
2076 bcopy(tp
->ftt_instr
, &scratch
[i
], tp
->ftt_size
);
2078 scratch
[i
++] = FASTTRAP_INT
;
2079 scratch
[i
++] = T_DTRACE_RET
;
2081 ASSERT(i
<= sizeof (scratch
));
2083 if (fasttrap_copyout(scratch
, addr
, i
)) {
2084 fasttrap_sigtrap(p
, uthread
, pc
);
2089 if (tp
->ftt_retids
!= NULL
) {
2090 uthread
->t_dtrace_step
= 1;
2091 uthread
->t_dtrace_ret
= 1;
2092 new_pc
= uthread
->t_dtrace_astpc
;
2094 new_pc
= uthread
->t_dtrace_scrpc
;
2097 uthread
->t_dtrace_pc
= pc
;
2098 uthread
->t_dtrace_npc
= pc
+ tp
->ftt_size
;
2099 uthread
->t_dtrace_on
= 1;
2104 panic("fasttrap: mishandled an instruction");
2111 * We're setting this earlier than Solaris does, to get a "correct"
2112 * ustack() output. In the Sun code, a() -> b() -> c() -> d() is
2113 * reported at: d, b, a. The new way gives c, b, a, which is closer
2114 * to correct, as the return instruction has already exectued.
2116 regs64
->isf
.rip
= new_pc
;
2120 * If there were no return probes when we first found the tracepoint,
2121 * we should feel no obligation to honor any return probes that were
2122 * subsequently enabled -- they'll just have to wait until the next
2125 if (tp
->ftt_retids
!= NULL
) {
2127 * We need to wait until the results of the instruction are
2128 * apparent before invoking any return probes. If this
2129 * instruction was emulated we can just call
2130 * fasttrap_return_common(); if it needs to be executed, we
2131 * need to wait until the user thread returns to the kernel.
2133 if (tp
->ftt_type
!= FASTTRAP_T_COMMON
) {
2134 fasttrap_return_common(regs
, pc
, pid
, new_pc
);
2136 ASSERT(uthread
->t_dtrace_ret
!= 0);
2137 ASSERT(uthread
->t_dtrace_pc
== pc
);
2138 ASSERT(uthread
->t_dtrace_scrpc
!= 0);
2139 ASSERT(new_pc
== uthread
->t_dtrace_astpc
);
2147 fasttrap_pid_probe(x86_saved_state_t
*regs
)
2149 if (is_saved_state64(regs
))
2150 return fasttrap_pid_probe64(regs
);
2152 return fasttrap_pid_probe32(regs
);
2156 fasttrap_return_probe(x86_saved_state_t
*regs
)
2158 x86_saved_state64_t
*regs64
;
2159 x86_saved_state32_t
*regs32
;
2160 unsigned int p_model
;
2162 if (is_saved_state64(regs
)) {
2163 regs64
= saved_state64(regs
);
2165 p_model
= DATAMODEL_LP64
;
2168 regs32
= saved_state32(regs
);
2169 p_model
= DATAMODEL_ILP32
;
2172 proc_t
*p
= current_proc();
2173 uthread_t uthread
= (uthread_t
)get_bsdthread_info(current_thread());
2174 user_addr_t pc
= uthread
->t_dtrace_pc
;
2175 user_addr_t npc
= uthread
->t_dtrace_npc
;
2177 uthread
->t_dtrace_pc
= 0;
2178 uthread
->t_dtrace_npc
= 0;
2179 uthread
->t_dtrace_scrpc
= 0;
2180 uthread
->t_dtrace_astpc
= 0;
2183 * Treat a child created by a call to vfork(2) as if it were its
2184 * parent. We know that there's only one thread of control in such a
2185 * process: this one.
2188 * APPLE NOTE: Terry says: "You need to hold the process locks (currently: kernel funnel) for this traversal"
2189 * How do we assert this?
2191 while (p
->p_lflag
& P_LINVFORK
) {
2196 * We set rp->r_pc to the address of the traced instruction so
2197 * that it appears to dtrace_probe() that we're on the original
2198 * instruction, and so that the user can't easily detect our
2199 * complex web of lies. dtrace_return_probe() (our caller)
2200 * will correctly set %pc after we return.
2202 if (p_model
== DATAMODEL_LP64
)
2203 regs64
->isf
.rip
= pc
;
2207 fasttrap_return_common(regs
, pc
, p
->p_pid
, npc
);
2213 fasttrap_pid_getarg(void *arg
, dtrace_id_t id
, void *parg
, int argno
,
2216 pal_register_cache_state(current_thread(), VALID
);
2217 #pragma unused(arg, id, parg, aframes)
2218 return (fasttrap_anarg((x86_saved_state_t
*)find_user_regs(current_thread()), 1, argno
));
2222 fasttrap_usdt_getarg(void *arg
, dtrace_id_t id
, void *parg
, int argno
,
2225 pal_register_cache_state(current_thread(), VALID
);
2226 #pragma unused(arg, id, parg, aframes)
2227 return (fasttrap_anarg((x86_saved_state_t
*)find_user_regs(current_thread()), 0, argno
));
2231 * APPLE NOTE: See comments by regmap array definition. We are cheating
2232 * when returning 32 bit registers.
2235 fasttrap_getreg(x86_saved_state_t
*regs
, uint_t reg
)
2237 if (is_saved_state64(regs
)) {
2238 x86_saved_state64_t
*regs64
= saved_state64(regs
);
2241 case REG_RAX
: return regs64
->rax
;
2242 case REG_RCX
: return regs64
->rcx
;
2243 case REG_RDX
: return regs64
->rdx
;
2244 case REG_RBX
: return regs64
->rbx
;
2245 case REG_RSP
: return regs64
->isf
.rsp
;
2246 case REG_RBP
: return regs64
->rbp
;
2247 case REG_RSI
: return regs64
->rsi
;
2248 case REG_RDI
: return regs64
->rdi
;
2249 case REG_R8
: return regs64
->r8
;
2250 case REG_R9
: return regs64
->r9
;
2251 case REG_R10
: return regs64
->r10
;
2252 case REG_R11
: return regs64
->r11
;
2253 case REG_R12
: return regs64
->r12
;
2254 case REG_R13
: return regs64
->r13
;
2255 case REG_R14
: return regs64
->r14
;
2256 case REG_R15
: return regs64
->r15
;
2257 case REG_TRAPNO
: return regs64
->isf
.trapno
;
2258 case REG_ERR
: return regs64
->isf
.err
;
2259 case REG_RIP
: return regs64
->isf
.rip
;
2260 case REG_CS
: return regs64
->isf
.cs
;
2261 case REG_RFL
: return regs64
->isf
.rflags
;
2262 case REG_SS
: return regs64
->isf
.ss
;
2263 case REG_FS
: return regs64
->fs
;
2264 case REG_GS
: return regs64
->gs
;
2269 // Important to distinguish these requests (which should be legal) from other values.
2270 panic("dtrace: unimplemented x86_64 getreg()");
2273 panic("dtrace: unhandled x86_64 getreg() constant");
2275 x86_saved_state32_t
*regs32
= saved_state32(regs
);
2278 case REG_RAX
: return regs32
->eax
;
2279 case REG_RCX
: return regs32
->ecx
;
2280 case REG_RDX
: return regs32
->edx
;
2281 case REG_RBX
: return regs32
->ebx
;
2282 case REG_RSP
: return regs32
->uesp
;
2283 case REG_RBP
: return regs32
->ebp
;
2284 case REG_RSI
: return regs32
->esi
;
2285 case REG_RDI
: return regs32
->edi
;
2288 panic("dtrace: unhandled i386 getreg() constant");