Skip to content

Commit e0187f1

Browse files
committedNov 27, 2021
Do not use atomic reads on platforms without atomic support in LLVM.
1 parent b81db2f commit e0187f1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
 

‎src/mem/impls.rs

+10
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ pub unsafe fn copy_forward(mut dest: *mut u8, mut src: *const u8, mut n: usize)
6262
// Realign src
6363
let mut src_aligned = (src as usize & !WORD_MASK) as *mut usize;
6464
// This will read (but won't use) bytes out of bound.
65+
// cfg needed because not all targets will have atomic loads that can be lowered
66+
// (e.g. BPF, MSP430), or provided by an external library (e.g. RV32I)
67+
#[cfg(target_has_atomic_load_store = "ptr")]
6568
let mut prev_word = core::intrinsics::atomic_load_unordered(src_aligned);
69+
#[cfg(not(target_has_atomic_load_store = "ptr"))]
70+
let mut prev_word = core::ptr::read_volatile(src_aligned);
6671

6772
while dest_usize < dest_end {
6873
src_aligned = src_aligned.add(1);
@@ -155,7 +160,12 @@ pub unsafe fn copy_backward(dest: *mut u8, src: *const u8, mut n: usize) {
155160
// Realign src_aligned
156161
let mut src_aligned = (src as usize & !WORD_MASK) as *mut usize;
157162
// This will read (but won't use) bytes out of bound.
163+
// cfg needed because not all targets will have atomic loads that can be lowered
164+
// (e.g. BPF, MSP430), or provided by an external library (e.g. RV32I)
165+
#[cfg(target_has_atomic_load_store = "ptr")]
158166
let mut prev_word = core::intrinsics::atomic_load_unordered(src_aligned);
167+
#[cfg(not(target_has_atomic_load_store = "ptr"))]
168+
let mut prev_word = core::ptr::read_volatile(src_aligned);
159169

160170
while dest_start < dest_usize {
161171
src_aligned = src_aligned.sub(1);

0 commit comments

Comments
 (0)
Please sign in to comment.