Thread notices for title images
The prepared images get no DLL_THREAD_ATTACH/DETACH from Windows. A TLS callback in our exe, called on every thread of the process, passes each start and end on to the attached images: their TLS callbacks, then a DLL's DllMain. DisableThreadLibraryCalls stops the DllMain calls and fails for images with static TLS, as on Windows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
d032b8a241
commit
4b2526918b
6 files changed
+210
-11
No files matched your search
@@ -180,6 +180,12 @@ pub extern "system" fn FreeLibrary(module: *mut c_void) -> i32 {
|
||||
host::free_library(module)
|
||||
}
|
||||
|
||||
/// Title images hear of thread starts and ends from us, not from the
|
||||
/// Windows loader (`victory_loader::disable_thread_calls`).
|
||||
pub extern "system" fn DisableThreadLibraryCalls(module: *mut c_void) -> i32 {
|
||||
host::disable_thread_library_calls(module)
|
||||
}
|
||||
|
||||
/// Title debug output goes to our log (no debugger needs to be attached).
|
||||
pub extern "system" fn OutputDebugStringA(text: *const u8) {
|
||||
if !text.is_null() {
|
||||
@@ -293,6 +299,7 @@ pub(crate) fn module() -> HleModule {
|
||||
hle_export!(LoadLibraryW),
|
||||
hle_export!(GetProcAddress),
|
||||
hle_export!(FreeLibrary),
|
||||
hle_export!(DisableThreadLibraryCalls),
|
||||
hle_export!(OutputDebugStringA),
|
||||
hle_export!(OutputDebugStringW),
|
||||
hle_export!(exit),
|
||||
@@ -311,8 +318,8 @@ mod host {
|
||||
use windows_sys::Win32::Foundation::{FreeLibrary, SetLastError};
|
||||
use windows_sys::Win32::System::Diagnostics::Debug::RtlCaptureStackBackTrace;
|
||||
use windows_sys::Win32::System::LibraryLoader::{
|
||||
GetModuleFileNameA, GetModuleFileNameW, GetModuleHandleA, GetModuleHandleW, GetProcAddress,
|
||||
LoadLibraryExA, LoadLibraryExW,
|
||||
DisableThreadLibraryCalls, GetModuleFileNameA, GetModuleFileNameW, GetModuleHandleA,
|
||||
GetModuleHandleW, GetProcAddress, LoadLibraryExA, LoadLibraryExW,
|
||||
};
|
||||
use windows_sys::Win32::System::Threading::TerminateProcess;
|
||||
|
||||
@@ -375,6 +382,14 @@ mod host {
|
||||
unsafe { FreeLibrary(module) }
|
||||
}
|
||||
|
||||
pub(super) fn disable_thread_library_calls(module: *mut c_void) -> i32 {
|
||||
match victory_loader::disable_thread_calls(module as usize) {
|
||||
Some(done) => i32::from(done),
|
||||
// SAFETY: see above.
|
||||
None => unsafe { DisableThreadLibraryCalls(module) },
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn exit(code: i32) -> ! {
|
||||
// SAFETY: see above.
|
||||
unsafe { crt_exit(code) }
|
||||
@@ -448,6 +463,10 @@ mod host {
|
||||
0
|
||||
}
|
||||
|
||||
pub(super) fn disable_thread_library_calls(_: *mut c_void) -> i32 {
|
||||
0
|
||||
}
|
||||
|
||||
pub(super) fn exit(code: i32) -> ! {
|
||||
std::process::exit(code)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user