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:
207 * The fasttrap_getreg function knows how to make the correct transformation.
209 static const uint8_t regmap
[16] = {
210 REG_RAX
, REG_RCX
, REG_RDX
, REG_RBX
, REG_RSP
, REG_RBP
, REG_RSI
, REG_RDI
,
211 REG_R8
, REG_R9
, REG_R10
, REG_R11
, REG_R12
, REG_R13
, REG_R14
, REG_R15
,
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
;
365 * Identify the REX prefix on 64-bit processes.
367 if (p_model
== DATAMODEL_LP64
&& (instr
[start
] & 0xf0) == 0x40)
368 rex
= instr
[start
++];
371 * Now that we're pretty sure that the instruction is okay, copy the
372 * valid part to the tracepoint.
374 bcopy(instr
, tp
->ftt_instr
, FASTTRAP_MAX_INSTR_SIZE
);
376 tp
->ftt_type
= FASTTRAP_T_COMMON
;
377 if (instr
[start
] == FASTTRAP_2_BYTE_OP
) {
378 switch (instr
[start
+ 1]) {
380 case FASTTRAP_0F_JNO
:
382 case FASTTRAP_0F_JAE
:
384 case FASTTRAP_0F_JNE
:
385 case FASTTRAP_0F_JBE
:
388 case FASTTRAP_0F_JNS
:
390 case FASTTRAP_0F_JNP
:
392 case FASTTRAP_0F_JGE
:
393 case FASTTRAP_0F_JLE
:
395 tp
->ftt_type
= FASTTRAP_T_JCC
;
396 tp
->ftt_code
= (instr
[start
+ 1] & 0x0f) | FASTTRAP_JO
;
397 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
398 /* LINTED - alignment */
399 *(int32_t *)&instr
[start
+ 2];
402 } else if (instr
[start
] == FASTTRAP_GROUP5_OP
) {
403 uint_t mod
= FASTTRAP_MODRM_MOD(instr
[start
+ 1]);
404 uint_t reg
= FASTTRAP_MODRM_REG(instr
[start
+ 1]);
405 uint_t rm
= FASTTRAP_MODRM_RM(instr
[start
+ 1]);
407 if (reg
== 2 || reg
== 4) {
411 tp
->ftt_type
= FASTTRAP_T_CALL
;
413 tp
->ftt_type
= FASTTRAP_T_JMP
;
420 ASSERT(p_model
== DATAMODEL_LP64
|| rex
== 0);
423 * See AMD x86-64 Architecture Programmer's Manual
424 * Volume 3, Section 1.2.7, Table 1-12, and
425 * Appendix A.3.1, Table A-15.
427 if (mod
!= 3 && rm
== 4) {
428 uint8_t sib
= instr
[start
+ 2];
429 uint_t index
= FASTTRAP_SIB_INDEX(sib
);
430 uint_t base
= FASTTRAP_SIB_BASE(sib
);
432 tp
->ftt_scale
= FASTTRAP_SIB_SCALE(sib
);
434 tp
->ftt_index
= (index
== 4) ?
436 regmap
[index
| (FASTTRAP_REX_X(rex
) << 3)];
437 tp
->ftt_base
= (mod
== 0 && base
== 5) ?
439 regmap
[base
| (FASTTRAP_REX_B(rex
) << 3)];
442 sz
= mod
== 1 ? 1 : 4;
445 * In 64-bit mode, mod == 0 and r/m == 5
446 * denotes %rip-relative addressing; in 32-bit
447 * mode, the base register isn't used. In both
448 * modes, there is a 32-bit operand.
450 if (mod
== 0 && rm
== 5) {
451 if (p_model
== DATAMODEL_LP64
)
452 tp
->ftt_base
= REG_RIP
;
454 tp
->ftt_base
= FASTTRAP_NOREG
;
458 (FASTTRAP_REX_B(rex
) << 3);
460 tp
->ftt_base
= regmap
[base
];
461 sz
= mod
== 1 ? 1 : mod
== 2 ? 4 : 0;
463 tp
->ftt_index
= FASTTRAP_NOREG
;
468 tp
->ftt_dest
= *(int8_t *)&instr
[start
+ i
];
469 } else if (sz
== 4) {
470 /* LINTED - alignment */
471 tp
->ftt_dest
= *(int32_t *)&instr
[start
+ i
];
477 switch (instr
[start
]) {
479 tp
->ftt_type
= FASTTRAP_T_RET
;
483 tp
->ftt_type
= FASTTRAP_T_RET16
;
484 /* LINTED - alignment */
485 tp
->ftt_dest
= *(uint16_t *)&instr
[start
+ 1];
504 tp
->ftt_type
= FASTTRAP_T_JCC
;
505 tp
->ftt_code
= instr
[start
];
506 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
507 (int8_t)instr
[start
+ 1];
510 case FASTTRAP_LOOPNZ
:
513 tp
->ftt_type
= FASTTRAP_T_LOOP
;
514 tp
->ftt_code
= instr
[start
];
515 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
516 (int8_t)instr
[start
+ 1];
520 tp
->ftt_type
= FASTTRAP_T_JCXZ
;
521 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
522 (int8_t)instr
[start
+ 1];
526 tp
->ftt_type
= FASTTRAP_T_CALL
;
527 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
528 /* LINTED - alignment */
529 *(int32_t *)&instr
[start
+ 1];
534 tp
->ftt_type
= FASTTRAP_T_JMP
;
535 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
536 /* LINTED - alignment */
537 *(int32_t *)&instr
[start
+ 1];
540 tp
->ftt_type
= FASTTRAP_T_JMP
;
541 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
542 (int8_t)instr
[start
+ 1];
545 case FASTTRAP_PUSHL_EBP
:
547 tp
->ftt_type
= FASTTRAP_T_PUSHL_EBP
;
551 ASSERT(p_model
== DATAMODEL_LP64
|| rex
== 0);
554 * On sol64 we have to be careful not to confuse a nop
555 * (actually xchgl %eax, %eax) with an instruction using
556 * the same opcode, but that does something different
557 * (e.g. xchgl %r8d, %eax or xcghq %r8, %rax).
559 if (FASTTRAP_REX_B(rex
) == 0)
560 tp
->ftt_type
= FASTTRAP_T_NOP
;
565 * The pid provider shares the int3 trap with debugger
566 * breakpoints so we can't instrument them.
568 ASSERT(instr
[start
] == FASTTRAP_INSTR
);
573 * Interrupts seem like they could be traced with
574 * no negative implications, but it's possible that
575 * a thread could be redirected by the trap handling
576 * code which would eventually return to the
577 * instruction after the interrupt. If the interrupt
578 * were in our scratch space, the subsequent
579 * instruction might be overwritten before we return.
580 * Accordingly we refuse to instrument any interrupt.
586 if (p_model
== DATAMODEL_LP64
&& tp
->ftt_type
== FASTTRAP_T_COMMON
) {
588 * If the process is 64-bit and the instruction type is still
589 * FASTTRAP_T_COMMON -- meaning we're going to copy it out an
590 * execute it -- we need to watch for %rip-relative
591 * addressing mode. See the portion of fasttrap_pid_probe()
592 * below where we handle tracepoints with type
593 * FASTTRAP_T_COMMON for how we emulate instructions that
594 * employ %rip-relative addressing.
597 uint_t mod
= FASTTRAP_MODRM_MOD(instr
[rmindex
]);
598 uint_t reg
= FASTTRAP_MODRM_REG(instr
[rmindex
]);
599 uint_t rm
= FASTTRAP_MODRM_RM(instr
[rmindex
]);
601 ASSERT(rmindex
> (int)start
);
603 if (mod
== 0 && rm
== 5) {
605 * We need to be sure to avoid other
606 * registers used by this instruction. While
607 * the reg field may determine the op code
608 * rather than denoting a register, assuming
609 * that it denotes a register is always safe.
610 * We leave the REX field intact and use
611 * whatever value's there for simplicity.
614 tp
->ftt_ripmode
= FASTTRAP_RIP_1
|
616 FASTTRAP_REX_B(rex
));
619 tp
->ftt_ripmode
= FASTTRAP_RIP_2
|
621 FASTTRAP_REX_B(rex
));
625 tp
->ftt_modrm
= tp
->ftt_instr
[rmindex
];
626 tp
->ftt_instr
[rmindex
] =
627 FASTTRAP_MODRM(2, reg
, rm
);
636 fasttrap_tracepoint_install(proc_t
*p
, fasttrap_tracepoint_t
*tp
)
638 fasttrap_instr_t instr
= FASTTRAP_INSTR
;
640 if (uwrite(p
, &instr
, 1, tp
->ftt_pc
) != 0)
643 tp
->ftt_installed
= 1;
649 fasttrap_tracepoint_remove(proc_t
*p
, fasttrap_tracepoint_t
*tp
)
654 * Distinguish between read or write failures and a changed
657 if (uread(p
, &instr
, 1, tp
->ftt_pc
) != 0)
659 if (instr
!= FASTTRAP_INSTR
)
661 if (uwrite(p
, &tp
->ftt_instr
[0], 1, tp
->ftt_pc
) != 0)
664 tp
->ftt_installed
= 0;
670 fasttrap_return_common(x86_saved_state_t
*regs
, user_addr_t pc
, pid_t pid
,
673 x86_saved_state64_t
*regs64
;
674 x86_saved_state32_t
*regs32
;
675 unsigned int p_model
;
678 dtrace_icookie_t cookie
;
680 if (is_saved_state64(regs
)) {
681 regs64
= saved_state64(regs
);
683 p_model
= DATAMODEL_LP64
;
686 regs32
= saved_state32(regs
);
687 p_model
= DATAMODEL_ILP32
;
690 fasttrap_tracepoint_t
*tp
;
691 fasttrap_bucket_t
*bucket
;
695 pid_mtx
= &cpu_core
[CPU
->cpu_id
].cpuc_pid_lock
;
696 lck_mtx_lock(pid_mtx
);
697 bucket
= &fasttrap_tpoints
.fth_table
[FASTTRAP_TPOINTS_INDEX(pid
, pc
)];
699 for (tp
= bucket
->ftb_data
; tp
!= NULL
; tp
= tp
->ftt_next
) {
700 if (pid
== tp
->ftt_pid
&& pc
== tp
->ftt_pc
&&
701 tp
->ftt_proc
->ftpc_acount
!= 0)
706 * Don't sweat it if we can't find the tracepoint again; unlike
707 * when we're in fasttrap_pid_probe(), finding the tracepoint here
708 * is not essential to the correct execution of the process.
711 lck_mtx_unlock(pid_mtx
);
715 for (id
= tp
->ftt_retids
; id
!= NULL
; id
= id
->fti_next
) {
716 fasttrap_probe_t
*probe
= id
->fti_probe
;
718 * If there's a branch that could act as a return site, we
719 * need to trace it, and check here if the program counter is
720 * external to the function.
722 if (tp
->ftt_type
!= FASTTRAP_T_RET
&&
723 tp
->ftt_type
!= FASTTRAP_T_RET16
&&
724 new_pc
- probe
->ftp_faddr
< probe
->ftp_fsize
)
727 if (probe
->ftp_prov
->ftp_provider_type
== DTFTP_PROVIDER_ONESHOT
) {
728 uint8_t already_triggered
= atomic_or_8(&probe
->ftp_triggered
, 1);
729 if (already_triggered
) {
734 * If we have at least one probe associated that
735 * is not a oneshot probe, don't remove the
742 * Provide a hint to the stack trace functions to add the
743 * following pc to the top of the stack since it's missing
744 * on a return probe yet highly desirable for consistency.
746 cookie
= dtrace_interrupt_disable();
747 cpu_core
[CPU
->cpu_id
].cpuc_missing_tos
= pc
;
748 if (ISSET(current_proc()->p_lflag
, P_LNOATTACH
)) {
749 dtrace_probe(dtrace_probeid_error
, 0 /* state */, probe
->ftp_id
,
750 1 /* ndx */, -1 /* offset */, DTRACEFLT_UPRIV
);
751 } else if (p_model
== DATAMODEL_LP64
) {
752 dtrace_probe(probe
->ftp_id
,
753 pc
- id
->fti_probe
->ftp_faddr
,
754 regs64
->rax
, regs64
->rdx
, 0, 0);
756 dtrace_probe(probe
->ftp_id
,
757 pc
- id
->fti_probe
->ftp_faddr
,
758 regs32
->eax
, regs32
->edx
, 0, 0);
760 /* remove the hint */
761 cpu_core
[CPU
->cpu_id
].cpuc_missing_tos
= 0;
762 dtrace_interrupt_enable(cookie
);
765 lck_mtx_unlock(pid_mtx
);
769 fasttrap_sigsegv(proc_t
*p
, uthread_t t
, user_addr_t addr
)
773 /* Set fault address and mark signal */
775 t
->uu_siglist
|= sigmask(SIGSEGV
);
778 * XXX These two line may be redundant; if not, then we need
779 * XXX to potentially set the data address in the machine
780 * XXX specific thread state structure to indicate the address.
782 t
->uu_exception
= KERN_INVALID_ADDRESS
; /* SIGSEGV */
783 t
->uu_subcode
= 0; /* XXX pad */
788 signal_setast(t
->uu_context
.vc_thread
);
792 fasttrap_usdt_args64(fasttrap_probe_t
*probe
, x86_saved_state64_t
*regs64
, int argc
,
795 int i
, x
, cap
= MIN(argc
, probe
->ftp_nargs
);
796 user_addr_t stack
= (user_addr_t
)regs64
->isf
.rsp
;
798 for (i
= 0; i
< cap
; i
++) {
799 x
= probe
->ftp_argmap
[i
];
802 /* FIXME! This may be broken, needs testing */
803 argv
[i
] = (®s64
->rdi
)[x
];
805 fasttrap_fuword64_noerr(stack
+ (x
* sizeof(uint64_t)), &argv
[i
]);
809 for (; i
< argc
; i
++) {
815 fasttrap_usdt_args32(fasttrap_probe_t
*probe
, x86_saved_state32_t
*regs32
, int argc
,
818 int i
, x
, cap
= MIN(argc
, probe
->ftp_nargs
);
819 uint32_t *stack
= (uint32_t *)(uintptr_t)(regs32
->uesp
);
821 for (i
= 0; i
< cap
; i
++) {
822 x
= probe
->ftp_argmap
[i
];
824 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[x
], &argv
[i
]);
827 for (; i
< argc
; i
++) {
836 fasttrap_do_seg(fasttrap_tracepoint_t
*tp
, x86_saved_state_t
*rp
, user_addr_t
*addr
) // 64 bit
838 #pragma unused(tp, rp, addr)
839 printf("fasttrap_do_seg() called while unimplemented.\n");
843 uint16_t sel
, ndx
, type
;
846 switch (tp
->ftt_segment
) {
847 case FASTTRAP_SEG_CS
:
850 case FASTTRAP_SEG_DS
:
853 case FASTTRAP_SEG_ES
:
856 case FASTTRAP_SEG_FS
:
859 case FASTTRAP_SEG_GS
:
862 case FASTTRAP_SEG_SS
:
868 * Make sure the given segment register specifies a user priority
869 * selector rather than a kernel selector.
877 * Check the bounds and grab the descriptor out of the specified
881 if (ndx
> p
->p_ldtlimit
)
884 desc
= p
->p_ldt
+ ndx
;
890 desc
= cpu_get_gdt() + ndx
;
894 * The descriptor must have user privilege level and it must be
897 if (desc
->usd_dpl
!= SEL_UPL
|| desc
->usd_p
!= 1)
900 type
= desc
->usd_type
;
903 * If the S bit in the type field is not set, this descriptor can
904 * only be used in system context.
906 if ((type
& 0x10) != 0x10)
909 limit
= USEGD_GETLIMIT(desc
) * (desc
->usd_gran
? PAGESIZE
: 1);
911 if (tp
->ftt_segment
== FASTTRAP_SEG_CS
) {
913 * The code/data bit and readable bit must both be set.
915 if ((type
& 0xa) != 0xa)
922 * The code/data bit must be clear.
924 if ((type
& 0x8) != 0)
928 * If the expand-down bit is clear, we just check the limit as
929 * it would naturally be applied. Otherwise, we need to check
930 * that the address is the range [limit + 1 .. 0xffff] or
931 * [limit + 1 ... 0xffffffff] depending on if the default
932 * operand size bit is set.
934 if ((type
& 0x4) == 0) {
937 } else if (desc
->usd_def32
) {
938 if (*addr
< limit
+ 1 || 0xffff < *addr
)
941 if (*addr
< limit
+ 1 || 0xffffffff < *addr
)
946 *addr
+= USEGD_GETBASE(desc
);
952 * Due to variances between Solaris and xnu, I have split this into a 32 bit and 64 bit
953 * code path. It still takes an x86_saved_state_t* argument, because it must sometimes
954 * call other methods that require a x86_saved_state_t.
958 * Any changes made to this method must be echo'd in fasttrap_pid_probe64!
962 fasttrap_pid_probe32(x86_saved_state_t
*regs
)
964 ASSERT(is_saved_state32(regs
));
966 x86_saved_state32_t
*regs32
= saved_state32(regs
);
967 user_addr_t pc
= regs32
->eip
- 1;
968 proc_t
*p
= current_proc();
969 user_addr_t new_pc
= 0;
970 fasttrap_bucket_t
*bucket
;
972 fasttrap_tracepoint_t
*tp
, tp_local
;
974 dtrace_icookie_t cookie
;
975 uint_t is_enabled
= 0, retire_tp
= 1;
977 uthread_t uthread
= (uthread_t
)get_bsdthread_info(current_thread());
980 * It's possible that a user (in a veritable orgy of bad planning)
981 * could redirect this thread's flow of control before it reached the
982 * return probe fasttrap. In this case we need to kill the process
983 * since it's in a unrecoverable state.
985 if (uthread
->t_dtrace_step
) {
986 ASSERT(uthread
->t_dtrace_on
);
987 fasttrap_sigtrap(p
, uthread
, pc
);
992 * Clear all user tracing flags.
994 uthread
->t_dtrace_ft
= 0;
995 uthread
->t_dtrace_pc
= 0;
996 uthread
->t_dtrace_npc
= 0;
997 uthread
->t_dtrace_scrpc
= 0;
998 uthread
->t_dtrace_astpc
= 0;
1001 * Treat a child created by a call to vfork(2) as if it were its
1002 * parent. We know that there's only one thread of control in such a
1003 * process: this one.
1005 if (p
->p_lflag
& P_LINVFORK
) {
1007 while (p
->p_lflag
& P_LINVFORK
)
1013 pid_mtx
= &cpu_core
[CPU
->cpu_id
].cpuc_pid_lock
;
1014 lck_mtx_lock(pid_mtx
);
1015 bucket
= &fasttrap_tpoints
.fth_table
[FASTTRAP_TPOINTS_INDEX(pid
, pc
)];
1018 * Lookup the tracepoint that the process just hit.
1020 for (tp
= bucket
->ftb_data
; tp
!= NULL
; tp
= tp
->ftt_next
) {
1021 if (pid
== tp
->ftt_pid
&& pc
== tp
->ftt_pc
&&
1022 tp
->ftt_proc
->ftpc_acount
!= 0)
1027 * If we couldn't find a matching tracepoint, either a tracepoint has
1028 * been inserted without using the pid<pid> ioctl interface (see
1029 * fasttrap_ioctl), or somehow we have mislaid this tracepoint.
1032 lck_mtx_unlock(pid_mtx
);
1037 * Set the program counter to the address of the traced instruction
1038 * so that it looks right in ustack() output.
1042 if (tp
->ftt_ids
!= NULL
) {
1045 uint32_t s0
, s1
, s2
, s3
, s4
, s5
;
1046 uint32_t *stack
= (uint32_t *)(uintptr_t)(regs32
->uesp
);
1049 * In 32-bit mode, all arguments are passed on the
1050 * stack. If this is a function entry probe, we need
1051 * to skip the first entry on the stack as it
1052 * represents the return address rather than a
1053 * parameter to the function.
1055 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[0], &s0
);
1056 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[1], &s1
);
1057 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[2], &s2
);
1058 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[3], &s3
);
1059 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[4], &s4
);
1060 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[5], &s5
);
1062 for (id
= tp
->ftt_ids
; id
!= NULL
; id
= id
->fti_next
) {
1063 fasttrap_probe_t
*probe
= id
->fti_probe
;
1065 if (ISSET(current_proc()->p_lflag
, P_LNOATTACH
)) {
1066 dtrace_probe(dtrace_probeid_error
, 0 /* state */, probe
->ftp_id
,
1067 1 /* ndx */, -1 /* offset */, DTRACEFLT_UPRIV
);
1069 if (probe
->ftp_prov
->ftp_provider_type
== DTFTP_PROVIDER_ONESHOT
) {
1070 uint8_t already_triggered
= atomic_or_8(&probe
->ftp_triggered
, 1);
1071 if (already_triggered
) {
1076 * If we have at least one probe associated that
1077 * is not a oneshot probe, don't remove the
1083 if (id
->fti_ptype
== DTFTP_ENTRY
) {
1085 * We note that this was an entry
1086 * probe to help ustack() find the
1089 cookie
= dtrace_interrupt_disable();
1090 DTRACE_CPUFLAG_SET(CPU_DTRACE_ENTRY
);
1091 dtrace_probe(probe
->ftp_id
, s1
, s2
,
1093 DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_ENTRY
);
1094 dtrace_interrupt_enable(cookie
);
1095 } else if (id
->fti_ptype
== DTFTP_IS_ENABLED
) {
1097 * Note that in this case, we don't
1098 * call dtrace_probe() since it's only
1099 * an artificial probe meant to change
1100 * the flow of control so that it
1101 * encounters the true probe.
1104 } else if (probe
->ftp_argmap
== NULL
) {
1105 dtrace_probe(probe
->ftp_id
, s0
, s1
,
1110 fasttrap_usdt_args32(probe
, regs32
,
1111 sizeof (t
) / sizeof (t
[0]), t
);
1113 dtrace_probe(probe
->ftp_id
, t
[0], t
[1],
1119 fasttrap_tracepoint_retire(p
, tp
);
1124 * We're about to do a bunch of work so we cache a local copy of
1125 * the tracepoint to emulate the instruction, and then find the
1126 * tracepoint again later if we need to light up any return probes.
1129 lck_mtx_unlock(pid_mtx
);
1133 * Set the program counter to appear as though the traced instruction
1134 * had completely executed. This ensures that fasttrap_getreg() will
1135 * report the expected value for REG_RIP.
1137 regs32
->eip
= pc
+ tp
->ftt_size
;
1140 * If there's an is-enabled probe connected to this tracepoint it
1141 * means that there was a 'xorl %eax, %eax' or 'xorq %rax, %rax'
1142 * instruction that was placed there by DTrace when the binary was
1143 * linked. As this probe is, in fact, enabled, we need to stuff 1
1144 * into %eax or %rax. Accordingly, we can bypass all the instruction
1145 * emulation logic since we know the inevitable result. It's possible
1146 * that a user could construct a scenario where the 'is-enabled'
1147 * probe was on some other instruction, but that would be a rather
1148 * exotic way to shoot oneself in the foot.
1152 new_pc
= regs32
->eip
;
1157 * We emulate certain types of instructions to ensure correctness
1158 * (in the case of position dependent instructions) or optimize
1159 * common cases. The rest we have the thread execute back in user-
1162 switch (tp
->ftt_type
) {
1163 case FASTTRAP_T_RET
:
1164 case FASTTRAP_T_RET16
:
1171 * We have to emulate _every_ facet of the behavior of a ret
1172 * instruction including what happens if the load from %esp
1173 * fails; in that case, we send a SIGSEGV.
1176 ret
= fasttrap_fuword32((user_addr_t
)regs32
->uesp
, &dst32
);
1178 addr
= regs32
->uesp
+ sizeof (uint32_t);
1181 fasttrap_sigsegv(p
, uthread
, (user_addr_t
)regs32
->uesp
);
1186 if (tp
->ftt_type
== FASTTRAP_T_RET16
)
1187 addr
+= tp
->ftt_dest
;
1189 regs32
->uesp
= addr
;
1194 case FASTTRAP_T_JCC
:
1198 switch (tp
->ftt_code
) {
1200 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_OF
) != 0;
1203 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_OF
) == 0;
1206 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_CF
) != 0;
1209 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_CF
) == 0;
1212 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) != 0;
1215 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) == 0;
1218 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_CF
) != 0 ||
1219 (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) != 0;
1222 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_CF
) == 0 &&
1223 (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) == 0;
1226 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_SF
) != 0;
1229 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_SF
) == 0;
1232 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_PF
) != 0;
1235 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_PF
) == 0;
1238 taken
= ((regs32
->efl
& FASTTRAP_EFLAGS_SF
) == 0) !=
1239 ((regs32
->efl
& FASTTRAP_EFLAGS_OF
) == 0);
1242 taken
= ((regs32
->efl
& FASTTRAP_EFLAGS_SF
) == 0) ==
1243 ((regs32
->efl
& FASTTRAP_EFLAGS_OF
) == 0);
1246 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) != 0 ||
1247 ((regs32
->efl
& FASTTRAP_EFLAGS_SF
) == 0) !=
1248 ((regs32
->efl
& FASTTRAP_EFLAGS_OF
) == 0);
1251 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) == 0 &&
1252 ((regs32
->efl
& FASTTRAP_EFLAGS_SF
) == 0) ==
1253 ((regs32
->efl
& FASTTRAP_EFLAGS_OF
) == 0);
1260 new_pc
= tp
->ftt_dest
;
1262 new_pc
= pc
+ tp
->ftt_size
;
1266 case FASTTRAP_T_LOOP
:
1269 greg_t cx
= regs32
->ecx
--;
1271 switch (tp
->ftt_code
) {
1272 case FASTTRAP_LOOPNZ
:
1273 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) == 0 &&
1276 case FASTTRAP_LOOPZ
:
1277 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) != 0 &&
1288 new_pc
= tp
->ftt_dest
;
1290 new_pc
= pc
+ tp
->ftt_size
;
1294 case FASTTRAP_T_JCXZ
:
1296 greg_t cx
= regs32
->ecx
;
1299 new_pc
= tp
->ftt_dest
;
1301 new_pc
= pc
+ tp
->ftt_size
;
1305 case FASTTRAP_T_PUSHL_EBP
:
1307 user_addr_t addr
= regs32
->uesp
- sizeof (uint32_t);
1308 int ret
= fasttrap_suword32(addr
, (uint32_t)regs32
->ebp
);
1311 fasttrap_sigsegv(p
, uthread
, addr
);
1316 regs32
->uesp
= addr
;
1317 new_pc
= pc
+ tp
->ftt_size
;
1321 case FASTTRAP_T_NOP
:
1322 new_pc
= pc
+ tp
->ftt_size
;
1325 case FASTTRAP_T_JMP
:
1326 case FASTTRAP_T_CALL
:
1327 if (tp
->ftt_code
== 0) {
1328 new_pc
= tp
->ftt_dest
;
1330 user_addr_t
/* value ,*/ addr
= tp
->ftt_dest
;
1332 if (tp
->ftt_base
!= FASTTRAP_NOREG
)
1333 addr
+= fasttrap_getreg(regs
, tp
->ftt_base
);
1334 if (tp
->ftt_index
!= FASTTRAP_NOREG
)
1335 addr
+= fasttrap_getreg(regs
, tp
->ftt_index
) <<
1338 if (tp
->ftt_code
== 1) {
1340 * If there's a segment prefix for this
1341 * instruction, we'll need to check permissions
1342 * and bounds on the given selector, and adjust
1343 * the address accordingly.
1345 if (tp
->ftt_segment
!= FASTTRAP_SEG_NONE
&&
1346 fasttrap_do_seg(tp
, regs
, &addr
) != 0) {
1347 fasttrap_sigsegv(p
, uthread
, addr
);
1353 addr
= (user_addr_t
)(uint32_t)addr
;
1354 if (fasttrap_fuword32(addr
, &value32
) == -1) {
1355 fasttrap_sigsegv(p
, uthread
, addr
);
1366 * If this is a call instruction, we need to push the return
1367 * address onto the stack. If this fails, we send the process
1368 * a SIGSEGV and reset the pc to emulate what would happen if
1369 * this instruction weren't traced.
1371 if (tp
->ftt_type
== FASTTRAP_T_CALL
) {
1372 user_addr_t addr
= regs32
->uesp
- sizeof (uint32_t);
1373 int ret
= fasttrap_suword32(addr
, (uint32_t)(pc
+ tp
->ftt_size
));
1376 fasttrap_sigsegv(p
, uthread
, addr
);
1381 regs32
->uesp
= addr
;
1385 case FASTTRAP_T_COMMON
:
1388 uint8_t scratch
[2 * FASTTRAP_MAX_INSTR_SIZE
+ 7];
1392 * Generic Instruction Tracing
1393 * ---------------------------
1395 * This is the layout of the scratch space in the user-land
1396 * thread structure for our generated instructions.
1399 * ------------------------ -----
1400 * a: <original instruction> <= 15
1401 * jmp <pc + tp->ftt_size> 5
1402 * b: <original instrction> <= 15
1403 * int T_DTRACE_RET 2
1408 * ------------------------ -----
1409 * a: <original instruction> <= 15
1411 * <pc + tp->ftt_size> 8
1412 * b: <original instruction> <= 15
1413 * int T_DTRACE_RET 2
1417 * The %pc is set to a, and curthread->t_dtrace_astpc is set
1418 * to b. If we encounter a signal on the way out of the
1419 * kernel, trap() will set %pc to curthread->t_dtrace_astpc
1420 * so that we execute the original instruction and re-enter
1421 * the kernel rather than redirecting to the next instruction.
1423 * If there are return probes (so we know that we're going to
1424 * need to reenter the kernel after executing the original
1425 * instruction), the scratch space will just contain the
1426 * original instruction followed by an interrupt -- the same
1430 addr
= uthread
->t_dtrace_scratch
->addr
;
1433 fasttrap_sigtrap(p
, uthread
, pc
); // Should be killing target proc
1438 ASSERT(tp
->ftt_size
< FASTTRAP_MAX_INSTR_SIZE
);
1440 uthread
->t_dtrace_scrpc
= addr
;
1441 bcopy(tp
->ftt_instr
, &scratch
[i
], tp
->ftt_size
);
1445 * Set up the jmp to the next instruction; note that
1446 * the size of the traced instruction cancels out.
1448 scratch
[i
++] = FASTTRAP_JMP32
;
1449 /* LINTED - alignment */
1450 *(uint32_t *)&scratch
[i
] = pc
- addr
- 5;
1451 i
+= sizeof (uint32_t);
1453 uthread
->t_dtrace_astpc
= addr
+ i
;
1454 bcopy(tp
->ftt_instr
, &scratch
[i
], tp
->ftt_size
);
1456 scratch
[i
++] = FASTTRAP_INT
;
1457 scratch
[i
++] = T_DTRACE_RET
;
1459 ASSERT(i
<= sizeof (scratch
));
1461 if (fasttrap_copyout(scratch
, addr
, i
)) {
1462 fasttrap_sigtrap(p
, uthread
, pc
);
1467 if (tp
->ftt_retids
!= NULL
) {
1468 uthread
->t_dtrace_step
= 1;
1469 uthread
->t_dtrace_ret
= 1;
1470 new_pc
= uthread
->t_dtrace_astpc
;
1472 new_pc
= uthread
->t_dtrace_scrpc
;
1475 uthread
->t_dtrace_pc
= pc
;
1476 uthread
->t_dtrace_npc
= pc
+ tp
->ftt_size
;
1477 uthread
->t_dtrace_on
= 1;
1482 panic("fasttrap: mishandled an instruction");
1489 * We're setting this earlier than Solaris does, to get a "correct"
1490 * ustack() output. In the Sun code, a() -> b() -> c() -> d() is
1491 * reported at: d, b, a. The new way gives c, b, a, which is closer
1492 * to correct, as the return instruction has already exectued.
1494 regs32
->eip
= new_pc
;
1497 * If there were no return probes when we first found the tracepoint,
1498 * we should feel no obligation to honor any return probes that were
1499 * subsequently enabled -- they'll just have to wait until the next
1502 if (tp
->ftt_retids
!= NULL
) {
1504 * We need to wait until the results of the instruction are
1505 * apparent before invoking any return probes. If this
1506 * instruction was emulated we can just call
1507 * fasttrap_return_common(); if it needs to be executed, we
1508 * need to wait until the user thread returns to the kernel.
1510 if (tp
->ftt_type
!= FASTTRAP_T_COMMON
) {
1511 fasttrap_return_common(regs
, pc
, pid
, new_pc
);
1513 ASSERT(uthread
->t_dtrace_ret
!= 0);
1514 ASSERT(uthread
->t_dtrace_pc
== pc
);
1515 ASSERT(uthread
->t_dtrace_scrpc
!= 0);
1516 ASSERT(new_pc
== uthread
->t_dtrace_astpc
);
1524 * Due to variances between Solaris and xnu, I have split this into a 32 bit and 64 bit
1525 * code path. It still takes an x86_saved_state_t* argument, because it must sometimes
1526 * call other methods that require a x86_saved_state_t.
1530 * Any changes made to this method must be echo'd in fasttrap_pid_probe32!
1534 fasttrap_pid_probe64(x86_saved_state_t
*regs
)
1536 ASSERT(is_saved_state64(regs
));
1538 x86_saved_state64_t
*regs64
= saved_state64(regs
);
1539 user_addr_t pc
= regs64
->isf
.rip
- 1;
1540 proc_t
*p
= current_proc();
1541 user_addr_t new_pc
= 0;
1542 fasttrap_bucket_t
*bucket
;
1544 fasttrap_tracepoint_t
*tp
, tp_local
;
1546 dtrace_icookie_t cookie
;
1547 uint_t is_enabled
= 0;
1550 uthread_t uthread
= (uthread_t
)get_bsdthread_info(current_thread());
1553 * It's possible that a user (in a veritable orgy of bad planning)
1554 * could redirect this thread's flow of control before it reached the
1555 * return probe fasttrap. In this case we need to kill the process
1556 * since it's in a unrecoverable state.
1558 if (uthread
->t_dtrace_step
) {
1559 ASSERT(uthread
->t_dtrace_on
);
1560 fasttrap_sigtrap(p
, uthread
, pc
);
1565 * Clear all user tracing flags.
1567 uthread
->t_dtrace_ft
= 0;
1568 uthread
->t_dtrace_pc
= 0;
1569 uthread
->t_dtrace_npc
= 0;
1570 uthread
->t_dtrace_scrpc
= 0;
1571 uthread
->t_dtrace_astpc
= 0;
1572 uthread
->t_dtrace_regv
= 0;
1575 * Treat a child created by a call to vfork(2) as if it were its
1576 * parent. We know that there's only one thread of control in such a
1577 * process: this one.
1579 if (p
->p_lflag
& P_LINVFORK
) {
1581 while (p
->p_lflag
& P_LINVFORK
)
1587 pid_mtx
= &cpu_core
[CPU
->cpu_id
].cpuc_pid_lock
;
1588 lck_mtx_lock(pid_mtx
);
1589 bucket
= &fasttrap_tpoints
.fth_table
[FASTTRAP_TPOINTS_INDEX(pid
, pc
)];
1592 * Lookup the tracepoint that the process just hit.
1594 for (tp
= bucket
->ftb_data
; tp
!= NULL
; tp
= tp
->ftt_next
) {
1595 if (pid
== tp
->ftt_pid
&& pc
== tp
->ftt_pc
&&
1596 tp
->ftt_proc
->ftpc_acount
!= 0)
1601 * If we couldn't find a matching tracepoint, either a tracepoint has
1602 * been inserted without using the pid<pid> ioctl interface (see
1603 * fasttrap_ioctl), or somehow we have mislaid this tracepoint.
1606 lck_mtx_unlock(pid_mtx
);
1611 * Set the program counter to the address of the traced instruction
1612 * so that it looks right in ustack() output.
1614 regs64
->isf
.rip
= pc
;
1616 if (tp
->ftt_ids
!= NULL
) {
1619 for (id
= tp
->ftt_ids
; id
!= NULL
; id
= id
->fti_next
) {
1620 fasttrap_probe_t
*probe
= id
->fti_probe
;
1622 if (probe
->ftp_prov
->ftp_provider_type
== DTFTP_PROVIDER_ONESHOT
) {
1623 uint8_t already_triggered
= atomic_or_8(&probe
->ftp_triggered
, 1);
1624 if (already_triggered
) {
1629 * If we have at least probe associated that
1630 * is not a oneshot probe, don't remove the
1636 if (ISSET(current_proc()->p_lflag
, P_LNOATTACH
)) {
1637 dtrace_probe(dtrace_probeid_error
, 0 /* state */, probe
->ftp_id
,
1638 1 /* ndx */, -1 /* offset */, DTRACEFLT_UPRIV
);
1639 } else if (id
->fti_ptype
== DTFTP_ENTRY
) {
1641 * We note that this was an entry
1642 * probe to help ustack() find the
1645 cookie
= dtrace_interrupt_disable();
1646 DTRACE_CPUFLAG_SET(CPU_DTRACE_ENTRY
);
1647 dtrace_probe(probe
->ftp_id
, regs64
->rdi
,
1648 regs64
->rsi
, regs64
->rdx
, regs64
->rcx
,
1650 DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_ENTRY
);
1651 dtrace_interrupt_enable(cookie
);
1652 } else if (id
->fti_ptype
== DTFTP_IS_ENABLED
) {
1654 * Note that in this case, we don't
1655 * call dtrace_probe() since it's only
1656 * an artificial probe meant to change
1657 * the flow of control so that it
1658 * encounters the true probe.
1661 } else if (probe
->ftp_argmap
== NULL
) {
1662 dtrace_probe(probe
->ftp_id
, regs64
->rdi
,
1663 regs64
->rsi
, regs64
->rdx
, regs64
->rcx
,
1668 fasttrap_usdt_args64(probe
, regs64
,
1669 sizeof (t
) / sizeof (t
[0]), t
);
1671 dtrace_probe(probe
->ftp_id
, t
[0], t
[1],
1677 fasttrap_tracepoint_retire(p
, tp
);
1682 * We're about to do a bunch of work so we cache a local copy of
1683 * the tracepoint to emulate the instruction, and then find the
1684 * tracepoint again later if we need to light up any return probes.
1687 lck_mtx_unlock(pid_mtx
);
1691 * Set the program counter to appear as though the traced instruction
1692 * had completely executed. This ensures that fasttrap_getreg() will
1693 * report the expected value for REG_RIP.
1695 regs64
->isf
.rip
= pc
+ tp
->ftt_size
;
1698 * If there's an is-enabled probe connected to this tracepoint it
1699 * means that there was a 'xorl %eax, %eax' or 'xorq %rax, %rax'
1700 * instruction that was placed there by DTrace when the binary was
1701 * linked. As this probe is, in fact, enabled, we need to stuff 1
1702 * into %eax or %rax. Accordingly, we can bypass all the instruction
1703 * emulation logic since we know the inevitable result. It's possible
1704 * that a user could construct a scenario where the 'is-enabled'
1705 * probe was on some other instruction, but that would be a rather
1706 * exotic way to shoot oneself in the foot.
1710 new_pc
= regs64
->isf
.rip
;
1715 * We emulate certain types of instructions to ensure correctness
1716 * (in the case of position dependent instructions) or optimize
1717 * common cases. The rest we have the thread execute back in user-
1720 switch (tp
->ftt_type
) {
1721 case FASTTRAP_T_RET
:
1722 case FASTTRAP_T_RET16
:
1729 * We have to emulate _every_ facet of the behavior of a ret
1730 * instruction including what happens if the load from %esp
1731 * fails; in that case, we send a SIGSEGV.
1733 ret
= fasttrap_fuword64((user_addr_t
)regs64
->isf
.rsp
, &dst
);
1734 addr
= regs64
->isf
.rsp
+ sizeof (uint64_t);
1737 fasttrap_sigsegv(p
, uthread
, (user_addr_t
)regs64
->isf
.rsp
);
1742 if (tp
->ftt_type
== FASTTRAP_T_RET16
)
1743 addr
+= tp
->ftt_dest
;
1745 regs64
->isf
.rsp
= addr
;
1750 case FASTTRAP_T_JCC
:
1754 switch (tp
->ftt_code
) {
1756 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) != 0;
1759 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) == 0;
1762 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_CF
) != 0;
1765 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_CF
) == 0;
1768 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) != 0;
1771 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) == 0;
1774 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_CF
) != 0 ||
1775 (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) != 0;
1778 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_CF
) == 0 &&
1779 (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) == 0;
1782 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) != 0;
1785 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) == 0;
1788 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_PF
) != 0;
1791 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_PF
) == 0;
1794 taken
= ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) == 0) !=
1795 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) == 0);
1798 taken
= ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) == 0) ==
1799 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) == 0);
1802 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) != 0 ||
1803 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) == 0) !=
1804 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) == 0);
1807 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) == 0 &&
1808 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) == 0) ==
1809 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) == 0);
1816 new_pc
= tp
->ftt_dest
;
1818 new_pc
= pc
+ tp
->ftt_size
;
1822 case FASTTRAP_T_LOOP
:
1825 uint64_t cx
= regs64
->rcx
--;
1827 switch (tp
->ftt_code
) {
1828 case FASTTRAP_LOOPNZ
:
1829 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) == 0 &&
1832 case FASTTRAP_LOOPZ
:
1833 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) != 0 &&
1844 new_pc
= tp
->ftt_dest
;
1846 new_pc
= pc
+ tp
->ftt_size
;
1850 case FASTTRAP_T_JCXZ
:
1852 uint64_t cx
= regs64
->rcx
;
1855 new_pc
= tp
->ftt_dest
;
1857 new_pc
= pc
+ tp
->ftt_size
;
1861 case FASTTRAP_T_PUSHL_EBP
:
1863 user_addr_t addr
= regs64
->isf
.rsp
- sizeof (uint64_t);
1864 int ret
= fasttrap_suword64(addr
, (uint64_t)regs64
->rbp
);
1867 fasttrap_sigsegv(p
, uthread
, addr
);
1872 regs64
->isf
.rsp
= addr
;
1873 new_pc
= pc
+ tp
->ftt_size
;
1877 case FASTTRAP_T_NOP
:
1878 new_pc
= pc
+ tp
->ftt_size
;
1881 case FASTTRAP_T_JMP
:
1882 case FASTTRAP_T_CALL
:
1883 if (tp
->ftt_code
== 0) {
1884 new_pc
= tp
->ftt_dest
;
1886 user_addr_t value
, addr
= tp
->ftt_dest
;
1888 if (tp
->ftt_base
!= FASTTRAP_NOREG
)
1889 addr
+= fasttrap_getreg(regs
, tp
->ftt_base
);
1890 if (tp
->ftt_index
!= FASTTRAP_NOREG
)
1891 addr
+= fasttrap_getreg(regs
, tp
->ftt_index
) <<
1894 if (tp
->ftt_code
== 1) {
1896 * If there's a segment prefix for this
1897 * instruction, we'll need to check permissions
1898 * and bounds on the given selector, and adjust
1899 * the address accordingly.
1901 if (tp
->ftt_segment
!= FASTTRAP_SEG_NONE
&&
1902 fasttrap_do_seg(tp
, regs
, &addr
) != 0) {
1903 fasttrap_sigsegv(p
, uthread
, addr
);
1908 if (fasttrap_fuword64(addr
, &value
) == -1) {
1909 fasttrap_sigsegv(p
, uthread
, addr
);
1920 * If this is a call instruction, we need to push the return
1921 * address onto the stack. If this fails, we send the process
1922 * a SIGSEGV and reset the pc to emulate what would happen if
1923 * this instruction weren't traced.
1925 if (tp
->ftt_type
== FASTTRAP_T_CALL
) {
1926 user_addr_t addr
= regs64
->isf
.rsp
- sizeof (uint64_t);
1927 int ret
= fasttrap_suword64(addr
, pc
+ tp
->ftt_size
);
1930 fasttrap_sigsegv(p
, uthread
, addr
);
1935 regs64
->isf
.rsp
= addr
;
1939 case FASTTRAP_T_COMMON
:
1942 uint8_t scratch
[2 * FASTTRAP_MAX_INSTR_SIZE
+ 22];
1946 * Generic Instruction Tracing
1947 * ---------------------------
1949 * This is the layout of the scratch space in the user-land
1950 * thread structure for our generated instructions.
1953 * ------------------------ -----
1954 * a: <original instruction> <= 15
1955 * jmp <pc + tp->ftt_size> 5
1956 * b: <original instrction> <= 15
1957 * int T_DTRACE_RET 2
1962 * ------------------------ -----
1963 * a: <original instruction> <= 15
1965 * <pc + tp->ftt_size> 8
1966 * b: <original instruction> <= 15
1967 * int T_DTRACE_RET 2
1971 * The %pc is set to a, and curthread->t_dtrace_astpc is set
1972 * to b. If we encounter a signal on the way out of the
1973 * kernel, trap() will set %pc to curthread->t_dtrace_astpc
1974 * so that we execute the original instruction and re-enter
1975 * the kernel rather than redirecting to the next instruction.
1977 * If there are return probes (so we know that we're going to
1978 * need to reenter the kernel after executing the original
1979 * instruction), the scratch space will just contain the
1980 * original instruction followed by an interrupt -- the same
1983 * %rip-relative Addressing
1984 * ------------------------
1986 * There's a further complication in 64-bit mode due to %rip-
1987 * relative addressing. While this is clearly a beneficial
1988 * architectural decision for position independent code, it's
1989 * hard not to see it as a personal attack against the pid
1990 * provider since before there was a relatively small set of
1991 * instructions to emulate; with %rip-relative addressing,
1992 * almost every instruction can potentially depend on the
1993 * address at which it's executed. Rather than emulating
1994 * the broad spectrum of instructions that can now be
1995 * position dependent, we emulate jumps and others as in
1996 * 32-bit mode, and take a different tack for instructions
1997 * using %rip-relative addressing.
1999 * For every instruction that uses the ModRM byte, the
2000 * in-kernel disassembler reports its location. We use the
2001 * ModRM byte to identify that an instruction uses
2002 * %rip-relative addressing and to see what other registers
2003 * the instruction uses. To emulate those instructions,
2004 * we modify the instruction to be %rax-relative rather than
2005 * %rip-relative (or %rcx-relative if the instruction uses
2006 * %rax; or %r8- or %r9-relative if the REX.B is present so
2007 * we don't have to rewrite the REX prefix). We then load
2008 * the value that %rip would have been into the scratch
2009 * register and generate an instruction to reset the scratch
2010 * register back to its original value. The instruction
2011 * sequence looks like this:
2013 * 64-mode %rip-relative bytes
2014 * ------------------------ -----
2015 * a: <modified instruction> <= 15
2016 * movq $<value>, %<scratch> 6
2018 * <pc + tp->ftt_size> 8
2019 * b: <modified instruction> <= 15
2020 * int T_DTRACE_RET 2
2024 * We set curthread->t_dtrace_regv so that upon receiving
2025 * a signal we can reset the value of the scratch register.
2028 addr
= uthread
->t_dtrace_scratch
->addr
;
2031 fasttrap_sigtrap(p
, uthread
, pc
); // Should be killing target proc
2036 ASSERT(tp
->ftt_size
< FASTTRAP_MAX_INSTR_SIZE
);
2038 uthread
->t_dtrace_scrpc
= addr
;
2039 bcopy(tp
->ftt_instr
, &scratch
[i
], tp
->ftt_size
);
2042 if (tp
->ftt_ripmode
!= 0) {
2045 ASSERT(tp
->ftt_ripmode
&
2046 (FASTTRAP_RIP_1
| FASTTRAP_RIP_2
));
2049 * If this was a %rip-relative instruction, we change
2050 * it to be either a %rax- or %rcx-relative
2051 * instruction (depending on whether those registers
2052 * are used as another operand; or %r8- or %r9-
2053 * relative depending on the value of REX.B). We then
2054 * set that register and generate a movq instruction
2055 * to reset the value.
2057 if (tp
->ftt_ripmode
& FASTTRAP_RIP_X
)
2058 scratch
[i
++] = FASTTRAP_REX(1, 0, 0, 1);
2060 scratch
[i
++] = FASTTRAP_REX(1, 0, 0, 0);
2062 if (tp
->ftt_ripmode
& FASTTRAP_RIP_1
)
2063 scratch
[i
++] = FASTTRAP_MOV_EAX
;
2065 scratch
[i
++] = FASTTRAP_MOV_ECX
;
2067 switch (tp
->ftt_ripmode
) {
2068 case FASTTRAP_RIP_1
:
2070 uthread
->t_dtrace_reg
= REG_RAX
;
2072 case FASTTRAP_RIP_2
:
2074 uthread
->t_dtrace_reg
= REG_RCX
;
2076 case FASTTRAP_RIP_1
| FASTTRAP_RIP_X
:
2078 uthread
->t_dtrace_reg
= REG_R8
;
2080 case FASTTRAP_RIP_2
| FASTTRAP_RIP_X
:
2082 uthread
->t_dtrace_reg
= REG_R9
;
2086 panic("unhandled ripmode in fasttrap_pid_probe64");
2089 /* LINTED - alignment */
2090 *(uint64_t *)&scratch
[i
] = *reg
;
2091 uthread
->t_dtrace_regv
= *reg
;
2092 *reg
= pc
+ tp
->ftt_size
;
2093 i
+= sizeof (uint64_t);
2097 * Generate the branch instruction to what would have
2098 * normally been the subsequent instruction. In 32-bit mode,
2099 * this is just a relative branch; in 64-bit mode this is a
2100 * %rip-relative branch that loads the 64-bit pc value
2101 * immediately after the jmp instruction.
2103 scratch
[i
++] = FASTTRAP_GROUP5_OP
;
2104 scratch
[i
++] = FASTTRAP_MODRM(0, 4, 5);
2105 /* LINTED - alignment */
2106 *(uint32_t *)&scratch
[i
] = 0;
2107 i
+= sizeof (uint32_t);
2108 /* LINTED - alignment */
2109 *(uint64_t *)&scratch
[i
] = pc
+ tp
->ftt_size
;
2110 i
+= sizeof (uint64_t);
2112 uthread
->t_dtrace_astpc
= addr
+ i
;
2113 bcopy(tp
->ftt_instr
, &scratch
[i
], tp
->ftt_size
);
2115 scratch
[i
++] = FASTTRAP_INT
;
2116 scratch
[i
++] = T_DTRACE_RET
;
2118 ASSERT(i
<= sizeof (scratch
));
2120 if (fasttrap_copyout(scratch
, addr
, i
)) {
2121 fasttrap_sigtrap(p
, uthread
, pc
);
2126 if (tp
->ftt_retids
!= NULL
) {
2127 uthread
->t_dtrace_step
= 1;
2128 uthread
->t_dtrace_ret
= 1;
2129 new_pc
= uthread
->t_dtrace_astpc
;
2131 new_pc
= uthread
->t_dtrace_scrpc
;
2134 uthread
->t_dtrace_pc
= pc
;
2135 uthread
->t_dtrace_npc
= pc
+ tp
->ftt_size
;
2136 uthread
->t_dtrace_on
= 1;
2141 panic("fasttrap: mishandled an instruction");
2148 * We're setting this earlier than Solaris does, to get a "correct"
2149 * ustack() output. In the Sun code, a() -> b() -> c() -> d() is
2150 * reported at: d, b, a. The new way gives c, b, a, which is closer
2151 * to correct, as the return instruction has already exectued.
2153 regs64
->isf
.rip
= new_pc
;
2157 * If there were no return probes when we first found the tracepoint,
2158 * we should feel no obligation to honor any return probes that were
2159 * subsequently enabled -- they'll just have to wait until the next
2162 if (tp
->ftt_retids
!= NULL
) {
2164 * We need to wait until the results of the instruction are
2165 * apparent before invoking any return probes. If this
2166 * instruction was emulated we can just call
2167 * fasttrap_return_common(); if it needs to be executed, we
2168 * need to wait until the user thread returns to the kernel.
2170 if (tp
->ftt_type
!= FASTTRAP_T_COMMON
) {
2171 fasttrap_return_common(regs
, pc
, pid
, new_pc
);
2173 ASSERT(uthread
->t_dtrace_ret
!= 0);
2174 ASSERT(uthread
->t_dtrace_pc
== pc
);
2175 ASSERT(uthread
->t_dtrace_scrpc
!= 0);
2176 ASSERT(new_pc
== uthread
->t_dtrace_astpc
);
2184 fasttrap_pid_probe(x86_saved_state_t
*regs
)
2186 if (is_saved_state64(regs
))
2187 return fasttrap_pid_probe64(regs
);
2189 return fasttrap_pid_probe32(regs
);
2193 fasttrap_return_probe(x86_saved_state_t
*regs
)
2195 x86_saved_state64_t
*regs64
;
2196 x86_saved_state32_t
*regs32
;
2197 unsigned int p_model
;
2199 if (is_saved_state64(regs
)) {
2200 regs64
= saved_state64(regs
);
2202 p_model
= DATAMODEL_LP64
;
2205 regs32
= saved_state32(regs
);
2206 p_model
= DATAMODEL_ILP32
;
2209 proc_t
*p
= current_proc();
2210 uthread_t uthread
= (uthread_t
)get_bsdthread_info(current_thread());
2211 user_addr_t pc
= uthread
->t_dtrace_pc
;
2212 user_addr_t npc
= uthread
->t_dtrace_npc
;
2214 uthread
->t_dtrace_pc
= 0;
2215 uthread
->t_dtrace_npc
= 0;
2216 uthread
->t_dtrace_scrpc
= 0;
2217 uthread
->t_dtrace_astpc
= 0;
2220 * Treat a child created by a call to vfork(2) as if it were its
2221 * parent. We know that there's only one thread of control in such a
2222 * process: this one.
2225 while (p
->p_lflag
& P_LINVFORK
)
2230 * We set rp->r_pc to the address of the traced instruction so
2231 * that it appears to dtrace_probe() that we're on the original
2232 * instruction, and so that the user can't easily detect our
2233 * complex web of lies. dtrace_return_probe() (our caller)
2234 * will correctly set %pc after we return.
2236 if (p_model
== DATAMODEL_LP64
)
2237 regs64
->isf
.rip
= pc
;
2241 fasttrap_return_common(regs
, pc
, p
->p_pid
, npc
);
2247 fasttrap_pid_getarg(void *arg
, dtrace_id_t id
, void *parg
, int argno
,
2250 pal_register_cache_state(current_thread(), VALID
);
2251 #pragma unused(arg, id, parg, aframes)
2252 return (fasttrap_anarg((x86_saved_state_t
*)find_user_regs(current_thread()), 1, argno
));
2256 fasttrap_usdt_getarg(void *arg
, dtrace_id_t id
, void *parg
, int argno
,
2259 pal_register_cache_state(current_thread(), VALID
);
2260 #pragma unused(arg, id, parg, aframes)
2261 return (fasttrap_anarg((x86_saved_state_t
*)find_user_regs(current_thread()), 0, argno
));
2265 * APPLE NOTE: See comments by regmap array definition. We are cheating
2266 * when returning 32 bit registers.
2269 fasttrap_getreg(x86_saved_state_t
*regs
, uint_t reg
)
2271 if (is_saved_state64(regs
)) {
2272 x86_saved_state64_t
*regs64
= saved_state64(regs
);
2275 case REG_RAX
: return regs64
->rax
;
2276 case REG_RCX
: return regs64
->rcx
;
2277 case REG_RDX
: return regs64
->rdx
;
2278 case REG_RBX
: return regs64
->rbx
;
2279 case REG_RSP
: return regs64
->isf
.rsp
;
2280 case REG_RBP
: return regs64
->rbp
;
2281 case REG_RSI
: return regs64
->rsi
;
2282 case REG_RDI
: return regs64
->rdi
;
2283 case REG_R8
: return regs64
->r8
;
2284 case REG_R9
: return regs64
->r9
;
2285 case REG_R10
: return regs64
->r10
;
2286 case REG_R11
: return regs64
->r11
;
2287 case REG_R12
: return regs64
->r12
;
2288 case REG_R13
: return regs64
->r13
;
2289 case REG_R14
: return regs64
->r14
;
2290 case REG_R15
: return regs64
->r15
;
2291 case REG_TRAPNO
: return regs64
->isf
.trapno
;
2292 case REG_ERR
: return regs64
->isf
.err
;
2293 case REG_RIP
: return regs64
->isf
.rip
;
2294 case REG_CS
: return regs64
->isf
.cs
;
2295 case REG_RFL
: return regs64
->isf
.rflags
;
2296 case REG_SS
: return regs64
->isf
.ss
;
2297 case REG_FS
: return regs64
->fs
;
2298 case REG_GS
: return regs64
->gs
;
2303 // Important to distinguish these requests (which should be legal) from other values.
2304 panic("dtrace: unimplemented x86_64 getreg()");
2307 panic("dtrace: unhandled x86_64 getreg() constant");
2309 x86_saved_state32_t
*regs32
= saved_state32(regs
);
2312 case REG_RAX
: return regs32
->eax
;
2313 case REG_RCX
: return regs32
->ecx
;
2314 case REG_RDX
: return regs32
->edx
;
2315 case REG_RBX
: return regs32
->ebx
;
2316 case REG_RSP
: return regs32
->uesp
;
2317 case REG_RBP
: return regs32
->ebp
;
2318 case REG_RSI
: return regs32
->esi
;
2319 case REG_RDI
: return regs32
->edi
;
2322 panic("dtrace: unhandled i386 getreg() constant");