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

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...

I've tried to lump these together with related functions in the same change, all
less than 100 lines per change (most less than 40). This represents a little
over 1/3 of the remaining system calls related to files (we have quite a few
more cagegories to go through). I think the lumping represents a good trade-off
between 'small enough to review' and 'few enough parts to not add too much
overhead' vs 'one commit per system call' which would have bloated this series
to 35 pieces. I hope to do the remaining system calls at this chunk granularity
and maybe twice as many parts to get through the ~15k backlog I still have to go
through.

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           | 369 ++++++++++++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c | 116 +++++++++++
 bsd-user/syscall_defs.h       |   4 +
 3 files changed, 489 insertions(+)

-- 
2.33.1



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

* [PATCH 01/11] bsd-user: Implement open, openat and close
  2022-06-12 20:48 [PATCH 00/11] bsd-user: Next round of syscalls Warner Losh
@ 2022-06-12 20:48 ` Warner Losh
  2022-06-13 19:45   ` Richard Henderson
  2022-06-12 20:48 ` [PATCH 02/11] bsd-user: Implement fdatasync, fsync and close_from Warner Losh
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 26+ messages in thread
From: Warner Losh @ 2022-06-12 20:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: jrtc27, Warner Losh, def, arrowd, Kyle Evans, Richard Henderson,
	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>
---
 bsd-user/bsd-file.h           | 50 +++++++++++++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c | 16 +++++++++++
 bsd-user/syscall_defs.h       |  4 +++
 3 files changed, 70 insertions(+)

diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
index e9e2c85eb67..fb54905b46f 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,40 @@ 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] 26+ messages in thread

* [PATCH 02/11] bsd-user: Implement fdatasync, fsync and close_from
  2022-06-12 20:48 [PATCH 00/11] bsd-user: Next round of syscalls Warner Losh
  2022-06-12 20:48 ` [PATCH 01/11] bsd-user: Implement open, openat and close Warner Losh
@ 2022-06-12 20:48 ` Warner Losh
  2022-06-13 19:46   ` Richard Henderson
  2022-06-12 20:48 ` [PATCH 03/11] bsd-user: Implement revoke, access, eaccess and faccessat Warner Losh
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 26+ messages in thread
From: Warner Losh @ 2022-06-12 20:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: jrtc27, Warner Losh, def, arrowd, Kyle Evans, Richard Henderson,
	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>
---
 bsd-user/bsd-file.h           | 22 ++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c | 12 ++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
index fb54905b46f..3e0f160e312 100644
--- a/bsd-user/bsd-file.h
+++ b/bsd-user/bsd-file.h
@@ -240,4 +240,26 @@ 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] 26+ messages in thread

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

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 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 3e0f160e312..37b3efccd2c 100644
--- a/bsd-user/bsd-file.h
+++ b/bsd-user/bsd-file.h
@@ -262,4 +262,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] 26+ messages in thread

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

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

diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
index 37b3efccd2c..8e5d302972c 100644
--- a/bsd-user/bsd-file.h
+++ b/bsd-user/bsd-file.h
@@ -315,4 +315,24 @@ 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] 26+ messages in thread

* [PATCH 05/11] bsd-user: Implement rename and renameat
  2022-06-12 20:48 [PATCH 00/11] bsd-user: Next round of syscalls Warner Losh
                   ` (3 preceding siblings ...)
  2022-06-12 20:48 ` [PATCH 04/11] bsd-user: Implement chdir and fchdir Warner Losh
@ 2022-06-12 20:48 ` Warner Losh
  2022-06-13 19:49   ` Richard Henderson
  2022-06-12 20:48 ` [PATCH 06/11] bsd-user: Implement link, linkat, unlink and unlinkat Warner Losh
                   ` (5 subsequent siblings)
  10 siblings, 1 reply; 26+ messages in thread
From: Warner Losh @ 2022-06-12 20:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: jrtc27, Warner Losh, def, arrowd, Kyle Evans, Richard Henderson,
	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>
---
 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 8e5d302972c..d75883ce95f 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);
@@ -335,4 +353,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] 26+ messages in thread

* [PATCH 06/11] bsd-user: Implement link, linkat, unlink and unlinkat
  2022-06-12 20:48 [PATCH 00/11] bsd-user: Next round of syscalls Warner Losh
                   ` (4 preceding siblings ...)
  2022-06-12 20:48 ` [PATCH 05/11] bsd-user: Implement rename and renameat Warner Losh
@ 2022-06-12 20:48 ` Warner Losh
  2022-06-13 19:49   ` Richard Henderson
  2022-06-12 20:48 ` [PATCH 07/11] bsd-user: Implement mkdir and mkdirat Warner Losh
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 26+ messages in thread
From: Warner Losh @ 2022-06-12 20:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: jrtc27, Warner Losh, def, arrowd, Kyle Evans, Richard Henderson,
	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>
---
 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 d75883ce95f..08b1d3a53a9 100644
--- a/bsd-user/bsd-file.h
+++ b/bsd-user/bsd-file.h
@@ -380,4 +380,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] 26+ messages in thread

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

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 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 08b1d3a53a9..35036364ad8 100644
--- a/bsd-user/bsd-file.h
+++ b/bsd-user/bsd-file.h
@@ -434,4 +434,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] 26+ messages in thread

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

Implemenet rmdir and __getcwd. Declare __getcwd as extern because
there's no installed FreeBSD header that has it. It's used internally by
libc, which doesn't provide an external declaration, but does export the
symbol.

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           | 30 ++++++++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c |  8 ++++++++
 2 files changed, 38 insertions(+)

diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
index 35036364ad8..500d6ba78b9 100644
--- a/bsd-user/bsd-file.h
+++ b/bsd-user/bsd-file.h
@@ -55,6 +55,7 @@ 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);
+extern int __getcwd(char *path, size_t len);
 
 int safe_open(const char *path, int flags, mode_t mode);
 int safe_openat(int fd, const char *path, int flags, mode_t mode);
@@ -461,4 +462,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 = __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] 26+ messages in thread

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

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

diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
index 500d6ba78b9..73263ba482f 100644
--- a/bsd-user/bsd-file.h
+++ b/bsd-user/bsd-file.h
@@ -491,4 +491,18 @@ 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] 26+ messages in thread

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

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

diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
index 73263ba482f..ccfa65ec5e9 100644
--- a/bsd-user/bsd-file.h
+++ b/bsd-user/bsd-file.h
@@ -505,4 +505,34 @@ 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] 26+ messages in thread

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

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

diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
index ccfa65ec5e9..6b20442ecdc 100644
--- a/bsd-user/bsd-file.h
+++ b/bsd-user/bsd-file.h
@@ -535,4 +535,28 @@ 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] 26+ messages in thread

* Re: [PATCH 01/11] bsd-user: Implement open, openat and close
  2022-06-12 20:48 ` [PATCH 01/11] bsd-user: Implement open, openat and close Warner Losh
@ 2022-06-13 19:45   ` Richard Henderson
  0 siblings, 0 replies; 26+ messages in thread
From: Richard Henderson @ 2022-06-13 19:45 UTC (permalink / raw)
  To: Warner Losh, qemu-devel
  Cc: jrtc27, def, arrowd, Kyle Evans, Stacey Son, Jung-uk Kim

On 6/12/22 13:48, Warner Losh wrote:
> +static inline abi_long do_bsd_close(abi_long arg1)
> +{
> +

Watch the extra linefeed.  Otherwise,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~


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

* Re: [PATCH 02/11] bsd-user: Implement fdatasync, fsync and close_from
  2022-06-12 20:48 ` [PATCH 02/11] bsd-user: Implement fdatasync, fsync and close_from Warner Losh
@ 2022-06-13 19:46   ` Richard Henderson
  0 siblings, 0 replies; 26+ messages in thread
From: Richard Henderson @ 2022-06-13 19:46 UTC (permalink / raw)
  To: Warner Losh, qemu-devel
  Cc: jrtc27, def, arrowd, Kyle Evans, Stacey Son, Jung-uk Kim

On 6/12/22 13:48, Warner Losh wrote:
> 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>
> ---
>   bsd-user/bsd-file.h           | 22 ++++++++++++++++++++++
>   bsd-user/freebsd/os-syscall.c | 12 ++++++++++++
>   2 files changed, 34 insertions(+)
> 
> diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
> index fb54905b46f..3e0f160e312 100644
> --- a/bsd-user/bsd-file.h
> +++ b/bsd-user/bsd-file.h
> @@ -240,4 +240,26 @@ 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);
> +}

All with extra linefeed.  Otherwise,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~


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

* Re: [PATCH 03/11] bsd-user: Implement revoke, access, eaccess and faccessat
  2022-06-12 20:48 ` [PATCH 03/11] bsd-user: Implement revoke, access, eaccess and faccessat Warner Losh
@ 2022-06-13 19:47   ` Richard Henderson
  2022-06-13 23:07   ` Philippe Mathieu-Daudé via
  1 sibling, 0 replies; 26+ messages in thread
From: Richard Henderson @ 2022-06-13 19:47 UTC (permalink / raw)
  To: Warner Losh, qemu-devel; +Cc: jrtc27, def, arrowd, Kyle Evans, Stacey Son

On 6/12/22 13:48, Warner Losh wrote:
> Signed-off-by: Stacey Son<sson@FreeBSD.org>
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/bsd-file.h           | 53 +++++++++++++++++++++++++++++++++++
>   bsd-user/freebsd/os-syscall.c | 16 +++++++++++
>   2 files changed, 69 insertions(+)

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

r~


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

* Re: [PATCH 04/11] bsd-user: Implement chdir and fchdir
  2022-06-12 20:48 ` [PATCH 04/11] bsd-user: Implement chdir and fchdir Warner Losh
@ 2022-06-13 19:48   ` Richard Henderson
  0 siblings, 0 replies; 26+ messages in thread
From: Richard Henderson @ 2022-06-13 19:48 UTC (permalink / raw)
  To: Warner Losh, qemu-devel; +Cc: jrtc27, def, arrowd, Kyle Evans, Stacey Son

On 6/12/22 13:48, Warner Losh wrote:
> Signed-off-by: Stacey Son <sson@FreeBSD.org>
> Signed-off-by: Warner Losh <imp@bsdimp.com>
> ---
>   bsd-user/bsd-file.h           | 20 ++++++++++++++++++++
>   bsd-user/freebsd/os-syscall.c |  8 ++++++++
>   2 files changed, 28 insertions(+)

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

r~


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

* Re: [PATCH 05/11] bsd-user: Implement rename and renameat
  2022-06-12 20:48 ` [PATCH 05/11] bsd-user: Implement rename and renameat Warner Losh
@ 2022-06-13 19:49   ` Richard Henderson
  0 siblings, 0 replies; 26+ messages in thread
From: Richard Henderson @ 2022-06-13 19:49 UTC (permalink / raw)
  To: Warner Losh, qemu-devel
  Cc: jrtc27, def, arrowd, Kyle Evans, Stacey Son, Jung-uk Kim

On 6/12/22 13:48, Warner Losh wrote:
> 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>
> ---
>   bsd-user/bsd-file.h           | 45 +++++++++++++++++++++++++++++++++++
>   bsd-user/freebsd/os-syscall.c |  8 +++++++
>   2 files changed, 53 insertions(+)

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

r~


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

* Re: [PATCH 06/11] bsd-user: Implement link, linkat, unlink and unlinkat
  2022-06-12 20:48 ` [PATCH 06/11] bsd-user: Implement link, linkat, unlink and unlinkat Warner Losh
@ 2022-06-13 19:49   ` Richard Henderson
  0 siblings, 0 replies; 26+ messages in thread
From: Richard Henderson @ 2022-06-13 19:49 UTC (permalink / raw)
  To: Warner Losh, qemu-devel
  Cc: jrtc27, def, arrowd, Kyle Evans, Stacey Son, Jung-uk Kim

On 6/12/22 13:48, Warner Losh wrote:
> 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           | 54 +++++++++++++++++++++++++++++++++++
>   bsd-user/freebsd/os-syscall.c | 16 +++++++++++
>   2 files changed, 70 insertions(+)

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

r~


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

* Re: [PATCH 07/11] bsd-user: Implement mkdir and mkdirat
  2022-06-12 20:48 ` [PATCH 07/11] bsd-user: Implement mkdir and mkdirat Warner Losh
@ 2022-06-13 19:50   ` Richard Henderson
  0 siblings, 0 replies; 26+ messages in thread
From: Richard Henderson @ 2022-06-13 19:50 UTC (permalink / raw)
  To: Warner Losh, qemu-devel; +Cc: jrtc27, def, arrowd, Kyle Evans, Stacey Son

On 6/12/22 13:48, Warner Losh wrote:
> Signed-off-by: Stacey Son<sson@FreeBSD.org>
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/bsd-file.h           | 27 +++++++++++++++++++++++++++
>   bsd-user/freebsd/os-syscall.c |  8 ++++++++
>   2 files changed, 35 insertions(+)

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

r~


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

* Re: [PATCH 08/11] bsd-user: Implement rmdir and undocumented -_getcwd
  2022-06-12 20:48 ` [PATCH 08/11] bsd-user: Implement rmdir and undocumented -_getcwd Warner Losh
@ 2022-06-13 19:52   ` Richard Henderson
  2022-06-13 23:45     ` Warner Losh
  0 siblings, 1 reply; 26+ messages in thread
From: Richard Henderson @ 2022-06-13 19:52 UTC (permalink / raw)
  To: Warner Losh, qemu-devel
  Cc: jrtc27, def, arrowd, Kyle Evans, Stacey Son, Jung-uk Kim

On 6/12/22 13:48, Warner Losh wrote:
> Implemenet rmdir and __getcwd. Declare __getcwd as extern because
> there's no installed FreeBSD header that has it. It's used internally by
> libc, which doesn't provide an external declaration, but does export the
> symbol.

Typo in subject: s/-/_/.

> @@ -55,6 +55,7 @@ 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);
> +extern int __getcwd(char *path, size_t len);

Do you really want to rely on this export?
Unless it does something special, I'd just declare a local version of the syscall as you 
do with safe_*.

> +/* undocumented __getcwd(char *buf, size_t len)  system call */

Surely the syscall itself is documented?


r~


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

* Re: [PATCH 09/11] bsd-user: Implement dup and dup2
  2022-06-12 20:48 ` [PATCH 09/11] bsd-user: Implement dup and dup2 Warner Losh
@ 2022-06-13 19:53   ` Richard Henderson
  2022-06-13 21:54     ` Warner Losh
  0 siblings, 1 reply; 26+ messages in thread
From: Richard Henderson @ 2022-06-13 19:53 UTC (permalink / raw)
  To: Warner Losh, qemu-devel; +Cc: jrtc27, def, arrowd, Kyle Evans, Stacey Son

On 6/12/22 13:48, Warner Losh wrote:
> Signed-off-by: Stacey Son <sson@FreeBSD.org>
> Signed-off-by: Warner Losh <imp@bsdimp.com>
> ---
>   bsd-user/bsd-file.h           | 14 ++++++++++++++
>   bsd-user/freebsd/os-syscall.c |  8 ++++++++
>   2 files changed, 22 insertions(+)
> 
> diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
> index 500d6ba78b9..73263ba482f 100644
> --- a/bsd-user/bsd-file.h
> +++ b/bsd-user/bsd-file.h
> @@ -491,4 +491,18 @@ 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));
> +}

Extra lines.  Is this some setting in your editor?  Otherwise,

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


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

* Re: [PATCH 10/11] bsd-user: Implement trunctate and ftruncate
  2022-06-12 20:48 ` [PATCH 10/11] bsd-user: Implement trunctate and ftruncate Warner Losh
@ 2022-06-13 19:54   ` Richard Henderson
  0 siblings, 0 replies; 26+ messages in thread
From: Richard Henderson @ 2022-06-13 19:54 UTC (permalink / raw)
  To: Warner Losh, qemu-devel; +Cc: jrtc27, def, arrowd, Kyle Evans, Stacey Son

On 6/12/22 13:48, Warner Losh wrote:
> +static abi_long do_bsd_ftruncate(void *cpu_env, abi_long arg1,
> +        abi_long arg2, abi_long arg3, abi_long arg4)
> +{
> +

Extra line.  Otherwise,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


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

* Re: [PATCH 11/11] bsd-user: Implement acct and sync
  2022-06-12 20:48 ` [PATCH 11/11] bsd-user: Implement acct and sync Warner Losh
@ 2022-06-13 19:54   ` Richard Henderson
  0 siblings, 0 replies; 26+ messages in thread
From: Richard Henderson @ 2022-06-13 19:54 UTC (permalink / raw)
  To: Warner Losh, qemu-devel; +Cc: jrtc27, def, arrowd, Kyle Evans, Stacey Son

On 6/12/22 13:48, Warner Losh wrote:
> +static abi_long do_bsd_sync(void)
> +{
> +

Extra line, otherwise,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


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

* Re: [PATCH 09/11] bsd-user: Implement dup and dup2
  2022-06-13 19:53   ` Richard Henderson
@ 2022-06-13 21:54     ` Warner Losh
  0 siblings, 0 replies; 26+ messages in thread
From: Warner Losh @ 2022-06-13 21:54 UTC (permalink / raw)
  To: Richard Henderson
  Cc: QEMU Developers, Jessica Clarke, Konrad Witaszczyk, Gleb Popov,
	Kyle Evans, Stacey Son

[-- Attachment #1: Type: text/plain, Size: 1254 bytes --]

On Mon, Jun 13, 2022 at 1:53 PM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 6/12/22 13:48, Warner Losh wrote:
> > Signed-off-by: Stacey Son <sson@FreeBSD.org>
> > Signed-off-by: Warner Losh <imp@bsdimp.com>
> > ---
> >   bsd-user/bsd-file.h           | 14 ++++++++++++++
> >   bsd-user/freebsd/os-syscall.c |  8 ++++++++
> >   2 files changed, 22 insertions(+)
> >
> > diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
> > index 500d6ba78b9..73263ba482f 100644
> > --- a/bsd-user/bsd-file.h
> > +++ b/bsd-user/bsd-file.h
> > @@ -491,4 +491,18 @@ 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));
> > +}
>
> Extra lines.  Is this some setting in your editor?  Otherwise,
>

It's an odd quirk of FreeBSD's style from the 90s until 2020... I'm totally
blind to
it most of the time...


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

Thanks for this, and all the other reviews.

Warner

[-- Attachment #2: Type: text/html, Size: 2149 bytes --]

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

* Re: [PATCH 03/11] bsd-user: Implement revoke, access, eaccess and faccessat
  2022-06-12 20:48 ` [PATCH 03/11] bsd-user: Implement revoke, access, eaccess and faccessat Warner Losh
  2022-06-13 19:47   ` Richard Henderson
@ 2022-06-13 23:07   ` Philippe Mathieu-Daudé via
  1 sibling, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé via @ 2022-06-13 23:07 UTC (permalink / raw)
  To: Warner Losh, qemu-devel
  Cc: jrtc27, def, arrowd, Kyle Evans, Richard Henderson, Stacey Son

On 12/6/22 22:48, Warner Losh wrote:
> Signed-off-by: Stacey Son <sson@FreeBSD.org>
> Signed-off-by: Warner Losh <imp@bsdimp.com>
> ---
>   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 3e0f160e312..37b3efccd2c 100644
> --- a/bsd-user/bsd-file.h
> +++ b/bsd-user/bsd-file.h
> @@ -262,4 +262,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;
> +}

Out of curiosity, what is the problem with path(p) here?

> +/* 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;
> +}


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

* Re: [PATCH 08/11] bsd-user: Implement rmdir and undocumented -_getcwd
  2022-06-13 19:52   ` Richard Henderson
@ 2022-06-13 23:45     ` Warner Losh
  0 siblings, 0 replies; 26+ messages in thread
From: Warner Losh @ 2022-06-13 23:45 UTC (permalink / raw)
  To: Richard Henderson
  Cc: QEMU Developers, Jessica Clarke, Konrad Witaszczyk, Gleb Popov,
	Kyle Evans, Stacey Son, Jung-uk Kim

[-- Attachment #1: Type: text/plain, Size: 1756 bytes --]

On Mon, Jun 13, 2022 at 1:52 PM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 6/12/22 13:48, Warner Losh wrote:
> > Implemenet rmdir and __getcwd. Declare __getcwd as extern because
> > there's no installed FreeBSD header that has it. It's used internally by
> > libc, which doesn't provide an external declaration, but does export the
> > symbol.
>
> Typo in subject: s/-/_/.
>

Indeed.


> > @@ -55,6 +55,7 @@ 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);
> > +extern int __getcwd(char *path, size_t len);
>
> Do you really want to rely on this export?
> Unless it does something special, I'd just declare a local version of the
> syscall as you
> do with safe_*.
>

Indeed not. I was just copying what we've been running, but I see now that
was unwise.
I'll do a safe_syscall directly here since we don't need to call it
anywhere else. I'll do a
sanity check on our upstream and make sure I can still run my favorite
shells, which
I believe use this call.


> > +/* undocumented __getcwd(char *buf, size_t len)  system call */
>
> Surely the syscall itself is documented?
>

One would think it was documented, but there's no man page for it and the
getcwd()
call has some extensions that it implements, plus there's some weird
special cases
that __getcwd() can sometimes return that getcwd() knows how to unwind (the
oddest being that sometimes paths are returned backwards). All these quirks
are not,
alas, documented in any place except the code. Hence the characterization
that this
is undocumented :)... I was rather surprised by this when I went looking.

Warner

[-- Attachment #2: Type: text/html, Size: 2668 bytes --]

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

end of thread, other threads:[~2022-06-13 23:47 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-12 20:48 [PATCH 00/11] bsd-user: Next round of syscalls Warner Losh
2022-06-12 20:48 ` [PATCH 01/11] bsd-user: Implement open, openat and close Warner Losh
2022-06-13 19:45   ` Richard Henderson
2022-06-12 20:48 ` [PATCH 02/11] bsd-user: Implement fdatasync, fsync and close_from Warner Losh
2022-06-13 19:46   ` Richard Henderson
2022-06-12 20:48 ` [PATCH 03/11] bsd-user: Implement revoke, access, eaccess and faccessat Warner Losh
2022-06-13 19:47   ` Richard Henderson
2022-06-13 23:07   ` Philippe Mathieu-Daudé via
2022-06-12 20:48 ` [PATCH 04/11] bsd-user: Implement chdir and fchdir Warner Losh
2022-06-13 19:48   ` Richard Henderson
2022-06-12 20:48 ` [PATCH 05/11] bsd-user: Implement rename and renameat Warner Losh
2022-06-13 19:49   ` Richard Henderson
2022-06-12 20:48 ` [PATCH 06/11] bsd-user: Implement link, linkat, unlink and unlinkat Warner Losh
2022-06-13 19:49   ` Richard Henderson
2022-06-12 20:48 ` [PATCH 07/11] bsd-user: Implement mkdir and mkdirat Warner Losh
2022-06-13 19:50   ` Richard Henderson
2022-06-12 20:48 ` [PATCH 08/11] bsd-user: Implement rmdir and undocumented -_getcwd Warner Losh
2022-06-13 19:52   ` Richard Henderson
2022-06-13 23:45     ` Warner Losh
2022-06-12 20:48 ` [PATCH 09/11] bsd-user: Implement dup and dup2 Warner Losh
2022-06-13 19:53   ` Richard Henderson
2022-06-13 21:54     ` Warner Losh
2022-06-12 20:48 ` [PATCH 10/11] bsd-user: Implement trunctate and ftruncate Warner Losh
2022-06-13 19:54   ` Richard Henderson
2022-06-12 20:48 ` [PATCH 11/11] bsd-user: Implement acct and sync Warner Losh
2022-06-13 19:54   ` Richard Henderson

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.