Commit 912fcae9 authored by Ed Swierk's avatar Ed Swierk Committed by Willy Tarreau

MIPS: Fix restart of indirect syscalls

commit e967ef02 upstream.

When 32-bit MIPS userspace invokes a syscall indirectly via syscall(number,
arg1, ..., arg7), the kernel looks up the actual syscall based on the given
number, shifts the other arguments to the left, and jumps to the syscall.

If the syscall is interrupted by a signal and indicates it needs to be
restarted by the kernel (by returning ERESTARTNOINTR for example), the
syscall must be called directly, since the number is no longer the first
argument, and the other arguments are now staged for a direct call.

Before shifting the arguments, store the syscall number in pt_regs->regs[2].
This gets copied temporarily into pt_regs->regs[0] after the syscall returns.
If the syscall needs to be restarted, handle_signal()/do_signal() copies the
number back to pt_regs->reg[2], which ends up in $v0 once control returns to
userspace.
Signed-off-by: default avatarEd Swierk <eswierk@skyportsystems.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/8929/Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
(cherry picked from commit 08f865bb)
Signed-off-by: default avatarWilly Tarreau <w@1wt.eu>
parent 533030ca
...@@ -194,6 +194,7 @@ illegal_syscall: ...@@ -194,6 +194,7 @@ illegal_syscall:
sll t1, t0, 3 sll t1, t0, 3
beqz v0, einval beqz v0, einval
lw t2, sys_call_table(t1) # syscall routine lw t2, sys_call_table(t1) # syscall routine
sw a0, PT_R2(sp) # call routine directly on restart
/* Some syscalls like execve get their arguments from struct pt_regs /* Some syscalls like execve get their arguments from struct pt_regs
and claim zero arguments in the syscall table. Thus we have to and claim zero arguments in the syscall table. Thus we have to
......
...@@ -180,6 +180,7 @@ LEAF(sys32_syscall) ...@@ -180,6 +180,7 @@ LEAF(sys32_syscall)
dsll t1, t0, 3 dsll t1, t0, 3
beqz v0, einval beqz v0, einval
ld t2, sys_call_table(t1) # syscall routine ld t2, sys_call_table(t1) # syscall routine
sd a0, PT_R2(sp) # call routine directly on restart
move a0, a1 # shift argument registers move a0, a1 # shift argument registers
move a1, a2 move a1, a2
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment