From patchwork Fri Jan 18 21:30:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 156058 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3733305jaa; Fri, 18 Jan 2019 13:40:18 -0800 (PST) X-Google-Smtp-Source: ALg8bN6eKM4HaSSBxkrVhGJC+tKbRXMzJuOx5r2f3B8pqUAFkscaiM11FFPCaNOhVXAWcO72IG+V X-Received: by 2002:adf:cc91:: with SMTP id p17mr18514991wrj.118.1547847618296; Fri, 18 Jan 2019 13:40:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547847618; cv=none; d=google.com; s=arc-20160816; b=TIqbLy0Z2cQFcemmvxc//lq26AfX4HSbDOYIwayJBrDCu38js5b8L9yXi/I0Bv18mB KOV/+UNWph9W+AVOg+C3RurBuD+Ecj4E2WhipJkeEX3A2cv4G3TrpCgsZzc48ftaA2ax 8InIu96BspdsV+wl6Cnfqfli7isd2TkHZmSjdq0sUTmxJKZzGBCyJUiZfCS8hf5aoq8f 5CAZyzXZTVZqyB4BXPhZteGZdQVlFZ/wzeVvY08bW1QdqqOSOjTcx/LdUwGzoZqExQif H4wtOk9rukRIe1h1S/sGnpKZnh1XTGeEQzRfva4vQFF8fVnI+0KIvxMVVxTGQlDY2K53 yv8Q== 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=0lX6Kpl2HawVr6cLh0Iq6aWEA9i6Vz7GS35r+BCsPqA=; b=Uot/RTGIKHscRrQqtJsPcReZuDL0BiMsXvBvCYi99U+IEdzL/BHzyq5rpUzJCzeMh2 c02RMEe0rtCX60Sr0zcBuYY+odIDWar8wQuGSQDOqYOYlYYFMmYaWbt/vGRuCDERE8FD yGk1I7I/Krall71inkxWSUG0U17OtVwbYxyi5rejPXva+z/RUXNUp4/x3YPK38Lnrggx p829s1S1pdMQdx3mWJvKzVM99xlL+N3aDAKhI/E4wsjDo/fdoElcctAvvQ5J3fytEPjg g7Hh7lRXJEE9Hp+wDMISPBbLRfdrSIh46dVzCLzR7nEDKUen60RKJXfNK5B5zmyO6j8X 0Lhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="dvusg2G/"; 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 u14si65217838wrg.415.2019.01.18.13.40.18 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 18 Jan 2019 13:40:18 -0800 (PST) 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="dvusg2G/"; 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]:47486 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkbs9-0003AU-4B for patch@linaro.org; Fri, 18 Jan 2019 16:40:17 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55785) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkbjx-0004jZ-94 for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:31:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkbjv-00041s-KK for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:31:49 -0500 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:42254) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gkbjv-00040B-Bw for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:31:47 -0500 Received: by mail-pf1-x441.google.com with SMTP id 64so7190254pfr.9 for ; Fri, 18 Jan 2019 13:31:47 -0800 (PST) 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=0lX6Kpl2HawVr6cLh0Iq6aWEA9i6Vz7GS35r+BCsPqA=; b=dvusg2G/XZcvWCeD7Jqt91BywW5n9mSymk7a59NDxEz9S7dh/rvveC/7psHtZsx2BU otbW7wzkj85UhuIjhCSS9OQ99AxXvnZuVl3hR6NSe+/qUIfFwndrc/b6l9AgHI6Sfwe0 gRQQ6KMd5Tbx1meCbE7g8x30sdqlh8s9AvEC0= 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=0lX6Kpl2HawVr6cLh0Iq6aWEA9i6Vz7GS35r+BCsPqA=; b=lcEez8qjSIRnuv4xY3L1w5/B7EvfxMkaYyBaJqXASQ46zWFWmRNd8CVFLBIYWR4/tV VHkZs9DUI5vXoBiw7vUUVFqOriMd8AKNTWRhjsMP4Wj/EHq80fQ3VzJlIkZmT+6oO29G 4cRxsZe5F0rZb4UzZZ3GFNvHl4P5bt6bVGzBlAmPUM1UU+qAaC8igTSfBraConfqoV8m BllUnNbLqczGXeC0iwbZw5f5FMGVyQkRdSbggUe/HdtBiG7p+n5giO0oOQ+2dkml/S3I WVLhSHNifLa9QgrRr6C4Gw+xTnvwdtjHZ9Ws9FnI0PaC09twE+4b3McIuNUAN7DP1Ii1 QWgQ== X-Gm-Message-State: AJcUukfnFUvV3C5q8orHsgAz3wcoWyQzJiNDqck6k61mhDRBLeSU0h4a 7lEx6rGAkcMdlSozx0ObPuorM7pTi2c= X-Received: by 2002:a65:50c1:: with SMTP id s1mr18915296pgp.350.1547847105984; Fri, 18 Jan 2019 13:31:45 -0800 (PST) Received: from cloudburst.twiddle.net ([2001:8000:10e0:a000:c673:a6b6:fdef:1933]) by smtp.gmail.com with ESMTPSA id v12sm5833667pgg.41.2019.01.18.13.31.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jan 2019 13:31:45 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 19 Jan 2019 08:30:41 +1100 Message-Id: <20190118213122.22865-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190118213122.22865-1-richard.henderson@linaro.org> References: <20190118213122.22865-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::441 Subject: [Qemu-devel] [PATCH v6 08/49] 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.2 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 feb83c4e87..9c8025b252 100644 --- a/linux-user/syscall-file.inc.c +++ b/linux-user/syscall-file.inc.c @@ -317,6 +317,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 (size == 0) { + return 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) { @@ -361,3 +387,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, 0, 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 f230fe161e..d4d5c25803 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6726,40 +6726,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 (arg3 == 0) { - return 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 71a18123bf..f3a1b0fe31 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