On Sun, Feb 8, 2026 at 6:12 PM Richard Henderson <
[email protected]> wrote:

> On 2/9/26 05:26, Warner Losh wrote:
> > From: Stacey Son <[email protected]>
> >
> > Add host_to_target_semarray() to convert host semaphore array to target
> > format for semctl(2) GETALL operations.
> >
> > Signed-off-by: Stacey Son <[email protected]>
> > Signed-off-by: Warner Losh <[email protected]>
> > ---
> >   bsd-user/bsd-misc.c | 33 +++++++++++++++++++++++++++++++++
> >   1 file changed, 33 insertions(+)
> >
> > diff --git a/bsd-user/bsd-misc.c b/bsd-user/bsd-misc.c
> > index d9eb87db80..677cb49d27 100644
> > --- a/bsd-user/bsd-misc.c
> > +++ b/bsd-user/bsd-misc.c
> > @@ -79,3 +79,36 @@ 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;
>
> Good, but...
>
> > +    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) {
> > +        free(host_array);
> > +        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) {
> > +        free(host_array);
>
> forgot to remove the explict free.
>
> > +        return -TARGET_EFAULT;
> > +    }
> > +    for (i = 0; i < nsems; i++) {
> > +        __put_user(array[i], host_array + i);
> > +    }
> > +    free(host_array);
>
> again.
>

Doh! Thanks!


> Otherwise,
> Reviewed-by: Richard Henderson <[email protected]>
>
>
> r~
> > +    unlock_user(array, target_addr, 1);
> > +    return 0;
> > +}
> >
>
>
>

Reply via email to