From patchwork Sun May 19 20:36:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164501 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp4784027ili; Sun, 19 May 2019 13:47:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqwYB9kX9kA6A0VN7NQgFoAbIK4sctmYAyU/TxZeVcTqIDrFAztoD4bDftS+SEPYVkg7ICdJ X-Received: by 2002:a50:a5ed:: with SMTP id b42mr69913519edc.178.1558298865727; Sun, 19 May 2019 13:47:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558298865; cv=none; d=google.com; s=arc-20160816; b=Uv025Ew+GRxOUejnYYIR1CDw9BQ88Negda1t9eNwaQ28o48RO7liAcr2VNh1FAaFwX 65pk9LKb0ncLAycczMRRdBLuxOfHQyoa3fgRRPtHYIREj9koKi9OOBT8RQ7uCDV1tcOU fm08tLKWI0q7QlIQvA3I2dOJHL1e/+Tbe01QfdejYDpVFZkbIeFsRtpIqhfxSK+AHgqf kvyGalFX6WC7iVb0BlGO2cNAiroW5Oy9kYqFPJnKEfMz0b5akEQFPd4FFkP0Ti4mY4mB 9VNso04c45qY8QR8RJMWh/5FLkVLcyytlCGtcTxaPee4464PuEngJDg5P0WksU5bW2Qn 895Q== 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; bh=v+DSPWFfKETKW6djLG4dV30pA06tpKN/mDvUPl9xg1M=; b=wvyHMtZPOBTM+k4WEAFctiTvXL3aDfUUKNEfjYrS3jGfOIYPKLPMzG6vd9pjt2TSpF wz7q88jw5yt7hNmA9zYckj/Dp5PztPUV+VVRc4z5MnfUEoR9YvXM4EtVdy5PO5Hlqop5 qShBCR1McOkp32BQyaC4hiw41cnwEHLL8XSzV/DG2ArsNrwmP8xY6Pv/AWv+hkLHooWo o/nbTOS2bBZZEFTsNjMzUapHluxPGFRDMB3/kmawQIxEil+fLjI446tqp834Wkmi0RnA tF/BqQagh9KKShSui6JdDSPEnA/UZTh5bRpav5EDYMewrrqUlHcWsnwiVDY1DbZe5Kcm 8YzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=kul8EKJ+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 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. [209.51.188.17]) by mx.google.com with ESMTPS id z40si243913edc.400.2019.05.19.13.47.45 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 19 May 2019 13:47:45 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=kul8EKJ+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 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 ([127.0.0.1]:53252 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSSie-0003IH-KG for patch@linaro.org; Sun, 19 May 2019 16:47:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50159) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSSYw-0002nl-Ci for qemu-devel@nongnu.org; Sun, 19 May 2019 16:37:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hSSYv-0003Wm-4f for qemu-devel@nongnu.org; Sun, 19 May 2019 16:37:42 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:32972) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hSSYu-0003Vo-Ug for qemu-devel@nongnu.org; Sun, 19 May 2019 16:37:41 -0400 Received: by mail-pg1-x544.google.com with SMTP id h17so5751680pgv.0 for ; Sun, 19 May 2019 13:37:40 -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=v+DSPWFfKETKW6djLG4dV30pA06tpKN/mDvUPl9xg1M=; b=kul8EKJ+Q4XjOZ96gaPQl3ei1QXKW4h4xkEUQ6XK080ElloUc1iEFs6lO9vKbFR9XY 7yItQEu89XB+RVe1GfGBGgx8UCwOw02bedJvIQWxH5IgnRZYvAtsHdVdQ72LooB5RrBc hh4wqx6aRaaoEQtdJCY+ikK8aMH5LKP1PQT764rE9KUxkk+wpvSH4xFwHJhbu67LKWLg 9Q3APNNKUkiDWwaW65EAa+QJ2sHwD/LK4UQM+yZwYBdQwTLZ8Hnx+sHu0YxXID+X6OQH F+i5qwjcdFRP6k+iuxxvvRgKUqWDUtbWSZEew2Zkk/rG2WpvE3jgcLSrqhGTgmHcQclh ORBQ== 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=v+DSPWFfKETKW6djLG4dV30pA06tpKN/mDvUPl9xg1M=; b=lDEuC6ATvINchhGeLD35ckGs9uuZ4F1GQYQ5D/RTIe0mS1Fr79kXalqn8ujlh4rpps SlV/DsQ92iqMNskQoxeXGOfcW56HYbdEicnzViPOls3+uQkobveNWmUmu8fu6gOId0vA GZotglboVrWPWCswmOQ3IWIyPYzNnAhgdB7f2k6ovmOrxn12OmvQOTTJyGu+mTipVV1N u79UNwndAReKCnZLPhvT1beWic389wXxVGO0Mp87IENXxykkQ/41wFKI7JnB2syQgPQL 9fD3zIidm0nEhNC5cKzL2XXCIdfdPtk/q02M+iffRyjHDJv071kI5TiLzLSjhrD2muwh vPIQ== X-Gm-Message-State: APjAAAWNBb9ya+pw8T4zCcqBQWU6Iyc7FNhRSxrccB/hfSEVP8Fp8NBM ga5fnCWaYANDRUZ2hDpeib6jUVuk1UQ= X-Received: by 2002:a65:64da:: with SMTP id t26mr71680641pgv.322.1558298259460; Sun, 19 May 2019 13:37:39 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id i7sm11397448pfo.19.2019.05.19.13.37.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 May 2019 13:37:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sun, 19 May 2019 13:36:19 -0700 Message-Id: <20190519203726.20729-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190519203726.20729-1-richard.henderson@linaro.org> References: <20190519203726.20729-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::544 Subject: [Qemu-devel] [PATCH v7 07/74] linux-user: Split out read, write 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" Signed-off-by: Richard Henderson --- linux-user/syscall-defs.h | 2 ++ linux-user/syscall-file.inc.c | 58 +++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 34 -------------------- linux-user/strace.list | 6 ---- 4 files changed, 60 insertions(+), 40 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h index 797426ae6f..b031de1375 100644 --- a/linux-user/syscall-defs.h +++ b/linux-user/syscall-defs.h @@ -21,9 +21,11 @@ SYSCALL_DEF(close, ARG_DEC); SYSCALL_DEF(open, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG); #endif SYSCALL_DEF(openat, ARG_ATDIRFD, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG); +SYSCALL_DEF(read, ARG_DEC, ARG_PTR, ARG_DEC); #ifdef TARGET_NR_readlink SYSCALL_DEF(readlink, ARG_STR, ARG_PTR, ARG_DEC); #endif #ifdef TARGET_NR_readlinkat SYSCALL_DEF(readlinkat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_DEC); #endif +SYSCALL_DEF(write, ARG_DEC, ARG_PTR, ARG_DEC); diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c index d9b09c2cd2..e6adcc351c 100644 --- a/linux-user/syscall-file.inc.c +++ b/linux-user/syscall-file.inc.c @@ -323,6 +323,32 @@ SYSCALL_IMPL(openat) return do_openat(cpu_env, arg1, arg2, arg3, arg4); } +SYSCALL_IMPL(read) +{ + int fd = arg1; + abi_ulong target_p = arg2; + abi_ulong size = arg3; + void *p; + abi_long ret; + + if (target_p == 0 && size == 0) { + return get_errno(safe_read(fd, NULL, 0)); + } + p = lock_user(VERIFY_WRITE, target_p, size, 0); + if (p == NULL) { + return -TARGET_EFAULT; + } + ret = get_errno(safe_read(fd, p, size)); + if (!is_error(ret)) { + TargetFdDataFunc trans = fd_trans_host_to_target_data(fd); + if (trans) { + ret = trans(p, ret); + } + } + unlock_user(p, target_p, ret); + return ret; +} + static abi_long do_readlinkat(int dirfd, abi_ulong target_path, abi_ulong target_buf, abi_ulong bufsiz) { @@ -367,3 +393,35 @@ SYSCALL_IMPL(readlinkat) return do_readlinkat(arg1, arg2, arg3, arg4); } #endif + +SYSCALL_IMPL(write) +{ + int fd = arg1; + abi_ulong target_p = arg2; + abi_ulong size = arg3; + TargetFdDataFunc trans; + abi_long ret; + void *p; + + if (target_p == 0 && size == 0) { + return get_errno(safe_write(fd, NULL, 0)); + } + p = lock_user(VERIFY_READ, target_p, size, 1); + if (p == NULL) { + return -TARGET_EFAULT; + } + trans = fd_trans_target_to_host_data(fd); + if (trans) { + void *copy = g_malloc(size); + memcpy(copy, p, size); + ret = trans(copy, size); + if (ret >= 0) { + ret = get_errno(safe_write(fd, copy, ret)); + } + g_free(copy); + } else { + ret = get_errno(safe_write(fd, p, size)); + } + unlock_user(p, target_p, 0); + return ret; +} diff --git a/linux-user/syscall.c b/linux-user/syscall.c index d2b1bb76c4..de80ddb330 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6782,40 +6782,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, preexit_cleanup(cpu_env, arg1); _exit(arg1); return 0; /* avoid warning */ - case TARGET_NR_read: - if (arg2 == 0 && arg3 == 0) { - return get_errno(safe_read(arg1, 0, 0)); - } else { - if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) - return -TARGET_EFAULT; - ret = get_errno(safe_read(arg1, p, arg3)); - if (ret >= 0 && - fd_trans_host_to_target_data(arg1)) { - ret = fd_trans_host_to_target_data(arg1)(p, ret); - } - unlock_user(p, arg2, ret); - } - return ret; - case TARGET_NR_write: - if (arg2 == 0 && arg3 == 0) { - return get_errno(safe_write(arg1, 0, 0)); - } - if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) - return -TARGET_EFAULT; - if (fd_trans_target_to_host_data(arg1)) { - void *copy = g_malloc(arg3); - memcpy(copy, p, arg3); - ret = fd_trans_target_to_host_data(arg1)(copy, arg3); - if (ret >= 0) { - ret = get_errno(safe_write(arg1, copy, ret)); - } - g_free(copy); - } else { - ret = get_errno(safe_write(arg1, p, arg3)); - } - unlock_user(p, arg2, 0); - return ret; - #if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE) case TARGET_NR_name_to_handle_at: ret = do_name_to_handle_at(arg1, arg2, arg3, arg4, arg5); diff --git a/linux-user/strace.list b/linux-user/strace.list index 43d3088669..2d6bfec692 100644 --- a/linux-user/strace.list +++ b/linux-user/strace.list @@ -1067,9 +1067,6 @@ #ifdef TARGET_NR_quotactl { TARGET_NR_quotactl, "quotactl" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_read -{ TARGET_NR_read, "read" , "%s(%d,%#x,%d)", NULL, NULL }, -#endif #ifdef TARGET_NR_readahead { TARGET_NR_readahead, "readahead" , NULL, NULL, NULL }, #endif @@ -1611,9 +1608,6 @@ #ifdef TARGET_NR_waitpid { TARGET_NR_waitpid, "waitpid" , "%s(%d,%p,%#x)", NULL, NULL }, #endif -#ifdef TARGET_NR_write -{ TARGET_NR_write, "write" , "%s(%d,%#x,%d)", NULL, NULL }, -#endif #ifdef TARGET_NR_writev { TARGET_NR_writev, "writev" , "%s(%d,%p,%#x)", NULL, NULL }, #endif