| 1 |
/* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd. |
| 2 |
|
| 3 |
Permission is hereby granted, free of charge, to any person obtaining |
| 4 |
a copy of this software and associated documentation files (the |
| 5 |
``Software''), to deal in the Software without restriction, including |
| 6 |
without limitation the rights to use, copy, modify, merge, publish, |
| 7 |
distribute, sublicense, and/or sell copies of the Software, and to |
| 8 |
permit persons to whom the Software is furnished to do so, subject to |
| 9 |
the following conditions: |
| 10 |
|
| 11 |
The above copyright notice and this permission notice shall be |
| 12 |
included in all copies or substantial portions of the Software. |
| 13 |
|
| 14 |
THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, |
| 15 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 16 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 17 |
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 18 |
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 19 |
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 20 |
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 21 |
|
| 22 |
#if defined(__aarch64__) || defined(__arm64__) |
| 23 |
#define LIBFFI_ASM |
| 24 |
#include <fficonfig.h> |
| 25 |
#include <ffi.h> |
| 26 |
#include <ffi_cfi.h> |
| 27 |
#include "internal.h" |
| 28 |
|
| 29 |
#ifdef HAVE_MACHINE_ASM_H |
| 30 |
#include <machine/asm.h> |
| 31 |
#else |
| 32 |
#ifdef __USER_LABEL_PREFIX__ |
| 33 |
#define CONCAT1(a, b) CONCAT2(a, b) |
| 34 |
#define CONCAT2(a, b) a ## b |
| 35 |
|
| 36 |
/* Use the right prefix for global labels. */ |
| 37 |
#define CNAME(x) CONCAT1 (__USER_LABEL_PREFIX__, x) |
| 38 |
#else |
| 39 |
#define CNAME(x) x |
| 40 |
#endif |
| 41 |
#endif |
| 42 |
|
| 43 |
#ifdef __APPLE__ |
| 44 |
# define L(X) CONCAT1(L, X) |
| 45 |
#else |
| 46 |
# define L(X) CONCAT1(.L, X) |
| 47 |
#endif |
| 48 |
|
| 49 |
#ifdef __AARCH64EB__ |
| 50 |
# define BE(X) X |
| 51 |
#else |
| 52 |
# define BE(X) 0 |
| 53 |
#endif |
| 54 |
|
| 55 |
#ifdef __ILP32__ |
| 56 |
#define PTR_REG(n) w##n |
| 57 |
#else |
| 58 |
#define PTR_REG(n) x##n |
| 59 |
#endif |
| 60 |
|
| 61 |
#ifdef __ILP32__ |
| 62 |
#define PTR_SIZE 4 |
| 63 |
#else |
| 64 |
#define PTR_SIZE 8 |
| 65 |
#endif |
| 66 |
|
| 67 |
#define BTI_C hint #34 |
| 68 |
#define BTI_J hint #36 |
| 69 |
/* |
| 70 |
* The ELF Notes section needs to indicate if BTI is supported, as the first ELF loaded that doesn't |
| 71 |
* declare this support disables it for memory region containing the loaded library. |
| 72 |
*/ |
| 73 |
# define GNU_PROPERTY_AARCH64_BTI (1 << 0) /* Has Branch Target Identification */ |
| 74 |
.text |
| 75 |
.align 4 |
| 76 |
|
| 77 |
/* ffi_call_SYSV |
| 78 |
extern void ffi_call_SYSV (void *stack, void *frame, |
| 79 |
void (*fn)(void), void *rvalue, |
| 80 |
int flags, void *closure); |
| 81 |
|
| 82 |
Therefore on entry we have: |
| 83 |
|
| 84 |
x0 stack |
| 85 |
x1 frame |
| 86 |
x2 fn |
| 87 |
x3 rvalue |
| 88 |
x4 flags |
| 89 |
x5 closure |
| 90 |
*/ |
| 91 |
|
| 92 |
CNAME(ffi_call_SYSV): |
| 93 |
cfi_startproc |
| 94 |
BTI_C |
| 95 |
PAC_CFI_WINDOW_SAVE |
| 96 |
/* Sign the lr with x1 since that is the CFA which is the modifer used in auth instructions */ |
| 97 |
SIGN_LR_WITH_REG(x1) |
| 98 |
|
| 99 |
#if defined(HAVE_ARM64E_PTRAUTH) && defined(__APPLE__) |
| 100 |
/* darwin's libunwind assumes that the cfa is the sp and that's the data |
| 101 |
* used to sign the lr. In order to allow unwinding through this |
| 102 |
* function it is necessary to point the cfa at the signing register. |
| 103 |
*/ |
| 104 |
cfi_def_cfa(x1, 0); |
| 105 |
#endif |
| 106 |
/* Use a stack frame allocated by our caller. */ |
| 107 |
stp x29, x30, [x1] |
| 108 |
cfi_def_cfa_register(x1) |
| 109 |
cfi_rel_offset (x29, 0) |
| 110 |
cfi_rel_offset (x30, 8) |
| 111 |
mov x9, sp |
| 112 |
str x9, [x1, #32] |
| 113 |
mov x29, x1 |
| 114 |
cfi_def_cfa_register(x29) |
| 115 |
mov sp, x0 |
| 116 |
|
| 117 |
mov x9, x2 /* save fn */ |
| 118 |
mov x8, x3 /* install structure return */ |
| 119 |
#ifdef FFI_GO_CLOSURES |
| 120 |
mov x18, x5 /* install static chain */ |
| 121 |
#endif |
| 122 |
stp x3, x4, [x29, #16] /* save rvalue and flags */ |
| 123 |
|
| 124 |
/* Load the vector argument passing registers, if necessary. */ |
| 125 |
tbz w4, #AARCH64_FLAG_ARG_V_BIT, 1f |
| 126 |
ldp q0, q1, [sp, #0] |
| 127 |
ldp q2, q3, [sp, #32] |
| 128 |
ldp q4, q5, [sp, #64] |
| 129 |
ldp q6, q7, [sp, #96] |
| 130 |
1: |
| 131 |
/* Load the core argument passing registers, including |
| 132 |
the structure return pointer. */ |
| 133 |
ldp x0, x1, [sp, #16*N_V_ARG_REG + 0] |
| 134 |
ldp x2, x3, [sp, #16*N_V_ARG_REG + 16] |
| 135 |
ldp x4, x5, [sp, #16*N_V_ARG_REG + 32] |
| 136 |
ldp x6, x7, [sp, #16*N_V_ARG_REG + 48] |
| 137 |
|
| 138 |
/* Deallocate the context, leaving the stacked arguments. */ |
| 139 |
add sp, sp, #CALL_CONTEXT_SIZE |
| 140 |
|
| 141 |
BRANCH_AND_LINK_TO_REG x9 /* call fn */ |
| 142 |
|
| 143 |
ldp x3, x4, [x29, #16] /* reload rvalue and flags */ |
| 144 |
|
| 145 |
/* Partially deconstruct the stack frame. */ |
| 146 |
ldr x9, [x29, #32] |
| 147 |
mov sp, x9 |
| 148 |
cfi_def_cfa_register (sp) |
| 149 |
mov x2, x29 /* Preserve for auth */ |
| 150 |
ldp x29, x30, [x29] |
| 151 |
|
| 152 |
/* Save the return value as directed. */ |
| 153 |
adr x5, 0f |
| 154 |
and w4, w4, #AARCH64_RET_MASK |
| 155 |
add x5, x5, x4, lsl #4 |
| 156 |
br x5 |
| 157 |
|
| 158 |
/* Note that each table entry is 4 insns, and thus 16 bytes. |
| 159 |
For integer data, note that we're storing into ffi_arg |
| 160 |
and therefore we want to extend to 64 bits; these types |
| 161 |
have two consecutive entries allocated for them. */ |
| 162 |
.align 4 |
| 163 |
0: BTI_J /* VOID */ |
| 164 |
b 99f |
| 165 |
nop |
| 166 |
nop |
| 167 |
1: BTI_J /* INT64 */ |
| 168 |
str x0, [x3] |
| 169 |
b 99f |
| 170 |
nop |
| 171 |
2: BTI_J /* INT128 */ |
| 172 |
stp x0, x1, [x3] |
| 173 |
b 99f |
| 174 |
nop |
| 175 |
3: brk #1000 /* UNUSED */ |
| 176 |
b 99f |
| 177 |
nop |
| 178 |
nop |
| 179 |
4: brk #1000 /* UNUSED */ |
| 180 |
b 99f |
| 181 |
nop |
| 182 |
nop |
| 183 |
5: brk #1000 /* UNUSED */ |
| 184 |
b 99f |
| 185 |
nop |
| 186 |
nop |
| 187 |
6: brk #1000 /* UNUSED */ |
| 188 |
b 99f |
| 189 |
nop |
| 190 |
nop |
| 191 |
7: brk #1000 /* UNUSED */ |
| 192 |
b 99f |
| 193 |
nop |
| 194 |
nop |
| 195 |
8: BTI_J /* S4 */ |
| 196 |
st4 { v0.s, v1.s, v2.s, v3.s }[0], [x3] |
| 197 |
b 99f |
| 198 |
nop |
| 199 |
9: BTI_J /* S3 */ |
| 200 |
st3 { v0.s, v1.s, v2.s }[0], [x3] |
| 201 |
b 99f |
| 202 |
nop |
| 203 |
10: BTI_J /* S2 */ |
| 204 |
stp s0, s1, [x3] |
| 205 |
b 99f |
| 206 |
nop |
| 207 |
11: BTI_J |
| 208 |
str s0, [x3] /* S1 */ |
| 209 |
b 99f |
| 210 |
nop |
| 211 |
12: BTI_J /* D4 */ |
| 212 |
st4 { v0.d, v1.d, v2.d, v3.d }[0], [x3] |
| 213 |
b 99f |
| 214 |
nop |
| 215 |
13: BTI_J /* D3 */ |
| 216 |
st3 { v0.d, v1.d, v2.d }[0], [x3] |
| 217 |
b 99f |
| 218 |
nop |
| 219 |
14: BTI_J /* D2 */ |
| 220 |
stp d0, d1, [x3] |
| 221 |
b 99f |
| 222 |
nop |
| 223 |
15: BTI_J /* D1 */ |
| 224 |
str d0, [x3] |
| 225 |
b 99f |
| 226 |
nop |
| 227 |
16: BTI_J /* Q4 */ |
| 228 |
str q3, [x3, #48] |
| 229 |
nop |
| 230 |
nop |
| 231 |
17: BTI_J /* Q3 */ |
| 232 |
str q2, [x3, #32] |
| 233 |
nop |
| 234 |
nop |
| 235 |
18: BTI_J /* Q2 */ |
| 236 |
stp q0, q1, [x3] |
| 237 |
b 99f |
| 238 |
nop |
| 239 |
19: BTI_J /* Q1 */ |
| 240 |
str q0, [x3] |
| 241 |
b 99f |
| 242 |
nop |
| 243 |
20: BTI_J /* UINT8 */ |
| 244 |
uxtb w0, w0 |
| 245 |
str x0, [x3] |
| 246 |
nop |
| 247 |
21: b 99f /* reserved */ |
| 248 |
nop |
| 249 |
nop |
| 250 |
nop |
| 251 |
22: BTI_J /* UINT16 */ |
| 252 |
uxth w0, w0 |
| 253 |
str x0, [x3] |
| 254 |
nop |
| 255 |
23: b 99f /* reserved */ |
| 256 |
nop |
| 257 |
nop |
| 258 |
nop |
| 259 |
24: BTI_J /* UINT32 */ |
| 260 |
mov w0, w0 |
| 261 |
str x0, [x3] |
| 262 |
nop |
| 263 |
25: b 99f /* reserved */ |
| 264 |
nop |
| 265 |
nop |
| 266 |
nop |
| 267 |
26: BTI_J /* SINT8 */ |
| 268 |
sxtb x0, w0 |
| 269 |
str x0, [x3] |
| 270 |
nop |
| 271 |
27: b 99f /* reserved */ |
| 272 |
nop |
| 273 |
nop |
| 274 |
nop |
| 275 |
28: BTI_J /* SINT16 */ |
| 276 |
sxth x0, w0 |
| 277 |
str x0, [x3] |
| 278 |
nop |
| 279 |
29: b 99f /* reserved */ |
| 280 |
nop |
| 281 |
nop |
| 282 |
nop |
| 283 |
30: BTI_J /* SINT32 */ |
| 284 |
sxtw x0, w0 |
| 285 |
str x0, [x3] |
| 286 |
nop |
| 287 |
31: b 99f /* reserved */ |
| 288 |
nop |
| 289 |
nop |
| 290 |
nop |
| 291 |
|
| 292 |
/* Return now that result has been populated. */ |
| 293 |
99: |
| 294 |
AUTH_LR_WITH_REG(x2) |
| 295 |
ret |
| 296 |
|
| 297 |
cfi_endproc |
| 298 |
|
| 299 |
.globl CNAME(ffi_call_SYSV) |
| 300 |
FFI_HIDDEN(CNAME(ffi_call_SYSV)) |
| 301 |
#ifdef __ELF__ |
| 302 |
.type CNAME(ffi_call_SYSV), #function |
| 303 |
.size CNAME(ffi_call_SYSV), .-CNAME(ffi_call_SYSV) |
| 304 |
#endif |
| 305 |
|
| 306 |
#if FFI_CLOSURES |
| 307 |
|
| 308 |
/* ffi_closure_SYSV |
| 309 |
|
| 310 |
Closure invocation glue. This is the low level code invoked directly by |
| 311 |
the closure trampoline to setup and call a closure. |
| 312 |
|
| 313 |
On entry x17 points to a struct ffi_closure, x16 has been clobbered |
| 314 |
all other registers are preserved. |
| 315 |
|
| 316 |
We allocate a call context and save the argument passing registers, |
| 317 |
then invoked the generic C ffi_closure_SYSV_inner() function to do all |
| 318 |
the real work, on return we load the result passing registers back from |
| 319 |
the call context. |
| 320 |
*/ |
| 321 |
|
| 322 |
#define ffi_closure_SYSV_FS (8*2 + CALL_CONTEXT_SIZE + 64) |
| 323 |
|
| 324 |
.align 4 |
| 325 |
CNAME(ffi_closure_SYSV_V): |
| 326 |
cfi_startproc |
| 327 |
BTI_C |
| 328 |
SIGN_LR |
| 329 |
PAC_CFI_WINDOW_SAVE |
| 330 |
stp x29, x30, [sp, #-ffi_closure_SYSV_FS]! |
| 331 |
cfi_adjust_cfa_offset (ffi_closure_SYSV_FS) |
| 332 |
cfi_rel_offset (x29, 0) |
| 333 |
cfi_rel_offset (x30, 8) |
| 334 |
|
| 335 |
/* Save the argument passing vector registers. */ |
| 336 |
stp q0, q1, [sp, #16 + 0] |
| 337 |
stp q2, q3, [sp, #16 + 32] |
| 338 |
stp q4, q5, [sp, #16 + 64] |
| 339 |
stp q6, q7, [sp, #16 + 96] |
| 340 |
b 0f |
| 341 |
cfi_endproc |
| 342 |
|
| 343 |
.globl CNAME(ffi_closure_SYSV_V) |
| 344 |
FFI_HIDDEN(CNAME(ffi_closure_SYSV_V)) |
| 345 |
#ifdef __ELF__ |
| 346 |
.type CNAME(ffi_closure_SYSV_V), #function |
| 347 |
.size CNAME(ffi_closure_SYSV_V), . - CNAME(ffi_closure_SYSV_V) |
| 348 |
#endif |
| 349 |
|
| 350 |
.align 4 |
| 351 |
CNAME(ffi_closure_SYSV): |
| 352 |
cfi_startproc |
| 353 |
BTI_C |
| 354 |
SIGN_LR |
| 355 |
PAC_CFI_WINDOW_SAVE |
| 356 |
stp x29, x30, [sp, #-ffi_closure_SYSV_FS]! |
| 357 |
cfi_adjust_cfa_offset (ffi_closure_SYSV_FS) |
| 358 |
cfi_rel_offset (x29, 0) |
| 359 |
cfi_rel_offset (x30, 8) |
| 360 |
0: |
| 361 |
mov x29, sp |
| 362 |
|
| 363 |
/* Save the argument passing core registers. */ |
| 364 |
stp x0, x1, [sp, #16 + 16*N_V_ARG_REG + 0] |
| 365 |
stp x2, x3, [sp, #16 + 16*N_V_ARG_REG + 16] |
| 366 |
stp x4, x5, [sp, #16 + 16*N_V_ARG_REG + 32] |
| 367 |
stp x6, x7, [sp, #16 + 16*N_V_ARG_REG + 48] |
| 368 |
|
| 369 |
/* Load ffi_closure_inner arguments. */ |
| 370 |
ldp PTR_REG(0), PTR_REG(1), [x17, #FFI_TRAMPOLINE_CLOSURE_OFFSET] /* load cif, fn */ |
| 371 |
ldr PTR_REG(2), [x17, #FFI_TRAMPOLINE_CLOSURE_OFFSET+PTR_SIZE*2] /* load user_data */ |
| 372 |
#ifdef FFI_GO_CLOSURES |
| 373 |
L(do_closure): |
| 374 |
#endif |
| 375 |
add x3, sp, #16 /* load context */ |
| 376 |
add x4, sp, #ffi_closure_SYSV_FS /* load stack */ |
| 377 |
add x5, sp, #16+CALL_CONTEXT_SIZE /* load rvalue */ |
| 378 |
mov x6, x8 /* load struct_rval */ |
| 379 |
bl CNAME(ffi_closure_SYSV_inner) |
| 380 |
|
| 381 |
/* Load the return value as directed. */ |
| 382 |
adr x1, 0f |
| 383 |
and w0, w0, #AARCH64_RET_MASK |
| 384 |
add x1, x1, x0, lsl #4 |
| 385 |
add x3, sp, #16+CALL_CONTEXT_SIZE |
| 386 |
br x1 |
| 387 |
|
| 388 |
/* Note that each table entry is 4 insns, and thus 16 bytes. */ |
| 389 |
.align 4 |
| 390 |
0: BTI_J /* VOID */ |
| 391 |
b 99f |
| 392 |
nop |
| 393 |
nop |
| 394 |
1: BTI_J /* INT64 */ |
| 395 |
ldr x0, [x3] |
| 396 |
b 99f |
| 397 |
nop |
| 398 |
2: BTI_J /* INT128 */ |
| 399 |
ldp x0, x1, [x3] |
| 400 |
b 99f |
| 401 |
nop |
| 402 |
3: brk #1000 /* UNUSED */ |
| 403 |
nop |
| 404 |
nop |
| 405 |
nop |
| 406 |
4: brk #1000 /* UNUSED */ |
| 407 |
nop |
| 408 |
nop |
| 409 |
nop |
| 410 |
5: brk #1000 /* UNUSED */ |
| 411 |
nop |
| 412 |
nop |
| 413 |
nop |
| 414 |
6: brk #1000 /* UNUSED */ |
| 415 |
nop |
| 416 |
nop |
| 417 |
nop |
| 418 |
7: brk #1000 /* UNUSED */ |
| 419 |
nop |
| 420 |
nop |
| 421 |
nop |
| 422 |
8: BTI_J /* S4 */ |
| 423 |
ldr s3, [x3, #12] |
| 424 |
nop |
| 425 |
nop |
| 426 |
9: BTI_J /* S3 */ |
| 427 |
ldr s2, [x3, #8] |
| 428 |
nop |
| 429 |
nop |
| 430 |
10: BTI_J /* S2 */ |
| 431 |
ldp s0, s1, [x3] |
| 432 |
b 99f |
| 433 |
nop |
| 434 |
11: BTI_J /* S1 */ |
| 435 |
ldr s0, [x3] |
| 436 |
b 99f |
| 437 |
nop |
| 438 |
12: BTI_J /* D4 */ |
| 439 |
ldr d3, [x3, #24] |
| 440 |
nop |
| 441 |
nop |
| 442 |
13: BTI_J /* D3 */ |
| 443 |
ldr d2, [x3, #16] |
| 444 |
nop |
| 445 |
nop |
| 446 |
14: BTI_J /* D2 */ |
| 447 |
ldp d0, d1, [x3] |
| 448 |
b 99f |
| 449 |
nop |
| 450 |
15: BTI_J /* D1 */ |
| 451 |
ldr d0, [x3] |
| 452 |
b 99f |
| 453 |
nop |
| 454 |
16: BTI_J /* Q4 */ |
| 455 |
ldr q3, [x3, #48] |
| 456 |
nop |
| 457 |
nop |
| 458 |
17: BTI_J /* Q3 */ |
| 459 |
ldr q2, [x3, #32] |
| 460 |
nop |
| 461 |
nop |
| 462 |
18: BTI_J /* Q2 */ |
| 463 |
ldp q0, q1, [x3] |
| 464 |
b 99f |
| 465 |
nop |
| 466 |
19: BTI_J /* Q1 */ |
| 467 |
ldr q0, [x3] |
| 468 |
b 99f |
| 469 |
nop |
| 470 |
20: BTI_J /* UINT8 */ |
| 471 |
ldrb w0, [x3, #BE(7)] |
| 472 |
b 99f |
| 473 |
nop |
| 474 |
21: brk #1000 /* reserved */ |
| 475 |
nop |
| 476 |
nop |
| 477 |
nop |
| 478 |
22: BTI_J /* UINT16 */ |
| 479 |
ldrh w0, [x3, #BE(6)] |
| 480 |
b 99f |
| 481 |
nop |
| 482 |
23: brk #1000 /* reserved */ |
| 483 |
nop |
| 484 |
nop |
| 485 |
nop |
| 486 |
24: BTI_J /* UINT32 */ |
| 487 |
ldr w0, [x3, #BE(4)] |
| 488 |
b 99f |
| 489 |
nop |
| 490 |
25: brk #1000 /* reserved */ |
| 491 |
nop |
| 492 |
nop |
| 493 |
nop |
| 494 |
26: BTI_J /* SINT8 */ |
| 495 |
ldrsb x0, [x3, #BE(7)] |
| 496 |
b 99f |
| 497 |
nop |
| 498 |
27: brk #1000 /* reserved */ |
| 499 |
nop |
| 500 |
nop |
| 501 |
nop |
| 502 |
28: BTI_J /* SINT16 */ |
| 503 |
ldrsh x0, [x3, #BE(6)] |
| 504 |
b 99f |
| 505 |
nop |
| 506 |
29: brk #1000 /* reserved */ |
| 507 |
nop |
| 508 |
nop |
| 509 |
nop |
| 510 |
30: BTI_J /* SINT32 */ |
| 511 |
ldrsw x0, [x3, #BE(4)] |
| 512 |
nop |
| 513 |
nop |
| 514 |
31: /* reserved */ |
| 515 |
99: ldp x29, x30, [sp], #ffi_closure_SYSV_FS |
| 516 |
cfi_adjust_cfa_offset (-ffi_closure_SYSV_FS) |
| 517 |
cfi_restore (x29) |
| 518 |
cfi_restore (x30) |
| 519 |
AUTH_LR_AND_RET |
| 520 |
cfi_endproc |
| 521 |
|
| 522 |
.globl CNAME(ffi_closure_SYSV) |
| 523 |
FFI_HIDDEN(CNAME(ffi_closure_SYSV)) |
| 524 |
#ifdef __ELF__ |
| 525 |
.type CNAME(ffi_closure_SYSV), #function |
| 526 |
.size CNAME(ffi_closure_SYSV), . - CNAME(ffi_closure_SYSV) |
| 527 |
#endif |
| 528 |
|
| 529 |
#if defined(FFI_EXEC_STATIC_TRAMP) |
| 530 |
.align 4 |
| 531 |
CNAME(ffi_closure_SYSV_V_alt): |
| 532 |
BTI_C |
| 533 |
/* See the comments above trampoline_code_table. */ |
| 534 |
ldr x17, [sp, #8] /* Load closure in x17 */ |
| 535 |
add sp, sp, #16 /* Restore the stack */ |
| 536 |
b CNAME(ffi_closure_SYSV_V) |
| 537 |
|
| 538 |
.globl CNAME(ffi_closure_SYSV_V_alt) |
| 539 |
FFI_HIDDEN(CNAME(ffi_closure_SYSV_V_alt)) |
| 540 |
#ifdef __ELF__ |
| 541 |
.type CNAME(ffi_closure_SYSV_V_alt), #function |
| 542 |
.size CNAME(ffi_closure_SYSV_V_alt), . - CNAME(ffi_closure_SYSV_V_alt) |
| 543 |
#endif |
| 544 |
|
| 545 |
.align 4 |
| 546 |
CNAME(ffi_closure_SYSV_alt): |
| 547 |
BTI_C |
| 548 |
/* See the comments above trampoline_code_table. */ |
| 549 |
ldr x17, [sp, #8] /* Load closure in x17 */ |
| 550 |
add sp, sp, #16 /* Restore the stack */ |
| 551 |
b CNAME(ffi_closure_SYSV) |
| 552 |
|
| 553 |
.globl CNAME(ffi_closure_SYSV_alt) |
| 554 |
FFI_HIDDEN(CNAME(ffi_closure_SYSV_alt)) |
| 555 |
#ifdef __ELF__ |
| 556 |
.type CNAME(ffi_closure_SYSV_alt), #function |
| 557 |
.size CNAME(ffi_closure_SYSV_alt), . - CNAME(ffi_closure_SYSV_alt) |
| 558 |
#endif |
| 559 |
|
| 560 |
/* |
| 561 |
* Below is the definition of the trampoline code table. Each element in |
| 562 |
* the code table is a trampoline. |
| 563 |
*/ |
| 564 |
/* |
| 565 |
* The trampoline uses register x17. It saves the original value of x17 on |
| 566 |
* the stack. |
| 567 |
* |
| 568 |
* The trampoline has two parameters - target code to jump to and data for |
| 569 |
* the target code. The trampoline extracts the parameters from its parameter |
| 570 |
* block (see tramp_table_map()). The trampoline saves the data address on |
| 571 |
* the stack. Finally, it jumps to the target code. |
| 572 |
* |
| 573 |
* The target code can choose to: |
| 574 |
* |
| 575 |
* - restore the value of x17 |
| 576 |
* - load the data address in a register |
| 577 |
* - restore the stack pointer to what it was when the trampoline was invoked. |
| 578 |
*/ |
| 579 |
.align AARCH64_TRAMP_MAP_SHIFT |
| 580 |
CNAME(trampoline_code_table): |
| 581 |
.rept AARCH64_TRAMP_MAP_SIZE / AARCH64_TRAMP_SIZE |
| 582 |
sub sp, sp, #16 /* Make space on the stack */ |
| 583 |
str x17, [sp] /* Save x17 on stack */ |
| 584 |
adr x17, #16376 /* Get data address */ |
| 585 |
ldr x17, [x17] /* Copy data into x17 */ |
| 586 |
str x17, [sp, #8] /* Save data on stack */ |
| 587 |
adr x17, #16372 /* Get code address */ |
| 588 |
ldr x17, [x17] /* Load code address into x17 */ |
| 589 |
br x17 /* Jump to code */ |
| 590 |
.endr |
| 591 |
|
| 592 |
.globl CNAME(trampoline_code_table) |
| 593 |
FFI_HIDDEN(CNAME(trampoline_code_table)) |
| 594 |
#ifdef __ELF__ |
| 595 |
.type CNAME(trampoline_code_table), #function |
| 596 |
.size CNAME(trampoline_code_table), . - CNAME(trampoline_code_table) |
| 597 |
#endif |
| 598 |
.align AARCH64_TRAMP_MAP_SHIFT |
| 599 |
#endif /* FFI_EXEC_STATIC_TRAMP */ |
| 600 |
|
| 601 |
#if FFI_EXEC_TRAMPOLINE_TABLE |
| 602 |
|
| 603 |
#ifdef __MACH__ |
| 604 |
#include <mach/machine/vm_param.h> |
| 605 |
.align PAGE_MAX_SHIFT |
| 606 |
CNAME(ffi_closure_trampoline_table_page): |
| 607 |
.rept PAGE_MAX_SIZE / FFI_TRAMPOLINE_SIZE |
| 608 |
adr x16, -PAGE_MAX_SIZE |
| 609 |
ldp x17, x16, [x16] |
| 610 |
br x16 |
| 611 |
nop /* each entry in the trampoline config page is 2*sizeof(void*) so the trampoline itself cannot be smaller than 16 bytes */ |
| 612 |
.endr |
| 613 |
|
| 614 |
.globl CNAME(ffi_closure_trampoline_table_page) |
| 615 |
FFI_HIDDEN(CNAME(ffi_closure_trampoline_table_page)) |
| 616 |
#ifdef __ELF__ |
| 617 |
.type CNAME(ffi_closure_trampoline_table_page), #function |
| 618 |
.size CNAME(ffi_closure_trampoline_table_page), . - CNAME(ffi_closure_trampoline_table_page) |
| 619 |
#endif |
| 620 |
#endif |
| 621 |
|
| 622 |
#endif /* FFI_EXEC_TRAMPOLINE_TABLE */ |
| 623 |
|
| 624 |
#ifdef FFI_GO_CLOSURES |
| 625 |
.align 4 |
| 626 |
CNAME(ffi_go_closure_SYSV_V): |
| 627 |
cfi_startproc |
| 628 |
BTI_C |
| 629 |
stp x29, x30, [sp, #-ffi_closure_SYSV_FS]! |
| 630 |
cfi_adjust_cfa_offset (ffi_closure_SYSV_FS) |
| 631 |
cfi_rel_offset (x29, 0) |
| 632 |
cfi_rel_offset (x30, 8) |
| 633 |
|
| 634 |
/* Save the argument passing vector registers. */ |
| 635 |
stp q0, q1, [sp, #16 + 0] |
| 636 |
stp q2, q3, [sp, #16 + 32] |
| 637 |
stp q4, q5, [sp, #16 + 64] |
| 638 |
stp q6, q7, [sp, #16 + 96] |
| 639 |
b 0f |
| 640 |
cfi_endproc |
| 641 |
|
| 642 |
.globl CNAME(ffi_go_closure_SYSV_V) |
| 643 |
FFI_HIDDEN(CNAME(ffi_go_closure_SYSV_V)) |
| 644 |
#ifdef __ELF__ |
| 645 |
.type CNAME(ffi_go_closure_SYSV_V), #function |
| 646 |
.size CNAME(ffi_go_closure_SYSV_V), . - CNAME(ffi_go_closure_SYSV_V) |
| 647 |
#endif |
| 648 |
|
| 649 |
.align 4 |
| 650 |
CNAME(ffi_go_closure_SYSV): |
| 651 |
cfi_startproc |
| 652 |
BTI_C |
| 653 |
SIGN_LR_LINUX_ONLY |
| 654 |
PAC_CFI_WINDOW_SAVE |
| 655 |
stp x29, x30, [sp, #-ffi_closure_SYSV_FS]! |
| 656 |
cfi_adjust_cfa_offset (ffi_closure_SYSV_FS) |
| 657 |
cfi_rel_offset (x29, 0) |
| 658 |
cfi_rel_offset (x30, 8) |
| 659 |
0: |
| 660 |
mov x29, sp |
| 661 |
|
| 662 |
/* Save the argument passing core registers. */ |
| 663 |
stp x0, x1, [sp, #16 + 16*N_V_ARG_REG + 0] |
| 664 |
stp x2, x3, [sp, #16 + 16*N_V_ARG_REG + 16] |
| 665 |
stp x4, x5, [sp, #16 + 16*N_V_ARG_REG + 32] |
| 666 |
stp x6, x7, [sp, #16 + 16*N_V_ARG_REG + 48] |
| 667 |
|
| 668 |
/* Load ffi_closure_inner arguments. */ |
| 669 |
ldp PTR_REG(0), PTR_REG(1), [x18, #PTR_SIZE]/* load cif, fn */ |
| 670 |
mov x2, x18 /* load user_data */ |
| 671 |
b L(do_closure) |
| 672 |
cfi_endproc |
| 673 |
|
| 674 |
.globl CNAME(ffi_go_closure_SYSV) |
| 675 |
FFI_HIDDEN(CNAME(ffi_go_closure_SYSV)) |
| 676 |
#ifdef __ELF__ |
| 677 |
.type CNAME(ffi_go_closure_SYSV), #function |
| 678 |
.size CNAME(ffi_go_closure_SYSV), . - CNAME(ffi_go_closure_SYSV) |
| 679 |
#endif |
| 680 |
#endif /* FFI_GO_CLOSURES */ |
| 681 |
#endif /* FFI_CLOSURES */ |
| 682 |
#endif /* __arm64__ */ |
| 683 |
|
| 684 |
#if defined __ELF__ && defined __linux__ |
| 685 |
.section .note.GNU-stack,"",%progbits |
| 686 |
|
| 687 |
.pushsection .note.gnu.property, "a"; |
| 688 |
.balign 8; |
| 689 |
.long 4; |
| 690 |
.long 0x10; |
| 691 |
.long 0x5; |
| 692 |
.asciz "GNU"; |
| 693 |
.long 0xc0000000; /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */ |
| 694 |
.long 4; |
| 695 |
.long GNU_PROPERTY_AARCH64_BTI | GNU_PROPERTY_AARCH64_POINTER_AUTH; |
| 696 |
.long 0; |
| 697 |
.popsection; |
| 698 |
#endif |
| 699 |
|