On Thu, Feb 5, 2026 at 7:25 PM Richard Henderson <
[email protected]> wrote:

> On 2/6/26 03:26, Warner Losh wrote:
> > From: Stacey Son <[email protected]>
> >
> > 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 <[email protected]>
> > Signed-off-by: Mikael Urankar <[email protected]>
> > Signed-off-by: Warner Losh <[email protected]>
> > ---
> >   bsd-user/bsd-misc.c | 23 +++++++++++++++++++++++
> >   1 file changed, 23 insertions(+)
> >
> > diff --git a/bsd-user/bsd-misc.c b/bsd-user/bsd-misc.c
> > index 7bdf65450a..581eb50355 100644
> > --- a/bsd-user/bsd-misc.c
> > +++ b/bsd-user/bsd-misc.c
> > @@ -111,3 +111,26 @@ 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);
>
> Drop the useless parens following &.
>
> > +    /* sem_base is not used by kernel for IPC_STAT/IPC_SET */
> > +    /* host_sd->sem_base  = g2h_untagged(target_sd->sem_base); */
> > +    host_sd->sem_nsems = tswap16(target_sd->sem_nsems);
> > +#if defined(TARGET_I386)
> > +    host_sd->sem_otime = tswap32(target_sd->sem_otime);
> > +    host_sd->sem_ctime = tswap32(target_sd->sem_ctime);
> > +#else
> > +    host_sd->sem_otime = tswap64(target_sd->sem_otime);
> > +    host_sd->sem_ctime = tswap64(target_sd->sem_ctime);
> > +#endif
> > +    unlock_user_struct(target_sd, target_addr, 0);
> > +    return 0;
> > +}
> >
>
> Use __get_user and you won't need the ifdef, since the size of the type is
> then
> automatically handled.
>

Agreed. Will update.

Warner

Reply via email to