Skip to content

Commit

Permalink
Merge pull request #50 from rust-osdev/nested-map_field
Browse files Browse the repository at this point in the history
Add support for nested `map_field` operations
  • Loading branch information
phil-opp authored Apr 21, 2024
2 parents 9c53163 + b2e54a6 commit 73e154b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/volatile_ptr/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@
/// ```
#[macro_export]
macro_rules! map_field {
($volatile:ident.$place:ident) => {{
($volatile:ident.$($place:ident).+) => {{
// Simulate creating a reference to the field. This is done to make
// sure that the field is not potentially unaligned. The body of the
// if statement will never be executed, so it can never cause any UB.
if false {
let _ref_to_field = &(unsafe { &*$volatile.as_raw_ptr().as_ptr() }).$place;
let _ref_to_field = &(unsafe { &*$volatile.as_raw_ptr().as_ptr() }).$($place).+;
}

unsafe {
$volatile.map(|ptr| {
core::ptr::NonNull::new(core::ptr::addr_of_mut!((*ptr.as_ptr()).$place)).unwrap()
core::ptr::NonNull::new(core::ptr::addr_of_mut!((*ptr.as_ptr()).$($place).+)).unwrap()
})
}
}};
Expand Down

0 comments on commit 73e154b

Please sign in to comment.