Skip to content

Commit baf9ff7

Browse files
ralfbaechleAl Viro
authored andcommitted
MIPS: Switch over to generic sys_execve and kernel_execve.
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>
1 parent 8f54bca commit baf9ff7

7 files changed

Lines changed: 19 additions & 76 deletions

File tree

‎arch/mips/include/asm/ptrace.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,10 @@ static inline void die_if_kernel(const char *str, struct pt_regs *regs)
6161
die(str, regs);
6262
}
6363

64+
#define current_pt_regs() \
65+
({ \
66+
unsigned long sp = (unsigned long)__builtin_frame_address(0); \
67+
(struct pt_regs *)((sp | (THREAD_SIZE - 1)) + 1 - 32) - 1; \
68+
})
69+
6470
#endif /* _ASM_PTRACE_H */

‎arch/mips/include/asm/unistd.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
#ifndef __ASSEMBLY__
1919

2020
#define __ARCH_OMIT_COMPAT_SYS_GETDENTS64
21+
#define __ARCH_WANT_KERNEL_EXECVE
2122
#define __ARCH_WANT_OLD_READDIR
2223
#define __ARCH_WANT_SYS_ALARM
24+
#define __ARCH_WANT_SYS_EXECVE
2325
#define __ARCH_WANT_SYS_GETHOSTNAME
2426
#define __ARCH_WANT_SYS_IPC
2527
#define __ARCH_WANT_SYS_PAUSE

‎arch/mips/kernel/entry.S‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,15 @@ syscall_exit_work:
192192
jal syscall_trace_leave
193193
b resume_userspace
194194

195+
LEAF(ret_from_kernel_execve)
196+
move sp, a0
197+
ori $28, sp, _THREAD_SIZE - 1
198+
xori $28, $28, _THREAD_SIZE - 1
199+
li v0, 0
200+
li a3, 0
201+
j syscall_exit_partial
202+
END(ret_from_kernel_execve)
203+
195204
#if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_MIPS_MT)
196205

197206
/*

‎arch/mips/kernel/linux32.c‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*
44
* Copyright (C) 2000 Silicon Graphics, Inc.
55
* Written by Ulf Carlsson (ulfc@engr.sgi.com)
6-
* sys32_execve from ia64/ia32 code, Feb 2000, Kanoj Sarcar (kanoj@sgi.com)
76
*/
87
#include <linux/compiler.h>
98
#include <linux/mm.h>
@@ -77,26 +76,6 @@ SYSCALL_DEFINE6(32_mmap2, unsigned long, addr, unsigned long, len,
7776
return error;
7877
}
7978

80-
/*
81-
* sys_execve() executes a new program.
82-
*/
83-
asmlinkage int sys32_execve(nabi_no_regargs struct pt_regs regs)
84-
{
85-
int error;
86-
struct filename *filename;
87-
88-
filename = getname(compat_ptr(regs.regs[4]));
89-
error = PTR_ERR(filename);
90-
if (IS_ERR(filename))
91-
goto out;
92-
error = compat_do_execve(filename->name, compat_ptr(regs.regs[5]),
93-
compat_ptr(regs.regs[6]), &regs);
94-
putname(filename);
95-
96-
out:
97-
return error;
98-
}
99-
10079
#define RLIM_INFINITY32 0x7fffffff
10180
#define RESOURCE32(x) ((x > RLIM_INFINITY32) ? RLIM_INFINITY32 : x)
10281

‎arch/mips/kernel/scall64-n32.S‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ EXPORT(sysn32_call_table)
167167
PTR sys_getsockopt
168168
PTR sys_clone /* 6055 */
169169
PTR sys_fork
170-
PTR sys32_execve
170+
PTR compat_sys_execve
171171
PTR sys_exit
172172
PTR compat_sys_wait4
173173
PTR sys_kill /* 6060 */

‎arch/mips/kernel/scall64-o32.S‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ sys_call_table:
203203
PTR sys_creat
204204
PTR sys_link
205205
PTR sys_unlink /* 4010 */
206-
PTR sys32_execve
206+
PTR compat_sys_execve
207207
PTR sys_chdir
208208
PTR compat_sys_time
209209
PTR sys_mknod

‎arch/mips/kernel/syscall.c‎

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -127,28 +127,6 @@ _sys_clone(nabi_no_regargs struct pt_regs regs)
127127
parent_tidptr, child_tidptr);
128128
}
129129

130-
/*
131-
* sys_execve() executes a new program.
132-
*/
133-
asmlinkage int sys_execve(nabi_no_regargs struct pt_regs regs)
134-
{
135-
int error;
136-
struct filename *filename;
137-
138-
filename = getname((const char __user *) (long)regs.regs[4]);
139-
error = PTR_ERR(filename);
140-
if (IS_ERR(filename))
141-
goto out;
142-
error = do_execve(filename->name,
143-
(const char __user *const __user *) (long)regs.regs[5],
144-
(const char __user *const __user *) (long)regs.regs[6],
145-
&regs);
146-
putname(filename);
147-
148-
out:
149-
return error;
150-
}
151-
152130
SYSCALL_DEFINE1(set_thread_area, unsigned long, addr)
153131
{
154132
struct thread_info *ti = task_thread_info(current);
@@ -313,34 +291,3 @@ asmlinkage void bad_stack(void)
313291
{
314292
do_exit(SIGSEGV);
315293
}
316-
317-
/*
318-
* Do a system call from kernel instead of calling sys_execve so we
319-
* end up with proper pt_regs.
320-
*/
321-
int kernel_execve(const char *filename,
322-
const char *const argv[],
323-
const char *const envp[])
324-
{
325-
register unsigned long __a0 asm("$4") = (unsigned long) filename;
326-
register unsigned long __a1 asm("$5") = (unsigned long) argv;
327-
register unsigned long __a2 asm("$6") = (unsigned long) envp;
328-
register unsigned long __a3 asm("$7");
329-
unsigned long __v0;
330-
331-
__asm__ volatile (" \n"
332-
" .set noreorder \n"
333-
" li $2, %5 # __NR_execve \n"
334-
" syscall \n"
335-
" move %0, $2 \n"
336-
" .set reorder \n"
337-
: "=&r" (__v0), "=r" (__a3)
338-
: "r" (__a0), "r" (__a1), "r" (__a2), "i" (__NR_execve)
339-
: "$2", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24",
340-
"memory");
341-
342-
if (__a3 == 0)
343-
return __v0;
344-
345-
return -__v0;
346-
}

0 commit comments

Comments
 (0)