From patchwork Fri Jun 1 07:30:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 137464 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp605986lji; Fri, 1 Jun 2018 00:34:48 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLZTFh8s8kbVwgplxHMiksuR4VeSHNnSSp/1fVmkejq8D5wP5zkQ3YzyxLlMq+QcnlE4C2V X-Received: by 2002:aed:39e6:: with SMTP id m93-v6mr9266093qte.328.1527838488289; Fri, 01 Jun 2018 00:34:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527838488; cv=none; d=google.com; s=arc-20160816; b=K0ZoFCFp4YfQTBRUnufPkbhXSKl3DwI2C+flsK7DvJVBxhQNTK1Crs3jMO0UGbiwML am28sdzJOjW97AHxLulkzdRW9sQnaeaNEiMvkzxjjiiqTGh0jFe1MME6zX/J4HyMuIHW Ado45SMPXG6utGpqt0o//ZBcmpiiWTj/OUSiBEZqxePUzIr9hv63ZHvNjHW6csspjLbg S8AYb/Z3NE/We8/27yhF+cg6VcEKIU+0Ecxt+X3ygowMLQJwgmRS2fMqnVrtxysDpRXh YaxjyKIQ1xffTqUN3m0nHYJvqN/pAqX70yqGR4rIoVnWqhaHMXuYD1ycK1B1wHUkA5nA Hs2w== 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=jiV3ryV7bNwrqAaXgi+PnuEbFIblWYhP1BSR8J6DhRw=; b=or8M0X46Q5uiMLw7kjFRkO8CRBdGdttplL/tCU+LcER+yEm5QKTByn8SuLU1MRbfZP TaELSqPknC6PZF/PckUyaP9Sk4rb2HQPa1W1+cNhVxNQV529ULCK24qcH+HTLk7tYwGn F24+qa99qDFjPPp3mkcZwNxhKhPb6lhEYGDjnaz+GR35GEjENk9A0wQC218yZOWAHVUV K61wugOcz0gJ1ox+qISxCnkALZyFq+o3WVsMsQL2xH0Ql1E5PUY3Egrhd/FP4wXcBW66 2/+k1K4PRhzQ/oJmBqO9s/DCB/jJ/Y7xagY9brGbJxpN+RV9vuW2oYuAzsTvG3hLehSL UMZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=TVzZ+bqT; 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-v6si9229078qvb.37.2018.06.01.00.34.48 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 01 Jun 2018 00:34:48 -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=TVzZ+bqT; 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]:47820 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOeaF-0007jO-LN for patch@linaro.org; Fri, 01 Jun 2018 03:34:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57244) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOeWY-0005N0-LX for qemu-devel@nongnu.org; Fri, 01 Jun 2018 03:31:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fOeWV-0000AK-VC for qemu-devel@nongnu.org; Fri, 01 Jun 2018 03:30:58 -0400 Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]:39304) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fOeWV-00009i-PN for qemu-devel@nongnu.org; Fri, 01 Jun 2018 03:30:55 -0400 Received: by mail-pl0-x243.google.com with SMTP id f1-v6so14382499plt.6 for ; Fri, 01 Jun 2018 00:30:55 -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=jiV3ryV7bNwrqAaXgi+PnuEbFIblWYhP1BSR8J6DhRw=; b=TVzZ+bqTpo9gtK+zwDHgfVCX3V1FOYAaovv9i4KT7/YCyULiaS8MBMxFywRhi2dAaV izfWVZa+4MiIiVl8RMTPQlsjLWOpqLsP9snQFuRog4oxWjQIlOatDbUj2REVFYYbmlbm WzDKRVuHbC/oM9bJQBKQ9UtjhpmN9C/paamHo= 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=jiV3ryV7bNwrqAaXgi+PnuEbFIblWYhP1BSR8J6DhRw=; b=WriKzvkffXN9ezzM9rWQrZ+iRGptJI2kRVxqGRW2QYqULFE0AbSRkZnmT3JE3LsT7c ceX7hPWaaiZYoXttIi0scC10R1T8t5aahr6C7pu8in+blz4m1NxBIo/17qbGBP+jLYnY zNebCfqAh7vxfSWNIYfQ8lyBZ7DxUU2JXkGBkSPMYyQmNxMKCzzCHe+RIp0WijYnCpFP 99H05sn3N1LD/hdZ6/WBy3Duo3CZL4QBVDn0sqIYA2fV5FyTbTM5uc3Gpp8Rym3xVRNC Bl119Y7Hew7ga3QCdT+SlZOhIhIBP8o2BScRas4t1O5tFkgK79W07SPZLJa7+ZZ3PPFK 8Xew== X-Gm-Message-State: ALKqPwe5EOon9MjBZGbP28kOJgcUkKKpJN/6at1rGjGtNyorFm1vaOWR EjGUzRjk6SNAHbr0A55ztWm8TBTEuWM= X-Received: by 2002:a17:902:4301:: with SMTP id i1-v6mr10106217pld.280.1527838254504; Fri, 01 Jun 2018 00:30:54 -0700 (PDT) Received: from cloudburst.twiddle.net (97-126-112-211.tukw.qwest.net. [97.126.112.211]) by smtp.gmail.com with ESMTPSA id c4-v6sm4431782pgv.86.2018.06.01.00.30.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Jun 2018 00:30:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 1 Jun 2018 00:30:18 -0700 Message-Id: <20180601073050.8054-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180601073050.8054-1-richard.henderson@linaro.org> References: <20180601073050.8054-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:c01::243 Subject: [Qemu-devel] [PATCH 01/33] 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. Signed-off-by: Richard Henderson --- linux-user/syscall.c | 89 +++++++++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 35 deletions(-) -- 2.17.0 Reviewed-by: Laurent Vivier diff --git a/linux-user/syscall.c b/linux-user/syscall.c index b75dd9a5bc..ebaefebcc2 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7962,13 +7962,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; @@ -7977,28 +7979,6 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, void *p; char *fn; -#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 - -#ifdef DEBUG - gemu_log("syscall %d", num); -#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). @@ -13101,12 +13081,6 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, break; } fail: -#ifdef DEBUG - gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret); -#endif - if(do_strace) - print_syscall_ret(num, ret); - trace_guest_user_syscall_ret(cpu, num, ret); return ret; efault: ret = -TARGET_EFAULT; @@ -13115,3 +13089,48 @@ ebadf: ret = -TARGET_EBADF; 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; + +#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 bool flag; + flag = !flag; + if (flag) { + return -TARGET_ERESTARTSYS; + } + } +#endif +#ifdef DEBUG + gemu_log("syscall %d", num); +#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); + } + +#ifdef DEBUG + gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret); +#endif + trace_guest_user_syscall_ret(cpu, num, ret); + return ret; +}