8000 New design based on `*mut T` by phil-opp · Pull Request #22 · rust-osdev/volatile · GitHub
[go: up one dir, main page]

Skip to content

New design based on *mut T #22

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 17 commits into from
Jun 24, 2023
Merged
Changes from 1 commit
Commits
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 missing access where bounds
  • Loading branch information
Freax13 committed Jun 15, 2022
commit aa93fb97f8eebd81fc01833c181652c7a6f510df
11 changes: 9 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
pub fn copy_into_slice(&self, dst: &mut [T])
where
T: Copy,
R: access::Safe,
{
let len = self.pointer.len();
assert_eq!(
Expand Down Expand Up @@ -591,6 +592,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
pub fn copy_from_slice(&mut self, src: &[T])
where
T: Copy,
W: access::Safe,
{
let len = self.pointer.len();
assert_eq!(
Expand Down Expand Up @@ -644,6 +646,8 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
pub fn copy_within(&mut self, src: impl RangeBounds<usize>, dest: usize)
where
T: Copy,
R: access::Safe,
W: access::Safe,
{
let len = self.pointer.len();
// implementation taken from https://github.com/rust-lang/rust/blob/683d1bcd405727fcc9209f64845bd3b9104878b8/library/core/src/slice/mod.rs#L2726-L2738
Expand Down Expand Up @@ -819,7 +823,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {

/// Methods for volatile byte slices
#[cfg(feature = "unstable")]
impl<A> VolatilePtr<'_, [u8], A> {
impl<R, W> VolatilePtr<'_, [u8], Access<R, W>> {
/// Sets all elements of the byte slice to the given `value` using a volatile `memset`.
///
/// This method is similar to the `slice::fill` method of the standard library, with the
Expand All @@ -841,7 +845,10 @@ impl<A> VolatilePtr<'_, [u8], A> {
/// buf.fill(1);
/// assert_eq!(unsafe { buf.as_ptr().as_mut() }, &mut vec![1; 10]);
/// ```
pub fn fill(&mut self, value: u8) {
pub fn fill(&mut self, value: u8)
where
W: access::Safe,
{
unsafe {
intrinsics::volatile_set_memory(self.pointer.as_mut_ptr(), value, self.pointer.len());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like for this method (and all the other methods that use volatile intrinsic), we should just have a stable, normal loop that just does read_volatile/write_volatile by default.

We could then add a nightly-only "slice_optimizations" feature, that changes the implementation to use the intrinsics. Then, when rust-lang/rfcs#2728 gets stabilized, we can switch to unconditionally using the stabilized methods.

}
Expand Down
0