-
Notifications
You must be signed in to change notification settings - Fork 132
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
VirtAddr::try_new() succeeds on non-canonical addresses #299
Comments
@phil-opp would you be OK with this breaking change for 0.15 ? |
A fully agree that this behavior wasn't a good idea. Many people treat the lower and upper half as separate address spaces (e.g. user and kernel space) so that the boundary should not be crossing silently. I agree with your point about 5-level paging too. So yes, I think we should make that breaking change. I normally try to avoid any breaking change that silently changes the runtime behavior, but in this case I don't see a better migration path. At least it only changes some behavior into errors, so all users that relied on the old behavior should notice the change at some point. (There might be users that want to treat the virtual address space as one contiguous address space and want to keep the current gap jump behavior. In that case, we could add some separate |
Sounds reasonable to me. |
I just left a comment in #293 that is related to this: #293 (comment) |
Fixed by #370 |
From the
VirtAddr::try_new
docs:This means that (surprisingly) you can provide a non-canonical address
0x00008123DEADBEEF
and, instead oftry_new
failing, you get theVirtAddr
0xFFFF8123DEADBEEF
. As thetry_new
implementation is used throughoutVirtAddr
's methods, this means you get weird behavior likeVirtAddr::new(addr).as_u64() == addr
andVirtAddr::from_ptr(ptr).as_ptr() == ptr
not necessarily being true, which is quite confusing.It's especially confusing if you're working on a 5-level paging system where the virtual address space now has 57 bits. In that case,
0x0008123DEADBEEF
is a canonical virtual address. I would either expectVirtAddr::try_new
to work in this case (returning the passed in address) or fail (returningErr
, as this library doesn't have to support 5-level paging). What I wouldn't want is for the virtual address to be silently modified.Issues related to this have come up in #298. One of the consequences of the current implementation is that adding an
u64
to aVirtAddr
can "jump" the gap between the lower and upper half of the virtual address space. For example:which seems very unintuitive.
I would propose the following breaking change:
VirtAddr::try_new
andVirtAddr::new
only succeed if the provided address is canonical and fail otherwise. This removes an unexpected foot-gun and simplifies the implementation.The text was updated successfully, but these errors were encountered: