From patchwork Thu Jan 31 17:30:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 217221 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]) by ozlabs.org (Postfix) with SMTP id 122312C02AC for ; Fri, 1 Feb 2013 04:30:55 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1360258256; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: From:To:Subject:Date:Message-ID:User-Agent:MIME-Version: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=xugL+15 Goe+EA3dGGBtCY4H+gjw=; b=yU+ynnOkJZvRLUmyUo4XXfSqH+8rXNwsC32im62 6XZISQ3LOla1JU5XSMcomKwpAyNAoBzj93BMs4N7gjjbsboyNQjBD8PXrh/GwCAa 8H5xbqTSpoyX0oeZpWoLmsg1TTazIFKYWSOkurTgOyVIA8VXiIbOcgmxWp2ipT+G LL7Q= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:X-Received:Received:From:To:Subject:Date:Message-ID:User-Agent:MIME-Version:Content-Type:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=M65LW9ify8paw5+VPGz070AXXo2fjrQ4uolNzj6vIYSlL1I5h+8N+q1rIriyXw D6JKuz+v4EZdSANwTIFThZNRnY1ELAg7LyP/aDUy0iZDbydxf9FZ3hkNQLbMgbFm Ne6Ik6dIv8jau5ZW1lyhqeDk7oJMMKQbDmrVqfYC76V6I=; Received: (qmail 14878 invoked by alias); 31 Jan 2013 17:30:45 -0000 Received: (qmail 14852 invoked by uid 22791); 31 Jan 2013 17:30:43 -0000 X-SWARE-Spam-Status: No, hits=-5.3 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from mail-pb0-f47.google.com (HELO mail-pb0-f47.google.com) (209.85.160.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 31 Jan 2013 17:30:35 +0000 Received: by mail-pb0-f47.google.com with SMTP id rp8so1708888pbb.6 for ; Thu, 31 Jan 2013 09:30:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:subject:date:message-id:user-agent:mime-version :content-type:x-gm-message-state; bh=uC20SU2sGz1fVox/80kg8RGXjO3icKFJ/lHvChoYL8g=; b=AeFLEpAGLRGETBNdWIKX92EjMn2/ZRWizBUDg9e9NmYTLFWzOQsoWG9au1k7OeMjif dxFnSJahpilGTGjYyhWF1RVGtt2+tP+My45E1YRqkLRZ3xumMi0/x1FGIVpu/Zr9fe3K FqCSTg7lFwjIcqWv7pwrur4Pt34xmLS0OYoAtHPi9xmqU7rCHLf2ZMexqUYHG9jiV6M/ xCFqoWG20sihtd1xn+7bp4DVmMknM2TXG6c21Z9oW25soxeJVV5zZSI4CHUuQZJ07Ru5 GvvnhyImILzkLRxYUMz2UZL7r04OtO6wB7rtXtTswt/jGGa9iZUTocpCOo/YGziAiiGj FSHg== X-Received: by 10.68.136.132 with SMTP id qa4mr23859930pbb.166.1359653434474; Thu, 31 Jan 2013 09:30:34 -0800 (PST) Received: from iant-glaptop.google.com ([172.26.54.189]) by mx.google.com with ESMTPS id qh4sm5585729pbb.9.2013.01.31.09.30.32 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 31 Jan 2013 09:30:33 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: libgo patch committed: Block signals when creating new thread Date: Thu, 31 Jan 2013 09:30:30 -0800 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 X-Gm-Message-State: ALoCoQlE/UPZLAvj70fkI1WxUuN3A8GyeNsKvB7XeCqyMtHqAalzdOwhPw/qbz7mpHQr2DjGhUAxTpe2FsiUj2Kn3jMS7MJKoGukYz3QUlDlqVRsUIaSbS8Fxeh1TvwZ7Myzna0M/nGewsCQ0fupJt2+yX0BL6k7fzcRwkhKzSFaozVaFye9WYiU1d0YHpMmtFAWEvl/xJwh X-IsSubscribed: yes 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 This patch to libgo disables signals while creating a new thread. Otherwise if a signal comes in between the time the thread starts and the time the thread initializes its m and g TLS variables, the program will crash with an error "signal received on thread not created by Go." Signals are already enabled by the thread after it has been initialized. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r 4716407240c2 libgo/runtime/proc.c --- a/libgo/runtime/proc.c Thu Jan 31 08:39:01 2013 -0800 +++ b/libgo/runtime/proc.c Thu Jan 31 09:24:12 2013 -0800 @@ -3,6 +3,7 @@ // license that can be found in the LICENSE file. #include +#include #include #include #include @@ -1217,6 +1218,9 @@ pthread_attr_t attr; pthread_t tid; size_t stacksize; + sigset_t clear; + sigset_t old; + int ret; #if 0 static const Type *mtype; // The Go type M @@ -1249,7 +1253,15 @@ if(pthread_attr_setstacksize(&attr, stacksize) != 0) runtime_throw("pthread_attr_setstacksize"); - if(pthread_create(&tid, &attr, runtime_mstart, mp) != 0) + // Block signals during pthread_create so that the new thread + // starts with signals disabled. It will enable them in minit. + sigfillset(&clear); + sigemptyset(&old); + sigprocmask(SIG_BLOCK, &clear, &old); + ret = pthread_create(&tid, &attr, runtime_mstart, mp); + sigprocmask(SIG_SETMASK, &old, nil); + + if (ret != 0) runtime_throw("pthread_create"); return mp;