From patchwork Wed Jun 8 13:30:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 69662 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp2522250qgf; Wed, 8 Jun 2016 07:20:07 -0700 (PDT) X-Received: by 10.140.29.247 with SMTP id b110mr4671789qgb.2.1465395605904; Wed, 08 Jun 2016 07:20:05 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id p39si781274qgp.86.2016.06.08.07.20.05 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 08 Jun 2016 07:20:05 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57278 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAeKz-0007Wy-C4 for patch@linaro.org; Wed, 08 Jun 2016 10:20:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37191) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAdZf-0004Y0-U6 for qemu-devel@nongnu.org; Wed, 08 Jun 2016 09:31:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bAdZZ-0005q0-HR for qemu-devel@nongnu.org; Wed, 08 Jun 2016 09:31:10 -0400 Received: from mail-lf0-x22b.google.com ([2a00:1450:4010:c07::22b]:35678) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAdZZ-0005pj-9A for qemu-devel@nongnu.org; Wed, 08 Jun 2016 09:31:05 -0400 Received: by mail-lf0-x22b.google.com with SMTP id u74so5855307lff.2 for ; Wed, 08 Jun 2016 06:31:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zbixF5lbgiWACh6Nt4lc/NgNEDS6k6/xUdK/vYb/eik=; b=A8ByqKVe+1db0gEz77YDjfudeZIkRbAIDncjcIpAW1XiNiUyuM2P5AbS9RfjhDFT6V lX0hZnxrQwlHss015M5nTn9dZcTgxnu8Itgk1DT2RsY/nZ/ERhrBhcYWE7ul62N2iO8/ bYRXTcP7t+F78Wt5q7N5wsG3XxjBE8R45Jzsw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zbixF5lbgiWACh6Nt4lc/NgNEDS6k6/xUdK/vYb/eik=; b=IgSL6WDTi/61ncqzVsaOCI14/v3aBVv1zk4VbaMh7Xid8uCTgzRiICSr+KWto7t9Cq XujC8VYQyQzj53AtT22rzxnwEtQUO0WGDYd0A5Wm0oSCjM9DuFVPApB3n5XB8OJbKD0U qMt2j3Ayv1Bo9sPpwJcy+TQCGPgmi2KJJSsVvFWQtaIzf8yfGI0pn2Iv6d3+k1FDlMxB aqh8WhOQSyAijKkyWO9KrwDMBXpwlzYACKraVWl18pugdC1kFNIpTOTeDFAKLxWwS6iQ BnfL3z9wgtK9UdHmlpDXBuJD4kbI39+uJ3UoFS6v/zMCM6NgSO5jWjv3TLhlGwm4YEJ9 XmSQ== X-Gm-Message-State: ALyK8tKg5eOMzHyLkykVjoKy2F1YR3i0bLNiPv2JocUHBblzgeHmkjbc+QTQ5TvlYTzchpyV X-Received: by 10.25.73.136 with SMTP id w130mr647018lfa.172.1465392664551; Wed, 08 Jun 2016 06:31:04 -0700 (PDT) Received: from beaming.home (91-157-170-157.elisa-laajakaista.fi. [91.157.170.157]) by smtp.gmail.com with ESMTPSA id 2sm139854lja.37.2016.06.08.06.31.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Jun 2016 06:31:03 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Wed, 8 Jun 2016 16:30:12 +0300 Message-Id: <89f9fe4452848386e9d0aacd84ac681944051b78.1465392531.git.riku.voipio@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::22b Subject: [Qemu-devel] [PULL 31/44] 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: Peter Maydell Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell 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 Signed-off-by: Riku Voipio --- linux-user/syscall.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) -- 2.1.4 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);