From patchwork Wed Aug 22 01:14:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 960755 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41w8jm0bcJz9s5c for ; Wed, 22 Aug 2018 11:15:24 +1000 (AEST) Received: from localhost ([::1]:56411 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fsHk1-00068b-MM for incoming@patchwork.ozlabs.org; Tue, 21 Aug 2018 21:15:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36339) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fsHjV-0005k9-C9 for qemu-devel@nongnu.org; Tue, 21 Aug 2018 21:14:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fsHjP-0001eU-Br for qemu-devel@nongnu.org; Tue, 21 Aug 2018 21:14:49 -0400 Received: from mout.kundenserver.de ([217.72.192.75]:42769) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fsHjN-0001ai-St for qemu-devel@nongnu.org; Tue, 21 Aug 2018 21:14:42 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0LaU1P-1gG2Dk382h-00mKoo; Wed, 22 Aug 2018 03:14:27 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 22 Aug 2018 03:14:12 +0200 Message-Id: <20180822011417.11608-3-laurent@vivier.eu> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180822011417.11608-1-laurent@vivier.eu> References: <20180822011417.11608-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:HrtQod8X3xyM1inMq4OmGrNJTR2GGr2LhKsOnGUJZs5hDTZgzid BtTv7A6rvOQ7PP26Vj/T8adnQSkT0UWJLNwKr3rMJ46IAQf08d3vy+s3lk8Hd6ldfFq9c84 19dAA9VMUKmLPYokCcBi3lEfQmxdZ5Efdob2PQ2fuQOdy6zvzJNX95R/OGuKMcDZNESEiHU N03nLYP4vEv7gkQCc7YzQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:I9ONJ5Fm55w=:BinhOGfbAWcCHV+Lln6QUx U52s6Zurj6OfXVL9vHvAY7/E/3JFb8z+rZEEXUozTEB53VjpVYN2PEdD9EvWN682tNns3XNP0 jt/QuIS7IJMMEv3dPUUPSnx57e1dMO394GMxPPsUQXm2EKpl7URg9YQQ0FGgEg6JVAZRlebZi k05F/jhpTbVX9VAE+QGnPXyqa1pSvqE6wBqLyvUUKbHZW9kaMQUioFQ/J2sgyU0T8fWy+xLhw zGeON6ytxu9RLCoEkbqbDK9abBqpVrQn5H4JOWBDjdxkkKyCCZEskI7iimLxcjZ3yJt0ygQxH QwYthMNTtK3DgPb+rmeaM27H+f8nXQI9bUEjP1gyZKnffcQ9f/kxIx7LwNzmMJcNOAryQrgIm mwBAKp9Ga88XJw//OB5YIc143NWcXWnoKoJNEn8IksZG9IjwAmOHSbCWMa3tKmV4vc3Cof3tY /DzjpHCtI3p6uiLGue/mJp9kLXmgqbbgDkM0TqOMKww1S8x1dYJllNiQlrPDsWZCSQtdpv2KM 7gmw/jQd5EpeODhlgWb7c/Ks2VNU8jYUTqhOeCz1lIASMYNiwA41ii+L6a07tCptiWaxkDAca Upp1GsTL6t/JnE1wnA+QbGBBXJl/E/qa3uNdnYBZIjraf1dZgilK3TJVz4aZnELJKiIZNmbnJ qbMFoRTkPfzPjQkRhleEqJEQKeagBNuTD5MYvWNFV2thcIo437P2tUASWGWD02NrB9RZMSIxg /lCVVPJK6N9EePU+ X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 217.72.192.75 Subject: [Qemu-devel] [PULL 2/7] linux-user: Split out do_syscall1 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: Riku Voipio , Richard Henderson , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson There was supposed to be a single point of return for do_syscall so that tracing works properly. However, there are a few bugs in that area. It is significantly simpler to simply split out an inner function to enforce this. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Laurent Vivier Signed-off-by: Richard Henderson Message-Id: <20180818190118.12911-3-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 77 +++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 29 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 2e45f854f7..f651024357 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8092,13 +8092,15 @@ static int host_to_target_cpu_mask(const unsigned long *host_mask, return 0; } -/* do_syscall() should always have a single exit point at the end so - that actions, such as logging of syscall results, can be performed. - All errnos that do_syscall() returns must be -TARGET_. */ -abi_long do_syscall(void *cpu_env, int num, abi_long arg1, - abi_long arg2, abi_long arg3, abi_long arg4, - abi_long arg5, abi_long arg6, abi_long arg7, - abi_long arg8) +/* This is an internal helper for do_syscall so that it is easier + * to have a single return point, so that actions, such as logging + * of syscall results, can be performed. + * All errnos that do_syscall() returns must be -TARGET_. + */ +static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, + abi_long arg2, abi_long arg3, abi_long arg4, + abi_long arg5, abi_long arg6, abi_long arg7, + abi_long arg8) { CPUState *cpu = ENV_GET_CPU(cpu_env); abi_long ret; @@ -8113,25 +8115,6 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, #endif void *p; -#if defined(DEBUG_ERESTARTSYS) - /* Debug-only code for exercising the syscall-restart code paths - * in the per-architecture cpu main loops: restart every syscall - * the guest makes once before letting it through. - */ - { - static int flag; - - flag = !flag; - if (flag) { - return -TARGET_ERESTARTSYS; - } - } -#endif - - trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); - if(do_strace) - print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); - switch(num) { case TARGET_NR_exit: /* In old applications this may be used to implement _exit(2). @@ -12942,11 +12925,47 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, break; } fail: - if(do_strace) - print_syscall_ret(num, ret); - trace_guest_user_syscall_ret(cpu, num, ret); return ret; efault: ret = -TARGET_EFAULT; goto fail; } + +abi_long do_syscall(void *cpu_env, int num, abi_long arg1, + abi_long arg2, abi_long arg3, abi_long arg4, + abi_long arg5, abi_long arg6, abi_long arg7, + abi_long arg8) +{ + CPUState *cpu = ENV_GET_CPU(cpu_env); + abi_long ret; + +#ifdef DEBUG_ERESTARTSYS + /* Debug-only code for exercising the syscall-restart code paths + * in the per-architecture cpu main loops: restart every syscall + * the guest makes once before letting it through. + */ + { + static bool flag; + flag = !flag; + if (flag) { + return -TARGET_ERESTARTSYS; + } + } +#endif + + trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, + arg5, arg6, arg7, arg8); + + if (unlikely(do_strace)) { + print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); + ret = do_syscall1(cpu_env, num, arg1, arg2, arg3, arg4, + arg5, arg6, arg7, arg8); + print_syscall_ret(num, ret); + } else { + ret = do_syscall1(cpu_env, num, arg1, arg2, arg3, arg4, + arg5, arg6, arg7, arg8); + } + + trace_guest_user_syscall_ret(cpu, num, ret); + return ret; +}