From patchwork Tue Dec 8 18:18:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 1412856 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=g88HKrXC; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cr7jV5vgsz9s1l for ; Wed, 9 Dec 2020 05:18:50 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DC8273851C31; Tue, 8 Dec 2020 18:18:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC8273851C31 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1607451527; bh=xEoxKYDwsvbmAoCdwdGTak5Ku4PS3f175cgvz5keNzo=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=g88HKrXCAsIxMW+S/DgwWJ2IDSyBALkDVyHJUF/uGwuT/U0R7Uen9OIMWm0/EQpdD XMNye/4Qi+6hUw2sKFArgHrEX9CkxZJw62kbla9Oj5f1+qaNVQsv3x47YfxkkXXDph 8xDY1AT9VFuPS5CnqKwsYwJn7jGVfd3Rmmfkm6EY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by sourceware.org (Postfix) with ESMTPS id 9183D3857C70 for ; Tue, 8 Dec 2020 18:18:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9183D3857C70 Received: by mail-ej1-x636.google.com with SMTP id ce23so22187464ejb.8 for ; Tue, 08 Dec 2020 10:18:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=xEoxKYDwsvbmAoCdwdGTak5Ku4PS3f175cgvz5keNzo=; b=d+yS+ZbEaiZvvVemhmgh8drZrSKoRtZFeaNP1Y9zhS/jX05zJBQmGZYFBd1n+4dJeJ P6RMxC5bTAgBU8kY08lb6g5Th1dFoU2YQIKHQiVipUKM9PdNwLPrNqMXoe6HeLTAqWi4 LKsToL2YtSu12/Nua89gC7kYi60KJVWsZdCg/pDonX9oma0nX0ti1INdavd5lstU6UGL 7FIbbvtS4iqbXL5OjeMmzB7pmK2c/E75d6xWTq7LutB+BGNStPmj3YTpNXoGlFgX0eR7 sUYFQ8uu0gdOiMjWBLaZgk8pm1FirSBgGCQr8Eqai5S//1BRPXAyeQ8tspJAmgmZGRNB VzPw== X-Gm-Message-State: AOAM533v4sSfRx0TBPbWN6qX1F3Evn3TR2qcVgjgim45v//SyWHrymGU 5iuyH4/br5/xxZdZ/flTrxLYVQ5SdXTl41yk1f89MV2Kp1r7pA== X-Google-Smtp-Source: ABdhPJw8nAn+y4fvh+HV1AH6DoNUQNy2bwZ6XtpEDZN0Ai2q9ZBOb+GXTtc9Or6nwj/AW7VDcSx0cm15Wk21O4Q/XLI= X-Received: by 2002:a17:907:20dc:: with SMTP id qq28mr23949031ejb.403.1607451521119; Tue, 08 Dec 2020 10:18:41 -0800 (PST) MIME-Version: 1.0 Date: Tue, 8 Dec 2020 10:18:29 -0800 Message-ID: Subject: libgcc patch committed: Block signals when release split-stack memory To: gcc-patches X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ian Lance Taylor via Gcc-patches From: Ian Lance Taylor Reply-To: Ian Lance Taylor Cc: gofrontend-dev Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This patch to libgcc blocks signals when releasing split-stack memory due to a thread exiting. Without this, if a signal arrives, the signal handler may try to split the stack itself, which won't work as the data structures won't be in a stable state. We just leave signals blocked while completing the exit; this should do no harm, and prevents a signal handler from jumping in and allocating new split-stack structures which will then never be freed. I will shortly check in a test for this case, as part of updating libgo to the Go 1.15.6 release. Bootstrapped this patch and ran Go and split-stack tests on x86_64-pc-linux-gnu. Committed to mainline. Ian * generic-morestack-thread.c (free_segments): Block signals during thread exit. f41dd93ade24f22f8cd1863129ab20c821000134 diff --git a/libgcc/generic-morestack-thread.c b/libgcc/generic-morestack-thread.c index 83a65501272..fd391bb2e1f 100644 --- a/libgcc/generic-morestack-thread.c +++ b/libgcc/generic-morestack-thread.c @@ -38,6 +38,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #ifndef inhibit_libc #include +#include #include #include "generic-morestack.h" @@ -54,6 +55,9 @@ extern int pthread_key_create (pthread_key_t *, void (*) (void *)) extern int pthread_setspecific (pthread_key_t, const void *) __attribute__ ((weak)); +extern int pthread_sigmask (int, const sigset_t *, sigset_t *) + __attribute__ ((weak)); + /* The key for the list of stack segments to free when the thread exits. This is created by pthread_key_create. */ @@ -70,6 +74,16 @@ static pthread_once_t create_key_once = PTHREAD_ONCE_INIT; static void free_segments (void* arg) { + /* We must block signals in case the signal handler tries to split + the stack. We leave them blocked while the thread exits. */ + if (pthread_sigmask) + { + sigset_t mask; + + sigfillset (&mask); + pthread_sigmask (SIG_BLOCK, &mask, NULL); + } + __morestack_release_segments ((struct stack_segment **) arg, 1); }