lkml.org 
[lkml]   [2011]   [Oct]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH RFC 5/8] x86: implement syscall restart generically
Date

Manipulating task state to effect re-execution of an interrupted syscall
used to be purely architecture specific code. However, as most arch's
were essentially just making minor adjustments to almost identical logic,
this code could be moved to a common implementation.

The generic variant introduces the function handle_syscall_restart() to be
called after get_signal_to_deliver(). The architecture specific register
manipulations required to effect the actual restart are now implemented
in the generic syscall interface found in asm/syscall.h

This patch transitions this architecture's signal handling code over to
using the generic syscall restart code by:

i) Implementing the register manipulations in asm/syscall.h
ii) Replacing the restart logic with a call to handle_syscall_restart

Cc: x86@kernel.org
Signed-off-by: Jonas Bonn <jonas@southpole.se>
---
arch/x86/include/asm/syscall.h | 21 +++++++++++++++++++
arch/x86/kernel/signal.c | 43 ++-------------------------------------
2 files changed, 24 insertions(+), 40 deletions(-)
diff --git a/arch/x86/include/asm/syscall.h b/arch/x86/include/asm/syscall.h
index c4a348f..bd7e0f6 100644
--- a/arch/x86/include/asm/syscall.h
+++ b/arch/x86/include/asm/syscall.h
@@ -15,6 +15,7 @@

#include <linux/sched.h>
#include <linux/err.h>
+#include <asm/unistd.h>

extern const unsigned long sys_call_table[];

@@ -34,6 +35,26 @@ static inline void syscall_rollback(struct task_struct *task,
regs->ax = regs->orig_ax;
}

+static inline void
+syscall_clear(struct task_struct *task, struct pt_regs *regs)
+{
+ regs->orig_ax = -1;
+}
+
+static inline void
+syscall_restart(struct task_struct *task, struct pt_regs *regs)
+{
+ syscall_rollback(task, regs);
+ regs->ip -= 2;
+}
+
+static inline void
+syscall_do_restartblock(struct task_struct *task, struct pt_regs *regs)
+{
+ regs->ax = __NR_restart_syscall;
+ regs->ip -= 2;
+}
+
static inline long syscall_get_error(struct task_struct *task,
struct pt_regs *regs)
{
diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index 54ddaeb2..366d5f7 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -685,28 +685,6 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
sigset_t blocked;
int ret;

- /* Are we from a system call? */
- if (syscall_get_nr(current, regs) >= 0) {
- /* If so, check system call restarting.. */
- switch (syscall_get_error(current, regs)) {
- case -ERESTART_RESTARTBLOCK:
- case -ERESTARTNOHAND:
- regs->ax = -EINTR;
- break;
-
- case -ERESTARTSYS:
- if (!(ka->sa.sa_flags & SA_RESTART)) {
- regs->ax = -EINTR;
- break;
- }
- /* fallthrough */
- case -ERESTARTNOINTR:
- regs->ax = regs->orig_ax;
- regs->ip -= 2;
- break;
- }
- }
-
/*
* If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
* flag so that register information in the sigcontext is correct.
@@ -773,30 +751,15 @@ static void do_signal(struct pt_regs *regs)
return;

signr = get_signal_to_deliver(&info, &ka, regs, NULL);
+
+ handle_syscall_restart(regs, &ka, (signr > 0));
+
if (signr > 0) {
/* Whee! Actually deliver the signal. */
handle_signal(signr, &info, &ka, regs);
return;
}

- /* Did we come from a system call? */
- if (syscall_get_nr(current, regs) >= 0) {
- /* Restart the system call - no handlers present */
- switch (syscall_get_error(current, regs)) {
- case -ERESTARTNOHAND:
- case -ERESTARTSYS:
- case -ERESTARTNOINTR:
- regs->ax = regs->orig_ax;
- regs->ip -= 2;
- break;
-
- case -ERESTART_RESTARTBLOCK:
- regs->ax = NR_restart_syscall;
- regs->ip -= 2;
- break;
- }
- }
-
/*
* If there's no signal to deliver, we just put the saved sigmask
* back.
--
1.7.5.4


\
 
 \ /
  Last update: 2011-10-23 12:23    [from the cache]
©2003-2014 Jasper Spaans. Advertise on this site