summaryrefslogtreecommitdiff
path: root/nptl/unwind.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-11-06 04:29:42 +0000
committerUlrich Drepper <drepper@redhat.com>2003-11-06 04:29:42 +0000
commit44e941492d0dcefa98e0b7686ecfba3f39ded173 (patch)
treec70e0334dc36dc62a595a7a2fcf1a543b0dcf8f1 /nptl/unwind.c
parentc28422b575d8399fc3d5ce8e50cbde83c58b647c (diff)
Update.
2003-11-05 Jakub Jelinek <jakub@redhat.com> * unwind.c (FRAME_LEFT): Define. (unwind_stop): Handle old style cleanups here. (__pthread_unwind): Handle old style cleanups only if !HAVE_FORCED_UNWIND. * Makefile (tests): Add tst-cleanup4 and tst-cleanupx4. (CFLAGS-tst-cleanupx4.c): Add -fexceptions. ($(objpfx)tst-cleanup4): Depend on $(objpfx)tst-cleanup4aux.o. ($(objpfx)tst-cleanupx4): Likewise. * tst-cleanup4.c: New test. * tst-cleanup4aux.c: New. * tst-cleanupx4.c: New test.
Diffstat (limited to 'nptl/unwind.c')
-rw-r--r--nptl/unwind.c58
1 files changed, 50 insertions, 8 deletions
diff --git a/nptl/unwind.c b/nptl/unwind.c
index a879e9297f..8013b5a829 100644
--- a/nptl/unwind.c
+++ b/nptl/unwind.c
@@ -27,6 +27,14 @@
#ifdef HAVE_FORCED_UNWIND
+#ifdef _STACK_GROWS_DOWN
+# define FRAME_LEFT(frame, other) ((char *) frame >= (char *) other)
+#elif _STACK_GROWS_UP
+# define FRAME_LEFT(frame, other) ((char *) frame <= (char *) other)
+#else
+# error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
+#endif
+
static _Unwind_Reason_Code
unwind_stop (int version, _Unwind_Action actions,
_Unwind_Exception_Class exc_class,
@@ -34,6 +42,9 @@ unwind_stop (int version, _Unwind_Action actions,
struct _Unwind_Context *context, void *stop_parameter)
{
struct pthread_unwind_buf *buf = stop_parameter;
+ struct pthread *self = THREAD_SELF;
+ struct _pthread_cleanup_buffer *curp = THREAD_GETMEM (self, cleanup);
+ int do_longjump = 0;
/* Do longjmp if we're at "end of stack", aka "end of unwind data".
We assume there are only C frame without unwind data in between
@@ -42,6 +53,37 @@ unwind_stop (int version, _Unwind_Action actions,
previous frame. */
if ((actions & _UA_END_OF_STACK)
|| ! _JMPBUF_CFA_UNWINDS (buf->cancel_jmp_buf[0].jmp_buf, context))
+ do_longjump = 1;
+
+ if (__builtin_expect (curp != NULL, 0))
+ {
+ /* Handle the compatibility stuff. Execute all handlers
+ registered with the old method which would be unwound by this
+ step. */
+ struct _pthread_cleanup_buffer *oldp = buf->priv.data.cleanup;
+ void *cfa = (void *) _Unwind_GetCFA (context);
+
+ if (curp != oldp && (do_longjump || FRAME_LEFT (cfa, curp)))
+ {
+ do
+ {
+ /* Pointer to the next element. */
+ struct _pthread_cleanup_buffer *nextp = curp->__prev;
+
+ /* Call the handler. */
+ curp->__routine (curp->__arg);
+
+ /* To the next. */
+ curp = nextp;
+ }
+ while (curp != oldp && (do_longjump || FRAME_LEFT (cfa, curp)));
+
+ /* Mark the current element as handled. */
+ THREAD_SETMEM (self, cleanup, curp);
+ }
+ }
+
+ if (do_longjump)
__libc_longjmp ((struct __jmp_buf_tag *) buf->cancel_jmp_buf, 1);
return _URC_NO_REASON;
@@ -70,6 +112,14 @@ __pthread_unwind (__pthread_unwind_buf_t *buf)
struct pthread_unwind_buf *ibuf = (struct pthread_unwind_buf *) buf;
struct pthread *self = THREAD_SELF;
+#ifdef HAVE_FORCED_UNWIND
+ /* This is not a catchable exception, so don't provide any details about
+ the exception type. We do need to initialize the field though. */
+ THREAD_SETMEM (self, exc.exception_class, 0);
+ THREAD_SETMEM (self, exc.exception_cleanup, unwind_cleanup);
+
+ _Unwind_ForcedUnwind (&self->exc, unwind_stop, ibuf);
+#else
/* Handle the compatibility stuff first. Execute all handlers
registered with the old method. We don't execute them in order,
instead, they will run first. */
@@ -95,14 +145,6 @@ __pthread_unwind (__pthread_unwind_buf_t *buf)
THREAD_SETMEM (self, cleanup, curp);
}
-#ifdef HAVE_FORCED_UNWIND
- /* This is not a catchable exception, so don't provide any details about
- the exception type. We do need to initialize the field though. */
- THREAD_SETMEM (self, exc.exception_class, 0);
- THREAD_SETMEM (self, exc.exception_cleanup, unwind_cleanup);
-
- _Unwind_ForcedUnwind (&self->exc, unwind_stop, ibuf);
-#else
/* We simply jump to the registered setjmp buffer. */
__libc_longjmp ((struct __jmp_buf_tag *) ibuf->cancel_jmp_buf, 1);
#endif