From patchwork Tue Aug 19 08:32:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 35567 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f199.google.com (mail-ob0-f199.google.com [209.85.214.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 37D372136C for ; Tue, 19 Aug 2014 08:43:56 +0000 (UTC) Received: by mail-ob0-f199.google.com with SMTP id wn1sf41421278obc.2 for ; Tue, 19 Aug 2014 01:43:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=g6f69iI0kwZB9pNwn2Oieo0xEiH3h3m3Ue1GW6RHdcs=; b=haZXS/nghiqcfMdY5x6/zxOG94xOqi582/zHfPfZQyYa7iXU8xoVfmOczLNayunVSc SFBfsR1zlV/aSuAAiaef10TU+adJ2iB87U/pruX4ccwEFm4JCa82JHmZJTFb56D/o3XY lZNT4hEonsAwYtUBy8nCbMDnvC9JqaU5U3gow2zR2q0X6Y4d76p+bESckrHFtKmHe6Lr ZccfhZVw1JNGpU35wfV3DmnJoJtGvWR5lrTzqMFxw8jU5xQ2j7Qj2hQU2VrhyIFCOBeU 0RJWPWI/Ri6+OM1zvbU1qXP94Ai3kG6ht67yy/DTDixqstjFozbfjFsh1saoQt0J5CP1 Jpig== X-Gm-Message-State: ALoCoQmloQCYfksLnNAOze1vYaibjHX/rUObQNEgZfIjZNCgxN1eOMgEuHkYyOmoTt2f26KFhv9N X-Received: by 10.182.43.164 with SMTP id x4mr21704229obl.5.1408437835804; Tue, 19 Aug 2014 01:43:55 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.84.47 with SMTP id k44ls2672183qgd.73.gmail; Tue, 19 Aug 2014 01:43:55 -0700 (PDT) X-Received: by 10.52.30.2 with SMTP id o2mr173009vdh.12.1408437835699; Tue, 19 Aug 2014 01:43:55 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id br4si8340110vcb.106.2014.08.19.01.43.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 19 Aug 2014 01:43:55 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id ij19so7112289vcb.11 for ; Tue, 19 Aug 2014 01:43:55 -0700 (PDT) X-Received: by 10.52.148.2 with SMTP id to2mr8441403vdb.38.1408437835591; Tue, 19 Aug 2014 01:43:55 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp220842vcb; Tue, 19 Aug 2014 01:43:55 -0700 (PDT) X-Received: by 10.224.88.71 with SMTP id z7mr66031039qal.94.1408437834840; Tue, 19 Aug 2014 01:43:54 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 76si28024057qgh.90.2014.08.19.01.43.54 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 19 Aug 2014 01:43:54 -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; Received: from localhost ([::1]:49154 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJf1G-0001xu-D7 for patch@linaro.org; Tue, 19 Aug 2014 04:43:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57378) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJequ-00012b-4K for qemu-devel@nongnu.org; Tue, 19 Aug 2014 04:33:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XJeql-0001Zo-IA for qemu-devel@nongnu.org; Tue, 19 Aug 2014 04:33:12 -0400 Received: from [2001:4b98:dc0:45:216:3eff:fe3d:166f] (port=50282 helo=afflict.kos.to) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJeql-0001YA-93 for qemu-devel@nongnu.org; Tue, 19 Aug 2014 04:33:03 -0400 Received: from afflict.kos.to (afflict [92.243.29.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by afflict.kos.to (Postfix) with ESMTPSA id 79DD926587; Tue, 19 Aug 2014 10:33:01 +0200 (CEST) From: riku.voipio@linaro.org To: Peter Maydell , qemu-devel@nongnu.org Date: Tue, 19 Aug 2014 11:32:39 +0300 Message-Id: <5cabb572cbb1995369a44c72b6f214e5a44c5b34.1408436940.git.riku.voipio@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 2001:4b98:dc0:45:216:3eff:fe3d:166f Subject: [Qemu-devel] [PULL v2 04/23] linux-user: Fix conversion of sigevent argument to timer_create X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: riku.voipio@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Peter Maydell There were a number of bugs in the conversion of the sigevent argument to timer_create from target to host format: * signal number not converted from target to host * thread ID not copied across * sigev_value not copied across * we never unlocked the struct when we were done Between them, these problems meant that SIGEV_THREAD_ID timers (and the glibc-implemented SIGEV_THREAD timers which depend on them) didn't work. Fix these problems and clean up the code a little by pulling the struct conversion out into its own function, in line with how we convert various other structs. This allows the test program in bug LP:1042388 to run. Signed-off-by: Peter Maydell Signed-off-by: Riku Voipio --- linux-user/syscall.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index dd77673..fccf9f0 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -4912,6 +4912,32 @@ static inline abi_long host_to_target_itimerspec(abi_ulong target_addr, return 0; } +static inline abi_long target_to_host_sigevent(struct sigevent *host_sevp, + abi_ulong target_addr) +{ + struct target_sigevent *target_sevp; + + if (!lock_user_struct(VERIFY_READ, target_sevp, target_addr, 1)) { + return -TARGET_EFAULT; + } + + /* This union is awkward on 64 bit systems because it has a 32 bit + * integer and a pointer in it; we follow the conversion approach + * used for handling sigval types in signal.c so the guest should get + * the correct value back even if we did a 64 bit byteswap and it's + * using the 32 bit integer. + */ + host_sevp->sigev_value.sival_ptr = + (void *)(uintptr_t)tswapal(target_sevp->sigev_value.sival_ptr); + host_sevp->sigev_signo = + target_to_host_signal(tswap32(target_sevp->sigev_signo)); + host_sevp->sigev_notify = tswap32(target_sevp->sigev_notify); + host_sevp->_sigev_un._tid = tswap32(target_sevp->_sigev_un._tid); + + unlock_user_struct(target_sevp, target_addr, 1); + return 0; +} + #if defined(TARGET_NR_stat64) || defined(TARGET_NR_newfstatat) static inline abi_long host_to_target_stat64(void *cpu_env, abi_ulong target_addr, @@ -9403,7 +9429,6 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, /* args: clockid_t clockid, struct sigevent *sevp, timer_t *timerid */ struct sigevent host_sevp = { {0}, }, *phost_sevp = NULL; - struct target_sigevent *ptarget_sevp; struct target_timer_t *ptarget_timer; int clkid = arg1; @@ -9415,14 +9440,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, timer_t *phtimer = g_posix_timers + timer_index; if (arg2) { - if (!lock_user_struct(VERIFY_READ, ptarget_sevp, arg2, 1)) { - goto efault; - } - - host_sevp.sigev_signo = tswap32(ptarget_sevp->sigev_signo); - host_sevp.sigev_notify = tswap32(ptarget_sevp->sigev_notify); - phost_sevp = &host_sevp; + ret = target_to_host_sigevent(phost_sevp, arg2); + if (ret != 0) { + break; + } } ret = get_errno(timer_create(clkid, phost_sevp, phtimer));