Skip to content

Commit

Permalink
Revert "fix: use pointer provenance APIs"
Browse files Browse the repository at this point in the history
This reverts commit 4fab4b1.
  • Loading branch information
morrisonlevi committed Jan 6, 2025
1 parent 6d2f343 commit a8443ad
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 30 deletions.
8 changes: 0 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion profiling/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ serde_json = {version = "1.0"}
rand = { version = "0.8.5" }
rand_distr = { version = "0.4.3" }
rustc-hash = "1.1.0"
sptr = "0.3"
uuid = { version = "1.0", features = ["v4"] }

[dev-dependencies]
Expand Down
10 changes: 3 additions & 7 deletions profiling/src/profiling/stack_walking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,9 @@ unsafe fn extract_file_and_line(execute_data: &zend_execute_data) -> (Option<Thi

#[cfg(php_run_time_cache)]
mod detail {
// See: https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance
#![allow(unstable_name_collisions, unused_imports)]
use sptr::Strict;

use super::*;
use crate::string_set::StringSet;
use datadog_thin_str::ThinStr;
use datadog_thin_str::{ThinHeader, ThinStr};
use log::{debug, trace};
use std::cell::RefCell;
use std::ops::Deref;
Expand Down Expand Up @@ -130,7 +126,7 @@ mod detail {
// SAFETY: the slot is in-bounds from CacheSlot -> usize conv.
let cached = unsafe { self.cache_slots.get_unchecked_mut(slot as usize) };

let ptr = sptr::from_exposed_addr_mut(*cached);
let ptr = *cached as *mut ThinHeader;
match NonNull::new(ptr) {
Some(non_null) => {
// SAFETY: the string set is only reset between requests,
Expand All @@ -143,7 +139,7 @@ mod detail {
let string = f()?;
let thin_str = self.string_set.insert(&string);
let non_null = thin_str.header_ptr();
*cached = non_null.as_ptr().expose_addr();
*cached = non_null.as_ptr() as usize;
Some(string)
}
}
Expand Down
1 change: 0 additions & 1 deletion thin-str/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ tagged-pointer = { version = "0.2", default-features = false }

[dev-dependencies]
naughty-strings = "0.2"
sptr = { version = "0.3", default-features = false }
18 changes: 5 additions & 13 deletions thin-str/src/thin_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,6 @@ mod ext {

#[cfg(test)]
mod tests {
// See: https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance
#![allow(unstable_name_collisions, unused_imports)]
use sptr::Strict;

use super::*;
use allocator_api2::alloc::Global;

Expand Down Expand Up @@ -331,19 +327,15 @@ This is a tribute.
fn test_round_tripping_to_usize() {
let datadog = "See inside any stack, any app, at any scale, anywhere.";
let string = ThinString::from(datadog);
let ptr = {

let bits = {
let thin_str = string.as_thin_str();
thin_str.header_ptr().as_ptr()
let non_null = thin_str.header_ptr();
non_null.as_ptr() as usize
};

let bits = ptr.addr();

let restored = {
// with_addr allows us to restore the provenance of the pointer,
// and we can do this because we have the original to restore it.
// The actually PHP profiler will not have such things available,
// and should use `expose_addr` and similar.
let non_null = unsafe { ptr::NonNull::new_unchecked(ptr.with_addr(bits)) };
let non_null = unsafe { ptr::NonNull::new_unchecked(bits as *mut ThinHeader) };
unsafe { ThinStr::from_header(non_null) }
};

Expand Down

0 comments on commit a8443ad

Please sign in to comment.