-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
constrain safety preconditions of layout_for_ptr
functionality
#117185
Conversation
r? @thomcc (rustbot has picked a reviewer for you, use r? to override) |
This feels like it's not a question for me. r? @rust-lang/opsem |
The noted comment suggests to
but this is already the case, as the docs say that the size of the entire value must fit in
is a completely different requirement. (Plus, See my reply in the tracking issue for more context. |
This commit implements the recommendation of [1] to make the safety preconditions of the raw pointer layout utilities more conservative, to ease the path towards stabilization. In the future, we may (if we choose) remove some of these restrictions without breaking forwards compatibility. [1]: rust-lang#69835 (comment)
13bb102
to
7cbdc9c
Compare
@CAD97, ah, I misunderstood what you meant by 'wrap'. Yes, I agree, the size wrapping constraint is already covered. Still, it is possible to use ptr::slice_from_raw_parts to overflow the address space without overflowing the size, and addressing this possibility seems useful. |
See the discussion here -- I don't think we should do this. We should allow raw ptr size-of for non-dereferenceable pointers. |
@RalfJung, as far as I can tell, the safety preconditions here do not generally require dereferenceability. The one exception is that the vtable part of a dyn pointer must point a valid vtable. |
Dereferencability specifically is more in respect to my proposed conservative wording in the tracking issue, but the sentiment holds the same for the change here: that there should be no restrictions placed by these I plan to make a PR sometime next week rewording/refining the current requirements and to propose T-lang FCP signoff on stabilizing that capability. I expect no lang concerns; I just haven't had the time/motivation to push for it yet. As such, I'd suggest closing this PR as not planned. If T-lang requests a more conservative option in their FCP, we can reopen and/or otherwise pivot. |
Happy to close, then. Let me know if there's anything @joshlf and I can do to help drive this forward. The stabilization of |
Does that include that there should be no restrictions on the vtable pointer, or is the vtable pointer the one exception (ie, it will be required to point to a valid vtable entry, and perhaps one whose metadata is such that the pointer encodes a value whose size fits in |
The current docs are the semantics I intend to FCP — the |
Currently, the vtable pointer being valid is part of the validity invariant of This might be relaxed in the future to only be a safety invariant, but can't be relaxed further as @CAD97 noted. |
This commit implements the recommendation of #69835 (comment) to make the safety preconditions of the raw pointer layout utilities more conservative, as to ease the path towards stabilization. In the future, we may (if we choose) remove some of these restrictions without breaking forwards compatibility.