123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- #include <setjmp.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include "pthreadP.h"
- #include <jmpbuf-unwind.h>
- #ifdef HAVE_FORCED_UNWIND
- #ifdef _STACK_GROWS_DOWN
- # define FRAME_LEFT(frame, other, adj) \
- ((uintptr_t) frame - adj >= (uintptr_t) other - adj)
- #elif defined _STACK_GROWS_UP
- # define FRAME_LEFT(frame, other, adj) \
- ((uintptr_t) frame - adj <= (uintptr_t) other - adj)
- #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,
- struct _Unwind_Exception *exc_obj,
- 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;
-
- uintptr_t adj = (uintptr_t) self->stackblock + self->stackblock_size;
-
- if ((actions & _UA_END_OF_STACK)
- || ! _JMPBUF_CFA_UNWINDS_ADJ (buf->cancel_jmp_buf[0].jmp_buf, context,
- adj))
- do_longjump = 1;
- if (__builtin_expect (curp != NULL, 0))
- {
-
- struct _pthread_cleanup_buffer *oldp = buf->priv.data.cleanup;
- void *cfa = (void *) _Unwind_GetCFA (context);
- if (curp != oldp && (do_longjump || FRAME_LEFT (cfa, curp, adj)))
- {
- do
- {
-
- struct _pthread_cleanup_buffer *nextp = curp->__prev;
-
- curp->__routine (curp->__arg);
-
- curp = nextp;
- }
- while (curp != oldp
- && (do_longjump || FRAME_LEFT (cfa, curp, adj)));
-
- THREAD_SETMEM (self, cleanup, curp);
- }
- }
- if (do_longjump)
- __libc_unwind_longjmp ((struct __jmp_buf_tag *) buf->cancel_jmp_buf, 1);
- return _URC_NO_REASON;
- }
- static attribute_noreturn void
- unwind_cleanup (_Unwind_Reason_Code reason, struct _Unwind_Exception *exc)
- {
-
- # define STR_N_LEN(str) str, strlen (str)
- INTERNAL_SYSCALL_DECL (err);
- INTERNAL_SYSCALL (write, err, 3, STDERR_FILENO,
- STR_N_LEN ("FATAL: exception not rethrown\n"));
- abort ();
- }
- #endif
- void
- __cleanup_fct_attribute __attribute ((noreturn))
- #if !defined SHARED && !defined IS_IN_libpthread
- weak_function
- #endif
- __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
-
- THREAD_SETMEM (self, exc.exception_class, 0);
- THREAD_SETMEM (self, exc.exception_cleanup, unwind_cleanup);
- _Unwind_ForcedUnwind (&self->exc, unwind_stop, ibuf);
- #else
-
- struct _pthread_cleanup_buffer *oldp = ibuf->priv.data.cleanup;
- struct _pthread_cleanup_buffer *curp = THREAD_GETMEM (self, cleanup);
- if (curp != oldp)
- {
- do
- {
-
- struct _pthread_cleanup_buffer *nextp = curp->__prev;
-
- curp->__routine (curp->__arg);
-
- curp = nextp;
- }
- while (curp != oldp);
-
- THREAD_SETMEM (self, cleanup, curp);
- }
-
- __libc_unwind_longjmp ((struct __jmp_buf_tag *) ibuf->cancel_jmp_buf, 1);
- #endif
-
-
- abort ();
- }
- hidden_def (__pthread_unwind)
- void
- __cleanup_fct_attribute __attribute ((noreturn))
- __pthread_unwind_next (__pthread_unwind_buf_t *buf)
- {
- struct pthread_unwind_buf *ibuf = (struct pthread_unwind_buf *) buf;
- __pthread_unwind ((__pthread_unwind_buf_t *) ibuf->priv.data.prev);
- }
- hidden_def (__pthread_unwind_next)
|