From patchwork Sat Aug 18 19:01:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 144502 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2204565ljj; Sat, 18 Aug 2018 12:07:52 -0700 (PDT) X-Google-Smtp-Source: AA+uWPx9D7dnhuY8quvXk0FHSPeYvMldAtBSlu1WLxo6I4CLBuMadiLSjahpcz/Hb5LkcZfZN7xk X-Received: by 2002:ae9:f449:: with SMTP id z9-v6mr37536852qkl.410.1534619272440; Sat, 18 Aug 2018 12:07:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534619272; cv=none; d=google.com; s=arc-20160816; b=thchLMnGJd7mIbskt/yEA9gPOav0iwNegBmc0eOEosjqEWuc0WFWBk0RIpCgjFuSno 4IJLWM9qhCmGcvcugqtw1fPrFCxDeEu4jLIfTEHhz4Cl9KeLmQVw9f/o0NnDCCFjMsc9 L0sMkQ2dOtCdjftqdtjUJOrwb2VEDre7X6XFhF9DTsxbovup8nNd0MalGjuLLiUPYEsr pzhlLnLJNX8GV/B/LT4HtX26AOkdnubmIjq0CstqFIjRg9KlxQNO4x4UT1fLReE+ELHj wtWZpGgOV5NYjsPWCNzHXUWXe0i4h1mkSjOI6I0/3o38sOsewu7JBIqh9jLDvvpBO0Ir bPJQ== 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:dkim-signature:arc-authentication-results; bh=4xBjw1bDXVECuMm9Kv+AFqaT2umgQswrrWiIl/+1TKs=; b=mwZddCqWFxnFqeTNFquU4epvFZD/oNeAmRcc8gmiZ2PtWybL8AKR8EPpWAp9JpKsgV 3kRreFlDZ5znBvd1VhWY35manPfsEZj6H/hJK/de9+kyMKNryP977Ne8b6QsHR6MJtfn eFcAPPvol//gPC3mc1RiZrxYNNIvsyugcN5eRpdZGi0gWI02zGua5UrNNBRUEf4U5XN4 jZmRZulFmN4umALpAJ1pevyPq8Ti50XnOLqxVu5lSWpADjbtxr7r5wxajV9gEAscYRAx biUyZbRGQHUBiXHtT0v4gNRcdxXEumhVMyQsTsZkxtDNeRBC1qzYY+JVwcvQEV+/cw7/ Cj/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=d01+zLls; 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"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id k5-v6si4782654qkb.28.2018.08.18.12.07.52 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 18 Aug 2018 12:07:52 -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; dkim=fail header.i=@linaro.org header.s=google header.b=d01+zLls; 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"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:40142 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fr6Zj-0000u9-QA for patch@linaro.org; Sat, 18 Aug 2018 15:07:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fr6TY-0005Eo-FU for qemu-devel@nongnu.org; Sat, 18 Aug 2018 15:01:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fr6TV-00076A-OZ for qemu-devel@nongnu.org; Sat, 18 Aug 2018 15:01:28 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:39449) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fr6TV-00075c-JQ for qemu-devel@nongnu.org; Sat, 18 Aug 2018 15:01:25 -0400 Received: by mail-pf1-x444.google.com with SMTP id j8-v6so4888867pff.6 for ; Sat, 18 Aug 2018 12:01:25 -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 :mime-version:content-transfer-encoding; bh=4xBjw1bDXVECuMm9Kv+AFqaT2umgQswrrWiIl/+1TKs=; b=d01+zLlsWAWgwsQuahT/nEKMBvdAp1kxj/LhY39WGfddQ3ExCZiegTKDPmyJ+GYQa/ Bki+21xX+baNy47J0wn4aJGAUgn66R7lVIQWFPAzjQ2guhxjvgZ+R20EFYbjFMAJ/vyl VZx9rgjTathBb3l7wCOQ1XeE4vQxUiJD+XGBU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4xBjw1bDXVECuMm9Kv+AFqaT2umgQswrrWiIl/+1TKs=; b=FSSHvbgsLshKb+F/zDtutc0XXODiYsLcAIg8XGrI6IQbtHaEm1zpwugOp5D4E47m0D b6TR/lKAc/IYkkCgusMQ6HboFuMm14ntFR13Pj1EzI/0kVWqx6ikzckRlDI7eTgQ4kOg kQQtFfChLblfDwyZnuEqIAwp7b6hWkjN4CMQ6MCxvB5fuo65snpak4dwqEfizhFrO9zr Pja151fS1xa9Is3m7VhBQqAF5l7rsm7sElEYXtXMxc8PTyEmiFe3LSIEJneVtTj2C6ez busGqDwCGyNQVTmMyjV/Mv+pEJ9WozQQdOIjmgINrNbjsm5YQohpk4lYoJ5bkh8bDCDA O9dg== X-Gm-Message-State: AOUpUlG/deYQXNEZdF5KWf0T0vhUKwCgvDx/Ws7ay4FKHJ9dua7U43Kw o05Aw/uNb/bWqyNUXDJq29EIJK2XJKA= X-Received: by 2002:a63:931c:: with SMTP id b28-v6mr2346884pge.81.1534618883191; Sat, 18 Aug 2018 12:01:23 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-8-179.tukw.qwest.net. [97.113.8.179]) by smtp.gmail.com with ESMTPSA id q85-v6sm9362783pfa.151.2018.08.18.12.01.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 12:01:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 18 Aug 2018 12:01:04 -0700 Message-Id: <20180818190118.12911-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180818190118.12911-1-richard.henderson@linaro.org> References: <20180818190118.12911-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::444 Subject: [Qemu-devel] [PATCH v4 02/16] 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: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- 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 6cd9b33a0d..dddd386ec4 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7986,13 +7986,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; @@ -8007,25 +8009,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). @@ -12836,11 +12819,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; +}