Skip to content

Commit 5f50245

Browse files
committed
signal/alpha: Use send_sig_fault where appropriate
Filling in struct siginfo before calling send_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 send_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 send_sig_info. In short about a 5 line reduction in code for every time send_sig_info is called, which makes the calling function clearer. Cc: Richard Henderson <rth@twiddle.net> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru> Cc: linux-alpha@vger.kernel.org Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
1 parent e821fa4 commit 5f50245

3 files changed

Lines changed: 24 additions & 79 deletions

File tree

‎arch/alpha/kernel/osf_sys.c‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,6 @@ SYSCALL_DEFINE5(osf_setsysinfo, unsigned long, op, void __user *, buffer,
871871
send a signal. Old exceptions are not signaled. */
872872
fex = (exc >> IEEE_STATUS_TO_EXCSUM_SHIFT) & swcr;
873873
if (fex) {
874-
siginfo_t info;
875874
int si_code = FPE_FLTUNK;
876875

877876
if (fex & IEEE_TRAP_ENABLE_DNO) si_code = FPE_FLTUND;
@@ -881,12 +880,9 @@ SYSCALL_DEFINE5(osf_setsysinfo, unsigned long, op, void __user *, buffer,
881880
if (fex & IEEE_TRAP_ENABLE_DZE) si_code = FPE_FLTDIV;
882881
if (fex & IEEE_TRAP_ENABLE_INV) si_code = FPE_FLTINV;
883882

884-
clear_siginfo(&info);
885-
info.si_signo = SIGFPE;
886-
info.si_errno = 0;
887-
info.si_code = si_code;
888-
info.si_addr = NULL; /* FIXME */
889-
send_sig_info(SIGFPE, &info, current);
883+
send_sig_fault(SIGFPE, si_code,
884+
(void __user *)NULL, /* FIXME */
885+
0, current);
890886
}
891887
return 0;
892888
}

‎arch/alpha/kernel/signal.c‎

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,8 @@ do_sigreturn(struct sigcontext __user *sc)
219219

220220
/* Send SIGTRAP if we're single-stepping: */
221221
if (ptrace_cancel_bpt (current)) {
222-
siginfo_t info;
223-
224-
clear_siginfo(&info);
225-
info.si_signo = SIGTRAP;
226-
info.si_errno = 0;
227-
info.si_code = TRAP_BRKPT;
228-
info.si_addr = (void __user *) regs->pc;
229-
info.si_trapno = 0;
230-
send_sig_info(SIGTRAP, &info, current);
222+
send_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *) regs->pc, 0,
223+
current);
231224
}
232225
return;
233226

@@ -254,15 +247,8 @@ do_rt_sigreturn(struct rt_sigframe __user *frame)
254247

255248
/* Send SIGTRAP if we're single-stepping: */
256249
if (ptrace_cancel_bpt (current)) {
257-
siginfo_t info;
258-
259-
clear_siginfo(&info);
260-
info.si_signo = SIGTRAP;
261-
info.si_errno = 0;
262-
info.si_code = TRAP_BRKPT;
263-
info.si_addr = (void __user *) regs->pc;
264-
info.si_trapno = 0;
265-
send_sig_info(SIGTRAP, &info, current);
250+
send_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *) regs->pc, 0,
251+
current);
266252
}
267253
return;
268254

‎arch/alpha/kernel/traps.c‎

Lines changed: 17 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ do_entArith(unsigned long summary, unsigned long write_mask,
213213
struct pt_regs *regs)
214214
{
215215
long si_code = FPE_FLTINV;
216-
siginfo_t info;
217216

218217
if (summary & 1) {
219218
/* Software-completion summary bit is set, so try to
@@ -228,21 +227,14 @@ do_entArith(unsigned long summary, unsigned long write_mask,
228227
}
229228
die_if_kernel("Arithmetic fault", regs, 0, NULL);
230229

231-
clear_siginfo(&info);
232-
info.si_signo = SIGFPE;
233-
info.si_errno = 0;
234-
info.si_code = si_code;
235-
info.si_addr = (void __user *) regs->pc;
236-
send_sig_info(SIGFPE, &info, current);
230+
send_sig_fault(SIGFPE, si_code, (void __user *) regs->pc, 0, current);
237231
}
238232

239233
asmlinkage void
240234
do_entIF(unsigned long type, struct pt_regs *regs)
241235
{
242-
siginfo_t info;
243236
int signo, code;
244237

245-
clear_siginfo(&info);
246238
if ((regs->ps & ~IPL_MAX) == 0) {
247239
if (type == 1) {
248240
const unsigned int *data
@@ -272,31 +264,20 @@ do_entIF(unsigned long type, struct pt_regs *regs)
272264

273265
switch (type) {
274266
case 0: /* breakpoint */
275-
info.si_signo = SIGTRAP;
276-
info.si_errno = 0;
277-
info.si_code = TRAP_BRKPT;
278-
info.si_trapno = 0;
279-
info.si_addr = (void __user *) regs->pc;
280-
281267
if (ptrace_cancel_bpt(current)) {
282268
regs->pc -= 4; /* make pc point to former bpt */
283269
}
284270

285-
send_sig_info(SIGTRAP, &info, current);
271+
send_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *)regs->pc, 0,
272+
current);
286273
return;
287274

288275
case 1: /* bugcheck */
289-
info.si_signo = SIGTRAP;
290-
info.si_errno = 0;
291-
info.si_code = TRAP_UNK;
292-
info.si_addr = (void __user *) regs->pc;
293-
info.si_trapno = 0;
294-
send_sig_info(SIGTRAP, &info, current);
276+
send_sig_fault(SIGTRAP, TRAP_UNK, (void __user *) regs->pc, 0,
277+
current);
295278
return;
296279

297280
case 2: /* gentrap */
298-
info.si_addr = (void __user *) regs->pc;
299-
info.si_trapno = regs->r16;
300281
switch ((long) regs->r16) {
301282
case GEN_INTOVF:
302283
signo = SIGFPE;
@@ -354,11 +335,8 @@ do_entIF(unsigned long type, struct pt_regs *regs)
354335
break;
355336
}
356337

357-
info.si_signo = signo;
358-
info.si_errno = 0;
359-
info.si_code = code;
360-
info.si_addr = (void __user *) regs->pc;
361-
send_sig_info(signo, &info, current);
338+
send_sig_fault(signo, code, (void __user *) regs->pc, regs->r16,
339+
current);
362340
return;
363341

364342
case 4: /* opDEC */
@@ -382,11 +360,9 @@ do_entIF(unsigned long type, struct pt_regs *regs)
382360
if (si_code == 0)
383361
return;
384362
if (si_code > 0) {
385-
info.si_signo = SIGFPE;
386-
info.si_errno = 0;
387-
info.si_code = si_code;
388-
info.si_addr = (void __user *) regs->pc;
389-
send_sig_info(SIGFPE, &info, current);
363+
send_sig_fault(SIGFPE, si_code,
364+
(void __user *) regs->pc, 0,
365+
current);
390366
return;
391367
}
392368
}
@@ -411,11 +387,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
411387
;
412388
}
413389

414-
info.si_signo = SIGILL;
415-
info.si_errno = 0;
416-
info.si_code = ILL_ILLOPC;
417-
info.si_addr = (void __user *) regs->pc;
418-
send_sig_info(SIGILL, &info, current);
390+
send_sig_fault(SIGILL, ILL_ILLOPC, (void __user *)regs->pc, 0, current);
419391
}
420392

421393
/* There is an ifdef in the PALcode in MILO that enables a
@@ -761,11 +733,9 @@ do_entUnaUser(void __user * va, unsigned long opcode,
761733

762734
unsigned long tmp1, tmp2, tmp3, tmp4;
763735
unsigned long fake_reg, *reg_addr = &fake_reg;
764-
siginfo_t info;
736+
int si_code;
765737
long error;
766738

767-
clear_siginfo(&info);
768-
769739
/* Check the UAC bits to decide what the user wants us to do
770740
with the unaliged access. */
771741

@@ -986,34 +956,27 @@ do_entUnaUser(void __user * va, unsigned long opcode,
986956

987957
give_sigsegv:
988958
regs->pc -= 4; /* make pc point to faulting insn */
989-
info.si_signo = SIGSEGV;
990-
info.si_errno = 0;
991959

992960
/* We need to replicate some of the logic in mm/fault.c,
993961
since we don't have access to the fault code in the
994962
exception handling return path. */
995963
if ((unsigned long)va >= TASK_SIZE)
996-
info.si_code = SEGV_ACCERR;
964+
si_code = SEGV_ACCERR;
997965
else {
998966
struct mm_struct *mm = current->mm;
999967
down_read(&mm->mmap_sem);
1000968
if (find_vma(mm, (unsigned long)va))
1001-
info.si_code = SEGV_ACCERR;
969+
si_code = SEGV_ACCERR;
1002970
else
1003-
info.si_code = SEGV_MAPERR;
971+
si_code = SEGV_MAPERR;
1004972
up_read(&mm->mmap_sem);
1005973
}
1006-
info.si_addr = va;
1007-
send_sig_info(SIGSEGV, &info, current);
974+
send_sig_fault(SIGSEGV, si_code, va, 0, current);
1008975
return;
1009976

1010977
give_sigbus:
1011978
regs->pc -= 4;
1012-
info.si_signo = SIGBUS;
1013-
info.si_errno = 0;
1014-
info.si_code = BUS_ADRALN;
1015-
info.si_addr = va;
1016-
send_sig_info(SIGBUS, &info, current);
979+
send_sig_fault(SIGBUS, BUS_ADRALN, va, 0, current);
1017980
return;
1018981
}
1019982

0 commit comments

Comments
 (0)