[PATCH] Handle TIF_RESTORE_SIGMASK for FRV

Handle TIF_RESTORE_SIGMASK as added by David Woodhouse's patch entitled:

        [PATCH] 2/3 Add TIF_RESTORE_SIGMASK support for arch/powerpc
        [PATCH] 3/3 Generic sys_rt_sigsuspend

It does the following:

 (1) Declares TIF_RESTORE_SIGMASK for FRV.

 (2) Invokes it over to do_signal() when TIF_RESTORE_SIGMASK is set.

 (3) Makes do_signal() support TIF_RESTORE_SIGMASK, using the signal mask saved
     in current->saved_sigmask.

 (4) Discards sys_rt_sigsuspend() from the arch, using the generic one instead.

 (5) Makes sys_sigsuspend() save the signal mask and set TIF_RESTORE_SIGMASK
     rather than attempting to fudge the return registers.

 (6) Makes sys_sigsuspend() return -ERESTARTNOHAND rather than looping
     intrinsically.

 (7) Makes setup_frame(), setup_rt_frame() and handle_signal() return 0 or
     -EFAULT rather than true/false to be consistent with the rest of the
      kernel.

Due to the fact do_signal() is then only called from one place:

 (8) Make do_signal() no longer have a return value is it was just being
     ignored; force_sig() takes care of this.

 (9) Discards the old sigmask argument to do_signal() as it's no longer
     necessary.

This patch depends on the FRV signalling patches as well as the
sys_rt_sigsuspend patch.

Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
David Howells 2006-01-18 17:43:59 -08:00 committed by Linus Torvalds
parent 150256d8aa
commit a411aee96e
3 changed files with 47 additions and 76 deletions

View File

@ -35,74 +35,22 @@ struct fdpic_func_descriptor {
unsigned long GOT; unsigned long GOT;
}; };
static int do_signal(sigset_t *oldset);
/* /*
* Atomically swap in the new signal mask, and wait for a signal. * Atomically swap in the new signal mask, and wait for a signal.
*/ */
asmlinkage int sys_sigsuspend(int history0, int history1, old_sigset_t mask) asmlinkage int sys_sigsuspend(int history0, int history1, old_sigset_t mask)
{ {
sigset_t saveset;
mask &= _BLOCKABLE; mask &= _BLOCKABLE;
spin_lock_irq(&current->sighand->siglock); spin_lock_irq(&current->sighand->siglock);
saveset = current->blocked; current->saved_sigmask = current->blocked;
siginitset(&current->blocked, mask); siginitset(&current->blocked, mask);
recalc_sigpending(); recalc_sigpending();
spin_unlock_irq(&current->sighand->siglock); spin_unlock_irq(&current->sighand->siglock);
__frame->gr8 = -EINTR; current->state = TASK_INTERRUPTIBLE;
while (1) { schedule();
current->state = TASK_INTERRUPTIBLE; set_thread_flag(TIF_RESTORE_SIGMASK);
schedule(); return -ERESTARTNOHAND;
if (do_signal(&saveset))
/* return the signal number as the return value of this function
* - this is an utterly evil hack. syscalls should not invoke do_signal()
* as entry.S sets regs->gr8 to the return value of the system call
* - we can't just use sigpending() as we'd have to discard SIG_IGN signals
* and call waitpid() if SIGCHLD needed discarding
* - this only works on the i386 because it passes arguments to the signal
* handler on the stack, and the return value in EAX is effectively
* discarded
*/
return __frame->gr8;
}
}
asmlinkage int sys_rt_sigsuspend(sigset_t __user *unewset, size_t sigsetsize)
{
sigset_t saveset, newset;
/* XXX: Don't preclude handling different sized sigset_t's. */
if (sigsetsize != sizeof(sigset_t))
return -EINVAL;
if (copy_from_user(&newset, unewset, sizeof(newset)))
return -EFAULT;
sigdelsetmask(&newset, ~_BLOCKABLE);
spin_lock_irq(&current->sighand->siglock);
saveset = current->blocked;
current->blocked = newset;
recalc_sigpending();
spin_unlock_irq(&current->sighand->siglock);
__frame->gr8 = -EINTR;
while (1) {
current->state = TASK_INTERRUPTIBLE;
schedule();
if (do_signal(&saveset))
/* return the signal number as the return value of this function
* - this is an utterly evil hack. syscalls should not invoke do_signal()
* as entry.S sets regs->gr8 to the return value of the system call
* - we can't just use sigpending() as we'd have to discard SIG_IGN signals
* and call waitpid() if SIGCHLD needed discarding
* - this only works on the i386 because it passes arguments to the signal
* handler on the stack, and the return value in EAX is effectively
* discarded
*/
return __frame->gr8;
}
} }
asmlinkage int sys_sigaction(int sig, asmlinkage int sys_sigaction(int sig,
@ -372,11 +320,11 @@ static int setup_frame(int sig, struct k_sigaction *ka, sigset_t *set)
frame->pretcode); frame->pretcode);
#endif #endif
return 1; return 0;
give_sigsegv: give_sigsegv:
force_sig(SIGSEGV, current); force_sig(SIGSEGV, current);
return 0; return -EFAULT;
} /* end setup_frame() */ } /* end setup_frame() */
@ -471,11 +419,11 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
frame->pretcode); frame->pretcode);
#endif #endif
return 1; return 0;
give_sigsegv: give_sigsegv:
force_sig(SIGSEGV, current); force_sig(SIGSEGV, current);
return 0; return -EFAULT;
} /* end setup_rt_frame() */ } /* end setup_rt_frame() */
@ -516,7 +464,7 @@ static int handle_signal(unsigned long sig, siginfo_t *info,
else else
ret = setup_frame(sig, ka, oldset); ret = setup_frame(sig, ka, oldset);
if (ret) { if (ret == 0) {
spin_lock_irq(&current->sighand->siglock); spin_lock_irq(&current->sighand->siglock);
sigorsets(&current->blocked, &current->blocked, sigorsets(&current->blocked, &current->blocked,
&ka->sa.sa_mask); &ka->sa.sa_mask);
@ -536,10 +484,11 @@ static int handle_signal(unsigned long sig, siginfo_t *info,
* want to handle. Thus you cannot kill init even with a SIGKILL even by * want to handle. Thus you cannot kill init even with a SIGKILL even by
* mistake. * mistake.
*/ */
static int do_signal(sigset_t *oldset) static void do_signal(void)
{ {
struct k_sigaction ka; struct k_sigaction ka;
siginfo_t info; siginfo_t info;
sigset_t *oldset;
int signr; int signr;
/* /*
@ -549,43 +498,62 @@ static int do_signal(sigset_t *oldset)
* if so. * if so.
*/ */
if (!user_mode(__frame)) if (!user_mode(__frame))
return 1; return;
if (try_to_freeze()) if (try_to_freeze())
goto no_signal; goto no_signal;
if (!oldset) if (test_thread_flag(TIF_RESTORE_SIGMASK))
oldset = &current->saved_sigmask;
else
oldset = &current->blocked; oldset = &current->blocked;
signr = get_signal_to_deliver(&info, &ka, __frame, NULL); signr = get_signal_to_deliver(&info, &ka, __frame, NULL);
if (signr > 0) if (signr > 0) {
return handle_signal(signr, &info, &ka, oldset); if (handle_signal(signr, &info, &ka, oldset) == 0) {
/* a signal was successfully delivered; the saved
* sigmask will have been stored in the signal frame,
* and will be restored by sigreturn, so we can simply
* clear the TIF_RESTORE_SIGMASK flag */
if (test_thread_flag(TIF_RESTORE_SIGMASK))
clear_thread_flag(TIF_RESTORE_SIGMASK);
}
return;
}
no_signal: no_signal:
/* Did we come from a system call? */ /* Did we come from a system call? */
if (__frame->syscallno >= 0) { if (__frame->syscallno >= 0) {
/* Restart the system call - no handlers present */ /* Restart the system call - no handlers present */
if (__frame->gr8 == -ERESTARTNOHAND || switch (__frame->gr8) {
__frame->gr8 == -ERESTARTSYS || case -ERESTARTNOHAND:
__frame->gr8 == -ERESTARTNOINTR) { case -ERESTARTSYS:
case -ERESTARTNOINTR:
__frame->gr8 = __frame->orig_gr8; __frame->gr8 = __frame->orig_gr8;
__frame->pc -= 4; __frame->pc -= 4;
} break;
if (__frame->gr8 == -ERESTART_RESTARTBLOCK){ case -ERESTART_RESTARTBLOCK:
__frame->gr8 = __NR_restart_syscall; __frame->gr8 = __NR_restart_syscall;
__frame->pc -= 4; __frame->pc -= 4;
break;
} }
} }
return 0; /* 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);
}
} /* end do_signal() */ } /* end do_signal() */
/*****************************************************************************/ /*****************************************************************************/
/* /*
* notification of userspace execution resumption * notification of userspace execution resumption
* - triggered by current->work.notify_resume * - triggered by the TIF_WORK_MASK flags
*/ */
asmlinkage void do_notify_resume(__u32 thread_info_flags) asmlinkage void do_notify_resume(__u32 thread_info_flags)
{ {
@ -594,7 +562,7 @@ asmlinkage void do_notify_resume(__u32 thread_info_flags)
clear_thread_flag(TIF_SINGLESTEP); clear_thread_flag(TIF_SINGLESTEP);
/* deal with pending signal delivery */ /* deal with pending signal delivery */
if (thread_info_flags & _TIF_SIGPENDING) if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
do_signal(NULL); do_signal();
} /* end do_notify_resume() */ } /* end do_notify_resume() */

View File

@ -129,6 +129,7 @@ register struct thread_info *__current_thread_info asm("gr15");
#define TIF_NEED_RESCHED 3 /* rescheduling necessary */ #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
#define TIF_SINGLESTEP 4 /* restore singlestep on return to user mode */ #define TIF_SINGLESTEP 4 /* restore singlestep on return to user mode */
#define TIF_IRET 5 /* return with iret */ #define TIF_IRET 5 /* return with iret */
#define TIF_RESTORE_SIGMASK 6 /* restore signal mask in do_signal() */
#define TIF_POLLING_NRFLAG 16 /* true if poll_idle() is polling TIF_NEED_RESCHED */ #define TIF_POLLING_NRFLAG 16 /* true if poll_idle() is polling TIF_NEED_RESCHED */
#define TIF_MEMDIE 17 /* OOM killer killed process */ #define TIF_MEMDIE 17 /* OOM killer killed process */
@ -138,6 +139,7 @@ register struct thread_info *__current_thread_info asm("gr15");
#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED) #define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
#define _TIF_SINGLESTEP (1 << TIF_SINGLESTEP) #define _TIF_SINGLESTEP (1 << TIF_SINGLESTEP)
#define _TIF_IRET (1 << TIF_IRET) #define _TIF_IRET (1 << TIF_IRET)
#define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG) #define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
#define _TIF_WORK_MASK 0x0000FFFE /* work to do on interrupt/exception return */ #define _TIF_WORK_MASK 0x0000FFFE /* work to do on interrupt/exception return */

View File

@ -486,6 +486,7 @@ static inline pid_t wait(int * wait_stat)
/* #define __ARCH_WANT_SYS_SIGPENDING */ /* #define __ARCH_WANT_SYS_SIGPENDING */
#define __ARCH_WANT_SYS_SIGPROCMASK #define __ARCH_WANT_SYS_SIGPROCMASK
#define __ARCH_WANT_SYS_RT_SIGACTION #define __ARCH_WANT_SYS_RT_SIGACTION
#define __ARCH_WANT_SYS_RT_SIGSUSPEND
#endif #endif
/* /*