From patchwork Thu Sep 17 20:04:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 519007 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id ABAA31402BF for ; Fri, 18 Sep 2015 06:04:31 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=Q3akva1M; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:subject:to:message-id:date:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=dhz F1QY4Y8cynPpmeYaihU+982GzuVcFI6VMHyl8ryJcxthaA6Zf4vlfvQgtlzWsemL LiqJ03GNMjkN0b7f7tEV4pGd9h+QD/nfmQ4ZUxq54WLK3Tcm8o/ugZ0Adqf4jhID JJM3ye+OupSF6uEueYGTU0OUZs4DbAl9PEPOtIEY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:subject:to:message-id:date:mime-version :content-type:content-transfer-encoding; s=default; bh=6/1s4UqHn zj9XLbwFaJyQdxdpEE=; b=Q3akva1M2150D9z84udsg6dlslNvf3f7RGJbMcdSz 5B2ng3RIXO6BiGW/10Lm+k/rbPlm13jOj/R0YW85+fLeOXAKt567bGc0UrnFVAC/ GHF9w3hPO/BoDBH9PZpAlwsiHXvje4FETF7eaJaHzJuszdO2HbqqHjrLbT+sPz37 LM= Received: (qmail 106551 invoked by alias); 17 Sep 2015 20:04:22 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 106474 invoked by uid 89); 17 Sep 2015 20:04:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-yk0-f176.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version:content-type:content-transfer-encoding; bh=jlwRzlH4UXqQf3ikATqw1laKgbo5XnmEHCh1374EP8c=; b=AbV8C7niNRPnxpa+VK0MTqPGWRJmW+aVklIC+2g2wtV7iKnyubAwKq556UFVX1AzGR INzN+LzUvSWJfnErvF8rXW8ELjZNMB9T4gorJGfNmo3z/0hvhVM4AboTLIrT98m8YRep xooBWzSusCGhUbMfxsmr5myilgsAfo7K6EW9whIBnu2mGQg18U3DCIovS1a6Q5I7PH0E Cfb7UUrW7H/U/W7io8HzfbvFTyGk9sV4Gg2t0eQm4V+W14MTqMLjktjhZa769dvba3mE oKg7xiJeDhWP8ZJb4QoiuJku+t4CSs1ArODYk3nzjHfl+MsShZN+YW/3ZoPTFgvuOGqV j2ZQ== X-Gm-Message-State: ALoCoQk0MA4lAjgpegrAJ1KC8Zo+liZ60uL8gt6puE47nMJIoiF939x68DaQh8ILxrlbsfbUvD0S X-Received: by 10.129.108.84 with SMTP id h81mr1124650ywc.134.1442520251205; Thu, 17 Sep 2015 13:04:11 -0700 (PDT) From: Adhemerval Zanella Subject: [PATCH 06/10] nptl: ppc32: Fix Race conditions in pthread cancellation (BZ#12683) To: GNU C Library Message-ID: <55FB1CBB.90001@linaro.org> Date: Thu, 17 Sep 2015 17:04:11 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 This patches adds the ppc32 modification required for the BZ#12683 fix. It basically removes the enable_asynccancel/disable_asynccancel function usage on code used on ppc32. --- * sysdeps/unix/sysv/linux/i386/fcntl.c (NO_CANCELLATION): Replace by IS_IN (rtld). * sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h (PSEUDO): Redefine to call __syscall_cancel function for cancellable syscalls. (__pthread_get_ip): Add implementation. * sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h [SYSCALL_CANCEL_ERROR]: New macro. [SYSCALL_CANCEL_ERRNO]: New macro. -- diff --git a/sysdeps/unix/sysv/linux/i386/fcntl.c b/sysdeps/unix/sysv/linux/i386/fcntl.c index 56f4bd1..ac5eed4 100644 --- a/sysdeps/unix/sysv/linux/i386/fcntl.c +++ b/sysdeps/unix/sysv/linux/i386/fcntl.c @@ -23,7 +23,7 @@ #include -#ifndef NO_CANCELLATION +#if !IS_IN (rtld) int __fcntl_nocancel (int fd, int cmd, ...) { @@ -36,7 +36,7 @@ __fcntl_nocancel (int fd, int cmd, ...) return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg); } -#endif /* NO_CANCELLATION */ +#endif int diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h b/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h index dd9ff1c..d625495 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h @@ -25,94 +25,83 @@ #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt) +# if !IS_IN (libc) +# define SETUP_PIC \ + bcl 20,31,got_label; \ +got_label: + +# define CANCEL_JUMPTARGET \ + stw r30,8(r1); \ + mflr r30; \ + addis r30,r30,_GLOBAL_OFFSET_TABLE_-got_label@ha; \ + addi r30,r30,_GLOBAL_OFFSET_TABLE_-got_label@l; \ + bl __syscall_cancel@plt; \ + lwz r30,8(r1) +# else +# define SETUP_PIC +# if defined SHARED && defined PIC +# define CANCEL_JUMPTARGET \ + bl __GI___syscall_cancel@locaL +# else +# define CANCEL_JUMPTARGET \ + bl __syscall_cancel +# endif +# endif + # undef PSEUDO # define PSEUDO(name, syscall_name, args) \ .section ".text"; \ ENTRY (name) \ SINGLE_THREAD_P; \ - bne- .Lpseudo_cancel; \ - .type __##syscall_name##_nocancel,@function; \ - .globl __##syscall_name##_nocancel; \ - __##syscall_name##_nocancel: \ + bne- L(pseudo_cancel); \ DO_CALL (SYS_ify (syscall_name)); \ - PSEUDO_RET; \ - .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \ - .Lpseudo_cancel: \ - stwu 1,-48(1); \ - cfi_adjust_cfa_offset (48); \ - mflr 9; \ - stw 9,52(1); \ + bnslr+; \ + b __syscall_error@local; \ + L(pseudo_cancel): \ + stwu r1,-16(r1); \ + cfi_adjust_cfa_offset (16); \ + mflr r0; \ + SETUP_PIC; \ + stw r0,20(r1); \ cfi_offset (lr, 4); \ - DOCARGS_##args; /* save syscall args around CENABLE. */ \ - CENABLE; \ - stw 3,16(1); /* store CENABLE return value (MASK). */ \ - UNDOCARGS_##args; /* restore syscall args. */ \ - DO_CALL (SYS_ify (syscall_name)); \ - mfcr 0; /* save CR/R3 around CDISABLE. */ \ - stw 3,8(1); \ - stw 0,12(1); \ - lwz 3,16(1); /* pass MASK to CDISABLE. */ \ - CDISABLE; \ - lwz 4,52(1); \ - lwz 0,12(1); /* restore CR/R3. */ \ - lwz 3,8(1); \ - mtlr 4; \ - mtcr 0; \ - addi 1,1,48; - -# define DOCARGS_0 -# define UNDOCARGS_0 - -# define DOCARGS_1 stw 3,20(1); DOCARGS_0 -# define UNDOCARGS_1 lwz 3,20(1); UNDOCARGS_0 - -# define DOCARGS_2 stw 4,24(1); DOCARGS_1 -# define UNDOCARGS_2 lwz 4,24(1); UNDOCARGS_1 - -# define DOCARGS_3 stw 5,28(1); DOCARGS_2 -# define UNDOCARGS_3 lwz 5,28(1); UNDOCARGS_2 - -# define DOCARGS_4 stw 6,32(1); DOCARGS_3 -# define UNDOCARGS_4 lwz 6,32(1); UNDOCARGS_3 - -# define DOCARGS_5 stw 7,36(1); DOCARGS_4 -# define UNDOCARGS_5 lwz 7,36(1); UNDOCARGS_4 - -# define DOCARGS_6 stw 8,40(1); DOCARGS_5 -# define UNDOCARGS_6 lwz 8,40(1); UNDOCARGS_5 - -# if IS_IN (libpthread) -# define CENABLE bl __pthread_enable_asynccancel@local -# define CDISABLE bl __pthread_disable_asynccancel@local -# elif IS_IN (libc) -# define CENABLE bl __libc_enable_asynccancel@local -# define CDISABLE bl __libc_disable_asynccancel@local -# elif IS_IN (librt) -# define CENABLE bl __librt_enable_asynccancel@local -# define CDISABLE bl __librt_disable_asynccancel@local -# else -# error Unsupported library -# endif + mr r9,r8; \ + mr r8,r7; \ + mr r7,r6; \ + mr r6,r5; \ + mr r5,r4; \ + mr r4,r3; \ + li r3,SYS_ify (syscall_name); \ + CANCEL_JUMPTARGET; \ + lwz r0,20(r1); \ + addi r1,r1,16; \ + cfi_adjust_cfa_offset (-16); \ + mtlr r0; \ + cfi_restore (lr); \ + b __syscall_cancel_error@local; + +# undef PSEUDO_RET +# define PSEUDO_RET # ifndef __ASSEMBLER__ -# define SINGLE_THREAD_P \ - __builtin_expect (THREAD_GETMEM (THREAD_SELF, \ - header.multiple_threads) == 0, 1) +# define SINGLE_THREAD_P \ + __builtin_expect (THREAD_GETMEM (THREAD_SELF, \ + header.multiple_threads) == 0, 1) # else -# define SINGLE_THREAD_P \ - lwz 10,MULTIPLE_THREADS_OFFSET(2); \ +# define SINGLE_THREAD_P \ + lwz 10,MULTIPLE_THREADS_OFFSET(2); \ cmpwi 10,0 # endif -#elif !defined __ASSEMBLER__ - -# define SINGLE_THREAD_P (1) -# define NO_CANCELLATION 1 - #endif #ifndef __ASSEMBLER__ # define RTLD_SINGLE_THREAD_P \ __builtin_expect (THREAD_GETMEM (THREAD_SELF, \ header.multiple_threads) == 0, 1) + +static inline +const char * __pthread_get_ip (const ucontext_t *uc) +{ + return (char *)uc->uc_mcontext.uc_regs->gregs[PT_NIP]; +} #endif diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h index dc56bea..46fd267 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h @@ -100,6 +100,14 @@ sc_ret; \ }) +#undef SYSCALL_CANCEL_ERROR +#define SYSCALL_CANCEL_ERROR(err) \ + (err > 0xfffffffffffff000UL) + +#undef SYSCALL_CANCEL_ERRNO +#define SYSCALL_CANCEL_ERRNO(err) \ + (-err) + /* Define a macro which expands inline into the wrapper code for a system call. This use is for internal calls that do not need to handle errors normally. It will never touch errno.