forked from luck/tmp_suning_uos_patched
[PATCH] Add TIF_RESTORE_SIGMASK
We need TIF_RESTORE_SIGMASK in order to support ppoll() and pselect() system calls. This patch originally came from Andi, and was based heavily on David Howells' implementation of same on i386. I fixed a typo which was causing do_signal() to use the wrong signal mask. Signed-off-by: David Woodhouse <dwmw2@infradead.org> Signed-off-by: Andi Kleen <ak@suse.de>
This commit is contained in:
parent
3adbbcce9a
commit
1d001df19d
@ -113,25 +113,19 @@ int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from)
|
|||||||
}
|
}
|
||||||
|
|
||||||
asmlinkage long
|
asmlinkage long
|
||||||
sys32_sigsuspend(int history0, int history1, old_sigset_t mask,
|
sys32_sigsuspend(int history0, int history1, old_sigset_t mask)
|
||||||
struct pt_regs *regs)
|
|
||||||
{
|
{
|
||||||
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->rax = -EINTR;
|
|
||||||
while (1) {
|
|
||||||
current->state = TASK_INTERRUPTIBLE;
|
current->state = TASK_INTERRUPTIBLE;
|
||||||
schedule();
|
schedule();
|
||||||
if (do_signal(regs, &saveset))
|
set_thread_flag(TIF_RESTORE_SIGMASK);
|
||||||
return -EINTR;
|
return -ERESTARTNOHAND;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
asmlinkage long
|
asmlinkage long
|
||||||
@ -508,11 +502,11 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
|
|||||||
current->comm, current->pid, frame, regs->rip, frame->pretcode);
|
current->comm, current->pid, frame, regs->rip, frame->pretcode);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
|
|
||||||
give_sigsegv:
|
give_sigsegv:
|
||||||
force_sigsegv(sig, current);
|
force_sigsegv(sig, current);
|
||||||
return 0;
|
return -EFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
|
int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
|
||||||
@ -604,9 +598,9 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
|
|||||||
current->comm, current->pid, frame, regs->rip, frame->pretcode);
|
current->comm, current->pid, frame, regs->rip, frame->pretcode);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
|
|
||||||
give_sigsegv:
|
give_sigsegv:
|
||||||
force_sigsegv(sig, current);
|
force_sigsegv(sig, current);
|
||||||
return 0;
|
return -EFAULT;
|
||||||
}
|
}
|
||||||
|
@ -37,37 +37,6 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
|
|||||||
int ia32_setup_frame(int sig, struct k_sigaction *ka,
|
int ia32_setup_frame(int sig, struct k_sigaction *ka,
|
||||||
sigset_t *set, struct pt_regs * regs);
|
sigset_t *set, struct pt_regs * regs);
|
||||||
|
|
||||||
asmlinkage long
|
|
||||||
sys_rt_sigsuspend(sigset_t __user *unewset, size_t sigsetsize, struct pt_regs *regs)
|
|
||||||
{
|
|
||||||
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(¤t->sighand->siglock);
|
|
||||||
saveset = current->blocked;
|
|
||||||
current->blocked = newset;
|
|
||||||
recalc_sigpending();
|
|
||||||
spin_unlock_irq(¤t->sighand->siglock);
|
|
||||||
#ifdef DEBUG_SIG
|
|
||||||
printk("rt_sigsuspend savset(%lx) newset(%lx) regs(%p) rip(%lx)\n",
|
|
||||||
saveset, newset, regs, regs->rip);
|
|
||||||
#endif
|
|
||||||
regs->rax = -EINTR;
|
|
||||||
while (1) {
|
|
||||||
current->state = TASK_INTERRUPTIBLE;
|
|
||||||
schedule();
|
|
||||||
if (do_signal(regs, &saveset))
|
|
||||||
return -EINTR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmlinkage long
|
asmlinkage long
|
||||||
sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
|
sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
|
||||||
struct pt_regs *regs)
|
struct pt_regs *regs)
|
||||||
@ -341,11 +310,11 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
|
|||||||
current->comm, current->pid, frame, regs->rip, frame->pretcode);
|
current->comm, current->pid, frame, regs->rip, frame->pretcode);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
|
|
||||||
give_sigsegv:
|
give_sigsegv:
|
||||||
force_sigsegv(sig, current);
|
force_sigsegv(sig, current);
|
||||||
return 0;
|
return -EFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -408,7 +377,7 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
|
|||||||
#endif
|
#endif
|
||||||
ret = setup_rt_frame(sig, ka, info, oldset, regs);
|
ret = setup_rt_frame(sig, ka, info, 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))
|
||||||
@ -425,11 +394,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 do_signal(struct pt_regs *regs, sigset_t *oldset)
|
static void do_signal(struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
struct k_sigaction ka;
|
struct k_sigaction ka;
|
||||||
siginfo_t info;
|
siginfo_t info;
|
||||||
int signr;
|
int signr;
|
||||||
|
sigset_t *oldset;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We want the common case to go fast, which
|
* We want the common case to go fast, which
|
||||||
@ -438,9 +408,11 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset)
|
|||||||
* if so.
|
* if so.
|
||||||
*/
|
*/
|
||||||
if (!user_mode(regs))
|
if (!user_mode(regs))
|
||||||
return 1;
|
return;
|
||||||
|
|
||||||
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);
|
||||||
@ -454,30 +426,46 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset)
|
|||||||
set_debugreg(current->thread.debugreg7, 7);
|
set_debugreg(current->thread.debugreg7, 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 */
|
||||||
|
clear_thread_flag(TIF_RESTORE_SIGMASK);
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Did we come from a system call? */
|
/* Did we come from a system call? */
|
||||||
if ((long)regs->orig_rax >= 0) {
|
if ((long)regs->orig_rax >= 0) {
|
||||||
/* Restart the system call - no handlers present */
|
/* Restart the system call - no handlers present */
|
||||||
long res = regs->rax;
|
long res = regs->rax;
|
||||||
if (res == -ERESTARTNOHAND ||
|
switch (res) {
|
||||||
res == -ERESTARTSYS ||
|
case -ERESTARTNOHAND:
|
||||||
res == -ERESTARTNOINTR) {
|
case -ERESTARTSYS:
|
||||||
|
case -ERESTARTNOINTR:
|
||||||
regs->rax = regs->orig_rax;
|
regs->rax = regs->orig_rax;
|
||||||
regs->rip -= 2;
|
regs->rip -= 2;
|
||||||
}
|
break;
|
||||||
if (regs->rax == (unsigned long)-ERESTART_RESTARTBLOCK) {
|
case -ERESTART_RESTARTBLOCK:
|
||||||
regs->rax = test_thread_flag(TIF_IA32) ?
|
regs->rax = test_thread_flag(TIF_IA32) ?
|
||||||
__NR_ia32_restart_syscall :
|
__NR_ia32_restart_syscall :
|
||||||
__NR_restart_syscall;
|
__NR_restart_syscall;
|
||||||
regs->rip -= 2;
|
regs->rip -= 2;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void do_notify_resume(struct pt_regs *regs, sigset_t *oldset, __u32 thread_info_flags)
|
/* 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_SIG
|
#ifdef DEBUG_SIG
|
||||||
printk("do_notify_resume flags:%x rip:%lx rsp:%lx caller:%lx pending:%lx\n",
|
printk("do_notify_resume flags:%x rip:%lx rsp:%lx caller:%lx pending:%lx\n",
|
||||||
@ -491,8 +479,8 @@ void do_notify_resume(struct pt_regs *regs, sigset_t *oldset, __u32 thread_info_
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
|
void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
|
||||||
|
@ -24,10 +24,6 @@ typedef struct {
|
|||||||
} sigset_t;
|
} sigset_t;
|
||||||
|
|
||||||
|
|
||||||
struct pt_regs;
|
|
||||||
asmlinkage int do_signal(struct pt_regs *regs, sigset_t *oldset);
|
|
||||||
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
/* Here we must cater to libcs that poke about in kernel headers. */
|
/* Here we must cater to libcs that poke about in kernel headers. */
|
||||||
|
|
||||||
|
@ -114,6 +114,7 @@ static inline struct thread_info *stack_thread_info(void)
|
|||||||
#define TIF_IRET 5 /* force IRET */
|
#define TIF_IRET 5 /* force IRET */
|
||||||
#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 */
|
||||||
/* 16 free */
|
/* 16 free */
|
||||||
#define TIF_IA32 17 /* 32bit process */
|
#define TIF_IA32 17 /* 32bit process */
|
||||||
#define TIF_FORK 18 /* ret_from_fork */
|
#define TIF_FORK 18 /* ret_from_fork */
|
||||||
@ -128,6 +129,7 @@ static inline struct thread_info *stack_thread_info(void)
|
|||||||
#define _TIF_IRET (1<<TIF_IRET)
|
#define _TIF_IRET (1<<TIF_IRET)
|
||||||
#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_IA32 (1<<TIF_IA32)
|
#define _TIF_IA32 (1<<TIF_IA32)
|
||||||
#define _TIF_FORK (1<<TIF_FORK)
|
#define _TIF_FORK (1<<TIF_FORK)
|
||||||
#define _TIF_ABI_PENDING (1<<TIF_ABI_PENDING)
|
#define _TIF_ABI_PENDING (1<<TIF_ABI_PENDING)
|
||||||
|
@ -658,6 +658,7 @@ do { \
|
|||||||
#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
|
||||||
#define __ARCH_WANT_SYS_TIME
|
#define __ARCH_WANT_SYS_TIME
|
||||||
#define __ARCH_WANT_COMPAT_SYS_TIME
|
#define __ARCH_WANT_COMPAT_SYS_TIME
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user