]> git.lizzy.rs Git - rust.git/commit
std: Fix Windows XP compatibility
authorAlex Crichton <alex@alexcrichton.com>
Fri, 26 Jun 2015 16:30:35 +0000 (09:30 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Sun, 28 Jun 2015 02:45:24 +0000 (19:45 -0700)
commit10b103af48368c5df644fa61dc417a36083922c8
tree538dbf67a23dbd8297576319f4bb0011bb633a65
parent87909582374be91bc5affdd2e74e265077a6e571
std: Fix Windows XP compatibility

This commit enables executables linked against the standard library to run on
Windows XP. There are two main components of this commit:

* APIs not available on XP are shimmed to have a fallback implementation and use
  runtime detection to determine if they are available.
* Mutexes on Windows were reimplemented to use critical sections on XP where
  rwlocks are not available.

The APIs which are not available on XP are:

* SetFileInformationByHandle - this is just used by `File::truncate` and that
  function just returns an error now.
* SetThreadStackGuarantee - this is used by the stack overflow support on
  windows, but if this isn't available then it's just ignored (it seems
  non-critical).
* All condition variable APIs are missing - the shims added for these apis
  simply always panic for now. We may eventually provide a fallback
  implementation, but for now the standard library does not rely on condition
  variables for normal use.
* RWLocks, like condition variables, are missing entirely. The same story for
  condition variables is taken here. These APIs are all now panicking stubs as
  the standard library doesn't rely on RWLocks for normal use.

Currently, as an optimization, we use SRWLOCKs for the standard `sync::Mutex`
implementation on Windows, which is indeed required for normal operation of the
standard library. To allow the standard library to run on XP, this commit
reimplements mutexes on Windows to use SRWLOCK instances *if available* and
otherwise a CriticalSection is used (with some checking for recursive
locking).

With all these changes put together, a 32-bit MSVC-built executable can run on
Windows XP and print "hello world"

Closes #12842
Closes #19992
Closes #24776
src/libstd/dynamic_lib.rs
src/libstd/sys/windows/c.rs
src/libstd/sys/windows/compat.rs [new file with mode: 0644]
src/libstd/sys/windows/condvar.rs
src/libstd/sys/windows/fs.rs
src/libstd/sys/windows/mod.rs
src/libstd/sys/windows/mutex.rs
src/libstd/sys/windows/rwlock.rs
src/libstd/sys/windows/stack_overflow.rs
src/libstd/sys/windows/sync.rs [deleted file]