From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id 8113C3858D38 for ; Thu, 3 Aug 2023 17:34:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8113C3858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-6bb29b9044dso1171404a34.1 for ; Thu, 03 Aug 2023 10:34:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691084083; x=1691688883; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=QMIazJYqVuyucDGD7gnDiVlujQudCH0UCwV20cgOTbU=; b=E6vfP3LX1/BlsJ4+8DU8DE+JazCYPiT5enAev28O+/SfKPtewFJ6DUEvL8A+Oie7Ri dL6k3yfDGqJKzcpk3uL1rWa4iYuZbKMLzShfCj7XRZENNEyiiM3dqjWI8oUhpJir4bSx hDYsykc95ZewFADpAMYJSJYAI/71t3YHuQLUNQo9qpS+5exhqH86Q9W9veZIX1fmiAsD CH9Kxdzf+v7JwW5JKLUQ/d6YkYMXmyIGwybmZHLqKKETbiiNP/4Xo1rujETbyEN8eYK0 TaAcqB4emM9hC91hiShkF+Q00COamWEAfES8nG+NadbV+wIxXThcsJgloIFxk744RasR r3AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691084083; x=1691688883; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QMIazJYqVuyucDGD7gnDiVlujQudCH0UCwV20cgOTbU=; b=PQMBQY+76TDh2dgzs4KfuYJXi+Sz1G7eBjxke0Lc1rulmor1V8DDB1eofiJ7n3HL0K Kwaw5+l3dkzERQGO7phFlpQv9ox/jWWlDnKWhVTnGQoFUGe/XZzVvAC7MQgFoCvp0MVs RfrmUp9if66G1NX7Hi7AEUvMotqSC0yjNuBzhivcHoErhqSjcFScocVdZ/Sp8dPyD14m ZoJMz9mFb2GRFmZx6Iyo8Gsh0+iENthIZqG/Mlr8E3NJKwingOpucAOFRUHXilu1H0j9 Vb/T32aHq8+4PspIlbbNG4lQpiVkym2DuU4kTjOZvHiUX7zbi7ObXlBrnpBgzEdf3PWF 6vSQ== X-Gm-Message-State: ABy/qLYF6cuu8EttJrj7dkgOmXml9cWT7CYLCvC0jJCXjdFtftHaLmF6 4Eso43Q/I5gylNvO438m9bfOlylvIt+lMeY2VGXaGw== X-Google-Smtp-Source: APBJJlEaUdxe6CEPo14TmbwsgQp8Jg6Jskt8LVFFzPAvGOMYa/QPouoDhzpXwjD9XzlLf5RGViDR5A== X-Received: by 2002:a05:6830:610:b0:6bc:bb29:a36e with SMTP id w16-20020a056830061000b006bcbb29a36emr5846714oti.29.1691084083200; Thu, 03 Aug 2023 10:34:43 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c1:9aa9:6a6b:da4a:374c:385a]) by smtp.gmail.com with ESMTPSA id l10-20020a9d7a8a000000b006b884bbb4f3sm215747otn.26.2023.08.03.10.34.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 10:34:42 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Carlos O'Donell , Florian Weimer Subject: [PATCH v2 1/2] setjmp: Use BSD sematic as default for setjmp Date: Thu, 3 Aug 2023 14:34:35 -0300 Message-Id: <20230803173436.4146900-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230803173436.4146900-1-adhemerval.zanella@linaro.org> References: <20230803173436.4146900-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: POSIX relaxed the relation of setjmp/longjmp and the signal mask save/restore, meaning that setjmp does not require to be routed to _setjmp to be standard compliant. This is done to avoid breakage of SIGABRT handlers, since to fully make abort AS-safe, it is required to remove the recurisve lock used to unblock SIGABRT prior raised the signal. Also, it allows caller to actually use setjmp, since from 7011c2622fe3e10a29dbe74f06aaebd07710127d the symbol is unconditionally routed to _setjmp. Checked on x86_64-linux-gnu. --- manual/setjmp.texi | 14 ++++---------- nptl/pthread_create.c | 3 ++- setjmp/setjmp.h | 5 ----- sysdeps/nptl/libc_start_call_main.h | 3 ++- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/manual/setjmp.texi b/manual/setjmp.texi index 7092a0dde2..f2d82a2f33 100644 --- a/manual/setjmp.texi +++ b/manual/setjmp.texi @@ -189,16 +189,10 @@ them @code{volatile}. @section Non-Local Exits and Signals In BSD Unix systems, @code{setjmp} and @code{longjmp} also save and -restore the set of blocked signals; see @ref{Blocking Signals}. However, -the POSIX.1 standard requires @code{setjmp} and @code{longjmp} not to -change the set of blocked signals, and provides an additional pair of -functions (@code{sigsetjmp} and @code{siglongjmp}) to get the BSD -behavior. - -The behavior of @code{setjmp} and @code{longjmp} in @theglibc{} is -controlled by feature test macros; see @ref{Feature Test Macros}. The -default in @theglibc{} is the POSIX.1 behavior rather than the BSD -behavior. +restore the set of blocked signals; see @ref{Blocking Signals}, while +on @w{System V} they will not. POSIX does not specify the relation of +@code{setjmp} and @code{longjmp} to signal mask. The default in +@theglibc{} is the BSD behavior. The facilities in this section are declared in the header file @file{setjmp.h}. diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c index 1ac8862ed2..3d7dfac198 100644 --- a/nptl/pthread_create.c +++ b/nptl/pthread_create.c @@ -399,7 +399,8 @@ start_thread (void *arg) the saved signal mask), so that is a false positive. */ DIAG_IGNORE_NEEDS_COMMENT (11, "-Wstringop-overflow="); #endif - not_first_call = setjmp ((struct __jmp_buf_tag *) unwind_buf.cancel_jmp_buf); + not_first_call = __sigsetjmp ( + (struct __jmp_buf_tag *) unwind_buf.cancel_jmp_buf, 0); DIAG_POP_NEEDS_COMMENT; /* No previous handlers. NB: This must be done after setjmp since the diff --git a/setjmp/setjmp.h b/setjmp/setjmp.h index 3cdc2dfcfb..53edbba92b 100644 --- a/setjmp/setjmp.h +++ b/setjmp/setjmp.h @@ -44,11 +44,6 @@ extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) __THROWNL Return 0. */ extern int _setjmp (struct __jmp_buf_tag __env[1]) __THROWNL; -/* Do not save the signal mask. This is equivalent to the `_setjmp' - BSD function. */ -#define setjmp(env) _setjmp (env) - - /* Jump to the environment saved in ENV, making the `setjmp' call there return VAL, or 1 if VAL is 0. */ extern void longjmp (struct __jmp_buf_tag __env[1], int __val) diff --git a/sysdeps/nptl/libc_start_call_main.h b/sysdeps/nptl/libc_start_call_main.h index a55e3df013..984e859550 100644 --- a/sysdeps/nptl/libc_start_call_main.h +++ b/sysdeps/nptl/libc_start_call_main.h @@ -41,7 +41,8 @@ __libc_start_call_main (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), the saved signal mask), so that is a false positive. */ DIAG_IGNORE_NEEDS_COMMENT (11, "-Wstringop-overflow="); #endif - not_first_call = setjmp ((struct __jmp_buf_tag *) unwind_buf.cancel_jmp_buf); + not_first_call = __sigsetjmp ( + (struct __jmp_buf_tag *) unwind_buf.cancel_jmp_buf, 0); DIAG_POP_NEEDS_COMMENT; if (__glibc_likely (! not_first_call)) { -- 2.34.1