qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: riku.voipio@linaro.org
To: qemu-devel@nongnu.org
Cc: Timothy E Baldwin <T.E.Baldwin99@members.leeds.ac.uk>
Subject: [Qemu-devel] [PULL v2 06/38] linux-user: Support for restarting system calls for x86 targets
Date: Fri, 27 May 2016 15:59:57 +0300	[thread overview]
Message-ID: <0284b03ba3f47da53b6b46293a3d586c08829f7e.1464353863.git.riku.voipio@linaro.org> (raw)
In-Reply-To: <cover.1464353863.git.riku.voipio@linaro.org>

From: Timothy E Baldwin <T.E.Baldwin99@members.leeds.ac.uk>

Update the x86 main loop and sigreturn code:
 * on TARGET_ERESTARTSYS, wind guest PC backwards to repeat syscall insn
 * set all guest CPU state within signal.c code rather than passing it
   back out as the "return code" from do_sigreturn()
 * handle TARGET_QEMU_ESIGRETURN in the main loop as the indication
   that the main loop should not touch EAX

Signed-off-by: Timothy Edward Baldwin <T.E.Baldwin99@members.leeds.ac.uk>
Message-id: 1441497448-32489-5-git-send-email-T.E.Baldwin99@members.leeds.ac.uk
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
[PMM: Commit message tweaks; drop TARGET_USE_ERESTARTSYS define]
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
 linux-user/main.c    | 47 +++++++++++++++++++++++++++++------------------
 linux-user/signal.c  | 15 +++++++--------
 linux-user/syscall.c |  2 --
 3 files changed, 36 insertions(+), 28 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 95ed11d..da5a033 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -285,6 +285,7 @@ void cpu_loop(CPUX86State *env)
     CPUState *cs = CPU(x86_env_get_cpu(env));
     int trapnr;
     abi_ulong pc;
+    abi_ulong ret;
     target_siginfo_t info;
 
     for(;;) {
@@ -294,28 +295,38 @@ void cpu_loop(CPUX86State *env)
         switch(trapnr) {
         case 0x80:
             /* linux syscall from int $0x80 */
-            env->regs[R_EAX] = do_syscall(env,
-                                          env->regs[R_EAX],
-                                          env->regs[R_EBX],
-                                          env->regs[R_ECX],
-                                          env->regs[R_EDX],
-                                          env->regs[R_ESI],
-                                          env->regs[R_EDI],
-                                          env->regs[R_EBP],
-                                          0, 0);
+            ret = do_syscall(env,
+                             env->regs[R_EAX],
+                             env->regs[R_EBX],
+                             env->regs[R_ECX],
+                             env->regs[R_EDX],
+                             env->regs[R_ESI],
+                             env->regs[R_EDI],
+                             env->regs[R_EBP],
+                             0, 0);
+            if (ret == -TARGET_ERESTARTSYS) {
+                env->eip -= 2;
+            } else if (ret != -TARGET_QEMU_ESIGRETURN) {
+                env->regs[R_EAX] = ret;
+            }
             break;
 #ifndef TARGET_ABI32
         case EXCP_SYSCALL:
             /* linux syscall from syscall instruction */
-            env->regs[R_EAX] = do_syscall(env,
-                                          env->regs[R_EAX],
-                                          env->regs[R_EDI],
-                                          env->regs[R_ESI],
-                                          env->regs[R_EDX],
-                                          env->regs[10],
-                                          env->regs[8],
-                                          env->regs[9],
-                                          0, 0);
+            ret = do_syscall(env,
+                             env->regs[R_EAX],
+                             env->regs[R_EDI],
+                             env->regs[R_ESI],
+                             env->regs[R_EDX],
+                             env->regs[10],
+                             env->regs[8],
+                             env->regs[9],
+                             0, 0);
+            if (ret == -TARGET_ERESTARTSYS) {
+                env->eip -= 2;
+            } else if (ret != -TARGET_QEMU_ESIGRETURN) {
+                env->regs[R_EAX] = ret;
+            }
             break;
 #endif
         case EXCP0B_NOSEG:
diff --git a/linux-user/signal.c b/linux-user/signal.c
index 04c21d0..11ddd05 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -1024,7 +1024,7 @@ give_sigsegv:
 }
 
 static int
-restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc, int *peax)
+restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc)
 {
     unsigned int err = 0;
     abi_ulong fpstate_addr;
@@ -1042,6 +1042,7 @@ restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc, int *peax)
     env->regs[R_EBX] = tswapl(sc->ebx);
     env->regs[R_EDX] = tswapl(sc->edx);
     env->regs[R_ECX] = tswapl(sc->ecx);
+    env->regs[R_EAX] = tswapl(sc->eax);
     env->eip = tswapl(sc->eip);
 
     cpu_x86_load_seg(env, R_CS, lduw_p(&sc->cs) | 3);
@@ -1059,7 +1060,6 @@ restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc, int *peax)
         cpu_x86_frstor(env, fpstate_addr, 1);
     }
 
-    *peax = tswapl(sc->eax);
     return err;
 badframe:
     return 1;
@@ -1071,7 +1071,7 @@ long do_sigreturn(CPUX86State *env)
     abi_ulong frame_addr = env->regs[R_ESP] - 8;
     target_sigset_t target_set;
     sigset_t set;
-    int eax, i;
+    int i;
 
     trace_user_do_sigreturn(env, frame_addr);
     if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1))
@@ -1086,10 +1086,10 @@ long do_sigreturn(CPUX86State *env)
     do_sigprocmask(SIG_SETMASK, &set, NULL);
 
     /* restore registers */
-    if (restore_sigcontext(env, &frame->sc, &eax))
+    if (restore_sigcontext(env, &frame->sc))
         goto badframe;
     unlock_user_struct(frame, frame_addr, 0);
-    return eax;
+    return -TARGET_QEMU_ESIGRETURN;
 
 badframe:
     unlock_user_struct(frame, frame_addr, 0);
@@ -1102,7 +1102,6 @@ long do_rt_sigreturn(CPUX86State *env)
     abi_ulong frame_addr;
     struct rt_sigframe *frame;
     sigset_t set;
-    int eax;
 
     frame_addr = env->regs[R_ESP] - 4;
     trace_user_do_rt_sigreturn(env, frame_addr);
@@ -1111,7 +1110,7 @@ long do_rt_sigreturn(CPUX86State *env)
     target_to_host_sigset(&set, &frame->uc.tuc_sigmask);
     do_sigprocmask(SIG_SETMASK, &set, NULL);
 
-    if (restore_sigcontext(env, &frame->uc.tuc_mcontext, &eax)) {
+    if (restore_sigcontext(env, &frame->uc.tuc_mcontext)) {
         goto badframe;
     }
 
@@ -1121,7 +1120,7 @@ long do_rt_sigreturn(CPUX86State *env)
     }
 
     unlock_user_struct(frame, frame_addr, 0);
-    return eax;
+    return -TARGET_QEMU_ESIGRETURN;
 
 badframe:
     unlock_user_struct(frame, frame_addr, 0);
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index f4c2e19..a4a1af7 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6940,12 +6940,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #ifdef TARGET_NR_sigreturn
     case TARGET_NR_sigreturn:
-        /* NOTE: ret is eax, so not transcoding must be done */
         ret = do_sigreturn(cpu_env);
         break;
 #endif
     case TARGET_NR_rt_sigreturn:
-        /* NOTE: ret is eax, so not transcoding must be done */
         ret = do_rt_sigreturn(cpu_env);
         break;
     case TARGET_NR_sethostname:
-- 
2.1.4

  parent reply	other threads:[~2016-05-27 13:00 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-27 12:59 [Qemu-devel] [PULL v2 00/38] linux-user pull request riku.voipio
2016-05-27 12:59 ` [Qemu-devel] [PULL v2 01/38] linux-user: Check array bounds in errno conversion riku.voipio
2016-05-27 12:59 ` [Qemu-devel] [PULL v2 02/38] linux-user: Consistently return host errnos from do_openat() riku.voipio
2016-05-27 12:59 ` [Qemu-devel] [PULL v2 03/38] linux-user: Reindent signal handling riku.voipio
2016-05-27 12:59 ` [Qemu-devel] [PULL v2 04/38] linux-user: Define TARGET_ERESTART* errno values riku.voipio
2016-05-27 12:59 ` [Qemu-devel] [PULL v2 05/38] linux-user: Renumber TARGET_QEMU_ESIGRETURN, make it not arch-specific riku.voipio
2016-05-27 12:59 ` riku.voipio [this message]
2016-05-27 12:59 ` [Qemu-devel] [PULL v2 07/38] linux-user: Support for restarting system calls for ARM targets riku.voipio
2016-05-27 12:59 ` [Qemu-devel] [PULL v2 08/38] linux-user: Support for restarting system calls for MIPS targets riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 09/38] linux-user: Support for restarting system calls for PPC targets riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 10/38] linux-user: Support for restarting system calls for SPARC targets riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 11/38] linux-user: Support for restarting system calls for SH4 targets riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 12/38] linux-user: Support for restarting system calls for Alpha targets riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 13/38] linux-user: Support for restarting system calls for UniCore32 targets riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 14/38] linux-user: Support for restarting system calls for OpenRISC targets riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 15/38] linux-user: Support for restarting system calls for M68K targets riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 16/38] linux-user: Support for restarting system calls for S390 targets riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 17/38] linux-user: Support for restarting system calls for CRIS targets riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 18/38] linux-user: Support for restarting system calls for tilegx targets riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 19/38] linux-user: Set r14 on exit from microblaze syscall riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 20/38] linux-user: Support for restarting system calls for Microblaze targets riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 21/38] linux-user: Add debug code to exercise restarting system calls riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 22/38] linux-user: Provide safe_syscall for fixing races between signals and syscalls riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 23/38] linux-user: Use safe_syscall for read and write system calls riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 24/38] linux-user: Use safe_syscall for open and openat " riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 25/38] linux-user: Use safe_syscall for wait " riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 26/38] linux-user: Use safe_syscall for execve syscall riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 27/38] linux-user: Use safe_syscall for pselect, select syscalls riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 28/38] linux-user: Use safe_syscall for futex syscall riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 29/38] linux-user: Handle negative values in timespec conversion riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 30/38] linux-user: Handle msgrcv error case correctly riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 31/38] linux-user: Use g_try_malloc() in do_msgrcv() riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 32/38] linux-user: x86_64: Don't use 16-bit UIDs riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 33/38] linux-user: Use direct syscalls for setuid(), etc riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 34/38] linux-user: arm: Remove ARM_cpsr and similar #defines riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 35/38] linux-user/signal.c: Generate opcode data for restorer in setup_rt_frame riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 36/38] linux-user/signal.c: Use target address instead of host address for microblaze restorer riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 37/38] linux-user/signal.c: Use s390 target space address instead of host space riku.voipio
2016-05-27 13:00 ` [Qemu-devel] [PULL v2 38/38] linux-user, target-ppc: fix use of MSR_LE riku.voipio
2016-05-27 14:03 ` [Qemu-devel] [PULL v2 00/38] linux-user pull request Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0284b03ba3f47da53b6b46293a3d586c08829f7e.1464353863.git.riku.voipio@linaro.org \
    --to=riku.voipio@linaro.org \
    --cc=T.E.Baldwin99@members.leeds.ac.uk \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).