From: Stacey Son Date: Mon, 2 Feb 2026 23:44:39 +0000 (-0700) Subject: bsd-user: Add do_bsd_semop implementation X-Git-Tag: v11.0.0-rc0~42^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=441ddfb820ae30d4a47bb378d7cd830c093a2747;p=thirdparty%2Fqemu.git 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 Reviewed-by: Richard Henderson Signed-off-by: Warner Losh --- diff --git a/bsd-user/bsd-misc.h b/bsd-user/bsd-misc.h index 3dffb977a54..e1e552b58f5 100644 --- a/bsd-user/bsd-misc.h +++ b/bsd-user/bsd-misc.h @@ -77,6 +77,28 @@ static inline abi_long do_bsd_semget(abi_long key, int nsems, target_to_host_bitmask(target_flags, ipc_flags_tbl))); } +/* semop(2) */ +static inline abi_long do_bsd_semop(int semid, abi_long ptr, unsigned nsops) +{ + g_autofree struct sembuf *sops = g_malloc(nsops * sizeof(struct sembuf)); + struct target_sembuf *target_sembuf; + int i; + + target_sembuf = lock_user(VERIFY_READ, ptr, + nsops * sizeof(struct target_sembuf), 1); + if (target_sembuf == NULL) { + return -TARGET_EFAULT; + } + for (i = 0; i < nsops; i++) { + __get_user(sops[i].sem_num, &target_sembuf[i].sem_num); + __get_user(sops[i].sem_op, &target_sembuf[i].sem_op); + __get_user(sops[i].sem_flg, &target_sembuf[i].sem_flg); + } + unlock_user(target_sembuf, ptr, 0); + + return semop(semid, sops, nsops); +} + /* getdtablesize(2) */ static inline abi_long do_bsd_getdtablesize(void) {