From e2ad4ba061a43d200c5bb9e53baa1bbb334d3354 Mon Sep 17 00:00:00 2001 From: Stacey Son Date: Mon, 2 Feb 2026 14:56:58 -0700 Subject: [PATCH] bsd-user: Add host_to_target_msqid_ds for msgctl(2) Add host_to_target_msqid_ds() to convert host struct msqid_ds to target format for msgctl(2) IPC_STAT operations. Signed-off-by: Stacey Son Signed-off-by: Brooks Davis Signed-off-by: Sean Bruno Signed-off-by: Mikael Urankar Reviewed-by: Richard Henderson Signed-off-by: Warner Losh --- bsd-user/bsd-misc.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/bsd-user/bsd-misc.c b/bsd-user/bsd-misc.c index 5e5a590227..3e1968718f 100644 --- a/bsd-user/bsd-misc.c +++ b/bsd-user/bsd-misc.c @@ -163,3 +163,30 @@ abi_long target_to_host_msqid_ds(struct msqid_ds *host_md, return 0; } + +abi_long host_to_target_msqid_ds(abi_ulong target_addr, + struct msqid_ds *host_md) +{ + struct target_msqid_ds *target_md; + + if (!lock_user_struct(VERIFY_WRITE, target_md, target_addr, 0)) { + return -TARGET_EFAULT; + } + + memset(target_md, 0, sizeof(struct target_msqid_ds)); + host_to_target_ipc_perm__locked(&target_md->msg_perm, + &host_md->msg_perm); + + /* msg_first and msg_last are not used by IPC_SET/IPC_STAT in kernel. */ + __put_user(target_md->msg_cbytes, &host_md->msg_cbytes); + __put_user(target_md->msg_qnum, &host_md->msg_qnum); + __put_user(target_md->msg_qbytes, &host_md->msg_qbytes); + __put_user(target_md->msg_lspid, &host_md->msg_lspid); + __put_user(target_md->msg_lrpid, &host_md->msg_lrpid); + __put_user(target_md->msg_stime, &host_md->msg_stime); + __put_user(target_md->msg_rtime, &host_md->msg_rtime); + __put_user(target_md->msg_ctime, &host_md->msg_ctime); + unlock_user_struct(target_md, target_addr, 1); + + return 0; +}