Skip to content
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

Support raw pointers #1818

Open
joshlf opened this issue Oct 4, 2024 · 1 comment
Open

Support raw pointers #1818

joshlf opened this issue Oct 4, 2024 · 1 comment

Comments

@joshlf
Copy link
Member

joshlf commented Oct 4, 2024

Design

Option 1: Implement FromBytes and IntoBytes directly

See #170 for a detailed discussion.

We would need to ensure that pointer-to-int transmutations are sound, which is currently up in the air. Even with that settled, these would be a significant footgun because it would be easy to perform transmutes that don't preserve provenance, and thus create raw pointers which users expect to be able to soundly dereference, but actually can't.

Option 2: Separate support for provenance-carrying types

We could do something similar to Immutable:

  • Treat FromBytes and IntoBytes as implicitly banning provenance
  • Split out a separate ProvenanceFree trait, and bound all existing transmutation methods with this trait
  • Permit implementing ProvenanceFree for everything that currently implements FromBytes and IntoBytes

With this scaffolding, we could add separate transmutation methods that do not require T: ProvenanceFree, and use strict provenance APIs like with_exposed_provenance to ensure that provenance is correctly handled.

Note that some APIs may not require this. For example, some uses of transmute! would be sound without a T: ProvenanceFree trait bound - e.g. transmuting from *mut T to *mut U might preserve provenance (although we would need to confirm this).

Option 3: Raw pointer wrapper types

Provide newtype wrappers around raw pointers which have getter methods that use strict provenance APIs like with_exposed_provenance to ensure that provenance is correctly handled. These newtypes can implement FromBytes and IntoBytes.

@djkoloski
Copy link
Member

Pointer-to-int transmutations are sound and should act like ptr.addr().

@joshlf joshlf mentioned this issue Nov 25, 2024
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants