Beingessner: Rust's Unsafe Pointer Types Need An Overhaul
Beingessner: Rust's Unsafe Pointer Types Need An Overhaul
Posted Mar 22, 2022 19:30 UTC (Tue) by NYKevin (subscriber, #129325)In reply to: Beingessner: Rust's Unsafe Pointer Types Need An Overhaul by wahern
Parent article: Beingessner: Rust's Unsafe Pointer Types Need An Overhaul
C arguably solves this problem by ignoring it. The standard already says it's illegal to even evaluate an invalid not-null not-one-past-the-end pointer, regardless of whether you dereference it, and integer types are similarly allowed to have trap representations, so you just declare "all the weird CHERI stuff" to be UB or implementation details that "portable" code can't rely on, and then you've "ported" C to CHERI by making CHERI look like just another architecture. The most you get out of this is "If your program otherwise would have performed certain very specific kinds of UB, on CHERI it will *probably* trap at runtime instead." "Probably" because who knows what the optimizer will do. Contrast this with the much stronger guarantees you get out of safe Rust, where it will fail at compile time, every time.
