From 95c2588191394e93fefeec9cd4cc7f47f7566884 Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Thu, 2 Jul 2026 13:00:30 -0700 Subject: [PATCH] Add TSD bootstrap reentrancy test --- test/unit/tsd.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/test/unit/tsd.c b/test/unit/tsd.c index 598f9b6d..7dee910b 100644 --- a/test/unit/tsd.c +++ b/test/unit/tsd.c @@ -130,6 +130,42 @@ TEST_BEGIN(test_tsd_reincarnation) { } TEST_END +static bool tsd_bootstrap_reentrant_hook_ran; + +static void +tsd_bootstrap_reentrant_hook(void) { + tsd_bootstrap_reentrant_hook_ran = true; + test_hooks_tsd_bootstrap_hook = NULL; + + void *p = malloc(16); + expect_ptr_not_null(p, "Unexpected recursive malloc() failure"); + free(p); +} + +static void * +thd_start_reentrant_tsd_bootstrap(void *arg) { + (void)arg; + + test_hooks_tsd_bootstrap_hook = tsd_bootstrap_reentrant_hook; + void *p = malloc(1); + expect_ptr_not_null(p, "Unexpected malloc() failure"); + free(p); + test_hooks_tsd_bootstrap_hook = NULL; + + expect_true(tsd_bootstrap_reentrant_hook_ran, + "TSD bootstrap hook should have executed"); + return NULL; +} + +TEST_BEGIN(test_tsd_reentrant_bootstrap) { + thd_t thd; + + tsd_bootstrap_reentrant_hook_ran = false; + thd_create(&thd, thd_start_reentrant_tsd_bootstrap, NULL); + thd_join(thd, NULL); +} +TEST_END + static void * thd_start_dalloc_only(void *arg) { void **ptrs = (void **)arg; @@ -194,5 +230,6 @@ main(void) { } return test_no_reentrancy(test_tsd_main_thread, test_tsd_sub_thread, - test_tsd_sub_thread_dalloc_only, test_tsd_reincarnation); + test_tsd_sub_thread_dalloc_only, test_tsd_reincarnation, + test_tsd_reentrant_bootstrap); }