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.
27 #include <sys/fasttrap_isa.h>
28 #include <sys/fasttrap_impl.h>
29 #include <sys/dtrace.h>
30 #include <sys/dtrace_impl.h>
31 extern dtrace_id_t dtrace_probeid_error
;
33 #include "fasttrap_regset.h"
35 #include <sys/dtrace_ptss.h>
36 #include <kern/debug.h>
38 #include <machine/pal_routines.h>
40 /* Solaris proc_t is the struct. Darwin's proc_t is a pointer to it. */
41 #define proc_t struct proc /* Steer clear of the Darwin typedef for proc_t */
44 * Lossless User-Land Tracing on x86
45 * ---------------------------------
47 * The execution of most instructions is not dependent on the address; for
48 * these instructions it is sufficient to copy them into the user process's
49 * address space and execute them. To effectively single-step an instruction
50 * in user-land, we copy out the following sequence of instructions to scratch
51 * space in the user thread's ulwp_t structure.
53 * We then set the program counter (%eip or %rip) to point to this scratch
54 * space. Once execution resumes, the original instruction is executed and
55 * then control flow is redirected to what was originally the subsequent
56 * instruction. If the kernel attemps to deliver a signal while single-
57 * stepping, the signal is deferred and the program counter is moved into the
58 * second sequence of instructions. The second sequence ends in a trap into
59 * the kernel where the deferred signal is then properly handled and delivered.
61 * For instructions whose execute is position dependent, we perform simple
62 * emulation. These instructions are limited to control transfer
63 * instructions in 32-bit mode, but in 64-bit mode there's the added wrinkle
64 * of %rip-relative addressing that means that almost any instruction can be
65 * position dependent. For all the details on how we emulate generic
66 * instructions included %rip-relative instructions, see the code in
67 * fasttrap_pid_probe() below where we handle instructions of type
68 * FASTTRAP_T_COMMON (under the header: Generic Instruction Tracing).
71 #define FASTTRAP_MODRM_MOD(modrm) (((modrm) >> 6) & 0x3)
72 #define FASTTRAP_MODRM_REG(modrm) (((modrm) >> 3) & 0x7)
73 #define FASTTRAP_MODRM_RM(modrm) ((modrm) & 0x7)
74 #define FASTTRAP_MODRM(mod, reg, rm) (((mod) << 6) | ((reg) << 3) | (rm))
76 #define FASTTRAP_SIB_SCALE(sib) (((sib) >> 6) & 0x3)
77 #define FASTTRAP_SIB_INDEX(sib) (((sib) >> 3) & 0x7)
78 #define FASTTRAP_SIB_BASE(sib) ((sib) & 0x7)
80 #define FASTTRAP_REX_W(rex) (((rex) >> 3) & 1)
81 #define FASTTRAP_REX_R(rex) (((rex) >> 2) & 1)
82 #define FASTTRAP_REX_X(rex) (((rex) >> 1) & 1)
83 #define FASTTRAP_REX_B(rex) ((rex) & 1)
84 #define FASTTRAP_REX(w, r, x, b) \
85 (0x40 | ((w) << 3) | ((r) << 2) | ((x) << 1) | (b))
88 * Single-byte op-codes.
90 #define FASTTRAP_PUSHL_EBP 0x55
92 #define FASTTRAP_JO 0x70
93 #define FASTTRAP_JNO 0x71
94 #define FASTTRAP_JB 0x72
95 #define FASTTRAP_JAE 0x73
96 #define FASTTRAP_JE 0x74
97 #define FASTTRAP_JNE 0x75
98 #define FASTTRAP_JBE 0x76
99 #define FASTTRAP_JA 0x77
100 #define FASTTRAP_JS 0x78
101 #define FASTTRAP_JNS 0x79
102 #define FASTTRAP_JP 0x7a
103 #define FASTTRAP_JNP 0x7b
104 #define FASTTRAP_JL 0x7c
105 #define FASTTRAP_JGE 0x7d
106 #define FASTTRAP_JLE 0x7e
107 #define FASTTRAP_JG 0x7f
109 #define FASTTRAP_NOP 0x90
111 #define FASTTRAP_MOV_EAX 0xb8
112 #define FASTTRAP_MOV_ECX 0xb9
114 #define FASTTRAP_RET16 0xc2
115 #define FASTTRAP_RET 0xc3
117 #define FASTTRAP_LOOPNZ 0xe0
118 #define FASTTRAP_LOOPZ 0xe1
119 #define FASTTRAP_LOOP 0xe2
120 #define FASTTRAP_JCXZ 0xe3
122 #define FASTTRAP_CALL 0xe8
123 #define FASTTRAP_JMP32 0xe9
124 #define FASTTRAP_JMP8 0xeb
126 #define FASTTRAP_INT3 0xcc
127 #define FASTTRAP_INT 0xcd
128 #define T_DTRACE_RET 0x7f
130 #define FASTTRAP_2_BYTE_OP 0x0f
131 #define FASTTRAP_GROUP5_OP 0xff
134 * Two-byte op-codes (second byte only).
136 #define FASTTRAP_0F_JO 0x80
137 #define FASTTRAP_0F_JNO 0x81
138 #define FASTTRAP_0F_JB 0x82
139 #define FASTTRAP_0F_JAE 0x83
140 #define FASTTRAP_0F_JE 0x84
141 #define FASTTRAP_0F_JNE 0x85
142 #define FASTTRAP_0F_JBE 0x86
143 #define FASTTRAP_0F_JA 0x87
144 #define FASTTRAP_0F_JS 0x88
145 #define FASTTRAP_0F_JNS 0x89
146 #define FASTTRAP_0F_JP 0x8a
147 #define FASTTRAP_0F_JNP 0x8b
148 #define FASTTRAP_0F_JL 0x8c
149 #define FASTTRAP_0F_JGE 0x8d
150 #define FASTTRAP_0F_JLE 0x8e
151 #define FASTTRAP_0F_JG 0x8f
153 #define FASTTRAP_EFLAGS_OF 0x800
154 #define FASTTRAP_EFLAGS_DF 0x400
155 #define FASTTRAP_EFLAGS_SF 0x080
156 #define FASTTRAP_EFLAGS_ZF 0x040
157 #define FASTTRAP_EFLAGS_AF 0x010
158 #define FASTTRAP_EFLAGS_PF 0x004
159 #define FASTTRAP_EFLAGS_CF 0x001
162 * Instruction prefixes.
164 #define FASTTRAP_PREFIX_OPERAND 0x66
165 #define FASTTRAP_PREFIX_ADDRESS 0x67
166 #define FASTTRAP_PREFIX_CS 0x2E
167 #define FASTTRAP_PREFIX_DS 0x3E
168 #define FASTTRAP_PREFIX_ES 0x26
169 #define FASTTRAP_PREFIX_FS 0x64
170 #define FASTTRAP_PREFIX_GS 0x65
171 #define FASTTRAP_PREFIX_SS 0x36
172 #define FASTTRAP_PREFIX_LOCK 0xF0
173 #define FASTTRAP_PREFIX_REP 0xF3
174 #define FASTTRAP_PREFIX_REPNE 0xF2
176 #define FASTTRAP_NOREG 0xff
179 * Map between instruction register encodings and the kernel constants which
180 * correspond to indicies into struct regs.
184 * APPLE NOTE: We are cheating here. The regmap is used to decode which register
185 * a given instruction is trying to reference. OS X does not have extended registers
186 * for 32 bit apps, but the *order* is the same. So for 32 bit state, we will return:
197 * The fasttrap_getreg function knows how to make the correct transformation.
199 static const uint8_t regmap
[16] = {
200 REG_RAX
, REG_RCX
, REG_RDX
, REG_RBX
, REG_RSP
, REG_RBP
, REG_RSI
, REG_RDI
,
201 REG_R8
, REG_R9
, REG_R10
, REG_R11
, REG_R12
, REG_R13
, REG_R14
, REG_R15
,
204 static user_addr_t
fasttrap_getreg(x86_saved_state_t
*, uint_t
);
207 fasttrap_anarg(x86_saved_state_t
*regs
, int function_entry
, int argno
)
210 int shift
= function_entry
? 1 : 0;
212 x86_saved_state64_t
*regs64
;
213 x86_saved_state32_t
*regs32
;
214 unsigned int p_model
;
216 if (is_saved_state64(regs
)) {
217 regs64
= saved_state64(regs
);
219 p_model
= DATAMODEL_LP64
;
222 regs32
= saved_state32(regs
);
223 p_model
= DATAMODEL_ILP32
;
226 if (p_model
== DATAMODEL_LP64
) {
230 * In 64-bit mode, the first six arguments are stored in
234 return ((®s64
->rdi
)[argno
]);
236 stack
= regs64
->isf
.rsp
+ sizeof(uint64_t) * (argno
- 6 + shift
);
237 DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT
);
238 value
= dtrace_fuword64(stack
);
239 DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT
| CPU_DTRACE_BADADDR
);
241 uint32_t *stack
= (uint32_t *)(uintptr_t)(regs32
->uesp
);
242 DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT
);
243 value
= dtrace_fuword32((user_addr_t
)(unsigned long)&stack
[argno
+ shift
]);
244 DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT
| CPU_DTRACE_BADADDR
);
252 fasttrap_tracepoint_init(proc_t
*p
, fasttrap_tracepoint_t
*tp
, user_addr_t pc
,
253 fasttrap_probe_type_t type
)
256 uint8_t instr
[FASTTRAP_MAX_INSTR_SIZE
+ 10];
257 size_t len
= FASTTRAP_MAX_INSTR_SIZE
;
258 size_t first
= MIN(len
, PAGE_SIZE
- (pc
& PAGE_MASK
));
262 uint8_t seg
, rex
= 0;
263 unsigned int p_model
= (p
->p_flag
& P_LP64
) ? DATAMODEL_LP64
: DATAMODEL_ILP32
;
266 * Read the instruction at the given address out of the process's
267 * address space. We don't have to worry about a debugger
268 * changing this instruction before we overwrite it with our trap
269 * instruction since P_PR_LOCK is set. Since instructions can span
270 * pages, we potentially read the instruction in two parts. If the
271 * second part fails, we just zero out that part of the instruction.
274 * APPLE NOTE: Of course, we do not have a P_PR_LOCK, so this is racey...
276 if (uread(p
, &instr
[0], first
, pc
) != 0)
279 uread(p
, &instr
[first
], len
- first
, pc
+ first
) != 0) {
280 bzero(&instr
[first
], len
- first
);
285 * If the disassembly fails, then we have a malformed instruction.
287 if ((size
= dtrace_instr_size_isa(instr
, p_model
, &rmindex
)) <= 0)
291 * Make sure the disassembler isn't completely broken.
293 ASSERT(-1 <= rmindex
&& rmindex
< (int)size
);
296 * If the computed size is greater than the number of bytes read,
297 * then it was a malformed instruction possibly because it fell on a
298 * page boundary and the subsequent page was missing or because of
299 * some malicious user.
304 tp
->ftt_size
= (uint8_t)size
;
305 tp
->ftt_segment
= FASTTRAP_SEG_NONE
;
308 * Find the start of the instruction's opcode by processing any
313 switch (instr
[start
]) {
314 case FASTTRAP_PREFIX_SS
:
317 case FASTTRAP_PREFIX_GS
:
320 case FASTTRAP_PREFIX_FS
:
323 case FASTTRAP_PREFIX_ES
:
326 case FASTTRAP_PREFIX_DS
:
329 case FASTTRAP_PREFIX_CS
:
332 case FASTTRAP_PREFIX_OPERAND
:
333 case FASTTRAP_PREFIX_ADDRESS
:
334 case FASTTRAP_PREFIX_LOCK
:
335 case FASTTRAP_PREFIX_REP
:
336 case FASTTRAP_PREFIX_REPNE
:
339 * It's illegal for an instruction to specify
340 * two segment prefixes -- give up on this
341 * illegal instruction.
343 if (tp
->ftt_segment
!= FASTTRAP_SEG_NONE
)
346 tp
->ftt_segment
= seg
;
355 * Identify the REX prefix on 64-bit processes.
357 if (p_model
== DATAMODEL_LP64
&& (instr
[start
] & 0xf0) == 0x40)
358 rex
= instr
[start
++];
361 * Now that we're pretty sure that the instruction is okay, copy the
362 * valid part to the tracepoint.
364 bcopy(instr
, tp
->ftt_instr
, FASTTRAP_MAX_INSTR_SIZE
);
366 tp
->ftt_type
= FASTTRAP_T_COMMON
;
367 if (instr
[start
] == FASTTRAP_2_BYTE_OP
) {
368 switch (instr
[start
+ 1]) {
370 case FASTTRAP_0F_JNO
:
372 case FASTTRAP_0F_JAE
:
374 case FASTTRAP_0F_JNE
:
375 case FASTTRAP_0F_JBE
:
378 case FASTTRAP_0F_JNS
:
380 case FASTTRAP_0F_JNP
:
382 case FASTTRAP_0F_JGE
:
383 case FASTTRAP_0F_JLE
:
385 tp
->ftt_type
= FASTTRAP_T_JCC
;
386 tp
->ftt_code
= (instr
[start
+ 1] & 0x0f) | FASTTRAP_JO
;
387 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
388 /* LINTED - alignment */
389 *(int32_t *)&instr
[start
+ 2];
392 } else if (instr
[start
] == FASTTRAP_GROUP5_OP
) {
393 uint_t mod
= FASTTRAP_MODRM_MOD(instr
[start
+ 1]);
394 uint_t reg
= FASTTRAP_MODRM_REG(instr
[start
+ 1]);
395 uint_t rm
= FASTTRAP_MODRM_RM(instr
[start
+ 1]);
397 if (reg
== 2 || reg
== 4) {
401 tp
->ftt_type
= FASTTRAP_T_CALL
;
403 tp
->ftt_type
= FASTTRAP_T_JMP
;
410 ASSERT(p_model
== DATAMODEL_LP64
|| rex
== 0);
413 * See AMD x86-64 Architecture Programmer's Manual
414 * Volume 3, Section 1.2.7, Table 1-12, and
415 * Appendix A.3.1, Table A-15.
417 if (mod
!= 3 && rm
== 4) {
418 uint8_t sib
= instr
[start
+ 2];
419 uint_t index
= FASTTRAP_SIB_INDEX(sib
);
420 uint_t base
= FASTTRAP_SIB_BASE(sib
);
422 tp
->ftt_scale
= FASTTRAP_SIB_SCALE(sib
);
424 tp
->ftt_index
= (index
== 4) ?
426 regmap
[index
| (FASTTRAP_REX_X(rex
) << 3)];
427 tp
->ftt_base
= (mod
== 0 && base
== 5) ?
429 regmap
[base
| (FASTTRAP_REX_B(rex
) << 3)];
432 sz
= mod
== 1 ? 1 : 4;
435 * In 64-bit mode, mod == 0 and r/m == 5
436 * denotes %rip-relative addressing; in 32-bit
437 * mode, the base register isn't used. In both
438 * modes, there is a 32-bit operand.
440 if (mod
== 0 && rm
== 5) {
441 if (p_model
== DATAMODEL_LP64
)
442 tp
->ftt_base
= REG_RIP
;
444 tp
->ftt_base
= FASTTRAP_NOREG
;
448 (FASTTRAP_REX_B(rex
) << 3);
450 tp
->ftt_base
= regmap
[base
];
451 sz
= mod
== 1 ? 1 : mod
== 2 ? 4 : 0;
453 tp
->ftt_index
= FASTTRAP_NOREG
;
458 tp
->ftt_dest
= *(int8_t *)&instr
[start
+ i
];
459 } else if (sz
== 4) {
460 /* LINTED - alignment */
461 tp
->ftt_dest
= *(int32_t *)&instr
[start
+ i
];
467 switch (instr
[start
]) {
469 tp
->ftt_type
= FASTTRAP_T_RET
;
473 tp
->ftt_type
= FASTTRAP_T_RET16
;
474 /* LINTED - alignment */
475 tp
->ftt_dest
= *(uint16_t *)&instr
[start
+ 1];
494 tp
->ftt_type
= FASTTRAP_T_JCC
;
495 tp
->ftt_code
= instr
[start
];
496 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
497 (int8_t)instr
[start
+ 1];
500 case FASTTRAP_LOOPNZ
:
503 tp
->ftt_type
= FASTTRAP_T_LOOP
;
504 tp
->ftt_code
= instr
[start
];
505 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
506 (int8_t)instr
[start
+ 1];
510 tp
->ftt_type
= FASTTRAP_T_JCXZ
;
511 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
512 (int8_t)instr
[start
+ 1];
516 tp
->ftt_type
= FASTTRAP_T_CALL
;
517 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
518 /* LINTED - alignment */
519 *(int32_t *)&instr
[start
+ 1];
524 tp
->ftt_type
= FASTTRAP_T_JMP
;
525 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
526 /* LINTED - alignment */
527 *(int32_t *)&instr
[start
+ 1];
530 tp
->ftt_type
= FASTTRAP_T_JMP
;
531 tp
->ftt_dest
= pc
+ tp
->ftt_size
+
532 (int8_t)instr
[start
+ 1];
535 case FASTTRAP_PUSHL_EBP
:
537 tp
->ftt_type
= FASTTRAP_T_PUSHL_EBP
;
541 ASSERT(p_model
== DATAMODEL_LP64
|| rex
== 0);
544 * On sol64 we have to be careful not to confuse a nop
545 * (actually xchgl %eax, %eax) with an instruction using
546 * the same opcode, but that does something different
547 * (e.g. xchgl %r8d, %eax or xcghq %r8, %rax).
549 if (FASTTRAP_REX_B(rex
) == 0)
550 tp
->ftt_type
= FASTTRAP_T_NOP
;
555 * The pid provider shares the int3 trap with debugger
556 * breakpoints so we can't instrument them.
558 ASSERT(instr
[start
] == FASTTRAP_INSTR
);
563 * Interrupts seem like they could be traced with
564 * no negative implications, but it's possible that
565 * a thread could be redirected by the trap handling
566 * code which would eventually return to the
567 * instruction after the interrupt. If the interrupt
568 * were in our scratch space, the subsequent
569 * instruction might be overwritten before we return.
570 * Accordingly we refuse to instrument any interrupt.
576 if (p_model
== DATAMODEL_LP64
&& tp
->ftt_type
== FASTTRAP_T_COMMON
) {
578 * If the process is 64-bit and the instruction type is still
579 * FASTTRAP_T_COMMON -- meaning we're going to copy it out an
580 * execute it -- we need to watch for %rip-relative
581 * addressing mode. See the portion of fasttrap_pid_probe()
582 * below where we handle tracepoints with type
583 * FASTTRAP_T_COMMON for how we emulate instructions that
584 * employ %rip-relative addressing.
587 uint_t mod
= FASTTRAP_MODRM_MOD(instr
[rmindex
]);
588 uint_t reg
= FASTTRAP_MODRM_REG(instr
[rmindex
]);
589 uint_t rm
= FASTTRAP_MODRM_RM(instr
[rmindex
]);
591 ASSERT(rmindex
> (int)start
);
593 if (mod
== 0 && rm
== 5) {
595 * We need to be sure to avoid other
596 * registers used by this instruction. While
597 * the reg field may determine the op code
598 * rather than denoting a register, assuming
599 * that it denotes a register is always safe.
600 * We leave the REX field intact and use
601 * whatever value's there for simplicity.
604 tp
->ftt_ripmode
= FASTTRAP_RIP_1
|
606 FASTTRAP_REX_B(rex
));
609 tp
->ftt_ripmode
= FASTTRAP_RIP_2
|
611 FASTTRAP_REX_B(rex
));
615 tp
->ftt_modrm
= tp
->ftt_instr
[rmindex
];
616 tp
->ftt_instr
[rmindex
] =
617 FASTTRAP_MODRM(2, reg
, rm
);
626 fasttrap_tracepoint_install(proc_t
*p
, fasttrap_tracepoint_t
*tp
)
628 fasttrap_instr_t instr
= FASTTRAP_INSTR
;
630 if (uwrite(p
, &instr
, 1, tp
->ftt_pc
) != 0)
633 tp
->ftt_installed
= 1;
639 fasttrap_tracepoint_remove(proc_t
*p
, fasttrap_tracepoint_t
*tp
)
644 * Distinguish between read or write failures and a changed
647 if (uread(p
, &instr
, 1, tp
->ftt_pc
) != 0)
649 if (instr
!= FASTTRAP_INSTR
)
651 if (uwrite(p
, &tp
->ftt_instr
[0], 1, tp
->ftt_pc
) != 0)
654 tp
->ftt_installed
= 0;
660 fasttrap_return_common(x86_saved_state_t
*regs
, user_addr_t pc
, pid_t pid
,
663 x86_saved_state64_t
*regs64
;
664 x86_saved_state32_t
*regs32
;
665 unsigned int p_model
;
668 dtrace_icookie_t cookie
;
670 if (is_saved_state64(regs
)) {
671 regs64
= saved_state64(regs
);
673 p_model
= DATAMODEL_LP64
;
676 regs32
= saved_state32(regs
);
677 p_model
= DATAMODEL_ILP32
;
680 fasttrap_tracepoint_t
*tp
;
681 fasttrap_bucket_t
*bucket
;
685 pid_mtx
= &cpu_core
[CPU
->cpu_id
].cpuc_pid_lock
;
686 lck_mtx_lock(pid_mtx
);
687 bucket
= &fasttrap_tpoints
.fth_table
[FASTTRAP_TPOINTS_INDEX(pid
, pc
)];
689 for (tp
= bucket
->ftb_data
; tp
!= NULL
; tp
= tp
->ftt_next
) {
690 if (pid
== tp
->ftt_pid
&& pc
== tp
->ftt_pc
&&
691 tp
->ftt_proc
->ftpc_acount
!= 0)
696 * Don't sweat it if we can't find the tracepoint again; unlike
697 * when we're in fasttrap_pid_probe(), finding the tracepoint here
698 * is not essential to the correct execution of the process.
701 lck_mtx_unlock(pid_mtx
);
705 for (id
= tp
->ftt_retids
; id
!= NULL
; id
= id
->fti_next
) {
706 fasttrap_probe_t
*probe
= id
->fti_probe
;
708 * If there's a branch that could act as a return site, we
709 * need to trace it, and check here if the program counter is
710 * external to the function.
712 if (tp
->ftt_type
!= FASTTRAP_T_RET
&&
713 tp
->ftt_type
!= FASTTRAP_T_RET16
&&
714 new_pc
- probe
->ftp_faddr
< probe
->ftp_fsize
)
717 if (probe
->ftp_prov
->ftp_provider_type
== DTFTP_PROVIDER_ONESHOT
) {
718 if (os_atomic_xchg(&probe
->ftp_triggered
, 1, relaxed
)) {
719 /* already triggered */
724 * If we have at least one probe associated that
725 * is not a oneshot probe, don't remove the
732 * Provide a hint to the stack trace functions to add the
733 * following pc to the top of the stack since it's missing
734 * on a return probe yet highly desirable for consistency.
736 cookie
= dtrace_interrupt_disable();
737 cpu_core
[CPU
->cpu_id
].cpuc_missing_tos
= pc
;
738 if (ISSET(current_proc()->p_lflag
, P_LNOATTACH
)) {
739 dtrace_probe(dtrace_probeid_error
, 0 /* state */, probe
->ftp_id
,
740 1 /* ndx */, -1 /* offset */, DTRACEFLT_UPRIV
);
741 } else if (p_model
== DATAMODEL_LP64
) {
742 dtrace_probe(probe
->ftp_id
,
743 pc
- id
->fti_probe
->ftp_faddr
,
744 regs64
->rax
, regs64
->rdx
, 0, 0);
746 dtrace_probe(probe
->ftp_id
,
747 pc
- id
->fti_probe
->ftp_faddr
,
748 regs32
->eax
, regs32
->edx
, 0, 0);
750 /* remove the hint */
751 cpu_core
[CPU
->cpu_id
].cpuc_missing_tos
= 0;
752 dtrace_interrupt_enable(cookie
);
755 lck_mtx_unlock(pid_mtx
);
759 fasttrap_sigsegv(proc_t
*p
, uthread_t t
, user_addr_t addr
)
763 /* Set fault address and mark signal */
765 t
->uu_siglist
|= sigmask(SIGSEGV
);
768 * XXX These two line may be redundant; if not, then we need
769 * XXX to potentially set the data address in the machine
770 * XXX specific thread state structure to indicate the address.
772 t
->uu_exception
= KERN_INVALID_ADDRESS
; /* SIGSEGV */
773 t
->uu_subcode
= 0; /* XXX pad */
778 signal_setast(t
->uu_context
.vc_thread
);
782 fasttrap_usdt_args64(fasttrap_probe_t
*probe
, x86_saved_state64_t
*regs64
, int argc
,
785 int i
, x
, cap
= MIN(argc
, probe
->ftp_nargs
);
786 user_addr_t stack
= (user_addr_t
)regs64
->isf
.rsp
;
788 for (i
= 0; i
< cap
; i
++) {
789 x
= probe
->ftp_argmap
[i
];
792 /* FIXME! This may be broken, needs testing */
793 argv
[i
] = (®s64
->rdi
)[x
];
795 fasttrap_fuword64_noerr(stack
+ (x
* sizeof(uint64_t)), &argv
[i
]);
799 for (; i
< argc
; i
++) {
805 fasttrap_usdt_args32(fasttrap_probe_t
*probe
, x86_saved_state32_t
*regs32
, int argc
,
808 int i
, x
, cap
= MIN(argc
, probe
->ftp_nargs
);
809 uint32_t *stack
= (uint32_t *)(uintptr_t)(regs32
->uesp
);
811 for (i
= 0; i
< cap
; i
++) {
812 x
= probe
->ftp_argmap
[i
];
814 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[x
], &argv
[i
]);
817 for (; i
< argc
; i
++) {
826 fasttrap_do_seg(fasttrap_tracepoint_t
*tp
, x86_saved_state_t
*rp
, user_addr_t
*addr
) // 64 bit
828 #pragma unused(tp, rp, addr)
829 printf("fasttrap_do_seg() called while unimplemented.\n");
833 uint16_t sel
, ndx
, type
;
836 switch (tp
->ftt_segment
) {
837 case FASTTRAP_SEG_CS
:
840 case FASTTRAP_SEG_DS
:
843 case FASTTRAP_SEG_ES
:
846 case FASTTRAP_SEG_FS
:
849 case FASTTRAP_SEG_GS
:
852 case FASTTRAP_SEG_SS
:
858 * Make sure the given segment register specifies a user priority
859 * selector rather than a kernel selector.
867 * Check the bounds and grab the descriptor out of the specified
871 if (ndx
> p
->p_ldtlimit
)
874 desc
= p
->p_ldt
+ ndx
;
880 desc
= cpu_get_gdt() + ndx
;
884 * The descriptor must have user privilege level and it must be
887 if (desc
->usd_dpl
!= SEL_UPL
|| desc
->usd_p
!= 1)
890 type
= desc
->usd_type
;
893 * If the S bit in the type field is not set, this descriptor can
894 * only be used in system context.
896 if ((type
& 0x10) != 0x10)
899 limit
= USEGD_GETLIMIT(desc
) * (desc
->usd_gran
? PAGESIZE
: 1);
901 if (tp
->ftt_segment
== FASTTRAP_SEG_CS
) {
903 * The code/data bit and readable bit must both be set.
905 if ((type
& 0xa) != 0xa)
912 * The code/data bit must be clear.
914 if ((type
& 0x8) != 0)
918 * If the expand-down bit is clear, we just check the limit as
919 * it would naturally be applied. Otherwise, we need to check
920 * that the address is the range [limit + 1 .. 0xffff] or
921 * [limit + 1 ... 0xffffffff] depending on if the default
922 * operand size bit is set.
924 if ((type
& 0x4) == 0) {
927 } else if (desc
->usd_def32
) {
928 if (*addr
< limit
+ 1 || 0xffff < *addr
)
931 if (*addr
< limit
+ 1 || 0xffffffff < *addr
)
936 *addr
+= USEGD_GETBASE(desc
);
942 * Due to variances between Solaris and xnu, I have split this into a 32 bit and 64 bit
943 * code path. It still takes an x86_saved_state_t* argument, because it must sometimes
944 * call other methods that require a x86_saved_state_t.
948 * Any changes made to this method must be echo'd in fasttrap_pid_probe64!
952 fasttrap_pid_probe32(x86_saved_state_t
*regs
)
954 ASSERT(is_saved_state32(regs
));
956 x86_saved_state32_t
*regs32
= saved_state32(regs
);
957 user_addr_t pc
= regs32
->eip
- 1;
958 proc_t
*p
= current_proc();
959 user_addr_t new_pc
= 0;
960 fasttrap_bucket_t
*bucket
;
962 fasttrap_tracepoint_t
*tp
, tp_local
;
964 dtrace_icookie_t cookie
;
965 uint_t is_enabled
= 0, retire_tp
= 1;
967 uthread_t uthread
= (uthread_t
)get_bsdthread_info(current_thread());
970 * It's possible that a user (in a veritable orgy of bad planning)
971 * could redirect this thread's flow of control before it reached the
972 * return probe fasttrap. In this case we need to kill the process
973 * since it's in a unrecoverable state.
975 if (uthread
->t_dtrace_step
) {
976 ASSERT(uthread
->t_dtrace_on
);
977 fasttrap_sigtrap(p
, uthread
, pc
);
982 * Clear all user tracing flags.
984 uthread
->t_dtrace_ft
= 0;
985 uthread
->t_dtrace_pc
= 0;
986 uthread
->t_dtrace_npc
= 0;
987 uthread
->t_dtrace_scrpc
= 0;
988 uthread
->t_dtrace_astpc
= 0;
991 * Treat a child created by a call to vfork(2) as if it were its
992 * parent. We know that there's only one thread of control in such a
995 if (p
->p_lflag
& P_LINVFORK
) {
997 while (p
->p_lflag
& P_LINVFORK
)
1003 pid_mtx
= &cpu_core
[CPU
->cpu_id
].cpuc_pid_lock
;
1004 lck_mtx_lock(pid_mtx
);
1005 bucket
= &fasttrap_tpoints
.fth_table
[FASTTRAP_TPOINTS_INDEX(pid
, pc
)];
1008 * Lookup the tracepoint that the process just hit.
1010 for (tp
= bucket
->ftb_data
; tp
!= NULL
; tp
= tp
->ftt_next
) {
1011 if (pid
== tp
->ftt_pid
&& pc
== tp
->ftt_pc
&&
1012 tp
->ftt_proc
->ftpc_acount
!= 0)
1017 * If we couldn't find a matching tracepoint, either a tracepoint has
1018 * been inserted without using the pid<pid> ioctl interface (see
1019 * fasttrap_ioctl), or somehow we have mislaid this tracepoint.
1022 lck_mtx_unlock(pid_mtx
);
1027 * Set the program counter to the address of the traced instruction
1028 * so that it looks right in ustack() output.
1032 if (tp
->ftt_ids
!= NULL
) {
1035 uint32_t s0
, s1
, s2
, s3
, s4
, s5
;
1036 uint32_t *stack
= (uint32_t *)(uintptr_t)(regs32
->uesp
);
1039 * In 32-bit mode, all arguments are passed on the
1040 * stack. If this is a function entry probe, we need
1041 * to skip the first entry on the stack as it
1042 * represents the return address rather than a
1043 * parameter to the function.
1045 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[0], &s0
);
1046 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[1], &s1
);
1047 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[2], &s2
);
1048 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[3], &s3
);
1049 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[4], &s4
);
1050 fasttrap_fuword32_noerr((user_addr_t
)(unsigned long)&stack
[5], &s5
);
1052 for (id
= tp
->ftt_ids
; id
!= NULL
; id
= id
->fti_next
) {
1053 fasttrap_probe_t
*probe
= id
->fti_probe
;
1055 if (ISSET(current_proc()->p_lflag
, P_LNOATTACH
)) {
1056 dtrace_probe(dtrace_probeid_error
, 0 /* state */, probe
->ftp_id
,
1057 1 /* ndx */, -1 /* offset */, DTRACEFLT_UPRIV
);
1059 if (probe
->ftp_prov
->ftp_provider_type
== DTFTP_PROVIDER_ONESHOT
) {
1060 if (os_atomic_xchg(&probe
->ftp_triggered
, 1, relaxed
)) {
1061 /* already triggered */
1066 * If we have at least one probe associated that
1067 * is not a oneshot probe, don't remove the
1073 if (id
->fti_ptype
== DTFTP_ENTRY
) {
1075 * We note that this was an entry
1076 * probe to help ustack() find the
1079 cookie
= dtrace_interrupt_disable();
1080 DTRACE_CPUFLAG_SET(CPU_DTRACE_ENTRY
);
1081 dtrace_probe(probe
->ftp_id
, s1
, s2
,
1083 DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_ENTRY
);
1084 dtrace_interrupt_enable(cookie
);
1085 } else if (id
->fti_ptype
== DTFTP_IS_ENABLED
) {
1087 * Note that in this case, we don't
1088 * call dtrace_probe() since it's only
1089 * an artificial probe meant to change
1090 * the flow of control so that it
1091 * encounters the true probe.
1094 } else if (probe
->ftp_argmap
== NULL
) {
1095 dtrace_probe(probe
->ftp_id
, s0
, s1
,
1100 fasttrap_usdt_args32(probe
, regs32
,
1101 sizeof (t
) / sizeof (t
[0]), t
);
1103 dtrace_probe(probe
->ftp_id
, t
[0], t
[1],
1109 fasttrap_tracepoint_retire(p
, tp
);
1114 * We're about to do a bunch of work so we cache a local copy of
1115 * the tracepoint to emulate the instruction, and then find the
1116 * tracepoint again later if we need to light up any return probes.
1119 lck_mtx_unlock(pid_mtx
);
1123 * Set the program counter to appear as though the traced instruction
1124 * had completely executed. This ensures that fasttrap_getreg() will
1125 * report the expected value for REG_RIP.
1127 regs32
->eip
= pc
+ tp
->ftt_size
;
1130 * If there's an is-enabled probe connected to this tracepoint it
1131 * means that there was a 'xorl %eax, %eax' or 'xorq %rax, %rax'
1132 * instruction that was placed there by DTrace when the binary was
1133 * linked. As this probe is, in fact, enabled, we need to stuff 1
1134 * into %eax or %rax. Accordingly, we can bypass all the instruction
1135 * emulation logic since we know the inevitable result. It's possible
1136 * that a user could construct a scenario where the 'is-enabled'
1137 * probe was on some other instruction, but that would be a rather
1138 * exotic way to shoot oneself in the foot.
1142 new_pc
= regs32
->eip
;
1147 * We emulate certain types of instructions to ensure correctness
1148 * (in the case of position dependent instructions) or optimize
1149 * common cases. The rest we have the thread execute back in user-
1152 switch (tp
->ftt_type
) {
1153 case FASTTRAP_T_RET
:
1154 case FASTTRAP_T_RET16
:
1161 * We have to emulate _every_ facet of the behavior of a ret
1162 * instruction including what happens if the load from %esp
1163 * fails; in that case, we send a SIGSEGV.
1166 ret
= fasttrap_fuword32((user_addr_t
)regs32
->uesp
, &dst32
);
1168 addr
= regs32
->uesp
+ sizeof (uint32_t);
1171 fasttrap_sigsegv(p
, uthread
, (user_addr_t
)regs32
->uesp
);
1176 if (tp
->ftt_type
== FASTTRAP_T_RET16
)
1177 addr
+= tp
->ftt_dest
;
1179 regs32
->uesp
= addr
;
1184 case FASTTRAP_T_JCC
:
1188 switch (tp
->ftt_code
) {
1190 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_OF
) != 0;
1193 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_OF
) == 0;
1196 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_CF
) != 0;
1199 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_CF
) == 0;
1202 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) != 0;
1205 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) == 0;
1208 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_CF
) != 0 ||
1209 (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) != 0;
1212 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_CF
) == 0 &&
1213 (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) == 0;
1216 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_SF
) != 0;
1219 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_SF
) == 0;
1222 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_PF
) != 0;
1225 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_PF
) == 0;
1228 taken
= ((regs32
->efl
& FASTTRAP_EFLAGS_SF
) == 0) !=
1229 ((regs32
->efl
& FASTTRAP_EFLAGS_OF
) == 0);
1232 taken
= ((regs32
->efl
& FASTTRAP_EFLAGS_SF
) == 0) ==
1233 ((regs32
->efl
& FASTTRAP_EFLAGS_OF
) == 0);
1236 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) != 0 ||
1237 ((regs32
->efl
& FASTTRAP_EFLAGS_SF
) == 0) !=
1238 ((regs32
->efl
& FASTTRAP_EFLAGS_OF
) == 0);
1241 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) == 0 &&
1242 ((regs32
->efl
& FASTTRAP_EFLAGS_SF
) == 0) ==
1243 ((regs32
->efl
& FASTTRAP_EFLAGS_OF
) == 0);
1250 new_pc
= tp
->ftt_dest
;
1252 new_pc
= pc
+ tp
->ftt_size
;
1256 case FASTTRAP_T_LOOP
:
1259 greg_t cx
= regs32
->ecx
--;
1261 switch (tp
->ftt_code
) {
1262 case FASTTRAP_LOOPNZ
:
1263 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) == 0 &&
1266 case FASTTRAP_LOOPZ
:
1267 taken
= (regs32
->efl
& FASTTRAP_EFLAGS_ZF
) != 0 &&
1278 new_pc
= tp
->ftt_dest
;
1280 new_pc
= pc
+ tp
->ftt_size
;
1284 case FASTTRAP_T_JCXZ
:
1286 greg_t cx
= regs32
->ecx
;
1289 new_pc
= tp
->ftt_dest
;
1291 new_pc
= pc
+ tp
->ftt_size
;
1295 case FASTTRAP_T_PUSHL_EBP
:
1297 user_addr_t addr
= regs32
->uesp
- sizeof (uint32_t);
1298 int ret
= fasttrap_suword32(addr
, (uint32_t)regs32
->ebp
);
1301 fasttrap_sigsegv(p
, uthread
, addr
);
1306 regs32
->uesp
= addr
;
1307 new_pc
= pc
+ tp
->ftt_size
;
1311 case FASTTRAP_T_NOP
:
1312 new_pc
= pc
+ tp
->ftt_size
;
1315 case FASTTRAP_T_JMP
:
1316 case FASTTRAP_T_CALL
:
1317 if (tp
->ftt_code
== 0) {
1318 new_pc
= tp
->ftt_dest
;
1320 user_addr_t
/* value ,*/ addr
= tp
->ftt_dest
;
1322 if (tp
->ftt_base
!= FASTTRAP_NOREG
)
1323 addr
+= fasttrap_getreg(regs
, tp
->ftt_base
);
1324 if (tp
->ftt_index
!= FASTTRAP_NOREG
)
1325 addr
+= fasttrap_getreg(regs
, tp
->ftt_index
) <<
1328 if (tp
->ftt_code
== 1) {
1330 * If there's a segment prefix for this
1331 * instruction, we'll need to check permissions
1332 * and bounds on the given selector, and adjust
1333 * the address accordingly.
1335 if (tp
->ftt_segment
!= FASTTRAP_SEG_NONE
&&
1336 fasttrap_do_seg(tp
, regs
, &addr
) != 0) {
1337 fasttrap_sigsegv(p
, uthread
, addr
);
1343 addr
= (user_addr_t
)(uint32_t)addr
;
1344 if (fasttrap_fuword32(addr
, &value32
) == -1) {
1345 fasttrap_sigsegv(p
, uthread
, addr
);
1356 * If this is a call instruction, we need to push the return
1357 * address onto the stack. If this fails, we send the process
1358 * a SIGSEGV and reset the pc to emulate what would happen if
1359 * this instruction weren't traced.
1361 if (tp
->ftt_type
== FASTTRAP_T_CALL
) {
1362 user_addr_t addr
= regs32
->uesp
- sizeof (uint32_t);
1363 int ret
= fasttrap_suword32(addr
, (uint32_t)(pc
+ tp
->ftt_size
));
1366 fasttrap_sigsegv(p
, uthread
, addr
);
1371 regs32
->uesp
= addr
;
1375 case FASTTRAP_T_COMMON
:
1377 user_addr_t addr
, write_addr
;
1378 uint8_t scratch
[2 * FASTTRAP_MAX_INSTR_SIZE
+ 7];
1382 * Generic Instruction Tracing
1383 * ---------------------------
1385 * This is the layout of the scratch space in the user-land
1386 * thread structure for our generated instructions.
1389 * ------------------------ -----
1390 * a: <original instruction> <= 15
1391 * jmp <pc + tp->ftt_size> 5
1392 * b: <original instrction> <= 15
1393 * int T_DTRACE_RET 2
1398 * ------------------------ -----
1399 * a: <original instruction> <= 15
1401 * <pc + tp->ftt_size> 8
1402 * b: <original instruction> <= 15
1403 * int T_DTRACE_RET 2
1407 * The %pc is set to a, and curthread->t_dtrace_astpc is set
1408 * to b. If we encounter a signal on the way out of the
1409 * kernel, trap() will set %pc to curthread->t_dtrace_astpc
1410 * so that we execute the original instruction and re-enter
1411 * the kernel rather than redirecting to the next instruction.
1413 * If there are return probes (so we know that we're going to
1414 * need to reenter the kernel after executing the original
1415 * instruction), the scratch space will just contain the
1416 * original instruction followed by an interrupt -- the same
1420 addr
= uthread
->t_dtrace_scratch
->addr
;
1421 write_addr
= uthread
->t_dtrace_scratch
->write_addr
;
1423 if (addr
== 0LL || write_addr
== 0LL) {
1424 fasttrap_sigtrap(p
, uthread
, pc
); // Should be killing target proc
1429 ASSERT(tp
->ftt_size
< FASTTRAP_MAX_INSTR_SIZE
);
1431 uthread
->t_dtrace_scrpc
= addr
;
1432 bcopy(tp
->ftt_instr
, &scratch
[i
], tp
->ftt_size
);
1436 * Set up the jmp to the next instruction; note that
1437 * the size of the traced instruction cancels out.
1439 scratch
[i
++] = FASTTRAP_JMP32
;
1440 /* LINTED - alignment */
1441 *(uint32_t *)&scratch
[i
] = pc
- addr
- 5;
1442 i
+= sizeof (uint32_t);
1444 uthread
->t_dtrace_astpc
= addr
+ i
;
1445 bcopy(tp
->ftt_instr
, &scratch
[i
], tp
->ftt_size
);
1447 scratch
[i
++] = FASTTRAP_INT
;
1448 scratch
[i
++] = T_DTRACE_RET
;
1450 ASSERT(i
<= sizeof (scratch
));
1452 if (fasttrap_copyout(scratch
, write_addr
, i
)) {
1453 fasttrap_sigtrap(p
, uthread
, pc
);
1458 if (tp
->ftt_retids
!= NULL
) {
1459 uthread
->t_dtrace_step
= 1;
1460 uthread
->t_dtrace_ret
= 1;
1461 new_pc
= uthread
->t_dtrace_astpc
;
1463 new_pc
= uthread
->t_dtrace_scrpc
;
1466 uthread
->t_dtrace_pc
= pc
;
1467 uthread
->t_dtrace_npc
= pc
+ tp
->ftt_size
;
1468 uthread
->t_dtrace_on
= 1;
1473 panic("fasttrap: mishandled an instruction");
1480 * We're setting this earlier than Solaris does, to get a "correct"
1481 * ustack() output. In the Sun code, a() -> b() -> c() -> d() is
1482 * reported at: d, b, a. The new way gives c, b, a, which is closer
1483 * to correct, as the return instruction has already exectued.
1485 regs32
->eip
= new_pc
;
1488 * If there were no return probes when we first found the tracepoint,
1489 * we should feel no obligation to honor any return probes that were
1490 * subsequently enabled -- they'll just have to wait until the next
1493 if (tp
->ftt_retids
!= NULL
) {
1495 * We need to wait until the results of the instruction are
1496 * apparent before invoking any return probes. If this
1497 * instruction was emulated we can just call
1498 * fasttrap_return_common(); if it needs to be executed, we
1499 * need to wait until the user thread returns to the kernel.
1501 if (tp
->ftt_type
!= FASTTRAP_T_COMMON
) {
1502 fasttrap_return_common(regs
, pc
, pid
, new_pc
);
1504 ASSERT(uthread
->t_dtrace_ret
!= 0);
1505 ASSERT(uthread
->t_dtrace_pc
== pc
);
1506 ASSERT(uthread
->t_dtrace_scrpc
!= 0);
1507 ASSERT(new_pc
== uthread
->t_dtrace_astpc
);
1515 * Due to variances between Solaris and xnu, I have split this into a 32 bit and 64 bit
1516 * code path. It still takes an x86_saved_state_t* argument, because it must sometimes
1517 * call other methods that require a x86_saved_state_t.
1521 * Any changes made to this method must be echo'd in fasttrap_pid_probe32!
1525 fasttrap_pid_probe64(x86_saved_state_t
*regs
)
1527 ASSERT(is_saved_state64(regs
));
1529 x86_saved_state64_t
*regs64
= saved_state64(regs
);
1530 user_addr_t pc
= regs64
->isf
.rip
- 1;
1531 proc_t
*p
= current_proc();
1532 user_addr_t new_pc
= 0;
1533 fasttrap_bucket_t
*bucket
;
1535 fasttrap_tracepoint_t
*tp
, tp_local
;
1537 dtrace_icookie_t cookie
;
1538 uint_t is_enabled
= 0;
1541 uthread_t uthread
= (uthread_t
)get_bsdthread_info(current_thread());
1544 * It's possible that a user (in a veritable orgy of bad planning)
1545 * could redirect this thread's flow of control before it reached the
1546 * return probe fasttrap. In this case we need to kill the process
1547 * since it's in a unrecoverable state.
1549 if (uthread
->t_dtrace_step
) {
1550 ASSERT(uthread
->t_dtrace_on
);
1551 fasttrap_sigtrap(p
, uthread
, pc
);
1556 * Clear all user tracing flags.
1558 uthread
->t_dtrace_ft
= 0;
1559 uthread
->t_dtrace_pc
= 0;
1560 uthread
->t_dtrace_npc
= 0;
1561 uthread
->t_dtrace_scrpc
= 0;
1562 uthread
->t_dtrace_astpc
= 0;
1563 uthread
->t_dtrace_regv
= 0;
1566 * Treat a child created by a call to vfork(2) as if it were its
1567 * parent. We know that there's only one thread of control in such a
1568 * process: this one.
1570 if (p
->p_lflag
& P_LINVFORK
) {
1572 while (p
->p_lflag
& P_LINVFORK
)
1578 pid_mtx
= &cpu_core
[CPU
->cpu_id
].cpuc_pid_lock
;
1579 lck_mtx_lock(pid_mtx
);
1580 bucket
= &fasttrap_tpoints
.fth_table
[FASTTRAP_TPOINTS_INDEX(pid
, pc
)];
1583 * Lookup the tracepoint that the process just hit.
1585 for (tp
= bucket
->ftb_data
; tp
!= NULL
; tp
= tp
->ftt_next
) {
1586 if (pid
== tp
->ftt_pid
&& pc
== tp
->ftt_pc
&&
1587 tp
->ftt_proc
->ftpc_acount
!= 0)
1592 * If we couldn't find a matching tracepoint, either a tracepoint has
1593 * been inserted without using the pid<pid> ioctl interface (see
1594 * fasttrap_ioctl), or somehow we have mislaid this tracepoint.
1597 lck_mtx_unlock(pid_mtx
);
1602 * Set the program counter to the address of the traced instruction
1603 * so that it looks right in ustack() output.
1605 regs64
->isf
.rip
= pc
;
1607 if (tp
->ftt_ids
!= NULL
) {
1610 for (id
= tp
->ftt_ids
; id
!= NULL
; id
= id
->fti_next
) {
1611 fasttrap_probe_t
*probe
= id
->fti_probe
;
1613 if (probe
->ftp_prov
->ftp_provider_type
== DTFTP_PROVIDER_ONESHOT
) {
1614 if (os_atomic_xchg(&probe
->ftp_triggered
, 1, relaxed
)) {
1615 /* already triggered */
1620 * If we have at least probe associated that
1621 * is not a oneshot probe, don't remove the
1627 if (ISSET(current_proc()->p_lflag
, P_LNOATTACH
)) {
1628 dtrace_probe(dtrace_probeid_error
, 0 /* state */, probe
->ftp_id
,
1629 1 /* ndx */, -1 /* offset */, DTRACEFLT_UPRIV
);
1630 } else if (id
->fti_ptype
== DTFTP_ENTRY
) {
1632 * We note that this was an entry
1633 * probe to help ustack() find the
1636 cookie
= dtrace_interrupt_disable();
1637 DTRACE_CPUFLAG_SET(CPU_DTRACE_ENTRY
);
1638 dtrace_probe(probe
->ftp_id
, regs64
->rdi
,
1639 regs64
->rsi
, regs64
->rdx
, regs64
->rcx
,
1641 DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_ENTRY
);
1642 dtrace_interrupt_enable(cookie
);
1643 } else if (id
->fti_ptype
== DTFTP_IS_ENABLED
) {
1645 * Note that in this case, we don't
1646 * call dtrace_probe() since it's only
1647 * an artificial probe meant to change
1648 * the flow of control so that it
1649 * encounters the true probe.
1652 } else if (probe
->ftp_argmap
== NULL
) {
1653 dtrace_probe(probe
->ftp_id
, regs64
->rdi
,
1654 regs64
->rsi
, regs64
->rdx
, regs64
->rcx
,
1659 fasttrap_usdt_args64(probe
, regs64
,
1660 sizeof (t
) / sizeof (t
[0]), t
);
1662 dtrace_probe(probe
->ftp_id
, t
[0], t
[1],
1668 fasttrap_tracepoint_retire(p
, tp
);
1673 * We're about to do a bunch of work so we cache a local copy of
1674 * the tracepoint to emulate the instruction, and then find the
1675 * tracepoint again later if we need to light up any return probes.
1678 lck_mtx_unlock(pid_mtx
);
1682 * Set the program counter to appear as though the traced instruction
1683 * had completely executed. This ensures that fasttrap_getreg() will
1684 * report the expected value for REG_RIP.
1686 regs64
->isf
.rip
= pc
+ tp
->ftt_size
;
1689 * If there's an is-enabled probe connected to this tracepoint it
1690 * means that there was a 'xorl %eax, %eax' or 'xorq %rax, %rax'
1691 * instruction that was placed there by DTrace when the binary was
1692 * linked. As this probe is, in fact, enabled, we need to stuff 1
1693 * into %eax or %rax. Accordingly, we can bypass all the instruction
1694 * emulation logic since we know the inevitable result. It's possible
1695 * that a user could construct a scenario where the 'is-enabled'
1696 * probe was on some other instruction, but that would be a rather
1697 * exotic way to shoot oneself in the foot.
1701 new_pc
= regs64
->isf
.rip
;
1706 * We emulate certain types of instructions to ensure correctness
1707 * (in the case of position dependent instructions) or optimize
1708 * common cases. The rest we have the thread execute back in user-
1711 switch (tp
->ftt_type
) {
1712 case FASTTRAP_T_RET
:
1713 case FASTTRAP_T_RET16
:
1720 * We have to emulate _every_ facet of the behavior of a ret
1721 * instruction including what happens if the load from %esp
1722 * fails; in that case, we send a SIGSEGV.
1724 ret
= fasttrap_fuword64((user_addr_t
)regs64
->isf
.rsp
, &dst
);
1725 addr
= regs64
->isf
.rsp
+ sizeof (uint64_t);
1728 fasttrap_sigsegv(p
, uthread
, (user_addr_t
)regs64
->isf
.rsp
);
1733 if (tp
->ftt_type
== FASTTRAP_T_RET16
)
1734 addr
+= tp
->ftt_dest
;
1736 regs64
->isf
.rsp
= addr
;
1741 case FASTTRAP_T_JCC
:
1745 switch (tp
->ftt_code
) {
1747 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) != 0;
1750 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) == 0;
1753 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_CF
) != 0;
1756 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_CF
) == 0;
1759 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) != 0;
1762 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) == 0;
1765 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_CF
) != 0 ||
1766 (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) != 0;
1769 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_CF
) == 0 &&
1770 (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) == 0;
1773 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) != 0;
1776 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) == 0;
1779 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_PF
) != 0;
1782 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_PF
) == 0;
1785 taken
= ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) == 0) !=
1786 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) == 0);
1789 taken
= ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) == 0) ==
1790 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) == 0);
1793 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) != 0 ||
1794 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) == 0) !=
1795 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) == 0);
1798 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) == 0 &&
1799 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_SF
) == 0) ==
1800 ((regs64
->isf
.rflags
& FASTTRAP_EFLAGS_OF
) == 0);
1807 new_pc
= tp
->ftt_dest
;
1809 new_pc
= pc
+ tp
->ftt_size
;
1813 case FASTTRAP_T_LOOP
:
1816 uint64_t cx
= regs64
->rcx
--;
1818 switch (tp
->ftt_code
) {
1819 case FASTTRAP_LOOPNZ
:
1820 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) == 0 &&
1823 case FASTTRAP_LOOPZ
:
1824 taken
= (regs64
->isf
.rflags
& FASTTRAP_EFLAGS_ZF
) != 0 &&
1835 new_pc
= tp
->ftt_dest
;
1837 new_pc
= pc
+ tp
->ftt_size
;
1841 case FASTTRAP_T_JCXZ
:
1843 uint64_t cx
= regs64
->rcx
;
1846 new_pc
= tp
->ftt_dest
;
1848 new_pc
= pc
+ tp
->ftt_size
;
1852 case FASTTRAP_T_PUSHL_EBP
:
1854 user_addr_t addr
= regs64
->isf
.rsp
- sizeof (uint64_t);
1855 int ret
= fasttrap_suword64(addr
, (uint64_t)regs64
->rbp
);
1858 fasttrap_sigsegv(p
, uthread
, addr
);
1863 regs64
->isf
.rsp
= addr
;
1864 new_pc
= pc
+ tp
->ftt_size
;
1868 case FASTTRAP_T_NOP
:
1869 new_pc
= pc
+ tp
->ftt_size
;
1872 case FASTTRAP_T_JMP
:
1873 case FASTTRAP_T_CALL
:
1874 if (tp
->ftt_code
== 0) {
1875 new_pc
= tp
->ftt_dest
;
1877 user_addr_t value
, addr
= tp
->ftt_dest
;
1879 if (tp
->ftt_base
!= FASTTRAP_NOREG
)
1880 addr
+= fasttrap_getreg(regs
, tp
->ftt_base
);
1881 if (tp
->ftt_index
!= FASTTRAP_NOREG
)
1882 addr
+= fasttrap_getreg(regs
, tp
->ftt_index
) <<
1885 if (tp
->ftt_code
== 1) {
1887 * If there's a segment prefix for this
1888 * instruction, we'll need to check permissions
1889 * and bounds on the given selector, and adjust
1890 * the address accordingly.
1892 if (tp
->ftt_segment
!= FASTTRAP_SEG_NONE
&&
1893 fasttrap_do_seg(tp
, regs
, &addr
) != 0) {
1894 fasttrap_sigsegv(p
, uthread
, addr
);
1899 if (fasttrap_fuword64(addr
, &value
) == -1) {
1900 fasttrap_sigsegv(p
, uthread
, addr
);
1911 * If this is a call instruction, we need to push the return
1912 * address onto the stack. If this fails, we send the process
1913 * a SIGSEGV and reset the pc to emulate what would happen if
1914 * this instruction weren't traced.
1916 if (tp
->ftt_type
== FASTTRAP_T_CALL
) {
1917 user_addr_t addr
= regs64
->isf
.rsp
- sizeof (uint64_t);
1918 int ret
= fasttrap_suword64(addr
, pc
+ tp
->ftt_size
);
1921 fasttrap_sigsegv(p
, uthread
, addr
);
1926 regs64
->isf
.rsp
= addr
;
1930 case FASTTRAP_T_COMMON
:
1932 user_addr_t addr
, write_addr
;
1933 uint8_t scratch
[2 * FASTTRAP_MAX_INSTR_SIZE
+ 22];
1937 * Generic Instruction Tracing
1938 * ---------------------------
1940 * This is the layout of the scratch space in the user-land
1941 * thread structure for our generated instructions.
1944 * ------------------------ -----
1945 * a: <original instruction> <= 15
1946 * jmp <pc + tp->ftt_size> 5
1947 * b: <original instrction> <= 15
1948 * int T_DTRACE_RET 2
1953 * ------------------------ -----
1954 * a: <original instruction> <= 15
1956 * <pc + tp->ftt_size> 8
1957 * b: <original instruction> <= 15
1958 * int T_DTRACE_RET 2
1962 * The %pc is set to a, and curthread->t_dtrace_astpc is set
1963 * to b. If we encounter a signal on the way out of the
1964 * kernel, trap() will set %pc to curthread->t_dtrace_astpc
1965 * so that we execute the original instruction and re-enter
1966 * the kernel rather than redirecting to the next instruction.
1968 * If there are return probes (so we know that we're going to
1969 * need to reenter the kernel after executing the original
1970 * instruction), the scratch space will just contain the
1971 * original instruction followed by an interrupt -- the same
1974 * %rip-relative Addressing
1975 * ------------------------
1977 * There's a further complication in 64-bit mode due to %rip-
1978 * relative addressing. While this is clearly a beneficial
1979 * architectural decision for position independent code, it's
1980 * hard not to see it as a personal attack against the pid
1981 * provider since before there was a relatively small set of
1982 * instructions to emulate; with %rip-relative addressing,
1983 * almost every instruction can potentially depend on the
1984 * address at which it's executed. Rather than emulating
1985 * the broad spectrum of instructions that can now be
1986 * position dependent, we emulate jumps and others as in
1987 * 32-bit mode, and take a different tack for instructions
1988 * using %rip-relative addressing.
1990 * For every instruction that uses the ModRM byte, the
1991 * in-kernel disassembler reports its location. We use the
1992 * ModRM byte to identify that an instruction uses
1993 * %rip-relative addressing and to see what other registers
1994 * the instruction uses. To emulate those instructions,
1995 * we modify the instruction to be %rax-relative rather than
1996 * %rip-relative (or %rcx-relative if the instruction uses
1997 * %rax; or %r8- or %r9-relative if the REX.B is present so
1998 * we don't have to rewrite the REX prefix). We then load
1999 * the value that %rip would have been into the scratch
2000 * register and generate an instruction to reset the scratch
2001 * register back to its original value. The instruction
2002 * sequence looks like this:
2004 * 64-mode %rip-relative bytes
2005 * ------------------------ -----
2006 * a: <modified instruction> <= 15
2007 * movq $<value>, %<scratch> 6
2009 * <pc + tp->ftt_size> 8
2010 * b: <modified instruction> <= 15
2011 * int T_DTRACE_RET 2
2015 * We set curthread->t_dtrace_regv so that upon receiving
2016 * a signal we can reset the value of the scratch register.
2019 addr
= uthread
->t_dtrace_scratch
->addr
;
2020 write_addr
= uthread
->t_dtrace_scratch
->write_addr
;
2022 if (addr
== 0LL || write_addr
== 0LL) {
2023 fasttrap_sigtrap(p
, uthread
, pc
); // Should be killing target proc
2028 ASSERT(tp
->ftt_size
< FASTTRAP_MAX_INSTR_SIZE
);
2030 uthread
->t_dtrace_scrpc
= addr
;
2031 bcopy(tp
->ftt_instr
, &scratch
[i
], tp
->ftt_size
);
2034 if (tp
->ftt_ripmode
!= 0) {
2037 ASSERT(tp
->ftt_ripmode
&
2038 (FASTTRAP_RIP_1
| FASTTRAP_RIP_2
));
2041 * If this was a %rip-relative instruction, we change
2042 * it to be either a %rax- or %rcx-relative
2043 * instruction (depending on whether those registers
2044 * are used as another operand; or %r8- or %r9-
2045 * relative depending on the value of REX.B). We then
2046 * set that register and generate a movq instruction
2047 * to reset the value.
2049 if (tp
->ftt_ripmode
& FASTTRAP_RIP_X
)
2050 scratch
[i
++] = FASTTRAP_REX(1, 0, 0, 1);
2052 scratch
[i
++] = FASTTRAP_REX(1, 0, 0, 0);
2054 if (tp
->ftt_ripmode
& FASTTRAP_RIP_1
)
2055 scratch
[i
++] = FASTTRAP_MOV_EAX
;
2057 scratch
[i
++] = FASTTRAP_MOV_ECX
;
2059 switch (tp
->ftt_ripmode
) {
2060 case FASTTRAP_RIP_1
:
2062 uthread
->t_dtrace_reg
= REG_RAX
;
2064 case FASTTRAP_RIP_2
:
2066 uthread
->t_dtrace_reg
= REG_RCX
;
2068 case FASTTRAP_RIP_1
| FASTTRAP_RIP_X
:
2070 uthread
->t_dtrace_reg
= REG_R8
;
2072 case FASTTRAP_RIP_2
| FASTTRAP_RIP_X
:
2074 uthread
->t_dtrace_reg
= REG_R9
;
2078 panic("unhandled ripmode in fasttrap_pid_probe64");
2081 /* LINTED - alignment */
2082 *(uint64_t *)&scratch
[i
] = *reg
;
2083 uthread
->t_dtrace_regv
= *reg
;
2084 *reg
= pc
+ tp
->ftt_size
;
2085 i
+= sizeof (uint64_t);
2089 * Generate the branch instruction to what would have
2090 * normally been the subsequent instruction. In 32-bit mode,
2091 * this is just a relative branch; in 64-bit mode this is a
2092 * %rip-relative branch that loads the 64-bit pc value
2093 * immediately after the jmp instruction.
2095 scratch
[i
++] = FASTTRAP_GROUP5_OP
;
2096 scratch
[i
++] = FASTTRAP_MODRM(0, 4, 5);
2097 /* LINTED - alignment */
2098 *(uint32_t *)&scratch
[i
] = 0;
2099 i
+= sizeof (uint32_t);
2100 /* LINTED - alignment */
2101 *(uint64_t *)&scratch
[i
] = pc
+ tp
->ftt_size
;
2102 i
+= sizeof (uint64_t);
2104 uthread
->t_dtrace_astpc
= addr
+ i
;
2105 bcopy(tp
->ftt_instr
, &scratch
[i
], tp
->ftt_size
);
2107 scratch
[i
++] = FASTTRAP_INT
;
2108 scratch
[i
++] = T_DTRACE_RET
;
2110 ASSERT(i
<= sizeof (scratch
));
2112 if (fasttrap_copyout(scratch
, write_addr
, i
)) {
2113 fasttrap_sigtrap(p
, uthread
, pc
);
2118 if (tp
->ftt_retids
!= NULL
) {
2119 uthread
->t_dtrace_step
= 1;
2120 uthread
->t_dtrace_ret
= 1;
2121 new_pc
= uthread
->t_dtrace_astpc
;
2123 new_pc
= uthread
->t_dtrace_scrpc
;
2126 uthread
->t_dtrace_pc
= pc
;
2127 uthread
->t_dtrace_npc
= pc
+ tp
->ftt_size
;
2128 uthread
->t_dtrace_on
= 1;
2133 panic("fasttrap: mishandled an instruction");
2140 * We're setting this earlier than Solaris does, to get a "correct"
2141 * ustack() output. In the Sun code, a() -> b() -> c() -> d() is
2142 * reported at: d, b, a. The new way gives c, b, a, which is closer
2143 * to correct, as the return instruction has already exectued.
2145 regs64
->isf
.rip
= new_pc
;
2149 * If there were no return probes when we first found the tracepoint,
2150 * we should feel no obligation to honor any return probes that were
2151 * subsequently enabled -- they'll just have to wait until the next
2154 if (tp
->ftt_retids
!= NULL
) {
2156 * We need to wait until the results of the instruction are
2157 * apparent before invoking any return probes. If this
2158 * instruction was emulated we can just call
2159 * fasttrap_return_common(); if it needs to be executed, we
2160 * need to wait until the user thread returns to the kernel.
2162 if (tp
->ftt_type
!= FASTTRAP_T_COMMON
) {
2163 fasttrap_return_common(regs
, pc
, pid
, new_pc
);
2165 ASSERT(uthread
->t_dtrace_ret
!= 0);
2166 ASSERT(uthread
->t_dtrace_pc
== pc
);
2167 ASSERT(uthread
->t_dtrace_scrpc
!= 0);
2168 ASSERT(new_pc
== uthread
->t_dtrace_astpc
);
2176 fasttrap_pid_probe(x86_saved_state_t
*regs
)
2178 if (is_saved_state64(regs
))
2179 return fasttrap_pid_probe64(regs
);
2181 return fasttrap_pid_probe32(regs
);
2185 fasttrap_return_probe(x86_saved_state_t
*regs
)
2187 x86_saved_state64_t
*regs64
;
2188 x86_saved_state32_t
*regs32
;
2189 unsigned int p_model
;
2191 if (is_saved_state64(regs
)) {
2192 regs64
= saved_state64(regs
);
2194 p_model
= DATAMODEL_LP64
;
2197 regs32
= saved_state32(regs
);
2198 p_model
= DATAMODEL_ILP32
;
2201 proc_t
*p
= current_proc();
2202 uthread_t uthread
= (uthread_t
)get_bsdthread_info(current_thread());
2203 user_addr_t pc
= uthread
->t_dtrace_pc
;
2204 user_addr_t npc
= uthread
->t_dtrace_npc
;
2206 uthread
->t_dtrace_pc
= 0;
2207 uthread
->t_dtrace_npc
= 0;
2208 uthread
->t_dtrace_scrpc
= 0;
2209 uthread
->t_dtrace_astpc
= 0;
2212 * Treat a child created by a call to vfork(2) as if it were its
2213 * parent. We know that there's only one thread of control in such a
2214 * process: this one.
2217 while (p
->p_lflag
& P_LINVFORK
)
2222 * We set rp->r_pc to the address of the traced instruction so
2223 * that it appears to dtrace_probe() that we're on the original
2224 * instruction, and so that the user can't easily detect our
2225 * complex web of lies. dtrace_return_probe() (our caller)
2226 * will correctly set %pc after we return.
2228 if (p_model
== DATAMODEL_LP64
)
2229 regs64
->isf
.rip
= pc
;
2233 fasttrap_return_common(regs
, pc
, p
->p_pid
, npc
);
2239 fasttrap_pid_getarg(void *arg
, dtrace_id_t id
, void *parg
, int argno
,
2242 pal_register_cache_state(current_thread(), VALID
);
2243 #pragma unused(arg, id, parg, aframes)
2244 return (fasttrap_anarg((x86_saved_state_t
*)find_user_regs(current_thread()), 1, argno
));
2248 fasttrap_usdt_getarg(void *arg
, dtrace_id_t id
, void *parg
, int argno
,
2251 pal_register_cache_state(current_thread(), VALID
);
2252 #pragma unused(arg, id, parg, aframes)
2253 return (fasttrap_anarg((x86_saved_state_t
*)find_user_regs(current_thread()), 0, argno
));
2257 * APPLE NOTE: See comments by regmap array definition. We are cheating
2258 * when returning 32 bit registers.
2261 fasttrap_getreg(x86_saved_state_t
*regs
, uint_t reg
)
2263 if (is_saved_state64(regs
)) {
2264 x86_saved_state64_t
*regs64
= saved_state64(regs
);
2267 case REG_RAX
: return regs64
->rax
;
2268 case REG_RCX
: return regs64
->rcx
;
2269 case REG_RDX
: return regs64
->rdx
;
2270 case REG_RBX
: return regs64
->rbx
;
2271 case REG_RSP
: return regs64
->isf
.rsp
;
2272 case REG_RBP
: return regs64
->rbp
;
2273 case REG_RSI
: return regs64
->rsi
;
2274 case REG_RDI
: return regs64
->rdi
;
2275 case REG_R8
: return regs64
->r8
;
2276 case REG_R9
: return regs64
->r9
;
2277 case REG_R10
: return regs64
->r10
;
2278 case REG_R11
: return regs64
->r11
;
2279 case REG_R12
: return regs64
->r12
;
2280 case REG_R13
: return regs64
->r13
;
2281 case REG_R14
: return regs64
->r14
;
2282 case REG_R15
: return regs64
->r15
;
2283 case REG_TRAPNO
: return regs64
->isf
.trapno
;
2284 case REG_ERR
: return regs64
->isf
.err
;
2285 case REG_RIP
: return regs64
->isf
.rip
;
2286 case REG_CS
: return regs64
->isf
.cs
;
2287 case REG_RFL
: return regs64
->isf
.rflags
;
2288 case REG_SS
: return regs64
->isf
.ss
;
2289 case REG_FS
: return regs64
->fs
;
2290 case REG_GS
: return regs64
->gs
;
2295 // Important to distinguish these requests (which should be legal) from other values.
2296 panic("dtrace: unimplemented x86_64 getreg()");
2299 panic("dtrace: unhandled x86_64 getreg() constant");
2301 x86_saved_state32_t
*regs32
= saved_state32(regs
);
2304 case REG_RAX
: return regs32
->eax
;
2305 case REG_RCX
: return regs32
->ecx
;
2306 case REG_RDX
: return regs32
->edx
;
2307 case REG_RBX
: return regs32
->ebx
;
2308 case REG_RSP
: return regs32
->uesp
;
2309 case REG_RBP
: return regs32
->ebp
;
2310 case REG_RSI
: return regs32
->esi
;
2311 case REG_RDI
: return regs32
->edi
;
2314 panic("dtrace: unhandled i386 getreg() constant");