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: 144789 Delivered-To: patch@linaro.org Received: by 2002:a2e:164a:0:0:0:0:0 with SMTP id 10-v6csp170824ljw; Tue, 21 Aug 2018 18:15:13 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxcr5wB7X/ouD4lalH/3szM7MYLaicOv43xYfyelf5UhitNH6UDSn0fdBeaC/1em5HQyg1Y X-Received: by 2002:a37:5805:: with SMTP id m5-v6mr23178542qkb.346.1534900513002; Tue, 21 Aug 2018 18:15:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534900512; cv=none; d=google.com; s=arc-20160816; b=LOKZ+1eXe/3S2fBYmSA0TlHOAKEFbVfwAMEJsXGwES0aGG7ZCtBWBIyF8oCK4jueZl Cix3ixGEvLXIhFfZUV4mn12/hwMHmGq/sodwBgMZE4urPwrbSJF4EXC0lzM9LsTakTzD qAQTcKAWrv+7zCQkbgsqOm3yJND87kVvG4lHP27AtW6CPPHHe0yTbCCy8og9SxiXlypM +EjDluK98bUkPAjyTsRgXvKDWqJ46cS5TIHuKrx+IpH6U5YhQ+w5ufQv/ykCD3PaRQR+ dyztPq95bc/PfYEw7cB1m8RPQJPMLCKMpBKZ/5k1kThXNewATXI+pvDxhR/Jw6MAh1EP 0TMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:arc-authentication-results; bh=Op3KsnWdustxUPK9tdGbgdtXQBVSwmbPwKK8aF5qiMk=; b=DhgfzKX/Uqi+scNAyk5C92wiDv2+wlpwBoxjaAXpd7TpQg3aroRSNBylxqGWn/IGje Wyu+5JgILLenhBkXCkV6UVBSAwXMnMNvarnVtLjbGtzX3NyqxW9CjOWwx+LNMR06any3 oG8MRnTgW+yHhXVGvmFyOJNwqaIV1O7WB84r23sX6SxpLweJIKIhD/+vbPlCQ9ZuzWGx F24u/4E0fq+ScEovEBcGTscMSZJm0L9hksv/GaEOu3tTEKvh65lMZ+K64/ltk2UGpcw5 5sMBwByas8m3Qais/NhCjo89jUrNFUJz2iZZYnERjYrKduUiCIvG2OWYGAq6x2Tm9THM 4DvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id r33-v6si311693qtc.108.2018.08.21.18.15.12 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 21 Aug 2018 18:15:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:56411 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fsHjo-00068b-2P for patch@linaro.org; Tue, 21 Aug 2018 21:15:08 -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+patch=linaro.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(-) -- 2.17.1 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; +}