On 2/6/26 03:26, Warner Losh wrote:
From: Stacey Son <[email protected]>
Add target_to_host_semarray() to convert target semaphore array to host
format for semctl(2) SETALL operations.
Signed-off-by: Stacey Son <[email protected]>
Signed-off-by: Warner Losh <[email protected]>
---
bsd-user/bsd-misc.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/bsd-user/bsd-misc.c b/bsd-user/bsd-misc.c
index d2107b2f85..07d8bf1304 100644
--- a/bsd-user/bsd-misc.c
+++ b/bsd-user/bsd-misc.c
@@ -18,6 +18,11 @@
*/
#include "qemu/osdep.h"
+#define _WANT_SEMUN
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <sys/sem.h>
#include <sys/uuid.h>
#include "qemu.h"
@@ -44,3 +49,33 @@ abi_long host_to_target_uuid(abi_ulong target_addr, struct
uuid *host_uuid)
unlock_user_struct(target_uuid, target_addr, 1);
return 0;
}
+
+abi_long target_to_host_semarray(int semid, unsigned short **host_array,
+ abi_ulong target_addr)
+{
+ 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;
+ *host_array = (unsigned short *)malloc(nsems * sizeof(unsigned short));
g_malloc, or test for allocation failure and return -TARGET_ENOMEM.
+ array = lock_user(VERIFY_READ, target_addr,
+ nsems * sizeof(unsigned short), 1);
+ if (array == NULL) {
+ free(*host_array);
+ return -TARGET_EFAULT;
+ }
+ for (i = 0; i < nsems; i++) {
+ (*host_array)[i] = array[i];
__get_user, for endianness issues.
r~