1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/dtrace.h>
#include <sys/fasttrap.h>
#include <sys/x_call.h>
#include <sys/atomic.h>
#include <sys/machsystm.h>
static void
dtrace_xcall_func(uint64_t arg1, uint64_t arg2)
{
(*(dtrace_xcall_t)arg1)((void *)(arg2));
}
void
dtrace_xcall(processorid_t cpu, dtrace_xcall_t func, void *arg)
{
if (cpu == DTRACE_CPUALL) {
xc_all(dtrace_xcall_func, (uint64_t)func, (uint64_t)arg);
} else {
xc_one(cpu, dtrace_xcall_func, (uint64_t)func, (uint64_t)arg);
}
}
/*ARGSUSED*/
static void
dtrace_sync_func(uint64_t arg1, uint64_t arg2)
{
membar_consumer();
}
void
dtrace_sync(void)
{
membar_producer();
xc_all(dtrace_sync_func, 0, 0);
}
void
dtrace_toxic_ranges(void (*func)(uintptr_t base, uintptr_t limit))
{
(*func)(PIOMAPBASE, PIOMAPBASE + PIOMAPSIZE);
(*func)(OFW_START_ADDR, OFW_END_ADDR);
if (hole_end > hole_start)
(*func)((uintptr_t)hole_start, (uintptr_t)hole_end);
}
int (*dtrace_pid_probe_ptr)(struct regs *);
void
dtrace_pid_probe(struct regs *rp)
{
krwlock_t *rwp = &CPU->cpu_ft_lock;
uint32_t instr;
/*
* This trap should only be invoked if there's a corresponding
* enabled dtrace probe. If there isn't, send SIGILL as though
* the process had executed an invalid trap instruction.
*/
rw_enter(rwp, RW_READER);
if (dtrace_pid_probe_ptr != NULL && (*dtrace_pid_probe_ptr)(rp) == 0) {
rw_exit(rwp);
return;
}
rw_exit(rwp);
/*
* It is possible that we were preempted after entering the kernel,
* and the tracepoint was removed. If it appears that the process hit
* our reserved trap instruction, we call send SIGILL just as though
* the user had executed an unused trap instruction.
*/
if (fuword32((void *)rp->r_pc, &instr) != 0 ||
instr == FASTTRAP_INSTR) {
sigqueue_t *sqp = kmem_zalloc(sizeof (sigqueue_t), KM_SLEEP);
proc_t *p = curproc;
sqp->sq_info.si_signo = SIGILL;
sqp->sq_info.si_code = ILL_ILLTRP;
sqp->sq_info.si_addr = (caddr_t)rp->r_pc;
sqp->sq_info.si_trapno = 0x38;
mutex_enter(&p->p_lock);
sigaddqa(p, curthread, sqp);
mutex_exit(&p->p_lock);
aston(curthread);
}
}
int (*dtrace_return_probe_ptr)(struct regs *);
void
dtrace_return_probe(struct regs *rp)
{
krwlock_t *rwp;
uintptr_t npc = curthread->t_dtrace_npc;
uint8_t step = curthread->t_dtrace_step;
uint8_t ret = curthread->t_dtrace_ret;
if (curthread->t_dtrace_ast) {
aston(curthread);
curthread->t_sig_check = 1;
}
/*
* Clear all user tracing flags.
*/
curthread->t_dtrace_ft = 0;
/*
* If we weren't expecting to take a return probe trap, kill the
* process as though it had just executed an unassigned trap
* instruction.
*/
if (step == 0) {
tsignal(curthread, SIGILL);
return;
}
ASSERT(rp->r_npc == rp->r_pc + 4);
/*
* If we hit this trap unrelated to a return probe, we're just here
* to reset the AST flag since we deferred a signal until after we
* logically single-stepped the instruction we copied out.
*/
if (ret == 0) {
rp->r_pc = npc;
rp->r_npc = npc + 4;
return;
}
/*
* We need to wait until after we've called the dtrace_return_probe_ptr
* function pointer to set %pc and %npc.
*/
rwp = &CPU->cpu_ft_lock;
rw_enter(rwp, RW_READER);
if (dtrace_return_probe_ptr != NULL)
(void) (*dtrace_return_probe_ptr)(rp);
rw_exit(rwp);
rp->r_pc = npc;
rp->r_npc = npc + 4;
}
void
dtrace_safe_synchronous_signal(void)
{
kthread_t *t = curthread;
struct regs *rp = lwptoregs(ttolwp(t));
ASSERT(t->t_dtrace_on);
/*
* If we're not actively tracing an instruction, turn off tracing
* flags. If the instruction we copied out caused a synchronous
* trap, reset the pc and npc back to their original values and turn
* off the flags.
*/
if (rp->r_pc != t->t_dtrace_scrpc && rp->r_pc != t->t_dtrace_astpc &&
rp->r_npc != t->t_dtrace_astpc) {
t->t_dtrace_ft = 0;
} else if (rp->r_pc == t->t_dtrace_scrpc) {
rp->r_pc = t->t_dtrace_pc;
rp->r_npc = t->t_dtrace_npc;
t->t_dtrace_ft = 0;
}
}
int
dtrace_safe_defer_signal(void)
{
kthread_t *t = curthread;
struct regs *rp = lwptoregs(ttolwp(t));
ASSERT(t->t_dtrace_on);
/*
* If we're not actively tracing an instruction, turn off tracing
* flags.
*/
if (rp->r_pc != t->t_dtrace_scrpc && rp->r_pc != t->t_dtrace_astpc &&
rp->r_npc != t->t_dtrace_astpc) {
t->t_dtrace_ft = 0;
return (0);
}
/*
* Otherwise, make sure we'll return to the kernel after executing
* the instruction we copied out.
*/
if (!t->t_dtrace_step) {
ASSERT(rp->r_pc == t->t_dtrace_scrpc);
rp->r_npc = t->t_dtrace_astpc;
t->t_dtrace_step = 1;
}
t->t_dtrace_ast = 1;
return (1);
}
/*
* Additional artificial frames for the machine type. For SPARC, we're already
* accounted for, so return 0.
*/
int
dtrace_mach_aframes(void)
{
return (0);
}
|