Make sure wut_get_thread_specific has been overriden properly

This commit is contained in:
Maschell 2023-07-19 16:12:09 +02:00
parent 84d6b15d83
commit 004f7f76e8
3 changed files with 42 additions and 25 deletions

View File

@ -165,9 +165,20 @@ typedef struct wums_relocs_done_args_t {
__EXTERN_C_MACRO void __fini_wut_socket(); \
WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT_SOCKETS, __fini_wut_socket)
#ifdef __cplusplus
extern "C" uint32_t __attribute__((weak)) wut_get_thread_specific(int id);
extern "C" const char wums_meta_info_linking_order[];
#else
extern uint32_t __attribute__((weak)) wut_get_thread_specific(int id);
extern const char wums_meta_info_linking_order[];
#endif
#define WUMS___INIT_WRAPPER() \
__EXTERN_C_MACRO void __init(); \
void __init_wrapper() { \
if (wut_get_thread_specific(0x13371337) != 0x42424242) { \
OSFatal(wums_meta_info_linking_order); \
} \
__init(); \
} \
WUMS_HOOK_EX(WUMS_HOOK_INIT_WRAPPER, __init_wrapper);

View File

@ -60,7 +60,11 @@ extern "C" {
extern const char wums_meta_info_dump[] WUMS_SECTION("meta"); \
const char wums_meta_info_dump[] = "(module: " __module_name ";" \
"wums " WUMS_VERSION ";" \
"buildtime: " __DATE__ " " __TIME__ ")"
"buildtime: " __DATE__ " " __TIME__ ")"; \
extern const char wums_meta_info_linking_order[] WUMS_SECTION("meta"); \
const char wums_meta_info_linking_order[] = "Loading module \"" __module_name "\" failed.\n" \
"Function \"wut_get_thread_specific\" returned unexpected value.\n" \
"Please check linking order (expected \"-lwums -lwut\")";
#define WUMS_MODULE_AUTHOR(x) WUMS_META(author, x)
#define WUMS_MODULE_VERSION(x) WUMS_META(version, x)

View File

@ -43,6 +43,8 @@ void *wums_get_thread_specific(__wut_thread_specific_id id) {
return thread->reserved[3];
} else if (id == WUT_THREAD_SPECIFIC_1) {
return thread->reserved[4];
} else if ((uint32_t) id == 0x13371337) { // Mechanism to detect if the function was overridden properly
return (void *) 0x42424242;
} else {
OSReport("[%s] wums_get_thread_specific: invalid id\n", wums_meta_info_dump);
OSFatal("wums_get_thread_specific: invalid id");