Skip to content
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

make HAL provenance-friendly #366

Open
hawkw opened this issue Nov 5, 2022 · 8 comments
Open

make HAL provenance-friendly #366

hawkw opened this issue Nov 5, 2022 · 8 comments
Labels
area/hal Related to the hardware abstraction layer help wanted Extra attention is needed kind/enhancement New feature or request

Comments

@hawkw
Copy link
Owner

hawkw commented Nov 5, 2022

the Mycelium HAL's address types (and other code that does on MMIO) was mostly written before Rust had ways to do int2ptr conversions without totally violating pointer provenance. we should update this code to be less egregiously wrong.

this basically means replacing all the int2ptr casts with ptr::from_exposed_addr and friends.

@hawkw
Copy link
Owner Author

hawkw commented Nov 5, 2022

we might also be better off changing the internal representation of VAddr from VAddr(usize) to VAddr(*const ()) so that when you construct one from a ptr it's "more provenance-preserving", and make the VAddr::from_usize constrictor be ptr::from_exposed_addr...

@hawkw hawkw added area/hal Related to the hardware abstraction layer help wanted Extra attention is needed kind/enhancement New feature or request labels Nov 5, 2022
@hawkw
Copy link
Owner Author

hawkw commented Nov 5, 2022

@myrrlyn do you wanna mess with this?

@myrrlyn
Copy link

myrrlyn commented Nov 6, 2022

sure. fwiw the standard library seems to Love storing *mut () instead of *const () for some reason so if VAddr occasionally allows write permissions it might be worth using that as the storage. idk i'm not a compilers boy. in The Future tm once funty gets cool (and able to provide const fns...) this won't matter, it'll store the Correct pointer always.

anyway yeah i'll poke

@hawkw
Copy link
Owner Author

hawkw commented Nov 7, 2022

yeah, it should probably be *mut () since it will grant write permissions through unsafe code --- that was what i meant.

@hawkw
Copy link
Owner Author

hawkw commented Nov 7, 2022

in an ideal world we would also probably represent physical addresses as *mut () so that they were "more provenance preserving", but...they're probably going to have to stay integers forever because they can sometimes have bit patterns that aren't valid virtual addresses...

also sidenote please feel free to clean up any of the other messy stuff in the address types if you like.

@hawkw
Copy link
Owner Author

hawkw commented Jan 6, 2023

@myrrlyn is this still something you're interested in taking a crack at? i might do it at some point, otherwise.

@myrrlyn
Copy link

myrrlyn commented Jan 6, 2023

yes but feel free to beat me to it

@hawkw
Copy link
Owner Author

hawkw commented Jan 6, 2023

i'm probably not going to start any time soon, so, i probably won't. but i figured i'd check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hal Related to the hardware abstraction layer help wanted Extra attention is needed kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants