From patchwork Sat Aug 9 14:42:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 35193 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qg0-f72.google.com (mail-qg0-f72.google.com [209.85.192.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 50DC82136C for ; Sat, 9 Aug 2014 14:42:36 +0000 (UTC) Received: by mail-qg0-f72.google.com with SMTP id q107sf19121200qgd.7 for ; Sat, 09 Aug 2014 07:42:36 -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:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=jkLDlNBduvWBwvhk8QJlrw8DPvkMXUZqolQXsZOlM4o=; b=fhknG/BY9hPSnKiyC6g4h0aKyY3CsDhbHuZ/ajuJ/xrqBf7PbQ0Gp8xqzvIt3EsDL7 nKYzM/HV3rjPZcOT9GZ7414/w6C+F4x2I3n/rh2id1dtOIf9mG6eJWHfFcxlqiam/nzl ZQSECgMA93GAcO05n6zkQx/9kBr+r3ZlxBKJZl526koTHyAWJreKw7m9L+8xr4nj51HE fnUfXLxsqYh/6qpJtUXM7ghpUNQUejJrBSglVlwCUchWig167ex8YXAomLz9Cm5zFmr4 /TLlnqe6PiUjso9z1a64j1wMD79Dft18AH1YaFww2LzDZ6nys+CltVBB2RkD2pWXwvyy Qy+Q== X-Gm-Message-State: ALoCoQlWYDmjvPshV8+FP/MKASU8RgepFf6HTTT+RVBYg0M2KLktsRjC/SG8c1TT4dUgMhHBmiem X-Received: by 10.236.216.67 with SMTP id f63mr2048120yhp.10.1407595356032; Sat, 09 Aug 2014 07:42:36 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.18.193 with SMTP id 59ls924325qgf.7.gmail; Sat, 09 Aug 2014 07:42:35 -0700 (PDT) X-Received: by 10.220.95.132 with SMTP id d4mr27405954vcn.33.1407595355962; Sat, 09 Aug 2014 07:42:35 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id xr4si3905142veb.87.2014.08.09.07.42.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 09 Aug 2014 07:42:35 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.170 as permitted sender) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id lf12so9726345vcb.15 for ; Sat, 09 Aug 2014 07:42:35 -0700 (PDT) X-Received: by 10.221.9.72 with SMTP id ov8mr27179677vcb.27.1407595355738; Sat, 09 Aug 2014 07:42:35 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp35269vcb; Sat, 9 Aug 2014 07:42:35 -0700 (PDT) X-Received: by 10.194.134.70 with SMTP id pi6mr40338116wjb.1.1407595354732; Sat, 09 Aug 2014 07:42:34 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id d7si7891205wiz.107.2014.08.09.07.42.34 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 09 Aug 2014 07:42:34 -0700 (PDT) Received-SPF: none (google.com: pm215@archaic.org.uk does not designate permitted sender hosts) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1XG7qq-0003LG-Qz; Sat, 09 Aug 2014 15:42:32 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Erik de Castro Lopo , Riku Voipio Subject: [PATCH] linux-user: Fix conversion of sigevent argument to timer_create Date: Sat, 9 Aug 2014 15:42:32 +0100 Message-Id: <1407595352-12821-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@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.170 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 --- Riku: this is going to conflict with and supersede Erik's oneliner patch which adds the unlock_user_struct() (I'm afraid I forgot about that when I was writing this and independently re-fixed the bug), so it might be simplest to drop that from the linux-user queue if you apply this instead. Otherwise if that patch makes it to master I'll rebase and resend this one at that point. 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 a50229d..4ce7455 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -4914,6 +4914,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, @@ -9413,7 +9439,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; @@ -9425,14 +9450,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));