[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 31/44] linux-user: Use safe_syscall wrapper for msgsn
From: |
riku . voipio |
Subject: |
[Qemu-devel] [PULL 31/44] linux-user: Use safe_syscall wrapper for msgsnd and msgrcv |
Date: |
Wed, 8 Jun 2016 16:30:12 +0300 |
From: Peter Maydell <address@hidden>
Use the safe_syscall wrapper for msgsnd and msgrcv syscalls.
This is made slightly awkward by some host architectures providing
only a single 'ipc' syscall rather than separate syscalls per
operation; we provide safe_msgsnd() and safe_msgrcv() as wrappers
around safe_ipc() to handle this if needed.
Signed-off-by: Peter Maydell <address@hidden>
Signed-off-by: Riku Voipio <address@hidden>
---
linux-user/syscall.c | 32 ++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index bcae62d..b41d269 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -722,6 +722,34 @@ safe_syscall6(ssize_t, recvfrom, int, fd, void *, buf,
size_t, len,
int, flags, struct sockaddr *, addr, socklen_t *, addrlen)
safe_syscall3(ssize_t, sendmsg, int, fd, const struct msghdr *, msg, int,
flags)
safe_syscall3(ssize_t, recvmsg, int, fd, struct msghdr *, msg, int, flags)
+#ifdef __NR_msgsnd
+safe_syscall4(int, msgsnd, int, msgid, const void *, msgp, size_t, sz,
+ int, flags)
+safe_syscall5(int, msgrcv, int, msgid, void *, msgp, size_t, sz,
+ long, msgtype, int, flags)
+#else
+/* This host kernel architecture uses a single ipc syscall; fake up
+ * wrappers for the sub-operations to hide this implementation detail.
+ * Annoyingly we can't include linux/ipc.h to get the constant definitions
+ * for the call parameter because some structs in there conflict with the
+ * sys/ipc.h ones. So we just define them here, and rely on them being
+ * the same for all host architectures.
+ */
+#define Q_MSGSND 11
+#define Q_MSGRCV 12
+#define Q_IPCCALL(VERSION, OP) ((VERSION) << 16 | (OP))
+
+safe_syscall6(int, ipc, int, call, long, first, long, second, long, third,
+ void *, ptr, long, fifth)
+static int safe_msgsnd(int msgid, const void *msgp, size_t sz, int flags)
+{
+ return safe_ipc(Q_IPCCALL(0, Q_MSGSND), msgid, sz, flags, (void *)msgp, 0);
+}
+static int safe_msgrcv(int msgid, void *msgp, size_t sz, long type, int flags)
+{
+ return safe_ipc(Q_IPCCALL(1, Q_MSGRCV), msgid, sz, flags, msgp, type);
+}
+#endif
static inline int host_to_target_sock_type(int host_type)
{
@@ -3796,7 +3824,7 @@ static inline abi_long do_msgsnd(int msqid, abi_long msgp,
}
host_mb->mtype = (abi_long) tswapal(target_mb->mtype);
memcpy(host_mb->mtext, target_mb->mtext, msgsz);
- ret = get_errno(msgsnd(msqid, host_mb, msgsz, msgflg));
+ ret = get_errno(safe_msgsnd(msqid, host_mb, msgsz, msgflg));
g_free(host_mb);
unlock_user_struct(target_mb, msgp, 0);
@@ -3824,7 +3852,7 @@ static inline abi_long do_msgrcv(int msqid, abi_long msgp,
ret = -TARGET_ENOMEM;
goto end;
}
- ret = get_errno(msgrcv(msqid, host_mb, msgsz, msgtyp, msgflg));
+ ret = get_errno(safe_msgrcv(msqid, host_mb, msgsz, msgtyp, msgflg));
if (ret > 0) {
abi_ulong target_mtext_addr = msgp + sizeof(abi_ulong);
--
2.1.4
- [Qemu-devel] [PULL 22/44] linux-user: Use both si_code and si_signo when converting siginfo_t, (continued)
- [Qemu-devel] [PULL 22/44] linux-user: Use both si_code and si_signo when converting siginfo_t, riku . voipio, 2016/06/08
- [Qemu-devel] [PULL 26/44] linux-user: Fix NR_fadvise64 and NR_fadvise64_64 for 32-bit guests, riku . voipio, 2016/06/08
- [Qemu-devel] [PULL 33/44] linux-user: Use safe_syscall wrapper for flock, riku . voipio, 2016/06/08
- [Qemu-devel] [PULL 30/44] linux-user: Use safe_syscall wrapper for send* and recv* syscalls, riku . voipio, 2016/06/08
- [Qemu-devel] [PULL 29/44] linux-user: Use safe_syscall wrapper for connect syscall, riku . voipio, 2016/06/08
- [Qemu-devel] [PULL 37/44] linux-user: Use safe_syscall wrapper for epoll_wait syscalls, riku . voipio, 2016/06/08
- [Qemu-devel] [PULL 27/44] linux-user: Fix error conversion in 64-bit fadvise syscall, riku . voipio, 2016/06/08
- [Qemu-devel] [PULL 36/44] linux-user: Use safe_syscall wrapper for poll and ppoll syscalls, riku . voipio, 2016/06/08
- [Qemu-devel] [PULL 32/44] linux-user: Use safe_syscall wrapper for mq_timedsend and mq_timedreceive, riku . voipio, 2016/06/08
- [Qemu-devel] [PULL 35/44] linux-user: Use safe_syscall wrapper for sleep syscalls, riku . voipio, 2016/06/08
- [Qemu-devel] [PULL 31/44] linux-user: Use safe_syscall wrapper for msgsnd and msgrcv,
riku . voipio <=
- [Qemu-devel] [PULL 38/44] linux-user: Use safe_syscall wrapper for semop, riku . voipio, 2016/06/08
- [Qemu-devel] [PULL 39/44] linux-user: Use safe_syscall wrapper for accept and accept4 syscalls, riku . voipio, 2016/06/08
- [Qemu-devel] [PULL 41/44] linux-user: Correct signedness of target_flock l_start and l_len fields, riku . voipio, 2016/06/08
- [Qemu-devel] [PULL 43/44] linux-user: Special-case ERESTARTSYS in target_strerror(), riku . voipio, 2016/06/08
- [Qemu-devel] [PULL 34/44] linux-user: Use safe_syscall wrapper for rt_sigtimedwait syscall, riku . voipio, 2016/06/08
- [Qemu-devel] [PULL 40/44] linux-user: Use safe_syscall wrapper for ioctl, riku . voipio, 2016/06/08
- [Qemu-devel] [PULL 42/44] linux-user: Make target_strerror() return 'const char *', riku . voipio, 2016/06/08
- [Qemu-devel] [PULL 44/44] linux-user: In fork_end(), remove correct CPUs from CPU list, riku . voipio, 2016/06/08
- Re: [Qemu-devel] [PULL 00/44] linux-user update, Peter Maydell, 2016/06/08
- Re: [Qemu-devel] [PULL 00/44] linux-user update, Laurent Vivier, 2016/06/09