xpsupport icon indicating copy to clipboard operation
xpsupport copied to clipboard

Doesn't work since Rust 1.51.0

Open BlueGradientHorizon opened this issue 3 years ago • 3 comments

In total, in my tests, I used these toolchains:

  • 1.50.0-i686-pc-windows-gnu
  • 1.50.0-i686-pc-windows-msvc
  • 1.51.0-i686-pc-windows-gnu
  • 1.51.0-i686-pc-windows-msvc

To build the program in gnu toolchains, I used the MinGW toolchain: i686-8.1.0-release-win32-dwarf. If I use Rust toolchains version 1.50.0, the program runs successfully on Windows XP (for msvc builds, of course, I installed MS Visual C++ 2015 Redist. x86 on my Windows XP virtual machine).

But if I try to run the same program built in any version of Rust since 1.51.0, I get an error [translated to English]: The procedure entry point AcquireSRWLockExclusive could not be located in the dynamic link library KERNEL32.dll. Capture

It looks like the xpsupport initialization doesn't happen until the Rust standard library is run.

Contents of the program source file src\main.rs:

extern crate xpsupport;
fn main() {
    xpsupport::init();
    println!("Hello, World!");
}

Cargo.toml:

[package]
name = "xp_test"
version = "0.1.0"
authors = ["lenovo-pc <***@gmail.com>"]
edition = "2018"

[dependencies]
xpsupport = "0.2"

RUSTFLAGS:

  • for gnu Rust toolchain build
set RUSTFLAGS=-Ctarget-feature=+crt-static
  • for msvc Rust toolchain build
set RUSTFLAGS=-Ctarget-feature=+crt-static -Clink-args=/subsystem:console,5.01

Build command:

cargo build --target i686-pc-windows-XXX --release

BlueGradientHorizon avatar Jul 12 '22 13:07 BlueGradientHorizon

Hm, I've made some progress. It turns out that the YY_Thunks_for_WinXP.obj file is required and must be included in the linker parameters. But also i need to pass user32.lib library as parameter for successfull linking. But now I have another missing function error: SetThreadStackGuarantee. I'm investigating it.

BlueGradientHorizon avatar Jul 12 '22 17:07 BlueGradientHorizon

Also, if I understand correctly, the SetThreadStackGuarantee function is the only one missing to run my Rust test program. I checked it with Dependency walker program.

BlueGradientHorizon avatar Jul 12 '22 17:07 BlueGradientHorizon

Sadly, the commit https://github.com/rust-lang/rust/commit/59855e0bbf0df22f39dbe39bc58ab5c978fb3765 make this crate not work anymore, but the YY_Thunks_for_WinXP.obj trick should work, I'v noticed your comment on https://github.com/Chuyu-Team/YY-Thunks/issues/37. Link YY_Thunks maybe the only solution to support XP right now.

You can write a obj file like YY-Thunks and link it to your rust code, and implement SetThreadStackGuarantee like this: https://github.com/rust-lang/rust/commit/59855e0bbf0df22f39dbe39bc58ab5c978fb3765#diff-96f5abd15201d718909ac0227541d568d9985ac9b075a34ae7eb9f5f66a562f9L1042-L1044

lynnux avatar Jul 13 '22 02:07 lynnux