Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2b0f119
Prepare for merging from rust-lang/rust
Jan 20, 2026
6090f88
Merge ref '63f4513795b1' from rust-lang/rust
Jan 20, 2026
ff5a250
fmt
Jan 20, 2026
24e28e7
make comment consistent
RalfJung Jan 20, 2026
0aac6d1
Merge pull request #4820 from rust-lang/rustup-2026-01-20
RalfJung Jan 20, 2026
47f3474
Prepare for merging from rust-lang/rust
Jan 21, 2026
add567b
Merge ref 'd27664687298' from rust-lang/rust
Jan 21, 2026
569b4f9
Merge pull request #4822 from rust-lang/rustup-2026-01-21
RalfJung Jan 21, 2026
a378a56
Compile-time variant of shim_sig_arg
CraftSpider Jan 6, 2026
b22c2f9
Merge pull request #4806 from CraftSpider/comp-sig
RalfJung Jan 22, 2026
c84eced
Add test for libc opendir and closedir
Islam-Imad Jan 22, 2026
9b30ff4
Prepare for merging from rust-lang/rust
Jan 23, 2026
bf04398
Merge ref 'd10ac47c2015' from rust-lang/rust
Jan 23, 2026
e4e57e5
Merge pull request #4825 from rust-lang/rustup-2026-01-23
RalfJung Jan 23, 2026
3159e80
Merge pull request #4824 from Islam-Imad/test-libc-opendir-closedir
RalfJung Jan 23, 2026
adeb4df
Unify readdir shim across Unix targets and add test
Islam-Imad Jan 20, 2026
b17a22f
used readdir_r for mac OS
Islam-Imad Jan 21, 2026
4cd367f
fix readdir on freebsd, and minor tweaks
RalfJung Jan 23, 2026
24ced66
Merge pull request #4821 from Islam-Imad/refactor/readdir
RalfJung Jan 23, 2026
3c03d82
error on DuplicateHandle of pseudo handle
beepster4096 Jan 18, 2026
1d85118
readdir: also emit the special directory entries . and ..
RalfJung Jan 24, 2026
7a937ae
add test for DuplicateHandle on a pseudo handle
RalfJung Jan 24, 2026
1046e2f
Merge pull request #4829 from RalfJung/readdir-special
RalfJung Jan 24, 2026
a3d2e99
Merge pull request #4818 from beepster4096/psuedohandling
RalfJung Jan 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/tools/miri/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ tex/*/out
*.rs.bk
.vscode
.helix
.zed
*.mm_profdata
perf.data
perf.data.old
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b6fdaf2a15736cbccf248b532f48e33179614d40
d10ac47c20152feb5e99b1c35a2e6830f77c66dc
2 changes: 1 addition & 1 deletion src/tools/miri/src/bin/miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
clippy::manual_range_contains,
clippy::useless_format,
clippy::field_reassign_with_default,
clippy::needless_lifetimes,
clippy::needless_lifetimes
)]

// The rustc crates we need
Expand Down
133 changes: 103 additions & 30 deletions src/tools/miri/src/shims/sig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,45 +28,118 @@ pub struct ShimSig<'tcx, const ARGS: usize> {
/// - `winapi::$ty` for a type from `std::sys::pal::windows::c`
#[macro_export]
macro_rules! shim_sig {
(extern $abi:literal fn($($arg:ty),* $(,)?) -> $ret:ty) => {
(extern $abi:literal fn($($args:tt)*) -> $($ret:tt)*) => {
|this| $crate::shims::sig::ShimSig {
abi: std::str::FromStr::from_str($abi).expect("incorrect abi specified"),
args: [$(shim_sig_arg!(this, $arg)),*],
ret: shim_sig_arg!(this, $ret),
args: shim_sig_args_sep!(this, [$($args)*]),
ret: shim_sig_arg!(this, $($ret)*),
}
};
}

/// Helper for `shim_sig!`.
///
/// Groups tokens into comma-separated chunks and calls the provided macro on them.
///
/// # Examples
///
/// ```ignore
/// shim_sig_args_sep!(this, [*const _, i32, libc::off64_t]);
/// // expands to:
/// [shim_sig_arg!(*const _), shim_sig_arg!(i32), shim_sig_arg!(libc::off64_t)];
/// ```
#[macro_export]
macro_rules! shim_sig_args_sep {
($this:ident, [$($tt:tt)*]) => {
shim_sig_args_sep!(@ $this [] [] $($tt)*)
};

// All below matchers form a fairly simple iterator over the input.
// - Non-comma token - append to collector
// - Comma token - call the provided macro on the collector and reset the collector
// - End of input - empty collector one last time. emit output as an array

// Handles `,` token - take collected type and call shim_sig_arg on it.
// Append the result to the final output.
(@ $this:ident [$($final:tt)*] [$($collected:tt)*] , $($tt:tt)*) => {
shim_sig_args_sep!(@ $this [$($final)* shim_sig_arg!($this, $($collected)*), ] [] $($tt)*)
};
// Handle non-comma token - append to collected type.
(@ $this:ident [$($final:tt)*] [$($collected:tt)*] $first:tt $($tt:tt)*) => {
shim_sig_args_sep!(@ $this [$($final)*] [$($collected)* $first] $($tt)*)
};
// No more tokens - emit final output, including final non-comma type.
(@ $this:ident [$($final:tt)*] [$($collected:tt)+] ) => {
[$($final)* shim_sig_arg!($this, $($collected)*)]
};
// No more tokens - emit final output.
(@ $this:ident [$($final:tt)*] [] ) => {
[$($final)*]
};
}

/// Helper for `shim_sig!`.
///
/// Converts a type
#[macro_export]
macro_rules! shim_sig_arg {
// Unfortuantely we cannot take apart a `ty`-typed token at compile time,
// so we have to stringify it and match at runtime.
($this:ident, $x:ty) => {{
match stringify!($x) {
"i8" => $this.tcx.types.i8,
"i16" => $this.tcx.types.i16,
"i32" => $this.tcx.types.i32,
"i64" => $this.tcx.types.i64,
"i128" => $this.tcx.types.i128,
"isize" => $this.tcx.types.isize,
"u8" => $this.tcx.types.u8,
"u16" => $this.tcx.types.u16,
"u32" => $this.tcx.types.u32,
"u64" => $this.tcx.types.u64,
"u128" => $this.tcx.types.u128,
"usize" => $this.tcx.types.usize,
"()" => $this.tcx.types.unit,
"bool" => $this.tcx.types.bool,
"*const _" => $this.machine.layouts.const_raw_ptr.ty,
"*mut _" => $this.machine.layouts.mut_raw_ptr.ty,
ty if let Some(win_ty) = ty.strip_prefix("winapi::") =>
$this.windows_ty_layout(win_ty).ty,
ty if ty.contains("::") =>
helpers::path_ty_layout($this, &ty.split("::").collect::<Vec<_>>()).ty,
ty => panic!("unsupported signature type {ty:?}"),
}
}};
($this:ident, i8) => {
$this.tcx.types.i8
};
($this:ident, i16) => {
$this.tcx.types.i16
};
($this:ident, i32) => {
$this.tcx.types.i32
};
($this:ident, i64) => {
$this.tcx.types.i64
};
($this:ident, i128) => {
$this.tcx.types.i128
};
($this:ident, isize) => {
$this.tcx.types.isize
};
($this:ident, u8) => {
$this.tcx.types.u8
};
($this:ident, u16) => {
$this.tcx.types.u16
};
($this:ident, u32) => {
$this.tcx.types.u32
};
($this:ident, u64) => {
$this.tcx.types.u64
};
($this:ident, u128) => {
$this.tcx.types.u128
};
($this:ident, usize) => {
$this.tcx.types.usize
};
($this:ident, ()) => {
$this.tcx.types.unit
};
($this:ident, bool) => {
$this.tcx.types.bool
};
($this:ident, *const _) => {
$this.machine.layouts.const_raw_ptr.ty
};
($this:ident, *mut _) => {
$this.machine.layouts.mut_raw_ptr.ty
};
($this:ident, winapi::$ty:ident) => {
$this.windows_ty_layout(stringify!($ty)).ty
};
($this:ident, $krate:ident :: $($path:ident)::+) => {
helpers::path_ty_layout($this, &[stringify!($krate), $(stringify!($path)),*]).ty
};
($this:ident, $($other:tt)*) => {
compile_error!(concat!("unsupported signature type: ", stringify!($($other)*)))
}
}

/// Helper function to compare two ABIs.
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/shims/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
assert_eq!(unblock, UnblockKind::TimedOut);
interp_ok(())
}
)
),
);

interp_ok(Scalar::from_i32(0)) // KERN_SUCCESS
Expand Down
8 changes: 1 addition & 7 deletions src/tools/miri/src/shims/unix/android/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
let result = this.lstat(path, buf)?;
this.write_scalar(result, dest)?;
}
"readdir" => {
// FIXME: This does not have a direct test (#3179).
let [dirp] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
let result = this.readdir64("dirent", dirp)?;
this.write_scalar(result, dest)?;
}
"pread64" => {
// FIXME: This does not have a direct test (#3179).
let [fd, buf, count, offset] = this.check_shim_sig(
Expand Down Expand Up @@ -85,7 +79,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
let fd = this.read_scalar(fd)?.to_i32()?;
let offset = this.read_scalar(offset)?.to_int(offset.layout.size)?;
let whence = this.read_scalar(whence)?.to_i32()?;
this.lseek64(fd, offset, whence, dest)?;
this.lseek(fd, offset, whence, dest)?;
}
"ftruncate64" => {
let [fd, length] = this.check_shim_sig(
Expand Down
8 changes: 5 additions & 3 deletions src/tools/miri/src/shims/unix/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.write_scalar(result, dest)?;
}
"opendir" => {
// FIXME: This does not have a direct test (#3179).
let [name] = this.check_shim_sig(
shim_sig!(extern "C" fn(*const _) -> *mut _),
link_name,
Expand All @@ -374,7 +373,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.write_scalar(result, dest)?;
}
"closedir" => {
// FIXME: This does not have a direct test (#3179).
let [dirp] = this.check_shim_sig(
shim_sig!(extern "C" fn(*mut _) -> i32),
link_name,
Expand All @@ -384,6 +382,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
let result = this.closedir(dirp)?;
this.write_scalar(result, dest)?;
}
"readdir" => {
let [dirp] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
this.readdir(dirp, dest)?;
}
"lseek" => {
// FIXME: This does not have a direct test (#3179).
let [fd, offset, whence] = this.check_shim_sig(
Expand All @@ -395,7 +397,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
let fd = this.read_scalar(fd)?.to_i32()?;
let offset = this.read_scalar(offset)?.to_int(offset.layout.size)?;
let whence = this.read_scalar(whence)?.to_i32()?;
this.lseek64(fd, offset, whence, dest)?;
this.lseek(fd, offset, whence, dest)?;
}
"ftruncate" => {
let [fd, length] = this.check_shim_sig(
Expand Down
6 changes: 2 additions & 4 deletions src/tools/miri/src/shims/unix/freebsd/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
let result = this.fstat(fd, buf)?;
this.write_scalar(result, dest)?;
}
"readdir" | "readdir@FBSD_1.0" => {
// FIXME: This does not have a direct test (#3179).
"readdir@FBSD_1.0" => {
let [dirp] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
let result = this.readdir64("dirent", dirp)?;
this.write_scalar(result, dest)?;
this.readdir(dirp, dest)?;
}
// Miscellaneous
"__error" => {
Expand Down
Loading
Loading