From 74604ed9c419ab380cacaaeb78e4c26f9f37e0ad Mon Sep 17 00:00:00 2001 From: davidxu Date: Sat, 25 Sep 2010 01:57:47 +0000 Subject: To support stack unwinding for cancellation points, add -fexceptions flag for them, two functions _pthread_cancel_enter and _pthread_cancel_leave are added to let thread enter and leave a cancellation point, it also makes it possible that other functions can be cancellation points in libraries without having to be rewritten in libthr. --- lib/libthr/Makefile | 4 +--- lib/libthr/pthread.map | 2 ++ lib/libthr/thread/thr_cancel.c | 12 ++++++++++++ lib/libthr/thread/thr_init.c | 4 +++- lib/libthr/thread/thr_private.h | 3 ++- 5 files changed, 20 insertions(+), 5 deletions(-) (limited to 'lib/libthr') diff --git a/lib/libthr/Makefile b/lib/libthr/Makefile index 8b7af3a..a51b446 100644 --- a/lib/libthr/Makefile +++ b/lib/libthr/Makefile @@ -26,9 +26,7 @@ CFLAGS+=-I${.CURDIR}/../../libexec/rtld-elf/${MACHINE_CPUARCH} CFLAGS+=-I${.CURDIR}/../libthread_db CFLAGS+=-Winline -LIBTHR_UNWIND_STACK=yes - -.ifdef LIBTHR_UNWIND_STACK +.ifndef NO_THREAD_UNWIND_STACK CFLAGS+=-I${.CURDIR}/../../contrib/gcc -fexceptions CFLAGS+=-D_PTHREAD_FORCED_UNWIND .endif diff --git a/lib/libthr/pthread.map b/lib/libthr/pthread.map index bcb5c08..5e36239 100644 --- a/lib/libthr/pthread.map +++ b/lib/libthr/pthread.map @@ -246,6 +246,8 @@ FBSDprivate_1.0 { _pthread_attr_setstackaddr; _pthread_attr_setstacksize; _pthread_cancel; + _pthread_cancel_enter; + _pthread_cancel_leave; _pthread_cleanup_pop; _pthread_cleanup_push; _pthread_cond_broadcast; diff --git a/lib/libthr/thread/thr_cancel.c b/lib/libthr/thread/thr_cancel.c index cd456b7..89f0ee1 100644 --- a/lib/libthr/thread/thr_cancel.c +++ b/lib/libthr/thread/thr_cancel.c @@ -162,3 +162,15 @@ _thr_cancel_leave(struct pthread *curthread, int maycancel) !THR_IN_CRITICAL(curthread) && maycancel)) _pthread_exit(PTHREAD_CANCELED); } + +void +_pthread_cancel_enter(int maycancel) +{ + _thr_cancel_enter2(_get_curthread(), maycancel); +} + +void +_pthread_cancel_leave(int maycancel) +{ + _thr_cancel_leave(_get_curthread(), maycancel); +} diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c index 56541a8..e8a01d3 100644 --- a/lib/libthr/thread/thr_init.c +++ b/lib/libthr/thread/thr_init.c @@ -248,7 +248,9 @@ static pthread_func_t jmp_table[][2] = { {DUAL_ENTRY(_pthread_sigmask)}, /* PJT_SIGMASK */ {DUAL_ENTRY(_pthread_testcancel)}, /* PJT_TESTCANCEL */ {DUAL_ENTRY(__pthread_cleanup_pop_imp)},/* PJT_CLEANUP_POP_IMP */ - {DUAL_ENTRY(__pthread_cleanup_push_imp)}/* PJT_CLEANUP_PUSH_IMP */ + {DUAL_ENTRY(__pthread_cleanup_push_imp)},/* PJT_CLEANUP_PUSH_IMP */ + {DUAL_ENTRY(_pthread_cancel_enter)}, /* PJT_CANCEL_ENTER */ + {DUAL_ENTRY(_pthread_cancel_leave)} /* PJT_CANCEL_LEAVE */ }; static int init_once = 0; diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h index a42b4ec..e5a82b9 100644 --- a/lib/libthr/thread/thr_private.h +++ b/lib/libthr/thread/thr_private.h @@ -716,7 +716,8 @@ int _sched_yield(void); void _pthread_cleanup_push(void (*)(void *), void *); void _pthread_cleanup_pop(int); void _pthread_exit_mask(void *status, sigset_t *mask) __dead2 __hidden; - +void _pthread_cancel_enter(int maycancel); +void _pthread_cancel_leave(int maycancel); /* #include */ #ifdef _SYS_FCNTL_H_ -- cgit v1.1