-
Notifications
You must be signed in to change notification settings - Fork 1
fix undef behavior caused by memory aliasing #7
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
base: main
Are you sure you want to change the base?
Conversation
dc76d82 to
7c838e3
Compare
|
Note that just |
a62c483 to
70e58b0
Compare
70e58b0 to
7b69a17
Compare
|
Thanks, @edef1c. I appreciate your help with this. It looks like the test is passing now. Could you give it a look over before I merge it and publish a new version? |
|
The The API I've adopted for the unsafe raw buffer library in my own codebases looks like this: /// Make the buffer contents consistent by (logically) copying memory.
pub fn fence(&self) {
unsafe {
// the MMU does the actual memcpy, so this requires no CPU instructions
asm!("/* {ptr} */", ptr = in(reg) self.ptr.as_ptr(), options(nostack, preserves_flags));
}
}
/// SAFETY: The buffer segment needs to be in a consistent state, and `len` needs to be in bounds.
pub unsafe fn get(&self, offset: usize, len: usize) -> NonNull<[u8]> {
debug_assert!(len <= self.capacity());
NonNull::slice_from_raw_parts(
NonNull::new_unchecked(self.ptr.as_ptr().add(offset & self.mask.get())),
len,
)
}(nb: the SAFETY comment isn't quite right yet, since it's really about dereferenceability rather than about when The discipline the calling code adopts is to invoke the fence method before making an I think we're a little stuck here, and the most pragmatic option might be to deprecate the current raw pointer APIs, and introduce new ones with clearer safety properties. |
to address issues #6