aboutsummaryrefslogtreecommitdiff
path: root/linux-user
diff options
context:
space:
mode:
authorTimothy E Baldwin <T.E.Baldwin99@members.leeds.ac.uk>2016-05-12 18:47:30 +0100
committerRiku Voipio <riku.voipio@linaro.org>2016-05-27 14:49:49 +0300
commit0284b03ba3f47da53b6b46293a3d586c08829f7e (patch)
treea7942bf22838565bf88cfccf69af317c36d90725 /linux-user
parent499b5d176a77773cab5479264a3d5067176df21c (diff)
linux-user: Support for restarting system calls for x86 targets
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>
Diffstat (limited to 'linux-user')
-rw-r--r--linux-user/main.c47
-rw-r--r--linux-user/signal.c15
-rw-r--r--linux-user/syscall.c2
3 files changed, 36 insertions, 28 deletions
diff --git a/linux-user/main.c b/linux-user/main.c
index 95ed11d85c..da5a0333b6 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 04c21d0ccd..11ddd05173 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 f4c2e190f8..a4a1af75f6 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: