12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- #include <setjmp.h>
- #include "pthread.h"
- #include "internals.h"
- #include <bits/stackinfo.h>
- #include <jmpbuf-unwind.h>
- 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 siglongjmp(sigjmp_buf env, int val)
- {
- pthread_cleanup_upto(env->__jmpbuf);
- __libc_siglongjmp(env, val);
- }
- void longjmp(jmp_buf env, int val)
- {
- pthread_cleanup_upto(env->__jmpbuf);
- __libc_longjmp(env, val);
- }
|