ffi 1.12.2 → 1.14.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 (135) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +82 -0
  3. data/Gemfile +4 -2
  4. data/README.md +10 -2
  5. data/Rakefile +31 -43
  6. data/ext/ffi_c/AbstractMemory.c +24 -25
  7. data/ext/ffi_c/Buffer.c +4 -9
  8. data/ext/ffi_c/Call.c +3 -14
  9. data/ext/ffi_c/ClosurePool.c +75 -25
  10. data/ext/ffi_c/ClosurePool.h +3 -1
  11. data/ext/ffi_c/DynamicLibrary.c +1 -6
  12. data/ext/ffi_c/Function.c +15 -35
  13. data/ext/ffi_c/FunctionInfo.c +3 -8
  14. data/ext/ffi_c/LastError.c +2 -6
  15. data/ext/ffi_c/LongDouble.c +5 -3
  16. data/ext/ffi_c/LongDouble.h +0 -4
  17. data/ext/ffi_c/MemoryPointer.c +3 -8
  18. data/ext/ffi_c/MethodHandle.c +21 -31
  19. data/ext/ffi_c/MethodHandle.h +3 -2
  20. data/ext/ffi_c/Platform.c +3 -7
  21. data/ext/ffi_c/Pointer.c +25 -26
  22. data/ext/ffi_c/Struct.c +3 -6
  23. data/ext/ffi_c/StructByValue.c +2 -7
  24. data/ext/ffi_c/StructLayout.c +9 -7
  25. data/ext/ffi_c/Thread.c +0 -8
  26. data/ext/ffi_c/Thread.h +1 -9
  27. data/ext/ffi_c/Type.c +1 -1
  28. data/ext/ffi_c/Variadic.c +2 -7
  29. data/ext/ffi_c/compat.h +4 -0
  30. data/ext/ffi_c/extconf.rb +33 -23
  31. data/ext/ffi_c/libffi/.travis.yml +4 -0
  32. data/ext/ffi_c/libffi/.travis/bfin-sim.exp +1 -1
  33. data/ext/ffi_c/libffi/.travis/build.sh +4 -0
  34. data/ext/ffi_c/libffi/.travis/m32r-sim.exp +1 -1
  35. data/ext/ffi_c/libffi/.travis/moxie-sim.exp +1 -1
  36. data/ext/ffi_c/libffi/.travis/or1k-sim.exp +1 -1
  37. data/ext/ffi_c/libffi/.travis/powerpc-eabisim.exp +1 -1
  38. data/ext/ffi_c/libffi/.travis/wine-sim.exp +1 -1
  39. data/ext/ffi_c/libffi/Makefile.am +49 -58
  40. data/ext/ffi_c/libffi/README.md +11 -1
  41. data/ext/ffi_c/libffi/config.guess +552 -331
  42. data/ext/ffi_c/libffi/config.sub +1321 -1306
  43. data/ext/ffi_c/libffi/configure.ac +31 -10
  44. data/ext/ffi_c/libffi/configure.host +32 -20
  45. data/ext/ffi_c/libffi/doc/Makefile.am +3 -0
  46. data/ext/ffi_c/libffi/doc/libffi.texi +997 -0
  47. data/ext/ffi_c/libffi/doc/version.texi +4 -0
  48. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +1 -1
  49. data/ext/ffi_c/libffi/include/ffi.h.in +8 -0
  50. data/ext/ffi_c/libffi/libffi.map.in +8 -12
  51. data/ext/ffi_c/libffi/libtool-version +1 -1
  52. data/ext/ffi_c/libffi/msvcc.sh +11 -11
  53. data/ext/ffi_c/libffi/src/aarch64/ffi.c +51 -35
  54. data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +10 -5
  55. data/ext/ffi_c/libffi/src/aarch64/internal.h +1 -0
  56. data/ext/ffi_c/libffi/src/aarch64/sysv.S +14 -3
  57. data/ext/ffi_c/libffi/src/aarch64/win64_armasm.S +1 -1
  58. data/ext/ffi_c/libffi/src/arm/ffi.c +22 -0
  59. data/ext/ffi_c/libffi/src/arm/sysv.S +4 -4
  60. data/ext/ffi_c/libffi/src/closures.c +33 -10
  61. data/ext/ffi_c/libffi/src/csky/ffi.c +395 -0
  62. data/ext/ffi_c/libffi/src/csky/ffitarget.h +63 -0
  63. data/ext/ffi_c/libffi/src/csky/sysv.S +371 -0
  64. data/ext/ffi_c/libffi/src/dlmalloc.c +1 -1
  65. data/ext/ffi_c/libffi/src/kvx/asm.h +5 -0
  66. data/ext/ffi_c/libffi/src/kvx/ffi.c +273 -0
  67. data/ext/ffi_c/libffi/src/kvx/ffitarget.h +75 -0
  68. data/ext/ffi_c/libffi/src/kvx/sysv.S +127 -0
  69. data/ext/ffi_c/libffi/src/mips/ffi.c +5 -1
  70. data/ext/ffi_c/libffi/src/mips/ffitarget.h +1 -1
  71. data/ext/ffi_c/libffi/src/pa/ffi.c +46 -91
  72. data/ext/ffi_c/libffi/src/pa/ffitarget.h +1 -6
  73. data/ext/ffi_c/libffi/src/pa/hpux32.S +4 -2
  74. data/ext/ffi_c/libffi/src/pa/linux.S +4 -2
  75. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +13 -1
  76. data/ext/ffi_c/libffi/src/powerpc/ffi_powerpc.h +1 -1
  77. data/ext/ffi_c/libffi/src/powerpc/linux64.S +8 -0
  78. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +13 -1
  79. data/ext/ffi_c/libffi/src/powerpc/sysv.S +5 -7
  80. data/ext/ffi_c/libffi/src/prep_cif.c +1 -1
  81. data/ext/ffi_c/libffi/src/x86/ffi.c +15 -6
  82. data/ext/ffi_c/libffi/src/x86/ffi64.c +17 -8
  83. data/ext/ffi_c/libffi/src/x86/ffitarget.h +15 -2
  84. data/ext/ffi_c/libffi/src/x86/ffiw64.c +15 -8
  85. data/ext/ffi_c/libffi/src/x86/sysv.S +15 -6
  86. data/ext/ffi_c/libffi/src/x86/unix64.S +59 -4
  87. data/ext/ffi_c/libffi/src/x86/win64.S +7 -3
  88. data/ext/ffi_c/libffi/src/x86/win64_intel.S +3 -2
  89. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +22 -2
  90. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +4 -4
  91. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-callback.c +2 -2
  92. data/ext/ffi_c/libffi/testsuite/libffi.closures/huge_struct.c +2 -0
  93. data/ffi.gemspec +2 -2
  94. data/lib/ffi.rb +10 -2
  95. data/lib/ffi/abstract_memory.rb +44 -0
  96. data/lib/ffi/autopointer.rb +1 -1
  97. data/lib/ffi/ffi.rb +1 -0
  98. data/lib/ffi/io.rb +3 -3
  99. data/lib/ffi/library.rb +6 -2
  100. data/lib/ffi/managedstruct.rb +2 -2
  101. data/lib/ffi/platform.rb +21 -8
  102. data/lib/ffi/platform/aarch64-darwin/types.conf +130 -0
  103. data/lib/ffi/platform/aarch64-openbsd/types.conf +134 -0
  104. data/lib/ffi/platform/arm-linux/types.conf +32 -4
  105. data/lib/ffi/platform/i386-windows/types.conf +26 -79
  106. data/lib/ffi/platform/powerpc-linux/types.conf +32 -2
  107. data/lib/ffi/platform/powerpc-openbsd/types.conf +156 -0
  108. data/lib/ffi/platform/sparcv9-openbsd/types.conf +156 -0
  109. data/lib/ffi/platform/x86_64-darwin/types.conf +4 -0
  110. data/lib/ffi/platform/x86_64-dragonflybsd/types.conf +4 -22
  111. data/lib/ffi/platform/x86_64-haiku/types.conf +117 -0
  112. data/lib/ffi/platform/x86_64-linux/types.conf +21 -0
  113. data/lib/ffi/platform/x86_64-msys/types.conf +119 -0
  114. data/lib/ffi/platform/x86_64-windows/types.conf +10 -78
  115. data/lib/ffi/pointer.rb +21 -14
  116. data/lib/ffi/struct.rb +8 -2
  117. data/lib/ffi/tools/types_generator.rb +2 -0
  118. data/lib/ffi/variadic.rb +1 -1
  119. data/lib/ffi/version.rb +1 -1
  120. data/samples/getlogin.rb +1 -1
  121. data/samples/getpid.rb +1 -1
  122. data/samples/gettimeofday.rb +8 -8
  123. data/samples/hello.rb +2 -1
  124. data/samples/inotify.rb +1 -1
  125. data/samples/pty.rb +1 -2
  126. data/samples/qsort.rb +0 -1
  127. metadata +18 -12
  128. data/.appveyor.yml +0 -27
  129. data/.gitignore +0 -25
  130. data/.gitmodules +0 -4
  131. data/.travis.yml +0 -44
  132. data/.yardopts +0 -5
  133. data/ext/ffi_c/win32/stdbool.h +0 -8
  134. data/ext/ffi_c/win32/stdint.h +0 -201
  135. data/samples/sample_helper.rb +0 -6
@@ -104,17 +104,16 @@ ENTRY(ffi_call_SYSV)
104
104
  bctrl
105
105
 
106
106
  /* Now, deal with the return value. */
107
- mtcrf 0x01,%r31 /* cr7 */
107
+ mtcrf 0x03,%r31 /* cr6-cr7 */
108
108
  bt- 31,L(small_struct_return_value)
109
109
  bt- 30,L(done_return_value)
110
110
  #ifndef __NO_FPRS__
111
111
  bt- 29,L(fp_return_value)
112
112
  #endif
113
113
  stw %r3,0(%r30)
114
- bf+ 28,L(done_return_value)
114
+ bf+ 27,L(done_return_value)
115
115
  stw %r4,4(%r30)
116
- mtcrf 0x02,%r31 /* cr6 */
117
- bf 27,L(done_return_value)
116
+ bf 26,L(done_return_value)
118
117
  stw %r5,8(%r30)
119
118
  stw %r6,12(%r30)
120
119
  /* Fall through... */
@@ -145,10 +144,9 @@ L(done_return_value):
145
144
  #ifndef __NO_FPRS__
146
145
  L(fp_return_value):
147
146
  .cfi_restore_state
148
- bf 28,L(float_return_value)
147
+ bf 27,L(float_return_value)
149
148
  stfd %f1,0(%r30)
150
- mtcrf 0x02,%r31 /* cr6 */
151
- bf 27,L(done_return_value)
149
+ bf 26,L(done_return_value)
152
150
  stfd %f2,8(%r30)
153
151
  b L(done_return_value)
154
152
  L(float_return_value):
@@ -129,7 +129,7 @@ ffi_status FFI_HIDDEN ffi_prep_cif_core(ffi_cif *cif, ffi_abi abi,
129
129
  cif->rtype = rtype;
130
130
 
131
131
  cif->flags = 0;
132
- #ifdef _M_ARM64
132
+ #if (defined(_M_ARM64) || defined(__aarch64__)) && defined(_WIN32)
133
133
  cif->is_variadic = isvariadic;
134
134
  #endif
135
135
  #if HAVE_LONG_DOUBLE_VARIANT
@@ -353,7 +353,7 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
353
353
  size_t align = FFI_SIZEOF_ARG;
354
354
 
355
355
  /* Issue 434: For thiscall and fastcall, if the paramter passed
356
- as 64-bit integer or struct, all following integer paramters
356
+ as 64-bit integer or struct, all following integer parameters
357
357
  will be passed on stack. */
358
358
  if ((cabi == FFI_THISCALL || cabi == FFI_FASTCALL)
359
359
  && (t == FFI_TYPE_SINT64
@@ -397,12 +397,14 @@ ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
397
397
  ffi_call_int (cif, fn, rvalue, avalue, NULL);
398
398
  }
399
399
 
400
+ #ifdef FFI_GO_CLOSURES
400
401
  void
401
402
  ffi_call_go (ffi_cif *cif, void (*fn)(void), void *rvalue,
402
403
  void **avalue, void *closure)
403
404
  {
404
405
  ffi_call_int (cif, fn, rvalue, avalue, closure);
405
406
  }
407
+ #endif
406
408
 
407
409
  /** private members **/
408
410
 
@@ -492,7 +494,7 @@ ffi_closure_inner (struct closure_frame *frame, char *stack)
492
494
  align = 16;
493
495
 
494
496
  /* Issue 434: For thiscall and fastcall, if the paramter passed
495
- as 64-bit integer or struct, all following integer paramters
497
+ as 64-bit integer or struct, all following integer parameters
496
498
  will be passed on stack. */
497
499
  if ((cabi == FFI_THISCALL || cabi == FFI_FASTCALL)
498
500
  && (t == FFI_TYPE_SINT64
@@ -557,13 +559,16 @@ ffi_prep_closure_loc (ffi_closure* closure,
557
559
  return FFI_BAD_ABI;
558
560
  }
559
561
 
562
+ /* endbr32. */
563
+ *(UINT32 *) tramp = 0xfb1e0ff3;
564
+
560
565
  /* movl or pushl immediate. */
561
- tramp[0] = op;
562
- *(void **)(tramp + 1) = codeloc;
566
+ tramp[4] = op;
567
+ *(void **)(tramp + 5) = codeloc;
563
568
 
564
569
  /* jmp dest */
565
- tramp[5] = 0xe9;
566
- *(unsigned *)(tramp + 6) = (unsigned)dest - ((unsigned)codeloc + 10);
570
+ tramp[9] = 0xe9;
571
+ *(unsigned *)(tramp + 10) = (unsigned)dest - ((unsigned)codeloc + 14);
567
572
 
568
573
  closure->cif = cif;
569
574
  closure->fun = fun;
@@ -572,6 +577,8 @@ ffi_prep_closure_loc (ffi_closure* closure,
572
577
  return FFI_OK;
573
578
  }
574
579
 
580
+ #ifdef FFI_GO_CLOSURES
581
+
575
582
  void FFI_HIDDEN ffi_go_closure_EAX(void);
576
583
  void FFI_HIDDEN ffi_go_closure_ECX(void);
577
584
  void FFI_HIDDEN ffi_go_closure_STDCALL(void);
@@ -608,6 +615,8 @@ ffi_prep_go_closure (ffi_go_closure* closure, ffi_cif* cif,
608
615
  return FFI_OK;
609
616
  }
610
617
 
618
+ #endif /* FFI_GO_CLOSURES */
619
+
611
620
  /* ------- Native raw API support -------------------------------- */
612
621
 
613
622
  #if !FFI_NO_RAW_API
@@ -688,6 +688,8 @@ ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
688
688
  ffi_call_int (cif, fn, rvalue, avalue, NULL);
689
689
  }
690
690
 
691
+ #ifdef FFI_GO_CLOSURES
692
+
691
693
  #ifndef __ILP32__
692
694
  extern void
693
695
  ffi_call_go_efi64(ffi_cif *cif, void (*fn)(void), void *rvalue,
@@ -708,6 +710,7 @@ ffi_call_go (ffi_cif *cif, void (*fn)(void), void *rvalue,
708
710
  ffi_call_int (cif, fn, rvalue, avalue, closure);
709
711
  }
710
712
 
713
+ #endif /* FFI_GO_CLOSURES */
711
714
 
712
715
  extern void ffi_closure_unix64(void) FFI_HIDDEN;
713
716
  extern void ffi_closure_unix64_sse(void) FFI_HIDDEN;
@@ -728,13 +731,15 @@ ffi_prep_closure_loc (ffi_closure* closure,
728
731
  void *user_data,
729
732
  void *codeloc)
730
733
  {
731
- static const unsigned char trampoline[16] = {
732
- /* leaq -0x7(%rip),%r10 # 0x0 */
733
- 0x4c, 0x8d, 0x15, 0xf9, 0xff, 0xff, 0xff,
734
- /* jmpq *0x3(%rip) # 0x10 */
735
- 0xff, 0x25, 0x03, 0x00, 0x00, 0x00,
736
- /* nopl (%rax) */
737
- 0x0f, 0x1f, 0x00
734
+ static const unsigned char trampoline[24] = {
735
+ /* endbr64 */
736
+ 0xf3, 0x0f, 0x1e, 0xfa,
737
+ /* leaq -0xb(%rip),%r10 # 0x0 */
738
+ 0x4c, 0x8d, 0x15, 0xf5, 0xff, 0xff, 0xff,
739
+ /* jmpq *0x7(%rip) # 0x18 */
740
+ 0xff, 0x25, 0x07, 0x00, 0x00, 0x00,
741
+ /* nopl 0(%rax) */
742
+ 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00
738
743
  };
739
744
  void (*dest)(void);
740
745
  char *tramp = closure->tramp;
@@ -752,7 +757,7 @@ ffi_prep_closure_loc (ffi_closure* closure,
752
757
  dest = ffi_closure_unix64;
753
758
 
754
759
  memcpy (tramp, trampoline, sizeof(trampoline));
755
- *(UINT64 *)(tramp + 16) = (uintptr_t)dest;
760
+ *(UINT64 *)(tramp + sizeof (trampoline)) = (uintptr_t)dest;
756
761
 
757
762
  closure->cif = cif;
758
763
  closure->fun = fun;
@@ -854,6 +859,8 @@ ffi_closure_unix64_inner(ffi_cif *cif,
854
859
  return flags;
855
860
  }
856
861
 
862
+ #ifdef FFI_GO_CLOSURES
863
+
857
864
  extern void ffi_go_closure_unix64(void) FFI_HIDDEN;
858
865
  extern void ffi_go_closure_unix64_sse(void) FFI_HIDDEN;
859
866
 
@@ -883,4 +890,6 @@ ffi_prep_go_closure (ffi_go_closure* closure, ffi_cif* cif,
883
890
  return FFI_OK;
884
891
  }
885
892
 
893
+ #endif /* FFI_GO_CLOSURES */
894
+
886
895
  #endif /* __x86_64__ */
@@ -136,12 +136,25 @@ typedef enum ffi_abi {
136
136
 
137
137
  #if defined (X86_64) || defined(X86_WIN64) \
138
138
  || (defined (__x86_64__) && defined (X86_DARWIN))
139
- # define FFI_TRAMPOLINE_SIZE 24
139
+ /* 4 bytes of ENDBR64 + 7 bytes of LEA + 6 bytes of JMP + 7 bytes of NOP
140
+ + 8 bytes of pointer. */
141
+ # define FFI_TRAMPOLINE_SIZE 32
140
142
  # define FFI_NATIVE_RAW_API 0
141
143
  #else
142
- # define FFI_TRAMPOLINE_SIZE 12
144
+ /* 4 bytes of ENDBR32 + 5 bytes of MOV + 5 bytes of JMP + 2 unused
145
+ bytes. */
146
+ # define FFI_TRAMPOLINE_SIZE 16
143
147
  # define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */
144
148
  #endif
145
149
 
150
+ #if !defined(GENERATE_LIBFFI_MAP) && defined(__ASSEMBLER__) \
151
+ && defined(__CET__)
152
+ # include <cet.h>
153
+ # define _CET_NOTRACK notrack
154
+ #else
155
+ # define _CET_ENDBR
156
+ # define _CET_NOTRACK
157
+ #endif
158
+
146
159
  #endif
147
160
 
@@ -187,7 +187,10 @@ EFI64(ffi_call_go)(ffi_cif *cif, void (*fn)(void), void *rvalue,
187
187
 
188
188
 
189
189
  extern void ffi_closure_win64(void) FFI_HIDDEN;
190
+
191
+ #ifdef FFI_GO_CLOSURES
190
192
  extern void ffi_go_closure_win64(void) FFI_HIDDEN;
193
+ #endif
191
194
 
192
195
  ffi_status
193
196
  EFI64(ffi_prep_closure_loc)(ffi_closure* closure,
@@ -196,13 +199,15 @@ EFI64(ffi_prep_closure_loc)(ffi_closure* closure,
196
199
  void *user_data,
197
200
  void *codeloc)
198
201
  {
199
- static const unsigned char trampoline[16] = {
200
- /* leaq -0x7(%rip),%r10 # 0x0 */
201
- 0x4c, 0x8d, 0x15, 0xf9, 0xff, 0xff, 0xff,
202
- /* jmpq *0x3(%rip) # 0x10 */
203
- 0xff, 0x25, 0x03, 0x00, 0x00, 0x00,
204
- /* nopl (%rax) */
205
- 0x0f, 0x1f, 0x00
202
+ static const unsigned char trampoline[FFI_TRAMPOLINE_SIZE - 8] = {
203
+ /* endbr64 */
204
+ 0xf3, 0x0f, 0x1e, 0xfa,
205
+ /* leaq -0xb(%rip),%r10 # 0x0 */
206
+ 0x4c, 0x8d, 0x15, 0xf5, 0xff, 0xff, 0xff,
207
+ /* jmpq *0x7(%rip) # 0x18 */
208
+ 0xff, 0x25, 0x07, 0x00, 0x00, 0x00,
209
+ /* nopl 0(%rax) */
210
+ 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00
206
211
  };
207
212
  char *tramp = closure->tramp;
208
213
 
@@ -216,7 +221,7 @@ EFI64(ffi_prep_closure_loc)(ffi_closure* closure,
216
221
  }
217
222
 
218
223
  memcpy (tramp, trampoline, sizeof(trampoline));
219
- *(UINT64 *)(tramp + 16) = (uintptr_t)ffi_closure_win64;
224
+ *(UINT64 *)(tramp + sizeof (trampoline)) = (uintptr_t)ffi_closure_win64;
220
225
 
221
226
  closure->cif = cif;
222
227
  closure->fun = fun;
@@ -225,6 +230,7 @@ EFI64(ffi_prep_closure_loc)(ffi_closure* closure,
225
230
  return FFI_OK;
226
231
  }
227
232
 
233
+ #ifdef FFI_GO_CLOSURES
228
234
  ffi_status
229
235
  EFI64(ffi_prep_go_closure)(ffi_go_closure* closure, ffi_cif* cif,
230
236
  void (*fun)(ffi_cif*, void*, void**, void*))
@@ -244,6 +250,7 @@ EFI64(ffi_prep_go_closure)(ffi_go_closure* closure, ffi_cif* cif,
244
250
 
245
251
  return FFI_OK;
246
252
  }
253
+ #endif
247
254
 
248
255
  struct win64_closure_frame
249
256
  {
@@ -56,8 +56,8 @@
56
56
 
57
57
  /* Handle win32 fastcall name mangling. */
58
58
  #ifdef X86_WIN32
59
- # define ffi_call_i386 @ffi_call_i386@8
60
- # define ffi_closure_inner @ffi_closure_inner@8
59
+ # define ffi_call_i386 "@ffi_call_i386@8"
60
+ # define ffi_closure_inner "@ffi_closure_inner@8"
61
61
  #else
62
62
  # define ffi_call_i386 C(ffi_call_i386)
63
63
  # define ffi_closure_inner C(ffi_closure_inner)
@@ -92,6 +92,7 @@
92
92
  ffi_call_i386:
93
93
  L(UW0):
94
94
  # cfi_startproc
95
+ _CET_ENDBR
95
96
  #if !HAVE_FASTCALL
96
97
  movl 4(%esp), %ecx
97
98
  movl 8(%esp), %edx
@@ -133,7 +134,7 @@ L(pc1):
133
134
  leal L(store_table)(,%ecx, 8), %ebx
134
135
  #endif
135
136
  movl 16(%ebp), %ecx /* load result address */
136
- jmp *%ebx
137
+ _CET_NOTRACK jmp *%ebx
137
138
 
138
139
  .balign 8
139
140
  L(store_table):
@@ -256,7 +257,7 @@ ENDF(ffi_call_i386)
256
257
  andl $X86_RET_TYPE_MASK, %eax; \
257
258
  leal L(C1(load_table,N))(, %eax, 8), %edx; \
258
259
  movl closure_CF(%esp), %eax; /* optimiztic load */ \
259
- jmp *%edx
260
+ _CET_NOTRACK jmp *%edx
260
261
 
261
262
  #ifdef __PIC__
262
263
  # if defined X86_DARWIN || defined HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
@@ -267,7 +268,7 @@ ENDF(ffi_call_i386)
267
268
  L(C1(pc,N)): \
268
269
  leal L(C1(load_table,N))-L(C1(pc,N))(%edx, %eax, 8), %edx; \
269
270
  movl closure_CF(%esp), %eax; /* optimiztic load */ \
270
- jmp *%edx
271
+ _CET_NOTRACK jmp *%edx
271
272
  # else
272
273
  # define FFI_CLOSURE_CALL_INNER_SAVE_EBX
273
274
  # undef FFI_CLOSURE_CALL_INNER
@@ -286,7 +287,7 @@ L(C1(UW,UWN)): \
286
287
  L(C1(UW,UWN)): \
287
288
  /* cfi_restore(%ebx); */ \
288
289
  movl closure_CF(%esp), %eax; /* optimiztic load */ \
289
- jmp *%edx
290
+ _CET_NOTRACK jmp *%edx
290
291
  # endif /* DARWIN || HIDDEN */
291
292
  #endif /* __PIC__ */
292
293
 
@@ -296,6 +297,7 @@ L(C1(UW,UWN)): \
296
297
  C(ffi_go_closure_EAX):
297
298
  L(UW6):
298
299
  # cfi_startproc
300
+ _CET_ENDBR
299
301
  subl $closure_FS, %esp
300
302
  L(UW7):
301
303
  # cfi_def_cfa_offset(closure_FS + 4)
@@ -316,6 +318,7 @@ ENDF(C(ffi_go_closure_EAX))
316
318
  C(ffi_go_closure_ECX):
317
319
  L(UW9):
318
320
  # cfi_startproc
321
+ _CET_ENDBR
319
322
  subl $closure_FS, %esp
320
323
  L(UW10):
321
324
  # cfi_def_cfa_offset(closure_FS + 4)
@@ -340,6 +343,7 @@ ENDF(C(ffi_go_closure_ECX))
340
343
  C(ffi_closure_i386):
341
344
  L(UW12):
342
345
  # cfi_startproc
346
+ _CET_ENDBR
343
347
  subl $closure_FS, %esp
344
348
  L(UW13):
345
349
  # cfi_def_cfa_offset(closure_FS + 4)
@@ -423,6 +427,7 @@ ENDF(C(ffi_closure_i386))
423
427
  C(ffi_go_closure_STDCALL):
424
428
  L(UW21):
425
429
  # cfi_startproc
430
+ _CET_ENDBR
426
431
  subl $closure_FS, %esp
427
432
  L(UW22):
428
433
  # cfi_def_cfa_offset(closure_FS + 4)
@@ -448,6 +453,7 @@ L(UW24):
448
453
  # cfi_startproc
449
454
  # cfi_def_cfa(%esp, 8)
450
455
  # cfi_offset(%eip, -8)
456
+ _CET_ENDBR
451
457
  subl $closure_FS-4, %esp
452
458
  L(UW25):
453
459
  # cfi_def_cfa_offset(closure_FS + 4)
@@ -470,6 +476,7 @@ ENDF(C(ffi_closure_REGISTER))
470
476
  C(ffi_closure_STDCALL):
471
477
  L(UW27):
472
478
  # cfi_startproc
479
+ _CET_ENDBR
473
480
  subl $closure_FS, %esp
474
481
  L(UW28):
475
482
  # cfi_def_cfa_offset(closure_FS + 4)
@@ -576,6 +583,7 @@ ENDF(C(ffi_closure_STDCALL))
576
583
  C(ffi_closure_raw_SYSV):
577
584
  L(UW32):
578
585
  # cfi_startproc
586
+ _CET_ENDBR
579
587
  subl $raw_closure_S_FS, %esp
580
588
  L(UW33):
581
589
  # cfi_def_cfa_offset(raw_closure_S_FS + 4)
@@ -679,6 +687,7 @@ ENDF(C(ffi_closure_raw_SYSV))
679
687
  C(ffi_closure_raw_THISCALL):
680
688
  L(UW41):
681
689
  # cfi_startproc
690
+ _CET_ENDBR
682
691
  /* Rearrange the stack such that %ecx is the first argument.
683
692
  This means moving the return address. */
684
693
  popl %edx
@@ -42,7 +42,11 @@
42
42
  #if defined(__clang__) || defined(__APPLE__) || (defined (__sun__) && defined(__svr4__))
43
43
  # define E(BASE, X) .balign 8
44
44
  #else
45
- # define E(BASE, X) .balign 8; .org BASE + X * 8
45
+ # ifdef __CET__
46
+ # define E(BASE, X) .balign 8; .org BASE + X * 16
47
+ # else
48
+ # define E(BASE, X) .balign 8; .org BASE + X * 8
49
+ # endif
46
50
  #endif
47
51
 
48
52
  /* ffi_call_unix64 (void *args, unsigned long bytes, unsigned flags,
@@ -58,6 +62,7 @@
58
62
 
59
63
  C(ffi_call_unix64):
60
64
  L(UW0):
65
+ _CET_ENDBR
61
66
  movq (%rsp), %r10 /* Load return address. */
62
67
  leaq (%rdi, %rsi), %rax /* Find local stack base. */
63
68
  movq %rdx, (%rax) /* Save flags. */
@@ -79,7 +84,6 @@ L(UW1):
79
84
 
80
85
  movq %rdi, %r10 /* Save a copy of the register area. */
81
86
  movq %r8, %r11 /* Save a copy of the target fn. */
82
- movl %r9d, %eax /* Set number of SSE registers. */
83
87
 
84
88
  /* Load up all argument registers. */
85
89
  movq (%r10), %rdi
@@ -88,7 +92,7 @@ L(UW1):
88
92
  movq 0x18(%r10), %rcx
89
93
  movq 0x20(%r10), %r8
90
94
  movq 0x28(%r10), %r9
91
- movl 0xb0(%r10), %eax
95
+ movl 0xb0(%r10), %eax /* Set number of SSE registers. */
92
96
  testl %eax, %eax
93
97
  jnz L(load_sse)
94
98
  L(ret_from_load_sse):
@@ -116,6 +120,11 @@ L(UW2):
116
120
  movzbl %cl, %r10d
117
121
  leaq L(store_table)(%rip), %r11
118
122
  ja L(sa)
123
+ #ifdef __CET__
124
+ /* NB: Originally, each slot is 8 byte. 4 bytes of ENDBR64 +
125
+ 4 bytes NOP padding double slot size to 16 bytes. */
126
+ addl %r10d, %r10d
127
+ #endif
119
128
  leaq (%r11, %r10, 8), %r10
120
129
 
121
130
  /* Prep for the structure cases: scratch area in redzone. */
@@ -125,57 +134,73 @@ L(UW2):
125
134
  .balign 8
126
135
  L(store_table):
127
136
  E(L(store_table), UNIX64_RET_VOID)
137
+ _CET_ENDBR
128
138
  ret
129
139
  E(L(store_table), UNIX64_RET_UINT8)
140
+ _CET_ENDBR
130
141
  movzbl %al, %eax
131
142
  movq %rax, (%rdi)
132
143
  ret
133
144
  E(L(store_table), UNIX64_RET_UINT16)
145
+ _CET_ENDBR
134
146
  movzwl %ax, %eax
135
147
  movq %rax, (%rdi)
136
148
  ret
137
149
  E(L(store_table), UNIX64_RET_UINT32)
150
+ _CET_ENDBR
138
151
  movl %eax, %eax
139
152
  movq %rax, (%rdi)
140
153
  ret
141
154
  E(L(store_table), UNIX64_RET_SINT8)
155
+ _CET_ENDBR
142
156
  movsbq %al, %rax
143
157
  movq %rax, (%rdi)
144
158
  ret
145
159
  E(L(store_table), UNIX64_RET_SINT16)
160
+ _CET_ENDBR
146
161
  movswq %ax, %rax
147
162
  movq %rax, (%rdi)
148
163
  ret
149
164
  E(L(store_table), UNIX64_RET_SINT32)
165
+ _CET_ENDBR
150
166
  cltq
151
167
  movq %rax, (%rdi)
152
168
  ret
153
169
  E(L(store_table), UNIX64_RET_INT64)
170
+ _CET_ENDBR
154
171
  movq %rax, (%rdi)
155
172
  ret
156
173
  E(L(store_table), UNIX64_RET_XMM32)
174
+ _CET_ENDBR
157
175
  movd %xmm0, (%rdi)
158
176
  ret
159
177
  E(L(store_table), UNIX64_RET_XMM64)
178
+ _CET_ENDBR
160
179
  movq %xmm0, (%rdi)
161
180
  ret
162
181
  E(L(store_table), UNIX64_RET_X87)
182
+ _CET_ENDBR
163
183
  fstpt (%rdi)
164
184
  ret
165
185
  E(L(store_table), UNIX64_RET_X87_2)
186
+ _CET_ENDBR
166
187
  fstpt (%rdi)
167
188
  fstpt 16(%rdi)
168
189
  ret
169
190
  E(L(store_table), UNIX64_RET_ST_XMM0_RAX)
191
+ _CET_ENDBR
170
192
  movq %rax, 8(%rsi)
171
193
  jmp L(s3)
172
194
  E(L(store_table), UNIX64_RET_ST_RAX_XMM0)
195
+ _CET_ENDBR
173
196
  movq %xmm0, 8(%rsi)
174
197
  jmp L(s2)
175
198
  E(L(store_table), UNIX64_RET_ST_XMM0_XMM1)
199
+ _CET_ENDBR
176
200
  movq %xmm1, 8(%rsi)
177
201
  jmp L(s3)
178
202
  E(L(store_table), UNIX64_RET_ST_RAX_RDX)
203
+ _CET_ENDBR
179
204
  movq %rdx, 8(%rsi)
180
205
  L(s2):
181
206
  movq %rax, (%rsi)
@@ -227,6 +252,7 @@ ENDF(C(ffi_call_unix64))
227
252
 
228
253
  C(ffi_closure_unix64_sse):
229
254
  L(UW5):
255
+ _CET_ENDBR
230
256
  subq $ffi_closure_FS, %rsp
231
257
  L(UW6):
232
258
  /* cfi_adjust_cfa_offset(ffi_closure_FS) */
@@ -250,6 +276,7 @@ ENDF(C(ffi_closure_unix64_sse))
250
276
 
251
277
  C(ffi_closure_unix64):
252
278
  L(UW8):
279
+ _CET_ENDBR
253
280
  subq $ffi_closure_FS, %rsp
254
281
  L(UW9):
255
282
  /* cfi_adjust_cfa_offset(ffi_closure_FS) */
@@ -286,6 +313,11 @@ L(UW10):
286
313
  movzbl %al, %r10d
287
314
  leaq L(load_table)(%rip), %r11
288
315
  ja L(la)
316
+ #ifdef __CET__
317
+ /* NB: Originally, each slot is 8 byte. 4 bytes of ENDBR64 +
318
+ 4 bytes NOP padding double slot size to 16 bytes. */
319
+ addl %r10d, %r10d
320
+ #endif
289
321
  leaq (%r11, %r10, 8), %r10
290
322
  leaq ffi_closure_RED_RVALUE(%rsp), %rsi
291
323
  jmp *%r10
@@ -293,51 +325,67 @@ L(UW10):
293
325
  .balign 8
294
326
  L(load_table):
295
327
  E(L(load_table), UNIX64_RET_VOID)
328
+ _CET_ENDBR
296
329
  ret
297
330
  E(L(load_table), UNIX64_RET_UINT8)
331
+ _CET_ENDBR
298
332
  movzbl (%rsi), %eax
299
333
  ret
300
334
  E(L(load_table), UNIX64_RET_UINT16)
335
+ _CET_ENDBR
301
336
  movzwl (%rsi), %eax
302
337
  ret
303
338
  E(L(load_table), UNIX64_RET_UINT32)
339
+ _CET_ENDBR
304
340
  movl (%rsi), %eax
305
341
  ret
306
342
  E(L(load_table), UNIX64_RET_SINT8)
343
+ _CET_ENDBR
307
344
  movsbl (%rsi), %eax
308
345
  ret
309
346
  E(L(load_table), UNIX64_RET_SINT16)
347
+ _CET_ENDBR
310
348
  movswl (%rsi), %eax
311
349
  ret
312
350
  E(L(load_table), UNIX64_RET_SINT32)
351
+ _CET_ENDBR
313
352
  movl (%rsi), %eax
314
353
  ret
315
354
  E(L(load_table), UNIX64_RET_INT64)
355
+ _CET_ENDBR
316
356
  movq (%rsi), %rax
317
357
  ret
318
358
  E(L(load_table), UNIX64_RET_XMM32)
359
+ _CET_ENDBR
319
360
  movd (%rsi), %xmm0
320
361
  ret
321
362
  E(L(load_table), UNIX64_RET_XMM64)
363
+ _CET_ENDBR
322
364
  movq (%rsi), %xmm0
323
365
  ret
324
366
  E(L(load_table), UNIX64_RET_X87)
367
+ _CET_ENDBR
325
368
  fldt (%rsi)
326
369
  ret
327
370
  E(L(load_table), UNIX64_RET_X87_2)
371
+ _CET_ENDBR
328
372
  fldt 16(%rsi)
329
373
  fldt (%rsi)
330
374
  ret
331
375
  E(L(load_table), UNIX64_RET_ST_XMM0_RAX)
376
+ _CET_ENDBR
332
377
  movq 8(%rsi), %rax
333
378
  jmp L(l3)
334
379
  E(L(load_table), UNIX64_RET_ST_RAX_XMM0)
380
+ _CET_ENDBR
335
381
  movq 8(%rsi), %xmm0
336
382
  jmp L(l2)
337
383
  E(L(load_table), UNIX64_RET_ST_XMM0_XMM1)
384
+ _CET_ENDBR
338
385
  movq 8(%rsi), %xmm1
339
386
  jmp L(l3)
340
387
  E(L(load_table), UNIX64_RET_ST_RAX_RDX)
388
+ _CET_ENDBR
341
389
  movq 8(%rsi), %rdx
342
390
  L(l2):
343
391
  movq (%rsi), %rax
@@ -358,6 +406,7 @@ ENDF(C(ffi_closure_unix64))
358
406
 
359
407
  C(ffi_go_closure_unix64_sse):
360
408
  L(UW12):
409
+ _CET_ENDBR
361
410
  subq $ffi_closure_FS, %rsp
362
411
  L(UW13):
363
412
  /* cfi_adjust_cfa_offset(ffi_closure_FS) */
@@ -381,6 +430,7 @@ ENDF(C(ffi_go_closure_unix64_sse))
381
430
 
382
431
  C(ffi_go_closure_unix64):
383
432
  L(UW15):
433
+ _CET_ENDBR
384
434
  subq $ffi_closure_FS, %rsp
385
435
  L(UW16):
386
436
  /* cfi_adjust_cfa_offset(ffi_closure_FS) */
@@ -424,7 +474,12 @@ EHFrame0:
424
474
  #endif
425
475
 
426
476
  /* Simplify advancing between labels. Assume DW_CFA_advance_loc1 fits. */
427
- #define ADV(N, P) .byte 2, L(N)-L(P)
477
+ #ifdef __CET__
478
+ /* Use DW_CFA_advance_loc2 when IBT is enabled. */
479
+ # define ADV(N, P) .byte 3; .2byte L(N)-L(P)
480
+ #else
481
+ # define ADV(N, P) .byte 2, L(N)-L(P)
482
+ #endif
428
483
 
429
484
  .balign 8
430
485
  L(CIE):