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]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <kern/cpu_data.h>
27 #include <kern/thread.h>
28 #include <mach/thread_status.h>
29 #include <mach/vm_param.h>
31 #include <sys/dtrace.h>
32 #include <sys/dtrace_impl.h>
34 #include <sys/dtrace_glue.h>
36 #include <sys/sdt_impl.h>
38 extern sdt_probe_t
**sdt_probetab
;
41 sdt_invop(__unused
uintptr_t addr
, __unused
uintptr_t *stack
, __unused
uintptr_t eax
)
44 sdt_probe_t
*sdt
= sdt_probetab
[SDT_ADDR2NDX(addr
)];
46 for (; sdt
!= NULL
; sdt
= sdt
->sdp_hashnext
) {
47 if ((uintptr_t) sdt
->sdp_patchpoint
== addr
) {
48 struct arm_saved_state
* regs
= (struct arm_saved_state
*) stack
;
49 uintptr_t stack4
= *((uintptr_t*) regs
->sp
);
51 dtrace_probe(sdt
->sdp_id
, regs
->r
[0], regs
->r
[1], regs
->r
[2], regs
->r
[3], stack4
);
53 return DTRACE_INVOP_NOP
;
61 struct frame
*backchain
;
67 sdt_getarg(void *arg
, dtrace_id_t id
, void *parg
, int argno
, int aframes
)
69 #pragma unused(arg,id,parg) /* __APPLE__ */
71 struct frame
*fp
= (struct frame
*)__builtin_frame_address(0);
77 * On ARM, up to four args are passed via registers; r0,r1,r2,r3
78 * So coming into this function, arg >= 4 should be on the stack.
79 * e.g. arg==5 refers to the 6th arg passed to the probed function.
83 for (i
= 1; i
<= aframes
; i
++) {
87 if (dtrace_invop_callsite_pre
!= NULL
88 && pc
> (uintptr_t)dtrace_invop_callsite_pre
89 && pc
<= (uintptr_t)dtrace_invop_callsite_post
) {
91 * When we pass through the invalid op handler,
92 * we expect to find the save area structure,
93 * pushed on the stack where we took the trap.
94 * If the argument we seek is passed in a register, then
95 * we can load it directly from this saved area.
96 * If the argument we seek is passed on the stack, then
97 * we increment the frame pointer further, to find the
101 /* fp points to the dtrace_invop activation */
102 fp
= fp
->backchain
; /* to the fbt_perfCallback activation */
103 fp
= fp
->backchain
; /* to the sleh_undef activation */
105 #if __BIGGEST_ALIGNMENT__ > 4
107 * rdar://problem/24228656: On armv7k, the stack is realigned in sleh_undef2 to
108 * be 16-bytes aligned and the old value is pushed to
109 * the stack, so we retrieve it from here
111 arm_saved_state_t
*saved_state
= (arm_saved_state_t
*)(uintptr_t*)*((uintptr_t *)&fp
[1]);
113 arm_saved_state_t
*saved_state
= (arm_saved_state_t
*)((uintptr_t *)&fp
[1]);
115 if (argno
<= inreg
) {
116 /* For clarity only... should not get here */
117 stack
= (uintptr_t *)&saved_state
->r
[0];
119 fp
= (struct frame
*)(saved_state
->sp
);
120 stack
= (uintptr_t *)&fp
[0]; /* Find marshalled arguments */
128 * We know that we did not come through a trap to get into
129 * dtrace_probe() -- We arrive here when the provider has
130 * called dtrace_probe() directly.
131 * The probe ID is the first argument to dtrace_probe().
132 * We must advance beyond that to get the argX.
134 argno
++; /* Advance past probeID */
136 if (argno
<= inreg
) {
138 * This shouldn't happen. If the argument is passed in a
139 * register then it should have been, well, passed in a
142 DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP
);
146 argno
-= (inreg
+ 1);
147 stack
= (uintptr_t *)&fp
[1]; /* Find marshalled arguments */
150 DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT
);
151 /* dtrace_probe arguments arg0 .. arg4 are 64bits wide */
152 val
= (uint64_t)(*(((uintptr_t *)stack
) + argno
));
153 DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT
);