From: Stacey Son <[email protected]>

Add target_to_host_msqid_ds() to convert target struct msqid_ds to host
format for msgctl(2) IPC_SET operations. Uses memset to zero the struct
rather than directly accessing kernel-only members. Handles FreeBSD
64-bit time_t except on i386.

Signed-off-by: Stacey Son <[email protected]>
Signed-off-by: Brooks Davis <[email protected]>
Signed-off-by: Sean Bruno <[email protected]>
Signed-off-by: Mikael Urankar <[email protected]>
Signed-off-by: Warner Losh <[email protected]>
---
 bsd-user/bsd-misc.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/bsd-user/bsd-misc.c b/bsd-user/bsd-misc.c
index f35f682aa4..e7031c5264 100644
--- a/bsd-user/bsd-misc.c
+++ b/bsd-user/bsd-misc.c
@@ -154,3 +154,36 @@ abi_long host_to_target_semid_ds(abi_ulong target_addr,
 
     return 0;
 }
+
+abi_long target_to_host_msqid_ds(struct msqid_ds *host_md,
+        abi_ulong target_addr)
+{
+    struct target_msqid_ds *target_md;
+
+    if (!lock_user_struct(VERIFY_READ, target_md, target_addr, 1)) {
+        return -TARGET_EFAULT;
+    }
+
+    memset(host_md, 0, sizeof(struct msqid_ds));
+    target_to_host_ipc_perm__locked(&host_md->msg_perm,
+                                    &target_md->msg_perm);
+
+    /* msg_first and msg_last are not used by IPC_SET/IPC_STAT in kernel. */
+    host_md->msg_cbytes = tswapal(target_md->msg_cbytes);
+    host_md->msg_qnum = tswapal(target_md->msg_qnum);
+    host_md->msg_qbytes = tswapal(target_md->msg_qbytes);
+    host_md->msg_lspid = tswapal(target_md->msg_lspid);
+    host_md->msg_lrpid = tswapal(target_md->msg_lrpid);
+#if defined(TARGET_I386)
+    host_md->msg_stime = tswap32(target_md->msg_stime);
+    host_md->msg_rtime = tswap32(target_md->msg_rtime);
+    host_md->msg_ctime = tswap32(target_md->msg_ctime);
+#else
+    host_md->msg_stime = tswap64(target_md->msg_stime);
+    host_md->msg_rtime = tswap64(target_md->msg_rtime);
+    host_md->msg_ctime = tswap64(target_md->msg_ctime);
+#endif
+    unlock_user_struct(target_md, target_addr, 0);
+
+    return 0;
+}

-- 
2.52.0


Reply via email to