about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-10-24 11:14:15 +0000
committerbors <bors@rust-lang.org>2023-10-24 11:14:15 +0000
commitcee6db171d03c22f1cbf98a72dffde858a49fbd8 (patch)
treeb5d2cf4db7a77f41a5b4f7edf6337241ce600cd7 /src/tools
parent271dcc1d40b57ad129d88fef1aa7f239308fbfb4 (diff)
parentfbf256716e499d9b2ee15c722c63d90d960f2859 (diff)
downloadrust-cee6db171d03c22f1cbf98a72dffde858a49fbd8.tar.gz
rust-cee6db171d03c22f1cbf98a72dffde858a49fbd8.zip
Auto merge of #116461 - ChrisDenton:sleep, r=thomcc
Windows: Support sub-millisecond sleep

Use `CreateWaitableTimerExW` with `CREATE_WAITABLE_TIMER_HIGH_RESOLUTION`. Does not work before Windows 10, version 1803 so in that case we fallback to using `Sleep`.

I've created a `WaitableTimer` type so it can one day be adapted to also support waiting to an absolute time (which has been talked about). Note though that it currently returns `Err(())` because we can't do anything with the errors other than fallback to the old `Sleep`. Feel free to tell me to do errors properly. It just didn't seem worth constructing an `io::Error` if we're never going to surface it to the user. And it *should* all be infallible anyway unless the OS is too old to support it.

Closes #43376
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/miri/src/shims/windows/foreign_items.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/tools/miri/src/shims/windows/foreign_items.rs b/src/tools/miri/src/shims/windows/foreign_items.rs
index 759a412c16a..c887e18e97e 100644
--- a/src/tools/miri/src/shims/windows/foreign_items.rs
+++ b/src/tools/miri/src/shims/windows/foreign_items.rs
@@ -272,6 +272,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
 
                 this.Sleep(timeout)?;
             }
+            "CreateWaitableTimerExW" => {
+                let [attributes, name, flags, access] =
+                    this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
+                this.read_pointer(attributes)?;
+                this.read_pointer(name)?;
+                this.read_scalar(flags)?.to_u32()?;
+                this.read_scalar(access)?.to_u32()?;
+                // Unimplemented. Always return failure.
+                let not_supported = this.eval_windows("c", "ERROR_NOT_SUPPORTED");
+                this.set_last_error(not_supported)?;
+                this.write_null(dest)?;
+            }
 
             // Synchronization primitives
             "AcquireSRWLockExclusive" => {