Skip to content

Commit 0f16c9b

Browse files
authored
Rollup merge of #122935 - RalfJung:with-exposed-provenance, r=Amanieu
rename ptr::from_exposed_addr -> ptr::with_exposed_provenance As discussed on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/To.20expose.20or.20not.20to.20expose/near/427757066). The old name, `from_exposed_addr`, makes little sense as it's not the address that is exposed, it's the provenance. (`ptr.expose_addr()` stays unchanged as we haven't found a better option yet. The intended interpretation is "expose the provenance and return the address".) The new name nicely matches `ptr::without_provenance`.
2 parents efd800d + e091ab8 commit 0f16c9b

15 files changed

+33
-33
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ environment variable. We first document the most relevant and most commonly used
324324
number of available CPUs is `1`. Note that this flag does not affect how miri handles threads in
325325
any way.
326326
* `-Zmiri-permissive-provenance` disables the warning for integer-to-pointer casts and
327-
[`ptr::from_exposed_addr`](https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html).
327+
[`ptr::with_exposed_provenance`](https://doc.rust-lang.org/nightly/std/ptr/fn.with_exposed_provenance.html).
328328
This will necessarily miss some bugs as those operations are not efficiently and accurately
329329
implementable in a sanitizer, but it will only miss bugs that concern memory/pointers which is
330330
subject to these operations.

src/alloc_addresses/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ use reuse_pool::ReusePool;
1818

1919
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
2020
pub enum ProvenanceMode {
21-
/// We support `expose_addr`/`from_exposed_addr` via "wildcard" provenance.
22-
/// However, we want on `from_exposed_addr` to alert the user of the precision loss.
21+
/// We support `expose_addr`/`with_exposed_provenance` via "wildcard" provenance.
22+
/// However, we want on `with_exposed_provenance` to alert the user of the precision loss.
2323
Default,
2424
/// Like `Default`, but without the warning.
2525
Permissive,
26-
/// We error on `from_exposed_addr`, ensuring no precision loss.
26+
/// We error on `with_exposed_provenance`, ensuring no precision loss.
2727
Strict,
2828
}
2929

src/diagnostics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl fmt::Display for TerminationInfo {
6666
Int2PtrWithStrictProvenance =>
6767
write!(
6868
f,
69-
"integer-to-pointer casts and `ptr::from_exposed_addr` are not supported with `-Zmiri-strict-provenance`"
69+
"integer-to-pointer casts and `ptr::with_exposed_provenance` are not supported with `-Zmiri-strict-provenance`"
7070
),
7171
StackedBorrowsUb { msg, .. } => write!(f, "{msg}"),
7272
TreeBorrowsUb { title, .. } => write!(f, "{title}"),
@@ -593,7 +593,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
593593
(
594594
None,
595595
format!(
596-
"This program is using integer-to-pointer casts or (equivalently) `ptr::from_exposed_addr`,"
596+
"This program is using integer-to-pointer casts or (equivalently) `ptr::with_exposed_provenance`,"
597597
),
598598
),
599599
(
@@ -603,7 +603,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
603603
(
604604
None,
605605
format!(
606-
"See https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html for more details on that operation."
606+
"See https://doc.rust-lang.org/nightly/std/ptr/fn.with_exposed_provenance.html for more details on that operation."
607607
),
608608
),
609609
(
@@ -615,7 +615,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
615615
(
616616
None,
617617
format!(
618-
"You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `from_exposed_addr` semantics."
618+
"You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `with_exposed_provenance` semantics."
619619
),
620620
),
621621
(

src/shims/intrinsics/simd.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
514514
dest.transmute(this.machine.layouts.uint(dest.layout.size).unwrap(), this)?;
515515
this.write_int(res, &dest)?;
516516
}
517-
"cast" | "as" | "cast_ptr" | "expose_addr" | "from_exposed_addr" => {
517+
"cast" | "as" | "cast_ptr" | "expose_addr" | "with_exposed_provenance" => {
518518
let [op] = check_arg_count(args)?;
519519
let (op, op_len) = this.operand_to_simd(op)?;
520520
let (dest, dest_len) = this.mplace_to_simd(dest)?;
@@ -525,7 +525,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
525525
let safe_cast = intrinsic_name == "as";
526526
let ptr_cast = intrinsic_name == "cast_ptr";
527527
let expose_cast = intrinsic_name == "expose_addr";
528-
let from_exposed_cast = intrinsic_name == "from_exposed_addr";
528+
let from_exposed_cast = intrinsic_name == "with_exposed_provenance";
529529

530530
for i in 0..dest_len {
531531
let op = this.read_immediate(&this.project_index(&op, i)?)?;
@@ -559,7 +559,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
559559
(ty::RawPtr(..), ty::Int(_) | ty::Uint(_)) if expose_cast =>
560560
this.pointer_expose_address_cast(&op, dest.layout)?,
561561
(ty::Int(_) | ty::Uint(_), ty::RawPtr(..)) if from_exposed_cast =>
562-
this.pointer_from_exposed_address_cast(&op, dest.layout)?,
562+
this.pointer_with_exposed_provenance_cast(&op, dest.layout)?,
563563
// Error otherwise
564564
_ =>
565565
throw_unsup_format!(

tests/fail/provenance/ptr_int_unexposed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ fn main() {
77

88
let x_usize: usize = x_ptr.addr();
99
// Cast back an address that did *not* get exposed.
10-
let ptr = std::ptr::from_exposed_addr::<i32>(x_usize);
10+
let ptr = std::ptr::with_exposed_provenance::<i32>(x_usize);
1111
assert_eq!(unsafe { *ptr }, 3); //~ ERROR: is a dangling pointer
1212
}

tests/fail/provenance/strict_provenance_cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
fn main() {
55
let addr = &0 as *const i32 as usize;
6-
let _ptr = std::ptr::from_exposed_addr::<i32>(addr); //~ ERROR: integer-to-pointer casts and `ptr::from_exposed_addr` are not supported
6+
let _ptr = std::ptr::with_exposed_provenance::<i32>(addr); //~ ERROR: integer-to-pointer casts and `ptr::with_exposed_provenance` are not supported
77
}

tests/fail/provenance/strict_provenance_cast.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: unsupported operation: integer-to-pointer casts and `ptr::from_exposed_addr` are not supported with `-Zmiri-strict-provenance`
1+
error: unsupported operation: integer-to-pointer casts and `ptr::with_exposed_provenance` are not supported with `-Zmiri-strict-provenance`
22
--> $DIR/strict_provenance_cast.rs:LL:CC
33
|
4-
LL | let _ptr = std::ptr::from_exposed_addr::<i32>(addr);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ integer-to-pointer casts and `ptr::from_exposed_addr` are not supported with `-Zmiri-strict-provenance`
4+
LL | let _ptr = std::ptr::with_exposed_provenance::<i32>(addr);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ integer-to-pointer casts and `ptr::with_exposed_provenance` are not supported with `-Zmiri-strict-provenance`
66
|
77
= help: use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead
88
= note: BACKTRACE:

tests/fail/stacked_borrows/exposed_only_ro.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ fn main() {
77
let mut x = 0;
88
let _fool = &mut x as *mut i32; // this would have fooled the old untagged pointer logic
99
let addr = (&x as *const i32).expose_addr();
10-
let ptr = std::ptr::from_exposed_addr_mut::<i32>(addr);
10+
let ptr = std::ptr::with_exposed_provenance_mut::<i32>(addr);
1111
unsafe { *ptr = 0 }; //~ ERROR: /write access using <wildcard> .* no exposed tags have suitable permission in the borrow stack/
1212
}

tests/pass/box.stack.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ warning: integer-to-pointer cast
44
LL | let r2 = ((r as usize) + 0) as *mut i32;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ integer-to-pointer cast
66
|
7-
= help: This program is using integer-to-pointer casts or (equivalently) `ptr::from_exposed_addr`,
7+
= help: This program is using integer-to-pointer casts or (equivalently) `ptr::with_exposed_provenance`,
88
= help: which means that Miri might miss pointer bugs in this program.
9-
= help: See https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html for more details on that operation.
9+
= help: See https://doc.rust-lang.org/nightly/std/ptr/fn.with_exposed_provenance.html for more details on that operation.
1010
= help: To ensure that Miri does not miss bugs in your program, use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead.
11-
= help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `from_exposed_addr` semantics.
11+
= help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `with_exposed_provenance` semantics.
1212
= help: Alternatively, the `-Zmiri-permissive-provenance` flag disables this warning.
1313
= note: BACKTRACE:
1414
= note: inside `into_raw` at $DIR/box.rs:LL:CC

tests/pass/extern_types.stack.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ warning: integer-to-pointer cast
44
LL | let x: &Foo = unsafe { &*(16 as *const Foo) };
55
| ^^^^^^^^^^^^^^^^^^ integer-to-pointer cast
66
|
7-
= help: This program is using integer-to-pointer casts or (equivalently) `ptr::from_exposed_addr`,
7+
= help: This program is using integer-to-pointer casts or (equivalently) `ptr::with_exposed_provenance`,
88
= help: which means that Miri might miss pointer bugs in this program.
9-
= help: See https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html for more details on that operation.
9+
= help: See https://doc.rust-lang.org/nightly/std/ptr/fn.with_exposed_provenance.html for more details on that operation.
1010
= help: To ensure that Miri does not miss bugs in your program, use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead.
11-
= help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `from_exposed_addr` semantics.
11+
= help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `with_exposed_provenance` semantics.
1212
= help: Alternatively, the `-Zmiri-permissive-provenance` flag disables this warning.
1313
= note: BACKTRACE:
1414
= note: inside `main` at $DIR/extern_types.rs:LL:CC

tests/pass/portable-simd-ptrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ fn main() {
88
// Pointer casts
99
let _val: Simd<*const u8, 4> = Simd::<*const i32, 4>::splat(ptr::null()).cast();
1010
let addrs = Simd::<*const i32, 4>::splat(ptr::null()).expose_addr();
11-
let _ptrs = Simd::<*const i32, 4>::from_exposed_addr(addrs);
11+
let _ptrs = Simd::<*const i32, 4>::with_exposed_provenance(addrs);
1212
}

tests/pass/ptr_int_from_exposed.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn ptr_roundtrip_out_of_bounds() {
1212

1313
let x_usize = x_ptr.wrapping_offset(128).expose_addr();
1414

15-
let ptr = ptr::from_exposed_addr::<i32>(x_usize).wrapping_offset(-128);
15+
let ptr = ptr::with_exposed_provenance::<i32>(x_usize).wrapping_offset(-128);
1616
assert_eq!(unsafe { *ptr }, 3);
1717
}
1818

@@ -27,7 +27,7 @@ fn ptr_roundtrip_confusion() {
2727
let x_usize = x_ptr.expose_addr();
2828
let y_usize = y_ptr.expose_addr();
2929

30-
let ptr = ptr::from_exposed_addr::<i32>(y_usize);
30+
let ptr = ptr::with_exposed_provenance::<i32>(y_usize);
3131
let ptr = ptr.with_addr(x_usize);
3232
assert_eq!(unsafe { *ptr }, 0);
3333
}
@@ -39,7 +39,7 @@ fn ptr_roundtrip_imperfect() {
3939

4040
let x_usize = x_ptr.expose_addr() + 128;
4141

42-
let ptr = ptr::from_exposed_addr::<u8>(x_usize).wrapping_offset(-128);
42+
let ptr = ptr::with_exposed_provenance::<u8>(x_usize).wrapping_offset(-128);
4343
assert_eq!(unsafe { *ptr }, 3);
4444
}
4545

@@ -51,7 +51,7 @@ fn ptr_roundtrip_null() {
5151
let null = x_null_ptr.expose_addr();
5252
assert_eq!(null, 0);
5353

54-
let x_null_ptr_copy = ptr::from_exposed_addr::<i32>(null); // just a roundtrip, so has provenance of x (angelically)
54+
let x_null_ptr_copy = ptr::with_exposed_provenance::<i32>(null); // just a roundtrip, so has provenance of x (angelically)
5555
let x_ptr_copy = x_null_ptr_copy.with_addr(x_ptr.addr()); // addr of x and provenance of x
5656
assert_eq!(unsafe { *x_ptr_copy }, 42);
5757
}

tests/pass/stacked-borrows/int-to-ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn example(variant: bool) {
3939
// 4 is the "obvious" choice (topmost tag, what we used to do with untagged pointers).
4040
// And indeed if `variant == true` it is the only possible choice.
4141
// But if `variant == false` then 2 is the only possible choice!
42-
let x_wildcard = ptr::from_exposed_addr_mut::<i32>(x_raw2_addr);
42+
let x_wildcard = ptr::with_exposed_provenance_mut::<i32>(x_raw2_addr);
4343

4444
if variant {
4545
// If we picked 2, this will invalidate 3.

tests/pass/stacked-borrows/issue-miri-2389.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ warning: integer-to-pointer cast
44
LL | let wildcard = &root0 as *const Cell<i32> as usize as *const Cell<i32>;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ integer-to-pointer cast
66
|
7-
= help: This program is using integer-to-pointer casts or (equivalently) `ptr::from_exposed_addr`,
7+
= help: This program is using integer-to-pointer casts or (equivalently) `ptr::with_exposed_provenance`,
88
= help: which means that Miri might miss pointer bugs in this program.
9-
= help: See https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html for more details on that operation.
9+
= help: See https://doc.rust-lang.org/nightly/std/ptr/fn.with_exposed_provenance.html for more details on that operation.
1010
= help: To ensure that Miri does not miss bugs in your program, use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead.
11-
= help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `from_exposed_addr` semantics.
11+
= help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `with_exposed_provenance` semantics.
1212
= help: Alternatively, the `-Zmiri-permissive-provenance` flag disables this warning.
1313
= note: BACKTRACE:
1414
= note: inside `main` at $DIR/issue-miri-2389.rs:LL:CC

tests/pass/stacked-borrows/unknown-bottom-gc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn main() {
99

1010
// Expose the allocation and use the exposed pointer, creating an unknown bottom
1111
unsafe {
12-
let p: *mut u8 = ptr::from_exposed_addr::<u8>(ptr.expose_addr()) as *mut u8;
12+
let p: *mut u8 = ptr::with_exposed_provenance::<u8>(ptr.expose_addr()) as *mut u8;
1313
*p = 1;
1414
}
1515

0 commit comments

Comments
 (0)