Skip to content

Commit ac9368a

Browse files
committed
have windows tests use windows-sys
1 parent 1754946 commit ac9368a

14 files changed

+212
-156
lines changed

src/tools/miri/test_dependencies/Cargo.lock

Lines changed: 123 additions & 56 deletions
Large diffs are not rendered by default.

src/tools/miri/test_dependencies/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ rand = { version = "0.8", features = ["small_rng"] }
2020
page_size = "0.6"
2121
tokio = { version = "1.24", features = ["full"] }
2222

23+
[target.'cfg(windows)'.dependencies]
24+
windows-sys = { version = "0.52", features = [ "Win32_Foundation", "Win32_System_Threading" ] }
25+
2326
[workspace]

src/tools/miri/tests/fail/concurrency/windows_join_detached.rs renamed to src/tools/miri/tests/fail-dep/concurrency/windows_join_detached.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
33

44
// Joining a detached thread is undefined behavior.
55

6-
use std::os::windows::io::{AsRawHandle, RawHandle};
6+
use std::os::windows::io::AsRawHandle;
77
use std::thread;
88

9-
extern "system" {
10-
fn CloseHandle(handle: RawHandle) -> u32;
11-
}
9+
use windows_sys::Win32::Foundation::CloseHandle;
1210

1311
fn main() {
1412
let thread = thread::spawn(|| ());
1513

1614
unsafe {
17-
assert_ne!(CloseHandle(thread.as_raw_handle()), 0);
15+
assert_ne!(CloseHandle(thread.as_raw_handle() as _), 0);
1816
}
1917

2018
thread.join().unwrap();

src/tools/miri/tests/fail/concurrency/windows_join_main.rs renamed to src/tools/miri/tests/fail-dep/concurrency/windows_join_main.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,18 @@
66

77
use std::thread;
88

9-
extern "system" {
10-
fn WaitForSingleObject(handle: isize, timeout: u32) -> u32;
11-
}
12-
13-
const INFINITE: u32 = u32::MAX;
9+
use windows_sys::Win32::Foundation::{HANDLE, WAIT_OBJECT_0};
10+
use windows_sys::Win32::System::Threading::{WaitForSingleObject, INFINITE};
1411

1512
// XXX HACK: This is how miri represents the handle for thread 0.
1613
// This value can be "legitimately" obtained by using `GetCurrentThread` with `DuplicateHandle`
1714
// but miri does not implement `DuplicateHandle` yet.
18-
const MAIN_THREAD: isize = (2i32 << 30) as isize;
15+
const MAIN_THREAD: HANDLE = (2i32 << 30) as HANDLE;
1916

2017
fn main() {
2118
thread::spawn(|| {
2219
unsafe {
23-
assert_eq!(WaitForSingleObject(MAIN_THREAD, INFINITE), 0); //~ ERROR: deadlock: the evaluated program deadlocked
20+
assert_eq!(WaitForSingleObject(MAIN_THREAD, INFINITE), WAIT_OBJECT_0); //~ ERROR: deadlock: the evaluated program deadlocked
2421
}
2522
})
2623
.join()

src/tools/miri/tests/fail/concurrency/windows_join_main.stderr renamed to src/tools/miri/tests/fail-dep/concurrency/windows_join_main.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: deadlock: the evaluated program deadlocked
22
--> $DIR/windows_join_main.rs:LL:CC
33
|
4-
LL | assert_eq!(WaitForSingleObject(MAIN_THREAD, INFINITE), 0);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program deadlocked
4+
LL | assert_eq!(WaitForSingleObject(MAIN_THREAD, INFINITE), WAIT_OBJECT_0);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program deadlocked
66
|
77
= note: inside closure at RUSTLIB/core/src/macros/mod.rs:LL:CC
88
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)

src/tools/miri/tests/fail/concurrency/windows_join_self.rs renamed to src/tools/miri/tests/fail-dep/concurrency/windows_join_self.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,14 @@
66

77
use std::thread;
88

9-
extern "system" {
10-
fn GetCurrentThread() -> usize;
11-
fn WaitForSingleObject(handle: usize, timeout: u32) -> u32;
12-
}
13-
14-
const INFINITE: u32 = u32::MAX;
9+
use windows_sys::Win32::Foundation::WAIT_OBJECT_0;
10+
use windows_sys::Win32::System::Threading::{GetCurrentThread, WaitForSingleObject, INFINITE};
1511

1612
fn main() {
1713
thread::spawn(|| {
1814
unsafe {
1915
let native = GetCurrentThread();
20-
assert_eq!(WaitForSingleObject(native, INFINITE), 0); //~ ERROR: deadlock: the evaluated program deadlocked
16+
assert_eq!(WaitForSingleObject(native, INFINITE), WAIT_OBJECT_0); //~ ERROR: deadlock: the evaluated program deadlocked
2117
}
2218
})
2319
.join()

src/tools/miri/tests/fail/concurrency/windows_join_self.stderr renamed to src/tools/miri/tests/fail-dep/concurrency/windows_join_self.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
error: deadlock: the evaluated program deadlocked
22
--> $DIR/windows_join_self.rs:LL:CC
33
|
4-
LL | assert_eq!(WaitForSingleObject(native, INFINITE), 0);
4+
LL | assert_eq!(WaitForSingleObject(native, INFINITE), WAIT_OBJECT_0);
55
| ^ the evaluated program deadlocked
66
|
77
= note: inside closure at $DIR/windows_join_self.rs:LL:CC

src/tools/miri/tests/pass/concurrency/windows_condvar_shared.rs renamed to src/tools/miri/tests/pass-dep/concurrency/windows_condvar_shared.rs

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,29 @@
22
// We are making scheduler assumptions here.
33
//@compile-flags: -Zmiri-preemption-rate=0
44

5-
use std::ffi::c_void;
6-
use std::ptr::null_mut;
5+
use std::mem::MaybeUninit;
76
use std::thread;
87

8+
use windows_sys::Win32::System::Threading::{
9+
AcquireSRWLockExclusive, AcquireSRWLockShared, ReleaseSRWLockExclusive, ReleaseSRWLockShared,
10+
SleepConditionVariableSRW, WakeAllConditionVariable, CONDITION_VARIABLE_LOCKMODE_SHARED,
11+
INFINITE,
12+
};
13+
914
#[derive(Copy, Clone)]
1015
struct SendPtr<T>(*mut T);
1116

1217
unsafe impl<T> Send for SendPtr<T> {}
1318

14-
extern "system" {
15-
fn SleepConditionVariableSRW(
16-
condvar: *mut *mut c_void,
17-
lock: *mut *mut c_void,
18-
timeout: u32,
19-
flags: u32,
20-
) -> i32;
21-
fn WakeAllConditionVariable(condvar: *mut *mut c_void);
22-
23-
fn AcquireSRWLockExclusive(lock: *mut *mut c_void);
24-
fn AcquireSRWLockShared(lock: *mut *mut c_void);
25-
fn ReleaseSRWLockExclusive(lock: *mut *mut c_void);
26-
fn ReleaseSRWLockShared(lock: *mut *mut c_void);
27-
}
28-
29-
const CONDITION_VARIABLE_LOCKMODE_SHARED: u32 = 1;
30-
const INFINITE: u32 = u32::MAX;
31-
3219
/// threads should be able to reacquire the lock while it is locked by multiple other threads in shared mode
3320
fn all_shared() {
3421
println!("all_shared");
3522

36-
let mut lock = null_mut();
37-
let mut condvar = null_mut();
23+
let mut lock = MaybeUninit::zeroed();
24+
let mut condvar = MaybeUninit::zeroed();
3825

39-
let lock_ptr = SendPtr(&mut lock);
40-
let condvar_ptr = SendPtr(&mut condvar);
26+
let lock_ptr = SendPtr(lock.as_mut_ptr());
27+
let condvar_ptr = SendPtr(condvar.as_mut_ptr());
4128

4229
let mut handles = Vec::with_capacity(10);
4330

@@ -105,11 +92,11 @@ fn all_shared() {
10592
fn shared_sleep_and_exclusive_lock() {
10693
println!("shared_sleep_and_exclusive_lock");
10794

108-
let mut lock = null_mut();
109-
let mut condvar = null_mut();
95+
let mut lock = MaybeUninit::zeroed();
96+
let mut condvar = MaybeUninit::zeroed();
11097

111-
let lock_ptr = SendPtr(&mut lock);
112-
let condvar_ptr = SendPtr(&mut condvar);
98+
let lock_ptr = SendPtr(lock.as_mut_ptr());
99+
let condvar_ptr = SendPtr(condvar.as_mut_ptr());
113100

114101
let mut waiters = Vec::with_capacity(5);
115102
for i in 0..5 {
@@ -166,11 +153,11 @@ fn shared_sleep_and_exclusive_lock() {
166153
fn exclusive_sleep_and_shared_lock() {
167154
println!("exclusive_sleep_and_shared_lock");
168155

169-
let mut lock = null_mut();
170-
let mut condvar = null_mut();
156+
let mut lock = MaybeUninit::zeroed();
157+
let mut condvar = MaybeUninit::zeroed();
171158

172-
let lock_ptr = SendPtr(&mut lock);
173-
let condvar_ptr = SendPtr(&mut condvar);
159+
let lock_ptr = SendPtr(lock.as_mut_ptr());
160+
let condvar_ptr = SendPtr(condvar.as_mut_ptr());
174161

175162
let mut handles = Vec::with_capacity(10);
176163
for i in 0..5 {

0 commit comments

Comments
 (0)