From patchwork Sun Jun 10 03:01:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 138162 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2608990lji; Sat, 9 Jun 2018 21:05:59 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJjLD8ilBWhCPttKvgotz0wGpNdl2rs5HKWUJVcHEfvg/wSUF/Xka1xbblNGEcTjsSlXZ/y X-Received: by 2002:aed:3ac7:: with SMTP id o65-v6mr11560271qte.127.1528603558930; Sat, 09 Jun 2018 21:05:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528603558; cv=none; d=google.com; s=arc-20160816; b=deUaJqiD1gYdyxZe2hNVEYcq74HrqLQQq8iKWmwGHKjbcrfzVGjCqTBUSvhRZTdmIN 91cLkx4fkWXjzGgqHTI8xS99pWyoI/kSPEgGYsFby3hw8ns02O6vqrv5vanrINQa82wX edrHiPMFsnAkbzEMSViuaEeaPD2BHbLml2mGMsczpnGTr9fWfNfzE7ORQaN856tTftPD 0hEvNyL72KssA9BxT5GRMKiuG/UhM92/SKZCtW0YCZIuUidH/Ji/1GrUTy6Q74725iz8 RlRfk4NU2mkO9JEJR2Tj/S2FsHHuM8F/agYHQ8+LEkdIwDxWKeZob/nygPu92X3mycmW 0YUw== 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=XyAo9SXJ9Cfar4HnwBLCXuw/sTqKMfM0/MatVpqiLrw=; b=RDytjrS8GoUIY/huURihRMfet89Mm43LPnP3NtB5BhHmC5MWLcmfY30Gixh2fVQAkq mv1SktT+77ISEXM9Z0ZbFoK7dL5SejICYmyw9tW0sLh58dBOzhafvX0VKuCsrFhVjrqe zmIsOqmHfzPUcWLH038xPWeaC8WfqIHwDkmFP4DJEQp1UaBZZ90J+vKDiGZC3VLZw0pa qX7vbN+Qbrki4VUo1SbhBQ+cs7TTQlit0KC6SSMT1ej3hxrD2s5+0g8BynDHEsq0Wx0a nUIHQbE33qsXWkz0BDsMRoEHJsNguxljRbEmRaTFI0OcZXPyLfh9Qw5Qup2KVa6uYhSz gl4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jZ384wzL; 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 i187-v6si5322160qke.393.2018.06.09.21.05.58 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 09 Jun 2018 21:05:58 -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=jZ384wzL; 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]:42527 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRrc6-0000lE-Bf for patch@linaro.org; Sun, 10 Jun 2018 00:05:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqfa-0004Hb-9c for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:05:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRqfY-0004Yq-IL for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:05:30 -0400 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:38123) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRqfY-0004Xw-3O for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:05:28 -0400 Received: by mail-pf0-x243.google.com with SMTP id b74-v6so8494653pfl.5 for ; Sat, 09 Jun 2018 20:05:28 -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=XyAo9SXJ9Cfar4HnwBLCXuw/sTqKMfM0/MatVpqiLrw=; b=jZ384wzLXjPjBaDsTo9lKmCSXkNBNO1ZSIuatfKRom5zVXojXVqQG848bHluxnnVwt JZyaBs/KO6aLSZYFyl12QXIn+WrqRzegWuCE1iq6mYPTzm/q5/+oW+MjBl5yCFqGdr/r uMJhDbWxlojJhPfsUkY9SKlirQ0g3GE2T9ed0= 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=XyAo9SXJ9Cfar4HnwBLCXuw/sTqKMfM0/MatVpqiLrw=; b=I627SK4+9e1dm1LNjFHljj2YFdqDZfmVTW9tZAhVPC4ZbqZZhq4n1ZCtQOY9KCdony tTM0Ht3K+pFj0NO6VUhJe1l5eVwBpKj2EslQGa6CqvJHo2XdGXzY262f8UEZhLX5XED/ OexhePk3uwKb3viZJBlndX6Hnlm418gXS9Lx249U0cYgkYVRuJCuxQSA8qbtjPboz0Hs SsIH0Y/k/HAPggVmbnafEafotlDDIODeUyVW5WUArvMQeUsJoVrpsiWpQVt3eNNi1o2/ DlITIKqGZ0fjD/VSxfdj4b3IFFU7pr4wRSGai+q4kdOY9nYdYBgu+Q+W2LiYkdWKtMb5 hCeg== X-Gm-Message-State: APt69E09qYE7Id2pJzeSZ7WHhVuEMN4cqNJRem3tBNyK5Sr6wPl9rp0+ cwOnW9YNgAu8tkuzmQ/mFoJxcQBKFk8= X-Received: by 2002:a65:65d6:: with SMTP id y22-v6mr10399518pgv.270.1528599926727; Sat, 09 Jun 2018 20:05:26 -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.05.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Jun 2018 20:05:25 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 9 Jun 2018 17:01:59 -1000 Message-Id: <20180610030220.3777-88-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:c00::243 Subject: [Qemu-devel] [PATCH v2 087/108] linux-user: Split out xattr syscalls 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" This includes fgetxattr, flistxattr, fremovexattr, fsetxattr, getxattr, lgetxattr, listxattr, llistxattr, lremovexattr, lsetxattr, removexattr, setxattr. All targets define all of these; simplify the ifdefs. Signed-off-by: Richard Henderson --- linux-user/syscall.c | 453 +++++++++++++++++++++++++++---------------- 1 file changed, 291 insertions(+), 162 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 0897449273..c37af32bb6 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8328,6 +8328,46 @@ IMPL(fdatasync) return get_errno(fdatasync(arg1)); } +#ifdef CONFIG_ATTR +IMPL(fgetxattr) +{ + void *n, *v = 0; + abi_long ret; + + if (arg3) { + v = lock_user(VERIFY_WRITE, arg3, arg4, 0); + if (!v) { + return -TARGET_EFAULT; + } + } + n = lock_user_string(arg2); + if (n) { + ret = get_errno(fgetxattr(arg1, n, v, arg4)); + } else { + ret = -TARGET_EFAULT; + } + unlock_user(n, arg2, 0); + unlock_user(v, arg3, arg4); + return ret; +} + +IMPL(flistxattr) +{ + void *b = 0; + abi_long ret; + + if (arg2) { + b = lock_user(VERIFY_WRITE, arg2, arg3, 0); + if (!b) { + return -TARGET_EFAULT; + } + } + ret = get_errno(flistxattr(arg1, b, arg3)); + unlock_user(b, arg2, arg3); + return ret; +} +#endif + IMPL(flock) { /* The flock constant seems to be the same for every Linux platform. */ @@ -8341,6 +8381,45 @@ IMPL(fork) } #endif +#ifdef CONFIG_ATTR +IMPL(fremovexattr) +{ + void *n; + abi_long ret; + + n = lock_user_string(arg2); + if (n) { + ret = get_errno(fremovexattr(arg1, n)); + } else { + ret = -TARGET_EFAULT; + } + unlock_user(n, arg2, 0); + return ret; +} + +IMPL(fsetxattr) +{ + void *n, *v = 0; + abi_long ret; + + if (arg3) { + v = lock_user(VERIFY_READ, arg3, arg4, 1); + if (!v) { + return -TARGET_EFAULT; + } + } + n = lock_user_string(arg2); + if (n) { + ret = get_errno(fsetxattr(arg1, n, v, arg4, arg5)); + } else { + ret = -TARGET_EFAULT; + } + unlock_user(n, arg2, 0); + unlock_user(v, arg3, 0); + return ret; +} +#endif + IMPL(fstat) { struct stat st; @@ -8981,6 +9060,32 @@ IMPL(getuid32) } #endif +#ifdef CONFIG_ATTR +IMPL(getxattr) +{ + void *p, *n, *v = 0; + abi_long ret; + + if (arg3) { + v = lock_user(VERIFY_WRITE, arg3, arg4, 0); + if (!v) { + return -TARGET_EFAULT; + } + } + p = lock_user_string(arg1); + n = lock_user_string(arg2); + if (p && n) { + ret = get_errno(getxattr(p, n, v, arg4)); + } else { + ret = -TARGET_EFAULT; + } + unlock_user(p, arg1, 0); + unlock_user(n, arg2, 0); + unlock_user(v, arg3, arg4); + return ret; +} +#endif + #if defined(TARGET_NR_getxgid) && defined(TARGET_ALPHA) IMPL(getxgid) { @@ -9212,6 +9317,32 @@ IMPL(lchown32) } #endif +#ifdef CONFIG_ATTR +IMPL(lgetxattr) +{ + void *p, *n, *v = 0; + abi_long ret; + + if (arg3) { + v = lock_user(VERIFY_WRITE, arg3, arg4, 0); + if (!v) { + return -TARGET_EFAULT; + } + } + p = lock_user_string(arg1); + n = lock_user_string(arg2); + if (p && n) { + ret = get_errno(lgetxattr(p, n, v, arg4)); + } else { + ret = -TARGET_EFAULT; + } + unlock_user(p, arg1, 0); + unlock_user(n, arg2, 0); + unlock_user(v, arg3, arg4); + return ret; +} +#endif + #ifdef TARGET_NR_link IMPL(link) { @@ -9249,6 +9380,50 @@ IMPL(listen) } #endif +#ifdef CONFIG_ATTR +IMPL(listxattr) +{ + void *p = lock_user_string(arg1); + void *b = 0; + abi_long ret; + + if (!p) { + return -TARGET_EFAULT; + } + if (arg2) { + b = lock_user(VERIFY_WRITE, arg2, arg3, 0); + if (!b) { + return -TARGET_EFAULT; + } + } + ret = get_errno(listxattr(p, b, arg3)); + unlock_user(p, arg1, 0); + unlock_user(b, arg2, arg3); + return ret; +} + +IMPL(llistxattr) +{ + void *p = lock_user_string(arg1); + void *b = 0; + abi_long ret; + + if (!p) { + return -TARGET_EFAULT; + } + if (arg2) { + b = lock_user(VERIFY_WRITE, arg2, arg3, 0); + if (!b) { + return -TARGET_EFAULT; + } + } + ret = get_errno(llistxattr(p, b, arg3)); + unlock_user(p, arg1, 0); + unlock_user(b, arg2, arg3); + return ret; +} +#endif + /* Older kernel ports have _llseek() instead of llseek() */ #if defined(TARGET_NR__llseek) && !defined(TARGET_NR_llseek) #define TARGET_NR_llseek TARGET_NR__llseek @@ -9270,11 +9445,54 @@ IMPL(llseek) } #endif +#ifdef CONFIG_ATTR +IMPL(lremovexattr) +{ + char *p = lock_user_string(arg1); + char *n = lock_user_string(arg2); + abi_long ret = -TARGET_EFAULT; + + if (p && n) { + ret = get_errno(lremovexattr(p, n)); + } + unlock_user(p, arg1, 0); + unlock_user(n, arg2, 0); + return ret; +} +#endif + IMPL(lseek) { return get_errno(lseek(arg1, arg2, arg3)); } +#ifdef CONFIG_ATTR +IMPL(lsetxattr) +{ + char *p, *n; + void *v = 0; + abi_long ret; + + if (arg3) { + v = lock_user(VERIFY_READ, arg3, arg4, 1); + if (!v) { + return -TARGET_EFAULT; + } + } + p = lock_user_string(arg1); + n = lock_user_string(arg2); + if (p && n) { + ret = get_errno(lsetxattr(p, n, v, arg4, arg5)); + } else { + ret = -TARGET_EFAULT; + } + unlock_user(p, arg1, 0); + unlock_user(n, arg2, 0); + unlock_user(v, arg3, 0); + return ret; +} +#endif + #ifdef TARGET_NR_lstat IMPL(lstat) { @@ -10428,6 +10646,22 @@ IMPL(recvmsg) } #endif +#ifdef CONFIG_ATTR +IMPL(removexattr) +{ + char *p = lock_user_string(arg1); + char *n = lock_user_string(arg2); + abi_long ret = -TARGET_EFAULT; + + if (p && n) { + ret = get_errno(removexattr(p, n)); + } + unlock_user(p, arg1, 0); + unlock_user(n, arg2, 0); + return ret; +} +#endif + #ifdef TARGET_NR_rename IMPL(rename) { @@ -11277,6 +11511,33 @@ IMPL(setuid32) } #endif +#ifdef CONFIG_ATTR +IMPL(setxattr) +{ + char *p, *n; + void *v = 0; + abi_long ret; + + if (arg3) { + v = lock_user(VERIFY_READ, arg3, arg4, 1); + if (!v) { + return -TARGET_EFAULT; + } + } + p = lock_user_string(arg1); + n = lock_user_string(arg2); + if (p && n) { + ret = get_errno(setxattr(p, n, v, arg4, arg5)); + } else { + ret = -TARGET_EFAULT; + } + unlock_user(p, arg1, 0); + unlock_user(n, arg2, 0); + unlock_user(v, arg3, 0); + return ret; +} +#endif + #ifdef TARGET_NR_sigaction IMPL(sigaction) { @@ -12203,168 +12464,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1, void *p; switch(num) { -#ifdef CONFIG_ATTR -#ifdef TARGET_NR_setxattr - case TARGET_NR_listxattr: - case TARGET_NR_llistxattr: - { - void *p, *b = 0; - if (arg2) { - b = lock_user(VERIFY_WRITE, arg2, arg3, 0); - if (!b) { - return -TARGET_EFAULT; - } - } - p = lock_user_string(arg1); - if (p) { - if (num == TARGET_NR_listxattr) { - ret = get_errno(listxattr(p, b, arg3)); - } else { - ret = get_errno(llistxattr(p, b, arg3)); - } - } else { - ret = -TARGET_EFAULT; - } - unlock_user(p, arg1, 0); - unlock_user(b, arg2, arg3); - return ret; - } - case TARGET_NR_flistxattr: - { - void *b = 0; - if (arg2) { - b = lock_user(VERIFY_WRITE, arg2, arg3, 0); - if (!b) { - return -TARGET_EFAULT; - } - } - ret = get_errno(flistxattr(arg1, b, arg3)); - unlock_user(b, arg2, arg3); - return ret; - } - case TARGET_NR_setxattr: - case TARGET_NR_lsetxattr: - { - void *p, *n, *v = 0; - if (arg3) { - v = lock_user(VERIFY_READ, arg3, arg4, 1); - if (!v) { - return -TARGET_EFAULT; - } - } - p = lock_user_string(arg1); - n = lock_user_string(arg2); - if (p && n) { - if (num == TARGET_NR_setxattr) { - ret = get_errno(setxattr(p, n, v, arg4, arg5)); - } else { - ret = get_errno(lsetxattr(p, n, v, arg4, arg5)); - } - } else { - ret = -TARGET_EFAULT; - } - unlock_user(p, arg1, 0); - unlock_user(n, arg2, 0); - unlock_user(v, arg3, 0); - } - return ret; - case TARGET_NR_fsetxattr: - { - void *n, *v = 0; - if (arg3) { - v = lock_user(VERIFY_READ, arg3, arg4, 1); - if (!v) { - return -TARGET_EFAULT; - } - } - n = lock_user_string(arg2); - if (n) { - ret = get_errno(fsetxattr(arg1, n, v, arg4, arg5)); - } else { - ret = -TARGET_EFAULT; - } - unlock_user(n, arg2, 0); - unlock_user(v, arg3, 0); - } - return ret; - case TARGET_NR_getxattr: - case TARGET_NR_lgetxattr: - { - void *p, *n, *v = 0; - if (arg3) { - v = lock_user(VERIFY_WRITE, arg3, arg4, 0); - if (!v) { - return -TARGET_EFAULT; - } - } - p = lock_user_string(arg1); - n = lock_user_string(arg2); - if (p && n) { - if (num == TARGET_NR_getxattr) { - ret = get_errno(getxattr(p, n, v, arg4)); - } else { - ret = get_errno(lgetxattr(p, n, v, arg4)); - } - } else { - ret = -TARGET_EFAULT; - } - unlock_user(p, arg1, 0); - unlock_user(n, arg2, 0); - unlock_user(v, arg3, arg4); - } - return ret; - case TARGET_NR_fgetxattr: - { - void *n, *v = 0; - if (arg3) { - v = lock_user(VERIFY_WRITE, arg3, arg4, 0); - if (!v) { - return -TARGET_EFAULT; - } - } - n = lock_user_string(arg2); - if (n) { - ret = get_errno(fgetxattr(arg1, n, v, arg4)); - } else { - ret = -TARGET_EFAULT; - } - unlock_user(n, arg2, 0); - unlock_user(v, arg3, arg4); - } - return ret; - case TARGET_NR_removexattr: - case TARGET_NR_lremovexattr: - { - void *p, *n; - p = lock_user_string(arg1); - n = lock_user_string(arg2); - if (p && n) { - if (num == TARGET_NR_removexattr) { - ret = get_errno(removexattr(p, n)); - } else { - ret = get_errno(lremovexattr(p, n)); - } - } else { - ret = -TARGET_EFAULT; - } - unlock_user(p, arg1, 0); - unlock_user(n, arg2, 0); - } - return ret; - case TARGET_NR_fremovexattr: - { - void *n; - n = lock_user_string(arg2); - if (n) { - ret = get_errno(fremovexattr(arg1, n)); - } else { - ret = -TARGET_EFAULT; - } - unlock_user(n, arg2, 0); - } - return ret; -#endif -#endif /* CONFIG_ATTR */ #ifdef TARGET_NR_set_thread_area case TARGET_NR_set_thread_area: #if defined(TARGET_MIPS) @@ -13253,9 +13352,17 @@ static impl_fn *syscall_table(unsigned num) SYSCALL(fcntl64); #endif SYSCALL(fdatasync); +#ifdef CONFIG_ATTR + SYSCALL(fgetxattr); + SYSCALL(flistxattr); +#endif SYSCALL(flock); #ifdef TARGET_NR_fork SYSCALL(fork); +#endif +#ifdef CONFIG_ATTR + SYSCALL(fremovexattr); + SYSCALL(fsetxattr); #endif SYSCALL(fstat); #ifdef TARGET_NR_fstat64 @@ -13354,6 +13461,9 @@ static impl_fn *syscall_table(unsigned num) #ifdef TARGET_NR_getuid32 SYSCALL(getuid32); #endif +#ifdef CONFIG_ATTR + SYSCALL(getxattr); +#endif #if defined(TARGET_NR_getxgid) && defined(TARGET_ALPHA) SYSCALL(getxgid); #endif @@ -13374,17 +13484,30 @@ static impl_fn *syscall_table(unsigned num) #ifdef TARGET_NR_lchown32 SYSCALL(lchown32); #endif +#ifdef CONFIG_ATTR + SYSCALL(lgetxattr); +#endif #ifdef TARGET_NR_link SYSCALL(link); #endif SYSCALL(linkat); +#ifdef CONFIG_ATTR + SYSCALL(listxattr); + SYSCALL(llistxattr); +#endif #ifdef TARGET_NR_listen SYSCALL(listen); #endif #ifdef TARGET_NR_llseek SYSCALL(llseek); +#endif +#ifdef CONFIG_ATTR + SYSCALL(lremovexattr); #endif SYSCALL(lseek); +#ifdef CONFIG_ATTR + SYSCALL(lsetxattr); +#endif #ifdef TARGET_NR_lstat SYSCALL(lstat); #endif @@ -13498,6 +13621,9 @@ static impl_fn *syscall_table(unsigned num) #ifdef TARGET_NR_recvmsg SYSCALL(recvmsg); #endif +#ifdef CONFIG_ATTR + SYSCALL(removexattr); +#endif #ifdef TARGET_NR_rename SYSCALL(rename); #endif @@ -13629,6 +13755,9 @@ static impl_fn *syscall_table(unsigned num) #ifdef TARGET_NR_setuid32 SYSCALL(setuid32); #endif +#ifdef CONFIG_ATTR + SYSCALL(setxattr); +#endif #ifdef TARGET_NR_sigaction SYSCALL(sigaction); #endif