From patchwork Mon Jun 6 18:58:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 631094 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rNkj76Mv3z9t3g for ; Tue, 7 Jun 2016 05:07:23 +1000 (AEST) Received: from localhost ([::1]:44675 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9zrt-0007Xn-Cl for incoming@patchwork.ozlabs.org; Mon, 06 Jun 2016 15:07:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59459) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9zjE-000066-SX for qemu-devel@nongnu.org; Mon, 06 Jun 2016 14:58:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b9zjD-0003lU-QF for qemu-devel@nongnu.org; Mon, 06 Jun 2016 14:58:24 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:57532) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9zjD-0003lI-IX for qemu-devel@nongnu.org; Mon, 06 Jun 2016 14:58:23 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1b9zjC-0008Pa-V1; Mon, 06 Jun 2016 19:58:22 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 6 Jun 2016 19:58:05 +0100 Message-Id: <1465239499-5048-5-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465239499-5048-1-git-send-email-peter.maydell@linaro.org> References: <1465239499-5048-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH 04/18] linux-user: Use safe_syscall wrapper for msgsnd and msgrcv X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Laurent Vivier , patches@linaro.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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 f5c5476..3735d7d 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -709,6 +709,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) { @@ -3155,7 +3183,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); @@ -3183,7 +3211,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);