diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2022-06-21 18:02:47 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-21 18:02:47 +0200 |
| commit | eec9be71f643070091fe8dddb5072853f30acd18 (patch) | |
| tree | ca1f44791130bb291d16c61f139bde2e6a9bae47 | |
| parent | 33d96fd28a107d55aacba87a6ed91ce60c9c41b8 (diff) | |
| parent | 888913c739464a51fec621d8eaf65eedb0527143 (diff) | |
Merge pull request #1854 from Kelimion/dll-entry-point
Add runtime.dll_forward_reason for Windows DLLs.
| -rw-r--r-- | core/runtime/core.odin | 13 | ||||
| -rw-r--r-- | core/runtime/entry_windows.odin | 14 |
2 files changed, 22 insertions, 5 deletions
diff --git a/core/runtime/core.odin b/core/runtime/core.odin index 73d1e6371..8fb3d7210 100644 --- a/core/runtime/core.odin +++ b/core/runtime/core.odin @@ -267,6 +267,19 @@ type_table: []Type_Info args__: []cstring +when ODIN_OS == .Windows { + // NOTE(Jeroen): If we're a Windows DLL, fwdReason will be populated. + // This tells a DLL if it's first loaded, about to be unloaded, or a thread is joining/exiting. + + DLL_Forward_Reason :: enum u32 { + Process_Detach = 0, // About to unload DLL + Process_Attach = 1, // Entry point + Thread_Attach = 2, + Thread_Detach = 3, + } + dll_forward_reason: DLL_Forward_Reason +} + // IMPORTANT NOTE(bill): Must be in this order (as the compiler relies upon it) diff --git a/core/runtime/entry_windows.odin b/core/runtime/entry_windows.odin index 2f323cb41..a315c1209 100644 --- a/core/runtime/entry_windows.odin +++ b/core/runtime/entry_windows.odin @@ -8,15 +8,19 @@ when ODIN_BUILD_MODE == .Dynamic { @(link_name="DllMain", linkage="strong", require) DllMain :: proc "stdcall" (hinstDLL: rawptr, fdwReason: u32, lpReserved: rawptr) -> b32 { context = default_context() - switch fdwReason { - case 1: // DLL_PROCESS_ATTACH + + // Populate Windows DLL-specific global + dll_forward_reason = DLL_Forward_Reason(fdwReason) + + switch dll_forward_reason { + case .Process_Attach: #force_no_inline _startup_runtime() intrinsics.__entry_point() - case 0: // DLL_PROCESS_DETACH + case .Process_Detach: #force_no_inline _cleanup_runtime() - case 2: // DLL_THREAD_ATTACH + case .Thread_Attach: break - case 3: // DLL_THREAD_DETACH + case .Thread_Detach: break } return true |