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
@@ -192,9 +192,10 @@ static void unmarshal_atom(call_builder *cb, int type, void *data) {
192
192
  /* for arguments passed by reference returns the pointer, otherwise the arg is copied (up to MAXCOPYARG bytes) */
193
193
  static void *unmarshal(call_builder *cb, ffi_type *type, int var, void *data) {
194
194
  size_t realign[2];
195
- void *pointer;
196
195
 
197
196
  #if defined(__ARC64_ARCH64__)
197
+ void *pointer;
198
+
198
199
  if (type->size > 2 * __SIZEOF_POINTER__) {
199
200
  /* pass by reference */
200
201
  unmarshal_atom(cb, FFI_TYPE_POINTER, (char*)&pointer);
@@ -348,7 +349,10 @@ ffi_prep_closure_loc (ffi_closure * closure, ffi_cif * cif,
348
349
  void *user_data, void *codeloc)
349
350
  {
350
351
  uint32_t *tramp = (uint32_t *) & (closure->tramp[0]);
352
+
353
+ #if defined(__ARC64_ARCH64__)
351
354
  size_t address_ffi_closure = (size_t) ffi_closure_asm;
355
+ #endif
352
356
 
353
357
  switch (cif->abi)
354
358
  {
@@ -367,7 +371,7 @@ ffi_prep_closure_loc (ffi_closure * closure, ffi_cif * cif,
367
371
  FFI_ASSERT (tramp == codeloc);
368
372
  tramp[0] = CODE_ENDIAN (0x200a1fc0); /* mov r8, pcl */
369
373
  tramp[1] = CODE_ENDIAN (0x20200f80); /* j [long imm] */
370
- tramp[2] = CODE_ENDIAN (ffi_closure_asm);
374
+ tramp[2] = CODE_ENDIAN ((uint32_t) ffi_closure_asm);
371
375
  break;
372
376
  #endif
373
377
 
@@ -164,7 +164,7 @@ ffi_tramp_is_present (__attribute__((unused)) void *ptr)
164
164
 
165
165
  #include <mach/mach.h>
166
166
  #include <pthread.h>
167
- #ifdef HAVE_PTRAUTH
167
+ #ifdef HAVE_ARM64E_PTRAUTH
168
168
  #include <ptrauth.h>
169
169
  #endif
170
170
  #include <stdio.h>
@@ -223,7 +223,7 @@ ffi_trampoline_table_alloc (void)
223
223
  /* Remap the trampoline table on top of the placeholder page */
224
224
  trampoline_page = config_page + PAGE_MAX_SIZE;
225
225
 
226
- #ifdef HAVE_PTRAUTH
226
+ #ifdef HAVE_ARM64E_PTRAUTH
227
227
  trampoline_page_template = (vm_address_t)(uintptr_t)ptrauth_auth_data((void *)&ffi_closure_trampoline_table_page, ptrauth_key_function_pointer, 0);
228
228
  #else
229
229
  trampoline_page_template = (vm_address_t)&ffi_closure_trampoline_table_page;
@@ -268,7 +268,7 @@ ffi_trampoline_table_alloc (void)
268
268
  ffi_trampoline_table_entry *entry = &table->free_list_pool[i];
269
269
  entry->trampoline =
270
270
  (void *) (trampoline_page + (i * FFI_TRAMPOLINE_SIZE));
271
- #ifdef HAVE_PTRAUTH
271
+ #ifdef HAVE_ARM64E_PTRAUTH
272
272
  entry->trampoline = ptrauth_sign_unauthenticated(entry->trampoline, ptrauth_key_function_pointer, 0);
273
273
  #endif
274
274
 
@@ -599,7 +599,7 @@ open_temp_exec_file_memfd (const char *name)
599
599
 
600
600
  /* Open a temporary file name, and immediately unlink it. */
601
601
  static int
602
- open_temp_exec_file_name (char *name, int flags)
602
+ open_temp_exec_file_name (char *name, int flags MAYBE_UNUSED)
603
603
  {
604
604
  int fd;
605
605
 
@@ -795,7 +795,7 @@ open_temp_exec_file (void)
795
795
  Failure to allocate the space will cause SIGBUS to be thrown when
796
796
  the mapping is subsequently written to. */
797
797
  static int
798
- allocate_space (int fd, off_t offset, off_t len)
798
+ allocate_space (int fd, off_t len)
799
799
  {
800
800
  static long page_size;
801
801
 
@@ -838,7 +838,7 @@ dlmmap_locked (void *start, size_t length, int prot, int flags, off_t offset)
838
838
 
839
839
  offset = execsize;
840
840
 
841
- if (allocate_space (execfd, offset, length))
841
+ if (allocate_space (execfd, length))
842
842
  return MFAIL;
843
843
 
844
844
  flags &= ~(MAP_PRIVATE | MAP_ANONYMOUS);
@@ -38,7 +38,7 @@ void ffi_stop_here(void)
38
38
 
39
39
  /* This function should only be called via the FFI_ASSERT() macro */
40
40
 
41
- void ffi_assert(char *expr, char *file, int line)
41
+ NORETURN void ffi_assert(const char *expr, const char *file, int line)
42
42
  {
43
43
  fprintf(stderr, "ASSERTION FAILURE: %s at %s:%d\n", expr, file, line);
44
44
  ffi_stop_here();
@@ -47,7 +47,7 @@ void ffi_assert(char *expr, char *file, int line)
47
47
 
48
48
  /* Perform a sanity check on an ffi_type structure */
49
49
 
50
- void ffi_type_test(ffi_type *a, char *file, int line)
50
+ void ffi_type_test(ffi_type *a, const char *file, int line)
51
51
  {
52
52
  FFI_ASSERT_AT(a != NULL, file, line);
53
53
 
@@ -3388,6 +3388,7 @@ static void add_segment(mstate m, char* tbase, size_t tsize, flag_t mmapped) {
3388
3388
  mchunkptr tnext = chunk_plus_offset(sp, ssize);
3389
3389
  mchunkptr p = tnext;
3390
3390
  int nfences = 0;
3391
+ (void)nfences; // Suppress unused variable warning
3391
3392
 
3392
3393
  /* reset top to new space */
3393
3394
  init_top(m, (mchunkptr)tbase, tsize - TOP_FOOT_SIZE);
@@ -4452,7 +4453,7 @@ struct mallinfo dlmallinfo(void) {
4452
4453
  }
4453
4454
  #endif /* NO_MALLINFO */
4454
4455
 
4455
- void dlmalloc_stats() {
4456
+ void dlmalloc_stats(void) {
4456
4457
  internal_malloc_stats(gm);
4457
4458
  }
4458
4459
 
@@ -28,6 +28,7 @@
28
28
 
29
29
  #include <ffi.h>
30
30
  #include <ffi_common.h>
31
+ #include <tramp.h>
31
32
 
32
33
  #include <stdlib.h>
33
34
  #include <stdint.h>
@@ -58,7 +59,9 @@
58
59
  */
59
60
  typedef struct call_context
60
61
  {
62
+ #if !defined(__loongarch_soft_float)
61
63
  ABI_FLOAT fa[8];
64
+ #endif
62
65
  size_t a[10];
63
66
  } call_context;
64
67
 
@@ -647,9 +647,9 @@ static ffi_status ffi_prep_cif_machdep_int(ffi_cif *cif, unsigned nfixedargs)
647
647
 
648
648
  case FFI_TYPE_POINTER:
649
649
  if (cif->abi == FFI_N32_SOFT_FLOAT || cif->abi == FFI_N32)
650
- cif->flags += FFI_TYPE_UINT32 << (FFI_FLAG_BITS * 8);
650
+ cif->flags += FFI_TYPE_SINT32 << (FFI_FLAG_BITS * 8);
651
651
  else
652
- cif->flags += FFI_TYPE_INT << (FFI_FLAG_BITS * 8);
652
+ cif->flags += FFI_TYPE_UINT64 << (FFI_FLAG_BITS * 8);
653
653
  break;
654
654
 
655
655
  case FFI_TYPE_FLOAT:
@@ -661,7 +661,7 @@ static ffi_status ffi_prep_cif_machdep_int(ffi_cif *cif, unsigned nfixedargs)
661
661
  /* else fall through */
662
662
  case FFI_TYPE_DOUBLE:
663
663
  if (soft_float)
664
- cif->flags += FFI_TYPE_INT << (FFI_FLAG_BITS * 8);
664
+ cif->flags += FFI_TYPE_UINT64 << (FFI_FLAG_BITS * 8);
665
665
  else
666
666
  cif->flags += cif->rtype->type << (FFI_FLAG_BITS * 8);
667
667
  break;
@@ -715,8 +715,16 @@ static ffi_status ffi_prep_cif_machdep_int(ffi_cif *cif, unsigned nfixedargs)
715
715
  }
716
716
  break;
717
717
  }
718
+ case FFI_TYPE_UINT32:
719
+ /* In the N32 or N64 ABI unsigned 32-bit integer should be
720
+ *sign*-extended. */
721
+ cif->flags += FFI_TYPE_SINT32 << (FFI_FLAG_BITS * 8);
722
+ break;
723
+ case FFI_TYPE_SINT64:
724
+ cif->flags += FFI_TYPE_UINT64 << (FFI_FLAG_BITS * 8);
725
+ break;
718
726
  default:
719
- cif->flags += FFI_TYPE_INT << (FFI_FLAG_BITS * 8);
727
+ cif->flags += cif->rtype->type << (FFI_FLAG_BITS * 8);
720
728
  break;
721
729
  }
722
730
  }
@@ -32,16 +32,14 @@
32
32
  #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
33
33
  #endif
34
34
 
35
- #ifdef __linux__
36
- # include <asm/sgidefs.h>
37
- #elif defined(__rtems__)
35
+ #ifdef __rtems__
38
36
  /*
39
37
  * Subprogram calling convention - copied from sgidefs.h
40
38
  */
41
39
  #define _MIPS_SIM_ABI32 1
42
40
  #define _MIPS_SIM_NABI32 2
43
41
  #define _MIPS_SIM_ABI64 3
44
- #elif !defined(__OpenBSD__) && !defined(__FreeBSD__)
42
+ #elif !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__linux__)
45
43
  # include <sgidefs.h>
46
44
  #endif
47
45
 
@@ -236,19 +236,54 @@ callit:
236
236
  # Shift the return type flag over
237
237
  SRL t6, 8*FFI_FLAG_BITS
238
238
 
239
- beq t6, FFI_TYPE_SINT32, retint
240
- bne t6, FFI_TYPE_INT, retuint32
241
- retint:
239
+ bne t6, FFI_TYPE_UINT64, retsint32
240
+
241
+ retuint64:
242
242
  jal t9
243
243
  REG_L t4, 4*FFI_SIZEOF_ARG($fp)
244
- REG_S v0, 0(t4)
244
+ sd v0, 0(t4)
245
245
  b epilogue
246
246
 
247
- retuint32:
248
- bne t6, FFI_TYPE_UINT32, retfloat
247
+ retsint32:
248
+ bne t6, FFI_TYPE_SINT32, retuint16
249
249
  jal t9
250
250
  REG_L t4, 4*FFI_SIZEOF_ARG($fp)
251
- sw v0, 0(t4)
251
+ sll v0, v0, 0
252
+ sd v0, 0(t4)
253
+ b epilogue
254
+
255
+ retuint16:
256
+ bne t6, FFI_TYPE_UINT16, retsint16
257
+ jal t9
258
+ REG_L t4, 4*FFI_SIZEOF_ARG($fp)
259
+ andi v0, v0, 0xffff
260
+ sd v0, 0(t4)
261
+ b epilogue
262
+
263
+ retsint16:
264
+ bne t6, FFI_TYPE_SINT16, retuint8
265
+ jal t9
266
+ REG_L t4, 4*FFI_SIZEOF_ARG($fp)
267
+ dsll v0, v0, 48
268
+ dsra v0, v0, 48
269
+ sd v0, 0(t4)
270
+ b epilogue
271
+
272
+ retuint8:
273
+ bne t6, FFI_TYPE_UINT8, retsint8
274
+ jal t9
275
+ REG_L t4, 4*FFI_SIZEOF_ARG($fp)
276
+ andi v0, v0, 0xff
277
+ sd v0, 0(t4)
278
+ b epilogue
279
+
280
+ retsint8:
281
+ bne t6, FFI_TYPE_SINT8, retfloat
282
+ jal t9
283
+ REG_L t4, 4*FFI_SIZEOF_ARG($fp)
284
+ sd v0, 0(t4)
285
+ dsll v0, v0, 56
286
+ dsra v0, v0, 56
252
287
  b epilogue
253
288
 
254
289
  retfloat:
@@ -585,19 +620,35 @@ $do_closure:
585
620
 
586
621
  jalr t9
587
622
 
623
+ cls_retuint64:
588
624
  # Return flags are in v0
589
- bne v0, FFI_TYPE_SINT32, cls_retuint32
625
+ bne v0, FFI_TYPE_UINT64, cls_retsint32
626
+ ld v0, V0_OFF2($sp)
627
+ b cls_epilogue
628
+
629
+ cls_retsint32:
630
+ bne v0, FFI_TYPE_SINT32, cls_retsint16
590
631
  lw v0, V0_OFF2($sp)
591
632
  b cls_epilogue
592
633
 
593
- cls_retuint32:
594
- bne v0, FFI_TYPE_UINT32, cls_retint
595
- lwu v0, V0_OFF2($sp)
634
+ cls_retsint16:
635
+ bne v0, FFI_TYPE_SINT16, cls_retuint16
636
+ lh v0, V0_OFF2($sp)
596
637
  b cls_epilogue
597
638
 
598
- cls_retint:
599
- bne v0, FFI_TYPE_INT, cls_retfloat
600
- REG_L v0, V0_OFF2($sp)
639
+ cls_retuint16:
640
+ bne v0, FFI_TYPE_UINT16, cls_retsint8
641
+ lhu v0, V0_OFF2($sp)
642
+ b cls_epilogue
643
+
644
+ cls_retsint8:
645
+ bne v0, FFI_TYPE_SINT8, cls_retuint8
646
+ lb v0, V0_OFF2($sp)
647
+ b cls_epilogue
648
+
649
+ cls_retuint8:
650
+ bne v0, FFI_TYPE_UINT8, cls_retfloat
651
+ lbu v0, V0_OFF2($sp)
601
652
  b cls_epilogue
602
653
 
603
654
  cls_retfloat:
@@ -770,3 +821,7 @@ cls_epilogue:
770
821
  #endif /* __GNUC__ */
771
822
 
772
823
  #endif
824
+
825
+ #if defined __ELF__ && defined __linux__
826
+ .section .note.GNU-stack,"",%progbits
827
+ #endif
@@ -559,3 +559,7 @@ $LASFDE2:
559
559
  $LEFDE2:
560
560
 
561
561
  #endif
562
+
563
+ #if defined __ELF__ && defined __linux__
564
+ .section .note.GNU-stack,"",%progbits
565
+ #endif
@@ -110,7 +110,7 @@ void* ffi_prep_args(char *stack, extended_cif *ecif)
110
110
 
111
111
  extern void ffi_call_SYSV(unsigned,
112
112
  extended_cif *,
113
- void *(*)(int *, extended_cif *),
113
+ void *(*)(char *, extended_cif *),
114
114
  unsigned *,
115
115
  void (*fn)(void),
116
116
  unsigned);
@@ -180,7 +180,7 @@ void ffi_closure_SYSV(unsigned long r3, unsigned long r4, unsigned long r5,
180
180
  register int *r13 __asm__ ("r13");
181
181
 
182
182
  ffi_closure* closure = (ffi_closure*) r13;
183
- char *stack_args = sp;
183
+ char *stack_args = (char*) sp;
184
184
 
185
185
  /* Lay the register arguments down in a continuous chunk of memory. */
186
186
  unsigned register_args[6] =
@@ -31,6 +31,8 @@
31
31
  #include "ffi.h"
32
32
  #include "ffi_common.h"
33
33
  #include "ffi_powerpc.h"
34
+ #include "internal.h"
35
+ #include <tramp.h>
34
36
 
35
37
  #if HAVE_LONG_DOUBLE_VARIANT
36
38
  /* Adjust ffi_type_longdouble. */
@@ -173,3 +175,14 @@ ffi_prep_go_closure (ffi_go_closure *closure,
173
175
  closure->fun = fun;
174
176
  return FFI_OK;
175
177
  }
178
+
179
+ #ifdef FFI_EXEC_STATIC_TRAMP
180
+ void *
181
+ ffi_tramp_arch (size_t *tramp_size, size_t *map_size)
182
+ {
183
+ extern void *trampoline_code_table;
184
+ *tramp_size = PPC_TRAMP_SIZE;
185
+ *map_size = PPC_TRAMP_MAP_SIZE;
186
+ return &trampoline_code_table;
187
+ }
188
+ #endif
@@ -623,38 +623,50 @@ darwin_adjust_aggregate_sizes (ffi_type *s)
623
623
  }
624
624
 
625
625
  /* Adjust the size of S to be correct for AIX.
626
- Word-align double unless it is the first member of a structure. */
626
+ Word-align double unless it is the first member of a structure recursively.
627
+ Return non-zero if we found a recursive first member aggregate of interest. */
627
628
 
628
- static void
629
- aix_adjust_aggregate_sizes (ffi_type *s)
629
+ static int
630
+ aix_adjust_aggregate_sizes (ffi_type *s, int outer_most_type_or_first_member)
630
631
  {
631
- int i;
632
+ int i, nested_first_member=0, final_align, rc=0;
632
633
 
633
634
  if (s->type != FFI_TYPE_STRUCT)
634
- return;
635
+ return 0;
635
636
 
636
637
  s->size = 0;
637
638
  for (i = 0; s->elements[i] != NULL; i++)
638
639
  {
639
- ffi_type *p;
640
+ ffi_type p;
640
641
  int align;
641
-
642
- p = s->elements[i];
643
- aix_adjust_aggregate_sizes (p);
644
- align = p->alignment;
645
- if (i != 0 && p->type == FFI_TYPE_DOUBLE)
646
- align = 4;
647
- s->size = FFI_ALIGN(s->size, align) + p->size;
642
+
643
+ /* nested aggregates layout differently on AIX, so take a copy of the type */
644
+ p = *(s->elements[i]);
645
+ if (i == 0)
646
+ nested_first_member = aix_adjust_aggregate_sizes(&p, outer_most_type_or_first_member);
647
+ else
648
+ aix_adjust_aggregate_sizes(&p, 0);
649
+ align = p.alignment;
650
+ if (i != 0 && p.type == FFI_TYPE_DOUBLE)
651
+ align = 4;
652
+ s->size = FFI_ALIGN(s->size, align) + p.size;
648
653
  }
649
-
650
- s->size = FFI_ALIGN(s->size, s->alignment);
651
-
652
- if (s->elements[0]->type == FFI_TYPE_UINT64
653
- || s->elements[0]->type == FFI_TYPE_SINT64
654
- || s->elements[0]->type == FFI_TYPE_DOUBLE
655
- || s->elements[0]->alignment == 8)
656
- s->alignment = s->alignment > 8 ? s->alignment : 8;
657
- /* Do not add additional tail padding. */
654
+
655
+ final_align=s->alignment;
656
+ if ((s->elements[0]->type == FFI_TYPE_UINT64
657
+ || s->elements[0]->type == FFI_TYPE_SINT64
658
+ || s->elements[0]->type == FFI_TYPE_DOUBLE
659
+ || s->elements[0]->alignment == 8 || nested_first_member)) {
660
+ final_align = s->alignment > 8 ? s->alignment : 8;
661
+ rc=1;
662
+ /* still use the adjusted alignment to calculate tail padding, but don't adjust the types alignment if
663
+ we aren't in the recursive first position */
664
+ if (outer_most_type_or_first_member)
665
+ s->alignment=final_align;
666
+ }
667
+
668
+ s->size = FFI_ALIGN(s->size, final_align);
669
+ return rc;
658
670
  }
659
671
 
660
672
  /* Perform machine dependent cif processing. */
@@ -682,9 +694,9 @@ ffi_prep_cif_machdep (ffi_cif *cif)
682
694
 
683
695
  if (cif->abi == FFI_AIX)
684
696
  {
685
- aix_adjust_aggregate_sizes (cif->rtype);
697
+ aix_adjust_aggregate_sizes (cif->rtype, 1);
686
698
  for (i = 0; i < cif->nargs; i++)
687
- aix_adjust_aggregate_sizes (cif->arg_types[i]);
699
+ aix_adjust_aggregate_sizes (cif->arg_types[i], 1);
688
700
  }
689
701
 
690
702
  /* Space for the frame pointer, callee's LR, CR, etc, and for
@@ -29,6 +29,7 @@
29
29
  ----------------------------------------------------------------------- */
30
30
 
31
31
  #include "ffi.h"
32
+ #include <tramp.h>
32
33
 
33
34
  #ifdef POWERPC64
34
35
  #include "ffi_common.h"
@@ -820,32 +821,38 @@ ffi_prep_closure_loc_linux64 (ffi_closure *closure,
820
821
  void *user_data,
821
822
  void *codeloc)
822
823
  {
823
- #if _CALL_ELF == 2
824
- unsigned int *tramp = (unsigned int *) &closure->tramp[0];
825
-
826
824
  if (cif->abi < FFI_LINUX || cif->abi >= FFI_LAST_ABI)
827
825
  return FFI_BAD_ABI;
828
826
 
829
- tramp[0] = 0xe96c0018; /* 0: ld 11,2f-0b(12) */
830
- tramp[1] = 0xe98c0010; /* ld 12,1f-0b(12) */
831
- tramp[2] = 0x7d8903a6; /* mtctr 12 */
832
- tramp[3] = 0x4e800420; /* bctr */
827
+ #ifdef FFI_EXEC_STATIC_TRAMP
828
+ if (ffi_tramp_is_present(closure))
829
+ {
830
+ /* Initialize the static trampoline's parameters. */
831
+ void (*dest)(void) = ffi_closure_LINUX64;
832
+ ffi_tramp_set_parms (closure->ftramp, dest, closure);
833
+ }
834
+ else
835
+ #endif
836
+ {
837
+ #if _CALL_ELF == 2
838
+ unsigned int *tramp = (unsigned int *) &closure->tramp[0];
839
+ tramp[0] = 0xe96c0018; /* 0: ld 11,2f-0b(12) */
840
+ tramp[1] = 0xe98c0010; /* ld 12,1f-0b(12) */
841
+ tramp[2] = 0x7d8903a6; /* mtctr 12 */
842
+ tramp[3] = 0x4e800420; /* bctr */
833
843
  /* 1: .quad function_addr */
834
844
  /* 2: .quad context */
835
- *(void **) &tramp[4] = (void *) ffi_closure_LINUX64;
836
- *(void **) &tramp[6] = codeloc;
837
- flush_icache ((char *) tramp, (char *) codeloc, 4 * 4);
845
+ *(void **) &tramp[4] = (void *) ffi_closure_LINUX64;
846
+ *(void **) &tramp[6] = codeloc;
847
+ flush_icache ((char *) tramp, (char *) codeloc, 4 * 4);
838
848
  #else
839
- void **tramp = (void **) &closure->tramp[0];
840
-
841
- if (cif->abi < FFI_LINUX || cif->abi >= FFI_LAST_ABI)
842
- return FFI_BAD_ABI;
843
-
844
- /* Copy function address and TOC from ffi_closure_LINUX64 OPD. */
845
- memcpy (&tramp[0], (void **) ffi_closure_LINUX64, sizeof (void *));
846
- tramp[1] = codeloc;
847
- memcpy (&tramp[2], (void **) ffi_closure_LINUX64 + 1, sizeof (void *));
849
+ /* Copy function address and TOC from ffi_closure_LINUX64 OPD. */
850
+ void **tramp = (void **) &closure->tramp[0];
851
+ memcpy (&tramp[0], (void **) ffi_closure_LINUX64, sizeof (void *));
852
+ tramp[1] = codeloc;
853
+ memcpy (&tramp[2], (void **) ffi_closure_LINUX64 + 1, sizeof (void *));
848
854
  #endif
855
+ }
849
856
 
850
857
  closure->cif = cif;
851
858
  closure->fun = fun;
@@ -29,6 +29,7 @@
29
29
  ----------------------------------------------------------------------- */
30
30
 
31
31
  #include "ffi.h"
32
+ #include <tramp.h>
32
33
 
33
34
  #ifndef POWERPC64
34
35
  #include "ffi_common.h"
@@ -636,25 +637,34 @@ ffi_prep_closure_loc_sysv (ffi_closure *closure,
636
637
  void *user_data,
637
638
  void *codeloc)
638
639
  {
639
- unsigned int *tramp;
640
-
641
640
  if (cif->abi < FFI_SYSV || cif->abi >= FFI_LAST_ABI)
642
641
  return FFI_BAD_ABI;
643
642
 
644
- tramp = (unsigned int *) &closure->tramp[0];
645
- tramp[0] = 0x7c0802a6; /* mflr r0 */
646
- tramp[1] = 0x429f0005; /* bcl 20,31,.+4 */
647
- tramp[2] = 0x7d6802a6; /* mflr r11 */
648
- tramp[3] = 0x7c0803a6; /* mtlr r0 */
649
- tramp[4] = 0x800b0018; /* lwz r0,24(r11) */
650
- tramp[5] = 0x816b001c; /* lwz r11,28(r11) */
651
- tramp[6] = 0x7c0903a6; /* mtctr r0 */
652
- tramp[7] = 0x4e800420; /* bctr */
653
- *(void **) &tramp[8] = (void *) ffi_closure_SYSV; /* function */
654
- *(void **) &tramp[9] = codeloc; /* context */
655
-
656
- /* Flush the icache. */
657
- flush_icache ((char *)tramp, (char *)codeloc, 8 * 4);
643
+ #ifdef FFI_EXEC_STATIC_TRAMP
644
+ if (ffi_tramp_is_present(closure))
645
+ {
646
+ /* Initialize the static trampoline's parameters. */
647
+ void (*dest)(void) = ffi_closure_SYSV;
648
+ ffi_tramp_set_parms (closure->ftramp, dest, closure);
649
+ }
650
+ else
651
+ #endif
652
+ {
653
+ unsigned int *tramp = (unsigned int *) &closure->tramp[0];
654
+ tramp[0] = 0x7c0802a6; /* mflr r0 */
655
+ tramp[1] = 0x429f0005; /* bcl 20,31,.+4 */
656
+ tramp[2] = 0x7d6802a6; /* mflr r11 */
657
+ tramp[3] = 0x7c0803a6; /* mtlr r0 */
658
+ tramp[4] = 0x800b0018; /* lwz r0,24(r11) */
659
+ tramp[5] = 0x816b001c; /* lwz r11,28(r11) */
660
+ tramp[6] = 0x7c0903a6; /* mtctr r0 */
661
+ tramp[7] = 0x4e800420; /* bctr */
662
+ *(void **) &tramp[8] = (void *) ffi_closure_SYSV; /* function */
663
+ *(void **) &tramp[9] = codeloc; /* context */
664
+
665
+ /* Flush the icache. */
666
+ flush_icache ((char *)tramp, (char *)codeloc, 8 * 4);
667
+ }
658
668
 
659
669
  closure->cif = cif;
660
670
  closure->fun = fun;
@@ -0,0 +1,10 @@
1
+ #ifdef FFI_EXEC_STATIC_TRAMP
2
+ /* For the trampoline code table mapping, a mapping size of 64K is chosen. */
3
+ #define PPC_TRAMP_MAP_SHIFT 16
4
+ #define PPC_TRAMP_MAP_SIZE (1 << PPC_TRAMP_MAP_SHIFT)
5
+ # ifdef __PCREL__
6
+ # define PPC_TRAMP_SIZE 24
7
+ # else
8
+ # define PPC_TRAMP_SIZE 40
9
+ # endif /* __PCREL__ */
10
+ #endif /* FFI_EXEC_STATIC_TRAMP */
@@ -27,6 +27,7 @@
27
27
  #define LIBFFI_ASM
28
28
  #include <fficonfig.h>
29
29
  #include <ffi.h>
30
+ #include "internal.h"
30
31
 
31
32
  .file "linux64_closure.S"
32
33
 
@@ -559,7 +560,53 @@ ffi_go_closure_linux64:
559
560
  .size .ffi_go_closure_linux64,.-.ffi_go_closure_linux64
560
561
  # endif
561
562
  # endif
563
+
564
+ #ifdef FFI_EXEC_STATIC_TRAMP
565
+ .text
566
+ .align PPC_TRAMP_MAP_SHIFT
567
+ FFI_HIDDEN (trampoline_code_table)
568
+ .globl trampoline_code_table
569
+ # if _CALL_ELF == 2
570
+ .type trampoline_code_table,@function
571
+ trampoline_code_table:
572
+ .localentry trampoline_code_table,.-trampoline_code_table
573
+ # else
574
+ .section ".opd","aw"
575
+ .align 3
576
+ trampoline_code_table:
577
+ .quad .L.trampoline_code_table,.TOC.@tocbase,0
578
+ .type trampoline_code_table,@function
579
+ .text
580
+ .L.trampoline_code_table:
581
+ # endif
582
+ .rept PPC_TRAMP_MAP_SIZE / PPC_TRAMP_SIZE
583
+ #ifdef __PCREL__
584
+ pla %r2,PPC_TRAMP_MAP_SIZE
585
+ ld %r11,0(%r2)
586
+ ld %r12,8(%r2)
587
+ mtctr %r12
588
+ bctr
589
+ #else
590
+ mflr %r0
591
+ bcl 20,31,$+4
592
+ mflr %r11
593
+ addis %r11,%r11,PPC_TRAMP_MAP_SIZE@ha
594
+ mtlr %r0
595
+ ld %r12,(PPC_TRAMP_MAP_SIZE+0)@l(%r11)
596
+ mtctr %r12
597
+ ld %r11,(PPC_TRAMP_MAP_SIZE-8)@l(%r11)
598
+ bctr
599
+ nop
600
+ #endif
601
+ .endr
602
+ .align PPC_TRAMP_MAP_SHIFT
603
+ #if _CALL_ELF == 2
604
+ .size trampoline_code_table,.-trampoline_code_table
605
+ #else
606
+ .size trampoline_code_table,.-.L.trampoline_code_table
562
607
  #endif
608
+ #endif /* FFI_EXEC_STATIC_TRAMP */
609
+ #endif /* POWERPC64 */
563
610
 
564
611
  #if (defined __ELF__ && defined __linux__) || _CALL_ELF == 2
565
612
  .section .note.GNU-stack,"",@progbits