From patchwork Sun May 19 20:36:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164522 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp4795558ili; Sun, 19 May 2019 14:04:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqwiVXUiupW1Sd/k3jZdZhmT5H7nTpCeQwOXcSIAELWucH6mdZLJDZUf+g8FCJiiXq8SOmAc X-Received: by 2002:a50:ce5b:: with SMTP id k27mr19246145edj.48.1558299889231; Sun, 19 May 2019 14:04:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558299889; cv=none; d=google.com; s=arc-20160816; b=pENS1Sum0gnd3gqOLh0cY6gtzK4/qOAuVWgs9qE+gJN5//1aW7aYFlzvJUmqlu4jfb vhkqoQCPKWTW8KEh5bXv7Arg+L49WgoBhHTpKezvPquMIZ/gvjWO3kNdcCTXjn4lBB28 vNpDRycdhFIMySC2p5q5WnqhuR4v5WoL2nPSdyuWiGTRq4ckZf4jwDvLmv6qlYcgZh/L st3mEDzUSs4LWbl/0FzdHjYiWzPeaXN3FEaAnMmTVJ+KeMaA8KTtq5/BEHdfGXwgF9dj cNRIRKng9O23iAONF4ABN6bGaVt7avt0xZ4XBTpplQiV4kbD49y8nqkmJO6XFYbYjoAy RIgg== 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=H4vQIA+B5PMSizbcnaZO+HK/zsI+Heqt+lO8dDvIHmE=; b=ho7eLjIF4x1WZKpccCiKyh0/GCUiUDwrvFKgtcxxxIBExTXRGoQ3Rl1UYpCYKQanfb 1UsCsOHyUz4uaT9JTh8FnizIzqhMsjD9NjMcoyriJi1bA75aw3x0oxuwi7UCP1h+Xe6Z F4TVSeTQbm8dD5lXgGtA4UR07v9DmR18pKXSTiS98aXQ/DrFk5n78/Q8B8ksbi/jCGHB ifgsmTs8gAS9VisbHQmWVXFjf3DNHyDInXm+yfuGcUAhF8BsPjvCZAtrXseIO1mbElwd 7d3ks5/lEPLsoOZbwgGvEyzlFF8lIVZXpYbfU8+mdQBfPXkE/rvTaLb6ASYLXOy1ObYg +yNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=nACouiip; 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 o54si8687828edc.7.2019.05.19.14.04.48 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 19 May 2019 14:04:49 -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=nACouiip; 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]:53481 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSSzA-0000Ni-3X for patch@linaro.org; Sun, 19 May 2019 17:04:48 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50421) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSSZF-0003JD-6b for qemu-devel@nongnu.org; Sun, 19 May 2019 16:38:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hSSZD-0003uG-RA for qemu-devel@nongnu.org; Sun, 19 May 2019 16:38:01 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:36600) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hSSZD-0003t0-IC for qemu-devel@nongnu.org; Sun, 19 May 2019 16:37:59 -0400 Received: by mail-pl1-x642.google.com with SMTP id d21so5723736plr.3 for ; Sun, 19 May 2019 13:37:59 -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=H4vQIA+B5PMSizbcnaZO+HK/zsI+Heqt+lO8dDvIHmE=; b=nACouiip8p+PlsU6WPVxFUhzvBWGxmsSE4WlYsnUrnPAJCG7bxnmI7C3A4X1p6kvHM /hu1V+GNRJqJb2i5vHj5DcwV+PkzRBNdYIdn2MJdHWaNue+fNEv3mXBY5lEVhhh+pFeZ wao1yG2zYRQAC/d+yh92oPHvegNRGVqO5Jrr9KBSCkdRnBOonXB3VHteftuN8i4qyQcK AKlvaNy9cwp5v1wuKzQBTfpwD0ULEDm8zY4k3xzPtlq8bAG7R0fdv+SjIU2jmejygj6i 2eHnRhRrwevU9pnUCK0JpVzUlOvd58UP888m+NoCCs7ELRQGRt9Wbtq6DpRX0g7qcDax Wvtw== 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=H4vQIA+B5PMSizbcnaZO+HK/zsI+Heqt+lO8dDvIHmE=; b=p+u0Eieu1BG8P8hOyXL5Fo7MQFDyv4ZAsT71ApyQO9949vZiQaqsgUcCXV7FtGSFLW YraHbOQznizbuyIjLf6hBVFJoYjph7nRXrSdp6C5zMdEBpb86Kz4GBkvs4N29eNSIQH7 8IPiBLpngauTdZJ9/GljJEOvHmw2mFp9gNEj2GGHmp07l+H/zeZ022Tf6fSJZxcXBsAP /YeqBn/M0VLpyS/5wXjpKpC7WYvuZL0Q64PbeF08dY3q+xE/Ve4wg5xm9nbGh+Jh6qx7 C6uRUn4xjX16K6zM+0GbuUfRKWdigdxpfSqCOwTMf+/6MwvjZZJKEKhiehqa19Dx3cjq znMw== X-Gm-Message-State: APjAAAWp5gyiWSs8Yv7FACqwrFk/icdj4K5xZlmZMxmLp3WvciMCIYrW c9VD5DNhKF7wWqIcQ8UqIpcJyJ3fvNo= X-Received: by 2002:a17:902:70c6:: with SMTP id l6mr54071306plt.84.1558298278338; Sun, 19 May 2019 13:37:58 -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.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 May 2019 13:37:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sun, 19 May 2019 13:36:34 -0700 Message-Id: <20190519203726.20729-23-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::642 Subject: [Qemu-devel] [PATCH v7 22/74] 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.1 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 feb8ec7c09..9ac0b859da 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 @@ -1810,18 +1810,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, @@ -2187,32 +2175,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, @@ -2475,6 +2437,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 440ff5ed14..5acd8ecc10 100644 --- a/linux-user/syscall-file.inc.c +++ b/linux-user/syscall-file.inc.c @@ -662,6 +662,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 865129df9e..53e108b614 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -5383,22 +5383,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; @@ -5790,14 +5774,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 f3c54cec69..f08ddaddac 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