Open
Description
Feature gate: #![feature(ptr_mask)]
This is a tracking issue for <*const T>::mask
and <*mut T>::mask
methods that allow masking pointers.
Public API
impl<T: ?Sized> *const T {
pub fn mask(self, mask: usize) -> *const T;
}
impl<T: ?Sized> *mut T {
pub fn mask(self, mask: usize) -> *mut T;
}
Steps / History
- Implementation: Add pointer masking convenience functions #96946Final comment period (FCP)Stabilization PR
Unresolved Questions
- None yet.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
hsanzg commentedon Jul 21, 2024
Are there plans to make the
ptr_mask
(and thereforeptr::mask
) usable fromconst
contexts?This currently depends on making
ptr::map_addr
andptr::with_addr
const
, which would need to be discussed in the context of the strict provenance project.RalfJung commentedon Jul 21, 2024
These functions cannot in general be made const-compatible, since their behavior depends on the exact bits of a pointer value which are not known at compile-time.
with_addr
will never beconst
. (More specifically, subtracting two pointers will never be possible at const-time, andwith_addr
depends on that ability.)Certain tricks could be played for the specific case where the original allocation was sufficiently aligned to make the lowest bits of the pointers statically predictable. That would need new specialized intrinsics though, it cannot be implemented via
with_addr
.RalfJung commentedon Sep 14, 2024
Don't we also need an operation that corresponds to
ptr.map_addr(|a| a | mask)
to make this sufficient for tagged pointers? But somehow LLVM seems to only support&
, not|
, on pointers?(Maybe LLVM should just support what we call
addr
andwith_addr
, then it wouldn't need a bunch of new pointer versions for each integer operation...)Cc @nikic
nikic commentedon Sep 14, 2024
LLVM currently doesn't have something like
addr
because the necessary analysis infrastructure to capitalize on it isn't in place (yet). LLVM currently combines address capture and provenance escape into one concept, and the addr vs ptrtoint distinction only really becomes relevant once you separate them. This is something I have on my long term TODO list, but never get around to...RalfJung commentedon Sep 14, 2024