lynnux / xpsupport

make rust support XP and vista
31 stars 1 forks source link

Doesn't work since Rust 1.51.0 #4

Open BlueGradientHorizon opened 2 years ago

BlueGradientHorizon commented 2 years ago

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

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:

set RUSTFLAGS=-Ctarget-feature=+crt-static
set RUSTFLAGS=-Ctarget-feature=+crt-static -Clink-args=/subsystem:console,5.01

Build command:

cargo build --target i686-pc-windows-XXX --release
BlueGradientHorizon commented 2 years ago

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 commented 2 years ago

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.

lynnux commented 2 years ago

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