aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2023-07-31 09:46:52 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2024-06-19 09:05:43 -0300
commitc49e66c7e507f2d37c4725ce4680f19179cfa44e (patch)
tree3b3c501f00e50015225ab9ff1ad28288be4004c9
parent19f6d6a480b29912022184f31f11dbf1c201a86b (diff)
downloadglibc-c49e66c7e507f2d37c4725ce4680f19179cfa44e.zip
glibc-c49e66c7e507f2d37c4725ce4680f19179cfa44e.tar.gz
glibc-c49e66c7e507f2d37c4725ce4680f19179cfa44e.tar.bz2
setjmp: Use BSD sematic as default for setjmp
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.
-rw-r--r--manual/setjmp.texi14
-rw-r--r--nptl/pthread_create.c3
-rw-r--r--setjmp/setjmp.h5
-rw-r--r--sysdeps/nptl/libc_start_call_main.h3
4 files changed, 8 insertions, 17 deletions
diff --git a/manual/setjmp.texi b/manual/setjmp.texi
index 7092a0d..f2d82a2 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 1d3665d..527cb90 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -402,7 +402,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 1309c62..98efa3e 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 26ac8dd..c41ca68 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))
{