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]> Reviewed-by: Richard Henderson <[email protected]> Signed-off-by: Warner Losh <[email protected]> --- bsd-user/bsd-misc.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/bsd-user/bsd-misc.h b/bsd-user/bsd-misc.h index d3ce01a2a3..a45fe8edb5 100644 --- a/bsd-user/bsd-misc.h +++ b/bsd-user/bsd-misc.h @@ -221,6 +221,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
