11 #include <linux/kernel.h>
12 #include <linux/sched.h>
13 #include <linux/perf_event.h>
17 #include <asm/ptrace.h>
18 #include <asm/pgtable.h>
19 #include <asm/sigcontext.h>
20 #include <asm/ucontext.h>
23 #include "../kernel/ppc32.h"
32 static int valid_next_sp(
unsigned long sp,
unsigned long prev_sp)
52 unsigned long sp, next_sp;
53 unsigned long next_ip;
66 fp = (
unsigned long *) sp;
94 if ((level == 1 && next_ip == lr) ||
101 perf_callchain_store(entry, next_ip);
102 if (!valid_next_sp(next_sp, sp))
114 static int read_user_stack_slow(
void __user *
ptr,
void *
ret,
int nb)
119 unsigned long addr = (
unsigned long) ptr;
133 offset = addr & ((1
UL << shift) - 1);
147 memcpy(ret, kaddr + offset, nb);
151 static int read_user_stack_64(
unsigned long __user *ptr,
unsigned long *ret)
153 if ((
unsigned long)ptr >
TASK_SIZE -
sizeof(
unsigned long) ||
154 ((
unsigned long)ptr & 7))
158 if (!__get_user_inatomic(*ret, ptr)) {
164 return read_user_stack_slow(ptr, ret, 8);
167 static int read_user_stack_32(
unsigned int __user *ptr,
unsigned int *ret)
169 if ((
unsigned long)ptr >
TASK_SIZE -
sizeof(
unsigned int) ||
170 ((
unsigned long)ptr & 3))
174 if (!__get_user_inatomic(*ret, ptr)) {
180 return read_user_stack_slow(ptr, ret, 4);
183 static inline int valid_user_sp(
unsigned long sp,
int is_64)
185 if (!sp || (sp & 7) || sp > (is_64 ?
TASK_SIZE : 0x100000000UL) - 32)
193 struct signal_frame_64 {
197 unsigned int tramp[6];
204 static int is_sigreturn_64_address(
unsigned long nip,
unsigned long fp)
208 if (vdso64_rt_sigtramp &&
current->mm->context.vdso_base &&
209 nip ==
current->mm->context.vdso_base + vdso64_rt_sigtramp)
218 static int sane_signal_64_frame(
unsigned long sp)
223 sf = (
struct signal_frame_64
__user *) sp;
224 if (read_user_stack_64((
unsigned long __user *) &sf->pinfo, &pinfo) ||
225 read_user_stack_64((
unsigned long __user *) &sf->puc, &puc))
227 return pinfo == (
unsigned long) &sf->info &&
228 puc == (
unsigned long) &sf->uc;
234 unsigned long sp, next_sp;
235 unsigned long next_ip;
244 perf_callchain_store(entry, next_ip);
247 fp = (
unsigned long __user *) sp;
248 if (!valid_user_sp(sp, 1) || read_user_stack_64(fp, &next_sp))
250 if (level > 0 && read_user_stack_64(&fp[2], &next_ip))
259 if (next_sp - sp >=
sizeof(
struct signal_frame_64) &&
260 (is_sigreturn_64_address(next_ip, sp) ||
261 (level <= 1 && is_sigreturn_64_address(lr, sp))) &&
262 sane_signal_64_frame(sp)) {
266 sigframe = (
struct signal_frame_64
__user *) sp;
267 uregs = sigframe->uc.uc_mcontext.gp_regs;
268 if (read_user_stack_64(&uregs[
PT_NIP], &next_ip) ||
269 read_user_stack_64(&uregs[
PT_LNK], &lr) ||
270 read_user_stack_64(&uregs[
PT_R1], &sp))
274 perf_callchain_store(entry, next_ip);
280 perf_callchain_store(entry, next_ip);
286 static inline int current_is_64bit(
void)
303 static int read_user_stack_32(
unsigned int __user *ptr,
unsigned int *ret)
307 if ((
unsigned long)ptr >
TASK_SIZE -
sizeof(
unsigned int) ||
308 ((
unsigned long)ptr & 3))
312 rc = __get_user_inatomic(*ret, ptr);
323 static inline int current_is_64bit(
void)
328 static inline int valid_user_sp(
unsigned long sp,
int is_64)
330 if (!sp || (sp & 7) || sp >
TASK_SIZE - 32)
335 #define __SIGNAL_FRAMESIZE32 __SIGNAL_FRAMESIZE
336 #define sigcontext32 sigcontext
337 #define mcontext32 mcontext
338 #define ucontext32 ucontext
339 #define compat_siginfo_t struct siginfo
363 static int is_sigreturn_32_address(
unsigned int nip,
unsigned int fp)
373 static int is_rt_sigreturn_32_address(
unsigned int nip,
unsigned int fp)
376 uc.uc_mcontext.mc_pad))
384 static int sane_signal_32_frame(
unsigned int sp)
390 if (read_user_stack_32((
unsigned int __user *) &sf->
sctx.regs, ®s))
392 return regs == (
unsigned long) &sf->
mctx;
395 static int sane_rt_signal_32_frame(
unsigned int sp)
401 if (read_user_stack_32((
unsigned int __user *) &sf->
uc.uc_regs, ®s))
403 return regs == (
unsigned long) &sf->
uc.uc_mcontext;
406 static unsigned int __user *signal_frame_32_regs(
unsigned int sp,
407 unsigned int next_sp,
unsigned int next_ip)
420 is_sigreturn_32_address(next_ip, sp) &&
421 sane_signal_32_frame(sp)) {
427 is_rt_sigreturn_32_address(next_ip, sp) &&
428 sane_rt_signal_32_frame(sp)) {
430 mctx = &rt_sf->
uc.uc_mcontext;
441 unsigned int sp, next_sp;
442 unsigned int next_ip;
450 perf_callchain_store(entry, next_ip);
453 fp = (
unsigned int __user *) (
unsigned long)
sp;
454 if (!valid_user_sp(sp, 0) || read_user_stack_32(fp, &next_sp))
456 if (level > 0 && read_user_stack_32(&fp[1], &next_ip))
459 uregs = signal_frame_32_regs(sp, next_sp, next_ip);
460 if (!uregs && level <= 1)
461 uregs = signal_frame_32_regs(sp, next_sp, lr);
467 if (read_user_stack_32(&uregs[
PT_NIP], &next_ip) ||
468 read_user_stack_32(&uregs[
PT_LNK], &lr) ||
469 read_user_stack_32(&uregs[
PT_R1], &sp))
473 perf_callchain_store(entry, next_ip);
479 perf_callchain_store(entry, next_ip);
488 if (current_is_64bit())
489 perf_callchain_user_64(entry, regs);
491 perf_callchain_user_32(entry, regs);