mirror of
https://gitee.com/openharmony/kernel_linux
synced 2025-02-24 13:45:11 +00:00
[PATCH] Handle TIF_RESTORE_SIGMASK for i386
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 i386. (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) Makes 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. (10) Makes do_signal() static. (11) Marks the second argument to do_notify_resume() as unused. The unused argument should remain in the middle as the arguments are passed in as registers, and the ordering is specific in entry.S Given the way do_signal() is now no longer called from sys_{,rt_}sigsuspend(), they no longer need access to the exception frame, and so can just take arguments normally. This patch depends on 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:
parent
a411aee96e
commit
283828f3c1
@ -37,51 +37,17 @@
|
|||||||
asmlinkage int
|
asmlinkage int
|
||||||
sys_sigsuspend(int history0, int history1, old_sigset_t mask)
|
sys_sigsuspend(int history0, int history1, old_sigset_t mask)
|
||||||
{
|
{
|
||||||
struct pt_regs * regs = (struct pt_regs *) &history0;
|
|
||||||
sigset_t saveset;
|
|
||||||
|
|
||||||
mask &= _BLOCKABLE;
|
mask &= _BLOCKABLE;
|
||||||
spin_lock_irq(¤t->sighand->siglock);
|
spin_lock_irq(¤t->sighand->siglock);
|
||||||
saveset = current->blocked;
|
current->saved_sigmask = current->blocked;
|
||||||
siginitset(¤t->blocked, mask);
|
siginitset(¤t->blocked, mask);
|
||||||
recalc_sigpending();
|
recalc_sigpending();
|
||||||
spin_unlock_irq(¤t->sighand->siglock);
|
spin_unlock_irq(¤t->sighand->siglock);
|
||||||
|
|
||||||
regs->eax = -EINTR;
|
current->state = TASK_INTERRUPTIBLE;
|
||||||
while (1) {
|
schedule();
|
||||||
current->state = TASK_INTERRUPTIBLE;
|
set_thread_flag(TIF_RESTORE_SIGMASK);
|
||||||
schedule();
|
return -ERESTARTNOHAND;
|
||||||
if (do_signal(regs, &saveset))
|
|
||||||
return -EINTR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmlinkage int
|
|
||||||
sys_rt_sigsuspend(struct pt_regs regs)
|
|
||||||
{
|
|
||||||
sigset_t saveset, newset;
|
|
||||||
|
|
||||||
/* XXX: Don't preclude handling different sized sigset_t's. */
|
|
||||||
if (regs.ecx != sizeof(sigset_t))
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
if (copy_from_user(&newset, (sigset_t __user *)regs.ebx, sizeof(newset)))
|
|
||||||
return -EFAULT;
|
|
||||||
sigdelsetmask(&newset, ~_BLOCKABLE);
|
|
||||||
|
|
||||||
spin_lock_irq(¤t->sighand->siglock);
|
|
||||||
saveset = current->blocked;
|
|
||||||
current->blocked = newset;
|
|
||||||
recalc_sigpending();
|
|
||||||
spin_unlock_irq(¤t->sighand->siglock);
|
|
||||||
|
|
||||||
regs.eax = -EINTR;
|
|
||||||
while (1) {
|
|
||||||
current->state = TASK_INTERRUPTIBLE;
|
|
||||||
schedule();
|
|
||||||
if (do_signal(®s, &saveset))
|
|
||||||
return -EINTR;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
asmlinkage int
|
asmlinkage int
|
||||||
@ -433,11 +399,11 @@ static int setup_frame(int sig, struct k_sigaction *ka,
|
|||||||
current->comm, current->pid, frame, regs->eip, frame->pretcode);
|
current->comm, current->pid, frame, regs->eip, frame->pretcode);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
|
|
||||||
give_sigsegv:
|
give_sigsegv:
|
||||||
force_sigsegv(sig, current);
|
force_sigsegv(sig, current);
|
||||||
return 0;
|
return -EFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
|
static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
|
||||||
@ -527,11 +493,11 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
|
|||||||
current->comm, current->pid, frame, regs->eip, frame->pretcode);
|
current->comm, current->pid, frame, regs->eip, frame->pretcode);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
|
|
||||||
give_sigsegv:
|
give_sigsegv:
|
||||||
force_sigsegv(sig, current);
|
force_sigsegv(sig, current);
|
||||||
return 0;
|
return -EFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -581,7 +547,7 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
|
|||||||
else
|
else
|
||||||
ret = setup_frame(sig, ka, oldset, regs);
|
ret = setup_frame(sig, ka, oldset, regs);
|
||||||
|
|
||||||
if (ret) {
|
if (ret == 0) {
|
||||||
spin_lock_irq(¤t->sighand->siglock);
|
spin_lock_irq(¤t->sighand->siglock);
|
||||||
sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
|
sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
|
||||||
if (!(ka->sa.sa_flags & SA_NODEFER))
|
if (!(ka->sa.sa_flags & SA_NODEFER))
|
||||||
@ -598,11 +564,12 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
|
|||||||
* 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.
|
||||||
*/
|
*/
|
||||||
int fastcall do_signal(struct pt_regs *regs, sigset_t *oldset)
|
static void fastcall do_signal(struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
siginfo_t info;
|
siginfo_t info;
|
||||||
int signr;
|
int signr;
|
||||||
struct k_sigaction ka;
|
struct k_sigaction ka;
|
||||||
|
sigset_t *oldset;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We want the common case to go fast, which
|
* We want the common case to go fast, which
|
||||||
@ -613,12 +580,14 @@ int fastcall do_signal(struct pt_regs *regs, sigset_t *oldset)
|
|||||||
* CS suffices.
|
* CS suffices.
|
||||||
*/
|
*/
|
||||||
if (!user_mode(regs))
|
if (!user_mode(regs))
|
||||||
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 = ¤t->saved_sigmask;
|
||||||
|
else
|
||||||
oldset = ¤t->blocked;
|
oldset = ¤t->blocked;
|
||||||
|
|
||||||
signr = get_signal_to_deliver(&info, &ka, regs, NULL);
|
signr = get_signal_to_deliver(&info, &ka, regs, NULL);
|
||||||
@ -628,38 +597,55 @@ int fastcall do_signal(struct pt_regs *regs, sigset_t *oldset)
|
|||||||
* have been cleared if the watchpoint triggered
|
* have been cleared if the watchpoint triggered
|
||||||
* inside the kernel.
|
* inside the kernel.
|
||||||
*/
|
*/
|
||||||
if (unlikely(current->thread.debugreg[7])) {
|
if (unlikely(current->thread.debugreg[7]))
|
||||||
set_debugreg(current->thread.debugreg[7], 7);
|
set_debugreg(current->thread.debugreg[7], 7);
|
||||||
}
|
|
||||||
|
|
||||||
/* Whee! Actually deliver the signal. */
|
/* Whee! Actually deliver the signal. */
|
||||||
return handle_signal(signr, &info, &ka, oldset, regs);
|
if (handle_signal(signr, &info, &ka, oldset, regs) == 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 (regs->orig_eax >= 0) {
|
if (regs->orig_eax >= 0) {
|
||||||
/* Restart the system call - no handlers present */
|
/* Restart the system call - no handlers present */
|
||||||
if (regs->eax == -ERESTARTNOHAND ||
|
switch (regs->eax) {
|
||||||
regs->eax == -ERESTARTSYS ||
|
case -ERESTARTNOHAND:
|
||||||
regs->eax == -ERESTARTNOINTR) {
|
case -ERESTARTSYS:
|
||||||
|
case -ERESTARTNOINTR:
|
||||||
regs->eax = regs->orig_eax;
|
regs->eax = regs->orig_eax;
|
||||||
regs->eip -= 2;
|
regs->eip -= 2;
|
||||||
}
|
break;
|
||||||
if (regs->eax == -ERESTART_RESTARTBLOCK){
|
|
||||||
|
case -ERESTART_RESTARTBLOCK:
|
||||||
regs->eax = __NR_restart_syscall;
|
regs->eax = __NR_restart_syscall;
|
||||||
regs->eip -= 2;
|
regs->eip -= 2;
|
||||||
|
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, ¤t->saved_sigmask, NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* notification of userspace execution resumption
|
* notification of userspace execution resumption
|
||||||
* - triggered by current->work.notify_resume
|
* - triggered by the TIF_WORK_MASK flags
|
||||||
*/
|
*/
|
||||||
__attribute__((regparm(3)))
|
__attribute__((regparm(3)))
|
||||||
void do_notify_resume(struct pt_regs *regs, sigset_t *oldset,
|
void do_notify_resume(struct pt_regs *regs, void *_unused,
|
||||||
__u32 thread_info_flags)
|
__u32 thread_info_flags)
|
||||||
{
|
{
|
||||||
/* Pending single-step? */
|
/* Pending single-step? */
|
||||||
@ -667,9 +653,10 @@ void do_notify_resume(struct pt_regs *regs, sigset_t *oldset,
|
|||||||
regs->eflags |= TF_MASK;
|
regs->eflags |= TF_MASK;
|
||||||
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(regs,oldset);
|
do_signal(regs);
|
||||||
|
|
||||||
clear_thread_flag(TIF_IRET);
|
clear_thread_flag(TIF_IRET);
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,6 @@ static __inline__ int sigfindinword(unsigned long word)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct pt_regs;
|
struct pt_regs;
|
||||||
extern int FASTCALL(do_signal(struct pt_regs *regs, sigset_t *oldset));
|
|
||||||
|
|
||||||
#define ptrace_signal_deliver(regs, cookie) \
|
#define ptrace_signal_deliver(regs, cookie) \
|
||||||
do { \
|
do { \
|
||||||
|
@ -140,6 +140,7 @@ register unsigned long current_stack_pointer asm("esp") __attribute_used__;
|
|||||||
#define TIF_SYSCALL_EMU 6 /* syscall emulation active */
|
#define TIF_SYSCALL_EMU 6 /* syscall emulation active */
|
||||||
#define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
|
#define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
|
||||||
#define TIF_SECCOMP 8 /* secure computing */
|
#define TIF_SECCOMP 8 /* secure computing */
|
||||||
|
#define TIF_RESTORE_SIGMASK 9 /* 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
|
#define TIF_MEMDIE 17
|
||||||
|
|
||||||
@ -152,6 +153,7 @@ register unsigned long current_stack_pointer asm("esp") __attribute_used__;
|
|||||||
#define _TIF_SYSCALL_EMU (1<<TIF_SYSCALL_EMU)
|
#define _TIF_SYSCALL_EMU (1<<TIF_SYSCALL_EMU)
|
||||||
#define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
|
#define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
|
||||||
#define _TIF_SECCOMP (1<<TIF_SECCOMP)
|
#define _TIF_SECCOMP (1<<TIF_SECCOMP)
|
||||||
|
#define _TIF_RESTORE_SIGMASK (1<<TIF_RESTORE_SIGMASK)
|
||||||
#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
|
#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
|
||||||
|
|
||||||
/* work to do on interrupt/exception return */
|
/* work to do on interrupt/exception return */
|
||||||
|
@ -430,6 +430,7 @@ __syscall_return(type,__res); \
|
|||||||
#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
|
||||||
|
|
||||||
#ifdef __KERNEL_SYSCALLS__
|
#ifdef __KERNEL_SYSCALLS__
|
||||||
|
Loading…
x
Reference in New Issue
Block a user