@samitouri / QOSamiQemu / commits / 441ddfb820

bsd-user: Add do_bsd_semop implementation

Add implementation of semop(2) syscall to perform System V semaphore operations. Converts target sembuf array to host format and executes 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>

Stacey Son committed Feb 2, 2026 at 16:44 UTC 441ddfb820ae30d4a47bb378d7cd830c093a2747
1 file changed +22
bsd-user/bsd-misc.h
+22
@@ -77,6 +77,28 @@ static inline abi_long do_bsd_semget(abi_long key, int nsems,
77 target_to_host_bitmask(target_flags, ipc_flags_tbl)));
78 }
79
80 +/* semop(2) */
81 +static inline abi_long do_bsd_semop(int semid, abi_long ptr, unsigned nsops)
82 +{
83 + g_autofree struct sembuf *sops = g_malloc(nsops * sizeof(struct sembuf));
84 + struct target_sembuf *target_sembuf;
85 + int i;
86 +
87 + target_sembuf = lock_user(VERIFY_READ, ptr,
88 + nsops * sizeof(struct target_sembuf), 1);
89 + if (target_sembuf == NULL) {
90 + return -TARGET_EFAULT;
91 + }
92 + for (i = 0; i < nsops; i++) {
93 + __get_user(sops[i].sem_num, &target_sembuf[i].sem_num);
94 + __get_user(sops[i].sem_op, &target_sembuf[i].sem_op);
95 + __get_user(sops[i].sem_flg, &target_sembuf[i].sem_flg);
96 + }
97 + unlock_user(target_sembuf, ptr, 0);
98 +
99 + return semop(semid, sops, nsops);
100 +}
101 +
102 /* getdtablesize(2) */
103 static inline abi_long do_bsd_getdtablesize(void)
104 {