Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
a02ec4c
remove HRTB from `[T]::is_sorted_by{,_key}`
Oct 12, 2022
f3d7b39
add regression test
Oct 12, 2022
aaa2392
Merge from rustc
RalfJung Nov 5, 2022
42e450d
Auto merge of #2650 - RalfJung:rustup, r=RalfJung
bors Nov 5, 2022
4828edf
Auto merge of #2638 - DrMeepster:windows-condvars, r=RalfJung
bors Nov 6, 2022
46d0df4
remove a stray stderr file
RalfJung Nov 6, 2022
724c1a0
Auto merge of #2653 - RalfJung:stderr, r=RalfJung
bors Nov 6, 2022
943f88b
README: Add macos cache deletion command
mkroening Nov 6, 2022
57d06f7
Auto merge of #2654 - mkroening:macos-cache, r=RalfJung
bors Nov 6, 2022
1f0a672
bump rustc-build-sysroot
RalfJung Nov 6, 2022
9c574d8
Auto merge of #2655 - RalfJung:rustc-build-sysroot, r=RalfJung
bors Nov 6, 2022
2b39687
Add miri_alloc, miri_dealloc
mkroening Nov 7, 2022
de562ec
Bump ui test
oli-obk Nov 8, 2022
71c3ecf
Auto merge of #2659 - oli-obk:ui_test_bump, r=RalfJung
bors Nov 8, 2022
c02fa89
Merge from rustc
RalfJung Nov 10, 2022
9356627
Auto merge of #2662 - RalfJung:rustup, r=RalfJung
bors Nov 10, 2022
b9ccc46
Minimal implementation of implicit deref patterns
fee1-dead Jul 5, 2022
f6123c5
Add feature gate
fee1-dead Jul 5, 2022
f06efcd
Move a ui test to make space for new folder
fee1-dead Jul 5, 2022
1a75a9b
Adding more tests
fee1-dead Jul 13, 2022
422b935
Add `rustc_baked_icu_data` crate.
crlf0710 Nov 5, 2022
18a1de2
Migrate diagnostics list output to use icu list formatter.
crlf0710 Nov 6, 2022
1ebe279
Import icu locale fallback data
crlf0710 Nov 6, 2022
9f6c6bd
Enable icu sync feature for parallel compiler
crlf0710 Nov 6, 2022
4c24176
Include `zh` locale in icu data
crlf0710 Nov 6, 2022
332f79e
Rm diagnostic item, use lang item
fee1-dead Jul 5, 2022
26be4ab
rename to `string_deref_patterns`
fee1-dead Nov 11, 2022
ecaf5f7
Fix compilation issue after rebase
crlf0710 Nov 12, 2022
6adb2df
pthread: slight refactoring of how we access the sync object fields
RalfJung Nov 13, 2022
2e6676d
Auto merge of #2663 - RalfJung:sync, r=RalfJung
bors Nov 13, 2022
096c33f
final tweaks
RalfJung Nov 13, 2022
9ef0de9
Auto merge of #2657 - mkroening:miri-alloc, r=RalfJung
bors Nov 13, 2022
269ce36
migrating rustc_resolve to SessionDiagnostic. work in progress. start
rajputrajat Sep 5, 2022
8d7f257
Merge from rustc
RalfJung Nov 15, 2022
c6649aa
Auto merge of #2665 - RalfJung:rustup, r=RalfJung
bors Nov 15, 2022
3c72492
update josh instructions
RalfJung Nov 15, 2022
a046f62
Auto merge of #2666 - RalfJung:josh, r=RalfJung
bors Nov 15, 2022
a47e431
adjust josh pushing and remove ./miri toolchain updating the toolchai…
RalfJung Nov 15, 2022
209bcbb
Auto merge of #2667 - RalfJung:josh, r=RalfJung
bors Nov 15, 2022
5516273
update lockfile
RalfJung Nov 15, 2022
d75c76d
Update crate documentation of `rustc_baked_icu_data` crate
crlf0710 Nov 15, 2022
6906f08
allow fastrand dependency
RalfJung Nov 16, 2022
157b2d5
ensure rand has its default features enabled
RalfJung Nov 16, 2022
9539eef
Rollup merge of #98914 - fee1-dead-contrib:min-deref-patterns, r=comp…
Manishearth Nov 16, 2022
9cab6ca
Rollup merge of #101162 - rajputrajat:master, r=davidtwco
Manishearth Nov 16, 2022
a396240
Rollup merge of #102977 - lukas-code:is-sorted-hrtb, r=m-ou-se
Manishearth Nov 16, 2022
fbc93c5
Rollup merge of #104047 - crlf0710:icu_based_list_formatting, r=david…
Manishearth Nov 16, 2022
82f40e0
Rollup merge of #104456 - RalfJung:miri, r=RalfJung
Manishearth Nov 16, 2022
e31f007
coalesce lockfile changes
Manishearth Nov 16, 2022
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
Add miri_alloc, miri_dealloc
  • Loading branch information
mkroening committed Nov 7, 2022
commit 2b396870537cc73b0e6d974e833b057194a67ae7
9 changes: 9 additions & 0 deletions src/tools/miri/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,15 @@ extern "Rust" {
/// program) the contents of a section of program memory, as bytes. Bytes
/// written using this function will emerge from the interpreter's stderr.
fn miri_write_to_stderr(bytes: &[u8]);

/// Miri-provided extern function to allocate memory from the interpreter.
///
/// This is useful when no fundamental way of allocating memory is
/// available, e.g. when using `no_std` + `alloc`.
fn miri_alloc(size: usize, align: usize) -> *mut u8;

/// Miri-provided extern function to deallocate memory.
fn miri_dealloc(ptr: *mut u8, size: usize, align: usize);
}
```

Expand Down
5 changes: 4 additions & 1 deletion src/tools/miri/src/concurrency/data_race.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,10 @@ impl VClockAlloc {
let (alloc_timestamp, alloc_index) = match kind {
// User allocated and stack memory should track allocation.
MemoryKind::Machine(
MiriMemoryKind::Rust | MiriMemoryKind::C | MiriMemoryKind::WinHeap,
MiriMemoryKind::Rust
| MiriMemoryKind::Miri
| MiriMemoryKind::C
| MiriMemoryKind::WinHeap,
)
| MemoryKind::Stack => {
let (alloc_index, clocks) = global.current_thread_state(thread_mgr);
Expand Down
5 changes: 4 additions & 1 deletion src/tools/miri/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ impl VisitTags for FrameData<'_> {
pub enum MiriMemoryKind {
/// `__rust_alloc` memory.
Rust,
/// `miri_alloc` memory.
Miri,
/// `malloc` memory.
C,
/// Windows `HeapAlloc` memory.
Expand Down Expand Up @@ -110,7 +112,7 @@ impl MayLeak for MiriMemoryKind {
fn may_leak(self) -> bool {
use self::MiriMemoryKind::*;
match self {
Rust | C | WinHeap | Runtime => false,
Rust | Miri | C | WinHeap | Runtime => false,
Machine | Global | ExternStatic | Tls => true,
}
}
Expand All @@ -121,6 +123,7 @@ impl fmt::Display for MiriMemoryKind {
use self::MiriMemoryKind::*;
match self {
Rust => write!(f, "Rust heap"),
Miri => write!(f, "Miri heap"),
C => write!(f, "C heap"),
WinHeap => write!(f, "Windows heap"),
Machine => write!(f, "machine-managed memory"),
Expand Down
46 changes: 38 additions & 8 deletions src/tools/miri/src/shims/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,22 +513,37 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
}

// Rust allocation
"__rust_alloc" => {
"__rust_alloc" | "miri_alloc" => {
let [size, align] = this.check_shim(abi, Abi::Rust, link_name, args)?;
let size = this.read_scalar(size)?.to_machine_usize(this)?;
let align = this.read_scalar(align)?.to_machine_usize(this)?;

return this.emulate_allocator(Symbol::intern("__rg_alloc"), |this| {
let default = |this: &mut MiriInterpCx<'mir, 'tcx>| {
Self::check_alloc_request(size, align)?;

let memory_kind = match link_name.as_str() {
"__rust_alloc" => MiriMemoryKind::Rust,
"miri_alloc" => MiriMemoryKind::Miri,
_ => unreachable!(),
};

let ptr = this.allocate_ptr(
Size::from_bytes(size),
Align::from_bytes(align).unwrap(),
MiriMemoryKind::Rust.into(),
memory_kind.into(),
)?;

this.write_pointer(ptr, dest)
});
};

match link_name.as_str() {
"__rust_alloc" => return this.emulate_allocator(Symbol::intern("__rg_alloc"), default),
"miri_alloc" => {
default(this)?;
return Ok(EmulateByNameResult::NeedsJumping);
},
_ => unreachable!(),
}
}
"__rust_alloc_zeroed" => {
let [size, align] = this.check_shim(abi, Abi::Rust, link_name, args)?;
Expand All @@ -549,20 +564,35 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
this.write_pointer(ptr, dest)
});
}
"__rust_dealloc" => {
"__rust_dealloc" | "miri_dealloc" => {
let [ptr, old_size, align] = this.check_shim(abi, Abi::Rust, link_name, args)?;
let ptr = this.read_pointer(ptr)?;
let old_size = this.read_scalar(old_size)?.to_machine_usize(this)?;
let align = this.read_scalar(align)?.to_machine_usize(this)?;

return this.emulate_allocator(Symbol::intern("__rg_dealloc"), |this| {
let default = |this: &mut MiriInterpCx<'mir, 'tcx>| {
let memory_kind = match link_name.as_str() {
"__rust_dealloc" => MiriMemoryKind::Rust,
"miri_dealloc" => MiriMemoryKind::Miri,
_ => unreachable!(),
};

// No need to check old_size/align; we anyway check that they match the allocation.
this.deallocate_ptr(
ptr,
Some((Size::from_bytes(old_size), Align::from_bytes(align).unwrap())),
MiriMemoryKind::Rust.into(),
memory_kind.into(),
)
});
};

match link_name.as_str() {
"__rust_dealloc" => return this.emulate_allocator(Symbol::intern("__rg_dealloc"), default),
"miri_dealloc" => {
default(this)?;
return Ok(EmulateByNameResult::NeedsJumping);
}
_ => unreachable!(),
}
}
"__rust_realloc" => {
let [ptr, old_size, align, new_size] = this.check_shim(abi, Abi::Rust, link_name, args)?;
Expand Down
29 changes: 29 additions & 0 deletions src/tools/miri/tests/pass/miri-alloc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#![feature(lang_items, start)]
#![no_std]
// windows tls dtors go through libstd right now, thus this test
// cannot pass. When windows tls dtors go through the special magic
// windows linker section, we can run this test on windows again.
//@ignore-target-windows: no-std not supported on Windows

extern "Rust" {
fn miri_alloc(size: usize, align: usize) -> *mut u8;
fn miri_dealloc(ptr: *mut u8, size: usize, align: usize);
}

#[start]
fn start(_: isize, _: *const *const u8) -> isize {
unsafe {
let ptr = miri_alloc(123, 1);
core::ptr::write_bytes(ptr, 0, 123);
miri_dealloc(ptr, 123, 1);
}
0
}

#[panic_handler]
fn panic_handler(_: &core::panic::PanicInfo) -> ! {
loop {}
}

#[lang = "eh_personality"]
fn eh_personality() {}