]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
x86: use regparm(3) for passed-in pt_regs pointer
authorBrian Gerst <brgerst@gmail.com>
Wed, 11 Feb 2009 21:43:58 +0000 (16:43 -0500)
committerH. Peter Anvin <hpa@linux.intel.com>
Wed, 11 Feb 2009 22:00:56 +0000 (14:00 -0800)
Some syscalls need to access the pt_regs structure, either to copy
user register state or to modifiy it.  This patch adds stubs to load
the address of the pt_regs struct into the %eax register, and changes
the syscalls to take the pointer as an argument instead of relying on
the assumption that the pt_regs structure overlaps the function
arguments.

Drop the use of regparm(1) due to concern about gcc bugs, and to move
in the direction of the eventual removal of regparm(0) for asmlinkage.

Signed-off-by: Brian Gerst <brgerst@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
arch/x86/include/asm/linkage.h
arch/x86/include/asm/syscalls.h
arch/x86/kernel/ioport.c
arch/x86/kernel/process_32.c
arch/x86/kernel/signal.c
arch/x86/kernel/vm86_32.c

index 2fd5926fb97d668ef65b25980fc944142f33e4ce..5d98d0b68ffc8e08e07cf829ed15103f6fc09796 100644 (file)
  */
 #define asmregparm __attribute__((regparm(3)))
 
-/*
- * For syscalls that need a pointer to the pt_regs struct (ie. fork).
- * The regs pointer is passed in %eax as the first argument.  The
- * remaining function arguments remain on the stack.
- */
-#define ptregscall __attribute__((regparm(1)))
-
 /*
  * Make sure the compiler doesn't do anything stupid with the
  * arguments on the stack - they are owned by the *caller*, not
index 617295255a17c5b9e794ab231fd16ce48049ca9e..77bb31a88ba8248b0084e8916d5a13ea2165f301 100644 (file)
@@ -29,26 +29,21 @@ asmlinkage int sys_get_thread_area(struct user_desc __user *);
 /* X86_32 only */
 #ifdef CONFIG_X86_32
 /* kernel/process_32.c */
-ptregscall int sys_fork(struct pt_regs *);
-ptregscall int sys_clone(struct pt_regs *, unsigned long,
-                        unsigned long, int __user *,
-                        unsigned long, int __user *);
-ptregscall int sys_vfork(struct pt_regs *);
-ptregscall int sys_execve(struct pt_regs *, char __user *,
-                         char __user * __user *,
-                         char __user * __user *);
+int sys_fork(struct pt_regs *);
+int sys_clone(struct pt_regs *);
+int sys_vfork(struct pt_regs *);
+int sys_execve(struct pt_regs *);
 
 /* kernel/signal_32.c */
 asmlinkage int sys_sigsuspend(int, int, old_sigset_t);
 asmlinkage int sys_sigaction(int, const struct old_sigaction __user *,
                             struct old_sigaction __user *);
-ptregscall int sys_sigaltstack(struct pt_regs *, const stack_t __user *,
-                              stack_t __user *);
-ptregscall unsigned long sys_sigreturn(struct pt_regs *);
-ptregscall int sys_rt_sigreturn(struct pt_regs *);
+int sys_sigaltstack(struct pt_regs *);
+unsigned long sys_sigreturn(struct pt_regs *);
+int sys_rt_sigreturn(struct pt_regs *);
 
 /* kernel/ioport.c */
-ptregscall long sys_iopl(struct pt_regs *, unsigned int);
+long sys_iopl(struct pt_regs *);
 
 /* kernel/sys_i386_32.c */
 asmlinkage long sys_mmap2(unsigned long, unsigned long, unsigned long,
@@ -64,8 +59,8 @@ struct oldold_utsname;
 asmlinkage int sys_olduname(struct oldold_utsname __user *);
 
 /* kernel/vm86_32.c */
-ptregscall int sys_vm86old(struct pt_regs *, struct vm86_struct __user *);
-ptregscall int sys_vm86(struct pt_regs *, unsigned long, unsigned long);
+int sys_vm86old(struct pt_regs *);
+int sys_vm86(struct pt_regs *);
 
 #else /* CONFIG_X86_32 */
 
index 7ec148646312f2b13807043af2368e6d770f60d4..e41980a373ab9768e42cedcd11bf7e6a60dcb1df 100644 (file)
@@ -131,8 +131,9 @@ static int do_iopl(unsigned int level, struct pt_regs *regs)
 }
 
 #ifdef CONFIG_X86_32
-ptregscall long sys_iopl(struct pt_regs *regs, unsigned int level)
+long sys_iopl(struct pt_regs *regs)
 {
+       unsigned int level = regs->bx;
        struct thread_struct *t = &current->thread;
        int rc;
 
index 5a9dcfb01f7136722d39782804b29274b7f774e2..fec79ad85dc65cd280e324819c02bc6bd8d2b821 100644 (file)
@@ -603,15 +603,21 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
        return prev_p;
 }
 
-ptregscall int sys_fork(struct pt_regs *regs)
+int sys_fork(struct pt_regs *regs)
 {
        return do_fork(SIGCHLD, regs->sp, regs, 0, NULL, NULL);
 }
 
-ptregscall int sys_clone(struct pt_regs *regs, unsigned long clone_flags,
-                        unsigned long newsp, int __user *parent_tidptr,
-                        unsigned long unused, int __user *child_tidptr)
+int sys_clone(struct pt_regs *regs)
 {
+       unsigned long clone_flags;
+       unsigned long newsp;
+       int __user *parent_tidptr, *child_tidptr;
+
+       clone_flags = regs->bx;
+       newsp = regs->cx;
+       parent_tidptr = (int __user *)regs->dx;
+       child_tidptr = (int __user *)regs->di;
        if (!newsp)
                newsp = regs->sp;
        return do_fork(clone_flags, newsp, regs, 0, parent_tidptr, child_tidptr);
@@ -627,7 +633,7 @@ ptregscall int sys_clone(struct pt_regs *regs, unsigned long clone_flags,
  * do not have enough call-clobbered registers to hold all
  * the information you need.
  */
-ptregscall int sys_vfork(struct pt_regs *regs)
+int sys_vfork(struct pt_regs *regs)
 {
        return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->sp, regs, 0, NULL, NULL);
 }
@@ -635,18 +641,19 @@ ptregscall int sys_vfork(struct pt_regs *regs)
 /*
  * sys_execve() executes a new program.
  */
-ptregscall int sys_execve(struct pt_regs *regs, char __user *u_filename,
-                         char __user * __user *argv,
-                         char __user * __user *envp)
+int sys_execve(struct pt_regs *regs)
 {
        int error;
        char *filename;
 
-       filename = getname(u_filename);
+       filename = getname((char __user *) regs->bx);
        error = PTR_ERR(filename);
        if (IS_ERR(filename))
                goto out;
-       error = do_execve(filename, argv, envp, regs);
+       error = do_execve(filename,
+                       (char __user * __user *) regs->cx,
+                       (char __user * __user *) regs->dx,
+                       regs);
        if (error == 0) {
                /* Make sure we don't return using sysenter.. */
                set_thread_flag(TIF_IRET);
index d7a158367e3866dbce6dbff59414c8b7e3372ea6..ccfb27412f0f817636beaffe044bc4b8166a2ba9 100644 (file)
@@ -549,23 +549,27 @@ sys_sigaction(int sig, const struct old_sigaction __user *act,
 #endif /* CONFIG_X86_32 */
 
 #ifdef CONFIG_X86_32
-ptregscall int
-sys_sigaltstack(struct pt_regs *regs, const stack_t __user *uss,
-               stack_t __user *uoss)
+int sys_sigaltstack(struct pt_regs *regs)
+{
+       const stack_t __user *uss = (const stack_t __user *)regs->bx;
+       stack_t __user *uoss = (stack_t __user *)regs->cx;
+
+       return do_sigaltstack(uss, uoss, regs->sp);
+}
 #else /* !CONFIG_X86_32 */
 asmlinkage long
 sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
                struct pt_regs *regs)
-#endif /* CONFIG_X86_32 */
 {
        return do_sigaltstack(uss, uoss, regs->sp);
 }
+#endif /* CONFIG_X86_32 */
 
 /*
  * Do a signal return; undo the signal stack.
  */
 #ifdef CONFIG_X86_32
-ptregscall unsigned long sys_sigreturn(struct pt_regs *regs)
+unsigned long sys_sigreturn(struct pt_regs *regs)
 {
        struct sigframe __user *frame;
        unsigned long ax;
@@ -629,13 +633,16 @@ badframe:
 }
 
 #ifdef CONFIG_X86_32
-ptregscall int sys_rt_sigreturn(struct pt_regs *regs)
+int sys_rt_sigreturn(struct pt_regs *regs)
+{
+       return do_rt_sigreturn(regs);
+}
 #else /* !CONFIG_X86_32 */
 asmlinkage long sys_rt_sigreturn(struct pt_regs *regs)
-#endif /* CONFIG_X86_32 */
 {
        return do_rt_sigreturn(regs);
 }
+#endif /* CONFIG_X86_32 */
 
 /*
  * OK, we're invoking a handler:
index 8fa6ba7c923326d10ce5fda2502164bc4b7eb3ea..d7ac84e7fc1c73f7cfcfd8ca6b66c5abed2219ce 100644 (file)
@@ -197,8 +197,9 @@ out:
 static int do_vm86_irq_handling(int subfunction, int irqnumber);
 static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk);
 
-ptregscall int sys_vm86old(struct pt_regs *regs, struct vm86_struct __user *v86)
+int sys_vm86old(struct pt_regs *regs)
 {
+       struct vm86_struct __user *v86 = (struct vm86_struct __user *)regs->bx;
        struct kernel_vm86_struct info; /* declare this _on top_,
                                         * this avoids wasting of stack space.
                                         * This remains on the stack until we
@@ -226,7 +227,7 @@ out:
 }
 
 
-ptregscall int sys_vm86(struct pt_regs *regs, unsigned long cmd, unsigned long arg)
+int sys_vm86(struct pt_regs *regs)
 {
        struct kernel_vm86_struct info; /* declare this _on top_,
                                         * this avoids wasting of stack space.
@@ -238,12 +239,12 @@ ptregscall int sys_vm86(struct pt_regs *regs, unsigned long cmd, unsigned long a
        struct vm86plus_struct __user *v86;
 
        tsk = current;
-       switch (cmd) {
+       switch (regs->bx) {
        case VM86_REQUEST_IRQ:
        case VM86_FREE_IRQ:
        case VM86_GET_IRQ_BITS:
        case VM86_GET_AND_RESET_IRQ:
-               ret = do_vm86_irq_handling(cmd, (int)arg);
+               ret = do_vm86_irq_handling(regs->bx, (int)regs->cx);
                goto out;
        case VM86_PLUS_INSTALL_CHECK:
                /*
@@ -260,7 +261,7 @@ ptregscall int sys_vm86(struct pt_regs *regs, unsigned long cmd, unsigned long a
        ret = -EPERM;
        if (tsk->thread.saved_sp0)
                goto out;
-       v86 = (struct vm86plus_struct __user *)arg;
+       v86 = (struct vm86plus_struct __user *)regs->cx;
        tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
                                       offsetof(struct kernel_vm86_struct, regs32) -
                                       sizeof(info.regs));