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 /* #pragma ident "@(#)sdt.c 1.6 06/03/24 SMI" */
30 #define _KERNEL /* Solaris vs. Darwin */
34 #include <kern/cpu_data.h>
35 #include <kern/debug.h>
36 #include <kern/thread.h>
37 #include <mach/thread_status.h>
38 #include <mach/vm_param.h>
40 #include <sys/dtrace.h>
41 #include <sys/dtrace_impl.h>
43 #include <sys/dtrace_glue.h>
45 #include <sys/sdt_impl.h>
47 extern sdt_probe_t
**sdt_probetab
;
50 sdt_invop(__unused
uintptr_t addr
, __unused
uintptr_t *stack
, __unused
uintptr_t eax
)
53 sdt_probe_t
*sdt
= sdt_probetab
[SDT_ADDR2NDX(addr
)];
55 for (; sdt
!= NULL
; sdt
= sdt
->sdp_hashnext
) {
56 if ((uintptr_t) sdt
->sdp_patchpoint
== addr
) {
57 struct arm_saved_state
* regs
= (struct arm_saved_state
*) stack
;
59 dtrace_probe(sdt
->sdp_id
, get_saved_state_reg(regs
, 0), get_saved_state_reg(regs
, 1),
60 get_saved_state_reg(regs
, 2), get_saved_state_reg(regs
, 3),get_saved_state_reg(regs
, 4));
62 return (DTRACE_INVOP_NOP
);
70 struct frame
*backchain
;
76 sdt_getarg(void *arg
, dtrace_id_t id
, void *parg
, int argno
, int aframes
)
79 #pragma unused(arg,id,parg) /* __APPLE__ */
82 struct frame
*fp
= (struct frame
*)__builtin_frame_address(0);
88 * A total of eight arguments are passed via registers; any argument
89 * with an index of 7 or lower is therefore in a register.
94 for (i
= 1; i
<= aframes
; i
++) {
98 if (dtrace_invop_callsite_pre
!= NULL
99 && pc
> (uintptr_t)dtrace_invop_callsite_pre
100 && pc
<= (uintptr_t)dtrace_invop_callsite_post
) {
103 * When we pass through the invalid op handler,
104 * we expect to find the save area structure,
105 * pushed on the stack where we took the trap.
106 * If the argument we seek is passed in a register, then
107 * we can load it directly from this saved area.
108 * If the argument we seek is passed on the stack, then
109 * we increment the frame pointer further, to find the
113 /* fp points to the dtrace_invop activation */
114 fp
= fp
->backchain
; /* fbt_perfCallback */
115 fp
= fp
->backchain
; /* sleh_synchronous */
116 fp
= fp
->backchain
; /* fleh_synchronous */
118 arm_saved_state_t
*tagged_regs
= (arm_saved_state_t
*)((uintptr_t *)&fp
[1]);
119 arm_saved_state64_t
*saved_state
= saved_state64(tagged_regs
);
121 if (argno
<= inreg
) {
122 /* The argument will be in a register */
123 stack
= (uintptr_t *)&saved_state
->x
[0];
125 /* The argument will be found on the stack */
126 fp
= (struct frame
*)(saved_state
->sp
);
127 stack
= (uintptr_t *)&fp
[0]; /* Find marshalled arguments */
128 argno
-= (inreg
+ 1);
135 * We know that we did not come through a trap to get into
136 * dtrace_probe() -- We arrive here when the provider has
137 * called dtrace_probe() directly.
138 * The probe ID is the first argument to dtrace_probe().
139 * We must advance beyond that to get the argX.
141 argno
++; /* Advance past probeID */
143 if (argno
<= inreg
) {
145 * This shouldn't happen. If the argument is passed in a
146 * register then it should have been, well, passed in a
149 DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP
);
153 argno
-= (inreg
+ 1);
154 stack
= (uintptr_t *)&fp
[1]; /* Find marshalled arguments */
157 DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT
);
158 /* dtrace_probe arguments arg0 .. arg4 are 64bits wide */
159 val
= (uint64_t)(*(((uintptr_t *)stack
) + argno
));
160 DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT
);