From patchwork Fri Jan 18 21:30:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 156073 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3742020jaa; Fri, 18 Jan 2019 13:53:21 -0800 (PST) X-Google-Smtp-Source: ALg8bN6ImZP+OIowAmpPrmWcGQRqu0aFPAypuo4ptIN1gOeUbdMLnuwxR3Lz8rbvM+v6PeB8TZ7j X-Received: by 2002:a1c:5892:: with SMTP id m140mr17004251wmb.60.1547848401408; Fri, 18 Jan 2019 13:53:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547848401; cv=none; d=google.com; s=arc-20160816; b=vJiGOo0BefcTy0I8ULBqxerQITJHT6B1/F8aObXHD9b1mMPtbDLJkC7aIY7s3w1Wdd j5pFEysKweWwoT2laeGaozuMxEKx/9+zUxT+0pkCc8gu/GfxqkEbb4WOkuJmOBnqRJTe aoJBhcXu7OiCd83hyEO2Yzpc8+KXtyUCvSRyhziyZcTZjUrL4CLM+RpmgzmDTfUlQOFT kmUU1T9mlsFukAaQKwddulzMUnoVYhUse8+OWs9tnYK1UdibhbzDlzGDWbNQ2zbmB5dM XWPAI0kWA23oFl1o6hyeyrKQcdMEae6Ng7azMIlapCfF8c1Vz1tz8jvhbEx88FK/c+jn U55A== 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=QcTx9xUhMTLOsLF+/TTUz9FMaNWvx4h/CHXeU4naRY4=; b=RCI4gB2vqfYnUUz8UeshkxIWdv+zQMVuNBkPqMFnV7gUcdeAC9zLM0VTr3RG9xtaRw Db5IJ4AqiDiMNqwn44n2UjKZnLnd4u7kXUVBVzgIOIA5bMmz+WRBiQMgHIq1e0eFC+9e 2EkEzT0sLGZmN9LWZdqCEZKnOLYyriJHVjImk4V+MrkiNFslNVLR41kDVExTppEdO+/1 dCa5Sd4GO3nBxFmnX19gvrQP9UNAd2kKIhA5m0ek0jtwPzQ+VsePPViSRNhmX4xh9oO5 NbE/GcPA5t/MKtkyRs6SkARQHxqJ6BUfzze801qzytjy9t2uSJTx6liQbNxqDZVs5acE uKvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=eXhnTrPE; 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 n6si58984514wrw.334.2019.01.18.13.53.21 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 18 Jan 2019 13:53:21 -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=eXhnTrPE; 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]:47676 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkc4m-0004WD-7v for patch@linaro.org; Fri, 18 Jan 2019 16:53:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56075) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkbkf-0005Mf-3s for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:32:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkbkd-0004tV-SZ for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:32:33 -0500 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:45120) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gkbkd-0004l3-Lg for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:32:31 -0500 Received: by mail-pg1-x541.google.com with SMTP id y4so6629776pgc.12 for ; Fri, 18 Jan 2019 13:32:23 -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=QcTx9xUhMTLOsLF+/TTUz9FMaNWvx4h/CHXeU4naRY4=; b=eXhnTrPEwO/i7yQAyszRaTn5Ou3JnH4crOFCaBUPcC6Wh8Y1Re9mSHX0CleIz0FQFT /DrodTmZnAeMHAhTEgyi4EWIsFfdR76Qm110wRjlmBz4cDzdYYXlh9RVT6PYPkwd84S0 OXNizxQTCnQ23SI6WQ26D4XE981zu9YQUsg2Q= 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=QcTx9xUhMTLOsLF+/TTUz9FMaNWvx4h/CHXeU4naRY4=; b=RZu4sZPXwLxZez7jfxm8Xd/ehyGkU087aKvN8V4yueQqu8559jU2IQoB+u48r79DqK 0eBpXJ9TinLH42WEn7oNZaIEaTsx5zDYOxjHf4U4mEE6Qg2hp+BMRh8p/D/d9DUXhlfb FtCWQQl/j2sUHB5Ek7FpcclqYrhAmal43XDfRCVW+D10xFxnV2tg7W6UgYOg5bESsO5W EDspB67hHxCSq2XrA9FBBtJKVQfJuKGVQr4qsaUBH0dvW7cTsEX3DvWp7AdMHO000TGP Ny2jxjTDgKoqALFEP7NNoK+hctkmPz8WVRrr7S/Qmy6+3dlNNHmpUwHc91IHki7AXll4 Ub1A== X-Gm-Message-State: AJcUuke/NkDPGt4kZWAdfvNiGh7H+zPxpyUebBIYmg0badNXyBQ5M9iB YCzP9BSCD9SY5ar19pUQ1/Ck4fki1D4= X-Received: by 2002:a63:2406:: with SMTP id k6mr18682337pgk.229.1547847141836; Fri, 18 Jan 2019 13:32:21 -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.32.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jan 2019 13:32:21 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 19 Jan 2019 08:30:56 +1100 Message-Id: <20190118213122.22865-23-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::541 Subject: [Qemu-devel] [PATCH v6 23/49] linux-user: Split out unlink, unlinkat, rmdir 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" Note that unlinkat is universally provided. Implement rmdir in terms of unlinkat. Signed-off-by: Richard Henderson --- linux-user/syscall-defs.h | 7 ++++++ linux-user/syscall.h | 1 + linux-user/strace.c | 43 ++++------------------------------- linux-user/syscall-file.inc.c | 32 ++++++++++++++++++++++++++ linux-user/syscall.c | 24 ------------------- linux-user/strace.list | 9 -------- 6 files changed, 44 insertions(+), 72 deletions(-) -- 2.17.2 diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h index 41dd887dbc..78d3f600eb 100644 --- a/linux-user/syscall-defs.h +++ b/linux-user/syscall-defs.h @@ -98,6 +98,9 @@ SYSCALL_DEF(readlink, ARG_STR, ARG_PTR, ARG_DEC); SYSCALL_DEF(readlinkat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_DEC); #endif SYSCALL_DEF(readv, ARG_DEC, ARG_PTR, ARG_DEC); +#ifdef TARGET_NR_rmdir +SYSCALL_DEF(rmdir, ARG_STR); +#endif #if !defined(SYSCALL_TABLE) || defined(TARGET_NR_semctl) SYSCALL_DEF(semctl, ARG_DEC, ARG_DEC, ARG_DEC, ARG_HEX); #endif @@ -121,6 +124,10 @@ SYSCALL_DEF(shmdt, ARG_PTR); #if !defined(SYSCALL_TABLE) || defined(TARGET_NR_shmget) SYSCALL_DEF(shmget, ARG_DEC, ARG_DEC, ARG_HEX); #endif +#ifdef TARGET_NR_unlink +SYSCALL_DEF(unlink, ARG_STR); +#endif +SYSCALL_DEF(unlinkat, ARG_ATDIRFD, ARG_STR, ARG_UNLINKATFLAG); #ifdef TARGET_NR_vfork /* Emulate vfork() with fork(). */ SYSCALL_DEF_FULL(vfork, .impl = impl_fork); diff --git a/linux-user/syscall.h b/linux-user/syscall.h index f75cd3ddd0..bdc4d653c4 100644 --- a/linux-user/syscall.h +++ b/linux-user/syscall.h @@ -63,6 +63,7 @@ typedef enum { ARG_MMAPPROT, ARG_MODEFLAG, ARG_OPENFLAG, + ARG_UNLINKATFLAG, /* These are interpreted as pointers. */ ARG_PTR, diff --git a/linux-user/strace.c b/linux-user/strace.c index 5b78eb137b..a41b6dcfe7 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -684,7 +684,7 @@ static struct flags const at_file_flags[] = { FLAG_END, }; -UNUSED static struct flags unlinkat_flags[] = { +static struct flags const unlinkat_flags[] = { #ifdef AT_REMOVEDIR FLAG_GENERIC(AT_REMOVEDIR), #endif @@ -1798,18 +1798,6 @@ print_mkdirat(const struct syscallname *name, } #endif -#ifdef TARGET_NR_rmdir -static void -print_rmdir(const struct syscallname *name, - abi_long arg0, abi_long arg1, abi_long arg2, - abi_long arg3, abi_long arg4, abi_long arg5) -{ - print_syscall_prologue(name); - print_string(arg0, 0); - print_syscall_epilogue(name); -} -#endif - #ifdef TARGET_NR_rt_sigaction static void print_rt_sigaction(const struct syscallname *name, @@ -2175,32 +2163,6 @@ print_umount2(const struct syscallname *name, } #endif -#ifdef TARGET_NR_unlink -static void -print_unlink(const struct syscallname *name, - abi_long arg0, abi_long arg1, abi_long arg2, - abi_long arg3, abi_long arg4, abi_long arg5) -{ - print_syscall_prologue(name); - print_string(arg0, 1); - print_syscall_epilogue(name); -} -#endif - -#ifdef TARGET_NR_unlinkat -static void -print_unlinkat(const struct syscallname *name, - abi_long arg0, abi_long arg1, abi_long arg2, - abi_long arg3, abi_long arg4, abi_long arg5) -{ - print_syscall_prologue(name); - print_at_dirfd(arg0, 0); - print_string(arg1, 0); - print_flags(unlinkat_flags, arg2, 1); - print_syscall_epilogue(name); -} -#endif - #ifdef TARGET_NR_utime static void print_utime(const struct syscallname *name, @@ -2463,6 +2425,9 @@ static void print_syscall_def1(const SyscallDef *def, int64_t args[6]) case ARG_OPENFLAG: len = add_open_flags(b, rest, arg); break; + case ARG_UNLINKATFLAG: + len = add_flags(b, rest, unlinkat_flags, arg, true); + break; case ARG_PTR: len = add_pointer(b, rest, arg); break; diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c index c6ca80955b..2dd57176b3 100644 --- a/linux-user/syscall-file.inc.c +++ b/linux-user/syscall-file.inc.c @@ -656,6 +656,38 @@ SYSCALL_IMPL(readlinkat) } #endif +static abi_long do_unlinkat(int dirfd, abi_ulong target_path, int flags) +{ + char *p = lock_user_string(target_path); + abi_long ret; + + if (!p) { + return -TARGET_EFAULT; + } + ret = get_errno(unlinkat(dirfd, p, flags)); + unlock_user(p, target_path, 0); + return ret; +} + +#ifdef TARGET_NR_unlink +SYSCALL_IMPL(unlink) +{ + return do_unlinkat(AT_FDCWD, arg1, 0); +} +#endif + +#ifdef TARGET_NR_rmdir +SYSCALL_IMPL(rmdir) +{ + return do_unlinkat(AT_FDCWD, arg1, AT_REMOVEDIR); +} +#endif + +SYSCALL_IMPL(unlinkat) +{ + return do_unlinkat(arg1, arg2, arg3); +} + SYSCALL_IMPL(write) { int fd = arg1; diff --git a/linux-user/syscall.c b/linux-user/syscall.c index f1e8d06996..eda199d46f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -5330,22 +5330,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, void *p; switch(num) { -#ifdef TARGET_NR_unlink - case TARGET_NR_unlink: - if (!(p = lock_user_string(arg1))) - return -TARGET_EFAULT; - ret = get_errno(unlink(p)); - unlock_user(p, arg1, 0); - return ret; -#endif -#if defined(TARGET_NR_unlinkat) - case TARGET_NR_unlinkat: - if (!(p = lock_user_string(arg2))) - return -TARGET_EFAULT; - ret = get_errno(unlinkat(arg1, p, arg3)); - unlock_user(p, arg2, 0); - return ret; -#endif case TARGET_NR_execve: { char **argp, **envp; @@ -5737,14 +5721,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, ret = get_errno(mkdirat(arg1, p, arg3)); unlock_user(p, arg2, 0); return ret; -#endif -#ifdef TARGET_NR_rmdir - case TARGET_NR_rmdir: - if (!(p = lock_user_string(arg1))) - return -TARGET_EFAULT; - ret = get_errno(rmdir(p)); - unlock_user(p, arg1, 0); - return ret; #endif case TARGET_NR_dup: ret = get_errno(dup(arg1)); diff --git a/linux-user/strace.list b/linux-user/strace.list index c369915759..faa0a9012d 100644 --- a/linux-user/strace.list +++ b/linux-user/strace.list @@ -527,9 +527,6 @@ #ifdef TARGET_NR_mkdirat { TARGET_NR_mkdirat, "mkdirat" , NULL, print_mkdirat, NULL }, #endif -#ifdef TARGET_NR_rmdir -{ TARGET_NR_rmdir, "rmdir" , NULL, print_rmdir, NULL }, -#endif #ifdef TARGET_NR_mknod { TARGET_NR_mknod, "mknod" , NULL, print_mknod, NULL }, #endif @@ -1425,12 +1422,6 @@ #ifdef TARGET_NR_uname { TARGET_NR_uname, "uname" , "%s(%p)", NULL, NULL }, #endif -#ifdef TARGET_NR_unlink -{ TARGET_NR_unlink, "unlink" , NULL, print_unlink, NULL }, -#endif -#ifdef TARGET_NR_unlinkat -{ TARGET_NR_unlinkat, "unlinkat" , NULL, print_unlinkat, NULL }, -#endif #ifdef TARGET_NR_unshare { TARGET_NR_unshare, "unshare" , NULL, NULL, NULL }, #endif