protonscr

Crash when calling DisableThreadLibraryCalls Win32 API from Rust

protonclosed
ValveSoftware/Proton#8992 · opened 2025-08-22 by ividyon · updated 2025-08-22 · 1 comments · github
Iividyon 2025-08-22 github

https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-disablethreadlibrarycalls

use windows::Win32::System::LibraryLoader::{DisableThreadLibraryCalls, GetModuleFileNameW};

pub extern "C" fn DllMain(hmodule: HMODULE, reason: u32) -> bool {
    // Check if we're attaching to the game
    if reason != 1 {
        return true;
    }

      unsafe {
          // SAFETY: Idk man
          DisableThreadLibraryCalls(hmodule).expect("Could not disable thread library calls");
      }
}

Injecting a Rust-made DLL containing this code into ELDEN RING causes a crash due to the following:

2025-08-22T05:03:10.324691Z  ERROR tracing_panic: A panic occurred
    panic.payload="Could not disable thread library calls: Error { code: HRESULT(0x8007007E), message: "Module not found." }"
    panic.location="src\lib.rs:92:44"
    panic.backtrace=disabled backtrace
    panic.note="run with RUST_BACKTRACE=1 environment variable to display a backtrace"

Happens when running ELDEN RING via the default version of Proton on a Steam Deck.

The API bindings are from the official Microsoft windows crate.

Kkisak-valve maintainer 2025-08-22 github

Hello @ividyon, it's not really clear what the intent is behind your tinkering. This doesn't look like a bug for a Proton dev to ponder.

Closing as invalid.

Error codes