diff --git a/aya-log-common/src/lib.rs b/aya-log-common/src/lib.rs index 37591f7e..6c610898 100644 --- a/aya-log-common/src/lib.rs +++ b/aya-log-common/src/lib.rs @@ -71,6 +71,9 @@ impl_formatter_for_types!( impl LowerHexFormatter for &[u8; N] {} +impl LowerHexFormatter for *const T {} +impl LowerHexFormatter for *mut T {} + pub trait UpperHexFormatter {} impl_formatter_for_types!( UpperHexFormatter: { @@ -82,6 +85,9 @@ impl_formatter_for_types!( impl UpperHexFormatter for &[u8; N] {} +impl UpperHexFormatter for *const T {} +impl UpperHexFormatter for *mut T {} + pub trait IpFormatter {} impl IpFormatter for IpAddr {} impl IpFormatter for Ipv4Addr {} @@ -144,6 +150,8 @@ pub enum ArgumentKind { Bytes, Str, + + Pointer, } /// All display hints @@ -282,6 +290,20 @@ impl Argument for DisplayHint { } } +impl sealed::Sealed for *const T {} +impl Argument for *const T { + fn as_argument(&self) -> (ArgumentKind, impl AsRef<[u8]>) { + (ArgumentKind::Pointer, (*self as usize).to_ne_bytes()) + } +} + +impl sealed::Sealed for *mut T {} +impl Argument for *mut T { + fn as_argument(&self) -> (ArgumentKind, impl AsRef<[u8]>) { + (ArgumentKind::Pointer, (*self as usize).to_ne_bytes()) + } +} + fn wire_len(value: &[u8]) -> Option<[u8; 2]> { match LogValueLength::try_from(value.len()) { Ok(wire_len) => Some(wire_len.to_ne_bytes()), diff --git a/aya-log/src/lib.rs b/aya-log/src/lib.rs index 04bb79b1..8f15cc9e 100644 --- a/aya-log/src/lib.rs +++ b/aya-log/src/lib.rs @@ -732,6 +732,16 @@ fn log_buf(mut buf: &[u8], logger: &T) -> Result<(), ()> { } Err(e) => error!("received invalid utf8 string: {e}"), }, + ArgumentKind::Pointer => { + full_log_msg.push_str( + &usize::from_ne_bytes( + value + .try_into() + .map_err(|std::array::TryFromSliceError { .. }| ())?, + ) + .format(last_hint.take())?, + ); + } } buf = rest;