[PATCH 19/24] bsd-user: Add do_bsd_msgctl implementation

Warner Losh posted 24 patches 3 days, 19 hours ago
Maintainers: Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, Riku Voipio <riku.voipio@iki.fi>, Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>
There is a newer version of this series
[PATCH 19/24] bsd-user: Add do_bsd_msgctl implementation
Posted by Warner Losh 3 days, 19 hours ago
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>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsd-misc.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/bsd-user/bsd-misc.h b/bsd-user/bsd-misc.h
index 81fdfd8351..27f4497d76 100644
--- a/bsd-user/bsd-misc.h
+++ b/bsd-user/bsd-misc.h
@@ -28,6 +28,12 @@
 
 #include "qemu-bsd.h"
 
+#ifdef MSGMAX
+static int bsd_msgmax = MSGMAX;
+#else
+static int bsd_msgmax;
+#endif
+
 /* quotactl(2) */
 static inline abi_long do_bsd_quotactl(abi_ulong path, abi_long cmd,
         __unused abi_ulong target_addr)
@@ -228,6 +234,53 @@ static inline abi_long do_bsd___semctl(int semid, int semnum, int target_cmd,
     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
Re: [PATCH 19/24] bsd-user: Add do_bsd_msgctl implementation
Posted by Richard Henderson 3 days, 9 hours ago
On 2/6/26 03:26, Warner Losh wrote:
> 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>
> Signed-off-by: Warner Losh <imp@bsdimp.com>
> ---
>   bsd-user/bsd-misc.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 53 insertions(+)
> 
> diff --git a/bsd-user/bsd-misc.h b/bsd-user/bsd-misc.h
> index 81fdfd8351..27f4497d76 100644
> --- a/bsd-user/bsd-misc.h
> +++ b/bsd-user/bsd-misc.h
> @@ -28,6 +28,12 @@
>   
>   #include "qemu-bsd.h"
>   
> +#ifdef MSGMAX
> +static int bsd_msgmax = MSGMAX;
> +#else
> +static int bsd_msgmax;
> +#endif

(1) This isn't used in this patch, and probably generates a Werror.
(2) Does any supported FreeBSD version actually define MSGMAX anymore?
     Grepping current source suggests one always has to probe at runtime.

Anyway, if you move this item to the next patch,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

for the rest of this one.

r~
Re: [PATCH 19/24] bsd-user: Add do_bsd_msgctl implementation
Posted by Warner Losh 2 days, 18 hours ago
On Thu, Feb 5, 2026 at 8:22 PM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 2/6/26 03:26, Warner Losh wrote:
> > 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>
> > Signed-off-by: Warner Losh <imp@bsdimp.com>
> > ---
> >   bsd-user/bsd-misc.h | 53
> +++++++++++++++++++++++++++++++++++++++++++++++++++++
> >   1 file changed, 53 insertions(+)
> >
> > diff --git a/bsd-user/bsd-misc.h b/bsd-user/bsd-misc.h
> > index 81fdfd8351..27f4497d76 100644
> > --- a/bsd-user/bsd-misc.h
> > +++ b/bsd-user/bsd-misc.h
> > @@ -28,6 +28,12 @@
> >
> >   #include "qemu-bsd.h"
> >
> > +#ifdef MSGMAX
> > +static int bsd_msgmax = MSGMAX;
> > +#else
> > +static int bsd_msgmax;
> > +#endif
>
> (1) This isn't used in this patch, and probably generates a Werror.
>

Yes, but no actually: bsd-misc.c isn't in the build yet... However, it
should be folded with later revs. I missed that in the prep.


> (2) Does any supported FreeBSD version actually define MSGMAX anymore?
>      Grepping current source suggests one always has to probe at runtime.
>

Yes. That's true. I'll remove the #ifdef. there is a define in the kernel,
but it's confined to sysv_msg.c file.


> Anyway, if you move this item to the next patch,
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>
> for the rest of this one.
>
> r~
>