#condvar #rw-lock #xp #windows

xpsupport

Hook serveral APIs to enable XP support for rust

9 releases

Uses old Rust 2015

0.2.2 Mar 15, 2020
0.2.1 Dec 25, 2019
0.2.0 Oct 30, 2019
0.1.5 Oct 22, 2019
0.1.2 Aug 9, 2017

#3 in #xp


Used in xpsupport-sys

MIT license

95KB
2K SLoC

C 2K SLoC // 0.2% comments Rust 85 SLoC // 0.1% comments

Usage

add this to your Cargo.toml:

[dependencies]
xpsupport = "0.2"

add this to your crate root:

extern crate xpsupport;

add xpsupport::init(); to fn main like:

fn main()
{
    xpsupport::init();
	//...
}	

for MSVC toolchain, you can run the bat file:

@echo off
cd %cd%
set RUSTFLAGS=-Ctarget-feature=+crt-static -Clink-args=/subsystem:console,5.01
cargo build --target i686-pc-windows-msvc --release
cmd /k

How does it work?

Idea of version 0.2 inspired by ctor. The xpsupport::init() runs before any initialization of Rust's stdlib (due to an issue of ctor issue27, xpsupport::init() in fn main is just a place holder). It hooks GetProcAddress, and return the below functions when on XP or Vista (most code are from wine project):

  • AcquireSRWLockShared
  • ReleaseSRWLockExclusive
  • ReleaseSRWLockShared
  • TryAcquireSRWLockExclusive
  • TryAcquireSRWLockShared
  • SleepConditionVariableSRW
  • WakeAllConditionVariable
  • WakeConditionVariable

External API solution

Some third party crate use winapi that not support xp, you can try YY-Thunks to resolve this. Download YY-Thunks-Binary, extract it somewhere, for xp we use the x86 binary, take E:\YY-Thunks-1.0.2.4-Beta-Binary\objs\x86\YY_Thunks_for_WinXP.obj for example, run the bat file:

@echo off
cd %cd%
set RUSTFLAGS=-Ctarget-feature=+crt-static -Clink-args=/subsystem:console,5.01 -Clink-args=E:\YY-Thunks-1.0.2.4-Beta-Binary\objs\x86\YY_Thunks_for_WinXP.obj
cargo build --target i686-pc-windows-msvc --release
cmd /k

just run the bat file. Cause it use the obj file to link, it's may incompatible with mingw.

Testing Result

Testing code are from libstd/sync, only mpsc::stress_recv_timeout_shared seems deadlock, all other are passed through! You may consider parking_lot crate as the sync library or spin, they both support XP.

No runtime deps

~170KB