Pointer compression and provenance

⚓ Rust    📅 2025-11-07    👤 surdeus    👁️ 6      

surdeus

Say I'm writing an OS or something where I have tight control of the memory layout, and I put frequently used data in a special heap near the bottom of the address space. I shouldn't need a full width pointer/reference to refer to this data. I also shouldn't need to use indexing, I should genuinely be able to use a smaller width value for direct loads and stores.

The obvious way to implement this is a custom pointer struct that holds an integer type (created by truncating a regular pointer) of the desired width with a Deref that casts the integer back to a regular pointer. But how to do this with proper provenance? The docs say you can use with_addr to copy provenance from some other existing pointer, but it's unclear what that would be in this case. The whole point of pointer compression is not keeping around other data. We could keep a global pointer to the beginning of the special heap just for the sake of provenance copying, but presumably each allocation out of the special heap creates a provenance with bounds specific to that allocation, not the whole heap? Because otherwise the spatial limits of provenance seem meaningless (every pointer would defacto be allowed to point at every allocation), but maybe I'm missing something here.

2 posts - 2 participants

Read full topic

🏷️ Rust_feed