bsd-user: Add target_to_host_msqid_ds for msgctl(2)
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 <sson@FreeBSD.org> Signed-off-by: Brooks Davis <brooks@one-eyed-alien.net> Signed-off-by: Sean Bruno <sbruno@FreeBSD.org> Signed-off-by: Mikael Urankar <mikael.urankar@gmail.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Warner Losh <imp@bsdimp.com>
Stacey Son committed
Feb 2, 2026 at 14:55 UTC
ee032d237fb5a52e574a9a57f083d0d8cde33340
1 file changed
+27
bsd-user/bsd-misc.c
+27
@@ -136,3 +136,30 @@ abi_long host_to_target_semid_ds(abi_ulong target_addr,
136
137
return 0;
138
}
139
+
140
+abi_long target_to_host_msqid_ds(struct msqid_ds *host_md,
141
+ abi_ulong target_addr)
142
+{
143
+ struct target_msqid_ds *target_md;
144
+
145
+ if (!lock_user_struct(VERIFY_READ, target_md, target_addr, 1)) {
146
+ return -TARGET_EFAULT;
147
+ }
148
+
149
+ memset(host_md, 0, sizeof(struct msqid_ds));
150
+ target_to_host_ipc_perm__locked(&host_md->msg_perm,
151
+ &target_md->msg_perm);
152
+
153
+ /* msg_first and msg_last are not used by IPC_SET/IPC_STAT in kernel. */
154
+ __get_user(host_md->msg_cbytes, &target_md->msg_cbytes);
155
+ __get_user(host_md->msg_qnum, &target_md->msg_qnum);
156
+ __get_user(host_md->msg_qbytes, &target_md->msg_qbytes);
157
+ __get_user(host_md->msg_lspid, &target_md->msg_lspid);
158
+ __get_user(host_md->msg_lrpid, &target_md->msg_lrpid);
159
+ __get_user(host_md->msg_stime, &target_md->msg_stime);
160
+ __get_user(host_md->msg_rtime, &target_md->msg_rtime);
161
+ __get_user(host_md->msg_ctime, &target_md->msg_ctime);
162
+ unlock_user_struct(target_md, target_addr, 0);
163
+
164
+ return 0;
165
+}