2 * @APPLE_LICENSE_HEADER_START@
4 * Copyright (c) 2018 Apple Inc. All Rights Reserved.
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 /********************************************************************
25 * arm64-asm.h - asm tools for arm64/arm64_32 and ROP/JOP
27 ********************************************************************/
31 #include "objc-config.h"
36 #define SUPPORT_TAGGED_POINTERS 1
39 #define PTRSHIFT 3 // 1<<PTRSHIFT == PTRSIZE
40 // "p" registers are pointer-sized
65 #define SUPPORT_TAGGED_POINTERS 0
68 #define PTRSHIFT 2 // 1<<PTRSHIFT == PTRSIZE
69 // "p" registers are pointer-sized
94 #if __has_feature(ptrauth_returns)
96 # define SignLR pacibsp
97 # define AuthenticateLR autibsp
101 # define AuthenticateLR
104 #if __has_feature(ptrauth_calls)
107 .macro TailCallFunctionPointer
108 // $0 = function pointer value
112 .macro TailCallCachedImp
113 // $0 = cached imp, $1 = address of cached imp, $2 = SEL, $3 = isa
114 eor $
1, $
1, $
2 // mix SEL into ptrauth modifier
115 eor $
1, $
1, $
3 // mix isa into ptrauth modifier
119 .macro TailCallMethodListImp
120 // $0 = method list imp, $1 = address of method list imp
124 .macro TailCallBlockInvoke
125 // $0 = invoke function, $1 = address of invoke function
129 .macro AuthAndResignAsIMP
130 // $0 = cached imp, $1 = address of cached imp, $2 = SEL, $3 = isa
131 // note: assumes the imp is not nil
132 eor $
1, $
1, $
2 // mix SEL into ptrauth modifier
133 eor $
1, $
1, $
3 // mix isa into ptrauth modifier
134 autib $
0, $
1 // authenticate cached imp
135 ldr xzr
, [$
0] // crash if authentication failed
136 paciza $
0 // resign cached imp as IMP
140 and $
0, $
1, #ISA_MASK
141 #if ISA_SIGNING_AUTH_MODE == ISA_SIGNING_STRIP
143 #elif ISA_SIGNING_AUTH_MODE == ISA_SIGNING_AUTH
145 movk x10
, #ISA_SIGNING_DISCRIMINATOR, LSL #48
150 .macro AuthISASuper dst
, addr_mutable
, discriminator
151 #if ISA_SIGNING_AUTH_MODE == ISA_SIGNING_AUTH
152 movk
\addr_mutable
, #\discriminator, LSL #48
153 autda \dst
, \addr_mutable
154 #elif ISA_SIGNING_AUTH_MODE == ISA_SIGNING_STRIP
167 .macro TailCallFunctionPointer
168 // $0 = function pointer value
172 .macro TailCallCachedImp
173 // $0 = cached imp, $1 = address of cached imp, $2 = SEL, $3 = isa
178 .macro TailCallMethodListImp
179 // $0 = method list imp, $1 = address of method list imp
183 .macro TailCallBlockInvoke
184 // $0 = invoke function, $1 = address of invoke function
188 .macro AuthAndResignAsIMP
189 // $0 = cached imp, $1 = address of cached imp, $2 = SEL
197 and $
0, $
1, #ISA_MASK
203 #define TailCallBlockInvoke TailCallMethodListImp