1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
use std::os::raw::c_void;

#[cfg(feature = "arm64e")]
#[link(name = "ptrauth", kind = "static")]
extern "C" {
    /// Strips pointer authentication from a C pointer on arm64e (ARMv8.3+)
    /// Does nothing on arm64 (ARMv8)
    /// `void* ptr_strip(void* address)`
    fn ptr_strip(address: *mut c_void) -> *mut c_void;
}

/// Strips the Pointer Authentication signature from a pointer. Only useful on arm64e (ARMv8.3+).
#[cfg(not(feature = "arm64e"))]
pub fn strip_pac(pointer: *mut c_void) -> *mut c_void {
    pointer
}

/// Strips the Pointer Authentication signature from a pointer. Only useful on arm64e (ARMv8.3+).
#[cfg(feature = "arm64e")]
pub fn strip_pac(pointer: *mut c_void) -> *mut c_void {
    unsafe { ptr_strip(pointer) }
}