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 | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/bsd-user/bsd-misc.c b/bsd-user/bsd-misc.c index 07d8bf1304..7bdf65450a 100644 --- a/bsd-user/bsd-misc.c +++ b/bsd-user/bsd-misc.c @@ -79,3 +79,35 @@ 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_array) +{ + 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); + return -TARGET_EFAULT; + } + for (i = 0; i < nsems; i++) { + array[i] = (*host_array)[i]; + } + free(*host_array); + unlock_user(array, target_addr, 1); + return 0; +} -- 2.52.0
