Skip to content

Commit ee987b5

Browse files
bors[bot]taiki-e
andauthored
Merge #5
5: Fix docs about uninitialized bytes r=taiki-e a=taiki-e Based on [the feedback](#1 (comment)) from `@RalfJung.` Co-authored-by: Taiki Endo <[email protected]>
2 parents 2a2010a + e53bb93 commit ee987b5

File tree

4 files changed

+6
-139
lines changed

4 files changed

+6
-139
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ See [P1478R1][p1478r1] for more.
1818
- If the alignment of the type being copied is the same as the pointer width, `atomic_load` is possible to produce an assembly roughly equivalent to the case of using volatile read + atomic fence on many platforms. (e.g., [aarch64](https://github.com/taiki-e/atomic-memcpy/blob/HEAD/tests/asm-test/asm/aarch64-unknown-linux-gnu/atomic_memcpy_load_align8), [riscv64](https://github.com/taiki-e/atomic-memcpy/blob/main/tests/asm-test/asm/riscv64gc-unknown-linux-gnu/atomic_memcpy_load_align8). See [`tests/asm-test/asm`][asm-test] directory for more).
1919
- If the alignment of the type being copied is smaller than the pointer width, there will be some performance degradation. However, it is implemented in such a way that it does not cause extreme performance degradation at least on x86_64. (See [the implementation comments of `atomic_load`][implementation] for more.) It is possible that there is still room for improvement, especially on non-x86_64 platforms.
2020
- Optimization for the case where the alignment of the type being copied is larger than the pointer width has not yet been fully investigated. It is possible that there is still room for improvement, especially on 32-bit platforms where `AtomicU64` is available.
21-
- If the type being copied contains uninitialized bytes (e.g., padding), it is incompatible with `-Zmiri-check-number-validity`. This will probably not be resolved until something like `AtomicMaybeUninit` is supported. **Note:** Due to [Miri does not track uninitialized bytes on a per byte basis for partially initialized scalars][rust-lang/rust#69488], Miri may report this case as an access to an uninitialized byte, regardless of whether the uninitialized byte is actually accessed or not.
21+
- If the type being copied contains uninitialized bytes (e.g., padding) [it is undefined behavior because the copy goes through integers][undefined-behavior]. This problem will probably not be resolved until something like `AtomicMaybeUninit` is supported.
2222

2323
## Related Projects
2424

@@ -28,7 +28,7 @@ See [P1478R1][p1478r1] for more.
2828
[implementation]: https://github.com/taiki-e/atomic-memcpy/blob/570de7be73b3cb086741cc6cff80dea4c706349c/src/lib.rs#L339-L383
2929
[p1478r1]: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1478r1.html
3030
[portable-atomic]: https://github.com/taiki-e/portable-atomic
31-
[rust-lang/rust#69488]: https://github.com/rust-lang/rust/issues/69488
31+
[undefined-behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
3232

3333
## License
3434

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ use core::sync::atomic::{self, Ordering};
5959
/// - `src` must be valid for reads.
6060
/// - `src` must be properly aligned.
6161
/// - `src` must go through [`UnsafeCell::get`](core::cell::UnsafeCell::get).
62+
/// - `T` must not contain uninitialized bytes.
6263
/// - There are no concurrent non-atomic write operations.
6364
/// - There are no concurrent atomic write operations of different
6465
/// granularity. The granularity of atomic operations is an implementation
@@ -126,6 +127,7 @@ pub unsafe fn atomic_load<T>(src: *const T, order: Ordering) -> core::mem::Maybe
126127
/// - `dst` must be [valid] for writes.
127128
/// - `dst` must be properly aligned.
128129
/// - `dst` must go through [`UnsafeCell::get`](core::cell::UnsafeCell::get).
130+
/// - `T` must not contain uninitialized bytes.
129131
/// - There are no concurrent non-atomic operations.
130132
/// - There are no concurrent atomic operations of different
131133
/// granularity. The granularity of atomic operations is an implementation
@@ -389,6 +391,7 @@ mod imp {
389391
// - `src` is valid for atomic reads.
390392
// - `src` is properly aligned for `T`.
391393
// - `src` go through `UnsafeCell::get`.
394+
// - `T` does not contain uninitialized bytes.
392395
// - there are no concurrent non-atomic write operations.
393396
// - there are no concurrent atomic write operations of different granularity.
394397
// Note that the safety of the code in this function relies on these guarantees,
@@ -627,6 +630,7 @@ mod imp {
627630
// - `dst` is valid for atomic writes.
628631
// - `dst` is properly aligned for `T`.
629632
// - `dst` go through `UnsafeCell::get`.
633+
// - `T` does not contain uninitialized bytes.
630634
// - there are no concurrent non-atomic operations.
631635
// - there are no concurrent atomic operations of different granularity.
632636
// - if there are concurrent atomic write operations, `T` is valid for all bit patterns.

tests/padding.rs

Lines changed: 0 additions & 66 deletions
This file was deleted.

tests/uninit.rs

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)