All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/11] bsd-user: Next round of syscalls
@ 2022-06-14  4:19 Warner Losh
  2022-06-14  4:20 ` [PATCH v2 01/11] bsd-user: Implement open, openat and close Warner Losh
                   ` (10 more replies)
  0 siblings, 11 replies; 13+ messages in thread
From: Warner Losh @ 2022-06-14  4:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kyle Evans, arrowd, Richard Henderson, jrtc27, Warner Losh, def

Implement the next round of system calls. These are open, openat, close,
fdatasync, fsync, close_from, revoke, access, eacccess, facccessat, chdir,
fchdir, rename, renameat, mkdir, mkdirat, rmdir, _getcwd, dup, dup2, truncate,
ftruncate, acct and sync. In addition, the helper functions needed for these to
work are included. With the helper functions, all of these system calls are the
'obvious' wrapper...

V2: Delete extra blank lines
    Use safe_syscall(SYS___getcwd,...) instead of __getcwd.

Only part 8 (bsd-user: Implement rmdir and undocumented __getcwd) needs to be
reviewed.

Warner Losh (11):
  bsd-user: Implement open, openat and close
  bsd-user: Implement fdatasync, fsync and close_from
  bsd-user: Implement revoke, access, eaccess and faccessat
  bsd-user: Implement chdir and fchdir
  bsd-user: Implement rename and renameat
  bsd-user: Implement link, linkat, unlink and unlinkat
  bsd-user: Implement mkdir and mkdirat
  bsd-user: Implement rmdir and undocumented __getcwd
  bsd-user: Implement dup and dup2
  bsd-user: Implement trunctate and ftruncate
  bsd-user: Implement acct and sync

 bsd-user/bsd-file.h           | 359 ++++++++++++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c | 116 +++++++++++
 bsd-user/syscall_defs.h       |   4 +
 3 files changed, 479 insertions(+)

-- 
2.33.1



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v2 01/11] bsd-user: Implement open, openat and close
  2022-06-14  4:19 [PATCH v2 00/11] bsd-user: Next round of syscalls Warner Losh
@ 2022-06-14  4:20 ` Warner Losh
  2022-06-14  4:20 ` [PATCH v2 02/11] bsd-user: Implement fdatasync, fsync and close_from Warner Losh
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Warner Losh @ 2022-06-14  4:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kyle Evans, arrowd, Richard Henderson, jrtc27, Warner Losh, def,
	Stacey Son, Jung-uk Kim, Kyle Evans

Add the open, openat and close system calls. We need to lock paths, so
implmenent that as well.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Jung-uk Kim <jkim@FreeBSD.org>
Signed-off-by: Kyle Evans <kevans@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-file.h           | 49 +++++++++++++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c | 16 ++++++++++++
 bsd-user/syscall_defs.h       |  4 +++
 3 files changed, 69 insertions(+)

diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
index e9e2c85eb67..2bd312f8e18 100644
--- a/bsd-user/bsd-file.h
+++ b/bsd-user/bsd-file.h
@@ -22,11 +22,25 @@
 
 #include "qemu/path.h"
 
+#define LOCK_PATH(p, arg)                   \
+do {                                        \
+    (p) = lock_user_string(arg);            \
+    if ((p) == NULL) {                      \
+        return -TARGET_EFAULT;              \
+    }                                       \
+} while (0)
+
+#define UNLOCK_PATH(p, arg)     unlock_user(p, arg, 0)
+
+
 extern struct iovec *lock_iovec(int type, abi_ulong target_addr, int count,
         int copy);
 extern void unlock_iovec(struct iovec *vec, abi_ulong target_addr, int count,
         int copy);
 
+int safe_open(const char *path, int flags, mode_t mode);
+int safe_openat(int fd, const char *path, int flags, mode_t mode);
+
 ssize_t safe_read(int fd, void *buf, size_t nbytes);
 ssize_t safe_pread(int fd, void *buf, size_t nbytes, off_t offset);
 ssize_t safe_readv(int fd, const struct iovec *iov, int iovcnt);
@@ -190,4 +204,39 @@ static abi_long do_bsd_pwritev(void *cpu_env, abi_long arg1,
     return ret;
 }
 
+/* open(2) */
+static abi_long do_bsd_open(abi_long arg1, abi_long arg2, abi_long arg3)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(safe_open(path(p), target_to_host_bitmask(arg2,
+                fcntl_flags_tbl), arg3));
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* openat(2) */
+static abi_long do_bsd_openat(abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg2);
+    ret = get_errno(safe_openat(arg1, path(p),
+                target_to_host_bitmask(arg3, fcntl_flags_tbl), arg4));
+    UNLOCK_PATH(p, arg2);
+
+    return ret;
+}
+
+/* close(2) */
+static inline abi_long do_bsd_close(abi_long arg1)
+{
+    return get_errno(close(arg1));
+}
+
 #endif /* BSD_FILE_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 71aa0d38e03..a824785fee8 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -44,6 +44,10 @@
 #include "bsd-proc.h"
 
 /* I/O */
+safe_syscall3(int, open, const char *, path, int, flags, mode_t, mode);
+safe_syscall4(int, openat, int, fd, const char *, path, int, flags, mode_t,
+    mode);
+
 safe_syscall3(ssize_t, read, int, fd, void *, buf, size_t, nbytes);
 safe_syscall4(ssize_t, pread, int, fd, void *, buf, size_t, nbytes, off_t,
     offset);
@@ -257,6 +261,18 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd_pwritev(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
         break;
 
+    case TARGET_FREEBSD_NR_open: /* open(2) */
+        ret = do_bsd_open(arg1, arg2, arg3);
+        break;
+
+    case TARGET_FREEBSD_NR_openat: /* openat(2) */
+        ret = do_bsd_openat(arg1, arg2, arg3, arg4);
+        break;
+
+    case TARGET_FREEBSD_NR_close: /* close(2) */
+        ret = do_bsd_close(arg1);
+        break;
+
     default:
         qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
         ret = -TARGET_ENOSYS;
diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h
index f5797b28e39..b6d113d24a7 100644
--- a/bsd-user/syscall_defs.h
+++ b/bsd-user/syscall_defs.h
@@ -226,4 +226,8 @@ type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
     return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4, arg5, arg6); \
 }
 
+/* So far all target and host bitmasks are the same */
+#define target_to_host_bitmask(x, tbl) (x)
+#define host_to_target_bitmask(x, tbl) (x)
+
 #endif /* SYSCALL_DEFS_H */
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 02/11] bsd-user: Implement fdatasync, fsync and close_from
  2022-06-14  4:19 [PATCH v2 00/11] bsd-user: Next round of syscalls Warner Losh
  2022-06-14  4:20 ` [PATCH v2 01/11] bsd-user: Implement open, openat and close Warner Losh
@ 2022-06-14  4:20 ` Warner Losh
  2022-06-14  4:20 ` [PATCH v2 03/11] bsd-user: Implement revoke, access, eaccess and faccessat Warner Losh
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Warner Losh @ 2022-06-14  4:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kyle Evans, arrowd, Richard Henderson, jrtc27, Warner Losh, def,
	Stacey Son, Jung-uk Kim

Implement fdatasync(2), fsync(2) and close_from(2).

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Jung-uk Kim <jkim@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-file.h           | 19 +++++++++++++++++++
 bsd-user/freebsd/os-syscall.c | 12 ++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
index 2bd312f8e18..94eb03df62e 100644
--- a/bsd-user/bsd-file.h
+++ b/bsd-user/bsd-file.h
@@ -239,4 +239,23 @@ static inline abi_long do_bsd_close(abi_long arg1)
     return get_errno(close(arg1));
 }
 
+/* fdatasync(2) */
+static abi_long do_bsd_fdatasync(abi_long arg1)
+{
+    return get_errno(fdatasync(arg1));
+}
+
+/* fsync(2) */
+static abi_long do_bsd_fsync(abi_long arg1)
+{
+    return get_errno(fsync(arg1));
+}
+
+/* closefrom(2) */
+static abi_long do_bsd_closefrom(abi_long arg1)
+{
+    closefrom(arg1);  /* returns void */
+    return get_errno(0);
+}
+
 #endif /* BSD_FILE_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index a824785fee8..f7d09909925 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -273,6 +273,18 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd_close(arg1);
         break;
 
+    case TARGET_FREEBSD_NR_fdatasync: /* fdatasync(2) */
+        ret = do_bsd_fdatasync(arg1);
+        break;
+
+    case TARGET_FREEBSD_NR_fsync: /* fsync(2) */
+        ret = do_bsd_fsync(arg1);
+        break;
+
+    case TARGET_FREEBSD_NR_freebsd12_closefrom: /* closefrom(2) */
+        ret = do_bsd_closefrom(arg1);
+        break;
+
     default:
         qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
         ret = -TARGET_ENOSYS;
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 03/11] bsd-user: Implement revoke, access, eaccess and faccessat
  2022-06-14  4:19 [PATCH v2 00/11] bsd-user: Next round of syscalls Warner Losh
  2022-06-14  4:20 ` [PATCH v2 01/11] bsd-user: Implement open, openat and close Warner Losh
  2022-06-14  4:20 ` [PATCH v2 02/11] bsd-user: Implement fdatasync, fsync and close_from Warner Losh
@ 2022-06-14  4:20 ` Warner Losh
  2022-06-14  4:20 ` [PATCH v2 04/11] bsd-user: Implement chdir and fchdir Warner Losh
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Warner Losh @ 2022-06-14  4:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kyle Evans, arrowd, Richard Henderson, jrtc27, Warner Losh, def,
	Stacey Son

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-file.h           | 53 +++++++++++++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c | 16 +++++++++++
 2 files changed, 69 insertions(+)

diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
index 94eb03df62e..6ff2be24e30 100644
--- a/bsd-user/bsd-file.h
+++ b/bsd-user/bsd-file.h
@@ -258,4 +258,57 @@ static abi_long do_bsd_closefrom(abi_long arg1)
     return get_errno(0);
 }
 
+/* revoke(2) */
+static abi_long do_bsd_revoke(abi_long arg1)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(revoke(p)); /* XXX path(p)? */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* access(2) */
+static abi_long do_bsd_access(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(access(path(p), arg2));
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* eaccess(2) */
+static abi_long do_bsd_eaccess(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(eaccess(path(p), arg2));
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* faccessat(2) */
+static abi_long do_bsd_faccessat(abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg2);
+    ret = get_errno(faccessat(arg1, p, arg3, arg4)); /* XXX path(p)? */
+    UNLOCK_PATH(p, arg2);
+
+    return ret;
+}
+
 #endif /* BSD_FILE_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index f7d09909925..7b7af914e49 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -285,6 +285,22 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd_closefrom(arg1);
         break;
 
+    case TARGET_FREEBSD_NR_revoke: /* revoke(2) */
+        ret = do_bsd_revoke(arg1);
+        break;
+
+    case TARGET_FREEBSD_NR_access: /* access(2) */
+        ret = do_bsd_access(arg1, arg2);
+        break;
+
+    case TARGET_FREEBSD_NR_eaccess: /* eaccess(2) */
+        ret = do_bsd_eaccess(arg1, arg2);
+        break;
+
+    case TARGET_FREEBSD_NR_faccessat: /* faccessat(2) */
+        ret = do_bsd_faccessat(arg1, arg2, arg3, arg4);
+        break;
+
     default:
         qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
         ret = -TARGET_ENOSYS;
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 04/11] bsd-user: Implement chdir and fchdir
  2022-06-14  4:19 [PATCH v2 00/11] bsd-user: Next round of syscalls Warner Losh
                   ` (2 preceding siblings ...)
  2022-06-14  4:20 ` [PATCH v2 03/11] bsd-user: Implement revoke, access, eaccess and faccessat Warner Losh
@ 2022-06-14  4:20 ` Warner Losh
  2022-06-14  4:20 ` [PATCH v2 05/11] bsd-user: Implement rename and renameat Warner Losh
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Warner Losh @ 2022-06-14  4:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kyle Evans, arrowd, Richard Henderson, jrtc27, Warner Losh, def,
	Stacey Son

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-file.h           | 19 +++++++++++++++++++
 bsd-user/freebsd/os-syscall.c |  8 ++++++++
 2 files changed, 27 insertions(+)

diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
index 6ff2be24e30..bc0a0c08d55 100644
--- a/bsd-user/bsd-file.h
+++ b/bsd-user/bsd-file.h
@@ -311,4 +311,23 @@ static abi_long do_bsd_faccessat(abi_long arg1, abi_long arg2,
     return ret;
 }
 
+/* chdir(2) */
+static abi_long do_bsd_chdir(abi_long arg1)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(chdir(p)); /* XXX  path(p)? */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* fchdir(2) */
+static abi_long do_bsd_fchdir(abi_long arg1)
+{
+    return get_errno(fchdir(arg1));
+}
+
 #endif /* BSD_FILE_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 7b7af914e49..8698db358c1 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -301,6 +301,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd_faccessat(arg1, arg2, arg3, arg4);
         break;
 
+    case TARGET_FREEBSD_NR_chdir: /* chdir(2) */
+        ret = do_bsd_chdir(arg1);
+        break;
+
+    case TARGET_FREEBSD_NR_fchdir: /* fchdir(2) */
+        ret = do_bsd_fchdir(arg1);
+        break;
+
     default:
         qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
         ret = -TARGET_ENOSYS;
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 05/11] bsd-user: Implement rename and renameat
  2022-06-14  4:19 [PATCH v2 00/11] bsd-user: Next round of syscalls Warner Losh
                   ` (3 preceding siblings ...)
  2022-06-14  4:20 ` [PATCH v2 04/11] bsd-user: Implement chdir and fchdir Warner Losh
@ 2022-06-14  4:20 ` Warner Losh
  2022-06-14  4:20 ` [PATCH v2 06/11] bsd-user: Implement link, linkat, unlink and unlinkat Warner Losh
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Warner Losh @ 2022-06-14  4:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kyle Evans, arrowd, Richard Henderson, jrtc27, Warner Losh, def,
	Stacey Son, Jung-uk Kim

Plus the helper LOCK_PATH2 and UNLOCK_PATH2 macros.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Jung-uk Kim <jkim@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-file.h           | 45 +++++++++++++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c |  8 +++++++
 2 files changed, 53 insertions(+)

diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
index bc0a0c08d55..fd8aba96180 100644
--- a/bsd-user/bsd-file.h
+++ b/bsd-user/bsd-file.h
@@ -32,6 +32,24 @@ do {                                        \
 
 #define UNLOCK_PATH(p, arg)     unlock_user(p, arg, 0)
 
+#define LOCK_PATH2(p1, arg1, p2, arg2)      \
+do {                                        \
+    (p1) = lock_user_string(arg1);          \
+    if ((p1) == NULL) {                     \
+        return -TARGET_EFAULT;              \
+    }                                       \
+    (p2) = lock_user_string(arg2);          \
+    if ((p2) == NULL) {                     \
+        unlock_user(p1, arg1, 0);           \
+        return -TARGET_EFAULT;              \
+    }                                       \
+} while (0)
+
+#define UNLOCK_PATH2(p1, arg1, p2, arg2)    \
+do {                                        \
+    unlock_user(p2, arg2, 0);               \
+    unlock_user(p1, arg1, 0);               \
+} while (0)
 
 extern struct iovec *lock_iovec(int type, abi_ulong target_addr, int count,
         int copy);
@@ -330,4 +348,31 @@ static abi_long do_bsd_fchdir(abi_long arg1)
     return get_errno(fchdir(arg1));
 }
 
+/* rename(2) */
+static abi_long do_bsd_rename(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    void *p1, *p2;
+
+    LOCK_PATH2(p1, arg1, p2, arg2);
+    ret = get_errno(rename(p1, p2)); /* XXX path(p1), path(p2) */
+    UNLOCK_PATH2(p1, arg1, p2, arg2);
+
+    return ret;
+}
+
+/* renameat(2) */
+static abi_long do_bsd_renameat(abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4)
+{
+    abi_long ret;
+    void *p1, *p2;
+
+    LOCK_PATH2(p1, arg2, p2, arg4);
+    ret = get_errno(renameat(arg1, p1, arg3, p2));
+    UNLOCK_PATH2(p1, arg2, p2, arg4);
+
+    return ret;
+}
+
 #endif /* BSD_FILE_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 8698db358c1..2d62a546328 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -309,6 +309,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd_fchdir(arg1);
         break;
 
+    case TARGET_FREEBSD_NR_rename: /* rename(2) */
+        ret = do_bsd_rename(arg1, arg2);
+        break;
+
+    case TARGET_FREEBSD_NR_renameat: /* renameat(2) */
+        ret = do_bsd_renameat(arg1, arg2, arg3, arg4);
+        break;
+
     default:
         qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
         ret = -TARGET_ENOSYS;
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 06/11] bsd-user: Implement link, linkat, unlink and unlinkat
  2022-06-14  4:19 [PATCH v2 00/11] bsd-user: Next round of syscalls Warner Losh
                   ` (4 preceding siblings ...)
  2022-06-14  4:20 ` [PATCH v2 05/11] bsd-user: Implement rename and renameat Warner Losh
@ 2022-06-14  4:20 ` Warner Losh
  2022-06-14  4:20 ` [PATCH v2 07/11] bsd-user: Implement mkdir and mkdirat Warner Losh
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Warner Losh @ 2022-06-14  4:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kyle Evans, arrowd, Richard Henderson, jrtc27, Warner Losh, def,
	Stacey Son, Jung-uk Kim

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Jung-uk Kim <jkim@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-file.h           | 54 +++++++++++++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c | 16 +++++++++++
 2 files changed, 70 insertions(+)

diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
index fd8aba96180..93e142d46e7 100644
--- a/bsd-user/bsd-file.h
+++ b/bsd-user/bsd-file.h
@@ -375,4 +375,58 @@ static abi_long do_bsd_renameat(abi_long arg1, abi_long arg2,
     return ret;
 }
 
+/* link(2) */
+static abi_long do_bsd_link(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    void *p1, *p2;
+
+    LOCK_PATH2(p1, arg1, p2, arg2);
+    ret = get_errno(link(p1, p2)); /* XXX path(p1), path(p2) */
+    UNLOCK_PATH2(p1, arg1, p2, arg2);
+
+    return ret;
+}
+
+/* linkat(2) */
+static abi_long do_bsd_linkat(abi_long arg1, abi_long arg2,
+        abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    abi_long ret;
+    void *p1, *p2;
+
+    LOCK_PATH2(p1, arg2, p2, arg4);
+    ret = get_errno(linkat(arg1, p1, arg3, p2, arg5));
+    UNLOCK_PATH2(p1, arg2, p2, arg4);
+
+    return ret;
+}
+
+/* unlink(2) */
+static abi_long do_bsd_unlink(abi_long arg1)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(unlink(p)); /* XXX path(p) */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* unlinkat(2) */
+static abi_long do_bsd_unlinkat(abi_long arg1, abi_long arg2,
+        abi_long arg3)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg2);
+    ret = get_errno(unlinkat(arg1, p, arg3)); /* XXX path(p) */
+    UNLOCK_PATH(p, arg2);
+
+    return ret;
+}
+
 #endif /* BSD_FILE_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 2d62a546328..c847e4d20c6 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -317,6 +317,22 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd_renameat(arg1, arg2, arg3, arg4);
         break;
 
+    case TARGET_FREEBSD_NR_link: /* link(2) */
+        ret = do_bsd_link(arg1, arg2);
+        break;
+
+    case TARGET_FREEBSD_NR_linkat: /* linkat(2) */
+        ret = do_bsd_linkat(arg1, arg2, arg3, arg4, arg5);
+        break;
+
+    case TARGET_FREEBSD_NR_unlink: /* unlink(2) */
+        ret = do_bsd_unlink(arg1);
+        break;
+
+    case TARGET_FREEBSD_NR_unlinkat: /* unlinkat(2) */
+        ret = do_bsd_unlinkat(arg1, arg2, arg3);
+        break;
+
     default:
         qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
         ret = -TARGET_ENOSYS;
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 07/11] bsd-user: Implement mkdir and mkdirat
  2022-06-14  4:19 [PATCH v2 00/11] bsd-user: Next round of syscalls Warner Losh
                   ` (5 preceding siblings ...)
  2022-06-14  4:20 ` [PATCH v2 06/11] bsd-user: Implement link, linkat, unlink and unlinkat Warner Losh
@ 2022-06-14  4:20 ` Warner Losh
  2022-06-14  4:20 ` [PATCH v2 08/11] bsd-user: Implement rmdir and undocumented __getcwd Warner Losh
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Warner Losh @ 2022-06-14  4:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kyle Evans, arrowd, Richard Henderson, jrtc27, Warner Losh, def,
	Stacey Son

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-file.h           | 27 +++++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c |  8 ++++++++
 2 files changed, 35 insertions(+)

diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
index 93e142d46e7..a4c6dd52a20 100644
--- a/bsd-user/bsd-file.h
+++ b/bsd-user/bsd-file.h
@@ -429,4 +429,31 @@ static abi_long do_bsd_unlinkat(abi_long arg1, abi_long arg2,
     return ret;
 }
 
+/* mkdir(2) */
+static abi_long do_bsd_mkdir(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(mkdir(p, arg2)); /* XXX path(p) */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* mkdirat(2) */
+static abi_long do_bsd_mkdirat(abi_long arg1, abi_long arg2,
+        abi_long arg3)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg2);
+    ret = get_errno(mkdirat(arg1, p, arg3));
+    UNLOCK_PATH(p, arg2);
+
+    return ret;
+}
+
 #endif /* BSD_FILE_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index c847e4d20c6..9381ddb5be1 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -333,6 +333,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd_unlinkat(arg1, arg2, arg3);
         break;
 
+    case TARGET_FREEBSD_NR_mkdir: /* mkdir(2) */
+        ret = do_bsd_mkdir(arg1, arg2);
+        break;
+
+    case TARGET_FREEBSD_NR_mkdirat: /* mkdirat(2) */
+        ret = do_bsd_mkdirat(arg1, arg2, arg3);
+        break;
+
     default:
         qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
         ret = -TARGET_ENOSYS;
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 08/11] bsd-user: Implement rmdir and undocumented __getcwd
  2022-06-14  4:19 [PATCH v2 00/11] bsd-user: Next round of syscalls Warner Losh
                   ` (6 preceding siblings ...)
  2022-06-14  4:20 ` [PATCH v2 07/11] bsd-user: Implement mkdir and mkdirat Warner Losh
@ 2022-06-14  4:20 ` Warner Losh
  2022-06-14  4:46   ` Richard Henderson
  2022-06-14  4:20 ` [PATCH v2 09/11] bsd-user: Implement dup and dup2 Warner Losh
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 13+ messages in thread
From: Warner Losh @ 2022-06-14  4:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kyle Evans, arrowd, Richard Henderson, jrtc27, Warner Losh, def,
	Stacey Son, Jung-uk Kim

Implemenet rmdir and __getcwd. __getcwd is the undocumented
back end to getcwd(3).

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Jung-uk Kim <jkim@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsd-file.h           | 29 +++++++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c |  8 ++++++++
 2 files changed, 37 insertions(+)

diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
index a4c6dd52a20..8ec53145894 100644
--- a/bsd-user/bsd-file.h
+++ b/bsd-user/bsd-file.h
@@ -456,4 +456,33 @@ static abi_long do_bsd_mkdirat(abi_long arg1, abi_long arg2,
     return ret;
 }
 
+/* rmdir(2) */
+static abi_long do_bsd_rmdir(abi_long arg1)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    ret = get_errno(rmdir(p)); /* XXX path(p)? */
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* undocumented __getcwd(char *buf, size_t len)  system call */
+static abi_long do_bsd___getcwd(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    void *p;
+
+    p = lock_user(VERIFY_WRITE, arg1, arg2, 0);
+    if (p == NULL) {
+        return -TARGET_EFAULT;
+    }
+    ret = safe_syscall(SYS___getcwd, p, arg2);
+    unlock_user(p, arg1, ret == 0 ? strlen(p) + 1 : 0);
+
+    return get_errno(ret);
+}
+
 #endif /* BSD_FILE_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 9381ddb5be1..e28a566d6c3 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -341,6 +341,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd_mkdirat(arg1, arg2, arg3);
         break;
 
+    case TARGET_FREEBSD_NR_rmdir: /* rmdir(2) (XXX no rmdirat()?) */
+        ret = do_bsd_rmdir(arg1);
+        break;
+
+    case TARGET_FREEBSD_NR___getcwd: /* undocumented __getcwd() */
+        ret = do_bsd___getcwd(arg1, arg2);
+        break;
+
     default:
         qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
         ret = -TARGET_ENOSYS;
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 09/11] bsd-user: Implement dup and dup2
  2022-06-14  4:19 [PATCH v2 00/11] bsd-user: Next round of syscalls Warner Losh
                   ` (7 preceding siblings ...)
  2022-06-14  4:20 ` [PATCH v2 08/11] bsd-user: Implement rmdir and undocumented __getcwd Warner Losh
@ 2022-06-14  4:20 ` Warner Losh
  2022-06-14  4:20 ` [PATCH v2 10/11] bsd-user: Implement trunctate and ftruncate Warner Losh
  2022-06-14  4:20 ` [PATCH v2 11/11] bsd-user: Implement acct and sync Warner Losh
  10 siblings, 0 replies; 13+ messages in thread
From: Warner Losh @ 2022-06-14  4:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kyle Evans, arrowd, Richard Henderson, jrtc27, Warner Losh, def,
	Stacey Son

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-file.h           | 12 ++++++++++++
 bsd-user/freebsd/os-syscall.c |  8 ++++++++
 2 files changed, 20 insertions(+)

diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
index 8ec53145894..021541ad2e0 100644
--- a/bsd-user/bsd-file.h
+++ b/bsd-user/bsd-file.h
@@ -485,4 +485,16 @@ static abi_long do_bsd___getcwd(abi_long arg1, abi_long arg2)
     return get_errno(ret);
 }
 
+/* dup(2) */
+static abi_long do_bsd_dup(abi_long arg1)
+{
+    return get_errno(dup(arg1));
+}
+
+/* dup2(2) */
+static abi_long do_bsd_dup2(abi_long arg1, abi_long arg2)
+{
+    return get_errno(dup2(arg1, arg2));
+}
+
 #endif /* BSD_FILE_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index e28a566d6c3..d9ebb9d50d6 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -349,6 +349,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd___getcwd(arg1, arg2);
         break;
 
+    case TARGET_FREEBSD_NR_dup: /* dup(2) */
+        ret = do_bsd_dup(arg1);
+        break;
+
+    case TARGET_FREEBSD_NR_dup2: /* dup2(2) */
+        ret = do_bsd_dup2(arg1, arg2);
+        break;
+
     default:
         qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
         ret = -TARGET_ENOSYS;
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 10/11] bsd-user: Implement trunctate and ftruncate
  2022-06-14  4:19 [PATCH v2 00/11] bsd-user: Next round of syscalls Warner Losh
                   ` (8 preceding siblings ...)
  2022-06-14  4:20 ` [PATCH v2 09/11] bsd-user: Implement dup and dup2 Warner Losh
@ 2022-06-14  4:20 ` Warner Losh
  2022-06-14  4:20 ` [PATCH v2 11/11] bsd-user: Implement acct and sync Warner Losh
  10 siblings, 0 replies; 13+ messages in thread
From: Warner Losh @ 2022-06-14  4:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kyle Evans, arrowd, Richard Henderson, jrtc27, Warner Losh, def,
	Stacey Son

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-file.h           | 29 +++++++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c |  8 ++++++++
 2 files changed, 37 insertions(+)

diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
index 021541ad2e0..fda36894605 100644
--- a/bsd-user/bsd-file.h
+++ b/bsd-user/bsd-file.h
@@ -497,4 +497,33 @@ static abi_long do_bsd_dup2(abi_long arg1, abi_long arg2)
     return get_errno(dup2(arg1, arg2));
 }
 
+/* truncate(2) */
+static abi_long do_bsd_truncate(void *cpu_env, abi_long arg1,
+        abi_long arg2, abi_long arg3, abi_long arg4)
+{
+    abi_long ret;
+    void *p;
+
+    LOCK_PATH(p, arg1);
+    if (regpairs_aligned(cpu_env) != 0) {
+        arg2 = arg3;
+        arg3 = arg4;
+    }
+    ret = get_errno(truncate(p, target_arg64(arg2, arg3)));
+    UNLOCK_PATH(p, arg1);
+
+    return ret;
+}
+
+/* ftruncate(2) */
+static abi_long do_bsd_ftruncate(void *cpu_env, abi_long arg1,
+        abi_long arg2, abi_long arg3, abi_long arg4)
+{
+    if (regpairs_aligned(cpu_env) != 0) {
+        arg2 = arg3;
+        arg3 = arg4;
+    }
+    return get_errno(ftruncate(arg1, target_arg64(arg2, arg3)));
+}
+
 #endif /* BSD_FILE_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index d9ebb9d50d6..3c8f6cad0e8 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -357,6 +357,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd_dup2(arg1, arg2);
         break;
 
+    case TARGET_FREEBSD_NR_truncate: /* truncate(2) */
+        ret = do_bsd_truncate(cpu_env, arg1, arg2, arg3, arg4);
+        break;
+
+    case TARGET_FREEBSD_NR_ftruncate: /* ftruncate(2) */
+        ret = do_bsd_ftruncate(cpu_env, arg1, arg2, arg3, arg4);
+        break;
+
     default:
         qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
         ret = -TARGET_ENOSYS;
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 11/11] bsd-user: Implement acct and sync
  2022-06-14  4:19 [PATCH v2 00/11] bsd-user: Next round of syscalls Warner Losh
                   ` (9 preceding siblings ...)
  2022-06-14  4:20 ` [PATCH v2 10/11] bsd-user: Implement trunctate and ftruncate Warner Losh
@ 2022-06-14  4:20 ` Warner Losh
  10 siblings, 0 replies; 13+ messages in thread
From: Warner Losh @ 2022-06-14  4:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kyle Evans, arrowd, Richard Henderson, jrtc27, Warner Losh, def,
	Stacey Son

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-file.h           | 23 +++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c |  8 ++++++++
 2 files changed, 31 insertions(+)

diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
index fda36894605..b2dca586129 100644
--- a/bsd-user/bsd-file.h
+++ b/bsd-user/bsd-file.h
@@ -526,4 +526,27 @@ static abi_long do_bsd_ftruncate(void *cpu_env, abi_long arg1,
     return get_errno(ftruncate(arg1, target_arg64(arg2, arg3)));
 }
 
+/* acct(2) */
+static abi_long do_bsd_acct(abi_long arg1)
+{
+    abi_long ret;
+    void *p;
+
+    if (arg1 == 0) {
+        ret = get_errno(acct(NULL));
+    } else {
+        LOCK_PATH(p, arg1);
+        ret = get_errno(acct(path(p)));
+        UNLOCK_PATH(p, arg1);
+    }
+    return ret;
+}
+
+/* sync(2) */
+static abi_long do_bsd_sync(void)
+{
+    sync();
+    return 0;
+}
+
 #endif /* BSD_FILE_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 3c8f6cad0e8..2623caf8007 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -365,6 +365,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd_ftruncate(cpu_env, arg1, arg2, arg3, arg4);
         break;
 
+    case TARGET_FREEBSD_NR_acct: /* acct(2) */
+        ret = do_bsd_acct(arg1);
+        break;
+
+    case TARGET_FREEBSD_NR_sync: /* sync(2) */
+        ret = do_bsd_sync();
+        break;
+
     default:
         qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
         ret = -TARGET_ENOSYS;
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 08/11] bsd-user: Implement rmdir and undocumented __getcwd
  2022-06-14  4:20 ` [PATCH v2 08/11] bsd-user: Implement rmdir and undocumented __getcwd Warner Losh
@ 2022-06-14  4:46   ` Richard Henderson
  0 siblings, 0 replies; 13+ messages in thread
From: Richard Henderson @ 2022-06-14  4:46 UTC (permalink / raw)
  To: Warner Losh, qemu-devel
  Cc: Kyle Evans, arrowd, jrtc27, def, Stacey Son, Jung-uk Kim

On 6/13/22 21:20, Warner Losh wrote:
> Implemenet rmdir and __getcwd. __getcwd is the undocumented
> back end to getcwd(3).
> 
> Signed-off-by: Stacey Son <sson@FreeBSD.org>
> Signed-off-by: Jung-uk Kim <jkim@FreeBSD.org>
> Signed-off-by: Warner Losh <imp@bsdimp.com>

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-06-14  4:49 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-14  4:19 [PATCH v2 00/11] bsd-user: Next round of syscalls Warner Losh
2022-06-14  4:20 ` [PATCH v2 01/11] bsd-user: Implement open, openat and close Warner Losh
2022-06-14  4:20 ` [PATCH v2 02/11] bsd-user: Implement fdatasync, fsync and close_from Warner Losh
2022-06-14  4:20 ` [PATCH v2 03/11] bsd-user: Implement revoke, access, eaccess and faccessat Warner Losh
2022-06-14  4:20 ` [PATCH v2 04/11] bsd-user: Implement chdir and fchdir Warner Losh
2022-06-14  4:20 ` [PATCH v2 05/11] bsd-user: Implement rename and renameat Warner Losh
2022-06-14  4:20 ` [PATCH v2 06/11] bsd-user: Implement link, linkat, unlink and unlinkat Warner Losh
2022-06-14  4:20 ` [PATCH v2 07/11] bsd-user: Implement mkdir and mkdirat Warner Losh
2022-06-14  4:20 ` [PATCH v2 08/11] bsd-user: Implement rmdir and undocumented __getcwd Warner Losh
2022-06-14  4:46   ` Richard Henderson
2022-06-14  4:20 ` [PATCH v2 09/11] bsd-user: Implement dup and dup2 Warner Losh
2022-06-14  4:20 ` [PATCH v2 10/11] bsd-user: Implement trunctate and ftruncate Warner Losh
2022-06-14  4:20 ` [PATCH v2 11/11] bsd-user: Implement acct and sync Warner Losh

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.