MIPS: Switch over to generic sys_execve and kernel_execve.
authorRalf Baechle <ralf@linux-mips.org>
Tue, 9 Oct 2012 19:16:07 +0000 (21:16 +0200)
committerAl Viro <viro@zeniv.linux.org.uk>
Sun, 14 Oct 2012 23:31:30 +0000 (19:31 -0400)
This version contains a few updates by David Daney, in particular it's
now using __builtin_frame_address() instead of asm() which depending
on personal taste, is slightly more appealing.

Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
arch/mips/include/asm/ptrace.h
arch/mips/include/asm/unistd.h
arch/mips/kernel/entry.S
arch/mips/kernel/linux32.c
arch/mips/kernel/scall64-n32.S
arch/mips/kernel/scall64-o32.S
arch/mips/kernel/syscall.c

index 4f5da948a777c91e9223d94991f76fbfad6f6f30..cec5e125f7e466fceb8680f029de9ad040b9c4a3 100644 (file)
@@ -61,4 +61,10 @@ static inline void die_if_kernel(const char *str, struct pt_regs *regs)
                die(str, regs);
 }
 
+#define current_pt_regs()                                              \
+({                                                                     \
+       unsigned long sp = (unsigned long)__builtin_frame_address(0);   \
+       (struct pt_regs *)((sp | (THREAD_SIZE - 1)) + 1 - 32) - 1;      \
+})
+
 #endif /* _ASM_PTRACE_H */
index 9e47cc11aa263ba3991d680736bce6aeea41447e..8ae908c66e599e24b84bcd01f5e46bd0bd86aa9f 100644 (file)
 #ifndef __ASSEMBLY__
 
 #define __ARCH_OMIT_COMPAT_SYS_GETDENTS64
+#define __ARCH_WANT_KERNEL_EXECVE
 #define __ARCH_WANT_OLD_READDIR
 #define __ARCH_WANT_SYS_ALARM
+#define __ARCH_WANT_SYS_EXECVE
 #define __ARCH_WANT_SYS_GETHOSTNAME
 #define __ARCH_WANT_SYS_IPC
 #define __ARCH_WANT_SYS_PAUSE
index aab6997b8f47a32eecc9379752921a9d3d950d80..5dcb5fbbbd53c4916f92a779b363898bc62dabb0 100644 (file)
@@ -192,6 +192,15 @@ syscall_exit_work:
        jal     syscall_trace_leave
        b       resume_userspace
 
+LEAF(ret_from_kernel_execve)
+       move    sp, a0
+       ori     $28,  sp, _THREAD_SIZE - 1
+       xori    $28, $28, _THREAD_SIZE - 1
+       li      v0, 0
+       li      a3, 0
+       j       syscall_exit_partial
+       END(ret_from_kernel_execve)
+
 #if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_MIPS_MT)
 
 /*
index 3a21acedf88231403703c3ca842916f325f88a6f..8796dbc7e3585ca1193e29fd967158efc2029157 100644 (file)
@@ -3,7 +3,6 @@
  *
  * Copyright (C) 2000 Silicon Graphics, Inc.
  * Written by Ulf Carlsson (ulfc@engr.sgi.com)
- * sys32_execve from ia64/ia32 code, Feb 2000, Kanoj Sarcar (kanoj@sgi.com)
  */
 #include <linux/compiler.h>
 #include <linux/mm.h>
@@ -77,26 +76,6 @@ out:
        return error;
 }
 
-/*
- * sys_execve() executes a new program.
- */
-asmlinkage int sys32_execve(nabi_no_regargs struct pt_regs regs)
-{
-       int error;
-       struct filename *filename;
-
-       filename = getname(compat_ptr(regs.regs[4]));
-       error = PTR_ERR(filename);
-       if (IS_ERR(filename))
-               goto out;
-       error = compat_do_execve(filename->name, compat_ptr(regs.regs[5]),
-                                compat_ptr(regs.regs[6]), &regs);
-       putname(filename);
-
-out:
-       return error;
-}
-
 #define RLIM_INFINITY32        0x7fffffff
 #define RESOURCE32(x) ((x > RLIM_INFINITY32) ? RLIM_INFINITY32 : x)
 
index f6ba8381ee0186c5dfc1f19879ae4c39d15d52e9..d27ca340d46dcbe6cb680f24b8c4e49e0bad1ebc 100644 (file)
@@ -167,7 +167,7 @@ EXPORT(sysn32_call_table)
        PTR     sys_getsockopt
        PTR     sys_clone                       /* 6055 */
        PTR     sys_fork
-       PTR     sys32_execve
+       PTR     compat_sys_execve
        PTR     sys_exit
        PTR     compat_sys_wait4
        PTR     sys_kill                        /* 6060 */
index 53c2d72457649f74f211ca894662dccabee470da..9601be6afa3de3b9571215bf75d2fe6c55392a60 100644 (file)
@@ -203,7 +203,7 @@ sys_call_table:
        PTR     sys_creat
        PTR     sys_link
        PTR     sys_unlink                      /* 4010 */
-       PTR     sys32_execve
+       PTR     compat_sys_execve
        PTR     sys_chdir
        PTR     compat_sys_time
        PTR     sys_mknod
index 2bd561bc05ae2b4e7b814ac866d21faaddd046a2..c611e2df7767e81550f89d645fe1025fcf281c1e 100644 (file)
@@ -127,28 +127,6 @@ _sys_clone(nabi_no_regargs struct pt_regs regs)
                       parent_tidptr, child_tidptr);
 }
 
-/*
- * sys_execve() executes a new program.
- */
-asmlinkage int sys_execve(nabi_no_regargs struct pt_regs regs)
-{
-       int error;
-       struct filename *filename;
-
-       filename = getname((const char __user *) (long)regs.regs[4]);
-       error = PTR_ERR(filename);
-       if (IS_ERR(filename))
-               goto out;
-       error = do_execve(filename->name,
-                         (const char __user *const __user *) (long)regs.regs[5],
-                         (const char __user *const __user *) (long)regs.regs[6],
-                         &regs);
-       putname(filename);
-
-out:
-       return error;
-}
-
 SYSCALL_DEFINE1(set_thread_area, unsigned long, addr)
 {
        struct thread_info *ti = task_thread_info(current);
@@ -313,34 +291,3 @@ asmlinkage void bad_stack(void)
 {
        do_exit(SIGSEGV);
 }
-
-/*
- * Do a system call from kernel instead of calling sys_execve so we
- * end up with proper pt_regs.
- */
-int kernel_execve(const char *filename,
-                 const char *const argv[],
-                 const char *const envp[])
-{
-       register unsigned long __a0 asm("$4") = (unsigned long) filename;
-       register unsigned long __a1 asm("$5") = (unsigned long) argv;
-       register unsigned long __a2 asm("$6") = (unsigned long) envp;
-       register unsigned long __a3 asm("$7");
-       unsigned long __v0;
-
-       __asm__ volatile ("                                     \n"
-       "       .set    noreorder                               \n"
-       "       li      $2, %5          # __NR_execve           \n"
-       "       syscall                                         \n"
-       "       move    %0, $2                                  \n"
-       "       .set    reorder                                 \n"
-       : "=&r" (__v0), "=r" (__a3)
-       : "r" (__a0), "r" (__a1), "r" (__a2), "i" (__NR_execve)
-       : "$2", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24",
-         "memory");
-
-       if (__a3 == 0)
-               return __v0;
-
-       return -__v0;
-}