Skip to content

Commit 37ddde9

Browse files
committed
Implement TryEnterCriticalSection
1 parent bb06a0c commit 37ddde9

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/shims/foreign_items/windows.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
233233
// (Windows locks are reentrant, and we have only 1 thread,
234234
// so not doing any futher checks here is at least not incorrect.)
235235
}
236+
"TryEnterCriticalSection" if this.frame().instance.to_string().starts_with("std::sys::windows::")
237+
=> {
238+
// There is only one thread, so this always succeeds and returns TRUE
239+
this.write_scalar(Scalar::from_int(1, dest.layout.size), dest)?;
240+
}
236241

237242
_ => throw_unsup_format!("can't call foreign function: {}", link_name),
238243
}

tests/run-pass/sync.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![feature(rustc_private)]
22

3-
use std::sync::{Mutex, RwLock, TryLockError};
3+
use std::sync::{Mutex, TryLockError};
44

55
extern crate libc;
66

@@ -86,6 +86,7 @@ fn test_mutex_libc_static_initializer_recursive() {
8686

8787
#[cfg(not(target_os = "windows"))]
8888
fn test_rwlock_stdlib() {
89+
use std::sync::RwLock;
8990
let rw = RwLock::new(0);
9091
{
9192
let _read_guard = rw.read().unwrap();

0 commit comments

Comments
 (0)