From patchwork Tue Oct 30 12:55:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandar Markovic X-Patchwork-Id: 990814 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=rt-rk.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42ks3s2zClz9s3T for ; Tue, 30 Oct 2018 23:59:03 +1100 (AEDT) Received: from localhost ([::1]:53086 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHTbo-0002T4-Fy for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 08:59:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39687) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHTYf-0007DM-18 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 08:55:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHTYd-0006aO-SY for qemu-devel@nongnu.org; Tue, 30 Oct 2018 08:55:44 -0400 Received: from mx2.rt-rk.com ([89.216.37.149]:60924 helo=mail.rt-rk.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHTYd-0006Dd-DS for qemu-devel@nongnu.org; Tue, 30 Oct 2018 08:55:43 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.rt-rk.com (Postfix) with ESMTP id 5F0B71A224B; Tue, 30 Oct 2018 13:55:23 +0100 (CET) X-Virus-Scanned: amavisd-new at rt-rk.com Received: from rtrkw774-lin.domain.local (rtrkw774-lin.domain.local [10.10.13.43]) by mail.rt-rk.com (Postfix) with ESMTPSA id 0B4121A1DEB; Tue, 30 Oct 2018 13:55:23 +0100 (CET) From: Aleksandar Markovic To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 13:55:07 +0100 Message-Id: <1540904108-30873-3-git-send-email-aleksandar.markovic@rt-rk.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1540904108-30873-1-git-send-email-aleksandar.markovic@rt-rk.com> References: <1540904108-30873-1-git-send-email-aleksandar.markovic@rt-rk.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 89.216.37.149 Subject: [Qemu-devel] [PATCH v3 2/3] linux-user: Add support for semtimedop() syscall 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: arikalo@wavecomp.com, riku.voipio@iki.fi, ysu@wavecomp.com, laurent@vivier.eu, smarkovic@wavecomp.com, pjovanovic@wavecomp.com, aurelien@aurel32.net Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Aleksandar Rikalo Add support for semtimedop() emulation. It is based on invocation of safe_semtimedop(). Conversion is left out of safe_semtimedop(), since other safe_xxx() usually don't contain similar conversions. Signed-off-by: Aleksandar Rikalo Signed-off-by: Aleksandar Markovic --- linux-user/syscall.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 1d3aaf5..709d9a7 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6384,7 +6384,39 @@ static inline abi_long host_to_target_statx(struct target_statx *host_stx, return 0; } #endif +#ifdef TARGET_NR_semtimedop +static inline abi_long do_semtimedop(int semid, abi_long ptr, unsigned nsops, + abi_long timeout) +{ + struct sembuf *sops; + struct timespec ts, *pts; + abi_long ret; + + if (timeout) { + pts = &ts; + if (target_to_host_timespec(pts, timeout)) { + return -TARGET_EFAULT; + } + } else { + pts = NULL; + } + sops = g_malloc(sizeof(struct sembuf) * nsops); + if (sops == NULL) { + return -TARGET_EFAULT; + } + + if (target_to_host_sembuf(sops, ptr, nsops)) { + g_free(sops); + return -TARGET_EFAULT; + } + + ret = get_errno(safe_semtimedop(semid, sops, nsops, pts)); + g_free(sops); + + return ret; +} +#endif /* ??? Using host futex calls even when target atomic operations are not really atomic probably breaks things. However implementing @@ -8888,6 +8920,10 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, case TARGET_NR_semop: return do_semop(arg1, arg2, arg3); #endif +#ifdef TARGET_NR_semtimedop + case TARGET_NR_semtimedop: + return do_semtimedop(arg1, arg2, arg3, arg4); +#endif #ifdef TARGET_NR_semctl case TARGET_NR_semctl: return do_semctl(arg1, arg2, arg3, arg4);