15ffd83dbSDimitry Andric //===-- sanitizer_ptrauth.h -------------------------------------*- C++ -*-===// 25ffd83dbSDimitry Andric // 35ffd83dbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 45ffd83dbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 55ffd83dbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 65ffd83dbSDimitry Andric // 75ffd83dbSDimitry Andric //===----------------------------------------------------------------------===// 85ffd83dbSDimitry Andric 95ffd83dbSDimitry Andric #ifndef SANITIZER_PTRAUTH_H 105ffd83dbSDimitry Andric #define SANITIZER_PTRAUTH_H 115ffd83dbSDimitry Andric 12*36b606aeSDimitry Andric #if __has_feature(ptrauth_intrinsics) 135ffd83dbSDimitry Andric # include <ptrauth.h> 14fe6060f1SDimitry Andric #elif defined(__ARM_FEATURE_PAC_DEFAULT) && !defined(__APPLE__) 15fe6060f1SDimitry Andric // On the stack the link register is protected with Pointer 16fe6060f1SDimitry Andric // Authentication Code when compiled with -mbranch-protection. 17fe6060f1SDimitry Andric // Let's stripping the PAC unconditionally because xpaclri is in 18fe6060f1SDimitry Andric // the NOP space so will do nothing when it is not enabled or not available. 19*36b606aeSDimitry Andric # define ptrauth_strip(__value, __key) \ 20*36b606aeSDimitry Andric ({ \ 21*36b606aeSDimitry Andric __typeof(__value) ret; \ 22*36b606aeSDimitry Andric asm volatile( \ 23*36b606aeSDimitry Andric "mov x30, %1\n\t" \ 24*36b606aeSDimitry Andric "hint #7\n\t" \ 25*36b606aeSDimitry Andric "mov %0, x30\n\t" \ 26*36b606aeSDimitry Andric "mov x30, xzr\n\t" \ 27*36b606aeSDimitry Andric : "=r"(ret) \ 28*36b606aeSDimitry Andric : "r"(__value) \ 29*36b606aeSDimitry Andric : "x30"); \ 30*36b606aeSDimitry Andric ret; \ 31*36b606aeSDimitry Andric }) 32fe6060f1SDimitry Andric # define ptrauth_auth_data(__value, __old_key, __old_data) __value 33fe6060f1SDimitry Andric # define ptrauth_string_discriminator(__string) ((int)0) 345ffd83dbSDimitry Andric #else 355ffd83dbSDimitry Andric // Copied from <ptrauth.h> 365ffd83dbSDimitry Andric # define ptrauth_strip(__value, __key) __value 375ffd83dbSDimitry Andric # define ptrauth_auth_data(__value, __old_key, __old_data) __value 385ffd83dbSDimitry Andric # define ptrauth_string_discriminator(__string) ((int)0) 395ffd83dbSDimitry Andric #endif 405ffd83dbSDimitry Andric 41fe6060f1SDimitry Andric #define STRIP_PAC_PC(pc) ((uptr)ptrauth_strip(pc, 0)) 42e8d8bef9SDimitry Andric 435ffd83dbSDimitry Andric #endif // SANITIZER_PTRAUTH_H 44