GitXplorerGitXplorer
G

sptr

public
76 stars
11 forks
6 issues

Commits

List of commits on branch main.
Unverified
e59792814876b4948279ec3121921fbe827b1077

0.3.2 release

RRalfJung committed 3 years ago
Verified
8c5dd0ef3156068a1f12fff400e7e15a48386c68

Merge pull request #9 from RalfJung/invalid2

RRalfJung committed 3 years ago
Verified
872e0f13313d7f5493bb52dd26a95f52f2af8e02

Merge pull request #10 from RalfJung/addr

RRalfJung committed 3 years ago
Unverified
9373c8080750eb3b7835d0685ef77d42cbddf1ed

use transmute for ptr.addr

RRalfJung committed 3 years ago
Unverified
cc23474e386168833ee4fdae5c0799dd2795e156

ptr::invalid is not the same as a cast

RRalfJung committed 3 years ago
Unverified
796f0f2ca96a0e187f8d9b63e9aed13b234ac3e4

ensure it actually builds and works in Miri

RRalfJung committed 3 years ago

README

The README file for this repository.

sptr: The Strict Provenance Polyfill

crates.io Rust CI

This library provides a stable polyfill for Rust's [Strict Provenance] experiment.

Mapping to STD APIs:

This crate "overlays" a bunch of unstable std apis, here are the mappings:

core::ptr (sptr)

core::pointer (sptr::Strict)

  • pub fn addr(self) -> usize;
  • pub fn expose_addr(self) -> usize;
  • pub fn with_addr(self, addr: usize) -> Self;
  • pub fn map_addr(self, f: impl FnOnce(usize) -> usize) -> Self;

NON-STANDARD EXTENSIONS (disabled by default, use at your own risk)

  • sptr::uptr (feature = uptr)
  • sptr::iptr (feature = uptr)
  • sptr::OpaqueFnPtr (feature = opaque_fn)

Applying The Overlay

Swapping between sptr and core::ptr should be as simple as switching between sptr:: and ptr:: for static functions. For methods, you must import sptr::Strict into your module for the extension trait's methods to overlay std. The compiler will (understandably) complain that you are overlaying std, so you will need to also silence that as seen in the following example:

#![allow(unstable_name_collisions)]
use sptr::Strict;

let ptr = sptr::invalid_mut::<u8>(1);
println!("{}", ptr.addr());

By default, this crate will also mark methods on pointers as "deprecated" if they are incompatible with strict_provenance. If you don't want this, set default-features = false in your Cargo.toml.

Rust is the canonical source of definitions for these APIs and semantics, but the docs here will vaguely try to mirror the docs checked into Rust.