I want to convert *mut
pointer to &mut
reference.
// Both setting a value to ptr and getting a value from ptr succeeds.
let ptr: &mut usize = unsafe { &mut *(VIRTUAL_ADDRESS_TO_ACCESS_FREE_PAGE as *mut usize) };
This works. However, if &mut
is outside of unsafe
block, the code will not work partially. *ptr = foo
will not store foo
to the memory ptr
points, but let foo = *ptr
will assign the value of *ptr
to foo
.
// Setting a value to ptr fails, but getting a value from ptr succeeds.
let ptr: &mut usize = &mut unsafe { *(VIRTUAL_ADDRESS_TO_ACCESS_FREE_PAGE as *mut usize) };
What's the difference between unsafe { &mut }
and &mut unsafe{ }
?