From: Stacey Son <[email protected]> Add implementation of msgctl(2) syscall for System V message queue control operations. Handles command translation and structure conversions for IPC_STAT/IPC_SET/IPC_RMID operations.
Signed-off-by: Stacey Son <[email protected]> Signed-off-by: Warner Losh <[email protected]> --- bsd-user/bsd-misc.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/bsd-user/bsd-misc.h b/bsd-user/bsd-misc.h index 81fdfd8351..27f4497d76 100644 --- a/bsd-user/bsd-misc.h +++ b/bsd-user/bsd-misc.h @@ -28,6 +28,12 @@ #include "qemu-bsd.h" +#ifdef MSGMAX +static int bsd_msgmax = MSGMAX; +#else +static int bsd_msgmax; +#endif + /* quotactl(2) */ static inline abi_long do_bsd_quotactl(abi_ulong path, abi_long cmd, __unused abi_ulong target_addr) @@ -228,6 +234,53 @@ static inline abi_long do_bsd___semctl(int semid, int semnum, int target_cmd, return ret; } +/* msgctl(2) */ +static inline abi_long do_bsd_msgctl(int msgid, int target_cmd, abi_long ptr) +{ + struct msqid_ds dsarg; + abi_long ret = -TARGET_EINVAL; + int host_cmd; + + switch (target_cmd) { + case TARGET_IPC_STAT: + host_cmd = IPC_STAT; + break; + + case TARGET_IPC_SET: + host_cmd = IPC_SET; + break; + + case TARGET_IPC_RMID: + host_cmd = IPC_RMID; + break; + + default: + return -TARGET_EINVAL; + } + + switch (host_cmd) { + case IPC_STAT: + case IPC_SET: + if (target_to_host_msqid_ds(&dsarg, ptr)) { + return -TARGET_EFAULT; + } + ret = get_errno(msgctl(msgid, host_cmd, &dsarg)); + if (host_to_target_msqid_ds(ptr, &dsarg)) { + return -TARGET_EFAULT; + } + break; + + case IPC_RMID: + ret = get_errno(msgctl(msgid, host_cmd, NULL)); + break; + + default: + ret = -TARGET_EINVAL; + break; + } + return ret; +} + /* getdtablesize(2) */ static inline abi_long do_bsd_getdtablesize(void) { -- 2.52.0
