mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-03 19:32:35 +00:00
[compile-rt] Reduce #ifdef noise for ptrauth
Create a sanitizer_ptrauth.h header that #includes <ptrauth> when available and defines just the required macros as "no ops" otherwise. This should avoid the need for excessive #ifdef'ing. Follow-up to and discussed in: https://reviews.llvm.org/D79132 Reviewed By: delcypher Differential Revision: https://reviews.llvm.org/D79540
This commit is contained in:
parent
e6615d71d8
commit
bba38de50c
@ -164,6 +164,7 @@ set(SANITIZER_IMPL_HEADERS
|
||||
sanitizer_platform_limits_solaris.h
|
||||
sanitizer_posix.h
|
||||
sanitizer_procmaps.h
|
||||
sanitizer_ptrauth.h
|
||||
sanitizer_quarantine.h
|
||||
sanitizer_report_decorator.h
|
||||
sanitizer_ring_buffer.h
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "sanitizer_placement_new.h"
|
||||
#include "sanitizer_platform_limits_posix.h"
|
||||
#include "sanitizer_procmaps.h"
|
||||
#include "sanitizer_ptrauth.h"
|
||||
|
||||
#if !SANITIZER_IOS
|
||||
#include <crt_externs.h> // for _NSGetEnviron
|
||||
@ -765,12 +766,6 @@ bool SignalContext::IsTrueFaultingAddress() const {
|
||||
return si->si_signo == SIGSEGV && si->si_code != 0;
|
||||
}
|
||||
|
||||
#if __has_feature(ptrauth_calls)
|
||||
# include <ptrauth.h>
|
||||
#else
|
||||
# define ptrauth_strip(value, key) (value)
|
||||
#endif
|
||||
|
||||
#if defined(__aarch64__) && defined(arm_thread_state64_get_sp)
|
||||
#define AARCH64_GET_REG(r) \
|
||||
(uptr)ptrauth_strip( \
|
||||
|
21
compiler-rt/lib/sanitizer_common/sanitizer_ptrauth.h
Normal file
21
compiler-rt/lib/sanitizer_common/sanitizer_ptrauth.h
Normal file
@ -0,0 +1,21 @@
|
||||
//===-- sanitizer_ptrauth.h -------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef SANITIZER_PTRAUTH_H
|
||||
#define SANITIZER_PTRAUTH_H
|
||||
|
||||
#if __has_feature(ptrauth_calls)
|
||||
#include <ptrauth.h>
|
||||
#else
|
||||
// Copied from <ptrauth.h>
|
||||
#define ptrauth_strip(__value, __key) __value
|
||||
#define ptrauth_auth_data(__value, __old_key, __old_data) __value
|
||||
#define ptrauth_string_discriminator(__string) ((int)0)
|
||||
#endif
|
||||
|
||||
#endif // SANITIZER_PTRAUTH_H
|
@ -19,6 +19,7 @@
|
||||
#include "sanitizer_common/sanitizer_libc.h"
|
||||
#include "sanitizer_common/sanitizer_posix.h"
|
||||
#include "sanitizer_common/sanitizer_procmaps.h"
|
||||
#include "sanitizer_common/sanitizer_ptrauth.h"
|
||||
#include "sanitizer_common/sanitizer_stackdepot.h"
|
||||
#include "tsan_platform.h"
|
||||
#include "tsan_rtl.h"
|
||||
@ -41,10 +42,6 @@
|
||||
#include <errno.h>
|
||||
#include <sched.h>
|
||||
|
||||
#if __has_feature(ptrauth_calls)
|
||||
#include <ptrauth.h>
|
||||
#endif
|
||||
|
||||
namespace __tsan {
|
||||
|
||||
#if !SANITIZER_GO
|
||||
@ -278,10 +275,8 @@ void InitializePlatform() {
|
||||
uptr ExtractLongJmpSp(uptr *env) {
|
||||
uptr mangled_sp = env[LONG_JMP_SP_ENV_SLOT];
|
||||
uptr sp = mangled_sp ^ longjmp_xor_key;
|
||||
#if __has_feature(ptrauth_calls)
|
||||
sp = (uptr)ptrauth_auth_data((void *)sp, ptrauth_key_asdb,
|
||||
ptrauth_string_discriminator("sp"));
|
||||
#endif
|
||||
return sp;
|
||||
}
|
||||
|
||||
|
@ -16,10 +16,7 @@
|
||||
#include "ubsan_type_hash.h"
|
||||
|
||||
#include "sanitizer_common/sanitizer_common.h"
|
||||
|
||||
#if __has_feature(ptrauth_calls)
|
||||
#include <ptrauth.h>
|
||||
#endif
|
||||
#include "sanitizer_common/sanitizer_ptrauth.h"
|
||||
|
||||
// The following are intended to be binary compatible with the definitions
|
||||
// given in the Itanium ABI. We make no attempt to be ODR-compatible with
|
||||
@ -198,9 +195,7 @@ struct VtablePrefix {
|
||||
std::type_info *TypeInfo;
|
||||
};
|
||||
VtablePrefix *getVtablePrefix(void *Vtable) {
|
||||
#if __has_feature(ptrauth_calls)
|
||||
Vtable = ptrauth_auth_data(Vtable, ptrauth_key_cxx_vtable_pointer, 0);
|
||||
#endif
|
||||
VtablePrefix *Vptr = reinterpret_cast<VtablePrefix*>(Vtable);
|
||||
VtablePrefix *Prefix = Vptr - 1;
|
||||
if (!IsAccessibleMemoryRange((uptr)Prefix, sizeof(VtablePrefix)))
|
||||
|
Loading…
Reference in New Issue
Block a user