]>
git.saurik.com Git - apple/xnu.git/blob - bsd/dev/ppc/dtrace_subr_ppc.c
2 * Copyright (c) 2007 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * The contents of this file are subject to the terms of the
33 * Common Development and Distribution License, Version 1.0 only
34 * (the "License"). You may not use this file except in compliance
37 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
38 * or http://www.opensolaris.org/os/licensing.
39 * See the License for the specific language governing permissions
40 * and limitations under the License.
42 * When distributing Covered Code, include this CDDL HEADER in each
43 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
44 * If applicable, add the following below this CDDL HEADER, with the
45 * fields enclosed by brackets "[]" replaced with your own identifying
46 * information: Portions Copyright [yyyy] [name of copyright owner]
51 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
52 * Use is subject to license terms.
56 * #pragma ident "@(#)dtrace_subr.c 1.12 05/06/08 SMI"
59 #define MACH__POSIX_C_SOURCE_PRIVATE 1 /* pulls in suitable savearea from mach/ppc/thread_status.h */
60 #include <sys/dtrace.h>
61 #include <sys/dtrace_glue.h>
62 #include <sys/dtrace_impl.h>
63 #include <sys/fasttrap.h>
66 #include <sys/kauth.h>
67 #include <kern/debug.h>
69 int (*dtrace_pid_probe_ptr
)(ppc_saved_state_t
*);
70 int (*dtrace_return_probe_ptr
)(ppc_saved_state_t
*);
71 kern_return_t
dtrace_user_probe(ppc_saved_state_t
*sv
);
74 dtrace_user_probe(ppc_saved_state_t
*sv
)
78 struct proc
*p
= current_proc();
80 uthread_t uthread
= (uthread_t
)get_bsdthread_info(current_thread());
82 * DTrace accesses t_cred in probe context. t_cred
83 * must always be either NULL, or point to a valid,
84 * allocated cred structure.
86 kauth_cred_uthread_update(uthread
, p
);
88 if (sv
->save_exception
== T_DTRACE_RET
) {
91 * T_DTRACE_RET is generated by the kernel when an emulation sequence
92 * ends. Unlike the x86 implementation, this can not be caused by
93 * a user state trap instruction. It is a system error if it occurs
94 * when not stepping and is, therefore, a panickable offence.
97 if(uthread
->t_dtrace_step
== 0) { /* Are we supposed to be tracing? */
98 panic("dtrace_user_probe: T_DTRACE_RET when not stepping\n");
101 if (uthread
->t_dtrace_ast
) {
102 printf("dtrace_user_probe() should be calling aston()\n");
104 // uthread->t_sig_check = 1;
108 * Clear all user tracing flags.
110 uthread
->t_dtrace_ft
= 0;
113 * We need to wait until after we've called the
114 * dtrace_return_probe_ptr function pointer to step the pc.
116 rwp
= &CPU
->cpu_ft_lock
;
117 lck_rw_lock_shared(rwp
);
119 if (dtrace_return_probe_ptr
!= NULL
) (void)(*dtrace_return_probe_ptr
)(sv
);
120 lck_rw_unlock_shared(rwp
);
122 sv
->save_srr0
= sv
->save_srr0
+ 4; /* Step to next instruction */
123 if(!(sv
->save_srr1
& 0x8000000000000000ULL
)) sv
->save_srr0
&= 0x00000000FFFFFFFF; /* Trim if in 32-bit mode */
130 * We have taken our normal trap to get here. Make sure we expect it
133 rwp
= &CPU
->cpu_ft_lock
;
136 * The DTrace fasttrap provider uses a trap, "twi 31,r31,0xDDDD".
137 * We will only be here if dtrace (or someone pretending to be us)
139 * We let DTrace take the first crack at handling
140 * this trap; if it's not a probe that DTrace knowns about,
141 * we call into the trap() routine to handle it like a
142 * breakpoint placed by a conventional debugger.
146 * APPLE NOTE: I believe the purpose of the reader/writers lock
147 * is thus: There are times which dtrace needs to prevent calling
148 * dtrace_pid_probe_ptr(). Sun's original impl grabbed a plain
149 * mutex here. However, that serialized all probe calls, and
150 * destroyed MP behavior. So now they use a RW lock, with probes
151 * as readers, and the top level synchronization as a writer.
153 lck_rw_lock_shared(rwp
);
154 if (dtrace_pid_probe_ptr
!= NULL
&&
155 (*dtrace_pid_probe_ptr
)(sv
) == 0) {
156 lck_rw_unlock_shared(rwp
);
159 lck_rw_unlock_shared(rwp
);
162 * If the instruction that caused the breakpoint trap doesn't
163 * look like our trap anymore, it may be that this tracepoint
164 * was removed just after the user thread executed it. In
165 * that case, return to user land to retry the instuction.
167 * Note that the PC is correct because we do not advance it until after emulation.
169 if (fuword32(sv
->save_srr0
, &instr
) == 0 && instr
!= FASTTRAP_INSTR
) {
176 * If we get here, we go back to throw an exception
183 dtrace_safe_synchronous_signal(void)
185 // This is commented out of the x86 code and is never called.
189 dtrace_safe_defer_signal(void)
191 // This is commented out of the x86 code and is never called.