qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD.
@ 2023-09-25 18:26 Karim Taha
  2023-09-25 18:26 ` [PATCH v6 01/23] bsd-user: Implement struct target_ipc_perm Karim Taha
                   ` (23 more replies)
  0 siblings, 24 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Warner Losh, Richard Henderson, Karim Taha

Upstream the implementation of the following mmap system calls, from the
qemu-bsd-user fork:
   mmap(2), munmap(2),
   mprotect(2),
   msync(2),
   mlock(2), munlock(2), mlockall(2), munlockall(2), mincore(2),
   madvise(2),
   minherit(2),
   shm_open(2),shm_open2(2), shm_rename2(2), shm_unlink(2), shmget(2), shmctl(2), shmat(2),
   shmdt(2)
   brk(2)

Karim Taha (3):
  bsd-user: Implement shm_open2(2) system call
  bsd-user: Add bsd-mem.c to meson.build
  bsd-user: Implment madvise(2) to match the linux-user implementation.

Kyle Evans (1):
  bsd-user: Implement shm_rename(2) system call

Stacey Son (18):
  bsd-user: Implement struct target_ipc_perm
  bsd-user: Implement struct target_shmid_ds
  bsd-user: Declarations for ipc_perm and shmid_ds conversion functions
  bsd-user: Introduce freebsd/os-misc.h to the source tree
  bsd-user: Implement target_set_brk function in bsd-mem.c instead of
    os-syscall.c
  bsd-user: Implement ipc_perm conversion between host and target.
  bsd-user: Implement shmid_ds conversion between host and target.
  bsd-user: Introduce bsd-mem.h to the source tree
  bsd-user: Implement mmap(2) and munmap(2)
  bsd-user: Implement mprotect(2)
  bsd-user: Implement msync(2)
  bsd-user: Implement mlock(2), munlock(2), mlockall(2), munlockall(2),
    minherit(2)
  bsd-user: Implement mincore(2)
  bsd-user: Implement do_obreak function
  bsd-user: Implement shm_open(2)
  bsd-user: Implement shm_unlink(2) and shmget(2)
  bsd-user: Implement shmctl(2)
  bsd-user: Implement shmat(2) and shmdt(2)

Warner Losh (1):
  bsd-user: Add stubs for vadvise(), sbrk() and sstk()

 bsd-user/bsd-mem.c            | 104 ++++++++
 bsd-user/bsd-mem.h            | 452 ++++++++++++++++++++++++++++++++++
 bsd-user/freebsd/os-misc.h    |  94 +++++++
 bsd-user/freebsd/os-syscall.c | 109 +++++++-
 bsd-user/meson.build          |   1 +
 bsd-user/mmap.c               |   2 +-
 bsd-user/qemu-bsd.h           |  45 ++++
 bsd-user/qemu.h               |   1 +
 bsd-user/syscall_defs.h       |  39 +++
 9 files changed, 842 insertions(+), 5 deletions(-)
 create mode 100644 bsd-user/bsd-mem.c
 create mode 100644 bsd-user/bsd-mem.h
 create mode 100644 bsd-user/freebsd/os-misc.h
 create mode 100644 bsd-user/qemu-bsd.h

-- 
2.42.0



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

* [PATCH v6 01/23] bsd-user: Implement struct target_ipc_perm
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
@ 2023-09-25 18:26 ` Karim Taha
  2023-09-25 18:26 ` [PATCH v6 02/23] bsd-user: Implement struct target_shmid_ds Karim Taha
                   ` (22 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Warner Losh, Richard Henderson, Stacey Son, Karim Taha

From: Stacey Son <sson@FreeBSD.org>

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/syscall_defs.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h
index 9c90616baa..4deb4fed35 100644
--- a/bsd-user/syscall_defs.h
+++ b/bsd-user/syscall_defs.h
@@ -55,6 +55,23 @@ struct target_iovec {
     abi_long iov_len;   /* Number of bytes */
 };
 
+/*
+ * sys/ipc.h
+ */
+struct target_ipc_perm {
+    uint32_t    cuid;       /* creator user id */
+    uint32_t    cgid;       /* creator group id */
+    uint32_t    uid;        /* user id */
+    uint32_t    gid;        /* group id */
+    uint16_t    mode;       /* r/w permission */
+    uint16_t    seq;        /* sequence # */
+    abi_long    key;        /* user specified msg/sem/shm key */
+};
+
+#define TARGET_IPC_RMID 0   /* remove identifier */
+#define TARGET_IPC_SET  1   /* set options */
+#define TARGET_IPC_STAT 2   /* get options */
+
 /*
  *  sys/mman.h
  */
-- 
2.42.0



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

* [PATCH v6 02/23] bsd-user: Implement struct target_shmid_ds
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
  2023-09-25 18:26 ` [PATCH v6 01/23] bsd-user: Implement struct target_ipc_perm Karim Taha
@ 2023-09-25 18:26 ` Karim Taha
  2023-09-25 18:26 ` [PATCH v6 03/23] bsd-user: Declarations for ipc_perm and shmid_ds conversion functions Karim Taha
                   ` (21 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Warner Losh, Richard Henderson, Stacey Son, Karim Taha

From: Stacey Son <sson@FreeBSD.org>

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/syscall_defs.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h
index 4deb4fed35..f4a5ae2a12 100644
--- a/bsd-user/syscall_defs.h
+++ b/bsd-user/syscall_defs.h
@@ -72,6 +72,26 @@ struct target_ipc_perm {
 #define TARGET_IPC_SET  1   /* set options */
 #define TARGET_IPC_STAT 2   /* get options */
 
+/*
+ * sys/shm.h
+ */
+struct target_shmid_ds {
+    struct  target_ipc_perm shm_perm; /* peration permission structure */
+    abi_ulong   shm_segsz;  /* size of segment in bytes */
+    int32_t     shm_lpid;   /* process ID of last shared memory op */
+    int32_t     shm_cpid;   /* process ID of creator */
+    int32_t     shm_nattch; /* number of current attaches */
+    target_time_t shm_atime;  /* time of last shmat() */
+    target_time_t shm_dtime;  /* time of last shmdt() */
+    target_time_t shm_ctime;  /* time of last change by shmctl() */
+};
+
+#define N_BSD_SHM_REGIONS   32
+struct bsd_shm_regions {
+    abi_long start;
+    abi_long size;
+};
+
 /*
  *  sys/mman.h
  */
-- 
2.42.0



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

* [PATCH v6 03/23] bsd-user: Declarations for ipc_perm and shmid_ds conversion functions
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
  2023-09-25 18:26 ` [PATCH v6 01/23] bsd-user: Implement struct target_ipc_perm Karim Taha
  2023-09-25 18:26 ` [PATCH v6 02/23] bsd-user: Implement struct target_shmid_ds Karim Taha
@ 2023-09-25 18:26 ` Karim Taha
  2023-09-25 18:26 ` [PATCH v6 04/23] bsd-user: Introduce freebsd/os-misc.h to the source tree Karim Taha
                   ` (20 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Warner Losh, Richard Henderson, Stacey Son, Karim Taha

From: Stacey Son <sson@FreeBSD.org>

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/qemu-bsd.h | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 bsd-user/qemu-bsd.h

diff --git a/bsd-user/qemu-bsd.h b/bsd-user/qemu-bsd.h
new file mode 100644
index 0000000000..46572ece7d
--- /dev/null
+++ b/bsd-user/qemu-bsd.h
@@ -0,0 +1,45 @@
+/*
+ *  BSD conversion extern declarations
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef QEMU_BSD_H
+#define QEMU_BSD_H
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <sys/resource.h>
+#include <sys/sem.h>
+#include <sys/shm.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/uuid.h>
+#include <sys/wait.h>
+#include <netinet/in.h>
+
+/* bsd-mem.c */
+void target_to_host_ipc_perm__locked(struct ipc_perm *host_ip,
+        struct target_ipc_perm *target_ip);
+void host_to_target_ipc_perm__locked(struct target_ipc_perm *target_ip,
+        struct ipc_perm *host_ip);
+abi_long target_to_host_shmid_ds(struct shmid_ds *host_sd,
+        abi_ulong target_addr);
+abi_long host_to_target_shmid_ds(abi_ulong target_addr,
+        struct shmid_ds *host_sd);
+
+#endif /* QEMU_BSD_H */
-- 
2.42.0



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

* [PATCH v6 04/23] bsd-user: Introduce freebsd/os-misc.h to the source tree
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
                   ` (2 preceding siblings ...)
  2023-09-25 18:26 ` [PATCH v6 03/23] bsd-user: Declarations for ipc_perm and shmid_ds conversion functions Karim Taha
@ 2023-09-25 18:26 ` Karim Taha
  2023-09-25 18:26 ` [PATCH v6 05/23] bsd-user: Implement shm_open2(2) system call Karim Taha
                   ` (19 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Warner Losh, Richard Henderson, Stacey Son, Karim Taha

From: Stacey Son <sson@FreeBSD.org>

To preserve the copyright notice and help with the 'Author' info for
subsequent changes to the file.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/freebsd/os-misc.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 bsd-user/freebsd/os-misc.h

diff --git a/bsd-user/freebsd/os-misc.h b/bsd-user/freebsd/os-misc.h
new file mode 100644
index 0000000000..8436ccb2f7
--- /dev/null
+++ b/bsd-user/freebsd/os-misc.h
@@ -0,0 +1,28 @@
+/*
+ *  miscellaneous FreeBSD system call shims
+ *
+ *  Copyright (c) 2013-14 Stacey D. Son
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef OS_MISC_H
+#define OS_MISC_H
+
+#include <sys/cpuset.h>
+#include <sys/random.h>
+#include <sched.h>
+
+
+#endif /* OS_MISC_H */
-- 
2.42.0



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

* [PATCH v6 05/23] bsd-user: Implement shm_open2(2) system call
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
                   ` (3 preceding siblings ...)
  2023-09-25 18:26 ` [PATCH v6 04/23] bsd-user: Introduce freebsd/os-misc.h to the source tree Karim Taha
@ 2023-09-25 18:26 ` Karim Taha
  2023-09-25 18:26 ` [PATCH v6 06/23] bsd-user: Implement shm_rename(2) " Karim Taha
                   ` (18 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Warner Losh, Richard Henderson, Karim Taha, Kyle Evans

Signed-off-by: Kyle Evans <kevans@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/freebsd/os-misc.h    | 42 +++++++++++++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c | 10 +++++++++
 2 files changed, 52 insertions(+)

diff --git a/bsd-user/freebsd/os-misc.h b/bsd-user/freebsd/os-misc.h
index 8436ccb2f7..6b424b7078 100644
--- a/bsd-user/freebsd/os-misc.h
+++ b/bsd-user/freebsd/os-misc.h
@@ -24,5 +24,47 @@
 #include <sys/random.h>
 #include <sched.h>
 
+int shm_open2(const char *path, int flags, mode_t mode, int shmflags,
+    const char *);
+
+#if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048
+/* shm_open2(2) */
+static inline abi_long do_freebsd_shm_open2(abi_ulong pathptr, abi_ulong flags,
+    abi_long mode, abi_ulong shmflags, abi_ulong nameptr)
+{
+    int ret;
+    void *uname, *upath;
+
+    if (pathptr == (uintptr_t)SHM_ANON) {
+        upath = SHM_ANON;
+    } else {
+        upath = lock_user_string(pathptr);
+        if (upath == NULL) {
+            return -TARGET_EFAULT;
+        }
+    }
+
+    uname = NULL;
+    if (nameptr != 0) {
+        uname = lock_user_string(nameptr);
+        if (uname == NULL) {
+            unlock_user(upath, pathptr, 0);
+            return -TARGET_EFAULT;
+        }
+    }
+    ret = get_errno(shm_open2(upath,
+                target_to_host_bitmask(flags, fcntl_flags_tbl), mode,
+                target_to_host_bitmask(shmflags, shmflag_flags_tbl), uname));
+
+    if (upath != SHM_ANON) {
+        unlock_user(upath, pathptr, 0);
+    }
+    if (uname != NULL) {
+        unlock_user(uname, nameptr, 0);
+    }
+    return ret;
+}
+#endif /* __FreeBSD_version >= 1300048 */
+
 
 #endif /* OS_MISC_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index fa60df529e..74146d8c72 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -33,11 +33,13 @@
 #include "signal-common.h"
 #include "user/syscall-trace.h"
 
+/* BSD independent syscall shims */
 #include "bsd-file.h"
 #include "bsd-proc.h"
 
 /* *BSD dependent syscall shims */
 #include "os-stat.h"
+#include "os-misc.h"
 
 /* I/O */
 safe_syscall3(int, open, const char *, path, int, flags, mode_t, mode);
@@ -592,6 +594,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_freebsd_fcntl(arg1, arg2, arg3);
         break;
 
+        /*
+         * Memory management system calls.
+         */
+#if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048
+    case TARGET_FREEBSD_NR_shm_open2: /* shm_open2(2) */
+        ret = do_freebsd_shm_open2(arg1, arg2, arg3, arg4, arg5);
+        break;
+#endif
 
         /*
          * sys{ctl, arch, call}
-- 
2.42.0



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

* [PATCH v6 06/23] bsd-user: Implement shm_rename(2) system call
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
                   ` (4 preceding siblings ...)
  2023-09-25 18:26 ` [PATCH v6 05/23] bsd-user: Implement shm_open2(2) system call Karim Taha
@ 2023-09-25 18:26 ` Karim Taha
  2023-09-25 18:26 ` [PATCH v6 07/23] bsd-user: Add bsd-mem.c to meson.build Karim Taha
                   ` (17 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Warner Losh, Richard Henderson, Kyle Evans, Karim Taha

From: Kyle Evans <kevans@FreeBSD.org>

Signed-off-by: Kyle Evans <kevans@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/freebsd/os-misc.h    | 24 ++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c |  6 ++++++
 2 files changed, 30 insertions(+)

diff --git a/bsd-user/freebsd/os-misc.h b/bsd-user/freebsd/os-misc.h
index 6b424b7078..67e450fe7c 100644
--- a/bsd-user/freebsd/os-misc.h
+++ b/bsd-user/freebsd/os-misc.h
@@ -66,5 +66,29 @@ static inline abi_long do_freebsd_shm_open2(abi_ulong pathptr, abi_ulong flags,
 }
 #endif /* __FreeBSD_version >= 1300048 */
 
+#if defined(__FreeBSD_version) && __FreeBSD_version >= 1300049
+/* shm_rename(2) */
+static inline abi_long do_freebsd_shm_rename(abi_ulong fromptr, abi_ulong toptr,
+        abi_ulong flags)
+{
+    int ret;
+    void *ufrom, *uto;
+
+    ufrom = lock_user_string(fromptr);
+    if (ufrom == NULL) {
+        return -TARGET_EFAULT;
+    }
+    uto = lock_user_string(toptr);
+    if (uto == NULL) {
+        unlock_user(ufrom, fromptr, 0);
+        return -TARGET_EFAULT;
+    }
+    ret = get_errno(shm_rename(ufrom, uto, flags));
+    unlock_user(ufrom, fromptr, 0);
+    unlock_user(uto, toptr, 0);
+
+    return ret;
+}
+#endif /* __FreeBSD_version >= 1300049 */
 
 #endif /* OS_MISC_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 74146d8c72..ae92a2314c 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -603,6 +603,12 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #endif
 
+#if defined(__FreeBSD_version) && __FreeBSD_version >= 1300049
+    case TARGET_FREEBSD_NR_shm_rename: /* shm_rename(2) */
+        ret = do_freebsd_shm_rename(arg1, arg2, arg3);
+        break;
+#endif
+
         /*
          * sys{ctl, arch, call}
          */
-- 
2.42.0



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

* [PATCH v6 07/23] bsd-user: Add bsd-mem.c to meson.build
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
                   ` (5 preceding siblings ...)
  2023-09-25 18:26 ` [PATCH v6 06/23] bsd-user: Implement shm_rename(2) " Karim Taha
@ 2023-09-25 18:26 ` Karim Taha
  2023-09-25 18:26 ` [PATCH v6 08/23] bsd-user: Implement target_set_brk function in bsd-mem.c instead of os-syscall.c Karim Taha
                   ` (16 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Warner Losh, Richard Henderson, Karim Taha

Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsd-mem.c   | 0
 bsd-user/meson.build | 1 +
 2 files changed, 1 insertion(+)
 create mode 100644 bsd-user/bsd-mem.c

diff --git a/bsd-user/bsd-mem.c b/bsd-user/bsd-mem.c
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/bsd-user/meson.build b/bsd-user/meson.build
index 5243122fc5..6ee68fdfe7 100644
--- a/bsd-user/meson.build
+++ b/bsd-user/meson.build
@@ -7,6 +7,7 @@ bsd_user_ss = ss.source_set()
 common_user_inc += include_directories('include')
 
 bsd_user_ss.add(files(
+  'bsd-mem.c',
   'bsdload.c',
   'elfload.c',
   'main.c',
-- 
2.42.0



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

* [PATCH v6 08/23] bsd-user: Implement target_set_brk function in bsd-mem.c instead of os-syscall.c
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
                   ` (6 preceding siblings ...)
  2023-09-25 18:26 ` [PATCH v6 07/23] bsd-user: Add bsd-mem.c to meson.build Karim Taha
@ 2023-09-25 18:26 ` Karim Taha
  2023-09-25 18:26 ` [PATCH v6 09/23] bsd-user: Implement ipc_perm conversion between host and target Karim Taha
                   ` (15 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Warner Losh, Richard Henderson, Stacey Son, Mikaël Urankar,
	Karim Taha

From: Stacey Son <sson@FreeBSD.org>

The definitions and variables names matches the corresponding ones in
linux-user/syscall.c, for making later implementation of do_obreak easier

Co-authored-by: Mikaël Urankar <mikael.urankar@gmail.com>
Signed-off-by: Mikaël Urankar <mikael.urankar@gmail.com>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-mem.c            | 32 ++++++++++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c |  4 ----
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/bsd-user/bsd-mem.c b/bsd-user/bsd-mem.c
index e69de29bb2..8834ab2e58 100644
--- a/bsd-user/bsd-mem.c
+++ b/bsd-user/bsd-mem.c
@@ -0,0 +1,32 @@
+/*
+ *  memory management system conversion routines
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "qemu-bsd.h"
+
+struct bsd_shm_regions bsd_shm_regions[N_BSD_SHM_REGIONS];
+
+abi_ulong target_brk;
+abi_ulong initial_target_brk;
+
+void target_set_brk(abi_ulong new_brk)
+{
+    target_brk = TARGET_PAGE_ALIGN(new_brk);
+    initial_target_brk = target_brk;
+}
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index ae92a2314c..4c99760a21 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -60,10 +60,6 @@ safe_syscall3(ssize_t, writev, int, fd, const struct iovec *, iov, int, iovcnt);
 safe_syscall4(ssize_t, pwritev, int, fd, const struct iovec *, iov, int, iovcnt,
     off_t, offset);
 
-void target_set_brk(abi_ulong new_brk)
-{
-}
-
 /*
  * errno conversion.
  */
-- 
2.42.0



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

* [PATCH v6 09/23] bsd-user: Implement ipc_perm conversion between host and target.
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
                   ` (7 preceding siblings ...)
  2023-09-25 18:26 ` [PATCH v6 08/23] bsd-user: Implement target_set_brk function in bsd-mem.c instead of os-syscall.c Karim Taha
@ 2023-09-25 18:26 ` Karim Taha
  2023-09-25 18:26 ` [PATCH v6 10/23] bsd-user: Implement shmid_ds " Karim Taha
                   ` (14 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Warner Losh, Richard Henderson, Stacey Son, Karim Taha

From: Stacey Son <sson@FreeBSD.org>

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-mem.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/bsd-user/bsd-mem.c b/bsd-user/bsd-mem.c
index 8834ab2e58..46cda8eb5c 100644
--- a/bsd-user/bsd-mem.c
+++ b/bsd-user/bsd-mem.c
@@ -30,3 +30,28 @@ void target_set_brk(abi_ulong new_brk)
     target_brk = TARGET_PAGE_ALIGN(new_brk);
     initial_target_brk = target_brk;
 }
+
+void target_to_host_ipc_perm__locked(struct ipc_perm *host_ip,
+                                     struct target_ipc_perm *target_ip)
+{
+    __get_user(host_ip->cuid, &target_ip->cuid);
+    __get_user(host_ip->cgid, &target_ip->cgid);
+    __get_user(host_ip->uid,  &target_ip->uid);
+    __get_user(host_ip->gid,  &target_ip->gid);
+    __get_user(host_ip->mode, &target_ip->mode);
+    __get_user(host_ip->seq,  &target_ip->seq);
+    __get_user(host_ip->key,  &target_ip->key);
+}
+
+void host_to_target_ipc_perm__locked(struct target_ipc_perm *target_ip,
+                                     struct ipc_perm *host_ip)
+{
+    __put_user(host_ip->cuid, &target_ip->cuid);
+    __put_user(host_ip->cgid, &target_ip->cgid);
+    __put_user(host_ip->uid,  &target_ip->uid);
+    __put_user(host_ip->gid,  &target_ip->gid);
+    __put_user(host_ip->mode, &target_ip->mode);
+    __put_user(host_ip->seq,  &target_ip->seq);
+    __put_user(host_ip->key,  &target_ip->key);
+}
+
-- 
2.42.0



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

* [PATCH v6 10/23] bsd-user: Implement shmid_ds conversion between host and target.
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
                   ` (8 preceding siblings ...)
  2023-09-25 18:26 ` [PATCH v6 09/23] bsd-user: Implement ipc_perm conversion between host and target Karim Taha
@ 2023-09-25 18:26 ` Karim Taha
  2023-09-25 18:26 ` [PATCH v6 11/23] bsd-user: Introduce bsd-mem.h to the source tree Karim Taha
                   ` (13 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Warner Losh, Richard Henderson, Stacey Son, Karim Taha

From: Stacey Son <sson@FreeBSD.org>

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-mem.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/bsd-user/bsd-mem.c b/bsd-user/bsd-mem.c
index 46cda8eb5c..2ab1334b70 100644
--- a/bsd-user/bsd-mem.c
+++ b/bsd-user/bsd-mem.c
@@ -43,6 +43,30 @@ void target_to_host_ipc_perm__locked(struct ipc_perm *host_ip,
     __get_user(host_ip->key,  &target_ip->key);
 }
 
+abi_long target_to_host_shmid_ds(struct shmid_ds *host_sd,
+                                 abi_ulong target_addr)
+{
+    struct target_shmid_ds *target_sd;
+
+    if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)) {
+        return -TARGET_EFAULT;
+    }
+
+    target_to_host_ipc_perm__locked(&(host_sd->shm_perm),
+                                    &(target_sd->shm_perm));
+
+    __get_user(host_sd->shm_segsz,  &target_sd->shm_segsz);
+    __get_user(host_sd->shm_lpid,   &target_sd->shm_lpid);
+    __get_user(host_sd->shm_cpid,   &target_sd->shm_cpid);
+    __get_user(host_sd->shm_nattch, &target_sd->shm_nattch);
+    __get_user(host_sd->shm_atime,  &target_sd->shm_atime);
+    __get_user(host_sd->shm_dtime,  &target_sd->shm_dtime);
+    __get_user(host_sd->shm_ctime,  &target_sd->shm_ctime);
+    unlock_user_struct(target_sd, target_addr, 0);
+
+    return 0;
+}
+
 void host_to_target_ipc_perm__locked(struct target_ipc_perm *target_ip,
                                      struct ipc_perm *host_ip)
 {
@@ -55,3 +79,26 @@ void host_to_target_ipc_perm__locked(struct target_ipc_perm *target_ip,
     __put_user(host_ip->key,  &target_ip->key);
 }
 
+abi_long host_to_target_shmid_ds(abi_ulong target_addr,
+                                 struct shmid_ds *host_sd)
+{
+    struct target_shmid_ds *target_sd;
+
+    if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) {
+        return -TARGET_EFAULT;
+    }
+
+    host_to_target_ipc_perm__locked(&(target_sd->shm_perm),
+                                    &(host_sd->shm_perm));
+
+    __put_user(host_sd->shm_segsz,  &target_sd->shm_segsz);
+    __put_user(host_sd->shm_lpid,   &target_sd->shm_lpid);
+    __put_user(host_sd->shm_cpid,   &target_sd->shm_cpid);
+    __put_user(host_sd->shm_nattch, &target_sd->shm_nattch);
+    __put_user(host_sd->shm_atime,  &target_sd->shm_atime);
+    __put_user(host_sd->shm_dtime,  &target_sd->shm_dtime);
+    __put_user(host_sd->shm_ctime,  &target_sd->shm_ctime);
+    unlock_user_struct(target_sd, target_addr, 1);
+
+    return 0;
+}
-- 
2.42.0



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

* [PATCH v6 11/23] bsd-user: Introduce bsd-mem.h to the source tree
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
                   ` (9 preceding siblings ...)
  2023-09-25 18:26 ` [PATCH v6 10/23] bsd-user: Implement shmid_ds " Karim Taha
@ 2023-09-25 18:26 ` Karim Taha
  2023-09-25 18:26 ` [PATCH v6 12/23] bsd-user: Implement mmap(2) and munmap(2) Karim Taha
                   ` (12 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Warner Losh, Richard Henderson, Stacey Son, Karim Taha

From: Stacey Son <sson@FreeBSD.org>

Preserve the copyright notice and help with the 'Author' info for
subsequent changes to the file.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-mem.h            | 64 +++++++++++++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c |  1 +
 2 files changed, 65 insertions(+)
 create mode 100644 bsd-user/bsd-mem.h

diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h
new file mode 100644
index 0000000000..d865e0807d
--- /dev/null
+++ b/bsd-user/bsd-mem.h
@@ -0,0 +1,64 @@
+/*
+ *  memory management system call shims and definitions
+ *
+ *  Copyright (c) 2013-15 Stacey D. Son
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * Copyright (c) 1982, 1986, 1993
+ *      The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef BSD_USER_BSD_MEM_H
+#define BSD_USER_BSD_MEM_H
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/mman.h>
+#include <sys/shm.h>
+#include <fcntl.h>
+
+#include "qemu-bsd.h"
+
+extern struct bsd_shm_regions bsd_shm_regions[];
+extern abi_ulong target_brk;
+extern abi_ulong initial_target_brk;
+
+#endif /* BSD_USER_BSD_MEM_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 4c99760a21..42cd52a406 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -35,6 +35,7 @@
 
 /* BSD independent syscall shims */
 #include "bsd-file.h"
+#include "bsd-mem.h"
 #include "bsd-proc.h"
 
 /* *BSD dependent syscall shims */
-- 
2.42.0



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

* [PATCH v6 12/23] bsd-user: Implement mmap(2) and munmap(2)
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
                   ` (10 preceding siblings ...)
  2023-09-25 18:26 ` [PATCH v6 11/23] bsd-user: Introduce bsd-mem.h to the source tree Karim Taha
@ 2023-09-25 18:26 ` Karim Taha
  2023-09-25 18:26 ` [PATCH v6 13/23] bsd-user: Implement mprotect(2) Karim Taha
                   ` (11 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Warner Losh, Richard Henderson, Stacey Son, Karim Taha

From: Stacey Son <sson@FreeBSD.org>

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-mem.h            | 20 ++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c |  9 +++++++++
 2 files changed, 29 insertions(+)

diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h
index d865e0807d..76b504f70c 100644
--- a/bsd-user/bsd-mem.h
+++ b/bsd-user/bsd-mem.h
@@ -61,4 +61,24 @@ extern struct bsd_shm_regions bsd_shm_regions[];
 extern abi_ulong target_brk;
 extern abi_ulong initial_target_brk;
 
+/* mmap(2) */
+static inline abi_long do_bsd_mmap(void *cpu_env, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6, abi_long arg7,
+    abi_long arg8)
+{
+    if (regpairs_aligned(cpu_env) != 0) {
+        arg6 = arg7;
+        arg7 = arg8;
+    }
+    return get_errno(target_mmap(arg1, arg2, arg3,
+                                 target_to_host_bitmask(arg4, mmap_flags_tbl),
+                                 arg5, target_arg64(arg6, arg7)));
+}
+
+/* munmap(2) */
+static inline abi_long do_bsd_munmap(abi_long arg1, abi_long arg2)
+{
+    return get_errno(target_munmap(arg1, arg2));
+}
+
 #endif /* BSD_USER_BSD_MEM_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 42cd52a406..893881c179 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -594,6 +594,15 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         /*
          * Memory management system calls.
          */
+    case TARGET_FREEBSD_NR_mmap: /* mmap(2) */
+        ret = do_bsd_mmap(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6, arg7,
+                          arg8);
+        break;
+
+    case TARGET_FREEBSD_NR_munmap: /* munmap(2) */
+        ret = do_bsd_munmap(arg1, arg2);
+        break;
+
 #if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048
     case TARGET_FREEBSD_NR_shm_open2: /* shm_open2(2) */
         ret = do_freebsd_shm_open2(arg1, arg2, arg3, arg4, arg5);
-- 
2.42.0



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

* [PATCH v6 13/23] bsd-user: Implement mprotect(2)
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
                   ` (11 preceding siblings ...)
  2023-09-25 18:26 ` [PATCH v6 12/23] bsd-user: Implement mmap(2) and munmap(2) Karim Taha
@ 2023-09-25 18:26 ` Karim Taha
  2023-09-25 18:27 ` [PATCH v6 14/23] bsd-user: Implement msync(2) Karim Taha
                   ` (10 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Warner Losh, Richard Henderson, Stacey Son, Karim Taha

From: Stacey Son <sson@FreeBSD.org>

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsd-mem.h            | 7 +++++++
 bsd-user/freebsd/os-syscall.c | 4 ++++
 2 files changed, 11 insertions(+)

diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h
index 76b504f70c..0f9e4a1d4b 100644
--- a/bsd-user/bsd-mem.h
+++ b/bsd-user/bsd-mem.h
@@ -81,4 +81,11 @@ static inline abi_long do_bsd_munmap(abi_long arg1, abi_long arg2)
     return get_errno(target_munmap(arg1, arg2));
 }
 
+/* mprotect(2) */
+static inline abi_long do_bsd_mprotect(abi_long arg1, abi_long arg2,
+        abi_long arg3)
+{
+    return get_errno(target_mprotect(arg1, arg2, arg3));
+}
+
 #endif /* BSD_USER_BSD_MEM_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 893881c179..74c0624637 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -603,6 +603,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd_munmap(arg1, arg2);
         break;
 
+    case TARGET_FREEBSD_NR_mprotect: /* mprotect(2) */
+        ret = do_bsd_mprotect(arg1, arg2, arg3);
+        break;
+
 #if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048
     case TARGET_FREEBSD_NR_shm_open2: /* shm_open2(2) */
         ret = do_freebsd_shm_open2(arg1, arg2, arg3, arg4, arg5);
-- 
2.42.0



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

* [PATCH v6 14/23] bsd-user: Implement msync(2)
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
                   ` (12 preceding siblings ...)
  2023-09-25 18:26 ` [PATCH v6 13/23] bsd-user: Implement mprotect(2) Karim Taha
@ 2023-09-25 18:27 ` Karim Taha
  2023-09-25 18:27 ` [PATCH v6 15/23] bsd-user: Implement mlock(2), munlock(2), mlockall(2), munlockall(2), minherit(2) Karim Taha
                   ` (9 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Warner Losh, Richard Henderson, Stacey Son, Kyle Evans,
	Karim Taha

From: Stacey Son <sson@FreeBSD.org>

Co-authored-by: Kyle Evans <kevans@FreeBSD.org>
Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Kyle Evans <kevans@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-mem.h            | 11 +++++++++++
 bsd-user/freebsd/os-syscall.c |  4 ++++
 2 files changed, 15 insertions(+)

diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h
index 0f9e4a1d4b..5e885823a7 100644
--- a/bsd-user/bsd-mem.h
+++ b/bsd-user/bsd-mem.h
@@ -88,4 +88,15 @@ static inline abi_long do_bsd_mprotect(abi_long arg1, abi_long arg2,
     return get_errno(target_mprotect(arg1, arg2, arg3));
 }
 
+/* msync(2) */
+static inline abi_long do_bsd_msync(abi_long addr, abi_long len, abi_long flags)
+{
+    if (!guest_range_valid_untagged(addr, len)) {
+        /* It seems odd, but POSIX wants this to be ENOMEM */
+        return -TARGET_ENOMEM;
+    }
+
+    return get_errno(msync(g2h_untagged(addr), len, flags));
+}
+
 #endif /* BSD_USER_BSD_MEM_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 74c0624637..5aebb18805 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -607,6 +607,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd_mprotect(arg1, arg2, arg3);
         break;
 
+    case TARGET_FREEBSD_NR_msync: /* msync(2) */
+        ret = do_bsd_msync(arg1, arg2, arg3);
+        break;
+
 #if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048
     case TARGET_FREEBSD_NR_shm_open2: /* shm_open2(2) */
         ret = do_freebsd_shm_open2(arg1, arg2, arg3, arg4, arg5);
-- 
2.42.0



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

* [PATCH v6 15/23] bsd-user: Implement mlock(2), munlock(2), mlockall(2), munlockall(2), minherit(2)
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
                   ` (13 preceding siblings ...)
  2023-09-25 18:27 ` [PATCH v6 14/23] bsd-user: Implement msync(2) Karim Taha
@ 2023-09-25 18:27 ` Karim Taha
  2023-09-25 18:27 ` [PATCH v6 16/23] bsd-user: Implment madvise(2) to match the linux-user implementation Karim Taha
                   ` (8 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Warner Losh, Richard Henderson, Stacey Son, Karim Taha

From: Stacey Son <sson@FreeBSD.org>

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-mem.h            | 37 +++++++++++++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c | 20 +++++++++++++++++++
 2 files changed, 57 insertions(+)

diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h
index 5e885823a7..16c22593bf 100644
--- a/bsd-user/bsd-mem.h
+++ b/bsd-user/bsd-mem.h
@@ -99,4 +99,41 @@ static inline abi_long do_bsd_msync(abi_long addr, abi_long len, abi_long flags)
     return get_errno(msync(g2h_untagged(addr), len, flags));
 }
 
+/* mlock(2) */
+static inline abi_long do_bsd_mlock(abi_long arg1, abi_long arg2)
+{
+    if (!guest_range_valid_untagged(arg1, arg2)) {
+        return -TARGET_EINVAL;
+    }
+    return get_errno(mlock(g2h_untagged(arg1), arg2));
+}
+
+/* munlock(2) */
+static inline abi_long do_bsd_munlock(abi_long arg1, abi_long arg2)
+{
+    if (!guest_range_valid_untagged(arg1, arg2)) {
+        return -TARGET_EINVAL;
+    }
+    return get_errno(munlock(g2h_untagged(arg1), arg2));
+}
+
+/* mlockall(2) */
+static inline abi_long do_bsd_mlockall(abi_long arg1)
+{
+    return get_errno(mlockall(arg1));
+}
+
+/* munlockall(2) */
+static inline abi_long do_bsd_munlockall(void)
+{
+    return get_errno(munlockall());
+}
+
+/* minherit(2) */
+static inline abi_long do_bsd_minherit(abi_long addr, abi_long len,
+        abi_long inherit)
+{
+    return get_errno(minherit(g2h_untagged(addr), len, inherit));
+}
+
 #endif /* BSD_USER_BSD_MEM_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 5aebb18805..553578708b 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -611,6 +611,26 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd_msync(arg1, arg2, arg3);
         break;
 
+    case TARGET_FREEBSD_NR_mlock: /* mlock(2) */
+        ret = do_bsd_mlock(arg1, arg2);
+        break;
+
+    case TARGET_FREEBSD_NR_munlock: /* munlock(2) */
+        ret = do_bsd_munlock(arg1, arg2);
+        break;
+
+    case TARGET_FREEBSD_NR_mlockall: /* mlockall(2) */
+        ret = do_bsd_mlockall(arg1);
+        break;
+
+    case TARGET_FREEBSD_NR_munlockall: /* munlockall(2) */
+        ret = do_bsd_munlockall();
+        break;
+
+    case TARGET_FREEBSD_NR_minherit: /* minherit(2) */
+        ret = do_bsd_minherit(arg1, arg2, arg3);
+        break;
+
 #if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048
     case TARGET_FREEBSD_NR_shm_open2: /* shm_open2(2) */
         ret = do_freebsd_shm_open2(arg1, arg2, arg3, arg4, arg5);
-- 
2.42.0



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

* [PATCH v6 16/23] bsd-user: Implment madvise(2) to match the linux-user implementation.
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
                   ` (14 preceding siblings ...)
  2023-09-25 18:27 ` [PATCH v6 15/23] bsd-user: Implement mlock(2), munlock(2), mlockall(2), munlockall(2), minherit(2) Karim Taha
@ 2023-09-25 18:27 ` Karim Taha
  2023-09-25 18:27 ` [PATCH v6 17/23] bsd-user: Implement mincore(2) Karim Taha
                   ` (7 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Warner Losh, Richard Henderson, Karim Taha

Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-mem.h            | 53 +++++++++++++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c |  4 +++
 bsd-user/syscall_defs.h       |  2 ++
 3 files changed, 59 insertions(+)

diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h
index 16c22593bf..b00ab3aed8 100644
--- a/bsd-user/bsd-mem.h
+++ b/bsd-user/bsd-mem.h
@@ -129,6 +129,59 @@ static inline abi_long do_bsd_munlockall(void)
     return get_errno(munlockall());
 }
 
+/* madvise(2) */
+static inline abi_long do_bsd_madvise(abi_long arg1, abi_long arg2,
+        abi_long arg3)
+{
+    abi_ulong len;
+    int ret = 0;
+    abi_long start = arg1;
+    abi_long len_in = arg2;
+    abi_long advice = arg3;
+
+    if (start & ~TARGET_PAGE_MASK) {
+        return -TARGET_EINVAL;
+    }
+    if (len_in == 0) {
+        return 0;
+    }
+    len = TARGET_PAGE_ALIGN(len_in);
+    if (len == 0 || !guest_range_valid_untagged(start, len)) {
+        return -TARGET_EINVAL;
+    }
+
+    /*
+     * Most advice values are hints, so ignoring and returning success is ok.
+     *
+     * However, some advice values such as MADV_DONTNEED, are not hints and
+     * need to be emulated.
+     *
+     * A straight passthrough for those may not be safe because qemu sometimes
+     * turns private file-backed mappings into anonymous mappings.
+     * If all guest pages have PAGE_PASSTHROUGH set, mappings have the
+     * same semantics for the host as for the guest.
+     *
+     * MADV_DONTNEED is passed through, if possible.
+     * If passthrough isn't possible, we nevertheless (wrongly!) return
+     * success, which is broken but some userspace programs fail to work
+     * otherwise. Completely implementing such emulation is quite complicated
+     * though.
+     */
+    mmap_lock();
+    switch (advice) {
+    case MADV_DONTNEED:
+        if (page_check_range(start, len, PAGE_PASSTHROUGH)) {
+            ret = get_errno(madvise(g2h_untagged(start), len, advice));
+            if (ret == 0) {
+                page_reset_target_data(start, start + len - 1);
+            }
+        }
+    }
+    mmap_unlock();
+
+    return ret;
+}
+
 /* minherit(2) */
 static inline abi_long do_bsd_minherit(abi_long addr, abi_long len,
         abi_long inherit)
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 553578708b..600d048120 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -627,6 +627,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd_munlockall();
         break;
 
+    case TARGET_FREEBSD_NR_madvise: /* madvise(2) */
+        ret = do_bsd_madvise(arg1, arg2, arg3);
+        break;
+
     case TARGET_FREEBSD_NR_minherit: /* minherit(2) */
         ret = do_bsd_minherit(arg1, arg2, arg3);
         break;
diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h
index f4a5ae2a12..929b155b10 100644
--- a/bsd-user/syscall_defs.h
+++ b/bsd-user/syscall_defs.h
@@ -95,6 +95,8 @@ struct bsd_shm_regions {
 /*
  *  sys/mman.h
  */
+#define TARGET_MADV_DONTNEED            4       /* dont need these pages */
+
 #define TARGET_FREEBSD_MAP_RESERVED0080 0x0080  /* previously misimplemented */
                                                 /* MAP_INHERIT */
 #define TARGET_FREEBSD_MAP_RESERVED0100 0x0100  /* previously unimplemented */
-- 
2.42.0



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

* [PATCH v6 17/23] bsd-user: Implement mincore(2)
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
                   ` (15 preceding siblings ...)
  2023-09-25 18:27 ` [PATCH v6 16/23] bsd-user: Implment madvise(2) to match the linux-user implementation Karim Taha
@ 2023-09-25 18:27 ` Karim Taha
  2023-09-25 18:27 ` [PATCH v6 18/23] bsd-user: Implement do_obreak function Karim Taha
                   ` (6 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Warner Losh, Richard Henderson, Stacey Son, Karim Taha

From: Stacey Son <sson@FreeBSD.org>

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-mem.h            | 23 +++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c |  4 ++++
 2 files changed, 27 insertions(+)

diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h
index b00ab3aed8..0c8d96d9a4 100644
--- a/bsd-user/bsd-mem.h
+++ b/bsd-user/bsd-mem.h
@@ -189,4 +189,27 @@ static inline abi_long do_bsd_minherit(abi_long addr, abi_long len,
     return get_errno(minherit(g2h_untagged(addr), len, inherit));
 }
 
+/* mincore(2) */
+static inline abi_long do_bsd_mincore(abi_ulong target_addr, abi_ulong len,
+        abi_ulong target_vec)
+{
+    abi_long ret;
+    void *p;
+    abi_ulong vec_len = DIV_ROUND_UP(len, TARGET_PAGE_SIZE);
+
+    if (!guest_range_valid_untagged(target_addr, len)
+        || !page_check_range(target_addr, len, PAGE_VALID)) {
+        return -TARGET_EFAULT;
+    }
+
+    p = lock_user(VERIFY_WRITE, target_vec, vec_len, 0);
+    if (p == NULL) {
+        return -TARGET_EFAULT;
+    }
+    ret = get_errno(mincore(g2h_untagged(target_addr), len, p));
+    unlock_user(p, target_vec, vec_len);
+
+    return ret;
+}
+
 #endif /* BSD_USER_BSD_MEM_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 600d048120..8ba5fcc6ca 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -635,6 +635,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd_minherit(arg1, arg2, arg3);
         break;
 
+    case TARGET_FREEBSD_NR_mincore: /* mincore(2) */
+        ret = do_bsd_mincore(arg1, arg2, arg3);
+        break;
+
 #if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048
     case TARGET_FREEBSD_NR_shm_open2: /* shm_open2(2) */
         ret = do_freebsd_shm_open2(arg1, arg2, arg3, arg4, arg5);
-- 
2.42.0



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

* [PATCH v6 18/23] bsd-user: Implement do_obreak function
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
                   ` (16 preceding siblings ...)
  2023-09-25 18:27 ` [PATCH v6 17/23] bsd-user: Implement mincore(2) Karim Taha
@ 2023-09-25 18:27 ` Karim Taha
  2023-09-25 18:27 ` [PATCH v6 19/23] bsd-user: Implement shm_open(2) Karim Taha
                   ` (5 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Warner Losh, Richard Henderson, Stacey Son, Karim Taha

From: Stacey Son <sson@FreeBSD.org>

Match linux-user, by manually applying the following commits, in order:

d28b3c90cfad1a7e211ae2bce36ecb9071086129   linux-user: Make sure initial brk(0) is page-aligned
15ad98536ad9410fb32ddf1ff09389b677643faa   linux-user: Fix qemu brk() to not zero bytes on current page
dfe49864afb06e7e452a4366051697bc4fcfc1a5   linux-user: Prohibit brk() to to shrink below initial heap address
eac78a4b0b7da4de2c0a297f4d528ca9cc6256a3   linux-user: Fix signed math overflow in brk() syscall
c6cc059eca18d9f6e4e26bb8b6d1135ddb35d81a   linux-user: Do not call get_errno() in do_brk()
e69e032d1a8ee8d754ca119009a3c2c997f8bb30   linux-user: Use MAP_FIXED_NOREPLACE for do_brk()
cb9d5d1fda0bc2312fc0c779b4ea1d7bf826f31f   linux-user: Do nothing if too small brk is specified
2aea137a425a87b930a33590177b04368fd7cc12   linux-user: Do not align brk with host page size

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-mem.h            | 45 +++++++++++++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c |  7 ++++++
 2 files changed, 52 insertions(+)

diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h
index 0c8d96d9a4..b296c5c6f0 100644
--- a/bsd-user/bsd-mem.h
+++ b/bsd-user/bsd-mem.h
@@ -212,4 +212,49 @@ static inline abi_long do_bsd_mincore(abi_ulong target_addr, abi_ulong len,
     return ret;
 }
 
+/* do_brk() must return target values and target errnos. */
+static inline abi_long do_obreak(abi_ulong brk_val)
+{
+    abi_long mapped_addr;
+    abi_ulong new_brk;
+    abi_ulong old_brk;
+
+    /* brk pointers are always untagged */
+
+    /* do not allow to shrink below initial brk value */
+    if (brk_val < initial_target_brk) {
+        return target_brk;
+    }
+
+    new_brk = TARGET_PAGE_ALIGN(brk_val);
+    old_brk = TARGET_PAGE_ALIGN(target_brk);
+
+    /* new and old target_brk might be on the same page */
+    if (new_brk == old_brk) {
+        target_brk = brk_val;
+        return target_brk;
+    }
+
+    /* Release heap if necesary */
+    if (new_brk < old_brk) {
+        target_munmap(new_brk, old_brk - new_brk);
+
+        target_brk = brk_val;
+        return target_brk;
+    }
+
+    mapped_addr = target_mmap(old_brk, new_brk - old_brk,
+                              PROT_READ | PROT_WRITE,
+                              MAP_FIXED | MAP_EXCL | MAP_ANON | MAP_PRIVATE,
+                              -1, 0);
+
+    if (mapped_addr == old_brk) {
+        target_brk = brk_val;
+        return target_brk;
+    }
+
+    /* For everything else, return the previous break. */
+    return target_brk;
+}
+
 #endif /* BSD_USER_BSD_MEM_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 8ba5fcc6ca..5cd60fc272 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -651,6 +651,13 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #endif
 
+        /*
+         * Misc
+         */
+    case TARGET_FREEBSD_NR_break:
+        ret = do_obreak(arg1);
+        break;
+
         /*
          * sys{ctl, arch, call}
          */
-- 
2.42.0



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

* [PATCH v6 19/23] bsd-user: Implement shm_open(2)
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
                   ` (17 preceding siblings ...)
  2023-09-25 18:27 ` [PATCH v6 18/23] bsd-user: Implement do_obreak function Karim Taha
@ 2023-09-25 18:27 ` Karim Taha
  2023-09-25 18:27 ` [PATCH v6 20/23] bsd-user: Implement shm_unlink(2) and shmget(2) Karim Taha
                   ` (4 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Warner Losh, Richard Henderson, Stacey Son, Kyle Evans,
	Karim Taha

From: Stacey Son <sson@FreeBSD.org>

Co-authored-by: Kyle Evans <kevans@FreeBSD.org>

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Kyle Evans <kevans@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-mem.h            | 25 +++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c |  4 ++++
 2 files changed, 29 insertions(+)

diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h
index b296c5c6f0..f8dc943c23 100644
--- a/bsd-user/bsd-mem.h
+++ b/bsd-user/bsd-mem.h
@@ -257,4 +257,29 @@ static inline abi_long do_obreak(abi_ulong brk_val)
     return target_brk;
 }
 
+/* shm_open(2) */
+static inline abi_long do_bsd_shm_open(abi_ulong arg1, abi_long arg2,
+        abi_long arg3)
+{
+    int ret;
+    void *p;
+
+    if (arg1 == (uintptr_t)SHM_ANON) {
+        p = SHM_ANON;
+    } else {
+        p = lock_user_string(arg1);
+        if (p == NULL) {
+            return -TARGET_EFAULT;
+        }
+    }
+    ret = get_errno(shm_open(p, target_to_host_bitmask(arg2, fcntl_flags_tbl),
+                             arg3));
+
+    if (p != SHM_ANON) {
+        unlock_user(p, arg1, 0);
+    }
+
+    return ret;
+}
+
 #endif /* BSD_USER_BSD_MEM_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 5cd60fc272..effa6dac54 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -639,6 +639,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd_mincore(arg1, arg2, arg3);
         break;
 
+    case TARGET_FREEBSD_NR_freebsd12_shm_open: /* shm_open(2) */
+        ret = do_bsd_shm_open(arg1, arg2, arg3);
+        break;
+
 #if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048
     case TARGET_FREEBSD_NR_shm_open2: /* shm_open2(2) */
         ret = do_freebsd_shm_open2(arg1, arg2, arg3, arg4, arg5);
-- 
2.42.0



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

* [PATCH v6 20/23] bsd-user: Implement shm_unlink(2) and shmget(2)
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
                   ` (18 preceding siblings ...)
  2023-09-25 18:27 ` [PATCH v6 19/23] bsd-user: Implement shm_open(2) Karim Taha
@ 2023-09-25 18:27 ` Karim Taha
  2023-09-25 18:27 ` [PATCH v6 21/23] bsd-user: Implement shmctl(2) Karim Taha
                   ` (3 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Warner Losh, Richard Henderson, Stacey Son, Karim Taha

From: Stacey Son <sson@FreeBSD.org>

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

diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h
index f8dc943c23..c362cc07a3 100644
--- a/bsd-user/bsd-mem.h
+++ b/bsd-user/bsd-mem.h
@@ -282,4 +282,27 @@ static inline abi_long do_bsd_shm_open(abi_ulong arg1, abi_long arg2,
     return ret;
 }
 
+/* shm_unlink(2) */
+static inline abi_long do_bsd_shm_unlink(abi_ulong arg1)
+{
+    int ret;
+    void *p;
+
+    p = lock_user_string(arg1);
+    if (p == NULL) {
+        return -TARGET_EFAULT;
+    }
+    ret = get_errno(shm_unlink(p)); /* XXX path(p)? */
+    unlock_user(p, arg1, 0);
+
+    return ret;
+}
+
+/* shmget(2) */
+static inline abi_long do_bsd_shmget(abi_long arg1, abi_ulong arg2,
+        abi_long arg3)
+{
+    return get_errno(shmget(arg1, arg2, arg3));
+}
+
 #endif /* BSD_USER_BSD_MEM_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index effa6dac54..f0ccd787e5 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -655,6 +655,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #endif
 
+    case TARGET_FREEBSD_NR_shm_unlink: /* shm_unlink(2) */
+        ret = do_bsd_shm_unlink(arg1);
+        break;
+
+    case TARGET_FREEBSD_NR_shmget: /* shmget(2) */
+        ret = do_bsd_shmget(arg1, arg2, arg3);
+        break;
+
         /*
          * Misc
          */
-- 
2.42.0



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

* [PATCH v6 21/23] bsd-user: Implement shmctl(2)
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
                   ` (19 preceding siblings ...)
  2023-09-25 18:27 ` [PATCH v6 20/23] bsd-user: Implement shm_unlink(2) and shmget(2) Karim Taha
@ 2023-09-25 18:27 ` Karim Taha
  2023-09-25 18:27 ` [PATCH v6 22/23] bsd-user: Implement shmat(2) and shmdt(2) Karim Taha
                   ` (2 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Warner Losh, Richard Henderson, Stacey Son, Karim Taha

From: Stacey Son <sson@FreeBSD.org>

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-mem.h            | 39 +++++++++++++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c |  4 ++++
 2 files changed, 43 insertions(+)

diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h
index c362cc07a3..b82f3eaa25 100644
--- a/bsd-user/bsd-mem.h
+++ b/bsd-user/bsd-mem.h
@@ -305,4 +305,43 @@ static inline abi_long do_bsd_shmget(abi_long arg1, abi_ulong arg2,
     return get_errno(shmget(arg1, arg2, arg3));
 }
 
+/* shmctl(2) */
+static inline abi_long do_bsd_shmctl(abi_long shmid, abi_long cmd,
+        abi_ulong buff)
+{
+    struct shmid_ds dsarg;
+    abi_long ret = -TARGET_EINVAL;
+
+    cmd &= 0xff;
+
+    switch (cmd) {
+    case IPC_STAT:
+        if (target_to_host_shmid_ds(&dsarg, buff)) {
+            return -TARGET_EFAULT;
+        }
+        ret = get_errno(shmctl(shmid, cmd, &dsarg));
+        if (host_to_target_shmid_ds(buff, &dsarg)) {
+            return -TARGET_EFAULT;
+        }
+        break;
+
+    case IPC_SET:
+        if (target_to_host_shmid_ds(&dsarg, buff)) {
+            return -TARGET_EFAULT;
+        }
+        ret = get_errno(shmctl(shmid, cmd, &dsarg));
+        break;
+
+    case IPC_RMID:
+        ret = get_errno(shmctl(shmid, cmd, NULL));
+        break;
+
+    default:
+        ret = -TARGET_EINVAL;
+        break;
+    }
+
+    return ret;
+}
+
 #endif /* BSD_USER_BSD_MEM_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index f0ccd787e5..664b8de104 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -663,6 +663,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd_shmget(arg1, arg2, arg3);
         break;
 
+    case TARGET_FREEBSD_NR_shmctl: /* shmctl(2) */
+        ret = do_bsd_shmctl(arg1, arg2, arg3);
+        break;
+
         /*
          * Misc
          */
-- 
2.42.0



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

* [PATCH v6 22/23] bsd-user: Implement shmat(2) and shmdt(2)
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
                   ` (20 preceding siblings ...)
  2023-09-25 18:27 ` [PATCH v6 21/23] bsd-user: Implement shmctl(2) Karim Taha
@ 2023-09-25 18:27 ` Karim Taha
  2023-09-25 18:27 ` [PATCH v6 23/23] bsd-user: Add stubs for vadvise(), sbrk() and sstk() Karim Taha
  2023-09-27  4:34 ` [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Warner Losh
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Warner Losh, Richard Henderson, Stacey Son, Karim Taha

From: Stacey Son <sson@FreeBSD.org>

Use `WITH_MMAP_LOCK_GUARD` instead of mmap_lock() and mmap_unlock(),
to match linux-user implementation, according to the following commits:

69fa2708a216df715ba5102a0f98468b540a464e linux-user: Use WITH_MMAP_LOCK_GUARD in target_{shmat,shmdt}
ceda5688b650646248f269a992c06b11148c5759 linux-user: Fix shmdt

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
---
 bsd-user/bsd-mem.h            | 87 +++++++++++++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c |  8 ++++
 bsd-user/mmap.c               |  2 +-
 bsd-user/qemu.h               |  1 +
 4 files changed, 97 insertions(+), 1 deletion(-)

diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h
index b82f3eaa25..c512a4e375 100644
--- a/bsd-user/bsd-mem.h
+++ b/bsd-user/bsd-mem.h
@@ -344,4 +344,91 @@ static inline abi_long do_bsd_shmctl(abi_long shmid, abi_long cmd,
     return ret;
 }
 
+/* shmat(2) */
+static inline abi_long do_bsd_shmat(int shmid, abi_ulong shmaddr, int shmflg)
+{
+    abi_ulong raddr;
+    abi_long ret;
+    struct shmid_ds shm_info;
+
+    /* Find out the length of the shared memory segment. */
+    ret = get_errno(shmctl(shmid, IPC_STAT, &shm_info));
+    if (is_error(ret)) {
+        /* Can't get the length */
+        return ret;
+    }
+
+    if (!guest_range_valid_untagged(shmaddr, shm_info.shm_segsz)) {
+        return -TARGET_EINVAL;
+    }
+
+    WITH_MMAP_LOCK_GUARD() {
+        void *host_raddr;
+
+        if (shmaddr) {
+            host_raddr = shmat(shmid, (void *)g2h_untagged(shmaddr), shmflg);
+        } else {
+            abi_ulong mmap_start;
+
+            mmap_start = mmap_find_vma(0, shm_info.shm_segsz);
+
+            if (mmap_start == -1) {
+                return -TARGET_ENOMEM;
+            }
+            host_raddr = shmat(shmid, g2h_untagged(mmap_start),
+                               shmflg | SHM_REMAP);
+        }
+
+        if (host_raddr == (void *)-1) {
+            return get_errno(-1);
+        }
+        raddr = h2g(host_raddr);
+
+        page_set_flags(raddr, raddr + shm_info.shm_segsz - 1,
+                       PAGE_VALID | PAGE_RESET | PAGE_READ |
+                       (shmflg & SHM_RDONLY ? 0 : PAGE_WRITE));
+
+        for (int i = 0; i < N_BSD_SHM_REGIONS; i++) {
+            if (bsd_shm_regions[i].start == 0) {
+                bsd_shm_regions[i].start = raddr;
+                bsd_shm_regions[i].size = shm_info.shm_segsz;
+                break;
+            }
+        }
+    }
+
+    return raddr;
+}
+
+/* shmdt(2) */
+static inline abi_long do_bsd_shmdt(abi_ulong shmaddr)
+{
+    abi_long ret;
+
+    WITH_MMAP_LOCK_GUARD() {
+        int i;
+
+        for (i = 0; i < N_BSD_SHM_REGIONS; ++i) {
+            if (bsd_shm_regions[i].start == shmaddr) {
+                break;
+            }
+        }
+
+        if (i == N_BSD_SHM_REGIONS) {
+            return -TARGET_EINVAL;
+        }
+
+        ret = get_errno(shmdt(g2h_untagged(shmaddr)));
+        if (ret == 0) {
+            abi_ulong size = bsd_shm_regions[i].size;
+
+            bsd_shm_regions[i].start = 0;
+            page_set_flags(shmaddr, shmaddr + size - 1, 0);
+            mmap_reserve(shmaddr, size);
+        }
+    }
+
+    return ret;
+}
+
 #endif /* BSD_USER_BSD_MEM_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 664b8de104..6b32d4df68 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -667,6 +667,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd_shmctl(arg1, arg2, arg3);
         break;
 
+    case TARGET_FREEBSD_NR_shmat: /* shmat(2) */
+        ret = do_bsd_shmat(arg1, arg2, arg3);
+        break;
+
+    case TARGET_FREEBSD_NR_shmdt: /* shmdt(2) */
+        ret = do_bsd_shmdt(arg1);
+        break;
+
         /*
          * Misc
          */
diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c
index 8e148a2ea3..3ef11b2807 100644
--- a/bsd-user/mmap.c
+++ b/bsd-user/mmap.c
@@ -636,7 +636,7 @@ fail:
     return -1;
 }
 
-static void mmap_reserve(abi_ulong start, abi_ulong size)
+void mmap_reserve(abi_ulong start, abi_ulong size)
 {
     abi_ulong real_start;
     abi_ulong real_end;
diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index d9507137cc..d67dd76827 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -232,6 +232,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
 int target_msync(abi_ulong start, abi_ulong len, int flags);
 extern abi_ulong mmap_next_start;
 abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size);
+void mmap_reserve(abi_ulong start, abi_ulong size);
 void TSA_NO_TSA mmap_fork_start(void);
 void TSA_NO_TSA mmap_fork_end(int child);
 
-- 
2.42.0



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

* [PATCH v6 23/23] bsd-user: Add stubs for vadvise(), sbrk() and sstk()
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
                   ` (21 preceding siblings ...)
  2023-09-25 18:27 ` [PATCH v6 22/23] bsd-user: Implement shmat(2) and shmdt(2) Karim Taha
@ 2023-09-25 18:27 ` Karim Taha
  2023-09-27  4:34 ` [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Warner Losh
  23 siblings, 0 replies; 25+ messages in thread
From: Karim Taha @ 2023-09-25 18:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Warner Losh, Richard Henderson, Karim Taha

From: Warner Losh <imp@bsdimp.com>

The above system calls are not supported by qemu.

Signed-off-by: Warner Losh <imp@bsdimp.com>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/bsd-mem.h            | 18 ++++++++++++++++++
 bsd-user/freebsd/os-syscall.c | 12 ++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h
index c512a4e375..c3e72e3b86 100644
--- a/bsd-user/bsd-mem.h
+++ b/bsd-user/bsd-mem.h
@@ -431,4 +431,22 @@ static inline abi_long do_bsd_shmdt(abi_ulong shmaddr)
     return ret;
 }
 
+static inline abi_long do_bsd_vadvise(void)
+{
+    /* See sys_ovadvise() in vm_unix.c */
+    return -TARGET_EINVAL;
+}
+
+static inline abi_long do_bsd_sbrk(void)
+{
+    /* see sys_sbrk() in vm_mmap.c */
+    return -TARGET_EOPNOTSUPP;
+}
+
+static inline abi_long do_bsd_sstk(void)
+{
+    /* see sys_sstk() in vm_mmap.c */
+    return -TARGET_EOPNOTSUPP;
+}
+
 #endif /* BSD_USER_BSD_MEM_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 6b32d4df68..ce2a6bc29e 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -675,6 +675,18 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd_shmdt(arg1);
         break;
 
+    case TARGET_FREEBSD_NR_freebsd11_vadvise:
+        ret = do_bsd_vadvise();
+        break;
+
+    case TARGET_FREEBSD_NR_sbrk:
+        ret = do_bsd_sbrk();
+        break;
+
+    case TARGET_FREEBSD_NR_sstk:
+        ret = do_bsd_sstk();
+        break;
+
         /*
          * Misc
          */
-- 
2.42.0



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

* Re: [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD.
  2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
                   ` (22 preceding siblings ...)
  2023-09-25 18:27 ` [PATCH v6 23/23] bsd-user: Add stubs for vadvise(), sbrk() and sstk() Karim Taha
@ 2023-09-27  4:34 ` Warner Losh
  23 siblings, 0 replies; 25+ messages in thread
From: Warner Losh @ 2023-09-27  4:34 UTC (permalink / raw)
  To: Karim Taha; +Cc: qemu-devel, Richard Henderson

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

On Mon, Sep 25, 2023 at 12:28 PM Karim Taha <kariem.taha2.7@gmail.com>
wrote:

> Upstream the implementation of the following mmap system calls, from the
> qemu-bsd-user fork:
>    mmap(2), munmap(2),
>    mprotect(2),
>    msync(2),
>    mlock(2), munlock(2), mlockall(2), munlockall(2), mincore(2),
>    madvise(2),
>    minherit(2),
>    shm_open(2),shm_open2(2), shm_rename2(2), shm_unlink(2), shmget(2),
> shmctl(2), shmat(2),
>    shmdt(2)
>    brk(2)
>
> Karim Taha (3):
>   bsd-user: Implement shm_open2(2) system call
>   bsd-user: Add bsd-mem.c to meson.build
>   bsd-user: Implment madvise(2) to match the linux-user implementation.
>
> Kyle Evans (1):
>   bsd-user: Implement shm_rename(2) system call
>
> Stacey Son (18):
>   bsd-user: Implement struct target_ipc_perm
>   bsd-user: Implement struct target_shmid_ds
>   bsd-user: Declarations for ipc_perm and shmid_ds conversion functions
>   bsd-user: Introduce freebsd/os-misc.h to the source tree
>   bsd-user: Implement target_set_brk function in bsd-mem.c instead of
>     os-syscall.c
>   bsd-user: Implement ipc_perm conversion between host and target.
>   bsd-user: Implement shmid_ds conversion between host and target.
>   bsd-user: Introduce bsd-mem.h to the source tree
>   bsd-user: Implement mmap(2) and munmap(2)
>   bsd-user: Implement mprotect(2)
>   bsd-user: Implement msync(2)
>   bsd-user: Implement mlock(2), munlock(2), mlockall(2), munlockall(2),
>     minherit(2)
>   bsd-user: Implement mincore(2)
>   bsd-user: Implement do_obreak function
>   bsd-user: Implement shm_open(2)
>   bsd-user: Implement shm_unlink(2) and shmget(2)
>   bsd-user: Implement shmctl(2)
>   bsd-user: Implement shmat(2) and shmdt(2)
>
> Warner Losh (1):
>   bsd-user: Add stubs for vadvise(), sbrk() and sstk()
>
>  bsd-user/bsd-mem.c            | 104 ++++++++
>  bsd-user/bsd-mem.h            | 452 ++++++++++++++++++++++++++++++++++
>  bsd-user/freebsd/os-misc.h    |  94 +++++++
>  bsd-user/freebsd/os-syscall.c | 109 +++++++-
>  bsd-user/meson.build          |   1 +
>  bsd-user/mmap.c               |   2 +-
>  bsd-user/qemu-bsd.h           |  45 ++++
>  bsd-user/qemu.h               |   1 +
>  bsd-user/syscall_defs.h       |  39 +++
>  9 files changed, 842 insertions(+), 5 deletions(-)
>  create mode 100644 bsd-user/bsd-mem.c
>  create mode 100644 bsd-user/bsd-mem.h
>  create mode 100644 bsd-user/freebsd/os-misc.h
>  create mode 100644 bsd-user/qemu-bsd.h
>

queued to bsd-user-topo

with minor conflicts from rebasing it and the proc system call changes onto
one branch.

I did fix one issue: in the blitz bsd-user fork branch, we called shm_open2
directly, which
you copied to this patch series. This works when compiling static, but not
when compiling
dynamically. In the blitz branch, we always do static building. But since
qemu's CI process
uses dynamic, there was an error. Turns out that shm_open2 is a 'hidden'
system call that's
used to implement other pseudo system calls. As such, it was purposely
hidden in the dynamic
case, exporting only the __sys_shm_open2 system call (normally there're
several ways to get
to these symbols for different threading models that aren't relevant for
this).  By the time I figured
out why it was failing, the history here, etc, it was easier to just make
the minor correction rather
than send it back to you for this one last trivial change. Especially since
the directions for
building bsd-user are recommend --static.

With these changes, I'm able to execute dynamically compiled hello-world:
% ./qemu-arm -L /vidpool/qemu/jails/jails/131armv7 ~/hello-13
Hello
%
which is the first time ever I've been able to run even a full trivial
program that's dynamically
linked. Well done!

Once I get these through the CI pipeline, I'll submit the pull request. And
then learn how to edit
the wiki page for the release notes :)


On Mon, Sep 25, 2023 at 12:28 PM Karim Taha <kariem.taha2.7@gmail.com>
wrote:

> Upstream the implementation of the following mmap system calls, from the
> qemu-bsd-user fork:
>    mmap(2), munmap(2),
>    mprotect(2),
>    msync(2),
>    mlock(2), munlock(2), mlockall(2), munlockall(2), mincore(2),
>    madvise(2),
>    minherit(2),
>    shm_open(2),shm_open2(2), shm_rename2(2), shm_unlink(2), shmget(2),
> shmctl(2), shmat(2),
>    shmdt(2)
>    brk(2)
>
> Karim Taha (3):
>   bsd-user: Implement shm_open2(2) system call
>   bsd-user: Add bsd-mem.c to meson.build
>   bsd-user: Implment madvise(2) to match the linux-user implementation.
>
> Kyle Evans (1):
>   bsd-user: Implement shm_rename(2) system call
>
> Stacey Son (18):
>   bsd-user: Implement struct target_ipc_perm
>   bsd-user: Implement struct target_shmid_ds
>   bsd-user: Declarations for ipc_perm and shmid_ds conversion functions
>   bsd-user: Introduce freebsd/os-misc.h to the source tree
>   bsd-user: Implement target_set_brk function in bsd-mem.c instead of
>     os-syscall.c
>   bsd-user: Implement ipc_perm conversion between host and target.
>   bsd-user: Implement shmid_ds conversion between host and target.
>   bsd-user: Introduce bsd-mem.h to the source tree
>   bsd-user: Implement mmap(2) and munmap(2)
>   bsd-user: Implement mprotect(2)
>   bsd-user: Implement msync(2)
>   bsd-user: Implement mlock(2), munlock(2), mlockall(2), munlockall(2),
>     minherit(2)
>   bsd-user: Implement mincore(2)
>   bsd-user: Implement do_obreak function
>   bsd-user: Implement shm_open(2)
>   bsd-user: Implement shm_unlink(2) and shmget(2)
>   bsd-user: Implement shmctl(2)
>   bsd-user: Implement shmat(2) and shmdt(2)
>
> Warner Losh (1):
>   bsd-user: Add stubs for vadvise(), sbrk() and sstk()
>
>  bsd-user/bsd-mem.c            | 104 ++++++++
>  bsd-user/bsd-mem.h            | 452 ++++++++++++++++++++++++++++++++++
>  bsd-user/freebsd/os-misc.h    |  94 +++++++
>  bsd-user/freebsd/os-syscall.c | 109 +++++++-
>  bsd-user/meson.build          |   1 +
>  bsd-user/mmap.c               |   2 +-
>  bsd-user/qemu-bsd.h           |  45 ++++
>  bsd-user/qemu.h               |   1 +
>  bsd-user/syscall_defs.h       |  39 +++
>  9 files changed, 842 insertions(+), 5 deletions(-)
>  create mode 100644 bsd-user/bsd-mem.c
>  create mode 100644 bsd-user/bsd-mem.h
>  create mode 100644 bsd-user/freebsd/os-misc.h
>  create mode 100644 bsd-user/qemu-bsd.h
>

queued to bsd-user-topo

with minor conflicts from rebasing it and the proc system call changes onto
one branch.

I did fix one issue: in the blitz bsd-user fork branch, we called shm_open2
directly, which
you copied to this patch series. This works when compiling static, but not
when compiling
dynamically. In the blitz branch, we always do static building. But since
qemu's CI process
uses dynamic, there was an error. Turns out that shm_open2 is a 'hidden'
system call that's
used to implement other pseudo system calls. As such, it was purposely
hidden in the dynamic
case, exporting only the __sys_shm_open2 system call (normally there's
several ways to get
to these symbols for different threading models that aren't relevant for
this).  By the time I figured
out why it was failing, the history here, etc, it was easier to just make
the minor correction rather
than send it back to you for this one last trivial change.

With these changes, I'm able to execute dynamically compiled hello-world:
% ./qemu-arm -L /vidpool/qemu/jails/jails/131armv7 ~/hello-13
Hello
%
which is one

Warner

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

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

end of thread, other threads:[~2023-09-27  4:35 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-25 18:26 [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Karim Taha
2023-09-25 18:26 ` [PATCH v6 01/23] bsd-user: Implement struct target_ipc_perm Karim Taha
2023-09-25 18:26 ` [PATCH v6 02/23] bsd-user: Implement struct target_shmid_ds Karim Taha
2023-09-25 18:26 ` [PATCH v6 03/23] bsd-user: Declarations for ipc_perm and shmid_ds conversion functions Karim Taha
2023-09-25 18:26 ` [PATCH v6 04/23] bsd-user: Introduce freebsd/os-misc.h to the source tree Karim Taha
2023-09-25 18:26 ` [PATCH v6 05/23] bsd-user: Implement shm_open2(2) system call Karim Taha
2023-09-25 18:26 ` [PATCH v6 06/23] bsd-user: Implement shm_rename(2) " Karim Taha
2023-09-25 18:26 ` [PATCH v6 07/23] bsd-user: Add bsd-mem.c to meson.build Karim Taha
2023-09-25 18:26 ` [PATCH v6 08/23] bsd-user: Implement target_set_brk function in bsd-mem.c instead of os-syscall.c Karim Taha
2023-09-25 18:26 ` [PATCH v6 09/23] bsd-user: Implement ipc_perm conversion between host and target Karim Taha
2023-09-25 18:26 ` [PATCH v6 10/23] bsd-user: Implement shmid_ds " Karim Taha
2023-09-25 18:26 ` [PATCH v6 11/23] bsd-user: Introduce bsd-mem.h to the source tree Karim Taha
2023-09-25 18:26 ` [PATCH v6 12/23] bsd-user: Implement mmap(2) and munmap(2) Karim Taha
2023-09-25 18:26 ` [PATCH v6 13/23] bsd-user: Implement mprotect(2) Karim Taha
2023-09-25 18:27 ` [PATCH v6 14/23] bsd-user: Implement msync(2) Karim Taha
2023-09-25 18:27 ` [PATCH v6 15/23] bsd-user: Implement mlock(2), munlock(2), mlockall(2), munlockall(2), minherit(2) Karim Taha
2023-09-25 18:27 ` [PATCH v6 16/23] bsd-user: Implment madvise(2) to match the linux-user implementation Karim Taha
2023-09-25 18:27 ` [PATCH v6 17/23] bsd-user: Implement mincore(2) Karim Taha
2023-09-25 18:27 ` [PATCH v6 18/23] bsd-user: Implement do_obreak function Karim Taha
2023-09-25 18:27 ` [PATCH v6 19/23] bsd-user: Implement shm_open(2) Karim Taha
2023-09-25 18:27 ` [PATCH v6 20/23] bsd-user: Implement shm_unlink(2) and shmget(2) Karim Taha
2023-09-25 18:27 ` [PATCH v6 21/23] bsd-user: Implement shmctl(2) Karim Taha
2023-09-25 18:27 ` [PATCH v6 22/23] bsd-user: Implement shmat(2) and shmdt(2) Karim Taha
2023-09-25 18:27 ` [PATCH v6 23/23] bsd-user: Add stubs for vadvise(), sbrk() and sstk() Karim Taha
2023-09-27  4:34 ` [PATCH v6 00/23] bsd-user: Implement mmap related system calls for FreeBSD Warner Losh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).