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

signal/nds32: 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: Greentime Hu <green.hu@gmail.com>
Cc: Vincent Chen <deanbo422@gmail.com>
Acked-by: default avatarVincent Chen <deanbo422@gmail.com>
Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
parent f43a54a0
...@@ -222,20 +222,13 @@ void die_if_kernel(const char *str, struct pt_regs *regs, int err) ...@@ -222,20 +222,13 @@ void die_if_kernel(const char *str, struct pt_regs *regs, int err)
int bad_syscall(int n, struct pt_regs *regs) int bad_syscall(int n, struct pt_regs *regs)
{ {
siginfo_t info;
if (current->personality != PER_LINUX) { if (current->personality != PER_LINUX) {
send_sig(SIGSEGV, current, 1); send_sig(SIGSEGV, current, 1);
return regs->uregs[0]; return regs->uregs[0];
} }
clear_siginfo(&info); force_sig_fault(SIGILL, ILL_ILLTRP,
info.si_signo = SIGILL; (void __user *)instruction_pointer(regs) - 4, current);
info.si_errno = 0;
info.si_code = ILL_ILLTRP;
info.si_addr = (void __user *)instruction_pointer(regs) - 4;
force_sig_info(SIGILL, &info, current);
die_if_kernel("Oops - bad syscall", regs, n); die_if_kernel("Oops - bad syscall", regs, n);
return regs->uregs[0]; return regs->uregs[0];
} }
...@@ -288,16 +281,11 @@ void __init early_trap_init(void) ...@@ -288,16 +281,11 @@ void __init early_trap_init(void)
void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
int error_code, int si_code) int error_code, int si_code)
{ {
struct siginfo info;
tsk->thread.trap_no = ENTRY_DEBUG_RELATED; tsk->thread.trap_no = ENTRY_DEBUG_RELATED;
tsk->thread.error_code = error_code; tsk->thread.error_code = error_code;
clear_siginfo(&info); force_sig_fault(SIGTRAP, si_code,
info.si_signo = SIGTRAP; (void __user *)instruction_pointer(regs), tsk);
info.si_code = si_code;
info.si_addr = (void __user *)instruction_pointer(regs);
force_sig_info(SIGTRAP, &info, tsk);
} }
void do_debug_trap(unsigned long entry, unsigned long addr, void do_debug_trap(unsigned long entry, unsigned long addr,
......
...@@ -72,16 +72,15 @@ void do_page_fault(unsigned long entry, unsigned long addr, ...@@ -72,16 +72,15 @@ void do_page_fault(unsigned long entry, unsigned long addr,
struct task_struct *tsk; struct task_struct *tsk;
struct mm_struct *mm; struct mm_struct *mm;
struct vm_area_struct *vma; struct vm_area_struct *vma;
siginfo_t info; int si_code;
int fault; int fault;
unsigned int mask = VM_READ | VM_WRITE | VM_EXEC; unsigned int mask = VM_READ | VM_WRITE | VM_EXEC;
unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE; unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
clear_siginfo(&info);
error_code = error_code & (ITYPE_mskINST | ITYPE_mskETYPE); error_code = error_code & (ITYPE_mskINST | ITYPE_mskETYPE);
tsk = current; tsk = current;
mm = tsk->mm; mm = tsk->mm;
info.si_code = SEGV_MAPERR; si_code = SEGV_MAPERR;
/* /*
* We fault-in kernel-space virtual memory on-demand. The * We fault-in kernel-space virtual memory on-demand. The
* 'reference' page table is init_mm.pgd. * 'reference' page table is init_mm.pgd.
...@@ -162,7 +161,7 @@ void do_page_fault(unsigned long entry, unsigned long addr, ...@@ -162,7 +161,7 @@ void do_page_fault(unsigned long entry, unsigned long addr,
*/ */
good_area: good_area:
info.si_code = SEGV_ACCERR; si_code = SEGV_ACCERR;
/* first do some preliminary protection checks */ /* first do some preliminary protection checks */
if (entry == ENTRY_PTE_NOT_PRESENT) { if (entry == ENTRY_PTE_NOT_PRESENT) {
...@@ -267,11 +266,7 @@ void do_page_fault(unsigned long entry, unsigned long addr, ...@@ -267,11 +266,7 @@ void do_page_fault(unsigned long entry, unsigned long addr,
tsk->thread.address = addr; tsk->thread.address = addr;
tsk->thread.error_code = error_code; tsk->thread.error_code = error_code;
tsk->thread.trap_no = entry; tsk->thread.trap_no = entry;
info.si_signo = SIGSEGV; force_sig_fault(SIGSEGV, si_code, (void __user *)addr, tsk);
info.si_errno = 0;
/* info.si_code has been set above */
info.si_addr = (void *)addr;
force_sig_info(SIGSEGV, &info, tsk);
return; return;
} }
...@@ -340,11 +335,7 @@ void do_page_fault(unsigned long entry, unsigned long addr, ...@@ -340,11 +335,7 @@ void do_page_fault(unsigned long entry, unsigned long addr,
tsk->thread.address = addr; tsk->thread.address = addr;
tsk->thread.error_code = error_code; tsk->thread.error_code = error_code;
tsk->thread.trap_no = entry; tsk->thread.trap_no = entry;
info.si_signo = SIGBUS; force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *)addr, tsk);
info.si_errno = 0;
info.si_code = BUS_ADRERR;
info.si_addr = (void *)addr;
force_sig_info(SIGBUS, &info, tsk);
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