ffi 1.17.1 → 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 (74) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +8 -0
  4. data/Gemfile +3 -1
  5. data/Rakefile +1 -1
  6. data/ext/ffi_c/libffi/.github/workflows/emscripten.yml +48 -60
  7. data/ext/ffi_c/libffi/Makefile.am +4 -3
  8. data/ext/ffi_c/libffi/Makefile.in +5 -25
  9. data/ext/ffi_c/libffi/README.md +19 -2
  10. data/ext/ffi_c/libffi/acinclude.m4 +6 -0
  11. data/ext/ffi_c/libffi/config.guess +80 -22
  12. data/ext/ffi_c/libffi/config.sub +161 -80
  13. data/ext/ffi_c/libffi/configure +968 -1266
  14. data/ext/ffi_c/libffi/configure.ac +9 -8
  15. data/ext/ffi_c/libffi/configure.host +0 -5
  16. data/ext/ffi_c/libffi/doc/Makefile.in +1 -0
  17. data/ext/ffi_c/libffi/doc/libffi.texi +3 -3
  18. data/ext/ffi_c/libffi/doc/version.texi +4 -4
  19. data/ext/ffi_c/libffi/fficonfig.h.in +9 -9
  20. data/ext/ffi_c/libffi/include/Makefile.in +1 -0
  21. data/ext/ffi_c/libffi/include/ffi_cfi.h +2 -0
  22. data/ext/ffi_c/libffi/include/ffi_common.h +17 -0
  23. data/ext/ffi_c/libffi/man/Makefile.in +1 -0
  24. data/ext/ffi_c/libffi/src/aarch64/ffi.c +7 -4
  25. data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +2 -2
  26. data/ext/ffi_c/libffi/src/aarch64/internal.h +63 -17
  27. data/ext/ffi_c/libffi/src/aarch64/sysv.S +16 -12
  28. data/ext/ffi_c/libffi/src/arc/arcompact.S +2 -2
  29. data/ext/ffi_c/libffi/src/arc/ffi.c +6 -2
  30. data/ext/ffi_c/libffi/src/closures.c +3 -3
  31. data/ext/ffi_c/libffi/src/dlmalloc.c +1 -0
  32. data/ext/ffi_c/libffi/src/mips/ffitarget.h +2 -4
  33. data/ext/ffi_c/libffi/src/mips/n32.S +4 -0
  34. data/ext/ffi_c/libffi/src/mips/o32.S +4 -0
  35. data/ext/ffi_c/libffi/src/or1k/ffi.c +2 -2
  36. data/ext/ffi_c/libffi/src/powerpc/ffi.c +13 -0
  37. data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +26 -19
  38. data/ext/ffi_c/libffi/src/powerpc/ffi_sysv.c +26 -16
  39. data/ext/ffi_c/libffi/src/powerpc/internal.h +10 -0
  40. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +47 -0
  41. data/ext/ffi_c/libffi/src/powerpc/ppc_closure.S +24 -0
  42. data/ext/ffi_c/libffi/src/prep_cif.c +1 -4
  43. data/ext/ffi_c/libffi/src/s390/ffi.c +28 -1
  44. data/ext/ffi_c/libffi/src/s390/internal.h +11 -0
  45. data/ext/ffi_c/libffi/src/s390/sysv.S +38 -0
  46. data/ext/ffi_c/libffi/src/sparc/ffi.c +16 -0
  47. data/ext/ffi_c/libffi/src/wasm32/ffi.c +10 -262
  48. data/ext/ffi_c/libffi/src/x86/ffi.c +4 -1
  49. data/ext/ffi_c/libffi/src/x86/ffi64.c +4 -1
  50. data/ext/ffi_c/libffi/testsuite/Makefile.am +4 -3
  51. data/ext/ffi_c/libffi/testsuite/Makefile.in +5 -3
  52. data/ext/ffi_c/libffi/testsuite/emscripten/build-tests.sh +4 -24
  53. data/ext/ffi_c/libffi/testsuite/emscripten/build.sh +8 -25
  54. data/ext/ffi_c/libffi/testsuite/emscripten/node-tests.sh +3 -28
  55. data/ext/ffi_c/libffi/testsuite/libffi.call/callback.c +2 -2
  56. data/ext/ffi_c/libffi/testsuite/libffi.call/callback2.c +2 -2
  57. data/ext/ffi_c/libffi/testsuite/libffi.call/callback3.c +2 -2
  58. data/ext/ffi_c/libffi/testsuite/libffi.call/callback4.c +2 -2
  59. data/ext/ffi_c/libffi/testsuite/libffi.call/overread.c +54 -0
  60. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_int_float.c +88 -0
  61. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct2.c +1 -0
  62. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct3.c +1 -0
  63. data/ext/ffi_c/libffi/testsuite/libffi.call/x32.c +31 -0
  64. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_sshortchar.c +1 -1
  65. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_ushortchar.c +1 -1
  66. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_int.c +1 -1
  67. data/lib/ffi/version.rb +1 -1
  68. data.tar.gz.sig +0 -0
  69. metadata +6 -6
  70. metadata.gz.sig +0 -0
  71. data/ext/ffi_c/libffi/.circleci/config.yml +0 -156
  72. data/ext/ffi_c/libffi/src/nios2/ffi.c +0 -304
  73. data/ext/ffi_c/libffi/src/nios2/ffitarget.h +0 -52
  74. data/ext/ffi_c/libffi/src/nios2/sysv.S +0 -136
@@ -41,28 +41,7 @@
41
41
 
42
42
  #define EM_JS_MACROS(ret, name, args, body...) EM_JS(ret, name, args, body)
43
43
 
44
- #if WASM_BIGINT
45
44
  EM_JS_DEPS(libffi, "$getWasmTableEntry,$setWasmTableEntry,$getEmptyTableSlot,$convertJsFunctionToWasm");
46
- #define CALL_FUNCTION_POINTER(ptr, args...) \
47
- (LOG_DEBUG("CALL_FUNC_PTR", ptr, args), \
48
- getWasmTableEntry(ptr).apply(null, args))
49
-
50
- #define JS_FUNCTION_TO_WASM convertJsFunctionToWasm
51
- #else
52
- EM_JS_DEPS(libffi, "$getWasmTableEntry,$setWasmTableEntry,$getEmptyTableSlot,$convertJsFunctionToWasm,$dynCall,$generateFuncType,$uleb128Encode");
53
- #define CALL_FUNCTION_POINTER(ptr, args...) \
54
- (LOG_DEBUG("CALL_FUNC_PTR", sig, ptr, args), \
55
- dynCall(sig, ptr, args))
56
-
57
- #define JS_FUNCTION_TO_WASM createLegalizerWrapper
58
- #endif
59
-
60
- // Signature calculations are not needed if WASM_BIGINT is present.
61
- #if WASM_BIGINT
62
- #define SIG(sig)
63
- #else
64
- #define SIG(sig) sig
65
- #endif
66
45
 
67
46
  #define DEREF_U8(addr, offset) HEAPU8[addr + offset]
68
47
  #define DEREF_S8(addr, offset) HEAP8[addr + offset]
@@ -73,12 +52,7 @@ EM_JS_DEPS(libffi, "$getWasmTableEntry,$setWasmTableEntry,$getEmptyTableSlot,$co
73
52
 
74
53
  #define DEREF_F32(addr, offset) HEAPF32[(addr >> 2) + offset]
75
54
  #define DEREF_F64(addr, offset) HEAPF64[(addr >> 3) + offset]
76
-
77
- #if WASM_BIGINT
78
- // We have HEAPU64 in this case.
79
55
  #define DEREF_U64(addr, offset) HEAPU64[(addr >> 3) + offset]
80
- #endif
81
-
82
56
 
83
57
  #define CHECK_FIELD_OFFSET(struct, field, offset) \
84
58
  _Static_assert( \
@@ -235,40 +209,6 @@ ffi_call_js, (ffi_cif *cif, ffi_fp fn, void *rvalue, void **avalue),
235
209
  ret_by_arg = true;
236
210
  }
237
211
 
238
- SIG(var sig = "");
239
-
240
- #if !WASM_BIGINT
241
- switch(rtype_id) {
242
- case FFI_TYPE_VOID:
243
- SIG(sig = 'v');
244
- break;
245
- case FFI_TYPE_STRUCT:
246
- case FFI_TYPE_LONGDOUBLE:
247
- SIG(sig = 'vi');
248
- break;
249
- case FFI_TYPE_INT:
250
- case FFI_TYPE_UINT8:
251
- case FFI_TYPE_SINT8:
252
- case FFI_TYPE_UINT16:
253
- case FFI_TYPE_SINT16:
254
- case FFI_TYPE_UINT32:
255
- case FFI_TYPE_SINT32:
256
- case FFI_TYPE_POINTER:
257
- SIG(sig = 'i');
258
- break;
259
- case FFI_TYPE_FLOAT:
260
- SIG(sig = 'f');
261
- break;
262
- case FFI_TYPE_DOUBLE:
263
- SIG(sig = 'd');
264
- break;
265
- case FFI_TYPE_UINT64:
266
- case FFI_TYPE_SINT64:
267
- SIG(sig = 'j');
268
- break;
269
- }
270
- #endif
271
-
272
212
  // Accumulate a Javascript list of arguments for the Javascript wrapper for
273
213
  // the wasm function. The Javascript wrapper does a type conversion from
274
214
  // Javascript to C automatically, here we manually do the inverse conversion
@@ -288,54 +228,33 @@ ffi_call_js, (ffi_cif *cif, ffi_fp fn, void *rvalue, void **avalue),
288
228
  case FFI_TYPE_UINT32:
289
229
  case FFI_TYPE_POINTER:
290
230
  args.push(DEREF_U32(arg_ptr, 0));
291
- SIG(sig += 'i');
292
231
  break;
293
232
  case FFI_TYPE_FLOAT:
294
233
  args.push(DEREF_F32(arg_ptr, 0));
295
- SIG(sig += 'f');
296
234
  break;
297
235
  case FFI_TYPE_DOUBLE:
298
236
  args.push(DEREF_F64(arg_ptr, 0));
299
- SIG(sig += 'd');
300
237
  break;
301
238
  case FFI_TYPE_UINT8:
302
239
  args.push(DEREF_U8(arg_ptr, 0));
303
- SIG(sig += 'i');
304
240
  break;
305
241
  case FFI_TYPE_SINT8:
306
242
  args.push(DEREF_S8(arg_ptr, 0));
307
- SIG(sig += 'i');
308
243
  break;
309
244
  case FFI_TYPE_UINT16:
310
245
  args.push(DEREF_U16(arg_ptr, 0));
311
- SIG(sig += 'i');
312
246
  break;
313
247
  case FFI_TYPE_SINT16:
314
248
  args.push(DEREF_S16(arg_ptr, 0));
315
- SIG(sig += 'i');
316
249
  break;
317
250
  case FFI_TYPE_UINT64:
318
251
  case FFI_TYPE_SINT64:
319
- #if WASM_BIGINT
320
252
  args.push(DEREF_U64(arg_ptr, 0));
321
- #else
322
- args.push(DEREF_U32(arg_ptr, 0));
323
- args.push(DEREF_U32(arg_ptr, 1));
324
- #endif
325
- SIG(sig += 'j');
326
253
  break;
327
254
  case FFI_TYPE_LONGDOUBLE:
328
255
  // long double is passed as a pair of BigInts.
329
- #if WASM_BIGINT
330
256
  args.push(DEREF_U64(arg_ptr, 0));
331
257
  args.push(DEREF_U64(arg_ptr, 1));
332
- #else
333
- args.push(DEREF_U32(arg_ptr, 0));
334
- args.push(DEREF_U32(arg_ptr, 1));
335
- args.push(DEREF_U32(arg_ptr, 2));
336
- args.push(DEREF_U32(arg_ptr, 3));
337
- #endif
338
- SIG(sig += "jj");
339
258
  break;
340
259
  case FFI_TYPE_STRUCT:
341
260
  // Nontrivial structs are passed by pointer.
@@ -346,7 +265,6 @@ ffi_call_js, (ffi_cif *cif, ffi_fp fn, void *rvalue, void **avalue),
346
265
  STACK_ALLOC(cur_stack_ptr, size, align);
347
266
  HEAP8.subarray(cur_stack_ptr, cur_stack_ptr+size).set(HEAP8.subarray(arg_ptr, arg_ptr + size));
348
267
  args.push(cur_stack_ptr);
349
- SIG(sig += 'i');
350
268
  break;
351
269
  case FFI_TYPE_COMPLEX:
352
270
  throw new Error('complex marshalling nyi');
@@ -365,7 +283,6 @@ ffi_call_js, (ffi_cif *cif, ffi_fp fn, void *rvalue, void **avalue),
365
283
  // just always copy extra nonsense past the end. The ownwards call will know
366
284
  // not to look at it.
367
285
  if (nfixedargs != nargs) {
368
- SIG(sig += 'i');
369
286
  var struct_arg_info = [];
370
287
  for (var i = nargs - 1; i >= nfixedargs; i--) {
371
288
  var arg_ptr = DEREF_U32(avalue, i);
@@ -434,7 +351,8 @@ ffi_call_js, (ffi_cif *cif, ffi_fp fn, void *rvalue, void **avalue),
434
351
  }
435
352
  stackRestore(cur_stack_ptr);
436
353
  stackAlloc(0); // stackAlloc enforces alignment invariants on the stack pointer
437
- var result = CALL_FUNCTION_POINTER(fn, args);
354
+ LOG_DEBUG("CALL_FUNC_PTR", "fn:", fn, "args:", args);
355
+ var result = getWasmTableEntry(fn).apply(null, args);
438
356
  // Put the stack pointer back (we moved it if there were any struct args or we
439
357
  // made a varargs call)
440
358
  stackRestore(orig_stack_ptr);
@@ -472,12 +390,7 @@ ffi_call_js, (ffi_cif *cif, ffi_fp fn, void *rvalue, void **avalue),
472
390
  break;
473
391
  case FFI_TYPE_UINT64:
474
392
  case FFI_TYPE_SINT64:
475
- #if WASM_BIGINT
476
393
  DEREF_U64(rvalue, 0) = result;
477
- #else
478
- DEREF_U32(rvalue, 0) = result;
479
- DEREF_U32(rvalue, 1) = getTempRet0();
480
- #endif
481
394
  break;
482
395
  case FFI_TYPE_COMPLEX:
483
396
  throw new Error('complex ret marshalling nyi');
@@ -524,146 +437,6 @@ ffi_closure_free(void *closure) {
524
437
  return ffi_closure_free_js(closure);
525
438
  }
526
439
 
527
- #if !WASM_BIGINT
528
-
529
- // When !WASM_BIGINT, we assume there is no JS bigint integration, so JavaScript
530
- // functions cannot take 64 bit integer arguments.
531
- //
532
- // We need to make our own wasm legalizer adaptor that splits 64 bit integer
533
- // arguments and then calls the JavaScript trampoline, then the JavaScript
534
- // trampoline reassembles them, calls the closure, then splits the result (if
535
- // it's a 64 bit integer) and the adaptor puts it back together.
536
- //
537
- // This is basically the reverse of the Emscripten function
538
- // createDyncallWrapper.
539
- EM_JS(void, createLegalizerWrapper, (int trampoline, int sig), {
540
- if(!sig.includes("j")) {
541
- return convertJsFunctionToWasm(trampoline, sig);
542
- }
543
- var sections = [];
544
- var prelude = [
545
- 0x00, 0x61, 0x73, 0x6d, // magic ("\0asm")
546
- 0x01, 0x00, 0x00, 0x00, // version: 1
547
- ];
548
- sections.push(prelude);
549
- var wrappersig = [
550
- // if return type is j, we will put the upper 32 bits into tempRet0.
551
- sig[0].replace("j", "i"),
552
- // in the rest of the argument list, one 64 bit integer is legalized into
553
- // two 32 bit integers.
554
- sig.slice(1).replace(/j/g, "ii"),
555
- ].join("");
556
-
557
- var typeSectionBody = [
558
- 0x03, // number of types = 3
559
- ];
560
- generateFuncType(wrappersig, typeSectionBody); // The signature of the wrapper we are generating
561
- generateFuncType(sig, typeSectionBody); // the signature of the function pointer we will call
562
- generateFuncType("i", typeSectionBody); // the signature of getTempRet0
563
-
564
- var typeSection = [0x01 /* Type section code */];
565
- uleb128Encode(typeSectionBody.length, typeSection); // length of section in bytes
566
- typeSection.push.apply(typeSection, typeSectionBody);
567
- sections.push(typeSection);
568
-
569
- var importSection = [
570
- 0x02, // import section code
571
- 0x0d, // length of section in bytes
572
- 0x02, // number of imports = 2
573
- // Import the getTempRet0 function, which we will call "r"
574
- 0x01, 0x65, // name "e"
575
- 0x01, 0x72, // name "r"
576
- 0x00, // importing a function
577
- 0x02, // type 2 = () -> i32
578
- // Import the wrapped function, which we will call "f"
579
- 0x01, 0x65, // name "e"
580
- 0x01, 0x66, // name "f"
581
- 0x00, // importing a function
582
- 0x00, // type 0 = wrappersig
583
- ];
584
- sections.push(importSection);
585
-
586
- var functionSection = [
587
- 0x03, // function section code
588
- 0x02, // length of section in bytes
589
- 0x01, // number of functions = 1
590
- 0x01, // type 1 = sig
591
- ];
592
- sections.push(functionSection);
593
-
594
- var exportSection = [
595
- 0x07, // export section code
596
- 0x05, // length of section in bytes
597
- 0x01, // One export
598
- 0x01, 0x66, // name "f"
599
- 0x00, // type: function
600
- 0x02, // function index 2 = the wrapper function
601
- ];
602
- sections.push(exportSection);
603
-
604
- var convert_code = [];
605
- convert_code.push(0x00); // no local variables (except the arguments)
606
-
607
- function localGet(j) {
608
- convert_code.push(0x20); // local.get
609
- uleb128Encode(j, convert_code);
610
- }
611
-
612
- for (var i = 1; i < sig.length; i++) {
613
- if (sig[i] == "j") {
614
- localGet(i - 1);
615
- convert_code.push(
616
- 0xa7 // i32.wrap_i64
617
- );
618
- localGet(i - 1);
619
- convert_code.push(
620
- 0x42, 0x20, // i64.const 32
621
- 0x88, // i64.shr_u
622
- 0xa7 // i32.wrap_i64
623
- );
624
- } else {
625
- localGet(i - 1);
626
- }
627
- }
628
- convert_code.push(
629
- 0x10, 0x01 // call f
630
- );
631
- if (sig[0] === "j") {
632
- // Need to reassemble a 64 bit integer. Lower 32 bits is on stack. Upper 32
633
- // bits we get from getTempRet0
634
- convert_code.push(
635
- 0xad, // i64.extend_i32_unsigned
636
- 0x10, 0x00, // Call function 0 (r = getTempRet0)
637
- // join lower 32 bits and upper 32 bits
638
- 0xac, // i64.extend_i32_signed
639
- 0x42, 0x20, // i64.const 32
640
- 0x86, // i64.shl,
641
- 0x84 // i64.or
642
- );
643
- }
644
- convert_code.push(0x0b); // end
645
-
646
- var codeBody = [0x01]; // one code
647
- uleb128Encode(convert_code.length, codeBody);
648
- codeBody.push.apply(codeBody, convert_code);
649
- var codeSection = [0x0a /* Code section code */];
650
- uleb128Encode(codeBody.length, codeSection);
651
- codeSection.push.apply(codeSection, codeBody);
652
- sections.push(codeSection);
653
-
654
- var bytes = new Uint8Array([].concat.apply([], sections));
655
- // We can compile this wasm module synchronously because it is small.
656
- var module = new WebAssembly.Module(bytes);
657
- var instance = new WebAssembly.Instance(module, {
658
- e: {
659
- r: getTempRet0,
660
- f: trampoline,
661
- },
662
- });
663
- return instance.exports.f;
664
- });
665
- #endif
666
-
667
440
  EM_JS_MACROS(
668
441
  ffi_status,
669
442
  ffi_prep_closure_loc_js,
@@ -759,9 +532,9 @@ ffi_prep_closure_loc_js,
759
532
  }
760
533
  if (nfixedargs < nargs) {
761
534
  // extra pointer to varargs stack
762
- sig += "i";
535
+ sig += 'i';
763
536
  }
764
- LOG_DEBUG("CREATE_CLOSURE", "sig:", sig);
537
+ LOG_DEBUG("CREATE_CLOSURE", "sig:", sig);
765
538
  function trampoline() {
766
539
  var args = Array.prototype.slice.call(arguments);
767
540
  var size = 0;
@@ -838,32 +611,14 @@ ffi_prep_closure_loc_js,
838
611
  case FFI_TYPE_SINT64:
839
612
  STACK_ALLOC(cur_ptr, 8, 8);
840
613
  DEREF_U32(args_ptr, carg_idx) = cur_ptr;
841
- #if WASM_BIGINT
842
614
  DEREF_U64(cur_ptr, 0) = cur_arg;
843
- #else
844
- // Bigint arg was split by legalizer adaptor
845
- DEREF_U32(cur_ptr, 0) = cur_arg;
846
- cur_arg = args[jsarg_idx++];
847
- DEREF_U32(cur_ptr, 1) = cur_arg;
848
- #endif
849
615
  break;
850
616
  case FFI_TYPE_LONGDOUBLE:
851
617
  STACK_ALLOC(cur_ptr, 16, 8);
852
618
  DEREF_U32(args_ptr, carg_idx) = cur_ptr;
853
- #if WASM_BIGINT
854
619
  DEREF_U64(cur_ptr, 0) = cur_arg;
855
620
  cur_arg = args[jsarg_idx++];
856
621
  DEREF_U64(cur_ptr, 1) = cur_arg;
857
- #else
858
- // Was split by legalizer adaptor
859
- DEREF_U32(cur_ptr, 0) = cur_arg;
860
- cur_arg = args[jsarg_idx++];
861
- DEREF_U32(cur_ptr, 1) = cur_arg;
862
- cur_arg = args[jsarg_idx++];
863
- DEREF_U32(cur_ptr, 2) = cur_arg;
864
- cur_arg = args[jsarg_idx++];
865
- DEREF_U32(cur_ptr, 3) = cur_arg;
866
- #endif
867
622
  break;
868
623
  }
869
624
  }
@@ -895,7 +650,7 @@ ffi_prep_closure_loc_js,
895
650
  }
896
651
  stackRestore(cur_ptr);
897
652
  stackAlloc(0); // stackAlloc enforces alignment invariants on the stack pointer
898
- LOG_DEBUG("CALL_CLOSURE", "closure:", closure, "fptr", CLOSURE__fun(closure), "cif", CLOSURE__cif(closure));
653
+ LOG_DEBUG("CALL_CLOSURE", "closure:", closure, "fptr", CLOSURE__fun(closure), "cif", CLOSURE__cif(closure));
899
654
  getWasmTableEntry(CLOSURE__fun(closure))(
900
655
  CLOSURE__cif(closure), ret_ptr, args_ptr,
901
656
  CLOSURE__user_data(closure)
@@ -905,26 +660,19 @@ ffi_prep_closure_loc_js,
905
660
  // If we aren't supposed to return by argument, figure out what to return.
906
661
  if (!ret_by_arg) {
907
662
  switch (sig[0]) {
908
- case "i":
663
+ case 'i':
909
664
  return DEREF_U32(ret_ptr, 0);
910
- case "j":
911
- #if WASM_BIGINT
665
+ case 'j':
912
666
  return DEREF_U64(ret_ptr, 0);
913
- #else
914
- // Split the return i64, set the upper 32 bits into tempRet0 and return
915
- // the lower 32 bits.
916
- setTempRet0(DEREF_U32(ret_ptr, 1));
917
- return DEREF_U32(ret_ptr, 0);
918
- #endif
919
- case "d":
667
+ case 'd':
920
668
  return DEREF_F64(ret_ptr, 0);
921
- case "f":
669
+ case 'f':
922
670
  return DEREF_F32(ret_ptr, 0);
923
671
  }
924
672
  }
925
673
  }
926
674
  try {
927
- var wasm_trampoline = JS_FUNCTION_TO_WASM(trampoline, sig);
675
+ var wasm_trampoline = convertJsFunctionToWasm(trampoline, sig);
928
676
  } catch(e) {
929
677
  return FFI_BAD_TYPEDEF_MACRO;
930
678
  }
@@ -118,7 +118,7 @@ ffi_prep_cif_machdep(ffi_cif *cif)
118
118
  break;
119
119
  case FFI_TYPE_STRUCT:
120
120
  {
121
- #ifdef X86_WIN32
121
+ #if defined(X86_WIN32) || defined(X86_DARWIN)
122
122
  size_t size = cif->rtype->size;
123
123
  if (size == 1)
124
124
  flags = X86_RET_STRUCT_1B;
@@ -270,6 +270,9 @@ extern void FFI_DECLARE_FASTCALL ffi_call_i386(struct call_frame *, char *) FFI_
270
270
  #if defined(_MSC_VER)
271
271
  #pragma runtime_checks("s", off)
272
272
  #endif
273
+ /* n.b. ffi_call_unix64 will steal the alloca'd `stack` variable here for use
274
+ _as its own stack_ - so we need to compile this function without ASAN */
275
+ FFI_ASAN_NO_SANITIZE
273
276
  static void
274
277
  ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
275
278
  void **avalue, void *closure)
@@ -557,6 +557,9 @@ ffi_prep_cif_machdep (ffi_cif *cif)
557
557
  return FFI_OK;
558
558
  }
559
559
 
560
+ /* n.b. ffi_call_unix64 will steal the alloca'd `stack` variable here for use
561
+ _as its own stack_ - so we need to compile this function without ASAN */
562
+ FFI_ASAN_NO_SANITIZE
560
563
  static void
561
564
  ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
562
565
  void **avalue, void *closure)
@@ -651,7 +654,7 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
651
654
  break;
652
655
  default:
653
656
  reg_args->gpr[gprcount] = 0;
654
- memcpy (&reg_args->gpr[gprcount], a, size);
657
+ memcpy (&reg_args->gpr[gprcount], a, size <= 8 ? size : 8);
655
658
  }
656
659
  gprcount++;
657
660
  break;
@@ -17,8 +17,8 @@ EXTRA_DIST = config/default.exp emscripten/build.sh emscripten/conftest.py \
17
17
  libffi.call/float1.c libffi.call/float2.c libffi.call/float3.c \
18
18
  libffi.call/float4.c libffi.call/float_va.c libffi.call/many.c \
19
19
  libffi.call/many2.c libffi.call/many_double.c libffi.call/many_mixed.c \
20
- libffi.call/negint.c libffi.call/offsets.c libffi.call/pr1172638.c \
21
- libffi.call/promotion.c libffi.call/pyobjc_tc.c libffi.call/return_dbl.c \
20
+ libffi.call/negint.c libffi.call/offsets.c libffi.call/overread.c \
21
+ libffi.call/pr1172638.c libffi.call/promotion.c libffi.call/pyobjc_tc.c libffi.call/return_dbl.c \
22
22
  libffi.call/return_dbl1.c libffi.call/return_dbl2.c libffi.call/return_fl.c \
23
23
  libffi.call/return_fl1.c libffi.call/return_fl2.c libffi.call/return_fl3.c \
24
24
  libffi.call/return_ldl.c libffi.call/return_ll.c libffi.call/return_ll1.c \
@@ -31,10 +31,11 @@ EXTRA_DIST = config/default.exp emscripten/build.sh emscripten/conftest.py \
31
31
  libffi.call/struct9.c libffi.call/struct_by_value_2.c libffi.call/struct_by_value_3.c \
32
32
  libffi.call/struct_by_value_3f.c libffi.call/struct_by_value_4.c libffi.call/struct_by_value_4f.c \
33
33
  libffi.call/struct_by_value_big.c libffi.call/struct_by_value_small.c libffi.call/struct_return_2H.c \
34
+ libffi.call/struct_int_float.c \
34
35
  libffi.call/struct_return_8H.c libffi.call/uninitialized.c libffi.call/va_1.c \
35
36
  libffi.call/va_2.c libffi.call/va_3.c libffi.call/va_struct1.c \
36
37
  libffi.call/va_struct2.c libffi.call/va_struct3.c libffi.call/callback.c \
37
- libffi.call/callback2.c libffi.call/callback3.c libffi.call/callback4.c \
38
+ libffi.call/callback2.c libffi.call/callback3.c libffi.call/callback4.c libffi.call/x32.c \
38
39
  libffi.closures/closure.exp libffi.closures/closure_fn0.c libffi.closures/closure_fn1.c \
39
40
  libffi.closures/closure_fn2.c libffi.closures/closure_fn3.c libffi.closures/closure_fn4.c \
40
41
  libffi.closures/closure_fn5.c libffi.closures/closure_fn6.c libffi.closures/closure_loc_fn0.c \
@@ -232,6 +232,7 @@ ac_ct_AR = @ac_ct_AR@
232
232
  ac_ct_CC = @ac_ct_CC@
233
233
  ac_ct_CXX = @ac_ct_CXX@
234
234
  ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
235
+ ac_ct_READELF = @ac_ct_READELF@
235
236
  am__include = @am__include@
236
237
  am__leading_dot = @am__leading_dot@
237
238
  am__quote = @am__quote@
@@ -301,8 +302,8 @@ EXTRA_DIST = config/default.exp emscripten/build.sh emscripten/conftest.py \
301
302
  libffi.call/float1.c libffi.call/float2.c libffi.call/float3.c \
302
303
  libffi.call/float4.c libffi.call/float_va.c libffi.call/many.c \
303
304
  libffi.call/many2.c libffi.call/many_double.c libffi.call/many_mixed.c \
304
- libffi.call/negint.c libffi.call/offsets.c libffi.call/pr1172638.c \
305
- libffi.call/promotion.c libffi.call/pyobjc_tc.c libffi.call/return_dbl.c \
305
+ libffi.call/negint.c libffi.call/offsets.c libffi.call/overread.c \
306
+ libffi.call/pr1172638.c libffi.call/promotion.c libffi.call/pyobjc_tc.c libffi.call/return_dbl.c \
306
307
  libffi.call/return_dbl1.c libffi.call/return_dbl2.c libffi.call/return_fl.c \
307
308
  libffi.call/return_fl1.c libffi.call/return_fl2.c libffi.call/return_fl3.c \
308
309
  libffi.call/return_ldl.c libffi.call/return_ll.c libffi.call/return_ll1.c \
@@ -315,10 +316,11 @@ EXTRA_DIST = config/default.exp emscripten/build.sh emscripten/conftest.py \
315
316
  libffi.call/struct9.c libffi.call/struct_by_value_2.c libffi.call/struct_by_value_3.c \
316
317
  libffi.call/struct_by_value_3f.c libffi.call/struct_by_value_4.c libffi.call/struct_by_value_4f.c \
317
318
  libffi.call/struct_by_value_big.c libffi.call/struct_by_value_small.c libffi.call/struct_return_2H.c \
319
+ libffi.call/struct_int_float.c \
318
320
  libffi.call/struct_return_8H.c libffi.call/uninitialized.c libffi.call/va_1.c \
319
321
  libffi.call/va_2.c libffi.call/va_3.c libffi.call/va_struct1.c \
320
322
  libffi.call/va_struct2.c libffi.call/va_struct3.c libffi.call/callback.c \
321
- libffi.call/callback2.c libffi.call/callback3.c libffi.call/callback4.c \
323
+ libffi.call/callback2.c libffi.call/callback3.c libffi.call/callback4.c libffi.call/x32.c \
322
324
  libffi.closures/closure.exp libffi.closures/closure_fn0.c libffi.closures/closure_fn1.c \
323
325
  libffi.closures/closure_fn2.c libffi.closures/closure_fn3.c libffi.closures/closure_fn4.c \
324
326
  libffi.closures/closure_fn5.c libffi.closures/closure_fn6.c libffi.closures/closure_loc_fn0.c \
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env bash
2
- emcc_exists="$(command -v emcc)"
3
- if [ ! "${emcc_exists}" ]; then
4
- echo "Emscripten not on path"
2
+
3
+ if ! [ -x "$(command -v emcc)" ]; then
4
+ echo "Error: emcc could not be found." >&2
5
5
  exit 1
6
6
  fi
7
7
 
@@ -10,19 +10,6 @@ set -e
10
10
  cd "$1"
11
11
  shift
12
12
 
13
- # Parse arguments
14
- while [ $# -gt 0 ]; do
15
- case $1 in
16
- --wasm-bigint) WASM_BIGINT=true ;;
17
- *)
18
- echo "ERROR: Unknown parameter: $1" >&2
19
- exit 1
20
- ;;
21
- esac
22
- shift
23
- done
24
-
25
-
26
13
  export CFLAGS="-fPIC -O2 -I../../target/include $EXTRA_CFLAGS"
27
14
  export CXXFLAGS="$CFLAGS -sNO_DISABLE_EXCEPTION_CATCHING $EXTRA_CXXFLAGS"
28
15
  export LDFLAGS=" \
@@ -31,17 +18,10 @@ export LDFLAGS=" \
31
18
  -sMODULARIZE \
32
19
  -sMAIN_MODULE \
33
20
  -sNO_DISABLE_EXCEPTION_CATCHING \
21
+ -sWASM_BIGINT \
34
22
  $EXTRA_LD_FLAGS \
35
23
  "
36
24
 
37
- # This needs to test false if there exists an environment variable called
38
- # WASM_BIGINT whose contents are empty. Don't use +x.
39
- if [ -n "${WASM_BIGINT}" ] ; then
40
- export LDFLAGS+=" -sWASM_BIGINT"
41
- else
42
- export LDFLAGS+=" -sEXPORTED_RUNTIME_METHODS='getTempRet0,setTempRet0'"
43
- fi
44
-
45
25
  # Rename main functions to test__filename so we can link them together
46
26
  ls *c | sed 's!\(.*\)\.c!sed -i "s/main/test__\1/g" \0!g' | bash
47
27
 
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env bash
2
- command -v emcc >/dev/null 2>&1 || {
3
- echo >&2 "emsdk could not be found. Aborting."
2
+
3
+ if ! [ -x "$(command -v emcc)" ]; then
4
+ echo "Error: emcc could not be found." >&2
4
5
  exit 1
5
- }
6
+ fi
6
7
 
7
8
  set -e
8
9
 
@@ -13,38 +14,20 @@ TARGET=$SOURCE_DIR/target
13
14
  mkdir -p "$TARGET"
14
15
 
15
16
  # Define default arguments
16
-
17
- # JS BigInt to Wasm i64 integration, disabled by default
18
- # This needs to test false if there exists an environment variable called
19
- # WASM_BIGINT whose contents are empty. Don't use +x.
20
- if [ -n "${WASM_BIGINT}" ]; then
21
- WASM_BIGINT=true
22
- else
23
- WASM_BIGINT=false
24
- fi
17
+ DEBUG=false
25
18
 
26
19
  # Parse arguments
27
20
  while [ $# -gt 0 ]; do
28
21
  case $1 in
29
- --wasm-bigint) WASM_BIGINT=true ;;
30
- --debug) DEBUG=true ;;
31
- *)
32
- echo "ERROR: Unknown parameter: $1" >&2
33
- exit 1
34
- ;;
22
+ --debug) DEBUG=true ;;
23
+ *) echo "ERROR: Unknown parameter: $1" >&2; exit 1 ;;
35
24
  esac
36
25
  shift
37
26
  done
38
27
 
39
28
  # Common compiler flags
40
29
  export CFLAGS="-O3 -fPIC"
41
- if [ "$WASM_BIGINT" = "true" ]; then
42
- # We need to detect WASM_BIGINT support at compile time
43
- export CFLAGS+=" -DWASM_BIGINT"
44
- fi
45
- if [ "$DEBUG" = "true" ]; then
46
- export CFLAGS+=" -DDEBUG_F"
47
- fi
30
+ if [ "$DEBUG" = "true" ]; then export CFLAGS+=" -DDEBUG_F"; fi
48
31
  export CXXFLAGS="$CFLAGS"
49
32
 
50
33
  # Build paths
@@ -1,39 +1,14 @@
1
1
  #!/bin/bash
2
2
 
3
- # JS BigInt to Wasm i64 integration, disabled by default
4
- WASM_BIGINT=false
5
-
6
- emcc_exists="$(command -v emcc)"
7
- if [ ! "${emcc_exists}" ]; then
8
- echo "Emscripten not on path"
3
+ if ! [ -x "$(command -v emcc)" ]; then
4
+ echo "Error: emcc could not be found." >&2
9
5
  exit 1
10
6
  fi
11
7
 
12
- # Parse arguments
13
- while [ $# -gt 0 ]; do
14
- case $1 in
15
- --wasm-bigint) WASM_BIGINT=true ;;
16
- *)
17
- echo "ERROR: Unknown parameter: $1" >&2
18
- exit 1
19
- ;;
20
- esac
21
- shift
22
- done
23
-
24
8
  # Common compiler flags
25
9
  export CFLAGS="-fPIC $EXTRA_CFLAGS"
26
- if [ "$WASM_BIGINT" = "true" ]; then
27
- # We need to detect WASM_BIGINT support at compile time
28
- export CFLAGS+=" -DWASM_BIGINT"
29
- fi
30
10
  export CXXFLAGS="$CFLAGS -sNO_DISABLE_EXCEPTION_CATCHING $EXTRA_CXXFLAGS"
31
- export LDFLAGS="-sEXPORTED_FUNCTIONS=_main,_malloc,_free -sALLOW_TABLE_GROWTH -sASSERTIONS -sNO_DISABLE_EXCEPTION_CATCHING"
32
- if [ "$WASM_BIGINT" = "true" ]; then
33
- export LDFLAGS+=" -sWASM_BIGINT"
34
- else
35
- export LDFLAGS+=" -sEXPORTED_RUNTIME_METHODS='getTempRet0,setTempRet0'"
36
- fi
11
+ export LDFLAGS="-sEXPORTED_FUNCTIONS=_main,_malloc,_free -sALLOW_TABLE_GROWTH -sASSERTIONS -sNO_DISABLE_EXCEPTION_CATCHING -sWASM_BIGINT"
37
12
 
38
13
  # Specific variables for cross-compilation
39
14
  export CHOST="wasm32-unknown-linux" # wasm32-unknown-emscripten
@@ -7,9 +7,9 @@
7
7
  /* { dg-do run } */
8
8
  #include "ffitest.h"
9
9
 
10
- int i=5;
10
+ static int i=5;
11
11
 
12
- void callback(void) { i++; }
12
+ static void callback(void) { i++; }
13
13
 
14
14
  typedef struct
15
15
  {
@@ -7,9 +7,9 @@
7
7
  /* { dg-do run } */
8
8
  #include "ffitest.h"
9
9
 
10
- int i=5;
10
+ static int i=5;
11
11
 
12
- void callback(void) { i++; }
12
+ static void callback(void) { i++; }
13
13
 
14
14
  typedef struct
15
15
  {
@@ -7,9 +7,9 @@
7
7
  /* { dg-do run } */
8
8
  #include "ffitest.h"
9
9
 
10
- int i=5;
10
+ static int i=5;
11
11
 
12
- void callback(void) { i++; }
12
+ static void callback(void) { i++; }
13
13
 
14
14
 
15
15
  typedef struct