libthr: Create landing pad in thr_once in C++ exception

In _thr_once, if init_routine fails with exception, the stack allocate
__cup will become invalid when unwinder walk back and free the stack of
thr_once. This cause cleanup linked list be dangling. In here, we give
the cleanup function a landing pad so that we td can correctly point
to previous cleanup function.

Reviewed by:    kib
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D61212
This commit is contained in:
ShengYi Hung committed 2026-11-06 03:01:55 +11:00
1 parent 71937d8e11
commit 2734bbbcba
1 file changed
+15 -1
+15 -1
View File
@@ -249,7 +249,9 @@ struct pthread_cleanup {
};
#define THR_CLEANUP_PUSH(td, func, arg) { \
struct pthread_cleanup __cup; \
struct pthread_cleanup __cup \
__attribute__((__cleanup__( \
_thr_cleanup_unwind))); \
\
__cup.routine = func; \
__cup.routine_arg = arg; \
@@ -949,6 +951,18 @@ _thr_check_init(void)
_libpthread_init(NULL);
}
static inline void
_thr_cleanup_unwind(struct pthread_cleanup *cup)
{
struct pthread *curthread;
curthread = _get_curthread();
if (curthread->cleanup == cup) {
curthread->cleanup = cup->prev;
cup->routine(cup->routine_arg);
}
}
struct wake_addr *_thr_alloc_wake_addr(void);
void _thr_release_wake_addr(struct wake_addr *);
int _thr_sleep(struct pthread *, int, const struct timespec *);