From patchwork Tue Nov 5 13:57:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 288527 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 40AA52C0091 for ; Wed, 6 Nov 2013 01:00:39 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=nYmjPI+NCV4wp5Ng+Zz+uOUr+7xRxLla0c+h1F2ct4tIhzSEKfHEQ R3iUeAtjZjDLXTjooQjbo0m0/Y4bhMLN5Bk4LXUhwL2zHdBWPtMBR4LPvooUpcFZ nlrLSgmHoscdlI6lpIxyXNuwH0ggT8aSMQI5Yu9jFaSa4V7SXzLZgY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=orTqoMATzv7n/ucwhpIxYVwVQ1A=; b=MZcggjgqDTFXWoXfPlRo 6BtIrz5l6S1+7aY75ZH2NNtIQA9hKz0l1D1JoYyBj9uQ2431Ql2erWfTHVBXyEln 88OxzBZ/JgdYgfiMR46p7tKNdoguEgpVUnWmOTKnA+3QR/+xaizZa1ik976f16VA L82aQv+voPHr+FSN/EIs3u8= Received: (qmail 12227 invoked by alias); 5 Nov 2013 13:58:59 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 12190 invoked by uid 89); 5 Nov 2013 13:58:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.3 required=5.0 tests=AWL, BAYES_50, FREEMAIL_FROM, RDNS_NONE, SPF_PASS, URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: mail-gg0-f170.google.com Received: from Unknown (HELO mail-gg0-f170.google.com) (209.85.161.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 05 Nov 2013 13:57:59 +0000 Received: by mail-gg0-f170.google.com with SMTP id 4so3177602ggm.15 for ; Tue, 05 Nov 2013 05:57:52 -0800 (PST) X-Received: by 10.236.163.228 with SMTP id a64mr18554289yhl.35.1383659872106; Tue, 05 Nov 2013 05:57:52 -0800 (PST) Received: from gnu-tools-1.localdomain (76-220-57-190.lightspeed.sntcca.sbcglobal.net. [76.220.57.190]) by mx.google.com with ESMTPSA id v22sm36217240yhn.12.2013.11.05.05.57.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Nov 2013 05:57:51 -0800 (PST) Received: by gnu-tools-1.localdomain (Postfix, from userid 1000) id D608C40738; Tue, 5 Nov 2013 05:57:49 -0800 (PST) Date: Tue, 5 Nov 2013 05:57:49 -0800 From: "H.J. Lu" To: gcc-patches@gcc.gnu.org, konstantin.s.serebryany@gmail.com Subject: [PATCH 2/4] Fix internal_clone for x32 Message-ID: <20131105135749.GA16493@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes We need to allcate 2 64-bit integers to restore fn and arg with pop, which only pop 64-bit integer into 64-bit register. Also pointers are 32-bit for x32. This patch properly loads r8/r10 fpr syscall. Please install it. Thanks. H.J. --- libsanitizer/ChangeLog.x32 | 6 ++++++ libsanitizer/sanitizer_common/sanitizer_linux.cc | 16 ++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/libsanitizer/ChangeLog.x32 b/libsanitizer/ChangeLog.x32 index 7b54005..40b185d 100644 --- a/libsanitizer/ChangeLog.x32 +++ b/libsanitizer/ChangeLog.x32 @@ -1,5 +1,11 @@ 2013-11-05 H.J. Lu + * sanitizer_common/sanitizer_linux.cc (internal_clone): Allocate + 2 64-bit integers to save and restore fn and arg. Properly load + newtls/child_tidptr into r8/r10. + +2013-11-05 H.J. Lu + * sanitizer_common/sanitizer_linux.cc (internal_mmap): Cast pointers to uptr for 64-bit syscalls. (internal_munmap): Likewise. diff --git a/libsanitizer/sanitizer_common/sanitizer_linux.cc b/libsanitizer/sanitizer_common/sanitizer_linux.cc index e48bee5..bb43437 100644 --- a/libsanitizer/sanitizer_common/sanitizer_linux.cc +++ b/libsanitizer/sanitizer_common/sanitizer_linux.cc @@ -772,9 +772,11 @@ uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg, if (!fn || !child_stack) return -EINVAL; CHECK_EQ(0, (uptr)child_stack % 16); - child_stack = (char *)child_stack - 2 * sizeof(void *); - ((void **)child_stack)[0] = (void *)(uptr)fn; - ((void **)child_stack)[1] = arg; + child_stack = (char *)child_stack - 2 * sizeof(unsigned long long); + ((unsigned long long *)child_stack)[0] = (uptr)fn; + ((unsigned long long *)child_stack)[1] = (uptr)arg; + void *r8 __asm__ ("r8") = newtls; + int *r10 __asm__ ("r10") = child_tidptr; __asm__ __volatile__( /* %rax = syscall(%rax = __NR_clone, * %rdi = flags, @@ -783,8 +785,6 @@ uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg, * %r8 = new_tls, * %r10 = child_tidptr) */ - "movq %6,%%r8\n" - "movq %7,%%r10\n" ".cfi_endproc\n" "syscall\n" @@ -816,9 +816,9 @@ uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg, "S"(child_stack), "D"(flags), "d"(parent_tidptr), - "r"(newtls), - "r"(child_tidptr) - : "rsp", "memory", "r8", "r10", "r11", "rcx"); + "r"(r8), + "r"(r10) + : "rsp", "memory", "r11", "rcx"); return res; } #endif // defined(__x86_64__)