public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
* [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc)
@ 2026-02-24 14:40 Warner Losh
  2026-02-24 14:40 ` [PATCH v4 01/24] freebsd: FreeBSD 15 has native inotify Warner Losh
                   ` (23 more replies)
  0 siblings, 24 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Richard Henderson, Stacey Son, Mikael Urankar,
	Brooks Davis, Sean Bruno, Pierrick Bouvier

[ Most of these have been reviewed, except I'm missing reviews on
  bsd-user: Add do_bsd___semctl implementation
]

Update all the system calls that are implemented by bsd-misc.c. These
are the System V msgq and semaphore system calls, reboot, quotactl,
getdtablesize, and uuidgen. This includes all the support routines
needed to convert types and integrates into the build.

So I did this with the help of Claude. However, claude took care of
sequencing the commits, pulling them out one function at a time (more or
less), finding who wrote them in the complicated git history that we
have, adding proto SOBs that I confirmed and edited to real SOB
lines. All the authors have explicitly signed off with me according to
the DCO in email on all their changes and given me their preferred names
and email (just like all other prior upstreaming). It also made sure
they all compiled (though that was mostly easy since it added bsd-misc.c
late in the gagme).

Claude wrote no code. I confirmed this by diffing the files against the
'blitz' upstream branch and confirming no stray code added.

After claude did its work, I rearranged the commits a little: claude
grouped them close, but not quite right.  Claude wrote the initial
commit messages, which I edited most of the time since claude wasn't
great about including the right things often. Many of them are just
'what' and thin ony the why, but that's implicit to anybody reading the
logs (and in line with what prior upstreaming efforts have done).

The first two patches in this series were not generated by claude, or
using claude. One removes a needless linux #ifdef to avoid warnings in
common-user. The other is the uglies hack possible to meson.build and
can't go in as is. FreeBSD has grown inotify (I think it's even in
15.0), so the extenral inotify emulation library isn't needed. I just
hacked out the FreeBSD special case, but need help with how to do it
properly (eg, check for it only if inotify isn't in libc).

I also verified by hand that the final version compiles, but haven't yet
re-verified that every single commit still builds (though I believe they
will). I tweaked a few style things and then commited mirroring tweaks
in the blitz branch.

Claude didn't help me with this letter. I believe that this use of
claude is OK and falls outside the project's general prohibitions
against AI because those are aimed at preventing contamination of the
code of the project, and the code is 100% written by humans, just not
yet upstreamed. If this is successful, expect a lot more of it. If there
are legitimate issues arising from this, I'll correct and modify my
approach in the future. Initial polling of qemu-devel, though suggests
I've covered all the bases.

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
Changes in v4:
- Fix an lock_user leak in the case of errors.
- Link to v3: https://lore.kernel.org/qemu-devel/20260218-bsd-user-claude-v3-0-0137b37b221e@bsdimp.com

Changes in v3:
- Prefer g_new over g_malloc with cast
- At this point, the only warning is about added files.
- Replaced the inotify hack with the real fix in meson.build
- Fixed the copyrights with Stacey Son's blessing
- Fix missing unlock in bsd_do___semctl, and make sure we copy it
  in/out
- Fix g_autofree problem, add comment about 2048 being a kenrel limit
  for genuuid, and simplify code a little.
- Fix g_autofree mistake in host_to_target_semarray, remove free()s.
- Rebase forward on master
- Link to v2: https://lore.kernel.org/qemu-devel/20260208-bsd-user-claude-v2-0-58e5fcfdb84f@bsdimp.com

Changes in v2:
- Fixes to __semctl implementation since it differs between Linux and
  FreeBSD
- Use abi_* more frequently (especially abi_ptr)
- generally use __get_user / __put_user
- Fix meson build for inotify for FreeBSD
- Update types for target_semid_ds and target_msqid_ds to be
  more logically correct (though physically the same type)
- Reword commit description of dropping .note.GNU-stack
- Link to v1: https://lore.kernel.org/qemu-devel/20260205-bsd-user-claude-v1-0-8d8ff0035372@bsdimp.com

---
Stacey Son (17):
      bsd-user: Add host_to_target_uuid for uuidgen(2)
      bsd-user: Add target_to_host_semarray for semaphore operations
      bsd-user: Add host_to_target_semarray for semaphore operations
      bsd-user: Add target_to_host_semid_ds for semctl(2)
      bsd-user: Add host_to_target_semid_ds for semctl(2)
      bsd-user: Add target_to_host_msqid_ds for msgctl(2)
      bsd-user: Add host_to_target_msqid_ds for msgctl(2)
      bsd-user: Add do_bsd_quotactl, do_bsd_reboot and do_bsd_getdtablesize
      bsd-user: Add do_bsd_uuidgen implementation
      bsd-user: Add do_bsd_semget implementation
      bsd-user: Add do_bsd_semop implementation
      bsd-user: Add do_bsd___semctl implementation
      bsd-user: Add do_bsd_msgctl implementation
      bsd-user: Add message queue implementations
      bsd-user: Implement System V semaphore calls
      bsd-user: Add System V message queue syscalls
      bsd-user: Add miscellaneous BSD syscall implementations

Warner Losh (7):
      freebsd: FreeBSD 15 has native inotify
      common-user: Drop __linux__ around .note.GNU-stack
      bsd-user: Add target_semid_ds and target_msqid_ds structures
      bsd-user: Add target_uuid structure for uuidgen syscall
      bsd-user: Add function declarations for bsd-misc.c conversions
      bsd-user: Add semaphore operation constants and structures
      bsd-user: Add bsd-misc.c to build

 bsd-user/bsd-misc.c           | 192 ++++++++++++++++++++++
 bsd-user/bsd-misc.h           | 363 ++++++++++++++++++++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c |  52 ++++++
 bsd-user/meson.build          |   1 +
 bsd-user/qemu-bsd.h           |  15 ++
 bsd-user/syscall_defs.h       |  67 ++++++++
 common-user/safe-syscall.S    |   2 +-
 meson.build                   |  14 +-
 util/meson.build              |   6 +-
 9 files changed, 697 insertions(+), 15 deletions(-)
---
base-commit: ece408818d27f745ef1b05fb3cc99a1e7a5bf580
change-id: 20260205-bsd-user-claude-a691717c430b

Best regards,
-- 
Warner Losh <imp@bsdimp.com>



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

* [PATCH v4 01/24] freebsd: FreeBSD 15 has native inotify
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-24 15:28   ` Gleb Popov
  2026-03-11 11:59   ` Michael Tokarev
  2026-02-24 14:40 ` [PATCH v4 02/24] common-user: Drop __linux__ around .note.GNU-stack Warner Losh
                   ` (22 subsequent siblings)
  23 siblings, 2 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh

Check to make sure that we have inotify in libc, before looking for it
in libinotify.

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: Daniel P. Berrange <berrange@redhat.com>
Cc: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 meson.build      | 14 +++++---------
 util/meson.build |  6 +-----
 2 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/meson.build b/meson.build
index 4af32c3e1f..3d761f89b5 100644
--- a/meson.build
+++ b/meson.build
@@ -2664,18 +2664,14 @@ else
 endif
 config_host_data.set('CONFIG_ASAN_IFACE_FIBER', have_asan_fiber)
 
+inotify = not_found
 have_inotify_init = cc.has_header_symbol('sys/inotify.h', 'inotify_init')
 have_inotify_init1 = cc.has_header_symbol('sys/inotify.h', 'inotify_init1')
-inotify = not_found
-if (have_inotify_init or have_inotify_init1) and host_os == 'freebsd'
-  # libinotify-kqueue
+if (have_inotify_init or have_inotify_init1) and not cc.has_function('inotify_init1')
+  # FreeBSD 14 and older need libinotify-kqueue wrapper
   inotify = cc.find_library('inotify')
-  if have_inotify_init
-    have_inotify_init = inotify.found()
-  endif
-  if have_inotify_init1
-    have_inotify_init1 = inotify.found()
-  endif
+  have_inotify_init = have_inotify_init and inotify.found()
+  have_inotify_init1 = have_inotify_init1 and inotify.found()
 endif
 config_host_data.set('CONFIG_INOTIFY', have_inotify_init)
 config_host_data.set('CONFIG_INOTIFY1', have_inotify_init1)
diff --git a/util/meson.build b/util/meson.build
index 7c9445615d..e7a2a2a64c 100644
--- a/util/meson.build
+++ b/util/meson.build
@@ -102,11 +102,7 @@ if have_block
   util_ss.add(files('throttle.c'))
   util_ss.add(files('timed-average.c'))
   if config_host_data.get('CONFIG_INOTIFY1')
-    freebsd_dep = []
-    if host_os == 'freebsd'
-      freebsd_dep = inotify
-    endif
-    util_ss.add(files('filemonitor-inotify.c'), freebsd_dep)
+    util_ss.add(files('filemonitor-inotify.c'), inotify)
   else
     util_ss.add(files('filemonitor-stub.c'))
   endif

-- 
2.52.0



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

* [PATCH v4 02/24] common-user: Drop __linux__ around .note.GNU-stack
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
  2026-02-24 14:40 ` [PATCH v4 01/24] freebsd: FreeBSD 15 has native inotify Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-24 14:40 ` [PATCH v4 03/24] bsd-user: Add target_semid_ds and target_msqid_ds structures Warner Losh
                   ` (21 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Richard Henderson

GNU-stack tagging is a toolchain issue, not an OS issue. All the
toolchains require this for ELF.

Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 common-user/safe-syscall.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common-user/safe-syscall.S b/common-user/safe-syscall.S
index 74f7e35694..2f714cfbe8 100644
--- a/common-user/safe-syscall.S
+++ b/common-user/safe-syscall.S
@@ -22,6 +22,6 @@
  * assembly needs an executable stack and the whole QEMU binary will
  * needlessly end up with one. This should be the last thing in this file.
  */
-#if defined(__linux__) && defined(__ELF__)
+#if defined(__ELF__)
 .section        .note.GNU-stack, "", %progbits
 #endif

-- 
2.52.0



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

* [PATCH v4 03/24] bsd-user: Add target_semid_ds and target_msqid_ds structures
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
  2026-02-24 14:40 ` [PATCH v4 01/24] freebsd: FreeBSD 15 has native inotify Warner Losh
  2026-02-24 14:40 ` [PATCH v4 02/24] common-user: Drop __linux__ around .note.GNU-stack Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-24 15:31   ` Gleb Popov
  2026-02-24 14:40 ` [PATCH v4 04/24] bsd-user: Add target_uuid structure for uuidgen syscall Warner Losh
                   ` (20 subsequent siblings)
  23 siblings, 1 reply; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Stacey Son, Mikael Urankar, Richard Henderson

Add the target ABI definitions for System V semaphore and message queue
data structures, needed for semctl() and msgctl() syscall emulation.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Mikael Urankar <mikael.urankar@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/syscall_defs.h | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h
index cc4b484f3a..92fec12acd 100644
--- a/bsd-user/syscall_defs.h
+++ b/bsd-user/syscall_defs.h
@@ -92,6 +92,39 @@ struct bsd_shm_regions {
     abi_long size;
 };
 
+/*
+ * sys/sem.h
+ */
+struct target_semid_ds {
+    struct target_ipc_perm sem_perm; /* operation permission struct */
+    abi_ptr     sem_base;   /* pointer to first semaphore in set */
+    abi_ushort  sem_nsems;  /* number of sems in set */
+    target_time_t   sem_otime;  /* last operation time */
+    target_time_t   sem_ctime;  /* times measured in secs */
+};
+
+/*
+ * sys/msg.h
+ */
+struct target_msqid_ds {
+    struct  target_ipc_perm msg_perm; /* msg queue permission bits */
+    abi_ptr     msg_first;  /* first message in the queue */
+    abi_ptr     msg_last;   /* last message in the queue */
+    abi_ulong   msg_cbytes; /* # of bytes in use on the queue */
+    abi_ulong   msg_qnum;   /* number of msgs in the queue */
+    abi_ulong   msg_qbytes; /* max # of bytes on the queue */
+    int32_t     msg_lspid;  /* pid of last msgsnd() */
+    int32_t     msg_lrpid;  /* pid of last msgrcv() */
+    target_time_t   msg_stime;  /* time of last msgsnd() */
+    target_time_t   msg_rtime;  /* time of last msgrcv() */
+    target_time_t   msg_ctime;  /* time of last msgctl() */
+};
+
+struct target_msgbuf {
+    abi_long    mtype;      /* message type */
+    char        mtext[1];   /* body of message */
+};
+
 /*
  *  sys/mman.h
  */

-- 
2.52.0



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

* [PATCH v4 04/24] bsd-user: Add target_uuid structure for uuidgen syscall
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
                   ` (2 preceding siblings ...)
  2026-02-24 14:40 ` [PATCH v4 03/24] bsd-user: Add target_semid_ds and target_msqid_ds structures Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-24 14:40 ` [PATCH v4 05/24] bsd-user: Add function declarations for bsd-misc.c conversions Warner Losh
                   ` (19 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Stacey Son, Richard Henderson

Add the target ABI definition for struct uuid, needed for uuidgen(2)
syscall emulation.

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

diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h
index 92fec12acd..972bcc425e 100644
--- a/bsd-user/syscall_defs.h
+++ b/bsd-user/syscall_defs.h
@@ -503,6 +503,20 @@ struct target_procctl_reaper_kill {
     uint32_t rk_pad0[15];
 };
 
+/*
+ * sys/uuid.h
+ */
+#define TARGET_UUID_NODE_LEN    6
+
+struct target_uuid {
+    uint32_t    time_low;
+    uint16_t    time_mid;
+    uint16_t    time_hi_and_version;
+    uint8_t     clock_seq_hi_and_reserved;
+    uint8_t     clock_seq_low;
+    uint8_t     node[TARGET_UUID_NODE_LEN];
+};
+
 
 #define safe_syscall0(type, name) \
 type safe_##name(void) \

-- 
2.52.0



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

* [PATCH v4 05/24] bsd-user: Add function declarations for bsd-misc.c conversions
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
                   ` (3 preceding siblings ...)
  2026-02-24 14:40 ` [PATCH v4 04/24] bsd-user: Add target_uuid structure for uuidgen syscall Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-24 14:40 ` [PATCH v4 06/24] bsd-user: Add host_to_target_uuid for uuidgen(2) Warner Losh
                   ` (18 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Stacey Son, Richard Henderson

Add function declarations for BSD System V IPC and UUID conversion
routines that will be implemented in bsd-misc.c.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/qemu-bsd.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/bsd-user/qemu-bsd.h b/bsd-user/qemu-bsd.h
index 56affcd31d..b98d1d76b2 100644
--- a/bsd-user/qemu-bsd.h
+++ b/bsd-user/qemu-bsd.h
@@ -54,4 +54,19 @@ abi_long target_to_host_shmid_ds(struct shmid_ds *host_sd,
 abi_long host_to_target_shmid_ds(abi_ulong target_addr,
         struct shmid_ds *host_sd);
 
+/* bsd-misc.c */
+abi_long host_to_target_uuid(abi_ulong target_addr, struct uuid *host_uuid);
+abi_long target_to_host_semarray(int semid, unsigned short **host_array,
+        abi_ulong target_addr);
+abi_long host_to_target_semarray(int semid, abi_ulong target_addr,
+        unsigned short **host_array);
+abi_long target_to_host_semid_ds(struct semid_ds *host_sd,
+        abi_ulong target_addr);
+abi_long host_to_target_semid_ds(abi_ulong target_addr,
+        struct semid_ds *host_sd);
+abi_long target_to_host_msqid_ds(struct msqid_ds *host_md,
+        abi_ulong target_addr);
+abi_long host_to_target_msqid_ds(abi_ulong target_addr,
+        struct msqid_ds *host_md);
+
 #endif /* QEMU_BSD_H */

-- 
2.52.0



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

* [PATCH v4 06/24] bsd-user: Add host_to_target_uuid for uuidgen(2)
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
                   ` (4 preceding siblings ...)
  2026-02-24 14:40 ` [PATCH v4 05/24] bsd-user: Add function declarations for bsd-misc.c conversions Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-24 14:40 ` [PATCH v4 07/24] bsd-user: Add target_to_host_semarray for semaphore operations Warner Losh
                   ` (17 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Stacey Son, Richard Henderson

From: Stacey Son <sson@FreeBSD.org>

Add host_to_target_uuid() to convert host struct uuid to target ABI
for the uuidgen(2) syscall.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsd-misc.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/bsd-user/bsd-misc.c b/bsd-user/bsd-misc.c
new file mode 100644
index 0000000000..68b67f37ba
--- /dev/null
+++ b/bsd-user/bsd-misc.c
@@ -0,0 +1,35 @@
+/*
+ * BSD misc system call conversions routines
+ *
+ * Copyright (c) 2013 Stacey D. Son
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include "qemu/osdep.h"
+
+#include <sys/uuid.h>
+
+#include "qemu.h"
+#include "qemu-bsd.h"
+
+/*
+ * BSD uuidgen(2) struct uuid conversion
+ */
+abi_long host_to_target_uuid(abi_ulong target_addr, struct uuid *host_uuid)
+{
+    struct target_uuid *target_uuid;
+
+    if (!lock_user_struct(VERIFY_WRITE, target_uuid, target_addr, 0)) {
+        return -TARGET_EFAULT;
+    }
+    __put_user(host_uuid->time_low, &target_uuid->time_low);
+    __put_user(host_uuid->time_mid, &target_uuid->time_mid);
+    __put_user(host_uuid->time_hi_and_version,
+        &target_uuid->time_hi_and_version);
+    host_uuid->clock_seq_hi_and_reserved =
+        target_uuid->clock_seq_hi_and_reserved;
+    host_uuid->clock_seq_low = target_uuid->clock_seq_low;
+    memcpy(host_uuid->node, target_uuid->node, TARGET_UUID_NODE_LEN);
+    unlock_user_struct(target_uuid, target_addr, 1);
+    return 0;
+}

-- 
2.52.0



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

* [PATCH v4 07/24] bsd-user: Add target_to_host_semarray for semaphore operations
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
                   ` (5 preceding siblings ...)
  2026-02-24 14:40 ` [PATCH v4 06/24] bsd-user: Add host_to_target_uuid for uuidgen(2) Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-24 14:40 ` [PATCH v4 08/24] bsd-user: Add host_to_target_semarray " Warner Losh
                   ` (16 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Stacey Son, Richard Henderson

From: Stacey Son <sson@FreeBSD.org>

Add target_to_host_semarray() to convert target semaphore array to host
format for semctl(2) SETALL operations.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsd-misc.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/bsd-user/bsd-misc.c b/bsd-user/bsd-misc.c
index 68b67f37ba..d1645db46b 100644
--- a/bsd-user/bsd-misc.c
+++ b/bsd-user/bsd-misc.c
@@ -7,6 +7,11 @@
  */
 #include "qemu/osdep.h"
 
+#define _WANT_SEMUN
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <sys/sem.h>
 #include <sys/uuid.h>
 
 #include "qemu.h"
@@ -33,3 +38,33 @@ abi_long host_to_target_uuid(abi_ulong target_addr, struct uuid *host_uuid)
     unlock_user_struct(target_uuid, target_addr, 1);
     return 0;
 }
+
+abi_long target_to_host_semarray(int semid, unsigned short **host_array,
+        abi_ulong target_addr)
+{
+    abi_long ret;
+    int nsems, i;
+    unsigned short *array;
+    union semun semun;
+    struct semid_ds semid_ds;
+
+    semun.buf = &semid_ds;
+    ret = semctl(semid, 0, IPC_STAT, semun);
+    if (ret == -1) {
+        return get_errno(ret);
+    }
+    nsems = semid_ds.sem_nsems;
+    *host_array = g_new(unsigned short, nsems);
+    array = lock_user(VERIFY_READ, target_addr,
+        nsems * sizeof(unsigned short), 1);
+    if (array == NULL) {
+        free(*host_array);
+        return -TARGET_EFAULT;
+    }
+    for (i = 0; i < nsems; i++) {
+        __get_user((*host_array)[i], array + i);
+    }
+    unlock_user(array, target_addr, 0);
+
+    return 0;
+}

-- 
2.52.0



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

* [PATCH v4 08/24] bsd-user: Add host_to_target_semarray for semaphore operations
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
                   ` (6 preceding siblings ...)
  2026-02-24 14:40 ` [PATCH v4 07/24] bsd-user: Add target_to_host_semarray for semaphore operations Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-24 14:40 ` [PATCH v4 09/24] bsd-user: Add target_to_host_semid_ds for semctl(2) Warner Losh
                   ` (15 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Stacey Son, Richard Henderson

From: Stacey Son <sson@FreeBSD.org>

Add host_to_target_semarray() to convert host semaphore array to target
format for semctl(2) GETALL operations.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsd-misc.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/bsd-user/bsd-misc.c b/bsd-user/bsd-misc.c
index d1645db46b..65fd7b72e5 100644
--- a/bsd-user/bsd-misc.c
+++ b/bsd-user/bsd-misc.c
@@ -68,3 +68,33 @@ abi_long target_to_host_semarray(int semid, unsigned short **host_array,
 
     return 0;
 }
+
+abi_long host_to_target_semarray(int semid, abi_ulong target_addr,
+        unsigned short **host_arrayp)
+{
+    g_autofree unsigned short *host_array = *host_arrayp;
+    abi_long ret;
+    int nsems, i;
+    unsigned short *array;
+    union semun semun;
+    struct semid_ds semid_ds;
+
+    semun.buf = &semid_ds;
+
+    ret = semctl(semid, 0, IPC_STAT, semun);
+    if (ret == -1) {
+        return get_errno(ret);
+    }
+
+    nsems = semid_ds.sem_nsems;
+    array = (unsigned short *)lock_user(VERIFY_WRITE, target_addr,
+        nsems * sizeof(unsigned short), 0);
+    if (array == NULL) {
+        return -TARGET_EFAULT;
+    }
+    for (i = 0; i < nsems; i++) {
+        __put_user(array[i], host_array + i);
+    }
+    unlock_user(array, target_addr, 1);
+    return 0;
+}

-- 
2.52.0



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

* [PATCH v4 09/24] bsd-user: Add target_to_host_semid_ds for semctl(2)
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
                   ` (7 preceding siblings ...)
  2026-02-24 14:40 ` [PATCH v4 08/24] bsd-user: Add host_to_target_semarray " Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-24 14:40 ` [PATCH v4 10/24] bsd-user: Add host_to_target_semid_ds " Warner Losh
                   ` (14 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Stacey Son, Mikael Urankar, Richard Henderson

From: Stacey Son <sson@FreeBSD.org>

Add target_to_host_semid_ds() to convert target struct semid_ds to host
format for semctl(2) IPC_SET operations.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Mikael Urankar <mikael.urankar@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsd-misc.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/bsd-user/bsd-misc.c b/bsd-user/bsd-misc.c
index 65fd7b72e5..941f30d547 100644
--- a/bsd-user/bsd-misc.c
+++ b/bsd-user/bsd-misc.c
@@ -98,3 +98,21 @@ abi_long host_to_target_semarray(int semid, abi_ulong target_addr,
     unlock_user(array, target_addr, 1);
     return 0;
 }
+
+abi_long target_to_host_semid_ds(struct semid_ds *host_sd,
+        abi_ulong target_addr)
+{
+    struct target_semid_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->sem_perm, &target_sd->sem_perm);
+    /* sem_base is not used by kernel for IPC_STAT/IPC_SET */
+    /* host_sd->sem_base  = g2h_untagged(target_sd->sem_base); */
+    __get_user(host_sd->sem_nsems, &target_sd->sem_nsems);
+    __get_user(host_sd->sem_otime, &target_sd->sem_otime);
+    __get_user(host_sd->sem_ctime, &target_sd->sem_ctime);
+    unlock_user_struct(target_sd, target_addr, 0);
+    return 0;
+}

-- 
2.52.0



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

* [PATCH v4 10/24] bsd-user: Add host_to_target_semid_ds for semctl(2)
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
                   ` (8 preceding siblings ...)
  2026-02-24 14:40 ` [PATCH v4 09/24] bsd-user: Add target_to_host_semid_ds for semctl(2) Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-24 14:40 ` [PATCH v4 11/24] bsd-user: Add target_to_host_msqid_ds for msgctl(2) Warner Losh
                   ` (13 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Stacey Son, Richard Henderson

From: Stacey Son <sson@FreeBSD.org>

Add host_to_target_semid_ds() to convert host struct semid_ds to target
format for semctl(2) IPC_STAT operations.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsd-misc.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/bsd-user/bsd-misc.c b/bsd-user/bsd-misc.c
index 941f30d547..5b02006313 100644
--- a/bsd-user/bsd-misc.c
+++ b/bsd-user/bsd-misc.c
@@ -116,3 +116,23 @@ abi_long target_to_host_semid_ds(struct semid_ds *host_sd,
     unlock_user_struct(target_sd, target_addr, 0);
     return 0;
 }
+
+abi_long host_to_target_semid_ds(abi_ulong target_addr,
+        struct semid_ds *host_sd)
+{
+    struct target_semid_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->sem_perm,
+                                    &host_sd->sem_perm);
+    /* sem_base is not used by kernel for IPC_STAT/IPC_SET */
+    /* target_sd->sem_base = h2g((void *)host_sd->sem_base); */
+    __put_user(target_sd->sem_nsems, &host_sd->sem_nsems);
+    __put_user(target_sd->sem_otime, &host_sd->sem_otime);
+    __put_user(target_sd->sem_ctime, &host_sd->sem_ctime);
+    unlock_user_struct(target_sd, target_addr, 1);
+
+    return 0;
+}

-- 
2.52.0



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

* [PATCH v4 11/24] bsd-user: Add target_to_host_msqid_ds for msgctl(2)
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
                   ` (9 preceding siblings ...)
  2026-02-24 14:40 ` [PATCH v4 10/24] bsd-user: Add host_to_target_semid_ds " Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-24 14:40 ` [PATCH v4 12/24] bsd-user: Add host_to_target_msqid_ds " Warner Losh
                   ` (12 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Stacey Son, Brooks Davis, Sean Bruno, Mikael Urankar,
	Richard Henderson

From: Stacey Son <sson@FreeBSD.org>

Add target_to_host_msqid_ds() to convert target struct msqid_ds to host
format for msgctl(2) IPC_SET operations. Uses memset to zero the struct
rather than directly accessing kernel-only members. Handles FreeBSD
64-bit time_t except on i386.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Brooks Davis <brooks@one-eyed-alien.net>
Signed-off-by: Sean Bruno <sbruno@FreeBSD.org>
Signed-off-by: Mikael Urankar <mikael.urankar@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsd-misc.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/bsd-user/bsd-misc.c b/bsd-user/bsd-misc.c
index 5b02006313..5e5a590227 100644
--- a/bsd-user/bsd-misc.c
+++ b/bsd-user/bsd-misc.c
@@ -136,3 +136,30 @@ abi_long host_to_target_semid_ds(abi_ulong target_addr,
 
     return 0;
 }
+
+abi_long target_to_host_msqid_ds(struct msqid_ds *host_md,
+        abi_ulong target_addr)
+{
+    struct target_msqid_ds *target_md;
+
+    if (!lock_user_struct(VERIFY_READ, target_md, target_addr, 1)) {
+        return -TARGET_EFAULT;
+    }
+
+    memset(host_md, 0, sizeof(struct msqid_ds));
+    target_to_host_ipc_perm__locked(&host_md->msg_perm,
+                                    &target_md->msg_perm);
+
+    /* msg_first and msg_last are not used by IPC_SET/IPC_STAT in kernel. */
+    __get_user(host_md->msg_cbytes, &target_md->msg_cbytes);
+    __get_user(host_md->msg_qnum, &target_md->msg_qnum);
+    __get_user(host_md->msg_qbytes, &target_md->msg_qbytes);
+    __get_user(host_md->msg_lspid, &target_md->msg_lspid);
+    __get_user(host_md->msg_lrpid, &target_md->msg_lrpid);
+    __get_user(host_md->msg_stime, &target_md->msg_stime);
+    __get_user(host_md->msg_rtime, &target_md->msg_rtime);
+    __get_user(host_md->msg_ctime, &target_md->msg_ctime);
+    unlock_user_struct(target_md, target_addr, 0);
+
+    return 0;
+}

-- 
2.52.0



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

* [PATCH v4 12/24] bsd-user: Add host_to_target_msqid_ds for msgctl(2)
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
                   ` (10 preceding siblings ...)
  2026-02-24 14:40 ` [PATCH v4 11/24] bsd-user: Add target_to_host_msqid_ds for msgctl(2) Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-24 14:40 ` [PATCH v4 13/24] bsd-user: Add semaphore operation constants and structures Warner Losh
                   ` (11 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Stacey Son, Brooks Davis, Sean Bruno, Mikael Urankar,
	Richard Henderson

From: Stacey Son <sson@FreeBSD.org>

Add host_to_target_msqid_ds() to convert host struct msqid_ds to target
format for msgctl(2) IPC_STAT operations.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Brooks Davis <brooks@one-eyed-alien.net>
Signed-off-by: Sean Bruno <sbruno@FreeBSD.org>
Signed-off-by: Mikael Urankar <mikael.urankar@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsd-misc.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/bsd-user/bsd-misc.c b/bsd-user/bsd-misc.c
index 5e5a590227..3e1968718f 100644
--- a/bsd-user/bsd-misc.c
+++ b/bsd-user/bsd-misc.c
@@ -163,3 +163,30 @@ abi_long target_to_host_msqid_ds(struct msqid_ds *host_md,
 
     return 0;
 }
+
+abi_long host_to_target_msqid_ds(abi_ulong target_addr,
+        struct msqid_ds *host_md)
+{
+    struct target_msqid_ds *target_md;
+
+    if (!lock_user_struct(VERIFY_WRITE, target_md, target_addr, 0)) {
+        return -TARGET_EFAULT;
+    }
+
+    memset(target_md, 0, sizeof(struct target_msqid_ds));
+    host_to_target_ipc_perm__locked(&target_md->msg_perm,
+                                    &host_md->msg_perm);
+
+    /* msg_first and msg_last are not used by IPC_SET/IPC_STAT in kernel. */
+    __put_user(target_md->msg_cbytes, &host_md->msg_cbytes);
+    __put_user(target_md->msg_qnum, &host_md->msg_qnum);
+    __put_user(target_md->msg_qbytes, &host_md->msg_qbytes);
+    __put_user(target_md->msg_lspid, &host_md->msg_lspid);
+    __put_user(target_md->msg_lrpid, &host_md->msg_lrpid);
+    __put_user(target_md->msg_stime, &host_md->msg_stime);
+    __put_user(target_md->msg_rtime, &host_md->msg_rtime);
+    __put_user(target_md->msg_ctime, &host_md->msg_ctime);
+    unlock_user_struct(target_md, target_addr, 1);
+
+    return 0;
+}

-- 
2.52.0



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

* [PATCH v4 13/24] bsd-user: Add semaphore operation constants and structures
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
                   ` (11 preceding siblings ...)
  2026-02-24 14:40 ` [PATCH v4 12/24] bsd-user: Add host_to_target_msqid_ds " Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-24 14:40 ` [PATCH v4 14/24] bsd-user: Add do_bsd_quotactl, do_bsd_reboot and do_bsd_getdtablesize Warner Losh
                   ` (10 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Stacey Son, Richard Henderson

Add System V semaphore operation constants (GETVAL, SETVAL, GETALL, etc.)
and the target_sembuf and target_semun structures needed for semop(2) and
semctl(2) syscall emulation.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-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 972bcc425e..6a789b2a29 100644
--- a/bsd-user/syscall_defs.h
+++ b/bsd-user/syscall_defs.h
@@ -95,6 +95,26 @@ struct bsd_shm_regions {
 /*
  * sys/sem.h
  */
+#define TARGET_GETNCNT  3   /* Return the value of semncnt {READ} */
+#define TARGET_GETPID   4   /* Return the value of sempid {READ} */
+#define TARGET_GETVAL   5   /* Return the value of semval {READ} */
+#define TARGET_GETALL   6   /* Return semvals into arg.array {READ} */
+#define TARGET_GETZCNT  7   /* Return the value of semzcnt {READ} */
+#define TARGET_SETVAL   8   /* Set the value of semval to arg.val {ALTER} */
+#define TARGET_SETALL   9   /* Set semvals from arg.array {ALTER} */
+
+struct target_sembuf {
+    abi_ushort      sem_num;        /* semaphore # */
+    abi_short       sem_op;         /* semaphore operation */
+    abi_short       sem_flg;        /* operation flags */
+};
+
+union target_semun {
+    abi_int     val;        /* value for SETVAL */
+    abi_ulong   buf;        /* buffer for IPC_STAT & IPC_SET */
+    abi_ulong   array;      /* array for GETALL & SETALL */
+};
+
 struct target_semid_ds {
     struct target_ipc_perm sem_perm; /* operation permission struct */
     abi_ptr     sem_base;   /* pointer to first semaphore in set */

-- 
2.52.0



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

* [PATCH v4 14/24] bsd-user: Add do_bsd_quotactl, do_bsd_reboot and do_bsd_getdtablesize
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
                   ` (12 preceding siblings ...)
  2026-02-24 14:40 ` [PATCH v4 13/24] bsd-user: Add semaphore operation constants and structures Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-24 14:40 ` [PATCH v4 15/24] bsd-user: Add do_bsd_uuidgen implementation Warner Losh
                   ` (9 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Stacey Son, Richard Henderson

From: Stacey Son <sson@FreeBSD.org>

Add some trivial misc system calls: stub implementations for quotactl(2)
and reboot(2) syscall; a trivial do_bsd_getdtablesize that calls
getdtablesize(2).

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsd-misc.h | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/bsd-user/bsd-misc.h b/bsd-user/bsd-misc.h
new file mode 100644
index 0000000000..7587ffd605
--- /dev/null
+++ b/bsd-user/bsd-misc.h
@@ -0,0 +1,41 @@
+/*
+ * miscellaneous BSD system call shims
+ *
+ * Copyright (c) 2013 Stacey D. Son
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef BSD_MISC_H
+#define BSD_MISC_H
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <sys/sem.h>
+#include <sys/uuid.h>
+
+#include "qemu-bsd.h"
+
+/* quotactl(2) */
+static inline abi_long do_bsd_quotactl(abi_ulong path, abi_long cmd,
+        __unused abi_ulong target_addr)
+{
+    qemu_log("qemu: Unsupported syscall quotactl()\n");
+    return -TARGET_ENOSYS;
+}
+
+/* reboot(2) */
+static inline abi_long do_bsd_reboot(abi_long how)
+{
+    qemu_log("qemu: Unsupported syscall reboot()\n");
+    return -TARGET_ENOSYS;
+}
+
+/* getdtablesize(2) */
+static inline abi_long do_bsd_getdtablesize(void)
+{
+    return get_errno(getdtablesize());
+}
+
+#endif /* BSD_MISC_H */

-- 
2.52.0



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

* [PATCH v4 15/24] bsd-user: Add do_bsd_uuidgen implementation
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
                   ` (13 preceding siblings ...)
  2026-02-24 14:40 ` [PATCH v4 14/24] bsd-user: Add do_bsd_quotactl, do_bsd_reboot and do_bsd_getdtablesize Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-24 14:40 ` [PATCH v4 16/24] bsd-user: Add do_bsd_semget implementation Warner Losh
                   ` (8 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Stacey Son, Pierrick Bouvier

From: Stacey Son <sson@FreeBSD.org>

Add implementation of uuidgen(2) syscall that generates UUIDs and
converts them to target ABI format.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsd-misc.h | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/bsd-user/bsd-misc.h b/bsd-user/bsd-misc.h
index 7587ffd605..9f1cc8a0cd 100644
--- a/bsd-user/bsd-misc.h
+++ b/bsd-user/bsd-misc.h
@@ -32,6 +32,39 @@ static inline abi_long do_bsd_reboot(abi_long how)
     return -TARGET_ENOSYS;
 }
 
+/* uuidgen(2) */
+static inline abi_long do_bsd_uuidgen(abi_ulong target_addr, int count)
+{
+    int i;
+    abi_long ret;
+    g_autofree struct uuid *host_uuid = NULL;
+
+    /*
+     * 2048 is the kernel limit, but there's no #define for it, nor any sysctl
+     * to query it.
+     */
+    if (count < 1 || count > 2048) {
+        return -TARGET_EINVAL;
+    }
+
+    host_uuid = g_malloc(count * sizeof(struct uuid));
+
+    ret = get_errno(uuidgen(host_uuid, count));
+    if (is_error(ret)) {
+        goto out;
+    }
+    for (i = 0; i < count; i++) {
+        ret = host_to_target_uuid(target_addr +
+            (abi_ulong)(sizeof(struct target_uuid) * i), &host_uuid[i]);
+        if (is_error(ret)) {
+            break;
+        }
+    }
+
+out:
+    return ret;
+}
+
 /* getdtablesize(2) */
 static inline abi_long do_bsd_getdtablesize(void)
 {

-- 
2.52.0



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

* [PATCH v4 16/24] bsd-user: Add do_bsd_semget implementation
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
                   ` (14 preceding siblings ...)
  2026-02-24 14:40 ` [PATCH v4 15/24] bsd-user: Add do_bsd_uuidgen implementation Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-24 14:40 ` [PATCH v4 17/24] bsd-user: Add do_bsd_semop implementation Warner Losh
                   ` (7 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Stacey Son, Richard Henderson

From: Stacey Son <sson@FreeBSD.org>

Add implementation of semget(2) syscall to get System V semaphore set
identifier. Converts target IPC flags to host format.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsd-misc.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/bsd-user/bsd-misc.h b/bsd-user/bsd-misc.h
index 9f1cc8a0cd..3dffb977a5 100644
--- a/bsd-user/bsd-misc.h
+++ b/bsd-user/bsd-misc.h
@@ -65,6 +65,18 @@ out:
     return ret;
 }
 
+/*
+ * System V Semaphores
+ */
+
+/* semget(2) */
+static inline abi_long do_bsd_semget(abi_long key, int nsems,
+        int target_flags)
+{
+    return get_errno(semget(key, nsems,
+                target_to_host_bitmask(target_flags, ipc_flags_tbl)));
+}
+
 /* getdtablesize(2) */
 static inline abi_long do_bsd_getdtablesize(void)
 {

-- 
2.52.0



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

* [PATCH v4 17/24] bsd-user: Add do_bsd_semop implementation
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
                   ` (15 preceding siblings ...)
  2026-02-24 14:40 ` [PATCH v4 16/24] bsd-user: Add do_bsd_semget implementation Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-24 14:40 ` [PATCH v4 18/24] bsd-user: Add do_bsd___semctl implementation Warner Losh
                   ` (6 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Stacey Son, Richard Henderson

From: Stacey Son <sson@FreeBSD.org>

Add implementation of semop(2) syscall to perform System V semaphore
operations. Converts target sembuf array to host format and executes
operations.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsd-misc.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/bsd-user/bsd-misc.h b/bsd-user/bsd-misc.h
index 3dffb977a5..e1e552b58f 100644
--- a/bsd-user/bsd-misc.h
+++ b/bsd-user/bsd-misc.h
@@ -77,6 +77,28 @@ static inline abi_long do_bsd_semget(abi_long key, int nsems,
                 target_to_host_bitmask(target_flags, ipc_flags_tbl)));
 }
 
+/* semop(2) */
+static inline abi_long do_bsd_semop(int semid, abi_long ptr, unsigned nsops)
+{
+    g_autofree struct sembuf *sops = g_malloc(nsops * sizeof(struct sembuf));
+    struct target_sembuf *target_sembuf;
+    int i;
+
+    target_sembuf = lock_user(VERIFY_READ, ptr,
+            nsops * sizeof(struct target_sembuf), 1);
+    if (target_sembuf == NULL) {
+        return -TARGET_EFAULT;
+    }
+    for (i = 0; i < nsops; i++) {
+        __get_user(sops[i].sem_num, &target_sembuf[i].sem_num);
+        __get_user(sops[i].sem_op, &target_sembuf[i].sem_op);
+        __get_user(sops[i].sem_flg, &target_sembuf[i].sem_flg);
+    }
+    unlock_user(target_sembuf, ptr, 0);
+
+    return semop(semid, sops, nsops);
+}
+
 /* getdtablesize(2) */
 static inline abi_long do_bsd_getdtablesize(void)
 {

-- 
2.52.0



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

* [PATCH v4 18/24] bsd-user: Add do_bsd___semctl implementation
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
                   ` (16 preceding siblings ...)
  2026-02-24 14:40 ` [PATCH v4 17/24] bsd-user: Add do_bsd_semop implementation Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-26 19:45   ` Warner Losh
  2026-02-26 19:56   ` Pierrick Bouvier
  2026-02-24 14:40 ` [PATCH v4 19/24] bsd-user: Add do_bsd_msgctl implementation Warner Losh
                   ` (5 subsequent siblings)
  23 siblings, 2 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Stacey Son, Pierrick Bouvier

From: Stacey Son <sson@FreeBSD.org>

Add implementation of __semctl(2) syscall for System V semaphore control
operations. Handles command translation, endianness conversion for GETVAL/
SETVAL, and array/structure conversions for GETALL/SETALL/IPC_STAT/IPC_SET.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Cc: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsd-misc.h | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 111 insertions(+)

diff --git a/bsd-user/bsd-misc.h b/bsd-user/bsd-misc.h
index e1e552b58f..72b3db0b74 100644
--- a/bsd-user/bsd-misc.h
+++ b/bsd-user/bsd-misc.h
@@ -99,6 +99,117 @@ static inline abi_long do_bsd_semop(int semid, abi_long ptr, unsigned nsops)
     return semop(semid, sops, nsops);
 }
 
+/* __semctl(2) */
+static inline abi_long do_bsd___semctl(int semid, int semnum, int target_cmd,
+                                       abi_ptr un_ptr)
+{
+    void *target_un;
+    union semun arg;
+    struct semid_ds dsarg;
+    unsigned short *array = NULL;
+    int host_cmd;
+    abi_long ret = 0;
+    abi_long err;
+    abi_ulong target_array, target_buffer;
+
+    switch (target_cmd) {
+    case TARGET_GETVAL:
+        host_cmd = GETVAL;
+        break;
+
+    case TARGET_SETVAL:
+        host_cmd = SETVAL;
+        break;
+
+    case TARGET_GETALL:
+        host_cmd = GETALL;
+        break;
+
+    case TARGET_SETALL:
+        host_cmd = SETALL;
+        break;
+
+    case TARGET_IPC_STAT:
+        host_cmd = IPC_STAT;
+        break;
+
+    case TARGET_IPC_SET:
+        host_cmd = IPC_SET;
+        break;
+
+    case TARGET_IPC_RMID:
+        host_cmd = IPC_RMID;
+        break;
+
+    case TARGET_GETPID:
+        host_cmd = GETPID;
+        break;
+
+    case TARGET_GETNCNT:
+        host_cmd = GETNCNT;
+        break;
+
+    case TARGET_GETZCNT:
+        host_cmd = GETZCNT;
+        break;
+
+    default:
+        return -TARGET_EINVAL;
+    }
+
+    /*
+     * Unlike Linux and the semctl system call, we take a pointer
+     * to the union arg here.
+     */
+    target_un = lock_user(VERIFY_READ, un_ptr, sizeof(union target_semun), 1);
+
+    switch (host_cmd) {
+    case GETVAL:
+    case SETVAL:
+        __get_user(arg.val, (abi_int *)target_un);
+        ret = get_errno(semctl(semid, semnum, host_cmd, arg));
+        break;
+
+    case GETALL:
+    case SETALL:
+        __get_user(target_array, (abi_ulong *)target_un);
+        err = target_to_host_semarray(semid, &array, target_array);
+        if (is_error(err)) {
+            goto out;
+        }
+        arg.array = array;
+        ret = get_errno(semctl(semid, semnum, host_cmd, arg));
+        err = host_to_target_semarray(semid, target_array, &array);
+        break;
+
+    case IPC_STAT:
+    case IPC_SET:
+        __get_user(target_buffer, (abi_ulong *)target_un);
+        err = target_to_host_semid_ds(&dsarg, target_buffer);
+        if (is_error(err)) {
+            goto out;
+        }
+        arg.buf = &dsarg;
+        ret = get_errno(semctl(semid, semnum, host_cmd, arg));
+        err = host_to_target_semid_ds(target_buffer, &dsarg);
+        break;
+
+    case IPC_RMID:
+    case GETPID:
+    case GETNCNT:
+    case GETZCNT:
+        ret = get_errno(semctl(semid, semnum, host_cmd, NULL));
+        break;
+
+    default:
+        ret = -TARGET_EINVAL;
+        break;
+    }
+out:
+    unlock_user(target_un, un_ptr, 1);
+    return ret;
+}
+
 /* getdtablesize(2) */
 static inline abi_long do_bsd_getdtablesize(void)
 {

-- 
2.52.0



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

* [PATCH v4 19/24] bsd-user: Add do_bsd_msgctl implementation
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
                   ` (17 preceding siblings ...)
  2026-02-24 14:40 ` [PATCH v4 18/24] bsd-user: Add do_bsd___semctl implementation Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-24 14:40 ` [PATCH v4 20/24] bsd-user: Add message queue implementations Warner Losh
                   ` (4 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Stacey Son, Richard Henderson

From: Stacey Son <sson@FreeBSD.org>

Add implementation of msgctl(2) syscall for System V message queue control
operations. Handles command translation and structure conversions for
IPC_STAT/IPC_SET/IPC_RMID operations.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsd-misc.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/bsd-user/bsd-misc.h b/bsd-user/bsd-misc.h
index 72b3db0b74..2e9de50ef9 100644
--- a/bsd-user/bsd-misc.h
+++ b/bsd-user/bsd-misc.h
@@ -210,6 +210,53 @@ out:
     return ret;
 }
 
+/* msgctl(2) */
+static inline abi_long do_bsd_msgctl(int msgid, int target_cmd, abi_long ptr)
+{
+    struct msqid_ds dsarg;
+    abi_long ret = -TARGET_EINVAL;
+    int host_cmd;
+
+    switch (target_cmd) {
+    case TARGET_IPC_STAT:
+        host_cmd = IPC_STAT;
+        break;
+
+    case TARGET_IPC_SET:
+        host_cmd = IPC_SET;
+        break;
+
+    case TARGET_IPC_RMID:
+        host_cmd = IPC_RMID;
+        break;
+
+    default:
+        return -TARGET_EINVAL;
+    }
+
+    switch (host_cmd) {
+    case IPC_STAT:
+    case IPC_SET:
+        if (target_to_host_msqid_ds(&dsarg, ptr)) {
+            return -TARGET_EFAULT;
+        }
+        ret = get_errno(msgctl(msgid, host_cmd, &dsarg));
+        if (host_to_target_msqid_ds(ptr, &dsarg)) {
+            return -TARGET_EFAULT;
+        }
+        break;
+
+    case IPC_RMID:
+        ret = get_errno(msgctl(msgid, host_cmd, NULL));
+        break;
+
+    default:
+        ret = -TARGET_EINVAL;
+        break;
+    }
+    return ret;
+}
+
 /* getdtablesize(2) */
 static inline abi_long do_bsd_getdtablesize(void)
 {

-- 
2.52.0



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

* [PATCH v4 20/24] bsd-user: Add message queue implementations
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
                   ` (18 preceding siblings ...)
  2026-02-24 14:40 ` [PATCH v4 19/24] bsd-user: Add do_bsd_msgctl implementation Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-24 14:40 ` [PATCH v4 21/24] bsd-user: Add bsd-misc.c to build Warner Losh
                   ` (3 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Stacey Son, Richard Henderson

From: Stacey Son <sson@FreeBSD.org>

Add implementations for:
- msgsnd(2): Send message to queue with size validation
- msgget(2): Get message queue identifier
- msgrcv(2): Receive message from queue with size validation

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsd-misc.h | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)

diff --git a/bsd-user/bsd-misc.h b/bsd-user/bsd-misc.h
index 2e9de50ef9..a25965598f 100644
--- a/bsd-user/bsd-misc.h
+++ b/bsd-user/bsd-misc.h
@@ -17,6 +17,8 @@
 
 #include "qemu-bsd.h"
 
+static int bsd_msgmax;
+
 /* quotactl(2) */
 static inline abi_long do_bsd_quotactl(abi_ulong path, abi_long cmd,
         __unused abi_ulong target_addr)
@@ -257,6 +259,101 @@ static inline abi_long do_bsd_msgctl(int msgid, int target_cmd, abi_long ptr)
     return ret;
 }
 
+struct kern_mymsg {
+    long mtype;
+    char mtext[1];
+};
+
+static inline abi_long bsd_validate_msgsz(abi_ulong msgsz)
+{
+    /* Fetch msgmax the first time we need it. */
+    if (bsd_msgmax == 0) {
+        size_t len = sizeof(bsd_msgmax);
+
+        if (sysctlbyname("kern.ipc.msgmax", &bsd_msgmax, &len, NULL, 0) == -1) {
+            return -TARGET_EINVAL;
+        }
+    }
+
+    if (msgsz > bsd_msgmax) {
+        return -TARGET_EINVAL;
+    }
+    return 0;
+}
+
+/* msgsnd(2) */
+static inline abi_long do_bsd_msgsnd(int msqid, abi_long msgp,
+        abi_ulong msgsz, int msgflg)
+{
+    struct target_msgbuf *target_mb;
+    struct kern_mymsg *host_mb;
+    abi_long ret;
+
+    ret = bsd_validate_msgsz(msgsz);
+    if (is_error(ret)) {
+        return ret;
+    }
+    if (!lock_user_struct(VERIFY_READ, target_mb, msgp, 0)) {
+        return -TARGET_EFAULT;
+    }
+    host_mb = g_malloc(msgsz + sizeof(long));
+    host_mb->mtype = (abi_long) tswapal(target_mb->mtype);
+    memcpy(host_mb->mtext, target_mb->mtext, msgsz);
+    ret = get_errno(msgsnd(msqid, host_mb, msgsz, msgflg));
+    g_free(host_mb);
+    unlock_user_struct(target_mb, msgp, 0);
+
+    return ret;
+}
+
+/* msgget(2) */
+static inline abi_long do_bsd_msgget(abi_long key, abi_long msgflag)
+{
+    abi_long ret;
+
+    ret = get_errno(msgget(key, msgflag));
+    return ret;
+}
+
+/* msgrcv(2) */
+static inline abi_long do_bsd_msgrcv(int msqid, abi_long msgp,
+        abi_ulong msgsz, abi_long msgtyp, int msgflg)
+{
+    struct target_msgbuf *target_mb = NULL;
+    char *target_mtext;
+    struct kern_mymsg *host_mb;
+    abi_long ret = 0;
+
+    ret = bsd_validate_msgsz(msgsz);
+    if (is_error(ret)) {
+        return ret;
+    }
+    if (!lock_user_struct(VERIFY_WRITE, target_mb, msgp, 0)) {
+        return -TARGET_EFAULT;
+    }
+    host_mb = g_malloc(msgsz + sizeof(long));
+    ret = get_errno(msgrcv(msqid, host_mb, msgsz, tswapal(msgtyp), msgflg));
+    if (ret > 0) {
+        abi_ulong target_mtext_addr = msgp + sizeof(abi_ulong);
+        target_mtext = lock_user(VERIFY_WRITE, target_mtext_addr, ret, 0);
+        if (target_mtext == NULL) {
+            ret = -TARGET_EFAULT;
+            goto end;
+        }
+        memcpy(target_mb->mtext, host_mb->mtext, ret);
+        unlock_user(target_mtext, target_mtext_addr, ret);
+    }
+    if (!is_error(ret)) {
+        target_mb->mtype = tswapal(host_mb->mtype);
+    }
+end:
+    if (target_mb != NULL) {
+        unlock_user_struct(target_mb, msgp, 1);
+    }
+    g_free(host_mb);
+    return ret;
+}
+
 /* getdtablesize(2) */
 static inline abi_long do_bsd_getdtablesize(void)
 {

-- 
2.52.0



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

* [PATCH v4 21/24] bsd-user: Add bsd-misc.c to build
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
                   ` (19 preceding siblings ...)
  2026-02-24 14:40 ` [PATCH v4 20/24] bsd-user: Add message queue implementations Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-24 14:40 ` [PATCH v4 22/24] bsd-user: Implement System V semaphore calls Warner Losh
                   ` (2 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Stacey Son, Richard Henderson

Build bsd-misc.c for routines to support System V IPC, UUID, quotactl,
reboot and getdtablesize.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/meson.build | 1 +
 1 file changed, 1 insertion(+)

diff --git a/bsd-user/meson.build b/bsd-user/meson.build
index 37b7cd6de8..00428fc2f8 100644
--- a/bsd-user/meson.build
+++ b/bsd-user/meson.build
@@ -8,6 +8,7 @@ common_user_inc += include_directories('include')
 
 bsd_user_ss.add(files(
   'bsd-mem.c',
+  'bsd-misc.c',
   'bsd-proc.c',
   'bsdload.c',
   'elfload.c',

-- 
2.52.0



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

* [PATCH v4 22/24] bsd-user: Implement System V semaphore calls
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
                   ` (20 preceding siblings ...)
  2026-02-24 14:40 ` [PATCH v4 21/24] bsd-user: Add bsd-misc.c to build Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-24 15:45   ` Gleb Popov
  2026-02-24 14:40 ` [PATCH v4 23/24] bsd-user: Add System V message queue syscalls Warner Losh
  2026-02-24 14:40 ` [PATCH v4 24/24] bsd-user: Add miscellaneous BSD syscall implementations Warner Losh
  23 siblings, 1 reply; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Stacey Son, Richard Henderson

From: Stacey Son <sson@FreeBSD.org>

Wire up semget(2) and semop(2) syscalls to get System V semaphore
implementation, as well the undocumented __semctl used to implement the
bits of the interface in libc.

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

diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 4c1191b8f4..234bd78fd2 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -36,6 +36,7 @@
 #include "bsd-file.h"
 #include "bsd-mem.h"
 #include "bsd-proc.h"
+#include "bsd-misc.h"
 
 /* BSD dependent syscall shims */
 #include "os-stat.h"
@@ -878,6 +879,21 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd_shmdt(arg1);
         break;
 
+        /*
+         * System V Semaphores
+         */
+    case TARGET_FREEBSD_NR_semget: /* semget(2) */
+        ret = do_bsd_semget(arg1, arg2, arg3);
+        break;
+
+    case TARGET_FREEBSD_NR_semop: /* semop(2) */
+        ret = do_bsd_semop(arg1, arg2, arg3);
+        break;
+
+    case TARGET_FREEBSD_NR___semctl: { /* __semctl() undocumented */
+        ret = do_bsd___semctl(arg1, arg2, arg3, arg4);
+        break;
+    }
     case TARGET_FREEBSD_NR_freebsd11_vadvise:
         ret = do_bsd_vadvise();
         break;

-- 
2.52.0



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

* [PATCH v4 23/24] bsd-user: Add System V message queue syscalls
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
                   ` (21 preceding siblings ...)
  2026-02-24 14:40 ` [PATCH v4 22/24] bsd-user: Implement System V semaphore calls Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  2026-02-24 14:40 ` [PATCH v4 24/24] bsd-user: Add miscellaneous BSD syscall implementations Warner Losh
  23 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Stacey Son, Richard Henderson

From: Stacey Son <sson@FreeBSD.org>

Connect the System V IPC message queue syscalls:
- msgctl(2): Message queue control
- msgget(2): Get message queue identifier
- msgsnd(2): Send message to queue
- msgrcv(2): Receive message from queue

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

diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 234bd78fd2..f39e521e42 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -894,6 +894,26 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_bsd___semctl(arg1, arg2, arg3, arg4);
         break;
     }
+
+        /*
+         * System V Messages
+         */
+    case TARGET_FREEBSD_NR_msgctl: /* msgctl(2) */
+        ret = do_bsd_msgctl(arg1, arg2, arg3);
+        break;
+
+    case TARGET_FREEBSD_NR_msgget: /* msgget(2) */
+        ret = do_bsd_msgget(arg1, arg2);
+        break;
+
+    case TARGET_FREEBSD_NR_msgsnd: /* msgsnd(2) */
+        ret = do_bsd_msgsnd(arg1, arg2, arg3, arg4);
+        break;
+
+    case TARGET_FREEBSD_NR_msgrcv: /* msgrcv(2) */
+        ret = do_bsd_msgrcv(arg1, arg2, arg3, arg4, arg5);
+        break;
+
     case TARGET_FREEBSD_NR_freebsd11_vadvise:
         ret = do_bsd_vadvise();
         break;

-- 
2.52.0



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

* [PATCH v4 24/24] bsd-user: Add miscellaneous BSD syscall implementations
  2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
                   ` (22 preceding siblings ...)
  2026-02-24 14:40 ` [PATCH v4 23/24] bsd-user: Add System V message queue syscalls Warner Losh
@ 2026-02-24 14:40 ` Warner Losh
  23 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-24 14:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Warner Losh, Stacey Son, Richard Henderson

From: Stacey Son <sson@FreeBSD.org>

Wire up the remaining miscellaneous BSD syscalls:
- quotactl(2): Quota control (stub returning ENOSYS)
- reboot(2): Reboot system (stub returning ENOSYS)
- uuidgen(2): Generate UUIDs
- getdtablesize(2): Get descriptor table size

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

diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index f39e521e42..85e5db19a3 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -933,6 +933,22 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_obreak(arg1);
         break;
 
+    case TARGET_FREEBSD_NR_quotactl: /* quotactl(2) */
+        ret = do_bsd_quotactl(arg1, arg2, arg3);
+        break;
+
+    case TARGET_FREEBSD_NR_reboot: /* reboot(2) */
+        ret = do_bsd_reboot(arg1);
+        break;
+
+    case TARGET_FREEBSD_NR_uuidgen: /* uuidgen(2) */
+        ret = do_bsd_uuidgen(arg1, arg2);
+        break;
+
+    case TARGET_FREEBSD_NR_getdtablesize: /* getdtablesize(2) */
+        ret = do_bsd_getdtablesize();
+        break;
+
         /*
          * sys{ctl, arch, call}
          */

-- 
2.52.0



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

* Re: [PATCH v4 01/24] freebsd: FreeBSD 15 has native inotify
  2026-02-24 14:40 ` [PATCH v4 01/24] freebsd: FreeBSD 15 has native inotify Warner Losh
@ 2026-02-24 15:28   ` Gleb Popov
  2026-03-11 11:59   ` Michael Tokarev
  1 sibling, 0 replies; 34+ messages in thread
From: Gleb Popov @ 2026-02-24 15:28 UTC (permalink / raw)
  To: Warner Losh; +Cc: qemu-devel

On Tue, Feb 24, 2026 at 5:41 PM Warner Losh <imp@bsdimp.com> wrote:
>
> Check to make sure that we have inotify in libc, before looking for it
> in libinotify.

This is how I solved the same problem in KDE lands (which uses CMake) [1].
In short, the algorithm is following:
1. Call into pkg-config to see if there is a .pc module for inotify
2. Check if /usr/include/sys/inotify.h exists
3. If there is no pkg-config module and no header -> no inotify
4. If there is no pkg-config module, but the header exists -> we have
"native" inotify,
    no CFLAGS/LDFLAGS manipulation needed
5. If there is pkg-config module, but no header -> use CFLAGS/LDFLAGS from
    pkg-config (IIRC, this is handled by the "dependency" function in
Meson). This
    case happens on FreeBSD where system and 3rd party headers are separated
    (/usr/include vs. /usr/local/include)
6. If we have both pkg-config module and /usr/include/sys/inotify.h,
then we need
    to figure if this header corresponds to libinotify-kqueue, or it
is a native one.
    This is done by comparing the installation prefix of the library and "/usr".

Hope that helps.

[1] https://invent.kde.org/frameworks/extra-cmake-modules/-/merge_requests/566


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

* Re: [PATCH v4 03/24] bsd-user: Add target_semid_ds and target_msqid_ds structures
  2026-02-24 14:40 ` [PATCH v4 03/24] bsd-user: Add target_semid_ds and target_msqid_ds structures Warner Losh
@ 2026-02-24 15:31   ` Gleb Popov
  2026-02-25  6:44     ` Warner Losh
  0 siblings, 1 reply; 34+ messages in thread
From: Gleb Popov @ 2026-02-24 15:31 UTC (permalink / raw)
  To: Warner Losh; +Cc: qemu-devel

On Tue, Feb 24, 2026 at 5:42 PM Warner Losh <imp@bsdimp.com> wrote:
>
> +
> +/*
> + * sys/msg.h
> + */
> +struct target_msqid_ds {
> +    struct  target_ipc_perm msg_perm; /* msg queue permission bits */
> +    abi_ptr     msg_first;  /* first message in the queue */
> +    abi_ptr     msg_last;   /* last message in the queue */
> +    abi_ulong   msg_cbytes; /* # of bytes in use on the queue */
> +    abi_ulong   msg_qnum;   /* number of msgs in the queue */
> +    abi_ulong   msg_qbytes; /* max # of bytes on the queue */
> +    int32_t     msg_lspid;  /* pid of last msgsnd() */
> +    int32_t     msg_lrpid;  /* pid of last msgrcv() */
> +    target_time_t   msg_stime;  /* time of last msgsnd() */
> +    target_time_t   msg_rtime;  /* time of last msgrcv() */
> +    target_time_t   msg_ctime;  /* time of last msgctl() */
> +};
> +
> +struct target_msgbuf {

You might want to put

/*
 * sys/msgbuf.h
 */

before the struct target_msgbuf definition, just like it is done for
struct target_msqid_ds


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

* Re: [PATCH v4 22/24] bsd-user: Implement System V semaphore calls
  2026-02-24 14:40 ` [PATCH v4 22/24] bsd-user: Implement System V semaphore calls Warner Losh
@ 2026-02-24 15:45   ` Gleb Popov
  2026-02-25  3:06     ` Warner Losh
  0 siblings, 1 reply; 34+ messages in thread
From: Gleb Popov @ 2026-02-24 15:45 UTC (permalink / raw)
  To: Warner Losh; +Cc: qemu-devel

On Tue, Feb 24, 2026 at 5:42 PM Warner Losh <imp@bsdimp.com> wrote:
>
> From: Stacey Son <sson@FreeBSD.org>
>
> Wire up semget(2) and semop(2) syscalls to get System V semaphore
> implementation, as well the undocumented __semctl used to implement the
> bits of the interface in libc.

semctl(2) seems to be documented since FreeBSD 2.2


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

* Re: [PATCH v4 22/24] bsd-user: Implement System V semaphore calls
  2026-02-24 15:45   ` Gleb Popov
@ 2026-02-25  3:06     ` Warner Losh
  0 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-25  3:06 UTC (permalink / raw)
  To: Gleb Popov; +Cc: QEMU Developers

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

On Tue, Feb 24, 2026, 8:45 AM Gleb Popov <arrowd@freebsd.org> wrote:

> On Tue, Feb 24, 2026 at 5:42 PM Warner Losh <imp@bsdimp.com> wrote:
> >
> > From: Stacey Son <sson@FreeBSD.org>
> >
> > Wire up semget(2) and semop(2) syscalls to get System V semaphore
> > implementation, as well the undocumented __semctl used to implement the
> > bits of the interface in libc.
>
> semctl(2) seems to be documented since FreeBSD 2.2
>

But __semctl is what actually implemented the system calls with a different
interface...

Warner

>

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

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

* Re: [PATCH v4 03/24] bsd-user: Add target_semid_ds and target_msqid_ds structures
  2026-02-24 15:31   ` Gleb Popov
@ 2026-02-25  6:44     ` Warner Losh
  0 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-25  6:44 UTC (permalink / raw)
  To: Gleb Popov; +Cc: qemu-devel

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

On Tue, Feb 24, 2026 at 8:32 AM Gleb Popov <arrowd@freebsd.org> wrote:

> On Tue, Feb 24, 2026 at 5:42 PM Warner Losh <imp@bsdimp.com> wrote:
> >
> > +
> > +/*
> > + * sys/msg.h
> > + */
> > +struct target_msqid_ds {
> > +    struct  target_ipc_perm msg_perm; /* msg queue permission bits */
> > +    abi_ptr     msg_first;  /* first message in the queue */
> > +    abi_ptr     msg_last;   /* last message in the queue */
> > +    abi_ulong   msg_cbytes; /* # of bytes in use on the queue */
> > +    abi_ulong   msg_qnum;   /* number of msgs in the queue */
> > +    abi_ulong   msg_qbytes; /* max # of bytes on the queue */
> > +    int32_t     msg_lspid;  /* pid of last msgsnd() */
> > +    int32_t     msg_lrpid;  /* pid of last msgrcv() */
> > +    target_time_t   msg_stime;  /* time of last msgsnd() */
> > +    target_time_t   msg_rtime;  /* time of last msgrcv() */
> > +    target_time_t   msg_ctime;  /* time of last msgctl() */
> > +};
> > +
> > +struct target_msgbuf {
>
> You might want to put
>
> /*
>  * sys/msgbuf.h
>  */
>
> before the struct target_msgbuf definition, just like it is done for
> struct target_msqid_ds
>

good catch. This was missing in bsd-user's blitz branch, but I'll add it
there too. Since it's trivial, I'm not going to resend unless I need a v5.

Warner

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

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

* Re: [PATCH v4 18/24] bsd-user: Add do_bsd___semctl implementation
  2026-02-24 14:40 ` [PATCH v4 18/24] bsd-user: Add do_bsd___semctl implementation Warner Losh
@ 2026-02-26 19:45   ` Warner Losh
  2026-02-26 19:56   ` Pierrick Bouvier
  1 sibling, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-26 19:45 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Stacey Son, Pierrick Bouvier

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

PING?

I'm planning on sending a pull request with this in it Monday March 2nd
unless anybody objects.

Thanks!

On Tue, Feb 24, 2026 at 7:41 AM Warner Losh <imp@bsdimp.com> wrote:

> From: Stacey Son <sson@FreeBSD.org>
>
> Add implementation of __semctl(2) syscall for System V semaphore control
> operations. Handles command translation, endianness conversion for GETVAL/
> SETVAL, and array/structure conversions for GETALL/SETALL/IPC_STAT/IPC_SET.
>
> Signed-off-by: Stacey Son <sson@FreeBSD.org>
> Cc: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> Signed-off-by: Warner Losh <imp@bsdimp.com>
> ---
>  bsd-user/bsd-misc.h | 111
> ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 111 insertions(+)
>
> diff --git a/bsd-user/bsd-misc.h b/bsd-user/bsd-misc.h
> index e1e552b58f..72b3db0b74 100644
> --- a/bsd-user/bsd-misc.h
> +++ b/bsd-user/bsd-misc.h
> @@ -99,6 +99,117 @@ static inline abi_long do_bsd_semop(int semid,
> abi_long ptr, unsigned nsops)
>      return semop(semid, sops, nsops);
>  }
>
> +/* __semctl(2) */
> +static inline abi_long do_bsd___semctl(int semid, int semnum, int
> target_cmd,
> +                                       abi_ptr un_ptr)
> +{
> +    void *target_un;
> +    union semun arg;
> +    struct semid_ds dsarg;
> +    unsigned short *array = NULL;
> +    int host_cmd;
> +    abi_long ret = 0;
> +    abi_long err;
> +    abi_ulong target_array, target_buffer;
> +
> +    switch (target_cmd) {
> +    case TARGET_GETVAL:
> +        host_cmd = GETVAL;
> +        break;
> +
> +    case TARGET_SETVAL:
> +        host_cmd = SETVAL;
> +        break;
> +
> +    case TARGET_GETALL:
> +        host_cmd = GETALL;
> +        break;
> +
> +    case TARGET_SETALL:
> +        host_cmd = SETALL;
> +        break;
> +
> +    case TARGET_IPC_STAT:
> +        host_cmd = IPC_STAT;
> +        break;
> +
> +    case TARGET_IPC_SET:
> +        host_cmd = IPC_SET;
> +        break;
> +
> +    case TARGET_IPC_RMID:
> +        host_cmd = IPC_RMID;
> +        break;
> +
> +    case TARGET_GETPID:
> +        host_cmd = GETPID;
> +        break;
> +
> +    case TARGET_GETNCNT:
> +        host_cmd = GETNCNT;
> +        break;
> +
> +    case TARGET_GETZCNT:
> +        host_cmd = GETZCNT;
> +        break;
> +
> +    default:
> +        return -TARGET_EINVAL;
> +    }
> +
> +    /*
> +     * Unlike Linux and the semctl system call, we take a pointer
> +     * to the union arg here.
> +     */
> +    target_un = lock_user(VERIFY_READ, un_ptr, sizeof(union
> target_semun), 1);
> +
> +    switch (host_cmd) {
> +    case GETVAL:
> +    case SETVAL:
> +        __get_user(arg.val, (abi_int *)target_un);
> +        ret = get_errno(semctl(semid, semnum, host_cmd, arg));
> +        break;
> +
> +    case GETALL:
> +    case SETALL:
> +        __get_user(target_array, (abi_ulong *)target_un);
> +        err = target_to_host_semarray(semid, &array, target_array);
> +        if (is_error(err)) {
> +            goto out;
> +        }
> +        arg.array = array;
> +        ret = get_errno(semctl(semid, semnum, host_cmd, arg));
> +        err = host_to_target_semarray(semid, target_array, &array);
> +        break;
> +
> +    case IPC_STAT:
> +    case IPC_SET:
> +        __get_user(target_buffer, (abi_ulong *)target_un);
> +        err = target_to_host_semid_ds(&dsarg, target_buffer);
> +        if (is_error(err)) {
> +            goto out;
> +        }
> +        arg.buf = &dsarg;
> +        ret = get_errno(semctl(semid, semnum, host_cmd, arg));
> +        err = host_to_target_semid_ds(target_buffer, &dsarg);
> +        break;
> +
> +    case IPC_RMID:
> +    case GETPID:
> +    case GETNCNT:
> +    case GETZCNT:
> +        ret = get_errno(semctl(semid, semnum, host_cmd, NULL));
> +        break;
> +
> +    default:
> +        ret = -TARGET_EINVAL;
> +        break;
> +    }
> +out:
> +    unlock_user(target_un, un_ptr, 1);
> +    return ret;
> +}
> +
>  /* getdtablesize(2) */
>  static inline abi_long do_bsd_getdtablesize(void)
>  {
>
> --
> 2.52.0
>
>

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

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

* Re: [PATCH v4 18/24] bsd-user: Add do_bsd___semctl implementation
  2026-02-24 14:40 ` [PATCH v4 18/24] bsd-user: Add do_bsd___semctl implementation Warner Losh
  2026-02-26 19:45   ` Warner Losh
@ 2026-02-26 19:56   ` Pierrick Bouvier
  2026-02-26 22:14     ` Warner Losh
  1 sibling, 1 reply; 34+ messages in thread
From: Pierrick Bouvier @ 2026-02-26 19:56 UTC (permalink / raw)
  To: Warner Losh, qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio,
	Stacey Son

On 2/24/26 6:40 AM, Warner Losh wrote:
> From: Stacey Son <sson@FreeBSD.org>
> 
> Add implementation of __semctl(2) syscall for System V semaphore control
> operations. Handles command translation, endianness conversion for GETVAL/
> SETVAL, and array/structure conversions for GETALL/SETALL/IPC_STAT/IPC_SET.
> 
> Signed-off-by: Stacey Son <sson@FreeBSD.org>
> Cc: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> Signed-off-by: Warner Losh <imp@bsdimp.com>
> ---
>   bsd-user/bsd-misc.h | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 111 insertions(+)
> 
> diff --git a/bsd-user/bsd-misc.h b/bsd-user/bsd-misc.h
> index e1e552b58f..72b3db0b74 100644
> --- a/bsd-user/bsd-misc.h
> +++ b/bsd-user/bsd-misc.h
> @@ -99,6 +99,117 @@ static inline abi_long do_bsd_semop(int semid, abi_long ptr, unsigned nsops)
>       return semop(semid, sops, nsops);
>   }
>   
> +/* __semctl(2) */
> +static inline abi_long do_bsd___semctl(int semid, int semnum, int target_cmd,
> +                                       abi_ptr un_ptr)
> +{
> +    void *target_un;
> +    union semun arg;
> +    struct semid_ds dsarg;
> +    unsigned short *array = NULL;
> +    int host_cmd;
> +    abi_long ret = 0;
> +    abi_long err;
> +    abi_ulong target_array, target_buffer;
> +
> +    switch (target_cmd) {
> +    case TARGET_GETVAL:
> +        host_cmd = GETVAL;
> +        break;
> +
> +    case TARGET_SETVAL:
> +        host_cmd = SETVAL;
> +        break;
> +
> +    case TARGET_GETALL:
> +        host_cmd = GETALL;
> +        break;
> +
> +    case TARGET_SETALL:
> +        host_cmd = SETALL;
> +        break;
> +
> +    case TARGET_IPC_STAT:
> +        host_cmd = IPC_STAT;
> +        break;
> +
> +    case TARGET_IPC_SET:
> +        host_cmd = IPC_SET;
> +        break;
> +
> +    case TARGET_IPC_RMID:
> +        host_cmd = IPC_RMID;
> +        break;
> +
> +    case TARGET_GETPID:
> +        host_cmd = GETPID;
> +        break;
> +
> +    case TARGET_GETNCNT:
> +        host_cmd = GETNCNT;
> +        break;
> +
> +    case TARGET_GETZCNT:
> +        host_cmd = GETZCNT;
> +        break;
> +
> +    default:
> +        return -TARGET_EINVAL;
> +    }
> +
> +    /*
> +     * Unlike Linux and the semctl system call, we take a pointer
> +     * to the union arg here.
> +     */
> +    target_un = lock_user(VERIFY_READ, un_ptr, sizeof(union target_semun), 1);
> +
> +    switch (host_cmd) {
> +    case GETVAL:
> +    case SETVAL:
> +        __get_user(arg.val, (abi_int *)target_un);
> +        ret = get_errno(semctl(semid, semnum, host_cmd, arg));
> +        break;
> +
> +    case GETALL:
> +    case SETALL:
> +        __get_user(target_array, (abi_ulong *)target_un);
> +        err = target_to_host_semarray(semid, &array, target_array);
> +        if (is_error(err)) {
> +            goto out;
> +        }

Seems like ret should be set to an error also, else we'll silently 
return default value 0. I'm not sure which error code we should return 
(EINVAL?)

> +        arg.array = array;
> +        ret = get_errno(semctl(semid, semnum, host_cmd, arg));
> +        err = host_to_target_semarray(semid, target_array, &array);
> +        break;
> +
> +    case IPC_STAT:
> +    case IPC_SET:
> +        __get_user(target_buffer, (abi_ulong *)target_un);
> +        err = target_to_host_semid_ds(&dsarg, target_buffer);
> +        if (is_error(err)) {
> +            goto out;
> +        }
> +        arg.buf = &dsarg;
> +        ret = get_errno(semctl(semid, semnum, host_cmd, arg));
> +        err = host_to_target_semid_ds(target_buffer, &dsarg);
> +        break;
> +
> +    case IPC_RMID:
> +    case GETPID:
> +    case GETNCNT:
> +    case GETZCNT:
> +        ret = get_errno(semctl(semid, semnum, host_cmd, NULL));
> +        break;
> +
> +    default:
> +        ret = -TARGET_EINVAL;
> +        break;
> +    }
> +out:
> +    unlock_user(target_un, un_ptr, 1);
> +    return ret;
> +}
> +
>   /* getdtablesize(2) */
>   static inline abi_long do_bsd_getdtablesize(void)
>   {
> 

With that,
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>

Feel free to add the fix and pull directly without reposting so you can 
save some time before softfreeze.

Regards,
Pierrick


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

* Re: [PATCH v4 18/24] bsd-user: Add do_bsd___semctl implementation
  2026-02-26 19:56   ` Pierrick Bouvier
@ 2026-02-26 22:14     ` Warner Losh
  0 siblings, 0 replies; 34+ messages in thread
From: Warner Losh @ 2026-02-26 22:14 UTC (permalink / raw)
  To: Pierrick Bouvier
  Cc: qemu-devel, Daniel P. Berrangé, Kyle Evans,
	Marc-André Lureau, Paolo Bonzini,
	Philippe Mathieu-Daudé, Riku Voipio, Stacey Son

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

On Thu, Feb 26, 2026 at 12:56 PM Pierrick Bouvier <
pierrick.bouvier@linaro.org> wrote:

> On 2/24/26 6:40 AM, Warner Losh wrote:
> > From: Stacey Son <sson@FreeBSD.org>
> >
> > Add implementation of __semctl(2) syscall for System V semaphore control
> > operations. Handles command translation, endianness conversion for
> GETVAL/
> > SETVAL, and array/structure conversions for
> GETALL/SETALL/IPC_STAT/IPC_SET.
> >
> > Signed-off-by: Stacey Son <sson@FreeBSD.org>
> > Cc: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> > Signed-off-by: Warner Losh <imp@bsdimp.com>
> > ---
> >   bsd-user/bsd-misc.h | 111
> ++++++++++++++++++++++++++++++++++++++++++++++++++++
> >   1 file changed, 111 insertions(+)
> >
> > diff --git a/bsd-user/bsd-misc.h b/bsd-user/bsd-misc.h
> > index e1e552b58f..72b3db0b74 100644
> > --- a/bsd-user/bsd-misc.h
> > +++ b/bsd-user/bsd-misc.h
> > @@ -99,6 +99,117 @@ static inline abi_long do_bsd_semop(int semid,
> abi_long ptr, unsigned nsops)
> >       return semop(semid, sops, nsops);
> >   }
> >
> > +/* __semctl(2) */
> > +static inline abi_long do_bsd___semctl(int semid, int semnum, int
> target_cmd,
> > +                                       abi_ptr un_ptr)
> > +{
> > +    void *target_un;
> > +    union semun arg;
> > +    struct semid_ds dsarg;
> > +    unsigned short *array = NULL;
> > +    int host_cmd;
> > +    abi_long ret = 0;
> > +    abi_long err;
> > +    abi_ulong target_array, target_buffer;
> > +
> > +    switch (target_cmd) {
> > +    case TARGET_GETVAL:
> > +        host_cmd = GETVAL;
> > +        break;
> > +
> > +    case TARGET_SETVAL:
> > +        host_cmd = SETVAL;
> > +        break;
> > +
> > +    case TARGET_GETALL:
> > +        host_cmd = GETALL;
> > +        break;
> > +
> > +    case TARGET_SETALL:
> > +        host_cmd = SETALL;
> > +        break;
> > +
> > +    case TARGET_IPC_STAT:
> > +        host_cmd = IPC_STAT;
> > +        break;
> > +
> > +    case TARGET_IPC_SET:
> > +        host_cmd = IPC_SET;
> > +        break;
> > +
> > +    case TARGET_IPC_RMID:
> > +        host_cmd = IPC_RMID;
> > +        break;
> > +
> > +    case TARGET_GETPID:
> > +        host_cmd = GETPID;
> > +        break;
> > +
> > +    case TARGET_GETNCNT:
> > +        host_cmd = GETNCNT;
> > +        break;
> > +
> > +    case TARGET_GETZCNT:
> > +        host_cmd = GETZCNT;
> > +        break;
> > +
> > +    default:
> > +        return -TARGET_EINVAL;
> > +    }
> > +
> > +    /*
> > +     * Unlike Linux and the semctl system call, we take a pointer
> > +     * to the union arg here.
> > +     */
> > +    target_un = lock_user(VERIFY_READ, un_ptr, sizeof(union
> target_semun), 1);
> > +
> > +    switch (host_cmd) {
> > +    case GETVAL:
> > +    case SETVAL:
> > +        __get_user(arg.val, (abi_int *)target_un);
> > +        ret = get_errno(semctl(semid, semnum, host_cmd, arg));
> > +        break;
> > +
> > +    case GETALL:
> > +    case SETALL:
> > +        __get_user(target_array, (abi_ulong *)target_un);
> > +        err = target_to_host_semarray(semid, &array, target_array);
> > +        if (is_error(err)) {
> > +            goto out;
> > +        }
>
> Seems like ret should be set to an error also, else we'll silently
> return default value 0. I'm not sure which error code we should return
> (EINVAL?)
>

Ah yes. I'll look at it and fix it.


> > +        arg.array = array;
> > +        ret = get_errno(semctl(semid, semnum, host_cmd, arg));
> > +        err = host_to_target_semarray(semid, target_array, &array);
>

And this is starting to look wrong too. I'll fix that.


> > +        break;
> > +
> > +    case IPC_STAT:
> > +    case IPC_SET:
> > +        __get_user(target_buffer, (abi_ulong *)target_un);
> > +        err = target_to_host_semid_ds(&dsarg, target_buffer);
> > +        if (is_error(err)) {
> > +            goto out;
> > +        }
> > +        arg.buf = &dsarg;
> > +        ret = get_errno(semctl(semid, semnum, host_cmd, arg));
> > +        err = host_to_target_semid_ds(target_buffer, &dsarg);
> > +        break;
> > +
> > +    case IPC_RMID:
> > +    case GETPID:
> > +    case GETNCNT:
> > +    case GETZCNT:
> > +        ret = get_errno(semctl(semid, semnum, host_cmd, NULL));
> > +        break;
> > +
> > +    default:
> > +        ret = -TARGET_EINVAL;
> > +        break;
> > +    }
> > +out:
> > +    unlock_user(target_un, un_ptr, 1);
> > +    return ret;
> > +}
> > +
> >   /* getdtablesize(2) */
> >   static inline abi_long do_bsd_getdtablesize(void)
> >   {
> >
>
> With that,
> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>
> Feel free to add the fix and pull directly without reposting so you can
> save some time before softfreeze.
>

Thanks! Most of these errors are rare, but still gotta get them right.

Warner

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

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

* Re: [PATCH v4 01/24] freebsd: FreeBSD 15 has native inotify
  2026-02-24 14:40 ` [PATCH v4 01/24] freebsd: FreeBSD 15 has native inotify Warner Losh
  2026-02-24 15:28   ` Gleb Popov
@ 2026-03-11 11:59   ` Michael Tokarev
  1 sibling, 0 replies; 34+ messages in thread
From: Michael Tokarev @ 2026-03-11 11:59 UTC (permalink / raw)
  To: Warner Losh, qemu-devel
  Cc: Daniel P. Berrangé, Kyle Evans, Marc-André Lureau,
	Paolo Bonzini, Philippe Mathieu-Daudé, Riku Voipio

On 24.02.2026 17:40, Warner Losh wrote:
> Check to make sure that we have inotify in libc, before looking for it
> in libinotify.
> 
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
> Cc: Daniel P. Berrange <berrange@redhat.com>
> Cc: Philippe Mathieu-Daudé <philmd@linaro.org>
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
> Signed-off-by: Warner Losh <imp@bsdimp.com>
> ---
>   meson.build      | 14 +++++---------
>   util/meson.build |  6 +-----
>   2 files changed, 6 insertions(+), 14 deletions(-)
> 
> diff --git a/meson.build b/meson.build
> index 4af32c3e1f..3d761f89b5 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -2664,18 +2664,14 @@ else
>   endif
>   config_host_data.set('CONFIG_ASAN_IFACE_FIBER', have_asan_fiber)
>   
> +inotify = not_found
>   have_inotify_init = cc.has_header_symbol('sys/inotify.h', 'inotify_init')
>   have_inotify_init1 = cc.has_header_symbol('sys/inotify.h', 'inotify_init1')
> -inotify = not_found
> -if (have_inotify_init or have_inotify_init1) and host_os == 'freebsd'
> -  # libinotify-kqueue
> +if (have_inotify_init or have_inotify_init1) and not cc.has_function('inotify_init1')
> +  # FreeBSD 14 and older need libinotify-kqueue wrapper
>     inotify = cc.find_library('inotify')
> -  if have_inotify_init
> -    have_inotify_init = inotify.found()
> -  endif
> -  if have_inotify_init1
> -    have_inotify_init1 = inotify.found()
> -  endif
> +  have_inotify_init = have_inotify_init and inotify.found()
> +  have_inotify_init1 = have_inotify_init1 and inotify.found()
>   endif
>   config_host_data.set('CONFIG_INOTIFY', have_inotify_init)
>   config_host_data.set('CONFIG_INOTIFY1', have_inotify_init1)

Does freebsd have inotify_init() or inotify_init1() or both?

I sent another patch for this area, which drops checking for
the original/early inotify_init(), because this function is
actually not used in qemu, - qemu only uses the more modern
inotify_init1() interface.

Now my change clashes with this change in a fun way.

Do we really need to check for inotify_init() at all?

Thanks,

/mjt


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

end of thread, other threads:[~2026-03-11 11:59 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-24 14:40 [PATCH v4 00/24] bsd-user: Upstream misc system calls (System V IPC, reboot, etc) Warner Losh
2026-02-24 14:40 ` [PATCH v4 01/24] freebsd: FreeBSD 15 has native inotify Warner Losh
2026-02-24 15:28   ` Gleb Popov
2026-03-11 11:59   ` Michael Tokarev
2026-02-24 14:40 ` [PATCH v4 02/24] common-user: Drop __linux__ around .note.GNU-stack Warner Losh
2026-02-24 14:40 ` [PATCH v4 03/24] bsd-user: Add target_semid_ds and target_msqid_ds structures Warner Losh
2026-02-24 15:31   ` Gleb Popov
2026-02-25  6:44     ` Warner Losh
2026-02-24 14:40 ` [PATCH v4 04/24] bsd-user: Add target_uuid structure for uuidgen syscall Warner Losh
2026-02-24 14:40 ` [PATCH v4 05/24] bsd-user: Add function declarations for bsd-misc.c conversions Warner Losh
2026-02-24 14:40 ` [PATCH v4 06/24] bsd-user: Add host_to_target_uuid for uuidgen(2) Warner Losh
2026-02-24 14:40 ` [PATCH v4 07/24] bsd-user: Add target_to_host_semarray for semaphore operations Warner Losh
2026-02-24 14:40 ` [PATCH v4 08/24] bsd-user: Add host_to_target_semarray " Warner Losh
2026-02-24 14:40 ` [PATCH v4 09/24] bsd-user: Add target_to_host_semid_ds for semctl(2) Warner Losh
2026-02-24 14:40 ` [PATCH v4 10/24] bsd-user: Add host_to_target_semid_ds " Warner Losh
2026-02-24 14:40 ` [PATCH v4 11/24] bsd-user: Add target_to_host_msqid_ds for msgctl(2) Warner Losh
2026-02-24 14:40 ` [PATCH v4 12/24] bsd-user: Add host_to_target_msqid_ds " Warner Losh
2026-02-24 14:40 ` [PATCH v4 13/24] bsd-user: Add semaphore operation constants and structures Warner Losh
2026-02-24 14:40 ` [PATCH v4 14/24] bsd-user: Add do_bsd_quotactl, do_bsd_reboot and do_bsd_getdtablesize Warner Losh
2026-02-24 14:40 ` [PATCH v4 15/24] bsd-user: Add do_bsd_uuidgen implementation Warner Losh
2026-02-24 14:40 ` [PATCH v4 16/24] bsd-user: Add do_bsd_semget implementation Warner Losh
2026-02-24 14:40 ` [PATCH v4 17/24] bsd-user: Add do_bsd_semop implementation Warner Losh
2026-02-24 14:40 ` [PATCH v4 18/24] bsd-user: Add do_bsd___semctl implementation Warner Losh
2026-02-26 19:45   ` Warner Losh
2026-02-26 19:56   ` Pierrick Bouvier
2026-02-26 22:14     ` Warner Losh
2026-02-24 14:40 ` [PATCH v4 19/24] bsd-user: Add do_bsd_msgctl implementation Warner Losh
2026-02-24 14:40 ` [PATCH v4 20/24] bsd-user: Add message queue implementations Warner Losh
2026-02-24 14:40 ` [PATCH v4 21/24] bsd-user: Add bsd-misc.c to build Warner Losh
2026-02-24 14:40 ` [PATCH v4 22/24] bsd-user: Implement System V semaphore calls Warner Losh
2026-02-24 15:45   ` Gleb Popov
2026-02-25  3:06     ` Warner Losh
2026-02-24 14:40 ` [PATCH v4 23/24] bsd-user: Add System V message queue syscalls Warner Losh
2026-02-24 14:40 ` [PATCH v4 24/24] bsd-user: Add miscellaneous BSD syscall implementations Warner Losh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox