[PATCH 13/24] bsd-user: Add semaphore operation constants and structures

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 13/24] bsd-user: Add semaphore operation constants and structures
Posted by Warner Losh 3 days, 19 hours ago
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>
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 62b9bc752b..becd04efb4 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 {
+    unsigned short  sem_num;    /* semaphore # */
+    short       sem_op;         /* semaphore operation */
+    short       sem_flg;        /* operation flags */
+};
+
+union target_semun {
+    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_ulong   sem_base;   /* pointer to first semaphore in set */

-- 
2.52.0
Re: [PATCH 13/24] bsd-user: Add semaphore operation constants and structures
Posted by Richard Henderson 3 days, 10 hours ago
On 2/6/26 03:26, Warner Losh wrote:
> 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>
> 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 62b9bc752b..becd04efb4 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 {
> +    unsigned short  sem_num;    /* semaphore # */
> +    short       sem_op;         /* semaphore operation */
> +    short       sem_flg;        /* operation flags */
> +};

abi_short, abi_ushort.

> +
> +union target_semun {
> +    int     val;        /* value for SETVAL */

abi_int.

> +    abi_ulong   buf;        /* buffer for IPC_STAT & IPC_SET */
> +    abi_ulong   array;      /* array for GETALL & SETALL */

abi_ptr.


r~
Re: [PATCH 13/24] bsd-user: Add semaphore operation constants and structures
Posted by Warner Losh 2 days, 19 hours ago
On Thu, Feb 5, 2026 at 7:48 PM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 2/6/26 03:26, Warner Losh wrote:
> > 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>
> > 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 62b9bc752b..becd04efb4 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 {
> > +    unsigned short  sem_num;    /* semaphore # */
> > +    short       sem_op;         /* semaphore operation */
> > +    short       sem_flg;        /* operation flags */
> > +};
>
> abi_short, abi_ushort.
>
> > +
> > +union target_semun {
> > +    int     val;        /* value for SETVAL */
>
> abi_int.
>
> > +    abi_ulong   buf;        /* buffer for IPC_STAT & IPC_SET */
> > +    abi_ulong   array;      /* array for GETALL & SETALL */
>
> abi_ptr.
>

Agreed.