Skip to content

Commit c9ff538

Browse files
committed
more detailed error message
1 parent c8094b9 commit c9ff538

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/concurrency/data_race.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -997,14 +997,21 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
997997
)?;
998998
// Ensure the allocation is mutable. Even failing (read-only) compare_exchange need mutable
999999
// memory on many targets (i.e., they segfault if taht memory is mapped read-only), and
1000-
// atomic loads can be implemented via compare_exchange on some targets. See
1001-
// <https://github.com/rust-lang/miri/issues/2463>.
1000+
// atomic loads can be implemented via compare_exchange on some targets. There could
1001+
// possibly be some very specific exceptions to this, see
1002+
// <https://github.com/rust-lang/miri/pull/2464#discussion_r939636130> for details.
10021003
// We avoid `get_ptr_alloc` since we do *not* want to run the access hooks -- the actual
10031004
// access will happen later.
10041005
let (alloc_id, _offset, _prov) =
10051006
this.ptr_try_get_alloc_id(place.ptr).expect("there are no zero-sized atomic accesses");
10061007
if this.get_alloc_mutability(alloc_id)? == Mutability::Not {
1007-
throw_ub_format!("atomic operations cannot be performed on read-only memory");
1008+
throw_ub_format!(
1009+
"atomic operations cannot be performed on read-only memory\n\
1010+
many platforms require atomic read-modify-write instructions to be performed on writeable memory, even if the operation fails \
1011+
(and is hence nominally read-only)\n\
1012+
some platforms implement (some) atomic loads via compare-exchange, which means they do not work on read-only memory; \
1013+
it is possible that we could have an exception permitting this for specific kinds of loads so please report an issue at <https://github.com/rust-lang/miri/issues> if this is a problem for you"
1014+
);
10081015
}
10091016
Ok(())
10101017
}

0 commit comments

Comments
 (0)