Rust: Investigate fallback implementations on Windows XP

Created on 29 Jun 2015  路  14Comments  路  Source: rust-lang/rust

Right now we have a large list of APIs we're using on Windows which aren't available on XP. The fallback implementations range from "call SetLastError" to "panic when called". There are likely at least somewhat compatible fallbacks in each situation that can be used:

  • Condition variables can likely be implemented on top of some other system primitive.
  • RwLock can be implemented on top of condition variables and mutexes
  • Various fs syscalls can likely have some form of a fallback.
A-concurrency C-tracking-issue Libs-Tracked O-windows T-libs

Most helpful comment

The parking_lot crate provides implementations of Mutex, Condvar, RwLock and Once that works on Windows XP.

All 14 comments

I'm looking into implementing SRWLocks and condition variables in a similar way to their actual implementation in Vista+ (atomics and keyed events.) Keyed events are undocumented and don't perform as well under XP as they do under Vista+, but for compatibility code, I think it would be sufficient.

Since the TryAcquireSRWLock* functions are unavailable in Vista, but SRWLocks are otherwise available, I'm thinking we should also split the compatibility fallbacks into groups where all the fallbacks will be used if ANY of the functions are unavailable, since the compatibility implementations of TryAcquireSRWLock* are unlikely to be compatible with the real thing.

Got a work in progress for SRWLocks and condition variables at MrAlert/rust@dbf7ca041b7079ecfb7d18f5b60003b4655f2851. Most of the related tests seem to pass under XP except for sync::condvar::tests::wait_timeout_with. Don't have the fallback grouping stuff yet though, so this'll cause problems under Vista.

Updated WIP at MrAlert/rust@08413003f32f2cc554215ff942e43ca47aa2362d. Added fallback groups, and removed branches on calls to compatibility functions by initializing the function pointers to point to loader stubs instead of NULL. Should perform roughly as well as regular DLL calls now (if it didn't already.)

I also tested the fallbacks under Windows 7, and for whatever reason sync::condvar::tests::wait_timeout_with still fails, even after I fixed the return values on SleepConditionVariableSRW. Everything else passes, however.

When using the executable from make check-stage1-std, thread::local::tests::dtors_in_dtors_in_dtors hangs under Windows XP, but using the stage2 test executable, it runs fine. Probably has to do with TLS callback stuff failing to work on a dynamically-linked libstd on XP for some reason.

libstd tests that currently fail in XP include: env::tests::test_env_set_var, fs::tests::truncate_works, all tests in net::tcp and net::udp, and sync::condvar::tests::wait_timeout_with.

The parking_lot crate provides implementations of Mutex, Condvar, RwLock and Once that works on Windows XP.

https://github.com/rust-lang/rust/issues/37638 proposes to provide a way to detect if XP compatibility is even wanted. It would be great if libstd could use a mechanism like that so that XP fallbacks are only provided when XP is actually being targetted. This would eliminate the additional runtime overhead of selecting different implementations based on the Windows version.

I believe that LLVM no longer supports Windows XP, so arguably while work on our side within our libraries would be a slight quality of life improvement, it is not going to change the unsupportedness of XP. If we're interested in individual improvements, please ask on internals.rust-lang.org or by filing an issue here and we can go forward from there.

This issue is for tracking XP compatibility for binaries produced by rustc, not rustc itself. Therefore this should remain open.

My understanding was that LLVM doesn't support XP as a target platform -- but I'm fine with keeping this open; I don't exactly know what the problems there are. I agree that it'd be great if we could continue to work on XP.

LLVM requires Windows 7 or newer as a host platform. It is capable of targeting much older than that, although you still have to tell the linker to target an older version as well as limiting your usage of system APIs to those that are available on older Windows.

Can LLVM target XP and Vista from Linux?

@techtonik LLVM's ability to target a specific architecture or operating system is not limited by what host system it is running on. The ability to link the resulting binaries however, does depend on your ability to acquire the appropriate libraries and linker. In the case of targeting Windows from Linux, you'd likely use MinGW for this, which is definitely capable of linking binaries that can run on XP.

I've created a thread about considering dropping XP support: https://internals.rust-lang.org/t/consider-dropping-support-for-windows-xp/8745

image

Was this page helpful?
0 / 5 - 0 ratings