ffi 1.16.3 → 1.17.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +59 -0
  4. data/Gemfile +11 -2
  5. data/README.md +1 -1
  6. data/Rakefile +19 -7
  7. data/ext/ffi_c/AbstractMemory.c +39 -38
  8. data/ext/ffi_c/ArrayType.c +2 -2
  9. data/ext/ffi_c/Buffer.c +4 -4
  10. data/ext/ffi_c/Call.c +12 -6
  11. data/ext/ffi_c/Call.h +3 -2
  12. data/ext/ffi_c/DynamicLibrary.c +2 -2
  13. data/ext/ffi_c/Function.c +52 -34
  14. data/ext/ffi_c/FunctionInfo.c +1 -1
  15. data/ext/ffi_c/LastError.c +4 -4
  16. data/ext/ffi_c/MemoryPointer.c +2 -2
  17. data/ext/ffi_c/Pointer.c +14 -11
  18. data/ext/ffi_c/Struct.c +11 -4
  19. data/ext/ffi_c/StructLayout.c +13 -13
  20. data/ext/ffi_c/Type.c +17 -16
  21. data/ext/ffi_c/Types.c +7 -1
  22. data/ext/ffi_c/Types.h +0 -1
  23. data/ext/ffi_c/Variadic.c +6 -3
  24. data/ext/ffi_c/libffi/.allow-ai-service +0 -0
  25. data/ext/ffi_c/libffi/.github/workflows/build.yml +34 -15
  26. data/ext/ffi_c/libffi/.github/workflows/emscripten.yml +50 -61
  27. data/ext/ffi_c/libffi/LICENSE +1 -1
  28. data/ext/ffi_c/libffi/Makefile.am +4 -3
  29. data/ext/ffi_c/libffi/Makefile.in +5 -25
  30. data/ext/ffi_c/libffi/README.md +28 -6
  31. data/ext/ffi_c/libffi/acinclude.m4 +6 -0
  32. data/ext/ffi_c/libffi/config.guess +80 -22
  33. data/ext/ffi_c/libffi/config.sub +161 -80
  34. data/ext/ffi_c/libffi/configure +46 -30
  35. data/ext/ffi_c/libffi/configure.ac +10 -9
  36. data/ext/ffi_c/libffi/configure.host +1 -6
  37. data/ext/ffi_c/libffi/doc/Makefile.in +1 -0
  38. data/ext/ffi_c/libffi/doc/libffi.texi +4 -4
  39. data/ext/ffi_c/libffi/doc/version.texi +4 -4
  40. data/ext/ffi_c/libffi/fficonfig.h.in +3 -3
  41. data/ext/ffi_c/libffi/include/Makefile.in +1 -0
  42. data/ext/ffi_c/libffi/include/ffi.h.in +2 -11
  43. data/ext/ffi_c/libffi/include/ffi_cfi.h +2 -0
  44. data/ext/ffi_c/libffi/include/ffi_common.h +21 -2
  45. data/ext/ffi_c/libffi/libffi.map.in +5 -0
  46. data/ext/ffi_c/libffi/libtool-version +1 -1
  47. data/ext/ffi_c/libffi/ltmain.sh +8 -20
  48. data/ext/ffi_c/libffi/man/Makefile.in +1 -0
  49. data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/ffi.h +1 -1
  50. data/ext/ffi_c/libffi/src/aarch64/ffi.c +33 -17
  51. data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +2 -2
  52. data/ext/ffi_c/libffi/src/aarch64/internal.h +63 -17
  53. data/ext/ffi_c/libffi/src/aarch64/sysv.S +213 -57
  54. data/ext/ffi_c/libffi/src/arc/arcompact.S +2 -2
  55. data/ext/ffi_c/libffi/src/arc/ffi.c +6 -2
  56. data/ext/ffi_c/libffi/src/closures.c +6 -6
  57. data/ext/ffi_c/libffi/src/debug.c +2 -2
  58. data/ext/ffi_c/libffi/src/dlmalloc.c +2 -1
  59. data/ext/ffi_c/libffi/src/loongarch64/ffi.c +3 -0
  60. data/ext/ffi_c/libffi/src/mips/ffi.c +12 -4
  61. data/ext/ffi_c/libffi/src/mips/ffitarget.h +2 -4
  62. data/ext/ffi_c/libffi/src/mips/n32.S +69 -14
  63. data/ext/ffi_c/libffi/src/mips/o32.S +4 -0
  64. data/ext/ffi_c/libffi/src/or1k/ffi.c +2 -2
  65. data/ext/ffi_c/libffi/src/powerpc/ffi.c +13 -0
  66. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +36 -24
  67. data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +26 -19
  68. data/ext/ffi_c/libffi/src/powerpc/ffi_sysv.c +26 -16
  69. data/ext/ffi_c/libffi/src/powerpc/internal.h +10 -0
  70. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +47 -0
  71. data/ext/ffi_c/libffi/src/powerpc/ppc_closure.S +24 -0
  72. data/ext/ffi_c/libffi/src/prep_cif.c +1 -4
  73. data/ext/ffi_c/libffi/src/s390/ffi.c +28 -1
  74. data/ext/ffi_c/libffi/src/s390/internal.h +11 -0
  75. data/ext/ffi_c/libffi/src/s390/sysv.S +38 -0
  76. data/ext/ffi_c/libffi/src/sparc/ffi.c +16 -0
  77. data/ext/ffi_c/libffi/src/sparc/ffi64.c +7 -1
  78. data/ext/ffi_c/libffi/src/tramp.c +1 -1
  79. data/ext/ffi_c/libffi/src/types.c +4 -6
  80. data/ext/ffi_c/libffi/src/wasm32/ffi.c +23 -262
  81. data/ext/ffi_c/libffi/src/x86/ffi.c +4 -1
  82. data/ext/ffi_c/libffi/src/x86/ffi64.c +4 -1
  83. data/ext/ffi_c/libffi/src/x86/ffiw64.c +1 -1
  84. data/ext/ffi_c/libffi/testsuite/Makefile.am +80 -127
  85. data/ext/ffi_c/libffi/testsuite/Makefile.in +81 -127
  86. data/ext/ffi_c/libffi/testsuite/emscripten/build-tests.sh +4 -24
  87. data/ext/ffi_c/libffi/testsuite/emscripten/build.sh +8 -25
  88. data/ext/ffi_c/libffi/testsuite/emscripten/conftest.py +6 -0
  89. data/ext/ffi_c/libffi/testsuite/emscripten/node-tests.sh +3 -28
  90. data/ext/ffi_c/libffi/testsuite/libffi.call/callback.c +99 -0
  91. data/ext/ffi_c/libffi/testsuite/libffi.call/callback2.c +108 -0
  92. data/ext/ffi_c/libffi/testsuite/libffi.call/callback3.c +114 -0
  93. data/ext/ffi_c/libffi/testsuite/libffi.call/callback4.c +119 -0
  94. data/ext/ffi_c/libffi/testsuite/libffi.call/overread.c +54 -0
  95. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_int_float.c +88 -0
  96. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct2.c +1 -0
  97. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct3.c +1 -0
  98. data/ext/ffi_c/libffi/testsuite/libffi.call/x32.c +31 -0
  99. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_sshortchar.c +1 -1
  100. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_ushortchar.c +1 -1
  101. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_int.c +1 -1
  102. data/ext/ffi_c/libffi.darwin.mk +2 -2
  103. data/lib/ffi/autopointer.rb +1 -9
  104. data/lib/ffi/dynamic_library.rb +34 -5
  105. data/lib/ffi/enum.rb +0 -1
  106. data/lib/ffi/ffi.rb +59 -0
  107. data/lib/ffi/function.rb +1 -1
  108. data/lib/ffi/io.rb +2 -2
  109. data/lib/ffi/library.rb +23 -23
  110. data/lib/ffi/platform/aarch64-linux/types.conf +74 -3
  111. data/lib/ffi/pointer.rb +6 -6
  112. data/lib/ffi/struct.rb +4 -4
  113. data/lib/ffi/struct_layout.rb +2 -2
  114. data/lib/ffi/struct_layout_builder.rb +8 -8
  115. data/lib/ffi/types.rb +51 -49
  116. data/lib/ffi/version.rb +1 -1
  117. data/sig/ffi/abstract_memory.rbs +165 -0
  118. data/sig/ffi/auto_pointer.rbs +26 -0
  119. data/sig/ffi/buffer.rbs +18 -0
  120. data/sig/ffi/data_converter.rbs +10 -0
  121. data/sig/ffi/dynamic_library.rbs +9 -0
  122. data/sig/ffi/enum.rbs +38 -0
  123. data/sig/ffi/function.rbs +39 -0
  124. data/sig/ffi/library.rbs +42 -0
  125. data/sig/ffi/native_type.rbs +86 -0
  126. data/sig/ffi/pointer.rbs +42 -0
  127. data/sig/ffi/struct.rbs +76 -0
  128. data/sig/ffi/struct_by_reference.rbs +11 -0
  129. data/sig/ffi/struct_by_value.rbs +7 -0
  130. data/sig/ffi/struct_layout.rbs +9 -0
  131. data/sig/ffi/struct_layout_builder.rbs +5 -0
  132. data/sig/ffi/type.rbs +39 -0
  133. data/sig/ffi.rbs +26 -0
  134. data.tar.gz.sig +0 -0
  135. metadata +41 -22
  136. metadata.gz.sig +0 -0
  137. data/ext/ffi_c/libffi/.circleci/config.yml +0 -156
  138. data/ext/ffi_c/libffi/src/nios2/ffi.c +0 -304
  139. data/ext/ffi_c/libffi/src/nios2/ffitarget.h +0 -52
  140. data/ext/ffi_c/libffi/src/nios2/sysv.S +0 -136
@@ -63,7 +63,7 @@ struct call_context
63
63
  #if FFI_EXEC_TRAMPOLINE_TABLE
64
64
 
65
65
  #ifdef __MACH__
66
- #ifdef HAVE_PTRAUTH
66
+ #ifdef HAVE_ARM64E_PTRAUTH
67
67
  #include <ptrauth.h>
68
68
  #endif
69
69
  #include <mach/vm_param.h>
@@ -386,51 +386,64 @@ extend_hfa_type (void *dest, void *src, int h)
386
386
  ssize_t f = h - AARCH64_RET_S4;
387
387
  void *x0;
388
388
 
389
+ #define BTI_J "hint #36"
389
390
  asm volatile (
390
391
  "adr %0, 0f\n"
391
392
  " add %0, %0, %1\n"
392
393
  " br %0\n"
393
- "0: ldp s16, s17, [%3]\n" /* S4 */
394
+ "0: "BTI_J"\n" /* S4 */
395
+ " ldp s16, s17, [%3]\n"
394
396
  " ldp s18, s19, [%3, #8]\n"
395
397
  " b 4f\n"
396
- " ldp s16, s17, [%3]\n" /* S3 */
398
+ " "BTI_J"\n" /* S3 */
399
+ " ldp s16, s17, [%3]\n"
397
400
  " ldr s18, [%3, #8]\n"
398
401
  " b 3f\n"
399
- " ldp s16, s17, [%3]\n" /* S2 */
402
+ " "BTI_J"\n" /* S2 */
403
+ " ldp s16, s17, [%3]\n"
400
404
  " b 2f\n"
401
405
  " nop\n"
402
- " ldr s16, [%3]\n" /* S1 */
406
+ " "BTI_J"\n" /* S1 */
407
+ " ldr s16, [%3]\n"
403
408
  " b 1f\n"
404
409
  " nop\n"
405
- " ldp d16, d17, [%3]\n" /* D4 */
410
+ " "BTI_J"\n" /* D4 */
411
+ " ldp d16, d17, [%3]\n"
406
412
  " ldp d18, d19, [%3, #16]\n"
407
413
  " b 4f\n"
408
- " ldp d16, d17, [%3]\n" /* D3 */
414
+ " "BTI_J"\n" /* D3 */
415
+ " ldp d16, d17, [%3]\n"
409
416
  " ldr d18, [%3, #16]\n"
410
417
  " b 3f\n"
411
- " ldp d16, d17, [%3]\n" /* D2 */
418
+ " "BTI_J"\n" /* D2 */
419
+ " ldp d16, d17, [%3]\n"
412
420
  " b 2f\n"
413
421
  " nop\n"
414
- " ldr d16, [%3]\n" /* D1 */
422
+ " "BTI_J"\n" /* D1 */
423
+ " ldr d16, [%3]\n"
415
424
  " b 1f\n"
416
425
  " nop\n"
417
- " ldp q16, q17, [%3]\n" /* Q4 */
426
+ " "BTI_J"\n" /* Q4 */
427
+ " ldp q16, q17, [%3]\n"
418
428
  " ldp q18, q19, [%3, #32]\n"
419
429
  " b 4f\n"
420
- " ldp q16, q17, [%3]\n" /* Q3 */
430
+ " "BTI_J"\n" /* Q3 */
431
+ " ldp q16, q17, [%3]\n"
421
432
  " ldr q18, [%3, #32]\n"
422
433
  " b 3f\n"
423
- " ldp q16, q17, [%3]\n" /* Q2 */
434
+ " "BTI_J"\n" /* Q2 */
435
+ " ldp q16, q17, [%3]\n"
424
436
  " b 2f\n"
425
437
  " nop\n"
426
- " ldr q16, [%3]\n" /* Q1 */
438
+ " "BTI_J"\n" /* Q1 */
439
+ " ldr q16, [%3]\n"
427
440
  " b 1f\n"
428
441
  "4: str q19, [%2, #48]\n"
429
442
  "3: str q18, [%2, #32]\n"
430
443
  "2: str q17, [%2, #16]\n"
431
444
  "1: str q16, [%2]"
432
445
  : "=&r"(x0)
433
- : "r"(f * 12), "r"(dest), "r"(src)
446
+ : "r"(f * 16), "r"(dest), "r"(src)
434
447
  : "memory", "v16", "v17", "v18", "v19");
435
448
  }
436
449
  #endif
@@ -632,7 +645,10 @@ extern void ffi_call_SYSV (struct call_context *context, void *frame,
632
645
  void *closure) FFI_HIDDEN;
633
646
 
634
647
  /* Call a function with the provided arguments and capture the return
635
- value. */
648
+ value.
649
+ n.b. ffi_call_SYSV will steal the alloca'd `stack` variable here for use
650
+ _as its own stack_ - so we need to compile this function without ASAN */
651
+ FFI_ASAN_NO_SANITIZE
636
652
  static void
637
653
  ffi_call_int (ffi_cif *cif, void (*fn)(void), void *orig_rvalue,
638
654
  void **avalue, void *closure)
@@ -669,7 +685,7 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *orig_rvalue,
669
685
  else if (flags & AARCH64_RET_NEED_COPY)
670
686
  rsize = 16;
671
687
 
672
- /* Allocate consectutive stack for everything we'll need.
688
+ /* Allocate consecutive stack for everything we'll need.
673
689
  The frame uses 40 bytes for: lr, fp, rvalue, flags, sp */
674
690
  context = alloca (sizeof(struct call_context) + stack_bytes + 40 + rsize);
675
691
  stack = context + 1;
@@ -864,7 +880,7 @@ ffi_prep_closure_loc (ffi_closure *closure,
864
880
 
865
881
  #if FFI_EXEC_TRAMPOLINE_TABLE
866
882
  # ifdef __MACH__
867
- # ifdef HAVE_PTRAUTH
883
+ # ifdef HAVE_ARM64E_PTRAUTH
868
884
  codeloc = ptrauth_auth_data(codeloc, ptrauth_key_function_pointer, 0);
869
885
  # endif
870
886
  void **config = (void **)((uint8_t *)codeloc - PAGE_MAX_SIZE);
@@ -83,8 +83,8 @@ typedef enum ffi_abi
83
83
 
84
84
  #if defined (__APPLE__)
85
85
  #define FFI_EXTRA_CIF_FIELDS unsigned aarch64_nfixedargs
86
- #elif !defined(_WIN32)
87
- /* iOS and Windows reserve x18 for the system. Disable Go closures until
86
+ #elif !defined(_WIN32) && !defined(__ANDROID__)
87
+ /* iOS, Windows and Android reserve x18 for the system. Disable Go closures until
88
88
  a new static chain is chosen. */
89
89
  #define FFI_GO_CLOSURES 1
90
90
  #endif
@@ -81,20 +81,66 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
81
81
  /* Helpers for writing assembly compatible with arm ptr auth */
82
82
  #ifdef LIBFFI_ASM
83
83
 
84
- #ifdef HAVE_PTRAUTH
85
- #define SIGN_LR pacibsp
86
- #define SIGN_LR_WITH_REG(x) pacib lr, x
87
- #define AUTH_LR_AND_RET retab
88
- #define AUTH_LR_WITH_REG(x) autib lr, x
89
- #define BRANCH_AND_LINK_TO_REG blraaz
90
- #define BRANCH_TO_REG braaz
91
- #else
92
- #define SIGN_LR
93
- #define SIGN_LR_WITH_REG(x)
94
- #define AUTH_LR_AND_RET ret
95
- #define AUTH_LR_WITH_REG(x)
96
- #define BRANCH_AND_LINK_TO_REG blr
97
- #define BRANCH_TO_REG br
98
- #endif
99
-
100
- #endif
84
+ #if defined(HAVE_ARM64E_PTRAUTH)
85
+ /* ARM64E ABI For Darwin */
86
+ #define SIGN_LR pacibsp
87
+ #define SIGN_LR_WITH_REG(x) pacib lr, x
88
+ #define AUTH_LR_AND_RET retab
89
+ #define AUTH_LR_WITH_REG(x) autib lr, x
90
+ #define BRANCH_AND_LINK_TO_REG blraaz
91
+ #define SIGN_LR_LINUX_ONLY
92
+ #define BRANCH_TO_REG braaz
93
+ #define PAC_CFI_WINDOW_SAVE
94
+ #define GNU_PROPERTY_AARCH64_POINTER_AUTH 0
95
+ /* Linux PAC Support */
96
+ #elif defined(__ARM_FEATURE_PAC_DEFAULT)
97
+ #define GNU_PROPERTY_AARCH64_POINTER_AUTH (1 << 1)
98
+ #define PAC_CFI_WINDOW_SAVE cfi_window_save
99
+ #define TMP_REG x9
100
+ #define BRANCH_TO_REG br
101
+ #define BRANCH_AND_LINK_TO_REG blr
102
+ #define SIGN_LR_LINUX_ONLY SIGN_LR
103
+ /* Which key to sign with? */
104
+ #if (__ARM_FEATURE_PAC_DEFAULT & 1) == 1
105
+ /* Signed with A-key */
106
+ #define SIGN_LR hint #25 /* paciasp */
107
+ #define AUTH_LR hint #29 /* autiasp */
108
+ #else
109
+ /* Signed with B-key */
110
+ #define SIGN_LR hint #27 /* pacibsp */
111
+ #define AUTH_LR hint #31 /* autibsp */
112
+ #endif /* __ARM_FEATURE_PAC_DEFAULT */
113
+ #define AUTH_LR_WITH_REG(x) _auth_lr_with_reg x
114
+ .macro _auth_lr_with_reg modifier
115
+ mov TMP_REG, sp
116
+ mov sp, \modifier
117
+ AUTH_LR
118
+ mov sp, TMP_REG
119
+ .endm
120
+ #define SIGN_LR_WITH_REG(x) _sign_lr_with_reg x
121
+ .macro _sign_lr_with_reg modifier
122
+ mov TMP_REG, sp
123
+ mov sp, \modifier
124
+ SIGN_LR
125
+ mov sp, TMP_REG
126
+ .endm
127
+ #define AUTH_LR_AND_RET _auth_lr_and_ret modifier
128
+ .macro _auth_lr_and_ret modifier
129
+ AUTH_LR
130
+ ret
131
+ .endm
132
+ #undef TMP_REG
133
+
134
+ /* No Pointer Auth */
135
+ #else
136
+ #define SIGN_LR
137
+ #define SIGN_LR_WITH_REG(x)
138
+ #define AUTH_LR_AND_RET ret
139
+ #define AUTH_LR_WITH_REG(x)
140
+ #define BRANCH_AND_LINK_TO_REG blr
141
+ #define SIGN_LR_LINUX_ONLY
142
+ #define BRANCH_TO_REG br
143
+ #define PAC_CFI_WINDOW_SAVE
144
+ #define GNU_PROPERTY_AARCH64_POINTER_AUTH 0
145
+ #endif /* HAVE_ARM64E_PTRAUTH */
146
+ #endif /* LIBFFI_ASM */
@@ -64,6 +64,13 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
64
64
  #define PTR_SIZE 8
65
65
  #endif
66
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 */
67
74
  .text
68
75
  .align 4
69
76
 
@@ -82,29 +89,30 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
82
89
  x5 closure
83
90
  */
84
91
 
85
- cfi_startproc
86
92
  CNAME(ffi_call_SYSV):
87
- /* Sign the lr with x1 since that is where it will be stored */
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 */
88
97
  SIGN_LR_WITH_REG(x1)
89
98
 
90
- /* Use a stack frame allocated by our caller. */
91
- #if defined(HAVE_PTRAUTH) && defined(__APPLE__)
99
+ #if defined(HAVE_ARM64E_PTRAUTH) && defined(__APPLE__)
92
100
  /* darwin's libunwind assumes that the cfa is the sp and that's the data
93
101
  * used to sign the lr. In order to allow unwinding through this
94
102
  * function it is necessary to point the cfa at the signing register.
95
103
  */
96
104
  cfi_def_cfa(x1, 0);
97
- #else
98
- cfi_def_cfa(x1, 40);
99
105
  #endif
106
+ /* Use a stack frame allocated by our caller. */
100
107
  stp x29, x30, [x1]
108
+ cfi_def_cfa_register(x1)
109
+ cfi_rel_offset (x29, 0)
110
+ cfi_rel_offset (x30, 8)
101
111
  mov x9, sp
102
112
  str x9, [x1, #32]
103
113
  mov x29, x1
104
- mov sp, x0
105
114
  cfi_def_cfa_register(x29)
106
- cfi_rel_offset (x29, 0)
107
- cfi_rel_offset (x30, 8)
115
+ mov sp, x0
108
116
 
109
117
  mov x9, x2 /* save fn */
110
118
  mov x8, x3 /* install structure return */
@@ -144,78 +152,142 @@ CNAME(ffi_call_SYSV):
144
152
  /* Save the return value as directed. */
145
153
  adr x5, 0f
146
154
  and w4, w4, #AARCH64_RET_MASK
147
- add x5, x5, x4, lsl #3
155
+ add x5, x5, x4, lsl #4
148
156
  br x5
149
157
 
150
- /* Note that each table entry is 2 insns, and thus 8 bytes.
158
+ /* Note that each table entry is 4 insns, and thus 16 bytes.
151
159
  For integer data, note that we're storing into ffi_arg
152
160
  and therefore we want to extend to 64 bits; these types
153
161
  have two consecutive entries allocated for them. */
154
162
  .align 4
155
- 0: b 99f /* VOID */
163
+ 0: BTI_J /* VOID */
164
+ b 99f
165
+ nop
156
166
  nop
157
- 1: str x0, [x3] /* INT64 */
167
+ 1: BTI_J /* INT64 */
168
+ str x0, [x3]
158
169
  b 99f
159
- 2: stp x0, x1, [x3] /* INT128 */
170
+ nop
171
+ 2: BTI_J /* INT128 */
172
+ stp x0, x1, [x3]
160
173
  b 99f
174
+ nop
161
175
  3: brk #1000 /* UNUSED */
162
176
  b 99f
177
+ nop
178
+ nop
163
179
  4: brk #1000 /* UNUSED */
164
180
  b 99f
181
+ nop
182
+ nop
165
183
  5: brk #1000 /* UNUSED */
166
184
  b 99f
185
+ nop
186
+ nop
167
187
  6: brk #1000 /* UNUSED */
168
188
  b 99f
189
+ nop
190
+ nop
169
191
  7: brk #1000 /* UNUSED */
170
192
  b 99f
171
- 8: st4 { v0.s, v1.s, v2.s, v3.s }[0], [x3] /* S4 */
193
+ nop
194
+ nop
195
+ 8: BTI_J /* S4 */
196
+ st4 { v0.s, v1.s, v2.s, v3.s }[0], [x3]
172
197
  b 99f
173
- 9: st3 { v0.s, v1.s, v2.s }[0], [x3] /* S3 */
198
+ nop
199
+ 9: BTI_J /* S3 */
200
+ st3 { v0.s, v1.s, v2.s }[0], [x3]
174
201
  b 99f
175
- 10: stp s0, s1, [x3] /* S2 */
202
+ nop
203
+ 10: BTI_J /* S2 */
204
+ stp s0, s1, [x3]
176
205
  b 99f
177
- 11: str s0, [x3] /* S1 */
206
+ nop
207
+ 11: BTI_J
208
+ str s0, [x3] /* S1 */
178
209
  b 99f
179
- 12: st4 { v0.d, v1.d, v2.d, v3.d }[0], [x3] /* D4 */
210
+ nop
211
+ 12: BTI_J /* D4 */
212
+ st4 { v0.d, v1.d, v2.d, v3.d }[0], [x3]
180
213
  b 99f
181
- 13: st3 { v0.d, v1.d, v2.d }[0], [x3] /* D3 */
214
+ nop
215
+ 13: BTI_J /* D3 */
216
+ st3 { v0.d, v1.d, v2.d }[0], [x3]
182
217
  b 99f
183
- 14: stp d0, d1, [x3] /* D2 */
218
+ nop
219
+ 14: BTI_J /* D2 */
220
+ stp d0, d1, [x3]
184
221
  b 99f
185
- 15: str d0, [x3] /* D1 */
222
+ nop
223
+ 15: BTI_J /* D1 */
224
+ str d0, [x3]
186
225
  b 99f
187
- 16: str q3, [x3, #48] /* Q4 */
188
226
  nop
189
- 17: str q2, [x3, #32] /* Q3 */
227
+ 16: BTI_J /* Q4 */
228
+ str q3, [x3, #48]
229
+ nop
230
+ nop
231
+ 17: BTI_J /* Q3 */
232
+ str q2, [x3, #32]
190
233
  nop
191
- 18: stp q0, q1, [x3] /* Q2 */
234
+ nop
235
+ 18: BTI_J /* Q2 */
236
+ stp q0, q1, [x3]
192
237
  b 99f
193
- 19: str q0, [x3] /* Q1 */
238
+ nop
239
+ 19: BTI_J /* Q1 */
240
+ str q0, [x3]
194
241
  b 99f
195
- 20: uxtb w0, w0 /* UINT8 */
242
+ nop
243
+ 20: BTI_J /* UINT8 */
244
+ uxtb w0, w0
196
245
  str x0, [x3]
246
+ nop
197
247
  21: b 99f /* reserved */
198
248
  nop
199
- 22: uxth w0, w0 /* UINT16 */
249
+ nop
250
+ nop
251
+ 22: BTI_J /* UINT16 */
252
+ uxth w0, w0
200
253
  str x0, [x3]
254
+ nop
201
255
  23: b 99f /* reserved */
202
256
  nop
203
- 24: mov w0, w0 /* UINT32 */
257
+ nop
258
+ nop
259
+ 24: BTI_J /* UINT32 */
260
+ mov w0, w0
204
261
  str x0, [x3]
262
+ nop
205
263
  25: b 99f /* reserved */
206
264
  nop
207
- 26: sxtb x0, w0 /* SINT8 */
265
+ nop
266
+ nop
267
+ 26: BTI_J /* SINT8 */
268
+ sxtb x0, w0
208
269
  str x0, [x3]
270
+ nop
209
271
  27: b 99f /* reserved */
210
272
  nop
211
- 28: sxth x0, w0 /* SINT16 */
273
+ nop
274
+ nop
275
+ 28: BTI_J /* SINT16 */
276
+ sxth x0, w0
212
277
  str x0, [x3]
278
+ nop
213
279
  29: b 99f /* reserved */
214
280
  nop
215
- 30: sxtw x0, w0 /* SINT32 */
281
+ nop
282
+ nop
283
+ 30: BTI_J /* SINT32 */
284
+ sxtw x0, w0
216
285
  str x0, [x3]
286
+ nop
217
287
  31: b 99f /* reserved */
218
288
  nop
289
+ nop
290
+ nop
219
291
 
220
292
  /* Return now that result has been populated. */
221
293
  99:
@@ -252,7 +324,9 @@ CNAME(ffi_call_SYSV):
252
324
  .align 4
253
325
  CNAME(ffi_closure_SYSV_V):
254
326
  cfi_startproc
327
+ BTI_C
255
328
  SIGN_LR
329
+ PAC_CFI_WINDOW_SAVE
256
330
  stp x29, x30, [sp, #-ffi_closure_SYSV_FS]!
257
331
  cfi_adjust_cfa_offset (ffi_closure_SYSV_FS)
258
332
  cfi_rel_offset (x29, 0)
@@ -274,9 +348,11 @@ CNAME(ffi_closure_SYSV_V):
274
348
  #endif
275
349
 
276
350
  .align 4
277
- cfi_startproc
278
351
  CNAME(ffi_closure_SYSV):
352
+ cfi_startproc
353
+ BTI_C
279
354
  SIGN_LR
355
+ PAC_CFI_WINDOW_SAVE
280
356
  stp x29, x30, [sp, #-ffi_closure_SYSV_FS]!
281
357
  cfi_adjust_cfa_offset (ffi_closure_SYSV_FS)
282
358
  cfi_rel_offset (x29, 0)
@@ -305,73 +381,135 @@ L(do_closure):
305
381
  /* Load the return value as directed. */
306
382
  adr x1, 0f
307
383
  and w0, w0, #AARCH64_RET_MASK
308
- add x1, x1, x0, lsl #3
384
+ add x1, x1, x0, lsl #4
309
385
  add x3, sp, #16+CALL_CONTEXT_SIZE
310
386
  br x1
311
387
 
312
- /* Note that each table entry is 2 insns, and thus 8 bytes. */
388
+ /* Note that each table entry is 4 insns, and thus 16 bytes. */
313
389
  .align 4
314
- 0: b 99f /* VOID */
390
+ 0: BTI_J /* VOID */
391
+ b 99f
392
+ nop
315
393
  nop
316
- 1: ldr x0, [x3] /* INT64 */
394
+ 1: BTI_J /* INT64 */
395
+ ldr x0, [x3]
317
396
  b 99f
318
- 2: ldp x0, x1, [x3] /* INT128 */
397
+ nop
398
+ 2: BTI_J /* INT128 */
399
+ ldp x0, x1, [x3]
319
400
  b 99f
401
+ nop
320
402
  3: brk #1000 /* UNUSED */
321
403
  nop
404
+ nop
405
+ nop
322
406
  4: brk #1000 /* UNUSED */
323
407
  nop
408
+ nop
409
+ nop
324
410
  5: brk #1000 /* UNUSED */
325
411
  nop
412
+ nop
413
+ nop
326
414
  6: brk #1000 /* UNUSED */
327
415
  nop
416
+ nop
417
+ nop
328
418
  7: brk #1000 /* UNUSED */
329
419
  nop
330
- 8: ldr s3, [x3, #12] /* S4 */
331
420
  nop
332
- 9: ldr s2, [x3, #8] /* S3 */
333
421
  nop
334
- 10: ldp s0, s1, [x3] /* S2 */
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]
335
432
  b 99f
336
- 11: ldr s0, [x3] /* S1 */
433
+ nop
434
+ 11: BTI_J /* S1 */
435
+ ldr s0, [x3]
337
436
  b 99f
338
- 12: ldr d3, [x3, #24] /* D4 */
339
437
  nop
340
- 13: ldr d2, [x3, #16] /* D3 */
438
+ 12: BTI_J /* D4 */
439
+ ldr d3, [x3, #24]
440
+ nop
441
+ nop
442
+ 13: BTI_J /* D3 */
443
+ ldr d2, [x3, #16]
341
444
  nop
342
- 14: ldp d0, d1, [x3] /* D2 */
445
+ nop
446
+ 14: BTI_J /* D2 */
447
+ ldp d0, d1, [x3]
343
448
  b 99f
344
- 15: ldr d0, [x3] /* D1 */
449
+ nop
450
+ 15: BTI_J /* D1 */
451
+ ldr d0, [x3]
345
452
  b 99f
346
- 16: ldr q3, [x3, #48] /* Q4 */
347
453
  nop
348
- 17: ldr q2, [x3, #32] /* Q3 */
454
+ 16: BTI_J /* Q4 */
455
+ ldr q3, [x3, #48]
456
+ nop
457
+ nop
458
+ 17: BTI_J /* Q3 */
459
+ ldr q2, [x3, #32]
349
460
  nop
350
- 18: ldp q0, q1, [x3] /* Q2 */
461
+ nop
462
+ 18: BTI_J /* Q2 */
463
+ ldp q0, q1, [x3]
351
464
  b 99f
352
- 19: ldr q0, [x3] /* Q1 */
465
+ nop
466
+ 19: BTI_J /* Q1 */
467
+ ldr q0, [x3]
353
468
  b 99f
354
- 20: ldrb w0, [x3, #BE(7)] /* UINT8 */
469
+ nop
470
+ 20: BTI_J /* UINT8 */
471
+ ldrb w0, [x3, #BE(7)]
355
472
  b 99f
473
+ nop
356
474
  21: brk #1000 /* reserved */
357
475
  nop
358
- 22: ldrh w0, [x3, #BE(6)] /* UINT16 */
476
+ nop
477
+ nop
478
+ 22: BTI_J /* UINT16 */
479
+ ldrh w0, [x3, #BE(6)]
359
480
  b 99f
481
+ nop
360
482
  23: brk #1000 /* reserved */
361
483
  nop
362
- 24: ldr w0, [x3, #BE(4)] /* UINT32 */
484
+ nop
485
+ nop
486
+ 24: BTI_J /* UINT32 */
487
+ ldr w0, [x3, #BE(4)]
363
488
  b 99f
489
+ nop
364
490
  25: brk #1000 /* reserved */
365
491
  nop
366
- 26: ldrsb x0, [x3, #BE(7)] /* SINT8 */
492
+ nop
493
+ nop
494
+ 26: BTI_J /* SINT8 */
495
+ ldrsb x0, [x3, #BE(7)]
367
496
  b 99f
497
+ nop
368
498
  27: brk #1000 /* reserved */
369
499
  nop
370
- 28: ldrsh x0, [x3, #BE(6)] /* SINT16 */
500
+ nop
501
+ nop
502
+ 28: BTI_J /* SINT16 */
503
+ ldrsh x0, [x3, #BE(6)]
371
504
  b 99f
505
+ nop
372
506
  29: brk #1000 /* reserved */
373
507
  nop
374
- 30: ldrsw x0, [x3, #BE(4)] /* SINT32 */
508
+ nop
509
+ nop
510
+ 30: BTI_J /* SINT32 */
511
+ ldrsw x0, [x3, #BE(4)]
512
+ nop
375
513
  nop
376
514
  31: /* reserved */
377
515
  99: ldp x29, x30, [sp], #ffi_closure_SYSV_FS
@@ -391,6 +529,7 @@ L(do_closure):
391
529
  #if defined(FFI_EXEC_STATIC_TRAMP)
392
530
  .align 4
393
531
  CNAME(ffi_closure_SYSV_V_alt):
532
+ BTI_C
394
533
  /* See the comments above trampoline_code_table. */
395
534
  ldr x17, [sp, #8] /* Load closure in x17 */
396
535
  add sp, sp, #16 /* Restore the stack */
@@ -405,6 +544,7 @@ CNAME(ffi_closure_SYSV_V_alt):
405
544
 
406
545
  .align 4
407
546
  CNAME(ffi_closure_SYSV_alt):
547
+ BTI_C
408
548
  /* See the comments above trampoline_code_table. */
409
549
  ldr x17, [sp, #8] /* Load closure in x17 */
410
550
  add sp, sp, #16 /* Restore the stack */
@@ -485,6 +625,7 @@ CNAME(ffi_closure_trampoline_table_page):
485
625
  .align 4
486
626
  CNAME(ffi_go_closure_SYSV_V):
487
627
  cfi_startproc
628
+ BTI_C
488
629
  stp x29, x30, [sp, #-ffi_closure_SYSV_FS]!
489
630
  cfi_adjust_cfa_offset (ffi_closure_SYSV_FS)
490
631
  cfi_rel_offset (x29, 0)
@@ -506,8 +647,11 @@ CNAME(ffi_go_closure_SYSV_V):
506
647
  #endif
507
648
 
508
649
  .align 4
509
- cfi_startproc
510
650
  CNAME(ffi_go_closure_SYSV):
651
+ cfi_startproc
652
+ BTI_C
653
+ SIGN_LR_LINUX_ONLY
654
+ PAC_CFI_WINDOW_SAVE
511
655
  stp x29, x30, [sp, #-ffi_closure_SYSV_FS]!
512
656
  cfi_adjust_cfa_offset (ffi_closure_SYSV_FS)
513
657
  cfi_rel_offset (x29, 0)
@@ -539,5 +683,17 @@ CNAME(ffi_go_closure_SYSV):
539
683
 
540
684
  #if defined __ELF__ && defined __linux__
541
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;
542
698
  #endif
543
699
 
@@ -39,14 +39,14 @@
39
39
  #define LARG ldl
40
40
  #define SARG stl
41
41
  #define ADDPTR addl
42
- #define MOVPTR movl_s
42
+ #define MOVPTR movl
43
43
  #else
44
44
  #define PTRS 4
45
45
  #define FLTS 4
46
46
  #define LARG ld
47
47
  #define SARG st
48
48
  #define ADDPTR add
49
- #define MOVPTR mov_s
49
+ #define MOVPTR mov
50
50
  #endif
51
51
 
52
52
  #define FRAME_LEN (8 * PTRS + 16)