Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
9e442c1
Preparing for merge from rustc
Jun 17, 2024
6b19af8
Merge from rustc
Jun 17, 2024
b8db9f0
show proper UB when making a too large allocation request
RalfJung Jun 17, 2024
4b1376a
Auto merge of #3682 - RalfJung:alloc-too-large, r=RalfJung
bors Jun 17, 2024
c84fa48
Auto merge of #3681 - rust-lang:rustup-2024-06-17, r=RalfJung
bors Jun 17, 2024
54594d6
tell people how to set miri flags
RalfJung Jun 17, 2024
af55a4a
Auto merge of #3683 - RalfJung:MIRIFLAGS, r=RalfJung
bors Jun 17, 2024
028f437
Preparing for merge from rustc
Jun 18, 2024
ca06b3b
Merge from rustc
Jun 18, 2024
62ef90c
Auto merge of #3684 - rust-lang:rustup-2024-06-18, r=RalfJung
bors Jun 18, 2024
d9f1d55
Preparing for merge from rustc
Jun 19, 2024
3e93254
Merge from rustc
Jun 19, 2024
ac4f1c4
Auto merge of #3685 - rust-lang:rustup-2024-06-19, r=RalfJung
bors Jun 19, 2024
68c84b6
Implement LLVM x86 bmi intrinsics
TDecking Jun 15, 2024
66ad792
Auto merge of #3674 - TDecking:bmi, r=RalfJung
bors Jun 20, 2024
c741315
Fix ICE caused by seeking past `i64::MAX`
adwinwhite Jun 20, 2024
121b06b
Preparing for merge from rustc
Jun 21, 2024
9d7de1f
Merge from rustc
Jun 21, 2024
79c9c80
Use strict ops instead of checked ops
southball Jun 21, 2024
1ee4a5a
Fix some missing ones
southball Jun 21, 2024
f1a7941
Auto merge of #3693 - rust-lang:rustup-2024-06-21, r=oli-obk
bors Jun 21, 2024
8a657f9
don't rely on libc existing on Windows
RalfJung Jun 21, 2024
53f8175
Auto merge of #3695 - RalfJung:no-libc-on-win, r=RalfJung
bors Jun 21, 2024
be307ca
Auto merge of #3694 - southball:fix/use_strict_ops_instead_of_checked…
bors Jun 21, 2024
4be2c66
Auto merge of #3689 - adwinwhite:lseek64, r=RalfJung
bors Jun 21, 2024
9afd752
Implement LLVM x86 adx intrinsics
TDecking Jun 20, 2024
ed83f1a
Move out addition logic
TDecking Jun 21, 2024
eaacf00
CI: try to share setup code across actions
RalfJung Jun 21, 2024
de8f05c
Auto merge of #3696 - RalfJung:ci, r=oli-obk
bors Jun 21, 2024
699b7d4
./miri: nicer error when building miri-script fails
RalfJung Jun 22, 2024
51363f5
Auto merge of #3700 - RalfJung:miri-script, r=RalfJung
bors Jun 22, 2024
dd2bd5b
evaluate arguments first, not inside the logic
RalfJung Jun 22, 2024
6d9fd24
Auto merge of #3690 - TDecking:adx, r=RalfJung
bors Jun 22, 2024
22bbff1
nicer batch file error when building miri-script fails
RossSmyth Jun 23, 2024
f91411b
Preparing for merge from rustc
Jun 23, 2024
d5feca9
Merge from rustc
Jun 23, 2024
d73be70
fmt
Jun 23, 2024
a25cb8a
Auto merge of #3704 - rust-lang:rustup-2024-06-23, r=RalfJung
bors Jun 23, 2024
9a42436
Auto merge of #3703 - RossSmyth:ms-err, r=RalfJung
bors Jun 23, 2024
903a424
unix/foreign_items: move getpid to the right part of the file
RalfJung Jun 23, 2024
aded2be
Auto merge of #3705 - RalfJung:getpid, r=RalfJung
bors Jun 23, 2024
732e687
Preparing for merge from rustc
Jun 24, 2024
c660016
Merge from rustc
Jun 24, 2024
b8e1d7e
Auto merge of #3706 - rust-lang:rustup-2024-06-24, r=oli-obk
bors Jun 24, 2024
f071a20
tests for when a thread-local gets initialized in a tls dtor
RalfJung Jun 24, 2024
4f8dc8f
Auto merge of #3708 - RalfJung:tls-dtor-in-dtor, r=RalfJung
bors Jun 24, 2024
0f114ec
clarify the warning shown when optimizations are enabled
RalfJung Jun 24, 2024
ba61c8f
clarify the status of Tree Borrows
RalfJung Jun 24, 2024
8a8b357
Auto merge of #3709 - RalfJung:docs-clarifications, r=saethlin
bors Jun 24, 2024
c6b2523
Preparing for merge from rustc
saethlin Jun 25, 2024
8f688d2
Merge from rustc
saethlin Jun 25, 2024
fc94ce2
Auto merge of #3711 - saethlin:rustup, r=saethlin
bors Jun 25, 2024
c8a89b0
Preparing for merge from rustc
Jun 27, 2024
a4e601f
Merge from rustc
Jun 27, 2024
4cc16a5
tame unexpected_cfgs
RalfJung Jun 27, 2024
b280af4
Auto merge of #3713 - rust-lang:rustup-2024-06-27, r=RalfJung
bors Jun 27, 2024
5ae2b37
Fix miri.bat
cgettys-microsoft Jun 27, 2024
9d69154
Relocate GetCurrentProcessId to Environment Related shims, remove unn…
cgettys-microsoft Jun 27, 2024
e7e35d7
Switch to the explicit parens version
cgettys-microsoft Jun 27, 2024
b687053
Preparing for merge from rustc
Jun 28, 2024
92b837b
Merge from rustc
Jun 28, 2024
9c21872
Auto merge of #3716 - cgettys-microsoft:dev/cgettys/process_id_fixup-…
bors Jun 28, 2024
340b98a
Auto merge of #3715 - cgettys-microsoft:dev/cgettys/process_id_fixup-…
bors Jun 28, 2024
afec0ab
Bless clippy
oli-obk Jun 28, 2024
1a7fce0
Auto merge of #3717 - rust-lang:rustup-2024-06-28, r=oli-obk
bors Jun 28, 2024
db243de
readme: tweak wording around soundness
RalfJung Jun 28, 2024
c471589
Auto merge of #3718 - RalfJung:readme, r=oli-obk
bors Jun 28, 2024
64c8366
Preparing for merge from rustc
Jun 29, 2024
ec7bcc0
Merge from rustc
Jun 29, 2024
abb5826
Auto merge of #3721 - rust-lang:rustup-2024-06-29, r=RalfJung
bors Jun 29, 2024
66a885b
iter_exported_symbols: also walk used statics in local crate
RalfJung Jun 29, 2024
9d920ed
Auto merge of #3723 - RalfJung:win-tls-callback, r=RalfJung
bors Jun 29, 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
24 changes: 14 additions & 10 deletions src/tools/miri/src/alloc_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,19 @@ impl MiriAllocBytes {
/// If `size == 0` we allocate using a different `alloc_layout` with `size = 1`, to ensure each allocation has a unique address.
/// Returns `Err(alloc_layout)` if the allocation function returns a `ptr` where `ptr.is_null()`.
fn alloc_with(
size: usize,
align: usize,
size: u64,
align: u64,
alloc_fn: impl FnOnce(Layout) -> *mut u8,
) -> Result<MiriAllocBytes, Layout> {
let layout = Layout::from_size_align(size, align).unwrap();
) -> Result<MiriAllocBytes, ()> {
let size = usize::try_from(size).map_err(|_| ())?;
let align = usize::try_from(align).map_err(|_| ())?;
let layout = Layout::from_size_align(size, align).map_err(|_| ())?;
// When size is 0 we allocate 1 byte anyway, to ensure each allocation has a unique address.
let alloc_layout =
if size == 0 { Layout::from_size_align(1, align).unwrap() } else { layout };
let ptr = alloc_fn(alloc_layout);
if ptr.is_null() {
Err(alloc_layout)
Err(())
} else {
// SAFETY: All `MiriAllocBytes` invariants are fulfilled.
Ok(Self { ptr, layout })
Expand All @@ -86,20 +88,22 @@ impl AllocBytes for MiriAllocBytes {
fn from_bytes<'a>(slice: impl Into<Cow<'a, [u8]>>, align: Align) -> Self {
let slice = slice.into();
let size = slice.len();
let align = align.bytes_usize();
let align = align.bytes();
// 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));
let alloc_bytes = MiriAllocBytes::alloc_with(size.try_into().unwrap(), align, alloc_fn)
.unwrap_or_else(|()| {
panic!("Miri ran out of memory: cannot create allocation of {size} bytes")
});
// SAFETY: `alloc_bytes.ptr` and `slice.as_ptr()` are non-null, properly aligned
// and valid for the `size`-many bytes to be copied.
unsafe { alloc_bytes.ptr.copy_from(slice.as_ptr(), size) };
alloc_bytes
}

fn zeroed(size: Size, align: Align) -> Option<Self> {
let size = size.bytes_usize();
let align = align.bytes_usize();
let size = size.bytes();
let align = align.bytes();
// 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
12 changes: 0 additions & 12 deletions src/tools/miri/src/shims/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@ use rustc_target::abi::{Align, Size};

use crate::*;

/// Check some basic requirements for this allocation request:
/// non-zero size, power-of-two alignment.
pub(super) fn check_alloc_request<'tcx>(size: u64, align: u64) -> InterpResult<'tcx> {
if size == 0 {
throw_ub_format!("creating allocation with size 0");
}
if !align.is_power_of_two() {
throw_ub_format!("creating allocation with non-power-of-two alignment {}", align);
}
Ok(())
}

impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {}
pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
/// Returns the alignment that `malloc` would guarantee for requests of the given size.
Expand Down
24 changes: 20 additions & 4 deletions src/tools/miri/src/shims/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_target::{
spec::abi::Abi,
};

use super::alloc::{check_alloc_request, EvalContextExt as _};
use super::alloc::EvalContextExt as _;
use super::backtrace::EvalContextExt as _;
use crate::*;
use helpers::{ToHost, ToSoft};
Expand Down Expand Up @@ -204,6 +204,22 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {

impl<'tcx> EvalContextExtPriv<'tcx> for crate::MiriInterpCx<'tcx> {}
trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
/// Check some basic requirements for this allocation request:
/// non-zero size, power-of-two alignment.
fn check_rustc_alloc_request(&self, size: u64, align: u64) -> InterpResult<'tcx> {
let this = self.eval_context_ref();
if size == 0 {
throw_ub_format!("creating allocation with size 0");
}
if i128::from(size) > this.tcx.data_layout.pointer_size.signed_int_max() {
throw_ub_format!("creating an allocation larger than half the address space");
}
if !align.is_power_of_two() {
throw_ub_format!("creating allocation with non-power-of-two alignment {}", align);
}
Ok(())
}

fn emulate_foreign_item_inner(
&mut self,
link_name: Symbol,
Expand Down Expand Up @@ -462,7 +478,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
let size = this.read_target_usize(size)?;
let align = this.read_target_usize(align)?;

check_alloc_request(size, align)?;
this.check_rustc_alloc_request(size, align)?;

let memory_kind = match link_name.as_str() {
"__rust_alloc" => MiriMemoryKind::Rust,
Expand Down Expand Up @@ -496,7 +512,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
let size = this.read_target_usize(size)?;
let align = this.read_target_usize(align)?;

check_alloc_request(size, align)?;
this.check_rustc_alloc_request(size, align)?;

let ptr = this.allocate_ptr(
Size::from_bytes(size),
Expand Down Expand Up @@ -560,7 +576,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
let new_size = this.read_target_usize(new_size)?;
// No need to check old_size; we anyway check that they match the allocation.

check_alloc_request(new_size, align)?;
this.check_rustc_alloc_request(new_size, align)?;

let align = Align::from_bytes(align).unwrap();
let new_ptr = this.reallocate_ptr(
Expand Down
10 changes: 10 additions & 0 deletions src/tools/miri/tests/fail/alloc/too_large.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extern "Rust" {
fn __rust_alloc(size: usize, align: usize) -> *mut u8;
}

fn main() {
let bytes = isize::MAX as usize + 1;
unsafe {
__rust_alloc(bytes, 1); //~ERROR: larger than half the address space
}
}
15 changes: 15 additions & 0 deletions src/tools/miri/tests/fail/alloc/too_large.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: Undefined Behavior: creating an allocation larger than half the address space
--> $DIR/too_large.rs:LL:CC
|
LL | __rust_alloc(bytes, 1);
| ^^^^^^^^^^^^^^^^^^^^^^ creating an allocation larger than half the address space
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: BACKTRACE:
= note: inside `main` at $DIR/too_large.rs:LL:CC

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to 1 previous error