Commit ccf75290 authored by Eric W. Biederman's avatar Eric W. Biederman

signal/parisc: Use force_sig_fault where appropriate

Filling in struct siginfo before calling force_sig_info a tedious and
error prone process, where once in a great while the wrong fields
are filled out, and siginfo has been inconsistently cleared.

Simplify this process by using the helper force_sig_fault.  Which
takes as a parameters all of the information it needs, ensures
all of the fiddly bits of filling in struct siginfo are done properly
and then calls force_sig_info.

In short about a 5 line reduction in code for every time force_sig_info
is called, which makes the calling function clearer.

Cc: James Bottomley <jejb@parisc-linux.org>
Cc: Helge Deller <deller@gmx.de>
Cc: linux-parisc@vger.kernel.org
Acked-by: Helge Deller <deller@gmx.de>   # parisc
Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
parent c2b0e0d3
...@@ -76,8 +76,6 @@ void user_enable_single_step(struct task_struct *task) ...@@ -76,8 +76,6 @@ void user_enable_single_step(struct task_struct *task)
set_tsk_thread_flag(task, TIF_SINGLESTEP); set_tsk_thread_flag(task, TIF_SINGLESTEP);
if (pa_psw(task)->n) { if (pa_psw(task)->n) {
struct siginfo si;
/* Nullified, just crank over the queue. */ /* Nullified, just crank over the queue. */
task_regs(task)->iaoq[0] = task_regs(task)->iaoq[1]; task_regs(task)->iaoq[0] = task_regs(task)->iaoq[1];
task_regs(task)->iasq[0] = task_regs(task)->iasq[1]; task_regs(task)->iasq[0] = task_regs(task)->iasq[1];
...@@ -90,12 +88,9 @@ void user_enable_single_step(struct task_struct *task) ...@@ -90,12 +88,9 @@ void user_enable_single_step(struct task_struct *task)
ptrace_disable(task); ptrace_disable(task);
/* Don't wake up the task, but let the /* Don't wake up the task, but let the
parent know something happened. */ parent know something happened. */
clear_siginfo(&si); force_sig_fault(SIGTRAP, TRAP_TRACE,
si.si_code = TRAP_TRACE; (void __user *) (task_regs(task)->iaoq[0] & ~3),
si.si_addr = (void __user *) (task_regs(task)->iaoq[0] & ~3); task);
si.si_signo = SIGTRAP;
si.si_errno = 0;
force_sig_info(SIGTRAP, &si, task);
/* notify_parent(task, SIGCHLD); */ /* notify_parent(task, SIGCHLD); */
return; return;
} }
......
...@@ -297,14 +297,8 @@ void die_if_kernel(char *str, struct pt_regs *regs, long err) ...@@ -297,14 +297,8 @@ void die_if_kernel(char *str, struct pt_regs *regs, long err)
#define GDB_BREAK_INSN 0x10004 #define GDB_BREAK_INSN 0x10004
static void handle_gdb_break(struct pt_regs *regs, int wot) static void handle_gdb_break(struct pt_regs *regs, int wot)
{ {
struct siginfo si; force_sig_fault(SIGTRAP, wot,
(void __user *) (regs->iaoq[0] & ~3), current);
clear_siginfo(&si);
si.si_signo = SIGTRAP;
si.si_errno = 0;
si.si_code = wot;
si.si_addr = (void __user *) (regs->iaoq[0] & ~3);
force_sig_info(SIGTRAP, &si, current);
} }
static void handle_break(struct pt_regs *regs) static void handle_break(struct pt_regs *regs)
...@@ -488,9 +482,8 @@ void notrace handle_interruption(int code, struct pt_regs *regs) ...@@ -488,9 +482,8 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
{ {
unsigned long fault_address = 0; unsigned long fault_address = 0;
unsigned long fault_space = 0; unsigned long fault_space = 0;
struct siginfo si; int si_code;
clear_siginfo(&si);
if (code == 1) if (code == 1)
pdc_console_restart(); /* switch back to pdc if HPMC */ pdc_console_restart(); /* switch back to pdc if HPMC */
else else
...@@ -573,7 +566,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs) ...@@ -573,7 +566,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
case 8: case 8:
/* Illegal instruction trap */ /* Illegal instruction trap */
die_if_kernel("Illegal instruction", regs, code); die_if_kernel("Illegal instruction", regs, code);
si.si_code = ILL_ILLOPC; si_code = ILL_ILLOPC;
goto give_sigill; goto give_sigill;
case 9: case 9:
...@@ -584,7 +577,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs) ...@@ -584,7 +577,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
case 10: case 10:
/* Privileged operation trap */ /* Privileged operation trap */
die_if_kernel("Privileged operation", regs, code); die_if_kernel("Privileged operation", regs, code);
si.si_code = ILL_PRVOPC; si_code = ILL_PRVOPC;
goto give_sigill; goto give_sigill;
case 11: case 11:
...@@ -607,20 +600,16 @@ void notrace handle_interruption(int code, struct pt_regs *regs) ...@@ -607,20 +600,16 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
} }
die_if_kernel("Privileged register usage", regs, code); die_if_kernel("Privileged register usage", regs, code);
si.si_code = ILL_PRVREG; si_code = ILL_PRVREG;
give_sigill: give_sigill:
si.si_signo = SIGILL; force_sig_fault(SIGILL, si_code,
si.si_errno = 0; (void __user *) regs->iaoq[0], current);
si.si_addr = (void __user *) regs->iaoq[0];
force_sig_info(SIGILL, &si, current);
return; return;
case 12: case 12:
/* Overflow Trap, let the userland signal handler do the cleanup */ /* Overflow Trap, let the userland signal handler do the cleanup */
si.si_signo = SIGFPE; force_sig_fault(SIGFPE, FPE_INTOVF,
si.si_code = FPE_INTOVF; (void __user *) regs->iaoq[0], current);
si.si_addr = (void __user *) regs->iaoq[0];
force_sig_info(SIGFPE, &si, current);
return; return;
case 13: case 13:
...@@ -628,13 +617,11 @@ void notrace handle_interruption(int code, struct pt_regs *regs) ...@@ -628,13 +617,11 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
The condition succeeds in an instruction which traps The condition succeeds in an instruction which traps
on condition */ on condition */
if(user_mode(regs)){ if(user_mode(regs)){
si.si_signo = SIGFPE;
/* Let userspace app figure it out from the insn pointed /* Let userspace app figure it out from the insn pointed
* to by si_addr. * to by si_addr.
*/ */
si.si_code = FPE_CONDTRAP; force_sig_fault(SIGFPE, FPE_CONDTRAP,
si.si_addr = (void __user *) regs->iaoq[0]; (void __user *) regs->iaoq[0], current);
force_sig_info(SIGFPE, &si, current);
return; return;
} }
/* The kernel doesn't want to handle condition codes */ /* The kernel doesn't want to handle condition codes */
...@@ -743,14 +730,10 @@ void notrace handle_interruption(int code, struct pt_regs *regs) ...@@ -743,14 +730,10 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
return; return;
die_if_kernel("Protection id trap", regs, code); die_if_kernel("Protection id trap", regs, code);
si.si_code = SEGV_MAPERR; force_sig_fault(SIGSEGV, SEGV_MAPERR,
si.si_signo = SIGSEGV; (code == 7)?
si.si_errno = 0; ((void __user *) regs->iaoq[0]) :
if (code == 7) ((void __user *) regs->ior), current);
si.si_addr = (void __user *) regs->iaoq[0];
else
si.si_addr = (void __user *) regs->ior;
force_sig_info(SIGSEGV, &si, current);
return; return;
case 28: case 28:
...@@ -764,11 +747,8 @@ void notrace handle_interruption(int code, struct pt_regs *regs) ...@@ -764,11 +747,8 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
"handle_interruption() pid=%d command='%s'\n", "handle_interruption() pid=%d command='%s'\n",
task_pid_nr(current), current->comm); task_pid_nr(current), current->comm);
/* SIGBUS, for lack of a better one. */ /* SIGBUS, for lack of a better one. */
si.si_signo = SIGBUS; force_sig_fault(SIGBUS, BUS_OBJERR,
si.si_code = BUS_OBJERR; (void __user *)regs->ior, current);
si.si_errno = 0;
si.si_addr = (void __user *) regs->ior;
force_sig_info(SIGBUS, &si, current);
return; return;
} }
pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC); pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC);
...@@ -783,11 +763,8 @@ void notrace handle_interruption(int code, struct pt_regs *regs) ...@@ -783,11 +763,8 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
"User fault %d on space 0x%08lx, pid=%d command='%s'\n", "User fault %d on space 0x%08lx, pid=%d command='%s'\n",
code, fault_space, code, fault_space,
task_pid_nr(current), current->comm); task_pid_nr(current), current->comm);
si.si_signo = SIGSEGV; force_sig_fault(SIGSEGV, SEGV_MAPERR,
si.si_errno = 0; (void __user *)regs->ior, current);
si.si_code = SEGV_MAPERR;
si.si_addr = (void __user *) regs->ior;
force_sig_info(SIGSEGV, &si, current);
return; return;
} }
} }
......
...@@ -452,10 +452,8 @@ void handle_unaligned(struct pt_regs *regs) ...@@ -452,10 +452,8 @@ void handle_unaligned(struct pt_regs *regs)
unsigned long newbase = R1(regs->iir)?regs->gr[R1(regs->iir)]:0; unsigned long newbase = R1(regs->iir)?regs->gr[R1(regs->iir)]:0;
int modify = 0; int modify = 0;
int ret = ERR_NOTHANDLED; int ret = ERR_NOTHANDLED;
struct siginfo si;
register int flop=0; /* true if this is a flop */ register int flop=0; /* true if this is a flop */
clear_siginfo(&si);
__inc_irq_stat(irq_unaligned_count); __inc_irq_stat(irq_unaligned_count);
/* log a message with pacing */ /* log a message with pacing */
...@@ -691,21 +689,15 @@ void handle_unaligned(struct pt_regs *regs) ...@@ -691,21 +689,15 @@ void handle_unaligned(struct pt_regs *regs)
if (ret == ERR_PAGEFAULT) if (ret == ERR_PAGEFAULT)
{ {
si.si_signo = SIGSEGV; force_sig_fault(SIGSEGV, SEGV_MAPERR,
si.si_errno = 0; (void __user *)regs->ior, current);
si.si_code = SEGV_MAPERR;
si.si_addr = (void __user *)regs->ior;
force_sig_info(SIGSEGV, &si, current);
} }
else else
{ {
force_sigbus: force_sigbus:
/* couldn't handle it ... */ /* couldn't handle it ... */
si.si_signo = SIGBUS; force_sig_fault(SIGBUS, BUS_ADRALN,
si.si_errno = 0; (void __user *)regs->ior, current);
si.si_code = BUS_ADRALN;
si.si_addr = (void __user *)regs->ior;
force_sig_info(SIGBUS, &si, current);
} }
return; return;
......
...@@ -81,7 +81,6 @@ int ...@@ -81,7 +81,6 @@ int
handle_fpe(struct pt_regs *regs) handle_fpe(struct pt_regs *regs)
{ {
extern void printbinary(unsigned long x, int nbits); extern void printbinary(unsigned long x, int nbits);
struct siginfo si;
unsigned int orig_sw, sw; unsigned int orig_sw, sw;
int signalcode; int signalcode;
/* need an intermediate copy of float regs because FPU emulation /* need an intermediate copy of float regs because FPU emulation
...@@ -93,7 +92,6 @@ handle_fpe(struct pt_regs *regs) ...@@ -93,7 +92,6 @@ handle_fpe(struct pt_regs *regs)
*/ */
__u64 frcopy[36]; __u64 frcopy[36];
clear_siginfo(&si);
memcpy(frcopy, regs->fr, sizeof regs->fr); memcpy(frcopy, regs->fr, sizeof regs->fr);
frcopy[32] = 0; frcopy[32] = 0;
...@@ -118,11 +116,8 @@ handle_fpe(struct pt_regs *regs) ...@@ -118,11 +116,8 @@ handle_fpe(struct pt_regs *regs)
memcpy(regs->fr, frcopy, sizeof regs->fr); memcpy(regs->fr, frcopy, sizeof regs->fr);
if (signalcode != 0) { if (signalcode != 0) {
si.si_signo = signalcode >> 24; force_sig_fault(signalcode >> 24, signalcode & 0xffffff,
si.si_errno = 0; (void __user *) regs->iaoq[0], current);
si.si_code = signalcode & 0xffffff;
si.si_addr = (void __user *) regs->iaoq[0];
force_sig_info(si.si_signo, &si, current);
return -1; return -1;
} }
......
...@@ -353,23 +353,22 @@ void do_page_fault(struct pt_regs *regs, unsigned long code, ...@@ -353,23 +353,22 @@ void do_page_fault(struct pt_regs *regs, unsigned long code,
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
if (user_mode(regs)) { if (user_mode(regs)) {
struct siginfo si; int signo, si_code;
clear_siginfo(&si);
switch (code) { switch (code) {
case 15: /* Data TLB miss fault/Data page fault */ case 15: /* Data TLB miss fault/Data page fault */
/* send SIGSEGV when outside of vma */ /* send SIGSEGV when outside of vma */
if (!vma || if (!vma ||
address < vma->vm_start || address >= vma->vm_end) { address < vma->vm_start || address >= vma->vm_end) {
si.si_signo = SIGSEGV; signo = SIGSEGV;
si.si_code = SEGV_MAPERR; si_code = SEGV_MAPERR;
break; break;
} }
/* send SIGSEGV for wrong permissions */ /* send SIGSEGV for wrong permissions */
if ((vma->vm_flags & acc_type) != acc_type) { if ((vma->vm_flags & acc_type) != acc_type) {
si.si_signo = SIGSEGV; signo = SIGSEGV;
si.si_code = SEGV_ACCERR; si_code = SEGV_ACCERR;
break; break;
} }
...@@ -377,17 +376,16 @@ void do_page_fault(struct pt_regs *regs, unsigned long code, ...@@ -377,17 +376,16 @@ void do_page_fault(struct pt_regs *regs, unsigned long code,
/* fall through */ /* fall through */
case 17: /* NA data TLB miss / page fault */ case 17: /* NA data TLB miss / page fault */
case 18: /* Unaligned access - PCXS only */ case 18: /* Unaligned access - PCXS only */
si.si_signo = SIGBUS; signo = SIGBUS;
si.si_code = (code == 18) ? BUS_ADRALN : BUS_ADRERR; si_code = (code == 18) ? BUS_ADRALN : BUS_ADRERR;
break; break;
case 16: /* Non-access instruction TLB miss fault */ case 16: /* Non-access instruction TLB miss fault */
case 26: /* PCXL: Data memory access rights trap */ case 26: /* PCXL: Data memory access rights trap */
default: default:
si.si_signo = SIGSEGV; signo = SIGSEGV;
si.si_code = (code == 26) ? SEGV_ACCERR : SEGV_MAPERR; si_code = (code == 26) ? SEGV_ACCERR : SEGV_MAPERR;
break; break;
} }
#ifdef CONFIG_MEMORY_FAILURE #ifdef CONFIG_MEMORY_FAILURE
if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) { if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
unsigned int lsb = 0; unsigned int lsb = 0;
...@@ -409,12 +407,9 @@ void do_page_fault(struct pt_regs *regs, unsigned long code, ...@@ -409,12 +407,9 @@ void do_page_fault(struct pt_regs *regs, unsigned long code,
return; return;
} }
#endif #endif
show_signal_msg(regs, code, address, tsk, vma); show_signal_msg(regs, code, address, tsk, vma);
si.si_errno = 0; force_sig_fault(signo, si_code, (void __user *) address, current);
si.si_addr = (void __user *) address;
force_sig_info(si.si_signo, &si, current);
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment