Skip to content

Commit

Permalink
new helper: restore_saved_sigmask()
Browse files Browse the repository at this point in the history
first fruits of ..._restore_sigmask() helpers: now we can take
boilerplate "signal didn't have a handler, clear RESTORE_SIGMASK
and restore the blocked mask from ->saved_mask" into a common
helper.  Open-coded instances switched...

Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Jun 1, 2012
1 parent 4ebefe3 commit 51a7b44
Show file tree
Hide file tree
Showing 32 changed files with 38 additions and 125 deletions.
4 changes: 1 addition & 3 deletions arch/alpha/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,7 @@ do_signal(struct pt_regs * regs, struct switch_stack * sw,
}

/* If there's no signal to deliver, we just restore the saved mask. */
if (test_and_clear_thread_flag(TIF_RESTORE_SIGMASK))
set_current_blocked(&current->saved_sigmask);

restore_saved_sigmask();
if (single_stepping)
ptrace_set_bpt(current); /* re-set breakpoint */
}
Expand Down
6 changes: 1 addition & 5 deletions arch/arm/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,11 +663,7 @@ static void do_signal(struct pt_regs *regs, int syscall)
set_thread_flag(TIF_SYSCALL_RESTARTSYS);
}

/* If there's no signal to deliver, we just put the saved sigmask
* back.
*/
if (test_and_clear_thread_flag(TIF_RESTORE_SIGMASK))
set_current_blocked(&current->saved_sigmask);
restore_saved_sigmask();
}

asmlinkage void
Expand Down
5 changes: 1 addition & 4 deletions arch/avr32/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,7 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset, int syscall)

if (signr == 0) {
/* No signal to deliver -- put the saved sigmask back */
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
clear_thread_flag(TIF_RESTORE_SIGMASK);
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}
restore_saved_sigmask();
return 0;
}

Expand Down
5 changes: 1 addition & 4 deletions arch/blackfin/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,7 @@ asmlinkage void do_signal(struct pt_regs *regs)

/* if there's no signal to deliver, we just put the saved sigmask
* back */
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
clear_thread_flag(TIF_RESTORE_SIGMASK);
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}
restore_saved_sigmask();
}

/*
Expand Down
5 changes: 1 addition & 4 deletions arch/c6x/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,7 @@ static void do_signal(struct pt_regs *regs, int syscall)

/* if there's no signal to deliver, we just put the saved sigmask
* back */
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
clear_thread_flag(TIF_RESTORE_SIGMASK);
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}
restore_saved_sigmask();
}

/*
Expand Down
5 changes: 1 addition & 4 deletions arch/cris/arch-v10/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,5 @@ void do_signal(int canrestart, struct pt_regs *regs)

/* if there's no signal to deliver, we just put the saved sigmask
* back */
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
clear_thread_flag(TIF_RESTORE_SIGMASK);
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}
restore_saved_sigmask();
}
5 changes: 1 addition & 4 deletions arch/cris/arch-v32/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,7 @@ do_signal(int canrestart, struct pt_regs *regs)

/* if there's no signal to deliver, we just put the saved sigmask
* back */
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
clear_thread_flag(TIF_RESTORE_SIGMASK);
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}
restore_saved_sigmask();
}

asmlinkage void
Expand Down
6 changes: 1 addition & 5 deletions arch/frv/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,7 @@ static void do_signal(void)

/* if there's no signal to deliver, we just put the saved sigmask
* back */
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
clear_thread_flag(TIF_RESTORE_SIGMASK);
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}

restore_saved_sigmask();
} /* end do_signal() */

/*****************************************************************************/
Expand Down
3 changes: 1 addition & 2 deletions arch/h8300/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,7 @@ statis void do_signal(struct pt_regs *regs)
}

/* If there's no signal to deliver, we just restore the saved mask. */
if (test_and_clear_thread_flag(TIF_RESTORE_SIGMASK))
set_current_blocked(&current->saved_sigmask);
restore_saved_sigmask();
}

asmlinkage void do_notify_resume(struct pt_regs *regs, u32 thread_info_flags)
Expand Down
5 changes: 1 addition & 4 deletions arch/hexagon/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,7 @@ static void do_signal(struct pt_regs *regs)

no_restart:
/* If there's no signal to deliver, put the saved sigmask back */
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
clear_thread_flag(TIF_RESTORE_SIGMASK);
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}
restore_saved_sigmask();
}

void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)
Expand Down
5 changes: 1 addition & 4 deletions arch/ia64/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,5 @@ ia64_do_signal (struct sigscratch *scr, long in_syscall)

/* if there's no signal to deliver, we just put the saved sigmask
* back */
if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}
restore_saved_sigmask();
}
5 changes: 1 addition & 4 deletions arch/m32r/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,7 @@ static void do_signal(struct pt_regs *regs)
prev_insn(regs);
}
}
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
clear_thread_flag(TIF_RESTORE_SIGMASK);
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}
restore_saved_sigmask();
}

/*
Expand Down
5 changes: 1 addition & 4 deletions arch/m68k/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1182,10 +1182,7 @@ static void do_signal(struct pt_regs *regs)
handle_restart(regs, NULL, 0);

/* If there's no signal to deliver, we just restore the saved mask. */
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
clear_thread_flag(TIF_RESTORE_SIGMASK);
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}
restore_saved_sigmask();
}

void do_notify_resume(struct pt_regs *regs)
Expand Down
5 changes: 1 addition & 4 deletions arch/microblaze/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,7 @@ static void do_signal(struct pt_regs *regs, int in_syscall)
* If there's no signal to deliver, we just put the saved sigmask
* back.
*/
if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}
restore_saved_sigmask();
}

void do_notify_resume(struct pt_regs *regs, int in_syscall)
Expand Down
5 changes: 1 addition & 4 deletions arch/mips/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,10 +614,7 @@ static void do_signal(struct pt_regs *regs)
* If there's no signal to deliver, we just put the saved sigmask
* back
*/
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
clear_thread_flag(TIF_RESTORE_SIGMASK);
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}
restore_saved_sigmask();
}

/*
Expand Down
5 changes: 1 addition & 4 deletions arch/mn10300/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,7 @@ static void do_signal(struct pt_regs *regs)

/* if there's no signal to deliver, we just put the saved sigmask
* back */
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
clear_thread_flag(TIF_RESTORE_SIGMASK);
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}
restore_saved_sigmask();
}

/*
Expand Down
6 changes: 1 addition & 5 deletions arch/openrisc/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,7 @@ void do_signal(struct pt_regs *regs)
if (signr <= 0) {
/* no signal to deliver so we just put the saved sigmask
* back */
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
clear_thread_flag(TIF_RESTORE_SIGMASK);
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}

restore_saved_sigmask();
} else { /* signr > 0 */
sigset_t *oldset;

Expand Down
7 changes: 1 addition & 6 deletions arch/parisc/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,12 +621,7 @@ do_signal(struct pt_regs *regs, long in_syscall)
DBG(1,"do_signal: Exit (not delivered), regs->gr[28] = %ld\n",
regs->gr[28]);

if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
clear_thread_flag(TIF_RESTORE_SIGMASK);
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}

return;
restore_saved_sigmask();
}

void do_notify_resume(struct pt_regs *regs, long in_syscall)
Expand Down
6 changes: 1 addition & 5 deletions arch/powerpc/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,8 @@ static int do_signal(struct pt_regs *regs)
check_syscall_restart(regs, &ka, signr > 0);

if (signr <= 0) {
struct thread_info *ti = current_thread_info();
/* No signal to deliver -- put the saved sigmask back */
if (ti->local_flags & _TLF_RESTORE_SIGMASK) {
ti->local_flags &= ~_TLF_RESTORE_SIGMASK;
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}
restore_saved_sigmask();
regs->trap = 0;
return 0; /* no signals delivered */
}
Expand Down
5 changes: 1 addition & 4 deletions arch/s390/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,7 @@ void do_signal(struct pt_regs *regs)
/*
* If there's no signal to deliver, we just put the saved sigmask back.
*/
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
clear_thread_flag(TIF_RESTORE_SIGMASK);
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}
restore_saved_sigmask();
}

void do_notify_resume(struct pt_regs *regs)
Expand Down
5 changes: 1 addition & 4 deletions arch/score/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,7 @@ static void do_signal(struct pt_regs *regs)
* If there's no signal to deliver, we just put the saved sigmask
* back
*/
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
clear_thread_flag(TIF_RESTORE_SIGMASK);
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}
restore_saved_sigmask();
}

/*
Expand Down
5 changes: 1 addition & 4 deletions arch/sh/kernel/signal_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,10 +610,7 @@ static void do_signal(struct pt_regs *regs, unsigned int save_r0)
* If there's no signal to deliver, we just put the saved sigmask
* back.
*/
if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}
restore_saved_sigmask();
}

asmlinkage void do_notify_resume(struct pt_regs *regs, unsigned int save_r0,
Expand Down
7 changes: 1 addition & 6 deletions arch/sh/kernel/signal_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,7 @@ static void do_signal(struct pt_regs *regs)
}

/* No signal to deliver -- put the saved sigmask back */
if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}

return;
restore_saved_sigmask();
}

/*
Expand Down
5 changes: 1 addition & 4 deletions arch/sparc/kernel/signal32.c
Original file line number Diff line number Diff line change
Expand Up @@ -872,10 +872,7 @@ void do_signal32(sigset_t *oldset, struct pt_regs * regs)
/* If there's no signal to deliver, we just put the saved sigmask
* back
*/
if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
set_current_blocked(&current->saved_sigmask);
}
restore_saved_sigmask();
}

struct sigstack32 {
Expand Down
5 changes: 1 addition & 4 deletions arch/sparc/kernel/signal_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,7 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
/* if there's no signal to deliver, we just put the saved sigmask
* back
*/
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
clear_thread_flag(TIF_RESTORE_SIGMASK);
set_current_blocked(&current->saved_sigmask);
}
restore_saved_sigmask();
}

void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0,
Expand Down
5 changes: 1 addition & 4 deletions arch/sparc/kernel/signal_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,7 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
/* If there's no signal to deliver, we just put the saved sigmask
* back
*/
if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
set_current_blocked(&current->saved_sigmask);
}
restore_saved_sigmask();
}

void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned long thread_info_flags)
Expand Down
5 changes: 1 addition & 4 deletions arch/tile/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,7 @@ void do_signal(struct pt_regs *regs)
}

/* If there's no signal to deliver, just put the saved sigmask back. */
if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}
restore_saved_sigmask();

done:
/* Avoid double syscall restart if there are nested signals. */
Expand Down
6 changes: 2 additions & 4 deletions arch/um/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,8 @@ static int kern_do_signal(struct pt_regs *regs)
* if there's no signal to deliver, we just put the saved sigmask
* back
*/
if (!handled_sig && test_thread_flag(TIF_RESTORE_SIGMASK)) {
clear_thread_flag(TIF_RESTORE_SIGMASK);
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}
if (!handled_sig)
restore_saved_sigmask();
return handled_sig;
}

Expand Down
3 changes: 1 addition & 2 deletions arch/unicore32/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,7 @@ static void do_signal(struct pt_regs *regs, int syscall)
/* If there's no signal to deliver, we just put the saved
* sigmask back.
*/
if (test_and_clear_thread_flag(TIF_RESTORE_SIGMASK))
set_current_blocked(&current->saved_sigmask);
restore_saved_sigmask();
}

asmlinkage void do_notify_resume(struct pt_regs *regs,
Expand Down
5 changes: 1 addition & 4 deletions arch/x86/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -796,10 +796,7 @@ static void do_signal(struct pt_regs *regs)
* If there's no signal to deliver, we just put the saved sigmask
* back.
*/
if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
set_current_blocked(&current->saved_sigmask);
}
restore_saved_sigmask();
}

/*
Expand Down
3 changes: 1 addition & 2 deletions arch/xtensa/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,7 @@ static void do_signal(struct pt_regs *regs)
}

/* If there's no signal to deliver, we just restore the saved mask. */
if (test_and_clear_thread_flag(TIF_RESTORE_SIGMASK))
set_current_blocked(&current->saved_sigmask);
restore_saved_sigmask();

if (current->ptrace & PT_SINGLESTEP)
task_pt_regs(current)->icountlevel = 1;
Expand Down
6 changes: 6 additions & 0 deletions include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -2207,6 +2207,12 @@ extern int send_sigqueue(struct sigqueue *, struct task_struct *, int group);
extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *);
extern int do_sigaltstack(const stack_t __user *, stack_t __user *, unsigned long);

static inline void restore_saved_sigmask(void)
{
if (test_and_clear_restore_sigmask())
set_current_blocked(&current->saved_sigmask);
}

static inline int kill_cad_pid(int sig, int priv)
{
return kill_pid(cad_pid, sig, priv);
Expand Down

0 comments on commit 51a7b44

Please sign in to comment.