diff options
| author | Rafael <rafaelalvesp2005@gmail.com> | 2026-11-23 15:36:26 -0300 |
|---|---|---|
| committer | Rafael <rafaelalvesp2005@gmail.com> | 2026-11-23 15:36:26 -0300 |
| commit | 63f0e0dea3a9d44201db408c4e2c3f2f5b2b94d6 (patch) | |
| tree | 86f0dcad8070e2a3a693ef4897aa83950cfeb224 /runtime/test/loader_test.cpp | |
| parent | f78f7d6a2a9364cb128c03ac539fe540d5c70df1 (diff) | |
| parent | 6dda0630bd6fc0514baadb94fb98e36bd7d64c0b (diff) | |
Merge main into fix/walk-bink_names
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/test/loader_test.cpp')
| -rw-r--r-- | runtime/test/loader_test.cpp | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/runtime/test/loader_test.cpp b/runtime/test/loader_test.cpp index 3ed83747a..aba37cdf3 100644 --- a/runtime/test/loader_test.cpp +++ b/runtime/test/loader_test.cpp | |||
| @@ -684,9 +684,18 @@ bool g_use_fls = false; | |||
| 684 | DWORD g_fls_index = FLS_OUT_OF_INDEXES; | 684 | DWORD g_fls_index = FLS_OUT_OF_INDEXES; |
| 685 | int g_fls_callbacks = 0; | 685 | int g_fls_callbacks = 0; |
| 686 | 686 | ||
| 687 | // DllMain's lpvReserved for its last DLL_PROCESS_ATTACH, and whether one was seen. | ||
| 688 | void* g_attach_reserved = nullptr; | ||
| 689 | bool g_attach_seen = false; | ||
| 690 | |||
| 687 | void observe_notification(void* base, DWORD reason, void* reserved, bool tls) { | 691 | void observe_notification(void* base, DWORD reason, void* reserved, bool tls) { |
| 688 | g_notifications.push_back({base, reason, tls}); | 692 | g_notifications.push_back({base, reason, tls}); |
| 689 | if (reserved) g_detach_state_live = false; | 693 | if (reason == DLL_PROCESS_ATTACH && !tls) { |
| 694 | g_attach_reserved = reserved; | ||
| 695 | g_attach_seen = true; | ||
| 696 | } | ||
| 697 | // ~Loader unmaps the image after the detach, which is FreeLibrary's case: lpvReserved is NULL there. | ||
| 698 | if (reason == DLL_PROCESS_DETACH && reserved) g_detach_state_live = false; | ||
| 690 | if (reason != DLL_PROCESS_DETACH) return; | 699 | if (reason != DLL_PROCESS_DETACH) return; |
| 691 | for (const auto& m : g_live_modules) { | 700 | for (const auto& m : g_live_modules) { |
| 692 | MEMORY_BASIC_INFORMATION info{}; | 701 | MEMORY_BASIC_INFORMATION info{}; |
| @@ -732,6 +741,8 @@ void reset_notifications() { | |||
| 732 | g_fail_attach = false; | 741 | g_fail_attach = false; |
| 733 | g_use_fls = false; | 742 | g_use_fls = false; |
| 734 | g_fls_callbacks = 0; | 743 | g_fls_callbacks = 0; |
| 744 | g_attach_reserved = nullptr; | ||
| 745 | g_attach_seen = false; | ||
| 735 | } | 746 | } |
| 736 | 747 | ||
| 737 | void expect_notifications(const char* what, const std::vector<Notification>& expected) { | 748 | void expect_notifications(const char* what, const std::vector<Notification>& expected) { |
| @@ -863,6 +874,37 @@ void test_process_detach_without_entry() { | |||
| 863 | reset_notifications(); | 874 | reset_notifications(); |
| 864 | } | 875 | } |
| 865 | 876 | ||
| 877 | // DllMain docs (learn.microsoft.com/windows/win32/dlls/dllmain): "If fdwReason is DLL_PROCESS_ATTACH, lpvReserved is | ||
| 878 | // NULL for dynamic loads and non-NULL for static loads." Loader::load() from the host is the process-start graph (the | ||
| 879 | // executable and the DLLs it imports), a run-time LoadLibrary of a bundled DLL is a dynamic load. | ||
| 880 | void test_attach_reserved() { | ||
| 881 | reset_notifications(); | ||
| 882 | try { | ||
| 883 | rt::Loader loader(g_dir); | ||
| 884 | loader.load(write_image(make_lifecycle_image())); | ||
| 885 | loader.initialise(); | ||
| 886 | if (!g_attach_seen) failed("a static load's DllMain gets a non-NULL lpvReserved", "DllMain was not called"); | ||
| 887 | else if (!g_attach_reserved) failed("a static load's DllMain gets a non-NULL lpvReserved", "lpvReserved was NULL"); | ||
| 888 | else pass("a static load's DllMain gets a non-NULL lpvReserved"); | ||
| 889 | } catch (const std::exception& e) { | ||
| 890 | failed("a static load's DllMain gets a non-NULL lpvReserved", e.what()); | ||
| 891 | } | ||
| 892 | |||
| 893 | reset_notifications(); | ||
| 894 | try { | ||
| 895 | write_image_as(make_lifecycle_image(), "attach_reserved_dynamic.dll"); | ||
| 896 | rt::Loader loader(g_dir); | ||
| 897 | bool handled = false; | ||
| 898 | void* h = loader.load_runtime_module("attach_reserved_dynamic.dll", 0, handled); | ||
| 899 | if (!handled || !h) failed("a run-time load's DllMain gets a NULL lpvReserved", "the run-time load failed"); | ||
| 900 | else if (!g_attach_seen) failed("a run-time load's DllMain gets a NULL lpvReserved", "DllMain was not called"); | ||
| 901 | else if (g_attach_reserved) failed("a run-time load's DllMain gets a NULL lpvReserved", "lpvReserved was non-NULL"); | ||
| 902 | else pass("a run-time load's DllMain gets a NULL lpvReserved"); | ||
| 903 | } catch (const std::exception& e) { | ||
| 904 | failed("a run-time load's DllMain gets a NULL lpvReserved", e.what()); | ||
| 905 | } | ||
| 906 | } | ||
| 907 | |||
| 866 | void test_process_detach_dependencies() { | 908 | void test_process_detach_dependencies() { |
| 867 | reset_notifications(); | 909 | reset_notifications(); |
| 868 | auto dep = make_forwarder_image("KERNEL32.GetCurrentProcessId", 0x180000000); | 910 | auto dep = make_forwarder_image("KERNEL32.GetCurrentProcessId", 0x180000000); |
| @@ -1303,6 +1345,7 @@ int main() { | |||
| 1303 | test_process_detach(); | 1345 | test_process_detach(); |
| 1304 | test_process_detach_invalid_tls(); | 1346 | test_process_detach_invalid_tls(); |
| 1305 | test_process_detach_without_entry(); | 1347 | test_process_detach_without_entry(); |
| 1348 | test_attach_reserved(); | ||
| 1306 | test_process_detach_dependencies(); | 1349 | test_process_detach_dependencies(); |
| 1307 | test_failed_dependency_not_registered(); | 1350 | test_failed_dependency_not_registered(); |
| 1308 | test_delay_descriptor_fields(); | 1351 | test_delay_descriptor_fields(); |