16 #include <linux/sched.h>
19 #include <linux/kernel.h>
20 #include <linux/signal.h>
21 #include <linux/errno.h>
22 #include <linux/wait.h>
23 #include <linux/ptrace.h>
26 #include <linux/stddef.h>
28 #include <linux/elf.h>
29 #include <asm/ucontext.h>
31 #include <asm/uaccess.h>
32 #include <asm/pgalloc.h>
33 #include <asm/cacheflush.h>
34 #include <asm/asm-offsets.h>
41 #define DEBUG_SIG_LEVEL 2
44 #define DBG(LEVEL, ...) \
45 ((DEBUG_SIG_LEVEL >= LEVEL) \
46 ? printk(__VA_ARGS__) : (void) 0)
48 #define DBG(LEVEL, ...)
56 #define A(__x) ((unsigned long)(__x))
70 #define INSN_LDI_R25_0 0x34190000
71 #define INSN_LDI_R25_1 0x34190002
72 #define INSN_LDI_R20 0x3414015a
73 #define INSN_BLE_SR2_R0 0xe4008200
74 #define INSN_NOP 0x08000240
76 #define INSN_DIE_HORRIBLY 0x68000ccc
88 DBG(2,
"restore_sigcontext: iaoq is 0x%#lx / 0x%#lx\n",
90 DBG(2,
"restore_sigcontext: r28 is %ld\n", regs->
gr[28]);
99 unsigned long usp = (regs->
gr[30] & ~(0x01
UL));
102 compat_sigset_t compat_set;
113 (usp - sigframe_size);
114 DBG(2,
"sys_rt_sigreturn: frame is %p\n", frame);
122 DBG(2,
"sys_rt_sigreturn: ELF32 process.\n");
138 DBG(1,
"sys_rt_sigreturn: compat_frame->uc.uc_mcontext 0x%p\n",
139 &compat_frame->
uc.uc_mcontext);
142 &compat_frame->
regs, regs))
144 DBG(1,
"sys_rt_sigreturn: usp %#08lx stack 0x%p\n",
145 usp, &compat_frame->
uc.uc_stack);
151 DBG(1,
"sys_rt_sigreturn: frame->uc.uc_mcontext 0x%p\n",
152 &frame->
uc.uc_mcontext);
155 DBG(1,
"sys_rt_sigreturn: usp %#08lx stack 0x%p\n",
156 usp, &frame->
uc.uc_stack);
167 regs->
gr[31] = regs->
iaoq[0];
169 DBG(1,
"sys_rt_sigreturn: returning to %#lx, DUMPING REGS:\n", regs->
iaoq[0]);
175 DBG(1,
"sys_rt_sigreturn: Sending SIGSEGV\n");
184 static inline void __user *
190 DBG(1,
"get_sigframe: ka = %#lx, sp = %#lx, frame_size = %#lx\n",
191 (
unsigned long)ka, sp, frame_size);
193 if ((ka->
sa.sa_flags &
SA_ONSTACK) != 0 && ! sas_ss_flags(sp))
196 DBG(1,
"get_sigframe: Returning sp = %#lx\n", (
unsigned long)sp);
197 return (
void __user *)
sp;
204 unsigned long flags = 0;
207 if (on_sig_stack((
unsigned long) sc))
216 DBG(1,
"setup_sigcontext: iaoq %#lx / %#lx (in syscall)\n",
217 regs->
gr[31], regs->
gr[31]+4);
221 DBG(1,
"setup_sigcontext: iaoq %#lx / %#lx (not in syscall)\n",
229 DBG(1,
"setup_sigcontext: r28 is %ld\n", regs->
gr[28]);
239 unsigned long rp, usp;
240 unsigned long haddr, sigframe_size;
245 compat_sigset_t compat_set;
248 usp = (regs->
gr[30] & ~(0x01
UL));
252 DBG(1,
"SETUP_RT_FRAME: START\n");
253 DBG(1,
"setup_rt_frame: frame %p info %p\n", frame, info);
261 DBG(1,
"setup_rt_frame: frame->info = 0x%p\n", &compat_frame->
info);
263 DBG(1,
"SETUP_RT_FRAME: 1\n");
265 err |=
__put_user(compat_val, &compat_frame->
uc.uc_stack.ss_sp);
266 DBG(1,
"SETUP_RT_FRAME: 2\n");
268 err |=
__put_user(compat_val, &compat_frame->
uc.uc_stack.ss_size);
269 DBG(1,
"SETUP_RT_FRAME: 3\n");
270 compat_val = sas_ss_flags(regs->
gr[30]);
271 err |=
__put_user(compat_val, &compat_frame->
uc.uc_stack.ss_flags);
272 DBG(1,
"setup_rt_frame: frame->uc = 0x%p\n", &compat_frame->
uc);
273 DBG(1,
"setup_rt_frame: frame->uc.uc_mcontext = 0x%p\n", &compat_frame->
uc.uc_mcontext);
275 &compat_frame->
regs, regs, in_syscall);
277 err |=
__copy_to_user(&compat_frame->
uc.uc_sigmask, &compat_set,
sizeof(compat_set));
281 DBG(1,
"setup_rt_frame: frame->info = 0x%p\n", &frame->
info);
286 &frame->
uc.uc_stack.ss_flags);
287 DBG(1,
"setup_rt_frame: frame->uc = 0x%p\n", &frame->
uc);
288 DBG(1,
"setup_rt_frame: frame->uc.uc_mcontext = 0x%p\n", &frame->
uc.uc_mcontext);
314 asm (
"mfsp %%sr3,%0" :
"=r" (
sid));
315 DBG(1,
"setup_rt_frame: Flushing 64 bytes at space %#x offset %p\n",
334 haddr =
A(ka->
sa.sa_handler);
349 regs->
gr[19] = fdesc.
gp;
362 regs->
gr[19] = fdesc.
gp;
363 DBG(1,
"setup_rt_frame: 64 bit signal, exe=%#lx, r19=%#lx, in_syscall=%d\n",
364 haddr, regs->
gr[19], in_syscall);
376 regs->
gr[31] = haddr;
378 if (!test_thread_flag(TIF_32BIT))
384 if (!test_thread_flag(TIF_32BIT))
401 regs->
iaoq[0] = haddr | 3;
410 regs->
gr[25] =
A(&compat_frame->
info);
411 regs->
gr[24] =
A(&compat_frame->
uc);
415 regs->
gr[25] =
A(&frame->
info);
416 regs->
gr[24] =
A(&frame->
uc);
419 DBG(1,
"setup_rt_frame: making sigreturn frame: %#lx + %#lx = %#lx\n",
420 regs->
gr[30], sigframe_size,
421 regs->
gr[30] + sigframe_size);
423 regs->
gr[30] = (
A(frame) + sigframe_size);
426 DBG(1,
"setup_rt_frame: sig deliver (%s,%d) frame=0x%p sp=%#lx iaoq=%#lx/%#lx rp=%#lx\n",
433 DBG(1,
"setup_rt_frame: sending SIGSEGV\n");
444 struct pt_regs *regs,
int in_syscall)
446 sigset_t *oldset = sigmask_to_save();
447 DBG(1,
"handle_signal: sig=%ld, ka=%p, info=%p, oldset=%p, regs=%p\n",
448 sig, ka, info, oldset, regs);
451 if (!setup_rt_frame(sig, ka, info, oldset, regs, in_syscall))
458 DBG(1,
KERN_DEBUG "do_signal: Exit (success), regs->gr[28] = %ld\n",
469 switch (regs->
gr[28]) {
472 DBG(1,
"ERESTARTNOHAND: returning -EINTR\n");
478 DBG(1,
"ERESTARTSYS: putting -EINTR\n");
493 insert_restart_trampoline(
struct pt_regs *regs)
498 switch(regs->
gr[28]) {
501 unsigned int *usp = (
unsigned int *)regs->
gr[30];
531 regs->
gr[31] = regs->
gr[30] + 8;
568 DBG(1,
"\ndo_signal: regs=0x%p, sr7 %#lx, in_syscall=%d\n",
569 regs, regs->
sr[7], in_syscall);
572 DBG(3,
"do_signal: signr = %d, regs->gr[28] = %ld\n", signr, regs->
gr[28]);
577 syscall_restart(regs, &ka);
579 handle_signal(signr, &info, &ka, regs, in_syscall);
585 insert_restart_trampoline(regs);
587 DBG(1,
"do_signal: Exit (not delivered), regs->gr[28] = %ld\n",
590 restore_saved_sigmask();
600 tracehook_notify_resume(regs);