From patchwork Tue Jun 12 00:51:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 138276 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp4703093lji; Mon, 11 Jun 2018 18:00:32 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJi5BnF08ow7zvgPNphNAd+VN/JVoQEtgdenmkz62kwCbEnBILdwcjqZ21h8rFDEMFLy/N8 X-Received: by 2002:a0c:cb13:: with SMTP id o19-v6mr1446689qvk.216.1528765231915; Mon, 11 Jun 2018 18:00:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528765231; cv=none; d=google.com; s=arc-20160816; b=I1ZCh+TDL1L5rnrzK7MGnMbOlZhCgYdeEJZijyYtxBj1GQTzS40QCAuCQLDyRSlajO vVcn2laTwsr8REcKLXJ1LpEmbYotGZeLvPdMlyLxhgF3uIsoEoNlRDfFBYoAMTAfWeIT 2ubkR4ycY9LywO+u5yGO5F5sLHzOlgVni0gZQAgv69dFf/mvvCnXOTDZS/JbtFEkaoPY OQXcguGCYXanljOLnMObraehFw9svESZArurFOZGe5vfChAI6m1SfouarFaKQWpfUlVQ L7E1gZfu8+UgUvdR+CbcrSX3QOoI6G+LW4LTjzT/LfNrazBBrUq1SO4vIImmBlKPl7t1 Bt8g== 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:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=aZhX4crw3nZleV9x/cupabZl+g+1NR+rOFu8N2TUSEM=; b=bK53LCCU69cIHOxLwZOZAUMU+2gE00fuyaGnLhAtQTEvB+1oYVE1liMWPJhT66po0a RBeQGRJ/76VwgXB5ff/FniHpudGeqgtqRwXVsVlf7oDMPl1B8rGH0JxwUc7Bx3tm6s2z DeTPkqzPt7FMGiyqUhdmBEvVbUykymb96y/iYFn1yjvSgFZPAFOQ1eWr+9GZ7uL4t+N3 AxQ3ffcTpqCgNQGXhEmuDGlu9H86nSv0lm+ch9srsABJSIH2TnwclpI0W02nx3oxNNj9 43BrYMOQ8bS3q8AmE2z1H/B1fs0b+9r4gZyFrEQsfO3Rclwj6rBZhx6fIW8UaqsFAIz9 q7ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=WuaY1eA5; 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 x21-v6si2844887qtk.211.2018.06.11.18.00.31 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 11 Jun 2018 18:00:31 -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=WuaY1eA5; 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]:52049 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSXfj-000411-B7 for patch@linaro.org; Mon, 11 Jun 2018 21:00:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59284) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSXXa-000536-Bx for qemu-devel@nongnu.org; Mon, 11 Jun 2018 20:52:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSXXZ-0007MU-7s for qemu-devel@nongnu.org; Mon, 11 Jun 2018 20:52:06 -0400 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:42759) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fSXXZ-0007LX-19 for qemu-devel@nongnu.org; Mon, 11 Jun 2018 20:52:05 -0400 Received: by mail-pg0-x243.google.com with SMTP id c10-v6so4967424pgu.9 for ; Mon, 11 Jun 2018 17:52:04 -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=aZhX4crw3nZleV9x/cupabZl+g+1NR+rOFu8N2TUSEM=; b=WuaY1eA5p7SCJu0CyH4x2Ui6+q6dv7siABPNeEPMaAB2iGN05KDDvbAQ5DcvGcwRUO Lr6a74InNmW0s2D/DyQS4lWETE338AZICm7+abfOAux9ggSjlZsGHY4+XYHcv1wrTjGf eRcrf9R46aCjt+AlAiiKNpZrOWWNjolJBMaoQ= 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; bh=aZhX4crw3nZleV9x/cupabZl+g+1NR+rOFu8N2TUSEM=; b=R7JqOMsqc3+xPUL22N0z74TPS8L5lTOXkzjpXSIp3YGw5YoVYH78c0Ebcb90uHqFfR dci1obXxiyZC2A8wByDU5RJhF2PtE+VLmkoeow1TU4L/Gg/9QKDur9gwF2wPEAv79lwr S1bZGnzhUy6x1n+9qlg/os2jEe3SVlopBBZZ+rtD7YL5Xd+nr+JkSM7RaQIuDUOX4Cif ClXj6DXZgUteM+a3ssQPmksqkN3o+0pV2YB+9Mkp8JNvJOTRTc0pBcG1I3HPpIu0FfJ8 18bHF6Zj6GbPjiqACeQkIpCMqZLM3aJuXJsOq1wbtuMamoq408L82RDbgDxxFAu6F/Qv ay5Q== X-Gm-Message-State: APt69E3eT3kCkaKuSav4V7PciqcfeuOIVK5IuR25TFKhTDCvRsGdKl/L Co42DpqW0ReRLJ0tveXYI+wquN/dQZc= X-Received: by 2002:a65:62d9:: with SMTP id m25-v6mr1156977pgv.371.1528764723714; Mon, 11 Jun 2018 17:52:03 -0700 (PDT) Received: from cloudburst.twiddle.net (rrcs-173-198-77-219.west.biz.rr.com. [173.198.77.219]) by smtp.gmail.com with ESMTPSA id l26-v6sm43362802pgn.55.2018.06.11.17.52.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Jun 2018 17:52:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 11 Jun 2018 14:51:32 -1000 Message-Id: <20180612005145.3375-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180612005145.3375-1-richard.henderson@linaro.org> References: <20180612005145.3375-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::243 Subject: [Qemu-devel] [PATCH v3 06/19] 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: peter.maydell@linaro.org, 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: Laurent Vivier Signed-off-by: Richard Henderson --- linux-user/syscall.c | 77 +++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 29 deletions(-) -- 2.17.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/linux-user/syscall.c b/linux-user/syscall.c index c212149245..ec3bc1cbe5 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7947,13 +7947,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; @@ -7961,25 +7963,6 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, struct statfs stfs; 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). @@ -12765,11 +12748,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; +}