bsd-user: Add host_to_target_semarray for semaphore operations

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>
This commit is contained in:
Stacey Son
2026-02-02 14:50:27 -07:00
committed by Warner Losh
parent ff1189f659
commit 685c763348

View File

@@ -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;
}