ffi 1.17.2 → 1.17.3

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 (90) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +25 -0
  4. data/Gemfile +7 -4
  5. data/README.md +1 -0
  6. data/Rakefile +7 -4
  7. data/Steepfile +8 -0
  8. data/ext/ffi_c/DynamicLibrary.c +1 -1
  9. data/ext/ffi_c/Function.c +2 -0
  10. data/ext/ffi_c/MethodHandle.c +4 -2
  11. data/ext/ffi_c/libffi/.ci/Containerfile.ppc64le +12 -0
  12. data/ext/ffi_c/libffi/.ci/build.sh +38 -33
  13. data/ext/ffi_c/libffi/.ci/install.sh +46 -50
  14. data/ext/ffi_c/libffi/.ci/site.exp +6 -0
  15. data/ext/ffi_c/libffi/.gail-labels +44 -0
  16. data/ext/ffi_c/libffi/.github/workflows/build.yml +212 -333
  17. data/ext/ffi_c/libffi/.github/workflows/emscripten.yml +58 -3
  18. data/ext/ffi_c/libffi/.github/workflows/label-new-issue.yaml +15 -0
  19. data/ext/ffi_c/libffi/.github/workflows/tarball.yml +55 -0
  20. data/ext/ffi_c/libffi/LICENSE +1 -1
  21. data/ext/ffi_c/libffi/Makefile.am +17 -13
  22. data/ext/ffi_c/libffi/Makefile.in +37 -30
  23. data/ext/ffi_c/libffi/README.md +22 -3
  24. data/ext/ffi_c/libffi/configure +105 -121
  25. data/ext/ffi_c/libffi/configure.ac +21 -8
  26. data/ext/ffi_c/libffi/configure.host +6 -1
  27. data/ext/ffi_c/libffi/doc/Makefile.in +3 -0
  28. data/ext/ffi_c/libffi/doc/libffi.texi +24 -1
  29. data/ext/ffi_c/libffi/doc/version.texi +4 -4
  30. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +1 -28
  31. data/ext/ffi_c/libffi/include/Makefile.in +3 -0
  32. data/ext/ffi_c/libffi/include/ffi.h.in +19 -1
  33. data/ext/ffi_c/libffi/libffi.map.in +13 -1
  34. data/ext/ffi_c/libffi/libtool-version +1 -1
  35. data/ext/ffi_c/libffi/m4/asmcfi.m4 +28 -11
  36. data/ext/ffi_c/libffi/m4/ax_check_compile_flag.m4 +13 -3
  37. data/ext/ffi_c/libffi/man/Makefile.in +3 -0
  38. data/ext/ffi_c/libffi/src/aarch64/sysv.S +7 -1
  39. data/ext/ffi_c/libffi/src/arm/sysv.S +1 -1
  40. data/ext/ffi_c/libffi/src/pa/linux.S +4 -0
  41. data/ext/ffi_c/libffi/src/powerpc/ffi.c +6 -0
  42. data/ext/ffi_c/libffi/src/riscv/ffi.c +39 -16
  43. data/ext/ffi_c/libffi/src/riscv/internal.h +7 -0
  44. data/ext/ffi_c/libffi/src/riscv/sysv.S +24 -0
  45. data/ext/ffi_c/libffi/src/tramp.c +6 -1
  46. data/ext/ffi_c/libffi/src/types.c +23 -1
  47. data/ext/ffi_c/libffi/src/{wasm32 → wasm}/ffi.c +157 -54
  48. data/ext/ffi_c/libffi/src/{wasm32 → wasm}/ffitarget.h +17 -0
  49. data/ext/ffi_c/libffi/src/x86/ffitarget.h +0 -3
  50. data/ext/ffi_c/libffi/src/x86/sysv.S +1 -3
  51. data/ext/ffi_c/libffi/src/x86/sysv_intel.S +1 -3
  52. data/ext/ffi_c/libffi/testsuite/Makefile.am +3 -2
  53. data/ext/ffi_c/libffi/testsuite/Makefile.in +6 -2
  54. data/ext/ffi_c/libffi/testsuite/emscripten/build.sh +2 -2
  55. data/ext/ffi_c/libffi/testsuite/emscripten/node-tests.sh +4 -4
  56. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +269 -256
  57. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/testcases.c +1 -1
  58. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +3 -0
  59. data/ext/ffi_c/libffi/testsuite/libffi.call/longjmp.c +60 -0
  60. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_dbls_struct.c +1 -1
  61. data/ext/ffi_c/libffi/testsuite/libffi.closures/huge_struct.c +1 -2
  62. data/ext/ffi_c/libffi/testsuite/libffi.closures/unwindtest.cc +2 -0
  63. data/ext/ffi_c/libffi/testsuite/libffi.closures/unwindtest_ffi_call.cc +2 -0
  64. data/ext/ffi_c/libffi/testsuite/libffi.threads/ffitest.h +1 -0
  65. data/ext/ffi_c/libffi/testsuite/libffi.threads/threads.exp +50 -0
  66. data/ext/ffi_c/libffi/testsuite/libffi.threads/tsan.c +74 -0
  67. data/ext/ffi_c/libffi.mk +5 -0
  68. data/ffi.gemspec +4 -5
  69. data/lib/ffi/autopointer.rb +6 -0
  70. data/lib/ffi/compat.rb +11 -0
  71. data/lib/ffi/function.rb +23 -0
  72. data/lib/ffi/library.rb +19 -3
  73. data/lib/ffi/struct_by_reference.rb +1 -1
  74. data/lib/ffi/version.rb +1 -1
  75. data/samples/hello_ractor.rb +9 -1
  76. data/samples/qsort_ractor.rb +9 -1
  77. data/sig/ffi/auto_pointer.rbs +1 -1
  78. data/sig/ffi/errno.rbs +8 -0
  79. data/sig/ffi/platform.rbs +49 -0
  80. data/sig/ffi/struct.rbs +2 -2
  81. data/sig/ffi/struct_by_reference.rbs +1 -1
  82. data/sig/ffi.rbs +4 -1
  83. data.tar.gz.sig +0 -0
  84. metadata +33 -79
  85. metadata.gz.sig +0 -0
  86. data/ext/ffi_c/libffi/.appveyor/site.exp +0 -16
  87. data/ext/ffi_c/libffi/.appveyor.yml +0 -84
  88. data/lib/ffi/tools/types_generator.rb +0 -137
  89. data/rakelib/ffi_gem_helper.rb +0 -65
  90. /data/ext/ffi_c/libffi/{.appveyor → .ci}/unix-noexec.exp +0 -0
@@ -11,15 +11,6 @@ class Platform(object):
11
11
  pass
12
12
 
13
13
 
14
- class i386_platform(Platform):
15
- arch = 'i386'
16
-
17
- prefix = "#ifdef __i386__\n\n"
18
- suffix = "\n\n#endif"
19
- src_dir = 'x86'
20
- src_files = ['sysv.S', 'ffi.c', 'internal.h']
21
-
22
-
23
14
  class x86_64_platform(Platform):
24
15
  arch = 'x86_64'
25
16
 
@@ -47,13 +38,6 @@ class armv7_platform(Platform):
47
38
  src_files = ['sysv.S', 'ffi.c', 'internal.h']
48
39
 
49
40
 
50
- class ios_simulator_i386_platform(i386_platform):
51
- target = 'i386-apple-ios-simulator'
52
- directory = 'darwin_ios'
53
- sdk = 'iphonesimulator'
54
- version_min = '-miphoneos-version-min=7.0'
55
-
56
-
57
41
  class ios_simulator_x86_64_platform(x86_64_platform):
58
42
  target = 'x86_64-apple-ios-simulator'
59
43
  directory = 'darwin_ios'
@@ -117,13 +101,6 @@ class tvos_device_arm64_platform(arm64_platform):
117
101
  version_min = '-mtvos-version-min=9.0'
118
102
 
119
103
 
120
- class watchos_simulator_i386_platform(i386_platform):
121
- target = 'i386-apple-watchos-simulator'
122
- directory = 'darwin_watchos'
123
- sdk = 'watchsimulator'
124
- version_min = '-mwatchos-version-min=4.0'
125
-
126
-
127
104
  class watchos_simulator_x86_64_platform(x86_64_platform):
128
105
  target = 'x86_64-apple-watchos-simulator'
129
106
  directory = 'darwin_watchos'
@@ -210,7 +187,7 @@ def build_target(platform, platform_headers):
210
187
  mkdir_p(build_dir)
211
188
  env = dict(CC=xcrun_cmd('clang'),
212
189
  LD=xcrun_cmd('ld'),
213
- CFLAGS='%s -fembed-bitcode' % (platform.version_min))
190
+ CFLAGS='%s' % (platform.version_min))
214
191
  working_dir = os.getcwd()
215
192
  try:
216
193
  os.chdir(build_dir)
@@ -248,7 +225,6 @@ def generate_source_and_headers(
248
225
  copy_files('include', 'darwin_common/include', pattern='*.h')
249
226
 
250
227
  if generate_ios:
251
- copy_src_platform_files(ios_simulator_i386_platform)
252
228
  copy_src_platform_files(ios_simulator_x86_64_platform)
253
229
  copy_src_platform_files(ios_simulator_arm64_platform)
254
230
  copy_src_platform_files(ios_device_armv7_platform)
@@ -261,7 +237,6 @@ def generate_source_and_headers(
261
237
  copy_src_platform_files(tvos_simulator_arm64_platform)
262
238
  copy_src_platform_files(tvos_device_arm64_platform)
263
239
  if generate_watchos:
264
- copy_src_platform_files(watchos_simulator_i386_platform)
265
240
  copy_src_platform_files(watchos_simulator_x86_64_platform)
266
241
  copy_src_platform_files(watchos_simulator_arm64_platform)
267
242
  copy_src_platform_files(watchos_device_armv7k_platform)
@@ -270,7 +245,6 @@ def generate_source_and_headers(
270
245
  platform_headers = collections.defaultdict(set)
271
246
 
272
247
  if generate_ios:
273
- build_target(ios_simulator_i386_platform, platform_headers)
274
248
  build_target(ios_simulator_x86_64_platform, platform_headers)
275
249
  build_target(ios_simulator_arm64_platform, platform_headers)
276
250
  build_target(ios_device_armv7_platform, platform_headers)
@@ -283,7 +257,6 @@ def generate_source_and_headers(
283
257
  build_target(tvos_simulator_arm64_platform, platform_headers)
284
258
  build_target(tvos_device_arm64_platform, platform_headers)
285
259
  if generate_watchos:
286
- build_target(watchos_simulator_i386_platform, platform_headers)
287
260
  build_target(watchos_simulator_x86_64_platform, platform_headers)
288
261
  build_target(watchos_simulator_arm64_platform, platform_headers)
289
262
  build_target(watchos_device_armv7k_platform, platform_headers)
@@ -217,6 +217,8 @@ EGREP = @EGREP@
217
217
  ETAGS = @ETAGS@
218
218
  EXEEXT = @EXEEXT@
219
219
  FFI_EXEC_TRAMPOLINE_TABLE = @FFI_EXEC_TRAMPOLINE_TABLE@
220
+ FFI_VERSION_NUMBER = @FFI_VERSION_NUMBER@
221
+ FFI_VERSION_STRING = @FFI_VERSION_STRING@
220
222
  FGREP = @FGREP@
221
223
  FILECMD = @FILECMD@
222
224
  GREP = @GREP@
@@ -267,6 +269,7 @@ TARGET = @TARGET@
267
269
  TARGETDIR = @TARGETDIR@
268
270
  TARGET_OBJ = @TARGET_OBJ@
269
271
  VERSION = @VERSION@
272
+ WASM64_MEMORY64 = @WASM64_MEMORY64@
270
273
  abs_builddir = @abs_builddir@
271
274
  abs_srcdir = @abs_srcdir@
272
275
  abs_top_builddir = @abs_top_builddir@
@@ -1,6 +1,6 @@
1
1
  /* -----------------------------------------------------------------*-C-*-
2
2
  libffi @VERSION@
3
- - Copyright (c) 2011, 2014, 2019, 2021, 2022, 2024 Anthony Green
3
+ - Copyright (c) 2011, 2014, 2019, 2021, 2022, 2024, 2025 Anthony Green
4
4
  - Copyright (c) 1996-2003, 2007, 2008 Red Hat, Inc.
5
5
 
6
6
  Permission is hereby granted, free of charge, to any person
@@ -314,6 +314,24 @@ void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args) __a
314
314
  FFI_API
315
315
  size_t ffi_java_raw_size (ffi_cif *cif) __attribute__((deprecated));
316
316
 
317
+ /* ---- Version API ------------------------------------------------------ */
318
+
319
+ #define FFI_VERSION_STRING "@FFI_VERSION_STRING@"
320
+ #define FFI_VERSION_NUMBER @FFI_VERSION_NUMBER@
321
+
322
+ #ifndef LIBFFI_ASM
323
+ /* Return a version string. */
324
+ FFI_API const char *ffi_get_version (void);
325
+
326
+ /* Return the version as an unsigned long value: (x * 10000 + y * 100 + z) */
327
+ FFI_API unsigned long ffi_get_version_number (void);
328
+ #endif
329
+
330
+ /* ---- Internals API ---------------------------------------------------- */
331
+
332
+ FFI_API unsigned int ffi_get_default_abi (void);
333
+ FFI_API size_t ffi_get_closure_size (void);
334
+
317
335
  /* ---- Definitions for closures ----------------------------------------- */
318
336
 
319
337
  #if FFI_CLOSURES
@@ -23,7 +23,6 @@ LIBFFI_BASE_8.0 {
23
23
  ffi_type_longdouble;
24
24
  ffi_type_pointer;
25
25
 
26
- /* Exported functions. */
27
26
  ffi_call;
28
27
  ffi_prep_cif;
29
28
  ffi_prep_cif_var;
@@ -46,6 +45,19 @@ LIBFFI_BASE_8.0 {
46
45
  *;
47
46
  };
48
47
 
48
+ /* ----------------------------------------------------------------------
49
+ Symbols **added in libffi 3.5.0**.
50
+ Give them a fresh namespace so that package managers notice when
51
+ code requires a newer libffi than 3.4.x.
52
+ -------------------------------------------------------------------- */
53
+ LIBFFI_BASE_8.1 {
54
+ global:
55
+ ffi_get_version;
56
+ ffi_get_version_number;
57
+ ffi_get_default_abi;
58
+ ffi_get_closure_size;
59
+ } LIBFFI_BASE_8.0;
60
+
49
61
  #ifdef FFI_TARGET_HAS_COMPLEX_TYPE
50
62
  LIBFFI_COMPLEX_8.0 {
51
63
  global:
@@ -26,4 +26,4 @@
26
26
  # release, then set age to 0.
27
27
  #
28
28
  # CURRENT:REVISION:AGE
29
- 9:4:1
29
+ 10:0:2
@@ -1,13 +1,30 @@
1
+ dnl ------------------------------------------------------------------
2
+ dnl Check whether the assembler understands .cfi_* pseudo-ops.
3
+ dnl ------------------------------------------------------------------
1
4
  AC_DEFUN([GCC_AS_CFI_PSEUDO_OP],
2
- [AC_CACHE_CHECK([assembler .cfi pseudo-op support],
3
- gcc_cv_as_cfi_pseudo_op, [
4
- gcc_cv_as_cfi_pseudo_op=unknown
5
- AC_TRY_COMPILE([asm (".cfi_sections\n\t.cfi_startproc\n\t.cfi_endproc");],,
6
- [gcc_cv_as_cfi_pseudo_op=yes],
7
- [gcc_cv_as_cfi_pseudo_op=no])
8
- ])
9
- if test "x$gcc_cv_as_cfi_pseudo_op" = xyes; then
10
- AC_DEFINE(HAVE_AS_CFI_PSEUDO_OP, 1,
11
- [Define if your assembler supports .cfi_* directives.])
12
- fi
5
+ [
6
+ AC_CACHE_CHECK([assembler .cfi pseudo-op support],
7
+ [gcc_cv_as_cfi_pseudo_op],
8
+ [ AC_LANG_PUSH([C])
9
+ AC_COMPILE_IFELSE(
10
+ [AC_LANG_SOURCE([[
11
+ #ifdef _MSC_VER
12
+ Nope.
13
+ #endif
14
+ int foo (void)
15
+ {
16
+ __asm__ (".cfi_remember_state\n\t"
17
+ ".cfi_restore_state\n\t");
18
+ return 0;
19
+ }
20
+ ]])],
21
+ [gcc_cv_as_cfi_pseudo_op=yes],
22
+ [gcc_cv_as_cfi_pseudo_op=no])
23
+ AC_LANG_POP([C])
24
+ ])
25
+
26
+ if test "x$gcc_cv_as_cfi_pseudo_op" = xyes; then
27
+ AC_DEFINE([HAVE_AS_CFI_PSEUDO_OP], [1],
28
+ [Define if your assembler supports .cfi_* directives.])
29
+ fi
13
30
  ])
@@ -34,14 +34,24 @@
34
34
  # and this notice are preserved. This file is offered as-is, without any
35
35
  # warranty.
36
36
 
37
- #serial 6
37
+ #serial 11
38
38
 
39
39
  AC_DEFUN([AX_CHECK_COMPILE_FLAG],
40
40
  [AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
41
41
  AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
42
- AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
42
+ AC_CACHE_CHECK([whether the _AC_LANG compiler accepts $1], CACHEVAR, [
43
43
  ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
44
- _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
44
+ if test x"m4_case(_AC_LANG,
45
+ [C], [$GCC],
46
+ [C++], [$GXX],
47
+ [Fortran], [$GFC],
48
+ [Fortran 77], [$G77],
49
+ [Objective C], [$GOBJC],
50
+ [Objective C++], [$GOBJCXX],
51
+ [no])" = xyes ; then
52
+ add_gnu_werror="-Werror"
53
+ fi
54
+ _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1 $add_gnu_werror"
45
55
  AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
46
56
  [AS_VAR_SET(CACHEVAR,[yes])],
47
57
  [AS_VAR_SET(CACHEVAR,[no])])
@@ -201,6 +201,8 @@ EGREP = @EGREP@
201
201
  ETAGS = @ETAGS@
202
202
  EXEEXT = @EXEEXT@
203
203
  FFI_EXEC_TRAMPOLINE_TABLE = @FFI_EXEC_TRAMPOLINE_TABLE@
204
+ FFI_VERSION_NUMBER = @FFI_VERSION_NUMBER@
205
+ FFI_VERSION_STRING = @FFI_VERSION_STRING@
204
206
  FGREP = @FGREP@
205
207
  FILECMD = @FILECMD@
206
208
  GREP = @GREP@
@@ -251,6 +253,7 @@ TARGET = @TARGET@
251
253
  TARGETDIR = @TARGETDIR@
252
254
  TARGET_OBJ = @TARGET_OBJ@
253
255
  VERSION = @VERSION@
256
+ WASM64_MEMORY64 = @WASM64_MEMORY64@
254
257
  abs_builddir = @abs_builddir@
255
258
  abs_srcdir = @abs_srcdir@
256
259
  abs_top_builddir = @abs_top_builddir@
@@ -74,6 +74,12 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
74
74
  .text
75
75
  .align 4
76
76
 
77
+ #if defined(__ARM_FEATURE_GCS_DEFAULT) && __ARM_FEATURE_GCS_DEFAULT == 1
78
+ #define GNU_PROPERTY_AARCH64_GCS (1<<2)
79
+ #else
80
+ #define GNU_PROPERTY_AARCH64_GCS 0 /* No GCS */
81
+ #endif
82
+
77
83
  /* ffi_call_SYSV
78
84
  extern void ffi_call_SYSV (void *stack, void *frame,
79
85
  void (*fn)(void), void *rvalue,
@@ -692,7 +698,7 @@ CNAME(ffi_go_closure_SYSV):
692
698
  .asciz "GNU";
693
699
  .long 0xc0000000; /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */
694
700
  .long 4;
695
- .long GNU_PROPERTY_AARCH64_BTI | GNU_PROPERTY_AARCH64_POINTER_AUTH;
701
+ .long GNU_PROPERTY_AARCH64_BTI | GNU_PROPERTY_AARCH64_POINTER_AUTH | GNU_PROPERTY_AARCH64_GCS;
696
702
  .long 0;
697
703
  .popsection;
698
704
  #endif
@@ -120,7 +120,7 @@
120
120
  #endif
121
121
 
122
122
 
123
- #ifndef __clang__
123
+ #ifdef __ELF__
124
124
  /* We require interworking on LDM, which implies ARMv5T,
125
125
  which implies the existance of BLX. */
126
126
  .arch armv5t
@@ -425,3 +425,7 @@ ffi_closure_pa32:
425
425
 
426
426
  .align 4
427
427
  .LEFDE2:
428
+
429
+ #if defined(__ELF__) && defined(__linux__)
430
+ .section .note.GNU-stack,"",%progbits
431
+ #endif
@@ -183,6 +183,12 @@ ffi_tramp_arch (size_t *tramp_size, size_t *map_size)
183
183
  extern void *trampoline_code_table;
184
184
  *tramp_size = PPC_TRAMP_SIZE;
185
185
  *map_size = PPC_TRAMP_MAP_SIZE;
186
+ #if defined (_CALL_AIX) || _CALL_ELF == 1
187
+ /* The caller wants the entry point address of the trampoline code,
188
+ not the address of the function descriptor. */
189
+ return *(void **)trampoline_code_table;
190
+ #else
186
191
  return &trampoline_code_table;
192
+ #endif
187
193
  }
188
194
  #endif
@@ -29,6 +29,8 @@
29
29
 
30
30
  #include <ffi.h>
31
31
  #include <ffi_common.h>
32
+ #include "internal.h"
33
+ #include <tramp.h>
32
34
 
33
35
  #include <stdlib.h>
34
36
  #include <stdint.h>
@@ -424,34 +426,44 @@ extern void ffi_closure_asm(void) FFI_HIDDEN;
424
426
 
425
427
  ffi_status ffi_prep_closure_loc(ffi_closure *closure, ffi_cif *cif, void (*fun)(ffi_cif*,void*,void**,void*), void *user_data, void *codeloc)
426
428
  {
427
- uint32_t *tramp = (uint32_t *) &closure->tramp[0];
428
- uint64_t fn = (uint64_t) (uintptr_t) ffi_closure_asm;
429
-
430
429
  if (cif->abi <= FFI_FIRST_ABI || cif->abi >= FFI_LAST_ABI)
431
430
  return FFI_BAD_ABI;
432
431
 
433
- /* we will call ffi_closure_inner with codeloc, not closure, but as long
434
- as the memory is readable it should work */
432
+ #ifdef FFI_EXEC_STATIC_TRAMP
433
+ if (ffi_tramp_is_present (closure))
434
+ {
435
+ /* Initialize the static trampoline's parameters. */
436
+ void (*dest)(void) = ffi_closure_asm;
437
+ ffi_tramp_set_parms (closure->ftramp, dest, closure);
438
+ }
439
+ else
440
+ #endif
441
+ {
442
+ uint32_t *tramp = (uint32_t *) &closure->tramp[0];
443
+ uint64_t fn = (uint64_t) (uintptr_t) ffi_closure_asm;
444
+
445
+ /* we will call ffi_closure_inner with codeloc, not closure, but as long
446
+ as the memory is readable it should work */
435
447
 
436
- tramp[0] = 0x00000317; /* auipc t1, 0 (i.e. t0 <- codeloc) */
448
+ tramp[0] = 0x00000317; /* auipc t1, 0 (i.e. t0 <- codeloc) */
437
449
  #if __SIZEOF_POINTER__ == 8
438
- tramp[1] = 0x01033383; /* ld t2, 16(t1) */
450
+ tramp[1] = 0x01033383; /* ld t2, 16(t1) */
439
451
  #else
440
- tramp[1] = 0x01032383; /* lw t2, 16(t1) */
452
+ tramp[1] = 0x01032383; /* lw t2, 16(t1) */
441
453
  #endif
442
- tramp[2] = 0x00038067; /* jr t2 */
443
- tramp[3] = 0x00000013; /* nop */
444
- tramp[4] = fn;
445
- tramp[5] = fn >> 32;
454
+ tramp[2] = 0x00038067; /* jr t2 */
455
+ tramp[3] = 0x00000013; /* nop */
456
+ tramp[4] = fn;
457
+ tramp[5] = fn >> 32;
458
+ #if !defined(__FreeBSD__)
459
+ __builtin___clear_cache(codeloc, codeloc + FFI_TRAMPOLINE_SIZE);
460
+ #endif
461
+ }
446
462
 
447
463
  closure->cif = cif;
448
464
  closure->fun = fun;
449
465
  closure->user_data = user_data;
450
466
 
451
- #if !defined(__FreeBSD__)
452
- __builtin___clear_cache(codeloc, codeloc + FFI_TRAMPOLINE_SIZE);
453
- #endif
454
-
455
467
  return FFI_OK;
456
468
  }
457
469
 
@@ -512,3 +524,14 @@ ffi_closure_inner (ffi_cif *cif,
512
524
  marshal(&cb, cif->rtype, 0, rvalue);
513
525
  }
514
526
  }
527
+
528
+ #ifdef FFI_EXEC_STATIC_TRAMP
529
+ void *
530
+ ffi_tramp_arch (size_t *tramp_size, size_t *map_size)
531
+ {
532
+ extern void *trampoline_code_table;
533
+ *tramp_size = RISCV_TRAMP_SIZE;
534
+ *map_size = RISCV_TRAMP_MAP_SIZE;
535
+ return &trampoline_code_table;
536
+ }
537
+ #endif
@@ -0,0 +1,7 @@
1
+ #ifdef FFI_EXEC_STATIC_TRAMP
2
+ /* For the trampoline table mapping, a mapping size of 4K (base page size)
3
+ is chosen. */
4
+ #define RISCV_TRAMP_MAP_SHIFT 12
5
+ #define RISCV_TRAMP_MAP_SIZE (1 << RISCV_TRAMP_MAP_SHIFT)
6
+ #define RISCV_TRAMP_SIZE 16
7
+ #endif /* FFI_EXEC_STATIC_TRAMP */
@@ -29,6 +29,7 @@
29
29
  #define LIBFFI_ASM
30
30
  #include <fficonfig.h>
31
31
  #include <ffi.h>
32
+ #include "internal.h"
32
33
 
33
34
  /* Define aliases so that we can handle all ABIs uniformly */
34
35
 
@@ -291,3 +292,26 @@ ffi_go_closure_asm:
291
292
  ret
292
293
  .cfi_endproc
293
294
  .size ffi_go_closure_asm, .-ffi_go_closure_asm
295
+
296
+ #ifdef FFI_EXEC_STATIC_TRAMP
297
+ /*
298
+ trampoline_code_table.
299
+ */
300
+ .globl trampoline_code_table
301
+ .hidden trampoline_code_table
302
+ .type trampoline_code_table, @function
303
+ .align RISCV_TRAMP_MAP_SHIFT
304
+ trampoline_code_table:
305
+ .option push
306
+ # Do not allow the jr insn to be encoded as c.jr for alignment purposes
307
+ .option norvc
308
+ .rept RISCV_TRAMP_MAP_SIZE / RISCV_TRAMP_SIZE
309
+ auipc t2, RISCV_TRAMP_MAP_SIZE >> 12
310
+ LARG t1, 0(t2)
311
+ LARG t2, PTRS(t2)
312
+ jr t2
313
+ .endr
314
+ .option pop
315
+ .size trampoline_code_table,.-trampoline_code_table
316
+ .align RISCV_TRAMP_MAP_SHIFT
317
+ #endif /* FFI_EXEC_STATIC_TRAMP */
@@ -209,6 +209,11 @@ ffi_tramp_get_libffi (void)
209
209
  unsigned long start, end, offset, inode;
210
210
  uintptr_t addr = (uintptr_t) tramp_globals.text;
211
211
  int nfields, found;
212
+ int open_flags = O_RDONLY;
213
+
214
+ #ifdef O_CLOEXEC
215
+ open_flags |= O_CLOEXEC;
216
+ #endif
212
217
 
213
218
  snprintf (file, PATH_MAX, "/proc/%d/maps", getpid());
214
219
  fp = fopen (file, "r");
@@ -236,7 +241,7 @@ ffi_tramp_get_libffi (void)
236
241
  if (!found)
237
242
  return 0;
238
243
 
239
- tramp_globals.fd = open (file, O_RDONLY);
244
+ tramp_globals.fd = open (file, open_flags);
240
245
  if (tramp_globals.fd == -1)
241
246
  return 0;
242
247
 
@@ -1,5 +1,5 @@
1
1
  /* -----------------------------------------------------------------------
2
- types.c - Copyright (c) 1996, 1998, 2024 Red Hat, Inc.
2
+ types.c - Copyright (c) 1996, 1998, 2024, 2025 Red Hat, Inc.
3
3
 
4
4
  Predefined ffi_types needed by libffi.
5
5
 
@@ -31,6 +31,28 @@
31
31
  #include <ffi.h>
32
32
  #include <ffi_common.h>
33
33
 
34
+ /* Return a version string. */
35
+ const char *ffi_get_version (void)
36
+ {
37
+ return FFI_VERSION_STRING;
38
+ }
39
+
40
+ /* Return the version as an unsigned long value: (x * 10000 + y * 100 + z) */
41
+ unsigned long ffi_get_version_number (void)
42
+ {
43
+ return FFI_VERSION_NUMBER;
44
+ }
45
+
46
+ unsigned int ffi_get_default_abi (void)
47
+ {
48
+ return FFI_DEFAULT_ABI;
49
+ }
50
+
51
+ size_t ffi_get_closure_size (void)
52
+ {
53
+ return sizeof(ffi_closure);
54
+ }
55
+
34
56
  /* Type definitions */
35
57
 
36
58
  #define FFI_TYPEDEF(name, type, id, maybe_const)\