sanitizer_ptrauth.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //===-- sanitizer_ptrauth.h -------------------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef SANITIZER_PTRAUTH_H
  9. #define SANITIZER_PTRAUTH_H
  10. #if __has_feature(ptrauth_calls)
  11. #error #include <ptrauth.h>
  12. #elif defined(__ARM_FEATURE_PAC_DEFAULT) && !defined(__APPLE__)
  13. inline unsigned long ptrauth_strip(void* __value, unsigned int __key) {
  14. // On the stack the link register is protected with Pointer
  15. // Authentication Code when compiled with -mbranch-protection.
  16. // Let's stripping the PAC unconditionally because xpaclri is in
  17. // the NOP space so will do nothing when it is not enabled or not available.
  18. unsigned long ret;
  19. asm volatile(
  20. "mov x30, %1\n\t"
  21. "hint #7\n\t" // xpaclri
  22. "mov %0, x30\n\t"
  23. : "=r"(ret)
  24. : "r"(__value)
  25. : "x30");
  26. return ret;
  27. }
  28. #define ptrauth_auth_data(__value, __old_key, __old_data) __value
  29. #define ptrauth_string_discriminator(__string) ((int)0)
  30. #else
  31. // Copied from <ptrauth.h>
  32. #define ptrauth_strip(__value, __key) __value
  33. #define ptrauth_auth_data(__value, __old_key, __old_data) __value
  34. #define ptrauth_string_discriminator(__string) ((int)0)
  35. #endif
  36. #define STRIP_PAC_PC(pc) ((uptr)ptrauth_strip(pc, 0))
  37. #endif // SANITIZER_PTRAUTH_H