// User-mode smoke test for POSIX dynamic module loading. #include #include #include #include #include #include #include static void print(const char* s) { write(1, s, strlen(s)); } static void exit_now(int code) { while (true) exit(code); } static void fail(const char* message) { print("posix_module_smoke: "); print(message); print("\n"); exit_now(1); } // Verifies that dlerror reports and clears one loader error. static void check_dlerror_clear(void) { void* missing = dlsym(0, "definitely_missing"); if (missing) fail("dlsym unexpectedly succeeded"); char* first = dlerror(); if (!first || !first[0]) fail("dlerror did not report the failure"); char* second = dlerror(); if (second) fail("dlerror did not clear the failure"); } // Runs the POSIX dynamic loader smoke test. int main(void) { print("posix_module_smoke: start\n"); check_dlerror_clear(); void* module = dlopen("syscall.dll", RTLD_NOW | RTLD_LOCAL); if (!module) fail("dlopen syscall.dll failed"); typedef uint32_t (__stdcall *GETPID_FN)(void); GETPID_FN getpid_native = (GETPID_FN)dlsym(module, "SysGetCurrentPid"); if (!getpid_native) fail("dlsym SysGetCurrentPid failed"); if (getpid_native() == 0) fail("resolved SysGetCurrentPid returned zero"); if (dlclose(module) != 0) fail("dlclose syscall.dll failed"); print("posix_module_smoke: PASS\n"); exit_now(0); return 0; }