Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7e907f48 authored by Ingo Molnar's avatar Ingo Molnar
Browse files

x86: clean up arch/x86/kernel/signal_32.c



Before:
   total: 21 errors, 6 warnings, 665 lines checked
After:
   total: 0 errors, 3 warnings, 685 lines checked

No code changed:

arch/x86/kernel/signal_32.o:

   text	   data	    bss	    dec	    hex	filename
   5333	      0	      4	   5337	   14d9	signal_32.o.before
   5333	      0	      4	   5337	   14d9	signal_32.o.after

md5:
   c279e98012a2808e90cfa2a7787e42a4  signal_32.o.before.asm
   c279e98012a2808e90cfa2a7787e42a4  signal_32.o.after.asm

Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent a7113170
Loading
Loading
Loading
Loading
+101 −79
Original line number Original line Diff line number Diff line
@@ -4,26 +4,29 @@
 *  1997-11-28  Modified for POSIX.1b signals by Richard Henderson
 *  1997-11-28  Modified for POSIX.1b signals by Richard Henderson
 *  2000-06-20  Pentium III FXSR, SSE support by Gareth Hughes
 *  2000-06-20  Pentium III FXSR, SSE support by Gareth Hughes
 */
 */
#include <linux/list.h>


#include <linux/sched.h>
#include <linux/personality.h>
#include <linux/mm.h>
#include <linux/binfmts.h>
#include <linux/smp.h>
#include <linux/suspend.h>
#include <linux/kernel.h>
#include <linux/kernel.h>
#include <linux/ptrace.h>
#include <linux/signal.h>
#include <linux/signal.h>
#include <linux/stddef.h>
#include <linux/unistd.h>
#include <linux/errno.h>
#include <linux/errno.h>
#include <linux/sched.h>
#include <linux/wait.h>
#include <linux/wait.h>
#include <linux/unistd.h>
#include <linux/stddef.h>
#include <linux/personality.h>
#include <linux/suspend.h>
#include <linux/ptrace.h>
#include <linux/elf.h>
#include <linux/elf.h>
#include <linux/binfmts.h>
#include <linux/smp.h>
#include <linux/mm.h>

#include <asm/processor.h>
#include <asm/processor.h>
#include <asm/ucontext.h>
#include <asm/ucontext.h>
#include <asm/uaccess.h>
#include <asm/uaccess.h>
#include <asm/i387.h>
#include <asm/i387.h>
#include <asm/vdso.h>
#include <asm/vdso.h>

#include "sigframe.h"
#include "sigframe.h"


#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
@@ -55,6 +58,7 @@ sys_sigsuspend(int history0, int history1, old_sigset_t mask)
	current->state = TASK_INTERRUPTIBLE;
	current->state = TASK_INTERRUPTIBLE;
	schedule();
	schedule();
	set_thread_flag(TIF_RESTORE_SIGMASK);
	set_thread_flag(TIF_RESTORE_SIGMASK);

	return -ERESTARTNOHAND;
	return -ERESTARTNOHAND;
}
}


@@ -67,10 +71,12 @@ sys_sigaction(int sig, const struct old_sigaction __user *act,


	if (act) {
	if (act) {
		old_sigset_t mask;
		old_sigset_t mask;

		if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
		if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
		    __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
		    __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
		    __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
		    __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
			return -EFAULT;
			return -EFAULT;

		__get_user(new_ka.sa.sa_flags, &act->sa_flags);
		__get_user(new_ka.sa.sa_flags, &act->sa_flags);
		__get_user(mask, &act->sa_mask);
		__get_user(mask, &act->sa_mask);
		siginitset(&new_ka.sa.sa_mask, mask);
		siginitset(&new_ka.sa.sa_mask, mask);
@@ -83,6 +89,7 @@ sys_sigaction(int sig, const struct old_sigaction __user *act,
		    __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
		    __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
		    __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
		    __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
			return -EFAULT;
			return -EFAULT;

		__put_user(old_ka.sa.sa_flags, &oact->sa_flags);
		__put_user(old_ka.sa.sa_flags, &oact->sa_flags);
		__put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
		__put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
	}
	}
@@ -90,10 +97,12 @@ sys_sigaction(int sig, const struct old_sigaction __user *act,
	return ret;
	return ret;
}
}


asmlinkage int
asmlinkage int sys_sigaltstack(unsigned long bx)
sys_sigaltstack(unsigned long bx)
{
{
	/* This is needed to make gcc realize it doesn't own the "struct pt_regs" */
	/*
	 * This is needed to make gcc realize it doesn't own the
	 * "struct pt_regs"
	 */
	struct pt_regs *regs = (struct pt_regs *)&bx;
	struct pt_regs *regs = (struct pt_regs *)&bx;
	const stack_t __user *uss = (const stack_t __user *)bx;
	const stack_t __user *uss = (const stack_t __user *)bx;
	stack_t __user *uoss = (stack_t __user *)regs->cx;
	stack_t __user *uoss = (stack_t __user *)regs->cx;
@@ -142,13 +151,16 @@ restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,


	{
	{
		unsigned int tmpflags;
		unsigned int tmpflags;

		err |= __get_user(tmpflags, &sc->flags);
		err |= __get_user(tmpflags, &sc->flags);
		regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
		regs->flags = (regs->flags & ~FIX_EFLAGS) |
						(tmpflags & FIX_EFLAGS);
		regs->orig_ax = -1;		/* disable syscall checks */
		regs->orig_ax = -1;		/* disable syscall checks */
	}
	}


	{
	{
		struct _fpstate __user *buf;
		struct _fpstate __user *buf;

		err |= __get_user(buf, &sc->fpstate);
		err |= __get_user(buf, &sc->fpstate);
		if (buf) {
		if (buf) {
			if (!access_ok(VERIFY_READ, buf, sizeof(*buf)))
			if (!access_ok(VERIFY_READ, buf, sizeof(*buf)))
@@ -156,6 +168,7 @@ restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
			err |= restore_i387(buf);
			err |= restore_i387(buf);
		} else {
		} else {
			struct task_struct *me = current;
			struct task_struct *me = current;

			if (used_math()) {
			if (used_math()) {
				clear_fpu(me);
				clear_fpu(me);
				clear_used_math();
				clear_used_math();
@@ -172,15 +185,17 @@ restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,


asmlinkage unsigned long sys_sigreturn(unsigned long __unused)
asmlinkage unsigned long sys_sigreturn(unsigned long __unused)
{
{
	struct pt_regs *regs = (struct pt_regs *) &__unused;
	struct sigframe __user *frame;
	struct sigframe __user *frame = (struct sigframe __user *)(regs->sp - 8);
	struct pt_regs *regs;
	sigset_t set;
	unsigned long ax;
	unsigned long ax;
	sigset_t set;

	regs = (struct pt_regs *) &__unused;
	frame = (struct sigframe __user *)(regs->sp - 8);


	if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
	if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
		goto badframe;
		goto badframe;
	if (__get_user(set.sig[0], &frame->sc.oldmask)
	if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1
	    || (_NSIG_WORDS > 1
		&& __copy_from_user(&set.sig[1], &frame->extramask,
		&& __copy_from_user(&set.sig[1], &frame->extramask,
				    sizeof(frame->extramask))))
				    sizeof(frame->extramask))))
		goto badframe;
		goto badframe;
@@ -207,6 +222,7 @@ asmlinkage unsigned long sys_sigreturn(unsigned long __unused)
	}
	}


	force_sig(SIGSEGV, current);
	force_sig(SIGSEGV, current);

	return 0;
	return 0;
}
}


@@ -245,7 +261,6 @@ asmlinkage int sys_rt_sigreturn(unsigned long __unused)
/*
/*
 * Set up a signal frame.
 * Set up a signal frame.
 */
 */

static int
static int
setup_sigcontext(struct sigcontext __user *sc, struct _fpstate __user *fpstate,
setup_sigcontext(struct sigcontext __user *sc, struct _fpstate __user *fpstate,
		 struct pt_regs *regs, unsigned long mask)
		 struct pt_regs *regs, unsigned long mask)
@@ -309,32 +324,37 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs * regs, size_t frame_size)
	if (ka->sa.sa_flags & SA_ONSTACK) {
	if (ka->sa.sa_flags & SA_ONSTACK) {
		if (sas_ss_flags(sp) == 0)
		if (sas_ss_flags(sp) == 0)
			sp = current->sas_ss_sp + current->sas_ss_size;
			sp = current->sas_ss_sp + current->sas_ss_size;
	}
	} else {

		/* This is the legacy signal stack switching. */
		/* This is the legacy signal stack switching. */
	else if ((regs->ss & 0xffff) != __USER_DS &&
		if ((regs->ss & 0xffff) != __USER_DS &&
			!(ka->sa.sa_flags & SA_RESTORER) &&
			!(ka->sa.sa_flags & SA_RESTORER) &&
		 ka->sa.sa_restorer) {
				ka->sa.sa_restorer)
			sp = (unsigned long) ka->sa.sa_restorer;
			sp = (unsigned long) ka->sa.sa_restorer;
	}
	}


	sp -= frame_size;
	sp -= frame_size;
	/* Align the stack pointer according to the i386 ABI,
	/*
	 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
	 * Align the stack pointer according to the i386 ABI,
	 * i.e. so that on function entry ((sp + 4) & 15) == 0.
	 */
	sp = ((sp + 4) & -16ul) - 4;
	sp = ((sp + 4) & -16ul) - 4;

	return (void __user *) sp;
	return (void __user *) sp;
}
}


/* These symbols are defined with the addresses in the vsyscall page.
/*
   See vsyscall-sigreturn.S.  */
 * These symbols are defined with the addresses in the vsyscall page.
 * See vsyscall-sigreturn.S.
 */
extern void __user __kernel_sigreturn;
extern void __user __kernel_sigreturn;
extern void __user __kernel_rt_sigreturn;
extern void __user __kernel_rt_sigreturn;


static int setup_frame(int sig, struct k_sigaction *ka,
static int
		       sigset_t *set, struct pt_regs * regs)
setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
	    struct pt_regs *regs)
{
{
	void __user *restorer;
	struct sigframe __user *frame;
	struct sigframe __user *frame;
	void __user *restorer;
	int err = 0;
	int err = 0;
	int usig;
	int usig;


@@ -375,7 +395,7 @@ static int setup_frame(int sig, struct k_sigaction *ka,
	err |= __put_user(restorer, &frame->pretcode);
	err |= __put_user(restorer, &frame->pretcode);


	/*
	/*
	 * This is popl %eax ; movl $,%eax ; int $0x80
	 * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80
	 *
	 *
	 * WE DO NOT USE IT ANY MORE! It's only left here for historical
	 * WE DO NOT USE IT ANY MORE! It's only left here for historical
	 * reasons and because gdb uses it as a signature to notice
	 * reasons and because gdb uses it as a signature to notice
@@ -420,8 +440,8 @@ static int setup_frame(int sig, struct k_sigaction *ka,
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,
			  sigset_t *set, struct pt_regs *regs)
			  sigset_t *set, struct pt_regs *regs)
{
{
	void __user *restorer;
	struct rt_sigframe __user *frame;
	struct rt_sigframe __user *frame;
	void __user *restorer;
	int err = 0;
	int err = 0;
	int usig;
	int usig;


@@ -463,7 +483,7 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
	err |= __put_user(restorer, &frame->pretcode);
	err |= __put_user(restorer, &frame->pretcode);


	/*
	/*
	 * This is movl $,%ax ; int $0x80
	 * This is movl $__NR_rt_sigreturn, %ax ; int $0x80
	 *
	 *
	 * WE DO NOT USE IT ANY MORE! It's only left here for historical
	 * WE DO NOT USE IT ANY MORE! It's only left here for historical
	 * reasons and because gdb uses it as a signature to notice
	 * reasons and because gdb uses it as a signature to notice
@@ -506,9 +526,8 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
}
}


/*
/*
 * OK, we're invoking a handler
 * OK, we're invoking a handler:
 */
 */

static int
static int
handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
	      sigset_t *oldset, struct pt_regs *regs)
	      sigset_t *oldset, struct pt_regs *regs)
@@ -551,16 +570,17 @@ 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 == 0) {
	if (ret)
		return ret;

	spin_lock_irq(&current->sighand->siglock);
	spin_lock_irq(&current->sighand->siglock);
	sigorsets(&current->blocked, &current->blocked, &ka->sa.sa_mask);
	sigorsets(&current->blocked, &current->blocked, &ka->sa.sa_mask);
	if (!(ka->sa.sa_flags & SA_NODEFER))
	if (!(ka->sa.sa_flags & SA_NODEFER))
		sigaddset(&current->blocked, sig);
		sigaddset(&current->blocked, sig);
	recalc_sigpending();
	recalc_sigpending();
	spin_unlock_irq(&current->sighand->siglock);
	spin_unlock_irq(&current->sighand->siglock);
	}


	return ret;
	return 0;
}
}


/*
/*
@@ -592,7 +612,8 @@ static void do_signal(struct pt_regs *regs)


	signr = get_signal_to_deliver(&info, &ka, regs, NULL);
	signr = get_signal_to_deliver(&info, &ka, regs, NULL);
	if (signr > 0) {
	if (signr > 0) {
		/* Re-enable any watchpoints before delivering the
		/*
		 * Re-enable any watchpoints before delivering the
		 * signal to user space. The processor register will
		 * signal to user space. The processor register will
		 * have been cleared if the watchpoint triggered
		 * have been cleared if the watchpoint triggered
		 * inside the kernel.
		 * inside the kernel.
@@ -602,14 +623,15 @@ static void do_signal(struct pt_regs *regs)


		/* Whee! Actually deliver the signal.  */
		/* Whee! Actually deliver the signal.  */
		if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
		if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
			/* a signal was successfully delivered; the saved
			/*
			 * a signal was successfully delivered; the saved
			 * sigmask will have been stored in the signal frame,
			 * sigmask will have been stored in the signal frame,
			 * and will be restored by sigreturn, so we can simply
			 * and will be restored by sigreturn, so we can simply
			 * clear the TIF_RESTORE_SIGMASK flag */
			 * clear the TIF_RESTORE_SIGMASK flag
			 */
			if (test_thread_flag(TIF_RESTORE_SIGMASK))
			if (test_thread_flag(TIF_RESTORE_SIGMASK))
				clear_thread_flag(TIF_RESTORE_SIGMASK);
				clear_thread_flag(TIF_RESTORE_SIGMASK);
		}
		}

		return;
		return;
	}
	}


@@ -645,8 +667,8 @@ static void do_signal(struct pt_regs *regs)
 * notification of userspace execution resumption
 * notification of userspace execution resumption
 * - triggered by the TIF_WORK_MASK flags
 * - triggered by the TIF_WORK_MASK flags
 */
 */
void do_notify_resume(struct pt_regs *regs, void *unused,
void
		      __u32 thread_info_flags)
do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
{
{
	/* Pending single-step? */
	/* Pending single-step? */
	if (thread_info_flags & _TIF_SINGLESTEP) {
	if (thread_info_flags & _TIF_SINGLESTEP) {