From patchwork Sun Jun 10 03:01:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 138126 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2594518lji; Sat, 9 Jun 2018 20:40:20 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK58Z8xFPKYdumOBGDKUw592aVvFj0ahkF/38AvI/AmghwZDmBnx2YKQI4dF0nZF/aPJh4W X-Received: by 2002:a37:2648:: with SMTP id y69-v6mr10600934qkg.258.1528602020317; Sat, 09 Jun 2018 20:40:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528602020; cv=none; d=google.com; s=arc-20160816; b=cIW/tVbF3d67i76xplBUWsYNP68p/pMjvhPJzKAFXMiH0bFm1TbKcAlocbdRm9r9aq OmHBEjeXWcYw6PLs8o7wJf6HNTsif4OgNwUjdK2NnLnhvLVDKkfumOICnioow/W5ZSjx 4Eey1UEEm4q7JsXJ6GQgoUmI1ZWsOpJ2mtAp/hh+6EhzHmujH47yZOp9xrKnKidTgVHx Pv81IB8UPehYocR3E3zA/XKDclFPFRXDc/f1n3/RbhmmDA7iiZ9ZSiAv0ogJtCNnNyKy qP4UAnIOfxeHv9G+NDNF3zrTTqGBs1cTmbt02NSUb1PMWo2vXe/DGZLYTQoyrenG+ZhC YgHg== 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=ySbzxelQtsO4OgTE8VIJgIVKguLD8H7LWHuTCeWLlCc=; b=1Jyt3Cbb7WAc6n1S0TIBney0Akc2wFC5KHv25sqk64CGi49poHr4559zAiJNTuWszW hDR2bc6JqsBF6VQ46bfxEqr2M/nhW51VK82F+QwgRQiHoLHJP21e9gOWXWnValJ3Sog+ sdNNdYH+tV/w6Zi31zkLI++DgO7eQ88Xaeq62iqCNlTjvUCHFaHvwvOwP98dbxcIATD0 sAgo869JmLGQEhJ15hTPj9yNXcH8jTd7+Rmc9f4r0pUh0mwcD1fUBH0+fUqUuZNGwjsE PgxF9rkbyKT0zUvTGl+Tl1YHA1rBoDqyp9du73JqxXYSS6kl7IsVZIZh0Ut/NSQxNn6h fJhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=IBpCrmrH; 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 w1-v6si9567861qtg.224.2018.06.09.20.40.20 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 09 Jun 2018 20:40:20 -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=IBpCrmrH; 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]:42382 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRrDH-00029b-Pa for patch@linaro.org; Sat, 09 Jun 2018 23:40:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40799) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqeT-0003Av-DW for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:04:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRqeQ-0003kI-4u for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:04:21 -0400 Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]:41585) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRqeP-0003jz-Sw for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:04:18 -0400 Received: by mail-pl0-x243.google.com with SMTP id az12-v6so10380339plb.8 for ; Sat, 09 Jun 2018 20:04:17 -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=ySbzxelQtsO4OgTE8VIJgIVKguLD8H7LWHuTCeWLlCc=; b=IBpCrmrHwiIO26Q7MShK7g4YRmDlI3ofRxEZOmov7MkrVvBRKjl9TFUKKgugL6sn3W cjP+xAx5te4vzYoTIUDe3GTbChsEfafCt7/5wwedd0XARtUNo/z3bahJYWj+9jLA0vJk fLUsFD7a9hPwv9ucQ2YmME6E85eP4nqlBtwh8= 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=ySbzxelQtsO4OgTE8VIJgIVKguLD8H7LWHuTCeWLlCc=; b=arVWMLFfeYUsPjVPpbDzD46N52sIA7N7yigBlRcYam+I1/yv+5sVCU+8U3ks83pAVk RiOfCrSQObQy4bYQQ43g5fq+4gcCTmG/QCYv9iQRc/iSLPFHBcq4WL6GI7GgPfkGpQ+a +dmOONOqVjYBKkhIpIQBXcfhGg5FNUXh4LmIob3sdAknsLQA5a0vSv2ec+RhfhNnmdov A60Nyl+wP5fwEsPkgzOgS+97UCMTsj9u44pE7uf8NVgN8Uhd+n9miaKwbN3yLVQSMuQd mCaBs+qDuKw4BTj3prOJFLuu2DdC4Ad/taH08XH5F5W686k4jtgtTaOgtHfnrVB2K89d ZzFg== X-Gm-Message-State: APt69E1boSiqT/akXmZwSk2w4AnlJkClsWyjVdAm4TQtnlHtskH3oBrD GiAD6ksTWdXprJVZTe+7Ev22jQP70Qc= X-Received: by 2002:a17:902:784d:: with SMTP id e13-v6mr12976706pln.197.1528599856717; Sat, 09 Jun 2018 20:04:16 -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 y17-v6sm31712718pfe.33.2018.06.09.20.04.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Jun 2018 20:04:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 9 Jun 2018 17:01:23 -1000 Message-Id: <20180610030220.3777-52-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180610030220.3777-1-richard.henderson@linaro.org> References: <20180610030220.3777-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 v2 051/108] linux-user: Split out fstat, lstat, stat 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.c | 129 +++++++++++++++++++++++++++---------------- 1 file changed, 82 insertions(+), 47 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index c8fc7fc908..4f6c01092b 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7052,6 +7052,31 @@ static inline abi_long target_to_host_sigevent(struct sigevent *host_sevp, return 0; } +static abi_long host_to_target_stat(abi_ulong target_addr, struct stat *st) +{ + struct target_stat *target_st; + + if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) { + return -TARGET_EFAULT; + } + memset(target_st, 0, sizeof(*target_st)); + __put_user(st->st_dev, &target_st->st_dev); + __put_user(st->st_ino, &target_st->st_ino); + __put_user(st->st_mode, &target_st->st_mode); + __put_user(st->st_uid, &target_st->st_uid); + __put_user(st->st_gid, &target_st->st_gid); + __put_user(st->st_nlink, &target_st->st_nlink); + __put_user(st->st_rdev, &target_st->st_rdev); + __put_user(st->st_size, &target_st->st_size); + __put_user(st->st_blksize, &target_st->st_blksize); + __put_user(st->st_blocks, &target_st->st_blocks); + __put_user(st->st_atime, &target_st->target_st_atime); + __put_user(st->st_mtime, &target_st->target_st_mtime); + __put_user(st->st_ctime, &target_st->target_st_ctime); + unlock_user_struct(target_st, target_addr, 1); + return 0; +} + static inline abi_long host_to_target_stat64(void *cpu_env, abi_ulong target_addr, struct stat *host_st) @@ -8100,6 +8125,18 @@ IMPL(fork) } #endif +IMPL(fstat) +{ + struct stat st; + abi_long ret; + + ret = get_errno(fstat(arg1, &st)); + if (!is_error(ret) && host_to_target_stat(arg2, &st)) { + return -TARGET_EFAULT; + } + return ret; +} + IMPL(fstatfs) { struct statfs stfs; @@ -8435,6 +8472,25 @@ IMPL(lseek) return get_errno(lseek(arg1, arg2, arg3)); } +#ifdef TARGET_NR_lstat +IMPL(lstat) +{ + char *p = lock_user_string(arg1); + struct stat st; + abi_long ret; + + if (!p) { + return -TARGET_EFAULT; + } + ret = get_errno(lstat(path(p), &st)); + unlock_user(p, arg1, 0); + if (!is_error(ret) && host_to_target_stat(arg2, &st)) { + return -TARGET_EFAULT; + } + return ret; +} +#endif + #ifdef TARGET_NR_mkdir IMPL(mkdir) { @@ -9781,6 +9837,25 @@ IMPL(ssetmask) } #endif +#ifdef TARGET_NR_stat +IMPL(stat) +{ + char *p = lock_user_string(arg1); + struct stat st; + abi_long ret; + + if (!p) { + return -TARGET_EFAULT; + } + ret = get_errno(stat(path(p), &st)); + unlock_user(p, arg1, 0); + if (!is_error(ret) && host_to_target_stat(arg2, &st)) { + return -TARGET_EFAULT; + } + return ret; +} +#endif + IMPL(statfs) { char *p = lock_user_string(arg1); @@ -10153,53 +10228,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1, void *p; switch(num) { -#ifdef TARGET_NR_stat - case TARGET_NR_stat: - if (!(p = lock_user_string(arg1))) { - return -TARGET_EFAULT; - } - ret = get_errno(stat(path(p), &st)); - unlock_user(p, arg1, 0); - goto do_stat; -#endif -#ifdef TARGET_NR_lstat - case TARGET_NR_lstat: - if (!(p = lock_user_string(arg1))) { - return -TARGET_EFAULT; - } - ret = get_errno(lstat(path(p), &st)); - unlock_user(p, arg1, 0); - goto do_stat; -#endif - case TARGET_NR_fstat: - { - ret = get_errno(fstat(arg1, &st)); -#if defined(TARGET_NR_stat) || defined(TARGET_NR_lstat) - do_stat: -#endif - if (!is_error(ret)) { - struct target_stat *target_st; - - if (!lock_user_struct(VERIFY_WRITE, target_st, arg2, 0)) - return -TARGET_EFAULT; - memset(target_st, 0, sizeof(*target_st)); - __put_user(st.st_dev, &target_st->st_dev); - __put_user(st.st_ino, &target_st->st_ino); - __put_user(st.st_mode, &target_st->st_mode); - __put_user(st.st_uid, &target_st->st_uid); - __put_user(st.st_gid, &target_st->st_gid); - __put_user(st.st_nlink, &target_st->st_nlink); - __put_user(st.st_rdev, &target_st->st_rdev); - __put_user(st.st_size, &target_st->st_size); - __put_user(st.st_blksize, &target_st->st_blksize); - __put_user(st.st_blocks, &target_st->st_blocks); - __put_user(st.st_atime, &target_st->target_st_atime); - __put_user(st.st_mtime, &target_st->target_st_mtime); - __put_user(st.st_ctime, &target_st->target_st_ctime); - unlock_user_struct(target_st, arg2, 1); - } - } - return ret; case TARGET_NR_vhangup: return get_errno(vhangup()); #ifdef TARGET_NR_syscall @@ -12873,6 +12901,7 @@ static impl_fn *syscall_table(unsigned num) #ifdef TARGET_NR_fork SYSCALL(fork); #endif + SYSCALL(fstat); SYSCALL(fstatfs); #ifdef TARGET_NR_fstatfs64 SYSCALL(fstatfs64); @@ -12918,6 +12947,9 @@ static impl_fn *syscall_table(unsigned num) SYSCALL(listen); #endif SYSCALL(lseek); +#ifdef TARGET_NR_lstat + SYSCALL(lstat); +#endif #ifdef TARGET_NR_mkdir SYSCALL(mkdir); #endif @@ -13062,6 +13094,9 @@ static impl_fn *syscall_table(unsigned num) #endif #ifdef TARGET_NR_ssetmask SYSCALL(ssetmask); +#endif +#ifdef TARGET_NR_stat + SYSCALL(stat); #endif SYSCALL(statfs); #ifdef TARGET_NR_statfs64