]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/arm/sdt_arm.c
xnu-4570.71.2.tar.gz
[apple/xnu.git] / bsd / dev / arm / sdt_arm.c
CommitLineData
5ba3f43e
A
1/*
2 * CDDL HEADER START
3 *
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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26/* #pragma ident "@(#)sdt.c 1.6 06/03/24 SMI" */
27
28#ifdef KERNEL
29#ifndef _KERNEL
30#define _KERNEL /* Solaris vs. Darwin */
31#endif
32#endif
33
34#define MACH__POSIX_C_SOURCE_PRIVATE 1 /* pulls in suitable savearea from mach/ppc/thread_status.h */
35#include <kern/cpu_data.h>
36#include <kern/thread.h>
37#include <mach/thread_status.h>
38#include <mach/vm_param.h>
39
40#include <sys/dtrace.h>
41#include <sys/dtrace_impl.h>
42
43#include <sys/dtrace_glue.h>
44
45#include <sys/sdt_impl.h>
46
47extern sdt_probe_t **sdt_probetab;
48
49int
50sdt_invop(__unused uintptr_t addr, __unused uintptr_t *stack, __unused uintptr_t eax)
51{
52#pragma unused(eax)
53 sdt_probe_t *sdt = sdt_probetab[SDT_ADDR2NDX(addr)];
54
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;
58 uintptr_t stack4 = *((uintptr_t*) regs->sp);
59
60 dtrace_probe(sdt->sdp_id, regs->r[0], regs->r[1], regs->r[2], regs->r[3], stack4);
61
62 return (DTRACE_INVOP_NOP);
63 }
64 }
65
66 return (0);
67}
68
69struct frame {
70 struct frame *backchain;
71 uintptr_t retaddr;
72};
73
74/*ARGSUSED*/
75uint64_t
76sdt_getarg(void *arg, dtrace_id_t id, void *parg, int argno, int aframes)
77{
78#pragma unused(arg,id,parg) /* __APPLE__ */
79 uint64_t val = 0;
80 struct frame *fp = (struct frame *)__builtin_frame_address(0);
81 uintptr_t *stack;
82 uintptr_t pc;
83 int i;
84
85 /*
86 * On ARM, up to four args are passed via registers; r0,r1,r2,r3
87 * So coming into this function, arg >= 4 should be on the stack.
88 * e.g. arg==5 refers to the 6th arg passed to the probed function.
89 */
90 int inreg = 4;
91
92 for (i = 1; i <= aframes; i++) {
93 fp = fp->backchain;
94 pc = fp->retaddr;
95
96 if (dtrace_invop_callsite_pre != NULL
97 && pc > (uintptr_t)dtrace_invop_callsite_pre
98 && pc <= (uintptr_t)dtrace_invop_callsite_post) {
99
100 /*
101 * When we pass through the invalid op handler,
102 * we expect to find the save area structure,
103 * pushed on the stack where we took the trap.
104 * If the argument we seek is passed in a register, then
105 * we can load it directly from this saved area.
106 * If the argument we seek is passed on the stack, then
107 * we increment the frame pointer further, to find the
108 * pushed args
109 */
110
111 /* fp points to the dtrace_invop activation */
112 fp = fp->backchain; /* to the fbt_perfCallback activation */
113 fp = fp->backchain; /* to the sleh_undef activation */
114
115#if __BIGGEST_ALIGNMENT__ > 4
116 /**
117 * rdar://problem/24228656: On armv7k, the stack is realigned in sleh_undef2 to
118 * be 16-bytes aligned and the old value is pushed to
119 * the stack, so we retrieve it from here
120 */
121 arm_saved_state_t *saved_state = (arm_saved_state_t *)(uintptr_t*)*((uintptr_t *)&fp[1]);
122#else
123 arm_saved_state_t *saved_state = (arm_saved_state_t *)((uintptr_t *)&fp[1]);
124#endif
125 if (argno <= inreg) {
126 /* For clarity only... should not get here */
127 stack = (uintptr_t *)&saved_state->r[0];
128 } else {
129 fp = (struct frame *)(saved_state->sp);
130 stack = (uintptr_t *)&fp[0]; /* Find marshalled arguments */
131 argno -= inreg;
132 }
133 goto load;
134 }
135 }
136
137 /*
138 * We know that we did not come through a trap to get into
139 * dtrace_probe() -- We arrive here when the provider has
140 * called dtrace_probe() directly.
141 * The probe ID is the first argument to dtrace_probe().
142 * We must advance beyond that to get the argX.
143 */
144 argno++; /* Advance past probeID */
145
146 if (argno <= inreg) {
147 /*
148 * This shouldn't happen. If the argument is passed in a
149 * register then it should have been, well, passed in a
150 * register...
151 */
152 DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP);
153 return (0);
154 }
155
156 argno -= (inreg + 1);
157 stack = (uintptr_t *)&fp[1]; /* Find marshalled arguments */
158
159load:
160 DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
161 /* dtrace_probe arguments arg0 .. arg4 are 64bits wide */
162 val = (uint64_t)(*(((uintptr_t *)stack) + argno));
163 DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
164 return (val);
165
166}