diff options
author | Jakub Jelinek <jakub@redhat.com> | 2021-03-04 15:15:33 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2021-03-04 15:15:33 +0100 |
commit | f0419e6a10740a672b28e112c409ae24f5e890ab (patch) | |
tree | 48034df63bcf917ba4a4b59c6c9238798e67e233 /nptl/tst-once5.cc | |
parent | 82215c1e251cf9a4668608974784c412d09c7ccd (diff) | |
download | glibc-f0419e6a10740a672b28e112c409ae24f5e890ab.tar.gz glibc-f0419e6a10740a672b28e112c409ae24f5e890ab.tar.xz glibc-f0419e6a10740a672b28e112c409ae24f5e890ab.zip |
[PATCH] pthread_once hangs when init routine throws an exception [BZ #18435]
This is another attempt at making pthread_once handle throwing exceptions from the init routine callback. As the new testcases show, just switching to the cleanup attribute based cleanup does fix the tst-once5 test, but breaks the new tst-oncey3 test. That is because when throwing exceptions, only the unwind info registered cleanups (i.e. C++ destructors or cleanup attribute), when cancelling threads and there has been unwind info from the cancellation point up to whatever needs cleanup both unwind info registered cleanups and THREAD_SETMEM (self, cleanup, ...) registered cleanups are invoked, but once we hit some frame with no unwind info, only the THREAD_SETMEM (self, cleanup, ...) registered cleanups are invoked. So, to stay fully backwards compatible (allow init routines without unwind info which encounter cancellation points) and handle exception throwing we actually need to register the pthread_once cleanups in both unwind info and in the THREAD_SETMEM (self, cleanup, ...) way. If an exception is thrown, only the former will happen and we in that case need to also unregister the THREAD_SETMEM (self, cleanup, ...) registered handler, because otherwise after catching the exception the user code could call deeper into the stack some cancellation point, get cancelled and then a stale cleanup handler would clobber stack and probably crash. If a thread calling init routine is cancelled and unwind info ends before the pthread_once frame, it will be cleaned up through self->cleanup as before. And if unwind info is present, unwind_stop first calls the self->cleanup registered handler for the frame, then it will call the unwind info registered handler but that will already see __do_it == 0 and do nothing.
Diffstat (limited to 'nptl/tst-once5.cc')
-rw-r--r-- | nptl/tst-once5.cc | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/nptl/tst-once5.cc b/nptl/tst-once5.cc index b797ab3562..60fe1ef820 100644 --- a/nptl/tst-once5.cc +++ b/nptl/tst-once5.cc @@ -59,7 +59,7 @@ do_test (void) " throwing an exception", stderr); } catch (OnceException) { - if (1 < niter) + if (niter > 1) fputs ("pthread_once unexpectedly threw", stderr); result = 0; } @@ -75,7 +75,5 @@ do_test (void) return result; } -// The test currently hangs and is XFAILed. Reduce the timeout. -#define TIMEOUT 1 #define TEST_FUNCTION do_test () #include "../test-skeleton.c" |