Skip to content

Miri subtree update #129230

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 85 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
2c166f4
Make unused states of Reserved unrepresentable
Vanille-N Jul 18, 2024
2431949
Preparing for merge from rustc
Aug 6, 2024
ac3e349
Merge from rustc
Aug 6, 2024
5b2cdc1
Auto merge of #3791 - rust-lang:rustup-2024-08-06, r=RalfJung
bors Aug 6, 2024
7d066c4
add return-place-protection tail-call test, and fix previous test
RalfJung Aug 6, 2024
c755314
Auto merge of #3792 - RalfJung:test-typo, r=RalfJung
bors Aug 6, 2024
0475bdd
Preparing for merge from rustc
Aug 7, 2024
630ad88
Merge from rustc
Aug 7, 2024
384f858
Auto merge of #3793 - rust-lang:rustup-2024-08-07, r=RalfJung
bors Aug 7, 2024
deeccf9
remove some SSE/SSE2 intrinsics that are no longer used by stdarch
RalfJung Jul 13, 2024
2f405eb
Auto merge of #3747 - RalfJung:sse-cleanup, r=RalfJung
bors Aug 7, 2024
d480954
allow all code to call getuid()
RalfJung Aug 7, 2024
dc9f4e8
Auto merge of #3794 - RalfJung:getuid, r=RalfJung
bors Aug 7, 2024
21f9175
Don't panic on `miri_print_borrow_state()` under `-Zmiri-disable-stac…
zachs18 Aug 8, 2024
6552a82
throw_unsup_format for alignment greater than 2^29 and refactor non-p…
tiif Aug 9, 2024
dc54f1d
miri_print_borrow_state: show error when AllocId is invalid
RalfJung Aug 9, 2024
d36e157
Auto merge of #3797 - zachs18:no-borrow-no-panic, r=RalfJung
bors Aug 9, 2024
bb04eab
Auto merge of #3795 - tiif:ice-layout-limit, r=RalfJung
bors Aug 10, 2024
f7c938a
miri-script: use --remap-path-prefix to print errors relative to the …
RalfJung Aug 9, 2024
d2e0970
update suggested RA config; the './miri cargo' command is not needed …
RalfJung Aug 9, 2024
118be41
add './miri doc' command
RalfJung Aug 9, 2024
8197f07
miri-script: pass around the relative crate dir, not the absolute pat…
RalfJung Aug 10, 2024
feab324
CI: we now need the nightly toolchain as well
RalfJung Aug 10, 2024
1156d58
josh: wait until the socket is ready
RalfJung Aug 10, 2024
3456432
Auto merge of #3799 - RalfJung:josh-wait, r=RalfJung
bors Aug 10, 2024
2b83935
josh-proxy: fix wait-for-josh logic
RalfJung Aug 12, 2024
3652011
Preparing for merge from rustc
RalfJung Aug 12, 2024
c0c6f28
Merge from rustc
RalfJung Aug 12, 2024
7383401
clippy fix
RalfJung Aug 12, 2024
14f9284
fix tree borrows Unique test
RalfJung Aug 12, 2024
a25ec22
Auto merge of #3801 - RalfJung:rustup, r=RalfJung
bors Aug 12, 2024
dd600ef
Auto merge of #3798 - RalfJung:miri-script-remap-path-prefix, r=saethlin
bors Aug 12, 2024
10cb5aa
borrow_tracker: update comments regarding protectors
RalfJung Aug 13, 2024
7db942b
remove the concept of a Call ID
RalfJung Aug 13, 2024
6ff09af
Auto merge of #3802 - RalfJung:no-more-call-id, r=RalfJung
bors Aug 13, 2024
ef91e65
Preparing for merge from rustc
RalfJung Aug 14, 2024
b65cdff
Merge from rustc
RalfJung Aug 14, 2024
c964938
fmt
RalfJung Aug 14, 2024
db3f921
CI: need nightly toolchain for auto-rustup PR
RalfJung Aug 14, 2024
f25ca7e
Auto merge of #3803 - RalfJung:rustup, r=RalfJung
bors Aug 14, 2024
607c4f5
Implement epoll shim
tiif Aug 14, 2024
86783be
Auto merge of #3712 - tiif:feat/epoll, r=oli-obk
bors Aug 14, 2024
293be46
add 'project' process guidlines for larger contributions
RalfJung Aug 15, 2024
17cfbc6
FD: remove big surrounding RefCell, simplify socketpair
RalfJung Aug 16, 2024
82c39ff
buf_has_writer is not needed any more
RalfJung Aug 16, 2024
34aec7c
make ecx.check_and_update_readiness a truly private helper function
RalfJung Aug 16, 2024
b4ab820
epoll test cleanup
RalfJung Aug 16, 2024
edd1efb
comment and test regarding notifications on writes that dont change r…
RalfJung Aug 16, 2024
9184eb5
more epoll test cleanup
RalfJung Aug 16, 2024
883e477
explain the behavior on closed peers
RalfJung Aug 16, 2024
1a51dd9
Auto merge of #3754 - Vanille-N:master, r=RalfJung
bors Aug 16, 2024
83f1b38
Auto merge of #3809 - RalfJung:fd-refcell, r=oli-obk
bors Aug 16, 2024
0951107
Add epoll EPOLLHUP flag support
tiif Aug 16, 2024
f9a7d6e
Move epoll_ready_events.epollhup = true up
tiif Aug 17, 2024
23b57e8
Preparing for merge from rustc
Aug 17, 2024
dc0faec
Merge from rustc
Aug 17, 2024
94e57fc
Auto merge of #3807 - RalfJung:projects, r=oli-obk
bors Aug 17, 2024
cab81d3
extend comments on HUP vs RDHUP
RalfJung Aug 17, 2024
78dfb8a
Auto merge of #3814 - tiif:epollhup, r=RalfJung
bors Aug 17, 2024
99d742e
implement pipe and pipe2
RalfJung Aug 16, 2024
5402be8
socketpair: test behavior when one end got closed
RalfJung Aug 17, 2024
5d59bde
test cleanup
RalfJung Aug 17, 2024
02a1166
SocketPair -> AnonSocket, because a single FD is not a pair
RalfJung Aug 17, 2024
db9a97f
Auto merge of #3817 - rust-lang:rustup-2024-08-17, r=RalfJung
bors Aug 17, 2024
465df56
epoll test: further clean up check_epoll_wait
RalfJung Aug 17, 2024
a4222b9
Auto merge of #3815 - RalfJung:pipe, r=RalfJung
bors Aug 17, 2024
0058752
Auto merge of #3819 - RalfJung:epoll-test, r=RalfJung
bors Aug 17, 2024
34e8245
tls_leak_main_thread_allowed: make test check target_thread_local
RalfJung Aug 17, 2024
bd4ef64
run TLS tests on Solarish
RalfJung Aug 17, 2024
3e698d0
Auto merge of #3822 - RalfJung:tls, r=RalfJung
bors Aug 17, 2024
7c81120
simplify synchronization object creation logic
RalfJung Aug 17, 2024
6ac5bbb
Auto merge of #3823 - RalfJung:sync, r=RalfJung
bors Aug 17, 2024
56eee8e
Apply test fix
tiif Aug 16, 2024
8821108
Auto merge of #3813 - tiif:epollfix, r=RalfJung
bors Aug 17, 2024
c0e799d
Set EINVAL for epoll_wait maxevent value 0
tiif Aug 17, 2024
8ae118d
Move the maxevents.try_into().unwrap() after value check
tiif Aug 18, 2024
f918de8
make sure we read all arguments before returning early
RalfJung Aug 18, 2024
aea3cfd
Auto merge of #3824 - tiif:maxeventeinval, r=RalfJung
bors Aug 18, 2024
e614d7d
epoll test_socketpair_read: explicitly check real and Miri behavior
RalfJung Aug 18, 2024
8f2768b
Auto merge of #3825 - RalfJung:epoll-miri, r=RalfJung
bors Aug 18, 2024
6702f15
epoll: iterate through output buffer then fetch an event from ready list
tiif Aug 17, 2024
9370020
Auto merge of #3818 - tiif:loseevents, r=RalfJung
bors Aug 18, 2024
483120d
Add EPOLLER support
tiif Aug 17, 2024
c74ffd8
Auto merge of #3820 - tiif:epoller, r=RalfJung
bors Aug 18, 2024
0708b28
fix build with bootstrap compiler
RalfJung Aug 18, 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
simplify synchronization object creation logic
  • Loading branch information
RalfJung committed Aug 17, 2024
commit 7c811203cd3e3f0bcdaedb6b51a81be2765bc635
26 changes: 2 additions & 24 deletions src/tools/miri/src/concurrency/init_once.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,6 @@ pub(super) struct InitOnce {
clock: VClock,
}

impl<'tcx> EvalContextExtPriv<'tcx> for crate::MiriInterpCx<'tcx> {}
trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
/// Provides the closure with the next InitOnceId. Creates that InitOnce if the closure returns None,
/// otherwise returns the value from the closure.
#[inline]
fn init_once_get_or_create<F>(&mut self, existing: F) -> InterpResult<'tcx, InitOnceId>
where
F: FnOnce(&mut MiriInterpCx<'tcx>, InitOnceId) -> InterpResult<'tcx, Option<InitOnceId>>,
{
let this = self.eval_context_mut();
let next_index = this.machine.sync.init_onces.next_index();
if let Some(old) = existing(this, next_index)? {
Ok(old)
} else {
let new_index = this.machine.sync.init_onces.push(Default::default());
assert_eq!(next_index, new_index);
Ok(new_index)
}
}
}

impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {}
pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn init_once_get_or_create_id(
Expand All @@ -56,9 +35,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
offset: u64,
) -> InterpResult<'tcx, InitOnceId> {
let this = self.eval_context_mut();
this.init_once_get_or_create(|ecx, next_id| {
ecx.get_or_create_id(next_id, lock_op, lock_layout, offset)
})
this.get_or_create_id(lock_op, lock_layout, offset, |ecx| &mut ecx.machine.sync.init_onces)?
.ok_or_else(|| err_ub_format!("init_once has invalid ID").into())
}

#[inline]
Expand Down
103 changes: 25 additions & 78 deletions src/tools/miri/src/concurrency/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,100 +164,50 @@ pub struct SynchronizationObjects {
impl<'tcx> EvalContextExtPriv<'tcx> for crate::MiriInterpCx<'tcx> {}
pub(super) trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
/// Lazily initialize the ID of this Miri sync structure.
/// ('0' indicates uninit.)
/// If memory stores '0', that indicates uninit and we generate a new instance.
/// Returns `None` if memory stores a non-zero invalid ID.
///
/// `get_objs` must return the `IndexVec` that stores all the objects of this type.
#[inline]
fn get_or_create_id<Id: SyncId>(
fn get_or_create_id<Id: SyncId + Idx, T: Default>(
&mut self,
next_id: Id,
lock_op: &OpTy<'tcx>,
lock_layout: TyAndLayout<'tcx>,
offset: u64,
get_objs: impl for<'a> Fn(&'a mut MiriInterpCx<'tcx>) -> &'a mut IndexVec<Id, T>,
) -> InterpResult<'tcx, Option<Id>> {
let this = self.eval_context_mut();
let value_place =
this.deref_pointer_and_offset(lock_op, offset, lock_layout, this.machine.layouts.u32)?;
let next_index = get_objs(this).next_index();

// Since we are lazy, this update has to be atomic.
let (old, success) = this
.atomic_compare_exchange_scalar(
&value_place,
&ImmTy::from_uint(0u32, this.machine.layouts.u32),
Scalar::from_u32(next_id.to_u32()),
Scalar::from_u32(next_index.to_u32()),
AtomicRwOrd::Relaxed, // deliberately *no* synchronization
AtomicReadOrd::Relaxed,
false,
)?
.to_scalar_pair();

Ok(if success.to_bool().expect("compare_exchange's second return value is a bool") {
// Caller of the closure needs to allocate next_id
None
} else {
Some(Id::from_u32(old.to_u32().expect("layout is u32")))
})
}

/// Provides the closure with the next MutexId. Creates that mutex if the closure returns None,
/// otherwise returns the value from the closure.
#[inline]
fn mutex_get_or_create<F>(&mut self, existing: F) -> InterpResult<'tcx, MutexId>
where
F: FnOnce(&mut MiriInterpCx<'tcx>, MutexId) -> InterpResult<'tcx, Option<MutexId>>,
{
let this = self.eval_context_mut();
let next_index = this.machine.sync.mutexes.next_index();
if let Some(old) = existing(this, next_index)? {
if this.machine.sync.mutexes.get(old).is_none() {
throw_ub_format!("mutex has invalid ID");
}
Ok(old)
} else {
let new_index = this.machine.sync.mutexes.push(Default::default());
// We set the in-memory ID to `next_index`, now also create this object in the machine
// state.
let new_index = get_objs(this).push(T::default());
assert_eq!(next_index, new_index);
Ok(new_index)
}
}

/// Provides the closure with the next RwLockId. Creates that RwLock if the closure returns None,
/// otherwise returns the value from the closure.
#[inline]
fn rwlock_get_or_create<F>(&mut self, existing: F) -> InterpResult<'tcx, RwLockId>
where
F: FnOnce(&mut MiriInterpCx<'tcx>, RwLockId) -> InterpResult<'tcx, Option<RwLockId>>,
{
let this = self.eval_context_mut();
let next_index = this.machine.sync.rwlocks.next_index();
if let Some(old) = existing(this, next_index)? {
if this.machine.sync.rwlocks.get(old).is_none() {
throw_ub_format!("rwlock has invalid ID");
}
Ok(old)
Some(new_index)
} else {
let new_index = this.machine.sync.rwlocks.push(Default::default());
assert_eq!(next_index, new_index);
Ok(new_index)
}
}

/// Provides the closure with the next CondvarId. Creates that Condvar if the closure returns None,
/// otherwise returns the value from the closure.
#[inline]
fn condvar_get_or_create<F>(&mut self, existing: F) -> InterpResult<'tcx, CondvarId>
where
F: FnOnce(&mut MiriInterpCx<'tcx>, CondvarId) -> InterpResult<'tcx, Option<CondvarId>>,
{
let this = self.eval_context_mut();
let next_index = this.machine.sync.condvars.next_index();
if let Some(old) = existing(this, next_index)? {
if this.machine.sync.condvars.get(old).is_none() {
throw_ub_format!("condvar has invalid ID");
let id = Id::from_u32(old.to_u32().expect("layout is u32"));
if get_objs(this).get(id).is_none() {
// The in-memory ID is invalid.
None
} else {
Some(id)
}
Ok(old)
} else {
let new_index = this.machine.sync.condvars.push(Default::default());
assert_eq!(next_index, new_index);
Ok(new_index)
}
})
}

fn condvar_reacquire_mutex(
Expand Down Expand Up @@ -293,9 +243,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
offset: u64,
) -> InterpResult<'tcx, MutexId> {
let this = self.eval_context_mut();
this.mutex_get_or_create(|ecx, next_id| {
ecx.get_or_create_id(next_id, lock_op, lock_layout, offset)
})
this.get_or_create_id(lock_op, lock_layout, offset, |ecx| &mut ecx.machine.sync.mutexes)?
.ok_or_else(|| err_ub_format!("mutex has invalid ID").into())
}

fn rwlock_get_or_create_id(
Expand All @@ -305,9 +254,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
offset: u64,
) -> InterpResult<'tcx, RwLockId> {
let this = self.eval_context_mut();
this.rwlock_get_or_create(|ecx, next_id| {
ecx.get_or_create_id(next_id, lock_op, lock_layout, offset)
})
this.get_or_create_id(lock_op, lock_layout, offset, |ecx| &mut ecx.machine.sync.rwlocks)?
.ok_or_else(|| err_ub_format!("rwlock has invalid ID").into())
}

fn condvar_get_or_create_id(
Expand All @@ -317,9 +265,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
offset: u64,
) -> InterpResult<'tcx, CondvarId> {
let this = self.eval_context_mut();
this.condvar_get_or_create(|ecx, next_id| {
ecx.get_or_create_id(next_id, lock_op, lock_layout, offset)
})
this.get_or_create_id(lock_op, lock_layout, offset, |ecx| &mut ecx.machine.sync.condvars)?
.ok_or_else(|| err_ub_format!("condvar has invalid ID").into())
}

#[inline]
Expand Down