@@ -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);
@@ -63,6 +63,7 @@ typedef enum {
ARG_MMAPPROT,
ARG_MODEFLAG,
ARG_OPENFLAG,
+ ARG_UNLINKATFLAG,
/* These are interpreted as pointers. */
ARG_PTR,
@@ -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;
@@ -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;
@@ -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));
@@ -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
Note that unlinkat is universally provided. Implement rmdir in terms of unlinkat. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> --- 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(-)