diff --git a/include/wums/hooks.h b/include/wums/hooks.h index 77a1ef0..e54d10c 100644 --- a/include/wums/hooks.h +++ b/include/wums/hooks.h @@ -165,11 +165,22 @@ 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) -#define WUMS___INIT_WRAPPER() \ - __EXTERN_C_MACRO void __init(); \ - void __init_wrapper() { \ - __init(); \ - } \ +#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); #define WUMS___FINI_WRAPPER() \ diff --git a/include/wums/meta.h b/include/wums/meta.h index 0134d18..f87332b 100644 --- a/include/wums/meta.h +++ b/include/wums/meta.h @@ -41,26 +41,30 @@ extern "C" { #define WUMS_VERSION "0.3.2" -#define WUMS_MODULE_EXPORT_NAME(__module_name) \ - WUMS_META(export_name, __module_name); \ - WUMS_META(wums, WUMS_VERSION); \ - WUMS_USE_WUT_MALLOC(); \ - WUMS_USE_WUT_SOCKETS(); \ - WUMS_USE_WUT_NEWLIB(); \ - WUMS_USE_WUT_STDCPP(); \ - WUMS___INIT_WRAPPER(); \ - WUMS___FINI_WRAPPER(); \ - __EXTERN_C_MACRO void abort(); \ - void abort() { \ - OSFatal(__module_name ": abort() called. Uncaught exception?"); \ - while (1) \ - ; \ - } \ - WUMS_META(buildtimestamp, __DATE__ " " __TIME__); \ - 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__ ")" +#define WUMS_MODULE_EXPORT_NAME(__module_name) \ + WUMS_META(export_name, __module_name); \ + WUMS_META(wums, WUMS_VERSION); \ + WUMS_USE_WUT_MALLOC(); \ + WUMS_USE_WUT_SOCKETS(); \ + WUMS_USE_WUT_NEWLIB(); \ + WUMS_USE_WUT_STDCPP(); \ + WUMS___INIT_WRAPPER(); \ + WUMS___FINI_WRAPPER(); \ + __EXTERN_C_MACRO void abort(); \ + void abort() { \ + OSFatal(__module_name ": abort() called. Uncaught exception?"); \ + while (1) \ + ; \ + } \ + WUMS_META(buildtimestamp, __DATE__ " " __TIME__); \ + 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__ ")"; \ + 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) diff --git a/libraries/libwums/wums_thread_specific.cpp b/libraries/libwums/wums_thread_specific.cpp index 8cb62c0..21fe6a1 100644 --- a/libraries/libwums/wums_thread_specific.cpp +++ b/libraries/libwums/wums_thread_specific.cpp @@ -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");