Skip to content

Miri subtree update #125580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
37a37f6
Use `throw_unsup_format` instead of returning `ENOTSUP` in the mmap shim
marc0246 May 20, 2024
41c006e
Auto merge of #3610 - marc0246:missing-error-kinds, r=RalfJung
bors May 20, 2024
24138f0
Preparing for merge from rustc
RalfJung May 22, 2024
a1bc030
Merge from rustc
RalfJung May 22, 2024
abbe244
clippy
RalfJung May 22, 2024
7fd1429
Auto merge of #3623 - RalfJung:rustup, r=RalfJung
bors May 22, 2024
3f638a9
solaris/illumos localtime_r / clock_getime support enabled.
devnexen May 18, 2024
04a9a1a
Auto merge of #3614 - devnexen:illumos_time_support, r=oli-obk
bors May 22, 2024
807a0f8
Preparing for merge from rustc
May 23, 2024
f1ffb8d
Merge from rustc
May 23, 2024
400835f
fmt
May 23, 2024
6ea763b
Auto merge of #3624 - rust-lang:rustup-2024-05-23, r=RalfJung
bors May 23, 2024
56c363b
fix alloc_bytes (always allocate at least 1B)
Strophox May 23, 2024
1b374df
differentiate between layout and alloc_layout
Strophox May 23, 2024
7f5e0aa
solaris add suport for threadname.
devnexen May 23, 2024
9ce95c3
Preparing for merge from rustc
May 24, 2024
debf88a
Merge from rustc
May 24, 2024
4763eaf
fmt
May 24, 2024
10d4140
Auto merge of #3627 - rust-lang:rustup-2024-05-24, r=RalfJung
bors May 24, 2024
561bd9a
add back some tokio features
RalfJung May 24, 2024
88d519f
Auto merge of #3628 - RalfJung:tokio, r=RalfJung
bors May 24, 2024
b84620f
extend comments
RalfJung May 24, 2024
7fc41d1
Auto merge of #3625 - Strophox:miri-allocation-fix, r=RalfJung
bors May 24, 2024
008f6b3
Auto merge of #3626 - devnexen:pthread_name_illumos, r=oli-obk
bors May 24, 2024
3cfcfbf
Preparing for merge from rustc
May 25, 2024
1d0ad04
Merge from rustc
May 25, 2024
331bb3f
Auto merge of #3630 - rust-lang:rustup-2024-05-25, r=saethlin
bors May 25, 2024
5fa30f7
make release_clock always work on the current thread
RalfJung May 26, 2024
a131243
completely refactor how we manage blocking and unblocking threads
RalfJung May 26, 2024
e6bb468
data_race: vector indices can be reused immediately when the thread i…
RalfJung May 26, 2024
cbec128
fix './miri run --dep --target _'
RalfJung May 26, 2024
e09bf56
Auto merge of #3633 - RalfJung:target, r=RalfJung
bors May 26, 2024
350f5c8
unix/fs: a bit of cleanup in macos_fbsd_readdir_r
RalfJung May 26, 2024
8e861c6
Auto merge of #3632 - RalfJung:readdir, r=RalfJung
bors May 26, 2024
2e89443
add a macro to declare thread unblock callbacks
RalfJung May 26, 2024
0963353
Auto merge of #3631 - RalfJung:blocking-refactor, r=RalfJung
bors May 26, 2024
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
Prev Previous commit
Next Next commit
fix alloc_bytes (always allocate at least 1B)
  • Loading branch information
Strophox committed May 23, 2024
commit 56c363b43e04803e891f242e78efc0c53230314f
37 changes: 15 additions & 22 deletions src/tools/miri/src/alloc_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ pub struct MiriAllocBytes {
/// Stored layout information about the allocation.
layout: alloc::Layout,
/// Pointer to the allocation contents.
/// Invariant:
/// * If `self.layout.size() == 0`, then `self.ptr` is some suitably aligned pointer
/// without provenance (and no actual memory was allocated).
/// * Otherwise, `self.ptr` points to memory allocated with `self.layout`.
/// Invariant: `self.ptr` points to memory allocated with `self.layout`.
ptr: *mut u8,
}

Expand All @@ -30,10 +27,8 @@ impl Clone for MiriAllocBytes {

impl Drop for MiriAllocBytes {
fn drop(&mut self) {
if self.layout.size() != 0 {
// SAFETY: Invariant, `self.ptr` points to memory allocated with `self.layout`.
unsafe { alloc::dealloc(self.ptr, self.layout) }
}
// SAFETY: Invariant, `self.ptr` points to memory allocated with `self.layout`.
unsafe { alloc::dealloc(self.ptr, self.layout) }
}
}

Expand All @@ -58,25 +53,23 @@ impl std::ops::DerefMut for MiriAllocBytes {
impl MiriAllocBytes {
/// This method factors out how a `MiriAllocBytes` object is allocated,
/// specifically given an allocation function `alloc_fn`.
/// `alloc_fn` is only used if `size != 0`.
/// Returns `Err(layout)` if the allocation function returns a `ptr` that is `ptr.is_null()`.
/// `alloc_fn` is only used with `size != 0`.
/// Returns `Err(layout)` if the allocation function returns a `ptr` where `ptr.is_null()`.
fn alloc_with(
size: usize,
align: usize,
alloc_fn: impl FnOnce(Layout) -> *mut u8,
) -> Result<MiriAllocBytes, Layout> {
// When size is 0 we allocate 1 byte anyway, so addresses don't possibly overlap.
let size = if size == 0 { 1 } else { size };
let layout = Layout::from_size_align(size, align).unwrap();
let ptr = if size == 0 {
std::ptr::without_provenance_mut(align)
let ptr = alloc_fn(layout);
if ptr.is_null() {
Err(layout)
} else {
let ptr = alloc_fn(layout);
if ptr.is_null() {
return Err(layout);
}
ptr
};
// SAFETY: All `MiriAllocBytes` invariants are fulfilled.
Ok(Self { ptr, layout })
// SAFETY: All `MiriAllocBytes` invariants are fulfilled.
Ok(Self { ptr, layout })
}
}
}

Expand All @@ -85,7 +78,7 @@ impl AllocBytes for MiriAllocBytes {
let slice = slice.into();
let size = slice.len();
let align = align.bytes_usize();
// SAFETY: `alloc_fn` will only be used if `size != 0`.
// SAFETY: `alloc_fn` will only be used with `size != 0`.
let alloc_fn = |layout| unsafe { alloc::alloc(layout) };
let alloc_bytes = MiriAllocBytes::alloc_with(size, align, alloc_fn)
.unwrap_or_else(|layout| alloc::handle_alloc_error(layout));
Expand All @@ -98,7 +91,7 @@ impl AllocBytes for MiriAllocBytes {
fn zeroed(size: Size, align: Align) -> Option<Self> {
let size = size.bytes_usize();
let align = align.bytes_usize();
// SAFETY: `alloc_fn` will only be used if `size != 0`.
// SAFETY: `alloc_fn` will only be used with `size != 0`.
let alloc_fn = |layout| unsafe { alloc::alloc_zeroed(layout) };
MiriAllocBytes::alloc_with(size, align, alloc_fn).ok()
}
Expand Down
1 change: 0 additions & 1 deletion src/tools/miri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#![feature(lint_reasons)]
#![feature(trait_upcasting)]
#![feature(strict_overflow_ops)]
#![feature(strict_provenance)]
// Configure clippy and other lints
#![allow(
clippy::collapsible_else_if,
Expand Down