1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #include <setjmp.h>
- #include "pthread.h"
- #include "internals.h"
- #include <bits/stackinfo.h>
- extern __typeof(siglongjmp) __libc_siglongjmp attribute_noreturn;
- extern __typeof(longjmp) __libc_longjmp attribute_noreturn;
- static void pthread_cleanup_upto(__jmp_buf target)
- {
- pthread_descr self = thread_self();
- struct _pthread_cleanup_buffer * c;
- char *currentframe = CURRENT_STACK_FRAME;
- for (c = THREAD_GETMEM(self, p_cleanup);
- c != NULL && _JMPBUF_UNWINDS(target, c);
- c = c->__prev)
- {
- #ifdef _STACK_GROWS_DOWN
- if ((char *) c <= currentframe)
- {
- c = NULL;
- break;
- }
- #elif defined _STACK_GROWS_UP
- if ((char *) c >= currentframe)
- {
- c = NULL;
- break;
- }
- #else
- # error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
- #endif
- c->__routine(c->__arg);
- }
- THREAD_SETMEM(self, p_cleanup, c);
- if (THREAD_GETMEM(self, p_in_sighandler)
- && _JMPBUF_UNWINDS(target, THREAD_GETMEM(self, p_in_sighandler)))
- THREAD_SETMEM(self, p_in_sighandler, NULL);
- }
- void attribute_noreturn siglongjmp(sigjmp_buf env, int val)
- {
- pthread_cleanup_upto(env->__jmpbuf);
- __libc_siglongjmp(env, val);
- }
- void attribute_noreturn longjmp(jmp_buf env, int val)
- {
- pthread_cleanup_upto(env->__jmpbuf);
- __libc_longjmp(env, val);
- }
|