ffi 1.12.2 → 1.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.appveyor.yml +3 -0
  3. data/.github/workflows/ci.yml +64 -0
  4. data/.travis.yml +19 -5
  5. data/CHANGELOG.md +41 -0
  6. data/Gemfile +4 -2
  7. data/Rakefile +24 -43
  8. data/ext/ffi_c/Buffer.c +2 -2
  9. data/ext/ffi_c/Call.c +1 -7
  10. data/ext/ffi_c/ClosurePool.c +11 -14
  11. data/ext/ffi_c/Function.c +8 -23
  12. data/ext/ffi_c/FunctionInfo.c +1 -2
  13. data/ext/ffi_c/LongDouble.c +5 -3
  14. data/ext/ffi_c/LongDouble.h +0 -4
  15. data/ext/ffi_c/MemoryPointer.c +1 -1
  16. data/ext/ffi_c/MethodHandle.c +18 -24
  17. data/ext/ffi_c/MethodHandle.h +3 -2
  18. data/ext/ffi_c/Platform.c +1 -0
  19. data/ext/ffi_c/Pointer.c +1 -1
  20. data/ext/ffi_c/StructLayout.c +7 -2
  21. data/ext/ffi_c/Thread.c +0 -3
  22. data/ext/ffi_c/Thread.h +0 -3
  23. data/ext/ffi_c/compat.h +4 -0
  24. data/ext/ffi_c/extconf.rb +16 -19
  25. data/ext/ffi_c/libffi/.travis.yml +4 -0
  26. data/ext/ffi_c/libffi/.travis/build.sh +4 -0
  27. data/ext/ffi_c/libffi/Makefile.am +2 -1
  28. data/ext/ffi_c/libffi/README.md +7 -1
  29. data/ext/ffi_c/libffi/configure.ac +25 -9
  30. data/ext/ffi_c/libffi/include/ffi.h.in +8 -0
  31. data/ext/ffi_c/libffi/libffi.map.in +8 -12
  32. data/ext/ffi_c/libffi/libtool-version +1 -1
  33. data/ext/ffi_c/libffi/src/aarch64/ffi.c +6 -0
  34. data/ext/ffi_c/libffi/src/aarch64/sysv.S +13 -2
  35. data/ext/ffi_c/libffi/src/closures.c +10 -4
  36. data/ext/ffi_c/libffi/src/pa/ffi.c +46 -91
  37. data/ext/ffi_c/libffi/src/pa/ffitarget.h +1 -6
  38. data/ext/ffi_c/libffi/src/pa/hpux32.S +4 -2
  39. data/ext/ffi_c/libffi/src/pa/linux.S +4 -2
  40. data/ext/ffi_c/libffi/src/powerpc/sysv.S +5 -7
  41. data/ext/ffi_c/libffi/src/x86/ffi.c +7 -4
  42. data/ext/ffi_c/libffi/src/x86/ffi64.c +10 -8
  43. data/ext/ffi_c/libffi/src/x86/ffitarget.h +15 -2
  44. data/ext/ffi_c/libffi/src/x86/ffiw64.c +10 -8
  45. data/ext/ffi_c/libffi/src/x86/sysv.S +13 -4
  46. data/ext/ffi_c/libffi/src/x86/unix64.S +58 -2
  47. data/ext/ffi_c/libffi/src/x86/win64.S +4 -1
  48. data/ffi.gemspec +1 -1
  49. data/lib/ffi.rb +10 -2
  50. data/lib/ffi/library.rb +5 -1
  51. data/lib/ffi/platform.rb +6 -2
  52. data/lib/ffi/platform/arm-linux/types.conf +32 -4
  53. data/lib/ffi/platform/i386-windows/types.conf +26 -79
  54. data/lib/ffi/platform/powerpc-linux/types.conf +32 -2
  55. data/lib/ffi/platform/powerpc-openbsd/types.conf +156 -0
  56. data/lib/ffi/platform/sparcv9-openbsd/types.conf +156 -0
  57. data/lib/ffi/platform/x86_64-darwin/types.conf +4 -0
  58. data/lib/ffi/platform/x86_64-dragonflybsd/types.conf +4 -22
  59. data/lib/ffi/platform/x86_64-linux/types.conf +21 -0
  60. data/lib/ffi/platform/x86_64-windows/types.conf +10 -78
  61. data/lib/ffi/pointer.rb +19 -12
  62. data/lib/ffi/struct.rb +8 -2
  63. data/lib/ffi/tools/types_generator.rb +2 -0
  64. data/lib/ffi/version.rb +1 -1
  65. data/samples/getlogin.rb +1 -1
  66. data/samples/getpid.rb +1 -1
  67. data/samples/gettimeofday.rb +8 -8
  68. data/samples/hello.rb +2 -1
  69. data/samples/inotify.rb +1 -1
  70. data/samples/pty.rb +1 -2
  71. data/samples/qsort.rb +0 -1
  72. metadata +6 -4
  73. data/samples/sample_helper.rb +0 -6
@@ -176,6 +176,28 @@ case "$TARGET" in
176
176
  ;;
177
177
  esac
178
178
 
179
+ AC_CACHE_CHECK([whether compiler supports pointer authentication],
180
+ libffi_cv_as_ptrauth, [
181
+ libffi_cv_as_ptrauth=unknown
182
+ AC_TRY_COMPILE(,[
183
+ #ifdef __clang__
184
+ # if __has_feature(ptrauth_calls)
185
+ # define HAVE_PTRAUTH 1
186
+ # endif
187
+ #endif
188
+
189
+ #ifndef HAVE_PTRAUTH
190
+ # error Pointer authentication not supported
191
+ #endif
192
+ ],
193
+ [libffi_cv_as_ptrauth=yes],
194
+ [libffi_cv_as_ptrauth=no])
195
+ ])
196
+ if test "x$libffi_cv_as_ptrauth" = xyes; then
197
+ AC_DEFINE(HAVE_PTRAUTH, 1,
198
+ [Define if your compiler supports pointer authentication.])
199
+ fi
200
+
179
201
  # On PaX enable kernels that have MPROTECT enable we can't use PROT_EXEC.
180
202
  AC_ARG_ENABLE(pax_emutramp,
181
203
  [ --enable-pax_emutramp enable pax emulated trampolines, for we can't use PROT_EXEC],
@@ -240,17 +262,11 @@ fi
240
262
  if test "x$GCC" = "xyes"; then
241
263
  AC_CACHE_CHECK([whether .eh_frame section should be read-only],
242
264
  libffi_cv_ro_eh_frame, [
243
- libffi_cv_ro_eh_frame=no
265
+ libffi_cv_ro_eh_frame=yes
244
266
  echo 'extern void foo (void); void bar (void) { foo (); foo (); }' > conftest.c
245
267
  if $CC $CFLAGS -c -fpic -fexceptions -o conftest.o conftest.c > /dev/null 2>&1; then
246
- objdump -h conftest.o > conftest.dump 2>&1
247
- libffi_eh_frame_line=`grep -n eh_frame conftest.dump | cut -d: -f 1`
248
- if test "x$libffi_eh_frame_line" != "x"; then
249
- libffi_test_line=`expr $libffi_eh_frame_line + 1`p
250
- sed -n $libffi_test_line conftest.dump > conftest.line
251
- if grep READONLY conftest.line > /dev/null; then
252
- libffi_cv_ro_eh_frame=yes
253
- fi
268
+ if readelf -WS conftest.o | grep -q -n 'eh_frame .* WA'; then
269
+ libffi_cv_ro_eh_frame=no
254
270
  fi
255
271
  fi
256
272
  rm -f conftest.*
@@ -330,6 +330,14 @@ typedef struct {
330
330
  FFI_API void *ffi_closure_alloc (size_t size, void **code);
331
331
  FFI_API void ffi_closure_free (void *);
332
332
 
333
+ #if defined(PA_LINUX) || defined(PA_HPUX)
334
+ #define FFI_CLOSURE_PTR(X) ((void *)((unsigned int)(X) | 2))
335
+ #define FFI_RESTORE_PTR(X) ((void *)((unsigned int)(X) & ~3))
336
+ #else
337
+ #define FFI_CLOSURE_PTR(X) (X)
338
+ #define FFI_RESTORE_PTR(X) (X)
339
+ #endif
340
+
333
341
  FFI_API ffi_status
334
342
  ffi_prep_closure (ffi_closure*,
335
343
  ffi_cif *,
@@ -6,7 +6,7 @@
6
6
  /* These version numbers correspond to the libtool-version abi numbers,
7
7
  not to the libffi release numbers. */
8
8
 
9
- LIBFFI_BASE_7.0 {
9
+ LIBFFI_BASE_8.0 {
10
10
  global:
11
11
  /* Exported data variables. */
12
12
  ffi_type_void;
@@ -38,27 +38,23 @@ LIBFFI_BASE_7.0 {
38
38
  ffi_java_raw_to_ptrarray;
39
39
  ffi_java_raw_size;
40
40
 
41
+ ffi_get_struct_offsets;
41
42
  local:
42
43
  *;
43
44
  };
44
45
 
45
- LIBFFI_BASE_7.1 {
46
- global:
47
- ffi_get_struct_offsets;
48
- } LIBFFI_BASE_7.0;
49
-
50
46
  #ifdef FFI_TARGET_HAS_COMPLEX_TYPE
51
- LIBFFI_COMPLEX_7.0 {
47
+ LIBFFI_COMPLEX_8.0 {
52
48
  global:
53
49
  /* Exported data variables. */
54
50
  ffi_type_complex_float;
55
51
  ffi_type_complex_double;
56
52
  ffi_type_complex_longdouble;
57
- } LIBFFI_BASE_7.0;
53
+ } LIBFFI_BASE_8.0;
58
54
  #endif
59
55
 
60
56
  #if FFI_CLOSURES
61
- LIBFFI_CLOSURE_7.0 {
57
+ LIBFFI_CLOSURE_8.0 {
62
58
  global:
63
59
  ffi_closure_alloc;
64
60
  ffi_closure_free;
@@ -68,13 +64,13 @@ LIBFFI_CLOSURE_7.0 {
68
64
  ffi_prep_raw_closure_loc;
69
65
  ffi_prep_java_raw_closure;
70
66
  ffi_prep_java_raw_closure_loc;
71
- } LIBFFI_BASE_7.0;
67
+ } LIBFFI_BASE_8.0;
72
68
  #endif
73
69
 
74
70
  #if FFI_GO_CLOSURES
75
- LIBFFI_GO_CLOSURE_7.0 {
71
+ LIBFFI_GO_CLOSURE_8.0 {
76
72
  global:
77
73
  ffi_call_go;
78
74
  ffi_prep_go_closure;
79
- } LIBFFI_CLOSURE_7.0;
75
+ } LIBFFI_CLOSURE_8.0;
80
76
  #endif
@@ -26,4 +26,4 @@
26
26
  # release, then set age to 0.
27
27
  #
28
28
  # CURRENT:REVISION:AGE
29
- 8:0:1
29
+ 9:0:1
@@ -62,6 +62,9 @@ struct call_context
62
62
  #if FFI_EXEC_TRAMPOLINE_TABLE
63
63
 
64
64
  #ifdef __MACH__
65
+ #ifdef HAVE_PTRAUTH
66
+ #include <ptrauth.h>
67
+ #endif
65
68
  #include <mach/vm_param.h>
66
69
  #endif
67
70
 
@@ -789,6 +792,9 @@ ffi_prep_closure_loc (ffi_closure *closure,
789
792
 
790
793
  #if FFI_EXEC_TRAMPOLINE_TABLE
791
794
  #ifdef __MACH__
795
+ #ifdef HAVE_PTRAUTH
796
+ codeloc = ptrauth_strip (codeloc, ptrauth_key_asia);
797
+ #endif
792
798
  void **config = (void **)((uint8_t *)codeloc - PAGE_MAX_SIZE);
793
799
  config[0] = closure;
794
800
  config[1] = start;
@@ -56,6 +56,14 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
56
56
  #define PTR_SIZE 4
57
57
  #else
58
58
  #define PTR_SIZE 8
59
+ #endif
60
+
61
+ #if FFI_EXEC_TRAMPOLINE_TABLE && defined(__MACH__) && defined(HAVE_PTRAUTH)
62
+ # define BR(r) braaz r
63
+ # define BLR(r) blraaz r
64
+ #else
65
+ # define BR(r) br r
66
+ # define BLR(r) blr r
59
67
  #endif
60
68
 
61
69
  .text
@@ -111,7 +119,7 @@ CNAME(ffi_call_SYSV):
111
119
  /* Deallocate the context, leaving the stacked arguments. */
112
120
  add sp, sp, #CALL_CONTEXT_SIZE
113
121
 
114
- blr x9 /* call fn */
122
+ BLR(x9) /* call fn */
115
123
 
116
124
  ldp x3, x4, [x29, #16] /* reload rvalue and flags */
117
125
 
@@ -271,6 +279,9 @@ CNAME(ffi_closure_SYSV):
271
279
  bl CNAME(ffi_closure_SYSV_inner)
272
280
 
273
281
  /* Load the return value as directed. */
282
+ #if FFI_EXEC_TRAMPOLINE_TABLE && defined(__MACH__) && defined(HAVE_PTRAUTH)
283
+ autiza x1
284
+ #endif
274
285
  adr x1, 0f
275
286
  and w0, w0, #AARCH64_RET_MASK
276
287
  add x1, x1, x0, lsl #3
@@ -365,7 +376,7 @@ CNAME(ffi_closure_trampoline_table_page):
365
376
  .rept PAGE_MAX_SIZE / FFI_TRAMPOLINE_SIZE
366
377
  adr x16, -PAGE_MAX_SIZE
367
378
  ldp x17, x16, [x16]
368
- br x16
379
+ BR(x16)
369
380
  nop /* each entry in the trampoline config page is 2*sizeof(void*) so the trampoline itself cannot be smaller that 16 bytes */
370
381
  .endr
371
382
 
@@ -148,6 +148,9 @@ ffi_closure_free (void *ptr)
148
148
 
149
149
  #include <mach/mach.h>
150
150
  #include <pthread.h>
151
+ #ifdef HAVE_PTRAUTH
152
+ #include <ptrauth.h>
153
+ #endif
151
154
  #include <stdio.h>
152
155
  #include <stdlib.h>
153
156
 
@@ -301,6 +304,9 @@ ffi_closure_alloc (size_t size, void **code)
301
304
 
302
305
  /* Initialize the return values */
303
306
  *code = entry->trampoline;
307
+ #ifdef HAVE_PTRAUTH
308
+ *code = ptrauth_sign_unauthenticated (*code, ptrauth_key_asia, 0);
309
+ #endif
304
310
  closure->trampoline_table = table;
305
311
  closure->trampoline_table_entry = entry;
306
312
 
@@ -921,7 +927,7 @@ ffi_closure_alloc (size_t size, void **code)
921
927
  if (!code)
922
928
  return NULL;
923
929
 
924
- ptr = dlmalloc (size);
930
+ ptr = FFI_CLOSURE_PTR (dlmalloc (size));
925
931
 
926
932
  if (ptr)
927
933
  {
@@ -961,7 +967,7 @@ ffi_closure_free (void *ptr)
961
967
  ptr = sub_segment_exec_offset (ptr, seg);
962
968
  #endif
963
969
 
964
- dlfree (ptr);
970
+ dlfree (FFI_RESTORE_PTR (ptr));
965
971
  }
966
972
 
967
973
  # else /* ! FFI_MMAP_EXEC_WRIT */
@@ -977,13 +983,13 @@ ffi_closure_alloc (size_t size, void **code)
977
983
  if (!code)
978
984
  return NULL;
979
985
 
980
- return *code = malloc (size);
986
+ return *code = FFI_CLOSURE_PTR (malloc (size));
981
987
  }
982
988
 
983
989
  void
984
990
  ffi_closure_free (void *ptr)
985
991
  {
986
- free (ptr);
992
+ free (FFI_RESTORE_PTR (ptr));
987
993
  }
988
994
 
989
995
  void *
@@ -421,12 +421,15 @@ ffi_status ffi_closure_inner_pa32(ffi_closure *closure, UINT32 *stack)
421
421
  ffi_cif *cif;
422
422
  void **avalue;
423
423
  void *rvalue;
424
- UINT32 ret[2]; /* function can return up to 64-bits in registers */
424
+ /* Functions can return up to 64-bits in registers. Return address
425
+ must be double word aligned. */
426
+ union { double rd; UINT32 ret[2]; } u;
425
427
  ffi_type **p_arg;
426
428
  char *tmp;
427
429
  int i, avn;
428
430
  unsigned int slot = FIRST_ARG_SLOT;
429
431
  register UINT32 r28 asm("r28");
432
+ ffi_closure *c = (ffi_closure *)FFI_RESTORE_PTR (closure);
430
433
 
431
434
  cif = closure->cif;
432
435
 
@@ -434,7 +437,7 @@ ffi_status ffi_closure_inner_pa32(ffi_closure *closure, UINT32 *stack)
434
437
  if (cif->flags == FFI_TYPE_STRUCT)
435
438
  rvalue = (void *)r28;
436
439
  else
437
- rvalue = &ret[0];
440
+ rvalue = &u;
438
441
 
439
442
  avalue = (void **)alloca(cif->nargs * FFI_SIZEOF_ARG);
440
443
  avn = cif->nargs;
@@ -529,35 +532,35 @@ ffi_status ffi_closure_inner_pa32(ffi_closure *closure, UINT32 *stack)
529
532
  }
530
533
 
531
534
  /* Invoke the closure. */
532
- (closure->fun) (cif, rvalue, avalue, closure->user_data);
535
+ (c->fun) (cif, rvalue, avalue, c->user_data);
533
536
 
534
- debug(3, "after calling function, ret[0] = %08x, ret[1] = %08x\n", ret[0],
535
- ret[1]);
537
+ debug(3, "after calling function, ret[0] = %08x, ret[1] = %08x\n", u.ret[0],
538
+ u.ret[1]);
536
539
 
537
540
  /* Store the result using the lower 2 bytes of the flags. */
538
541
  switch (cif->flags)
539
542
  {
540
543
  case FFI_TYPE_UINT8:
541
- *(stack - FIRST_ARG_SLOT) = (UINT8)(ret[0] >> 24);
544
+ *(stack - FIRST_ARG_SLOT) = (UINT8)(u.ret[0] >> 24);
542
545
  break;
543
546
  case FFI_TYPE_SINT8:
544
- *(stack - FIRST_ARG_SLOT) = (SINT8)(ret[0] >> 24);
547
+ *(stack - FIRST_ARG_SLOT) = (SINT8)(u.ret[0] >> 24);
545
548
  break;
546
549
  case FFI_TYPE_UINT16:
547
- *(stack - FIRST_ARG_SLOT) = (UINT16)(ret[0] >> 16);
550
+ *(stack - FIRST_ARG_SLOT) = (UINT16)(u.ret[0] >> 16);
548
551
  break;
549
552
  case FFI_TYPE_SINT16:
550
- *(stack - FIRST_ARG_SLOT) = (SINT16)(ret[0] >> 16);
553
+ *(stack - FIRST_ARG_SLOT) = (SINT16)(u.ret[0] >> 16);
551
554
  break;
552
555
  case FFI_TYPE_INT:
553
556
  case FFI_TYPE_SINT32:
554
557
  case FFI_TYPE_UINT32:
555
- *(stack - FIRST_ARG_SLOT) = ret[0];
558
+ *(stack - FIRST_ARG_SLOT) = u.ret[0];
556
559
  break;
557
560
  case FFI_TYPE_SINT64:
558
561
  case FFI_TYPE_UINT64:
559
- *(stack - FIRST_ARG_SLOT) = ret[0];
560
- *(stack - FIRST_ARG_SLOT - 1) = ret[1];
562
+ *(stack - FIRST_ARG_SLOT) = u.ret[0];
563
+ *(stack - FIRST_ARG_SLOT - 1) = u.ret[1];
561
564
  break;
562
565
 
563
566
  case FFI_TYPE_DOUBLE:
@@ -577,7 +580,7 @@ ffi_status ffi_closure_inner_pa32(ffi_closure *closure, UINT32 *stack)
577
580
  case FFI_TYPE_SMALL_STRUCT4:
578
581
  tmp = (void*)(stack - FIRST_ARG_SLOT);
579
582
  tmp += 4 - cif->rtype->size;
580
- memcpy((void*)tmp, &ret[0], cif->rtype->size);
583
+ memcpy((void*)tmp, &u, cif->rtype->size);
581
584
  break;
582
585
 
583
586
  case FFI_TYPE_SMALL_STRUCT5:
@@ -598,7 +601,7 @@ ffi_status ffi_closure_inner_pa32(ffi_closure *closure, UINT32 *stack)
598
601
  }
599
602
 
600
603
  memset (ret2, 0, sizeof (ret2));
601
- memcpy ((char *)ret2 + off, ret, 8 - off);
604
+ memcpy ((char *)ret2 + off, &u, 8 - off);
602
605
 
603
606
  *(stack - FIRST_ARG_SLOT) = ret2[0];
604
607
  *(stack - FIRST_ARG_SLOT - 1) = ret2[1];
@@ -630,89 +633,41 @@ ffi_prep_closure_loc (ffi_closure* closure,
630
633
  void *user_data,
631
634
  void *codeloc)
632
635
  {
633
- UINT32 *tramp = (UINT32 *)(closure->tramp);
634
- #ifdef PA_HPUX
635
- UINT32 *tmp;
636
- #endif
636
+ ffi_closure *c = (ffi_closure *)FFI_RESTORE_PTR (closure);
637
+
638
+ /* The layout of a function descriptor. A function pointer with the PLABEL
639
+ bit set points to a function descriptor. */
640
+ struct pa32_fd
641
+ {
642
+ UINT32 code_pointer;
643
+ UINT32 gp;
644
+ };
645
+
646
+ struct ffi_pa32_trampoline_struct
647
+ {
648
+ UINT32 code_pointer; /* Pointer to ffi_closure_unix. */
649
+ UINT32 fake_gp; /* Pointer to closure, installed as gp. */
650
+ UINT32 real_gp; /* Real gp value. */
651
+ };
652
+
653
+ struct ffi_pa32_trampoline_struct *tramp;
654
+ struct pa32_fd *fd;
637
655
 
638
656
  if (cif->abi != FFI_PA32)
639
657
  return FFI_BAD_ABI;
640
658
 
641
- /* Make a small trampoline that will branch to our
642
- handler function. Use PC-relative addressing. */
643
-
644
- #ifdef PA_LINUX
645
- tramp[0] = 0xeaa00000; /* b,l .+8,%r21 ; %r21 <- pc+8 */
646
- tramp[1] = 0xd6a01c1e; /* depi 0,31,2,%r21 ; mask priv bits */
647
- tramp[2] = 0x4aa10028; /* ldw 20(%r21),%r1 ; load plabel */
648
- tramp[3] = 0x36b53ff1; /* ldo -8(%r21),%r21 ; get closure addr */
649
- tramp[4] = 0x0c201096; /* ldw 0(%r1),%r22 ; address of handler */
650
- tramp[5] = 0xeac0c000; /* bv%r0(%r22) ; branch to handler */
651
- tramp[6] = 0x0c281093; /* ldw 4(%r1),%r19 ; GP of handler */
652
- tramp[7] = ((UINT32)(ffi_closure_pa32) & ~2);
653
-
654
- /* Flush d/icache -- have to flush up 2 two lines because of
655
- alignment. */
656
- __asm__ volatile(
657
- "fdc 0(%0)\n\t"
658
- "fdc %1(%0)\n\t"
659
- "fic 0(%%sr4, %0)\n\t"
660
- "fic %1(%%sr4, %0)\n\t"
661
- "sync\n\t"
662
- "nop\n\t"
663
- "nop\n\t"
664
- "nop\n\t"
665
- "nop\n\t"
666
- "nop\n\t"
667
- "nop\n\t"
668
- "nop\n"
669
- :
670
- : "r"((unsigned long)tramp & ~31),
671
- "r"(32 /* stride */)
672
- : "memory");
673
- #endif
659
+ /* Get function descriptor address for ffi_closure_pa32. */
660
+ fd = (struct pa32_fd *)((UINT32)ffi_closure_pa32 & ~3);
674
661
 
675
- #ifdef PA_HPUX
676
- tramp[0] = 0xeaa00000; /* b,l .+8,%r21 ; %r21 <- pc+8 */
677
- tramp[1] = 0xd6a01c1e; /* depi 0,31,2,%r21 ; mask priv bits */
678
- tramp[2] = 0x4aa10038; /* ldw 28(%r21),%r1 ; load plabel */
679
- tramp[3] = 0x36b53ff1; /* ldo -8(%r21),%r21 ; get closure addr */
680
- tramp[4] = 0x0c201096; /* ldw 0(%r1),%r22 ; address of handler */
681
- tramp[5] = 0x02c010b4; /* ldsid (%r22),%r20 ; load space id */
682
- tramp[6] = 0x00141820; /* mtsp %r20,%sr0 ; into %sr0 */
683
- tramp[7] = 0xe2c00000; /* be 0(%sr0,%r22) ; branch to handler */
684
- tramp[8] = 0x0c281093; /* ldw 4(%r1),%r19 ; GP of handler */
685
- tramp[9] = ((UINT32)(ffi_closure_pa32) & ~2);
686
-
687
- /* Flush d/icache -- have to flush three lines because of alignment. */
688
- __asm__ volatile(
689
- "copy %1,%0\n\t"
690
- "fdc,m %2(%0)\n\t"
691
- "fdc,m %2(%0)\n\t"
692
- "fdc,m %2(%0)\n\t"
693
- "ldsid (%1),%0\n\t"
694
- "mtsp %0,%%sr0\n\t"
695
- "copy %1,%0\n\t"
696
- "fic,m %2(%%sr0,%0)\n\t"
697
- "fic,m %2(%%sr0,%0)\n\t"
698
- "fic,m %2(%%sr0,%0)\n\t"
699
- "sync\n\t"
700
- "nop\n\t"
701
- "nop\n\t"
702
- "nop\n\t"
703
- "nop\n\t"
704
- "nop\n\t"
705
- "nop\n\t"
706
- "nop\n"
707
- : "=&r" ((unsigned long)tmp)
708
- : "r" ((unsigned long)tramp & ~31),
709
- "r" (32/* stride */)
710
- : "memory");
711
- #endif
662
+ /* Setup trampoline. */
663
+ tramp = (struct ffi_pa32_trampoline_struct *)c->tramp;
664
+ tramp->code_pointer = fd->code_pointer;
665
+ tramp->fake_gp = (UINT32)codeloc & ~3;
666
+ tramp->real_gp = fd->gp;
712
667
 
713
- closure->cif = cif;
714
- closure->user_data = user_data;
715
- closure->fun = fun;
668
+ c->cif = cif;
669
+ c->user_data = user_data;
670
+ c->fun = fun;
716
671
 
717
672
  return FFI_OK;
718
673
  }