From patchwork Thu Jul 31 21:07:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roland McGrath X-Patchwork-Id: 375437 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 C7D5D140190 for ; Fri, 1 Aug 2014 07:07:42 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:content-type :content-transfer-encoding:from:to:subject:message-id:date; q= dns; s=default; b=arFF0SZ1/KoJp6BGIJE806EFN/XoHsCOJRHWhMWAimBR0B 1X9L9kT4/0IxQiC1XBbxAwo6Jj4yX4kCxAF6G06zqYQUK0x4smBW/pPDvKsFke8+ f3/wUm9ayldmGYV1bB+Bg00rWxN3btjUjIczfZMONht+CXL76g9L64FLZEmFo= 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:mime-version:content-type :content-transfer-encoding:from:to:subject:message-id:date; s= default; bh=HG8r+kcBvQg/U0Kd8TsQE02blrU=; b=CLh6ZDV7QgfprP2PJVuu AvFNOvdbKT2DBVvK0dlmQL8OgVPFD6CfWHnq1G/wV1QB9/5ksuIB85FxuohjAErH +7ZVO8xbj6CtimAjRwbJ7nlVS+pCS6JQh0o/s86RTzsGXwipVelu2lFTjMmAPij+ ThShUob9aMXlVJEw4olnPOY= Received: (qmail 24024 invoked by alias); 31 Jul 2014 21:07:36 -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 24008 invoked by uid 89); 31 Jul 2014 21:07:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: topped-with-meat.com MIME-Version: 1.0 From: Roland McGrath To: "GNU C. Library" Subject: [COMMITTED PATCH] Add __safe_fatal and use it in __pthread_unwind forwarder fallback. Message-Id: <20140731210732.0AC5B2C39A3@topped-with-meat.com> Date: Thu, 31 Jul 2014 14:07:31 -0700 (PDT) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=SvUDtp+0 c=1 sm=1 tr=0 a=WkljmVdYkabdwxfqvArNOQ==:117 a=14OXPxybAAAA:8 a=SsHV0sN9K-0A:10 a=ggS3jnvFtpQA:10 a=Z6MIti7PxpgA:10 a=kj9zAlcOel0A:10 a=hOe2yjtxAAAA:8 a=mDV3o1hIAAAA:8 a=yfY4x9yJdBihe_ZNVxkA:9 a=OWA-pVM-uoiayO2U:21 a=nr4XLX63BTLA3ogT:21 a=CjuIK1q_8ugA:10 This both removes a Linuxism from nptl/forward.c and makes the code actually work. The old code was a bogus attempt at a one-argument kill system call, which means it actually attempted to send a random register value as signal number, to PID 9. The new code (for Linux) takes care to make a getpid system call and then a proper kill system call. Build-tested and eyeballed code on x86_64-linux-gnu and arm-linux-gnueabihf. * sysdeps/generic/safe-fatal.h: New file. * sysdeps/unix/sysv/linux/safe-fatal.h: New file. * nptl/forward.c: Include it. (__pthread_unwind): Use __safe_fatal as default action, rather than a bogus use of INTERNAL_SYSCALL that could never work. --- a/nptl/forward.c +++ b/nptl/forward.c @@ -23,7 +23,7 @@ #include #include -#include +#include /* Pointers to the libc functions. */ @@ -202,11 +202,8 @@ FORWARD (pthread_setcancelstate, (int state, int *oldstate), (state, oldstate), FORWARD (pthread_setcanceltype, (int type, int *oldtype), (type, oldtype), 0) -FORWARD_NORETURN(__pthread_unwind, - void attribute_hidden __attribute ((noreturn)) __cleanup_fct_attribute - attribute_compat_text_section, - (__pthread_unwind_buf_t *buf), (buf), { - /* We cannot call abort() here. */ - INTERNAL_SYSCALL_DECL (err); - INTERNAL_SYSCALL (kill, err, 1, SIGKILL); - }) +FORWARD_NORETURN (__pthread_unwind, + void attribute_hidden __attribute ((noreturn)) + __cleanup_fct_attribute attribute_compat_text_section, + (__pthread_unwind_buf_t *buf), (buf), + __safe_fatal ()) --- /dev/null +++ b/sysdeps/generic/safe-fatal.h @@ -0,0 +1,37 @@ +/* Crash the process immediately, without possibility of deadlock. Generic. + Copyright (C) 2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _SAFE_FATAL_H +#define _SAFE_FATAL_H 1 + +#include + +static inline void +__safe_fatal (void) +{ +#ifdef ABORT_INSTRUCTION + /* This is not guaranteed to be free from the possibility of deadlock, + since it might generate a signal that can be caught. But it's better + than nothing. */ + ABORT_INSTRUCTION; +#else +# error Need an OS-specific or machine-specific safe-fatal.h +#endif +} + +#endif /* safe-fatal.h */ --- /dev/null +++ b/sysdeps/unix/sysv/linux/safe-fatal.h @@ -0,0 +1,33 @@ +/* Crash the process immediately, without possibility of deadlock. Linux. + Copyright (C) 2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _SAFE_FATAL_H +#define _SAFE_FATAL_H 1 + +#include +#include + +static inline void +__safe_fatal (void) +{ + INTERNAL_SYSCALL_DECL (err); + pid_t self = INTERNAL_SYSCALL (getpid, err, 0); + INTERNAL_SYSCALL (kill, err, 2, self, SIGKILL); +} + +#endif /* safe-fatal.h */