From patchwork Wed May 25 05:27:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 9134739 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C8D45607D3 for ; Wed, 25 May 2016 05:33:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCE4328166 for ; Wed, 25 May 2016 05:33:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B1853282AF; Wed, 25 May 2016 05:33:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, FSL_HELO_HOME, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 062FB28166 for ; Wed, 25 May 2016 05:33:45 +0000 (UTC) Received: from localhost ([::1]:57395 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5RRw-0003U3-3V for patchwork-qemu-devel@patchwork.kernel.org; Wed, 25 May 2016 01:33:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33847) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5RN7-0008Aa-6D for qemu-devel@nongnu.org; Wed, 25 May 2016 01:28:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5RN2-0001Sn-WE for qemu-devel@nongnu.org; Wed, 25 May 2016 01:28:44 -0400 Received: from mail-lb0-x229.google.com ([2a00:1450:4010:c04::229]:33898) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5RN2-0001Rw-Em for qemu-devel@nongnu.org; Wed, 25 May 2016 01:28:40 -0400 Received: by mail-lb0-x229.google.com with SMTP id sh2so11955373lbb.1 for ; Tue, 24 May 2016 22:28:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UaLXGlmPEnDy5wi94ibHWfl+SEJQxRt7ckCaaIoM+9o=; b=GvP0tAnirR2NAqOrlgHsWbdGj4t/mduMtAb8tbgqaK3yeU/j0l5gvURRZ5VUVhrCCG 75qLks8urlMjalTZYJjDz0gnM809zipD8pfVmqvMsBkSI3Z+u5836nUvTHeDHIQ00SZI Rf3FV9Qpv+Zu7m2Tec4XONc0KO2WwGgLKZ9bk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UaLXGlmPEnDy5wi94ibHWfl+SEJQxRt7ckCaaIoM+9o=; b=IS8zcaE3yUL0OdOPxdUyvnxxF5GF68O8FWUufPQvXxqivPvQ9WDXVIdFQ6vp6fdrA7 RnUD8ACt/wMIZUTvIVjCJYBBfS/dn3j5gKo2Y078AQRAu9bIMLI+GiKgVmFWbjP/UEL/ h/PZGuztPO1nG7ub+rcn0LkE2TZpCHbht47phF+0rkmaOiE+Q7CUghQgkLo4SgYhTFrV T2gL1wy16r8XrJCKTDSWfjELnbFuxmejMn1vEI1S9Jp6RmqU8ErYV5byc65VVNPYch6Q JhBj57MIH2DcBRCW8UZPctg38RRsbd/MvSbDOKYcDaIfU1vunOK4itgJPMjtGHhqG8SA mK5w== X-Gm-Message-State: ALyK8tIbVr+GRyYScb8tA8RS7B79lDHK/T5H7T7K/6N7GrHD9EIDpCqs8xHI0wEQJWFL+1ox X-Received: by 10.112.22.134 with SMTP id d6mr526905lbf.100.1464154119658; Tue, 24 May 2016 22:28:39 -0700 (PDT) Received: from beaming.home (91-157-168-132.elisa-laajakaista.fi. [91.157.168.132]) by smtp.gmail.com with ESMTPSA id g10sm1136823lbc.43.2016.05.24.22.28.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 May 2016 22:28:38 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Wed, 25 May 2016 08:27:45 +0300 Message-Id: <70b0d405a0d37499a7aec2a5122d01e9763c68e0.1464153942.git.riku.voipio@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c04::229 Subject: [Qemu-devel] [PULL 07/38] linux-user: Support for restarting system calls for ARM targets X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Timothy E Baldwin Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Timothy E Baldwin Update the 32-bit and 64-bit ARM 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 on sigreturn * handle TARGET_QEMU_ESIGRETURN in the main loop as the indication that the main loop should not touch any guest CPU state Signed-off-by: Timothy Edward Baldwin Message-id: 1441497448-32489-6-git-send-email-T.E.Baldwin99@members.leeds.ac.uk Reviewed-by: Peter Maydell [PMM: tweak commit message; drop TARGET_USE_ERESTARTSYS define] Signed-off-by: Peter Maydell Signed-off-by: Riku Voipio --- linux-user/arm/target_signal.h | 1 + linux-user/main.c | 48 ++++++++++++++++++++++++++---------------- linux-user/signal.c | 10 ++++----- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/linux-user/arm/target_signal.h b/linux-user/arm/target_signal.h index 2b32813..fb31f4c 100644 --- a/linux-user/arm/target_signal.h +++ b/linux-user/arm/target_signal.h @@ -26,4 +26,5 @@ static inline abi_ulong get_sp_from_cpustate(CPUARMState *state) return state->regs[13]; } + #endif /* TARGET_SIGNAL_H */ diff --git a/linux-user/main.c b/linux-user/main.c index 57ae76e..0e3da58 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -727,6 +727,7 @@ void cpu_loop(CPUARMState *env) unsigned int n, insn; target_siginfo_t info; uint32_t addr; + abi_ulong ret; for(;;) { cpu_exec_start(cs); @@ -865,15 +866,20 @@ void cpu_loop(CPUARMState *env) break; } } else { - env->regs[0] = do_syscall(env, - n, - env->regs[0], - env->regs[1], - env->regs[2], - env->regs[3], - env->regs[4], - env->regs[5], - 0, 0); + ret = do_syscall(env, + n, + env->regs[0], + env->regs[1], + env->regs[2], + env->regs[3], + env->regs[4], + env->regs[5], + 0, 0); + if (ret == -TARGET_ERESTARTSYS) { + env->regs[15] -= env->thumb ? 2 : 4; + } else if (ret != -TARGET_QEMU_ESIGRETURN) { + env->regs[0] = ret; + } } } else { goto error; @@ -1056,6 +1062,7 @@ void cpu_loop(CPUARMState *env) { CPUState *cs = CPU(arm_env_get_cpu(env)); int trapnr, sig; + abi_long ret; target_siginfo_t info; for (;;) { @@ -1065,15 +1072,20 @@ void cpu_loop(CPUARMState *env) switch (trapnr) { case EXCP_SWI: - env->xregs[0] = do_syscall(env, - env->xregs[8], - env->xregs[0], - env->xregs[1], - env->xregs[2], - env->xregs[3], - env->xregs[4], - env->xregs[5], - 0, 0); + ret = do_syscall(env, + env->xregs[8], + env->xregs[0], + env->xregs[1], + env->xregs[2], + env->xregs[3], + env->xregs[4], + env->xregs[5], + 0, 0); + if (ret == -TARGET_ERESTARTSYS) { + env->pc -= 4; + } else if (ret != -TARGET_QEMU_ESIGRETURN) { + env->xregs[0] = ret; + } break; case EXCP_INTERRUPT: /* just indicate that signals should be handled asap */ diff --git a/linux-user/signal.c b/linux-user/signal.c index 11ddd05..14e58b0 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -1390,7 +1390,7 @@ long do_rt_sigreturn(CPUARMState *env) } unlock_user_struct(frame, frame_addr, 0); - return env->xregs[0]; + return -TARGET_QEMU_ESIGRETURN; badframe: unlock_user_struct(frame, frame_addr, 0); @@ -1902,7 +1902,7 @@ static long do_sigreturn_v1(CPUARMState *env) send_sig(SIGTRAP, current, 1); #endif unlock_user_struct(frame, frame_addr, 0); - return env->regs[0]; + return -TARGET_QEMU_ESIGRETURN; badframe: force_sig(TARGET_SIGSEGV /* , current */); @@ -2028,7 +2028,7 @@ static long do_sigreturn_v2(CPUARMState *env) } unlock_user_struct(frame, frame_addr, 0); - return env->regs[0]; + return -TARGET_QEMU_ESIGRETURN; badframe: unlock_user_struct(frame, frame_addr, 0); @@ -2082,7 +2082,7 @@ static long do_rt_sigreturn_v1(CPUARMState *env) send_sig(SIGTRAP, current, 1); #endif unlock_user_struct(frame, frame_addr, 0); - return env->regs[0]; + return -TARGET_QEMU_ESIGRETURN; badframe: unlock_user_struct(frame, frame_addr, 0); @@ -2115,7 +2115,7 @@ static long do_rt_sigreturn_v2(CPUARMState *env) } unlock_user_struct(frame, frame_addr, 0); - return env->regs[0]; + return -TARGET_QEMU_ESIGRETURN; badframe: unlock_user_struct(frame, frame_addr, 0);