Skip to content

Commit 20b39b8

Browse files
authored
Rollup merge of #151341 - miri, r=RalfJung
miri subtree update Subtree update of `miri` to rust-lang/miri@2d0a4f4. Created using https://github.com/rust-lang/josh-sync. r? @ghost
2 parents 82db63b + e582ac3 commit 20b39b8

32 files changed

Lines changed: 1216 additions & 623 deletions

src/tools/miri/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ and macOS targets are usually on par. Windows is supported less well.
228228

229229
### Running tests in parallel
230230

231-
Though it implements Rust threading, Miri itself is a single-threaded interpreter.
231+
Though it implements Rust threading, Miri itself is a single-threaded interpreter
232+
(it works like a multi-threaded OS on a single-core CPU).
232233
This means that when running `cargo miri test`, you will probably see a dramatic
233234
increase in the amount of time it takes to run your whole test suite due to the
234235
inherent interpreter slowdown and a loss of parallelism.

src/tools/miri/rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f57b9e6f565a1847e83a63f3e90faa3870536c1f
1+
b6fdaf2a15736cbccf248b532f48e33179614d40

src/tools/miri/src/bin/miri.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ fn main() {
710710
if !miri_config.native_lib.is_empty() && miri_config.provenance_mode == ProvenanceMode::Strict {
711711
fatal_error!("strict provenance is not compatible with calling native functions");
712712
}
713-
// Native calls and many-seeds are an "intersting" combination.
713+
// Native calls and many-seeds are an "interesting" combination.
714714
if !miri_config.native_lib.is_empty() && many_seeds.is_some() {
715715
eprintln!(
716716
"warning: `-Zmiri-many-seeds` runs multiple instances of the program in the same address space, \

src/tools/miri/src/shims/foreign_items.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::hash_map::Entry;
22
use std::io::Write;
33
use std::path::Path;
44

5-
use rustc_abi::{Align, CanonAbi, Size};
5+
use rustc_abi::{Align, CanonAbi, ExternAbi, Size};
66
use rustc_ast::expand::allocator::NO_ALLOC_SHIM_IS_UNSTABLE;
77
use rustc_data_structures::either::Either;
88
use rustc_hir::attrs::Linkage;
@@ -435,6 +435,40 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
435435
// Return value: 0 on success, otherwise the size it would have needed.
436436
this.write_int(if success { 0 } else { needed_size }, dest)?;
437437
}
438+
"miri_thread_spawn" => {
439+
// FIXME: `check_shim_sig` does not work with function pointers.
440+
let [start_routine, func_arg] =
441+
this.check_shim_sig_lenient(abi, CanonAbi::Rust, link_name, args)?;
442+
let start_routine = this.read_pointer(start_routine)?;
443+
let func_arg = this.read_immediate(func_arg)?;
444+
445+
this.start_regular_thread(
446+
Some(dest.clone()),
447+
start_routine,
448+
ExternAbi::Rust,
449+
func_arg,
450+
this.machine.layouts.unit,
451+
)?;
452+
}
453+
"miri_thread_join" => {
454+
let [thread_id] = this.check_shim_sig(
455+
shim_sig!(extern "Rust" fn(usize) -> bool),
456+
link_name,
457+
abi,
458+
args,
459+
)?;
460+
461+
let thread = this.read_target_usize(thread_id)?;
462+
if let Ok(thread) = this.thread_id_try_from(thread) {
463+
this.join_thread_exclusive(
464+
thread,
465+
/* success_retval */ Scalar::from_bool(true),
466+
dest,
467+
)?;
468+
} else {
469+
this.write_scalar(Scalar::from_bool(false), dest)?;
470+
}
471+
}
438472
// Hint that a loop is spinning indefinitely.
439473
"miri_spin_loop" => {
440474
let [] = this.check_shim_sig_lenient(abi, CanonAbi::Rust, link_name, args)?;

src/tools/miri/src/shims/sig.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,18 @@ pub struct ShimSig<'tcx, const ARGS: usize> {
1717

1818
/// Construct a `ShimSig` with convenient syntax:
1919
/// ```rust,ignore
20-
/// shim_sig!(this, extern "C" fn (*const T, i32) -> usize)
20+
/// shim_sig!(extern "C" fn (*const T, i32) -> usize)
2121
/// ```
22+
///
23+
/// The following types are supported:
24+
/// - primitive integer types
25+
/// - `()`
26+
/// - (thin) raw pointers, written `*const _` and `*mut _` since the pointee type is irrelevant
27+
/// - `$crate::$mod::...::$ty` for a type from the given crate (most commonly that is `libc`)
28+
/// - `winapi::$ty` for a type from `std::sys::pal::windows::c`
2229
#[macro_export]
2330
macro_rules! shim_sig {
24-
(extern $abi:literal fn($($arg:ty),*) -> $ret:ty) => {
31+
(extern $abi:literal fn($($arg:ty),* $(,)?) -> $ret:ty) => {
2532
|this| $crate::shims::sig::ShimSig {
2633
abi: std::str::FromStr::from_str($abi).expect("incorrect abi specified"),
2734
args: [$(shim_sig_arg!(this, $arg)),*],
@@ -50,9 +57,13 @@ macro_rules! shim_sig_arg {
5057
"u128" => $this.tcx.types.u128,
5158
"usize" => $this.tcx.types.usize,
5259
"()" => $this.tcx.types.unit,
60+
"bool" => $this.tcx.types.bool,
5361
"*const _" => $this.machine.layouts.const_raw_ptr.ty,
5462
"*mut _" => $this.machine.layouts.mut_raw_ptr.ty,
55-
ty if let Some(libc_ty) = ty.strip_prefix("libc::") => $this.libc_ty_layout(libc_ty).ty,
63+
ty if let Some(win_ty) = ty.strip_prefix("winapi::") =>
64+
$this.windows_ty_layout(win_ty).ty,
65+
ty if ty.contains("::") =>
66+
helpers::path_ty_layout($this, &ty.split("::").collect::<Vec<_>>()).ty,
5667
ty => panic!("unsupported signature type {ty:?}"),
5768
}
5869
}};

src/tools/miri/src/shims/unix/android/foreign_items.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,25 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
2828
match link_name.as_str() {
2929
// File related shims
3030
"stat" => {
31+
// FIXME: This does not have a direct test (#3179).
3132
let [path, buf] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
3233
let result = this.stat(path, buf)?;
3334
this.write_scalar(result, dest)?;
3435
}
3536
"lstat" => {
37+
// FIXME: This does not have a direct test (#3179).
3638
let [path, buf] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
3739
let result = this.lstat(path, buf)?;
3840
this.write_scalar(result, dest)?;
3941
}
4042
"readdir" => {
43+
// FIXME: This does not have a direct test (#3179).
4144
let [dirp] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
4245
let result = this.readdir64("dirent", dirp)?;
4346
this.write_scalar(result, dest)?;
4447
}
4548
"pread64" => {
49+
// FIXME: This does not have a direct test (#3179).
4650
let [fd, buf, count, offset] = this.check_shim_sig(
4751
shim_sig!(extern "C" fn(i32, *mut _, usize, libc::off64_t) -> isize),
4852
link_name,
@@ -56,6 +60,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
5660
this.read(fd, buf, count, Some(offset), dest)?;
5761
}
5862
"pwrite64" => {
63+
// FIXME: This does not have a direct test (#3179).
5964
let [fd, buf, n, offset] = this.check_shim_sig(
6065
shim_sig!(extern "C" fn(i32, *const _, usize, libc::off64_t) -> isize),
6166
link_name,
@@ -70,6 +75,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
7075
this.write(fd, buf, count, Some(offset), dest)?;
7176
}
7277
"lseek64" => {
78+
// FIXME: This does not have a direct test (#3179).
7379
let [fd, offset, whence] = this.check_shim_sig(
7480
shim_sig!(extern "C" fn(i32, libc::off64_t, i32) -> libc::off64_t),
7581
link_name,

src/tools/miri/src/shims/unix/foreign_items.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
143143
this.write_scalar(result, dest)?;
144144
}
145145
"getcwd" => {
146+
// FIXME: This does not have a direct test (#3179).
146147
let [buf, size] = this.check_shim_sig(
147148
shim_sig!(extern "C" fn(*mut _, usize) -> *mut _),
148149
link_name,
@@ -153,6 +154,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
153154
this.write_pointer(result, dest)?;
154155
}
155156
"chdir" => {
157+
// FIXME: This does not have a direct test (#3179).
156158
let [path] = this.check_shim_sig(
157159
shim_sig!(extern "C" fn(*const _) -> i32),
158160
link_name,
@@ -209,6 +211,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
209211
this.write(fd, buf, count, None, dest)?;
210212
}
211213
"pread" => {
214+
// FIXME: This does not have a direct test (#3179).
212215
let [fd, buf, count, offset] = this.check_shim_sig(
213216
shim_sig!(extern "C" fn(i32, *mut _, usize, libc::off_t) -> isize),
214217
link_name,
@@ -222,6 +225,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
222225
this.read(fd, buf, count, Some(offset), dest)?;
223226
}
224227
"pwrite" => {
228+
// FIXME: This does not have a direct test (#3179).
225229
let [fd, buf, n, offset] = this.check_shim_sig(
226230
shim_sig!(extern "C" fn(i32, *const _, usize, libc::off_t) -> isize),
227231
link_name,
@@ -299,6 +303,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
299303
this.write_scalar(result, dest)?;
300304
}
301305
"unlink" => {
306+
// FIXME: This does not have a direct test (#3179).
302307
let [path] = this.check_shim_sig(
303308
shim_sig!(extern "C" fn(*const _) -> i32),
304309
link_name,
@@ -309,6 +314,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
309314
this.write_scalar(result, dest)?;
310315
}
311316
"symlink" => {
317+
// FIXME: This does not have a direct test (#3179).
312318
let [target, linkpath] = this.check_shim_sig(
313319
shim_sig!(extern "C" fn(*const _, *const _) -> i32),
314320
link_name,
@@ -324,6 +330,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
324330
this.write_scalar(result, dest)?;
325331
}
326332
"rename" => {
333+
// FIXME: This does not have a direct test (#3179).
327334
let [oldpath, newpath] = this.check_shim_sig(
328335
shim_sig!(extern "C" fn(*const _, *const _) -> i32),
329336
link_name,
@@ -334,6 +341,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
334341
this.write_scalar(result, dest)?;
335342
}
336343
"mkdir" => {
344+
// FIXME: This does not have a direct test (#3179).
337345
let [path, mode] = this.check_shim_sig(
338346
shim_sig!(extern "C" fn(*const _, libc::mode_t) -> i32),
339347
link_name,
@@ -344,6 +352,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
344352
this.write_scalar(result, dest)?;
345353
}
346354
"rmdir" => {
355+
// FIXME: This does not have a direct test (#3179).
347356
let [path] = this.check_shim_sig(
348357
shim_sig!(extern "C" fn(*const _) -> i32),
349358
link_name,
@@ -354,6 +363,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
354363
this.write_scalar(result, dest)?;
355364
}
356365
"opendir" => {
366+
// FIXME: This does not have a direct test (#3179).
357367
let [name] = this.check_shim_sig(
358368
shim_sig!(extern "C" fn(*const _) -> *mut _),
359369
link_name,
@@ -364,6 +374,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
364374
this.write_scalar(result, dest)?;
365375
}
366376
"closedir" => {
377+
// FIXME: This does not have a direct test (#3179).
367378
let [dirp] = this.check_shim_sig(
368379
shim_sig!(extern "C" fn(*mut _) -> i32),
369380
link_name,
@@ -374,6 +385,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
374385
this.write_scalar(result, dest)?;
375386
}
376387
"lseek" => {
388+
// FIXME: This does not have a direct test (#3179).
377389
let [fd, offset, whence] = this.check_shim_sig(
378390
shim_sig!(extern "C" fn(i32, libc::off_t, i32) -> libc::off_t),
379391
link_name,
@@ -398,6 +410,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
398410
this.write_scalar(result, dest)?;
399411
}
400412
"fsync" => {
413+
// FIXME: This does not have a direct test (#3179).
401414
let [fd] = this.check_shim_sig(
402415
shim_sig!(extern "C" fn(i32) -> i32),
403416
link_name,
@@ -408,6 +421,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
408421
this.write_scalar(result, dest)?;
409422
}
410423
"fdatasync" => {
424+
// FIXME: This does not have a direct test (#3179).
411425
let [fd] = this.check_shim_sig(
412426
shim_sig!(extern "C" fn(i32) -> i32),
413427
link_name,
@@ -659,20 +673,23 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
659673
this.write_null(dest)?;
660674
}
661675
"pthread_key_delete" => {
676+
// FIXME: This does not have a direct test (#3179).
662677
let [key] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
663678
let key = this.read_scalar(key)?.to_bits(key.layout.size)?;
664679
this.machine.tls.delete_tls_key(key)?;
665680
// Return success (0)
666681
this.write_null(dest)?;
667682
}
668683
"pthread_getspecific" => {
684+
// FIXME: This does not have a direct test (#3179).
669685
let [key] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
670686
let key = this.read_scalar(key)?.to_bits(key.layout.size)?;
671687
let active_thread = this.active_thread();
672688
let ptr = this.machine.tls.load_tls(key, active_thread, this)?;
673689
this.write_scalar(ptr, dest)?;
674690
}
675691
"pthread_setspecific" => {
692+
// FIXME: This does not have a direct test (#3179).
676693
let [key, new_ptr] =
677694
this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
678695
let key = this.read_scalar(key)?.to_bits(key.layout.size)?;
@@ -833,6 +850,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
833850
this.write_scalar(res, dest)?;
834851
}
835852
"sched_yield" => {
853+
// FIXME: This does not have a direct test (#3179).
836854
let [] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
837855
this.sched_yield()?;
838856
this.write_null(dest)?;
@@ -941,6 +959,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
941959
this.write_scalar(result, dest)?;
942960
}
943961
"pthread_atfork" => {
962+
// FIXME: This does not have a direct test (#3179).
944963
let [prepare, parent, child] =
945964
this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
946965
this.read_pointer(prepare)?;

src/tools/miri/src/shims/unix/freebsd/foreign_items.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,13 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
139139
// For those, we both intercept `func` and `call@FBSD_1.0` symbols cases
140140
// since freebsd 12 the former form can be expected.
141141
"stat" | "stat@FBSD_1.0" => {
142+
// FIXME: This does not have a direct test (#3179).
142143
let [path, buf] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
143144
let result = this.stat(path, buf)?;
144145
this.write_scalar(result, dest)?;
145146
}
146147
"lstat" | "lstat@FBSD_1.0" => {
148+
// FIXME: This does not have a direct test (#3179).
147149
let [path, buf] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
148150
let result = this.lstat(path, buf)?;
149151
this.write_scalar(result, dest)?;
@@ -154,6 +156,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
154156
this.write_scalar(result, dest)?;
155157
}
156158
"readdir" | "readdir@FBSD_1.0" => {
159+
// FIXME: This does not have a direct test (#3179).
157160
let [dirp] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
158161
let result = this.readdir64("dirent", dirp)?;
159162
this.write_scalar(result, dest)?;

src/tools/miri/src/shims/unix/linux/foreign_items.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
4545
this.write_scalar(result, dest)?;
4646
}
4747
"pread64" => {
48+
// FIXME: This does not have a direct test (#3179).
4849
let [fd, buf, count, offset] = this.check_shim_sig(
4950
shim_sig!(extern "C" fn(i32, *mut _, usize, libc::off64_t) -> isize),
5051
link_name,
@@ -58,6 +59,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
5859
this.read(fd, buf, count, Some(offset), dest)?;
5960
}
6061
"pwrite64" => {
62+
// FIXME: This does not have a direct test (#3179).
6163
let [fd, buf, n, offset] = this.check_shim_sig(
6264
shim_sig!(extern "C" fn(i32, *const _, usize, libc::off64_t) -> isize),
6365
link_name,
@@ -72,6 +74,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
7274
this.write(fd, buf, count, Some(offset), dest)?;
7375
}
7476
"lseek64" => {
77+
// FIXME: This does not have a direct test (#3179).
7578
let [fd, offset, whence] = this.check_shim_sig(
7679
shim_sig!(extern "C" fn(i32, libc::off64_t, i32) -> libc::off64_t),
7780
link_name,
@@ -111,6 +114,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
111114
this.write_scalar(result, dest)?;
112115
}
113116
"readdir64" => {
117+
// FIXME: This does not have a direct test (#3179).
114118
let [dirp] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
115119
let result = this.readdir64("dirent64", dirp)?;
116120
this.write_scalar(result, dest)?;
@@ -122,6 +126,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
122126
this.write_scalar(result, dest)?;
123127
}
124128
"statx" => {
129+
// FIXME: This does not have a direct test (#3179).
125130
let [dirfd, pathname, flags, mask, statxbuf] =
126131
this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
127132
let result = this.linux_statx(dirfd, pathname, flags, mask, statxbuf)?;

0 commit comments

Comments
 (0)