diff options
| author | bors <bors@rust-lang.org> | 2022-03-30 10:09:10 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-03-30 10:09:10 +0000 |
| commit | e50ff9b4521234e56ff46f8ed0372d5cb5689654 (patch) | |
| tree | cbdc3072e4ed48fb9ffbae2c29438a7c37ae1f06 /library/std/src/thread | |
| parent | 05142a7e4495f09141fdd65f140fe44d8c200a9e (diff) | |
| parent | e3a3afe05099dc1f9078fa1f65ade467b92f42c3 (diff) | |
| download | rust-e50ff9b4521234e56ff46f8ed0372d5cb5689654.tar.gz rust-e50ff9b4521234e56ff46f8ed0372d5cb5689654.zip | |
Auto merge of #95241 - Gankra:cleaned-provenance, r=workingjubilee
Strict Provenance MVP This patch series examines the question: how bad would it be if we adopted an extremely strict pointer provenance model that completely banished all int<->ptr casts. The key insight to making this approach even *vaguely* pallatable is the ptr.with_addr(addr) -> ptr function, which takes a pointer and an address and creates a new pointer with that address and the provenance of the input pointer. In this way the "chain of custody" is completely and dynamically restored, making the model suitable even for dynamic checkers like CHERI and Miri. This is not a formal model, but lots of the docs discussing the model have been updated to try to the *concept* of this design in the hopes that it can be iterated on. See #95228
Diffstat (limited to 'library/std/src/thread')
| -rw-r--r-- | library/std/src/thread/local.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/library/std/src/thread/local.rs b/library/std/src/thread/local.rs index a100444f049..ca29261b1c9 100644 --- a/library/std/src/thread/local.rs +++ b/library/std/src/thread/local.rs @@ -1071,7 +1071,7 @@ pub mod os { pub unsafe fn get(&'static self, init: impl FnOnce() -> T) -> Option<&'static T> { // SAFETY: See the documentation for this method. let ptr = unsafe { self.os.get() as *mut Value<T> }; - if ptr as usize > 1 { + if ptr.addr() > 1 { // SAFETY: the check ensured the pointer is safe (its destructor // is not running) + it is coming from a trusted source (self). if let Some(ref value) = unsafe { (*ptr).inner.get() } { @@ -1090,7 +1090,7 @@ pub mod os { // SAFETY: No mutable references are ever handed out meaning getting // the value is ok. let ptr = unsafe { self.os.get() as *mut Value<T> }; - if ptr as usize == 1 { + if ptr.addr() == 1 { // destructor is running return None; } @@ -1130,7 +1130,7 @@ pub mod os { unsafe { let ptr = Box::from_raw(ptr as *mut Value<T>); let key = ptr.key; - key.os.set(1 as *mut u8); + key.os.set(ptr::invalid_mut(1)); drop(ptr); key.os.set(ptr::null_mut()); } |
