From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by sourceware.org (Postfix) with ESMTPS id 8EE3E3858C53 for ; Mon, 31 Jul 2023 17:19:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8EE3E3858C53 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-oi1-x236.google.com with SMTP id 5614622812f47-3a3efee1d44so3748788b6e.3 for ; Mon, 31 Jul 2023 10:19:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690823947; x=1691428747; 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=tlZKFc1DxEvg/P1hvbw0DyHzcRYUpd8y6i0ROXDr1lPeOrnId1dAlXU89gkyCmCUwQ XgF8ZFymh2rxf/3MsJ3jMR+RRyO6t3z7vRLIbg3gDL46a3ZzjwNxWix/H5v/3+w4GNE4 CZmuQdM/W6CEtETZKo8TjyiRqFWJHuhy5UpHnGSTOwg86crZ6d1Xt7RbeWhlADw9S5we z+YI+qoQA1ILBeha5+Avos6b2+tj27835F/qZXCn2zmpwlfFHQKU8NbiO41EG2xB0naZ AWVYQ2baW25cgab5LHEoAJD4I+RxUKqjcinTWVwjM77QdyNECLmBZ5aJfY+eHTw2+TzP Pfmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690823947; x=1691428747; 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=A/HEg45MRPhKf/NWrAAbpAcBsk3iyFbPsWf8zm7KH4XY8uhypWoU8PeglN1k3AwTYM ebUXoiKwYI9/DBkNrHidokdNGT2Ovaq2e3bXtASa0yHAU7R89XfN+g5LaXGftKm5lbLW mHkiWnecfI1rJqL/aJoF+0cYR6khqVWP2YnZvR6rCBhz4WxgRwTnoLH3XftTpv4mD0er 5l3Xef4VRyfyUgQZ1CeHZkBk5/MfVo27InbBruzntiOcv/ark2RjHS4uSB/d3omXdD2J EGmAFCmJo2wh7V+iRyGwQ5azzqE8frWYVb7ZJxPIihfU1FVTrU0G4q9cIl6pXeT27jOT BOZg== X-Gm-Message-State: ABy/qLY98+AUW26rvpIpEGODIJnukAygRhSfmUTqbbNcRt2FzScdHvrM h8Cx0KG3czFl82Zg7T07gwkE7g7VwIA7ZKjPTRVd6w== X-Google-Smtp-Source: APBJJlFQA2S7xN4rT1nZidVETa3k1KDAFJ5OUO5l6kW+gpFGW994ZnETyySFPCTtFYa2A0vdqJwP6Q== X-Received: by 2002:a05:6808:347:b0:3a7:1e40:6ce9 with SMTP id j7-20020a056808034700b003a71e406ce9mr6813360oie.26.1690823947197; Mon, 31 Jul 2023 10:19:07 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c1:440b:68be:64f1:9a6f:2423]) by smtp.gmail.com with ESMTPSA id k16-20020a05680808d000b003a724566afdsm1560047oij.20.2023.07.31.10.19.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 10:19:06 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Carlos O'Donell Subject: [PATCH 1/2] setjmp: Use BSD sematic as default for setjmp Date: Mon, 31 Jul 2023 14:18:59 -0300 Message-Id: <20230731171900.4065501-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731171900.4065501-1-adhemerval.zanella@linaro.org> References: <20230731171900.4065501-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.8 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