Skip to content

Commit

Permalink
get_module_file_name on main thread only
Browse files Browse the repository at this point in the history
Some child plug-ins start threads, causing the DLL_THREAD_ATTACH event.
Since the MULTIPLEXER has been locked on the main thread that may be
waiting for the new threads to initialize themselves, the DllMain
implementation must not try to acquire the lock on the new threads.
  • Loading branch information
magicant committed Jul 2, 2023
1 parent ca3cac6 commit a1cd3ac
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,13 @@ extern "system" fn DllMain(dll_module: HMODULE, call_reason: DWORD, _reserved: L
const DLL_PROCESS_DETACH: DWORD = 0;

match call_reason {
DLL_PROCESS_ATTACH | DLL_THREAD_ATTACH => {
DLL_PROCESS_ATTACH => {
let mut multiplexer = MULTIPLEXER.lock().unwrap();
multiplexer.path = get_module_file_name(dll_module).unwrap();
}
DLL_THREAD_DETACH | DLL_PROCESS_DETACH => (),
DLL_THREAD_ATTACH => (),
DLL_THREAD_DETACH => (),
DLL_PROCESS_DETACH => (),
_ => (),
}

Expand Down

0 comments on commit a1cd3ac

Please sign in to comment.