koffi 1.3.12 → 2.0.0

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 (89) hide show
  1. package/CMakeLists.txt +7 -2
  2. package/ChangeLog.md +42 -16
  3. package/README.md +6 -0
  4. package/build/qemu/2.0.0/koffi_darwin_arm64.tar.gz +0 -0
  5. package/build/qemu/2.0.0/koffi_darwin_x64.tar.gz +0 -0
  6. package/build/qemu/2.0.0/koffi_freebsd_arm64.tar.gz +0 -0
  7. package/build/qemu/2.0.0/koffi_freebsd_ia32.tar.gz +0 -0
  8. package/build/qemu/2.0.0/koffi_freebsd_x64.tar.gz +0 -0
  9. package/build/qemu/2.0.0/koffi_linux_arm32hf.tar.gz +0 -0
  10. package/build/qemu/2.0.0/koffi_linux_arm64.tar.gz +0 -0
  11. package/build/qemu/2.0.0/koffi_linux_ia32.tar.gz +0 -0
  12. package/build/qemu/2.0.0/koffi_linux_riscv64hf64.tar.gz +0 -0
  13. package/build/qemu/2.0.0/koffi_linux_x64.tar.gz +0 -0
  14. package/build/qemu/2.0.0/koffi_openbsd_ia32.tar.gz +0 -0
  15. package/build/qemu/2.0.0/koffi_openbsd_x64.tar.gz +0 -0
  16. package/build/qemu/2.0.0/koffi_win32_arm64.tar.gz +0 -0
  17. package/build/qemu/2.0.0/koffi_win32_ia32.tar.gz +0 -0
  18. package/build/qemu/2.0.0/koffi_win32_x64.tar.gz +0 -0
  19. package/doc/benchmarks.md +2 -2
  20. package/doc/changes.md +156 -1
  21. package/doc/contribute.md +0 -1
  22. package/doc/dist/doctrees/changes.doctree +0 -0
  23. package/doc/dist/doctrees/environment.pickle +0 -0
  24. package/doc/dist/doctrees/functions.doctree +0 -0
  25. package/doc/dist/doctrees/types.doctree +0 -0
  26. package/doc/dist/html/_sources/changes.md.txt +156 -1
  27. package/doc/dist/html/_sources/functions.md.txt +8 -4
  28. package/doc/dist/html/_sources/types.md.txt +9 -0
  29. package/doc/dist/html/benchmarks.html +1 -1
  30. package/doc/dist/html/changes.html +226 -14
  31. package/doc/dist/html/contribute.html +1 -1
  32. package/doc/dist/html/functions.html +15 -12
  33. package/doc/dist/html/genindex.html +1 -1
  34. package/doc/dist/html/index.html +6 -16
  35. package/doc/dist/html/memory.html +3 -3
  36. package/doc/dist/html/objects.inv +0 -0
  37. package/doc/dist/html/platforms.html +1 -1
  38. package/doc/dist/html/search.html +1 -1
  39. package/doc/dist/html/searchindex.js +1 -1
  40. package/doc/dist/html/start.html +1 -1
  41. package/doc/dist/html/types.html +11 -3
  42. package/doc/functions.md +137 -13
  43. package/doc/types.md +35 -10
  44. package/package.json +1 -1
  45. package/qemu/registry/machines.json +5 -5
  46. package/qemu/registry/sha256sum.txt +16 -16
  47. package/src/abi_arm32.cc +90 -18
  48. package/src/abi_arm32_fwd.S +121 -57
  49. package/src/abi_arm64.cc +90 -18
  50. package/src/abi_arm64_fwd.S +96 -0
  51. package/src/abi_arm64_fwd.asm +128 -0
  52. package/src/abi_riscv64.cc +88 -18
  53. package/src/abi_riscv64_fwd.S +96 -0
  54. package/src/abi_x64_sysv.cc +93 -21
  55. package/src/abi_x64_sysv_fwd.S +96 -0
  56. package/src/abi_x64_win.cc +88 -18
  57. package/src/abi_x64_win_fwd.asm +128 -0
  58. package/src/abi_x86.cc +93 -18
  59. package/src/abi_x86_fwd.S +96 -0
  60. package/src/abi_x86_fwd.asm +128 -0
  61. package/src/call.cc +97 -63
  62. package/src/call.hh +2 -1
  63. package/src/ffi.cc +452 -140
  64. package/src/ffi.hh +23 -9
  65. package/src/parser.cc +18 -41
  66. package/src/util.cc +117 -27
  67. package/src/util.hh +3 -2
  68. package/test/callbacks.js +54 -8
  69. package/test/misc.c +29 -14
  70. package/test/raylib.js +1 -1
  71. package/test/sqlite.js +24 -16
  72. package/test/sync.js +41 -31
  73. package/vendor/libcc/libcc.cc +18 -5
  74. package/vendor/libcc/libcc.hh +70 -23
  75. package/build/qemu/1.3.12/koffi_darwin_arm64.tar.gz +0 -0
  76. package/build/qemu/1.3.12/koffi_darwin_x64.tar.gz +0 -0
  77. package/build/qemu/1.3.12/koffi_freebsd_arm64.tar.gz +0 -0
  78. package/build/qemu/1.3.12/koffi_freebsd_ia32.tar.gz +0 -0
  79. package/build/qemu/1.3.12/koffi_freebsd_x64.tar.gz +0 -0
  80. package/build/qemu/1.3.12/koffi_linux_arm32hf.tar.gz +0 -0
  81. package/build/qemu/1.3.12/koffi_linux_arm64.tar.gz +0 -0
  82. package/build/qemu/1.3.12/koffi_linux_ia32.tar.gz +0 -0
  83. package/build/qemu/1.3.12/koffi_linux_riscv64hf64.tar.gz +0 -0
  84. package/build/qemu/1.3.12/koffi_linux_x64.tar.gz +0 -0
  85. package/build/qemu/1.3.12/koffi_openbsd_ia32.tar.gz +0 -0
  86. package/build/qemu/1.3.12/koffi_openbsd_x64.tar.gz +0 -0
  87. package/build/qemu/1.3.12/koffi_win32_arm64.tar.gz +0 -0
  88. package/build/qemu/1.3.12/koffi_win32_ia32.tar.gz +0 -0
  89. package/build/qemu/1.3.12/koffi_win32_x64.tar.gz +0 -0
@@ -247,7 +247,7 @@
247
247
  "qemu": {
248
248
  "binary": "qemu-system-x86_64",
249
249
  "arguments": ["-m", "1G", "-smp", 2, "-hda", "disk.qcow2", "-netdev", "user,id=mynet,hostfwd=tcp::22206-:22", "-device", "e1000,netdev=mynet", "-vnc", "127.0.0.1:16"],
250
- "version": 2,
250
+ "version": 3,
251
251
 
252
252
  "ssh_port": 22206,
253
253
  "vnc_port": 5916,
@@ -290,7 +290,7 @@
290
290
  "qemu": {
291
291
  "binary": "qemu-system-i386",
292
292
  "arguments": ["-m", "1G", "-smp", 2, "-hda", "disk.qcow2", "-netdev", "user,id=mynet,hostfwd=tcp::22207-:22", "-device", "e1000,netdev=mynet", "-vnc", "127.0.0.1:17"],
293
- "version": 2,
293
+ "version": 3,
294
294
 
295
295
  "ssh_port": 22207,
296
296
  "vnc_port": 5917,
@@ -333,7 +333,7 @@
333
333
  "qemu": {
334
334
  "binary": "qemu-system-aarch64",
335
335
  "arguments": ["-M", "virt", "-cpu", "cortex-a53", "-m", "1G", "-smp", 2, "-drive", "if=pflash,format=raw,file=QEMU_EFI.img", "-drive", "if=pflash,file=varstore.img", "-drive", "if=virtio,file=disk.qcow2,format=qcow2", "-netdev", "user,id=mynet,hostfwd=tcp::22208-:22", "-device", "virtio-net-device,netdev=mynet", "-vnc", "127.0.0.1:18"],
336
- "version": 2,
336
+ "version": 3,
337
337
 
338
338
  "ssh_port": 22208,
339
339
  "vnc_port": 5918,
@@ -424,7 +424,7 @@
424
424
  "qemu": {
425
425
  "binary": "qemu-system-x86_64",
426
426
  "arguments": ["-m", "1G", "-smp", 2, "-hda", "disk.qcow2", "-netdev", "user,id=mynet,hostfwd=tcp::22210-:22", "-device", "e1000,netdev=mynet", "-vnc", "127.0.0.1:20"],
427
- "version": 1,
427
+ "version": 2,
428
428
 
429
429
  "ssh_port": 22210,
430
430
  "vnc_port": 5920,
@@ -467,7 +467,7 @@
467
467
  "qemu": {
468
468
  "binary": "qemu-system-x86_64",
469
469
  "arguments": ["-m", "1G", "-smp", 2, "-hda", "disk.qcow2", "-netdev", "user,id=mynet,hostfwd=tcp::22211-:22", "-device", "e1000,netdev=mynet", "-vnc", "127.0.0.1:21"],
470
- "version": 2,
470
+ "version": 3,
471
471
 
472
472
  "ssh_port": 22211,
473
473
  "vnc_port": 5921,
@@ -22,20 +22,20 @@ ed05b84b7759ec945bb5422305a3a3c5b61d89e231844656ea31e07d89451a20 *qemu/debian_i3
22
22
  292a61c415a99a9c63a9337f1e074bea6c5df594e16bc40ded76141963c67ea4 *qemu/debian_i386/install.sh
23
23
  8dc1360e1c23ea21931f5eb94461d15fac6bcec00cf42bf1e590b7fb937e80c1 *qemu/debian_i386/initrd.img-5.10.0-12-686-pae
24
24
  338602d969f953cd88c2df736b9f8f7ee53029d233c83c7398258ae5bcb4e286 *qemu/debian_i386/disk.qcow2
25
- e5d9d3e1e4a5c980fce4ef3aab5e29b9607b8e5da6e9fe58c3f396009e283cff *qemu/freebsd_arm64/disk.qcow2
25
+ 1377fe08689438369e1c87b30f0b795e6e001b87f3b04a9bad46ddc8883ea9c7 *qemu/freebsd_arm64/disk.qcow2
26
26
  53a4dc48317e1c9de4a088cd45ba39a1810f0bafad75c7f810e18d4e3eb340e3 *qemu/freebsd_arm64/install.sh
27
27
  5daea533330eb8d2f8df946561680e09f8dacc467fbf03d28caa2115d94386b5 *qemu/freebsd_arm64/QEMU_EFI.img
28
- 8ac20d46117a5a15761bf3070e365141b96ee3283250824f113029e106c62a50 *qemu/freebsd_arm64/varstore.img
29
- d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35 *qemu/freebsd_arm64/VERSION
30
- 73837b3991eae13f6c346955ea4aa419c8c168cadf70e0a38446db60cf47b0e9 *qemu/freebsd_arm64/xvfb-run.sh
31
- fd0e51c43d7848564a81ddcb3eecf49103251bffcf25315ef87db01350ad4ac5 *qemu/freebsd_i386/disk.qcow2
28
+ 84766bab993aad040c76b24a0dfff7504af8585875d98065b97a5ad4c056c3c7 *qemu/freebsd_arm64/varstore.img
29
+ 4e07408562bedb8b60ce05c1decfe3ad16b72230967de01f640b7e4729b49fce *qemu/freebsd_arm64/VERSION
30
+ 3595d98051dba496053b23605ad9475836b89ca92e5e97d1b0af1233f0aa4295 *qemu/freebsd_arm64/xvfb-run.sh
31
+ c3370eb6a641e2fd4882580ee0d23abfbc7cde828378f74d20ab7872c008de2c *qemu/freebsd_i386/disk.qcow2
32
32
  bdeac2cca1d22d70c2d388a50709d5cba3069bbd4bd1bcb102955b0ee12ca3e9 *qemu/freebsd_i386/install.sh
33
- d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35 *qemu/freebsd_i386/VERSION
34
- 73837b3991eae13f6c346955ea4aa419c8c168cadf70e0a38446db60cf47b0e9 *qemu/freebsd_i386/xvfb-run.sh
35
- 41649d2f5959388e1c5d8ee89bb084795470a8b9e68d87861b4e95e4102b62cf *qemu/freebsd_x64/disk.qcow2
33
+ 4e07408562bedb8b60ce05c1decfe3ad16b72230967de01f640b7e4729b49fce *qemu/freebsd_i386/VERSION
34
+ 3595d98051dba496053b23605ad9475836b89ca92e5e97d1b0af1233f0aa4295 *qemu/freebsd_i386/xvfb-run.sh
35
+ 16b2be6321f02761e200a336d301f39ad628b6c310d893387916dcc902536833 *qemu/freebsd_x64/disk.qcow2
36
36
  06eef544fe9c61d3905b0e588c306d1dedac7ee7d4c01df154ff6ed64e25ef77 *qemu/freebsd_x64/install.sh
37
- d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35 *qemu/freebsd_x64/VERSION
38
- 73837b3991eae13f6c346955ea4aa419c8c168cadf70e0a38446db60cf47b0e9 *qemu/freebsd_x64/xvfb-run.sh
37
+ 4e07408562bedb8b60ce05c1decfe3ad16b72230967de01f640b7e4729b49fce *qemu/freebsd_x64/VERSION
38
+ 3595d98051dba496053b23605ad9475836b89ca92e5e97d1b0af1233f0aa4295 *qemu/freebsd_x64/xvfb-run.sh
39
39
  16a4f09b3e70b97f5cfb1cf9b913d67d0ec45c4342d202cc9a2b2cfee852a8de *qemu/macos_x64/ESP.qcow2
40
40
  5d2ac383371b408398accee7ec27c8c09ea5b74a0de0ceea6513388b15be5d1e *qemu/macos_x64/OVMF_VARS.fd
41
41
  d79538ac489f1948b04b65f12c5618c28e4a5de0be062f5cf1d73e422a091a37 *qemu/macos_x64/install.txt
@@ -43,14 +43,14 @@ d79538ac489f1948b04b65f12c5618c28e4a5de0be062f5cf1d73e422a091a37 *qemu/macos_x64
43
43
  5cc2d42949c7e4e763db0abeb88299972bafef991d87dbf744a5108ef9190f6f *qemu/macos_x64/OVMF_VARS-1024x768.fd
44
44
  53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3 *qemu/macos_x64/VERSION
45
45
  2a247500e8ad9aa479994097ba5976bd881fde4de1516abd14491f3dba9fe060 *qemu/macos_x64/OVMF_CODE.fd
46
- 3a3395f70240d8e3137dfe06ef7dd76255dc597626e087d33abdcc65710f3dff *qemu/openbsd_x64/disk.qcow2
46
+ c5bd8e76008f12a96fb05baf6e0b160be68a9d95451f1a7b1557902ea558b6b5 *qemu/openbsd_x64/disk.qcow2
47
47
  9dcdabfc12ad2ba2da1b9c3d95dc46311a12d6e3190f1bfd0c9b184ac1577c94 *qemu/openbsd_x64/install.sh
48
- 6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b *qemu/openbsd_x64/VERSION
49
- 7b66bdf8b77fd1c6256ffdab623e37ce099797ad657dcd25af5df0486fadce37 *qemu/openbsd_x64/xvfb-run.sh
50
- 3bef620f4c1050533c3c1bd62721f9617511a6791784fd641426a45fec289b07 *qemu/openbsd_i386/disk.qcow2
48
+ d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35 *qemu/openbsd_x64/VERSION
49
+ 80780df11a9cebbc012bb170bb5808b5970da074ff5b73f71c35ec2d5354fea9 *qemu/openbsd_x64/xvfb-run.sh
50
+ b124423055c572f8ee6d4fc918624d0f7d023796b26cd5dadf57c82fff141033 *qemu/openbsd_i386/disk.qcow2
51
51
  691ce78bb8a08f90903aec679017028fedd567b37bc7b4aa132baa083a7c1edd *qemu/openbsd_i386/install.sh
52
- d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35 *qemu/openbsd_i386/VERSION
53
- 7b66bdf8b77fd1c6256ffdab623e37ce099797ad657dcd25af5df0486fadce37 *qemu/openbsd_i386/xvfb-run.sh
52
+ 4e07408562bedb8b60ce05c1decfe3ad16b72230967de01f640b7e4729b49fce *qemu/openbsd_i386/VERSION
53
+ 80780df11a9cebbc012bb170bb5808b5970da074ff5b73f71c35ec2d5354fea9 *qemu/openbsd_i386/xvfb-run.sh
54
54
  64048432020bda960f397b5a138ea98aa6bbd42db02e8bb34ff3b9320763e36d *qemu/debian_riscv64/uboot.elf
55
55
  0bdd93879f87c338d62422a65fdcba4d8c834848f2305f31b916539cb523e9e8 *qemu/debian_riscv64/readme.txt
56
56
  76a5819cdacc8fe284370f441820620e911877122068a3b391fa064b7e9eb180 *qemu/debian_riscv64/initrd
package/src/abi_arm32.cc CHANGED
@@ -64,6 +64,22 @@ extern "C" int Trampoline12; extern "C" int TrampolineX12;
64
64
  extern "C" int Trampoline13; extern "C" int TrampolineX13;
65
65
  extern "C" int Trampoline14; extern "C" int TrampolineX14;
66
66
  extern "C" int Trampoline15; extern "C" int TrampolineX15;
67
+ extern "C" int Trampoline16; extern "C" int TrampolineX16;
68
+ extern "C" int Trampoline17; extern "C" int TrampolineX17;
69
+ extern "C" int Trampoline18; extern "C" int TrampolineX18;
70
+ extern "C" int Trampoline19; extern "C" int TrampolineX19;
71
+ extern "C" int Trampoline20; extern "C" int TrampolineX20;
72
+ extern "C" int Trampoline21; extern "C" int TrampolineX21;
73
+ extern "C" int Trampoline22; extern "C" int TrampolineX22;
74
+ extern "C" int Trampoline23; extern "C" int TrampolineX23;
75
+ extern "C" int Trampoline24; extern "C" int TrampolineX24;
76
+ extern "C" int Trampoline25; extern "C" int TrampolineX25;
77
+ extern "C" int Trampoline26; extern "C" int TrampolineX26;
78
+ extern "C" int Trampoline27; extern "C" int TrampolineX27;
79
+ extern "C" int Trampoline28; extern "C" int TrampolineX28;
80
+ extern "C" int Trampoline29; extern "C" int TrampolineX29;
81
+ extern "C" int Trampoline30; extern "C" int TrampolineX30;
82
+ extern "C" int Trampoline31; extern "C" int TrampolineX31;
67
83
 
68
84
  extern "C" napi_value CallSwitchStack(Napi::Function *func, size_t argc, napi_value *argv,
69
85
  uint8_t *old_sp, Span<uint8_t> *new_stack,
@@ -85,9 +101,25 @@ static void *const Trampolines[][2] = {
85
101
  { &Trampoline12, &TrampolineX12 },
86
102
  { &Trampoline13, &TrampolineX13 },
87
103
  { &Trampoline14, &TrampolineX14 },
88
- { &Trampoline15, &TrampolineX15 }
104
+ { &Trampoline15, &TrampolineX15 },
105
+ { &Trampoline16, &TrampolineX16 },
106
+ { &Trampoline17, &TrampolineX17 },
107
+ { &Trampoline18, &TrampolineX18 },
108
+ { &Trampoline19, &TrampolineX19 },
109
+ { &Trampoline20, &TrampolineX20 },
110
+ { &Trampoline21, &TrampolineX21 },
111
+ { &Trampoline22, &TrampolineX22 },
112
+ { &Trampoline23, &TrampolineX23 },
113
+ { &Trampoline24, &TrampolineX24 },
114
+ { &Trampoline25, &TrampolineX25 },
115
+ { &Trampoline26, &TrampolineX26 },
116
+ { &Trampoline27, &TrampolineX27 },
117
+ { &Trampoline28, &TrampolineX28 },
118
+ { &Trampoline29, &TrampolineX29 },
119
+ { &Trampoline30, &TrampolineX30 },
120
+ { &Trampoline31, &TrampolineX31 }
89
121
  };
90
- RG_STATIC_ASSERT(RG_LEN(Trampolines) == MaxTrampolines);
122
+ RG_STATIC_ASSERT(RG_LEN(Trampolines) == MaxTrampolines * 2);
91
123
 
92
124
  static RG_THREAD_LOCAL CallData *exec_call;
93
125
 
@@ -204,6 +236,8 @@ bool AnalyseFunction(Napi::Env, InstanceData *, FunctionInfo *func)
204
236
  }
205
237
  }
206
238
  } break;
239
+
240
+ case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
207
241
  }
208
242
 
209
243
  func->args_size += AlignLen(param.type->size, 16);
@@ -425,10 +459,10 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
425
459
  if (value.IsFunction()) {
426
460
  Napi::Function func = value.As<Napi::Function>();
427
461
 
428
- ptr = ReserveTrampoline(param.type->proto, func);
462
+ ptr = ReserveTrampoline(param.type->ref.proto, func);
429
463
  if (RG_UNLIKELY(!ptr))
430
464
  return false;
431
- } else if (CheckValueTag(instance, value, param.type)) {
465
+ } else if (CheckValueTag(instance, value, param.type->ref.marker)) {
432
466
  ptr = value.As<Napi::External<void>>().Data();
433
467
  } else if (IsNullOrUndefined(value)) {
434
468
  ptr = nullptr;
@@ -439,6 +473,8 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
439
473
 
440
474
  *(void **)((param.gpr_count ? gpr_ptr : args_ptr)++) = ptr;
441
475
  } break;
476
+
477
+ case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
442
478
  }
443
479
  }
444
480
 
@@ -485,6 +521,8 @@ void CallData::Execute()
485
521
  case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
486
522
  case PrimitiveKind::Float32: { result.f = PERFORM_CALL(F); } break;
487
523
  case PrimitiveKind::Float64: { result.d = PERFORM_CALL(DDDD).d0; } break;
524
+
525
+ case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
488
526
  }
489
527
 
490
528
  #undef PERFORM_CALL
@@ -492,7 +530,13 @@ void CallData::Execute()
492
530
 
493
531
  Napi::Value CallData::Complete()
494
532
  {
495
- PopOutArguments();
533
+ RG_DEFER {
534
+ PopOutArguments();
535
+
536
+ if (func->ret.type->dispose) {
537
+ func->ret.type->dispose(env, func->ret.type, result.ptr);
538
+ }
539
+ };
496
540
 
497
541
  switch (func->ret.type->primitive) {
498
542
  case PrimitiveKind::Void: return env.Null();
@@ -511,7 +555,7 @@ Napi::Value CallData::Complete()
511
555
  case PrimitiveKind::Callback: {
512
556
  if (result.ptr) {
513
557
  Napi::External<void> external = Napi::External<void>::New(env, result.ptr);
514
- SetValueTag(instance, external, func->ret.type);
558
+ SetValueTag(instance, external, func->ret.type->ref.marker);
515
559
 
516
560
  return external;
517
561
  } else {
@@ -528,6 +572,8 @@ Napi::Value CallData::Complete()
528
572
  case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
529
573
  case PrimitiveKind::Float32: return Napi::Number::New(env, (double)result.f);
530
574
  case PrimitiveKind::Float64: return Napi::Number::New(env, result.d);
575
+
576
+ case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
531
577
  }
532
578
 
533
579
  RG_UNREACHABLE();
@@ -535,12 +581,10 @@ Napi::Value CallData::Complete()
535
581
 
536
582
  void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegisters *out_reg)
537
583
  {
538
- const TrampolineInfo &trampoline = instance->trampolines[idx];
539
-
540
- if (RG_UNLIKELY(trampoline.generation != mem->generation)) {
541
- ThrowError<Napi::Error>(env, "Cannot use non-persistent callback beyond FFI call");
584
+ if (RG_UNLIKELY(env.IsExceptionPending()))
542
585
  return;
543
- }
586
+
587
+ const TrampolineInfo &trampoline = instance->trampolines[idx];
544
588
 
545
589
  const FunctionInfo *proto = trampoline.proto;
546
590
  Napi::Function func = trampoline.func.Value();
@@ -552,6 +596,13 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
552
596
  uint8_t *return_ptr = proto->ret.use_memory ? (uint8_t *)gpr_ptr[0] : nullptr;
553
597
  gpr_ptr += proto->ret.use_memory;
554
598
 
599
+ RG_DEFER_N(err_guard) { memset(out_reg, 0, RG_SIZE(*out_reg)); };
600
+
601
+ if (RG_UNLIKELY(trampoline.generation >= 0 && trampoline.generation != (int32_t)mem->generation)) {
602
+ ThrowError<Napi::Error>(env, "Cannot use non-registered callback beyond FFI call");
603
+ return;
604
+ }
605
+
555
606
  LocalArray<napi_value, MaxParameters> arguments;
556
607
 
557
608
  // Convert to JS arguments
@@ -627,12 +678,20 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
627
678
 
628
679
  Napi::Value arg = str ? Napi::String::New(env, str) : env.Null();
629
680
  arguments.Append(arg);
681
+
682
+ if (param.type->dispose) {
683
+ param.type->dispose(env, param.type, str);
684
+ }
630
685
  } break;
631
686
  case PrimitiveKind::String16: {
632
687
  const char16_t *str16 = *(const char16_t **)((param.gpr_count ? gpr_ptr : args_ptr)++);
633
688
 
634
689
  Napi::Value arg = str16 ? Napi::String::New(env, str16) : env.Null();
635
690
  arguments.Append(arg);
691
+
692
+ if (param.type->dispose) {
693
+ param.type->dispose(env, param.type, str16);
694
+ }
636
695
  } break;
637
696
  case PrimitiveKind::Pointer:
638
697
  case PrimitiveKind::Callback: {
@@ -640,12 +699,16 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
640
699
 
641
700
  if (ptr2) {
642
701
  Napi::External<void> external = Napi::External<void>::New(env, ptr2);
643
- SetValueTag(instance, external, param.type);
702
+ SetValueTag(instance, external, param.type->ref.marker);
644
703
 
645
704
  arguments.Append(external);
646
705
  } else {
647
706
  arguments.Append(env.Null());
648
707
  }
708
+
709
+ if (param.type->dispose) {
710
+ param.type->dispose(env, param.type, ptr2);
711
+ }
649
712
  } break;
650
713
  case PrimitiveKind::Record: {
651
714
  if (param.vec_count) {
@@ -721,6 +784,8 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
721
784
  Napi::Value arg = Napi::Number::New(env, d);
722
785
  arguments.Append(arg);
723
786
  } break;
787
+
788
+ case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
724
789
  }
725
790
  }
726
791
 
@@ -731,6 +796,9 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
731
796
  [](Napi::Function *func, size_t argc, napi_value *argv) { return (napi_value)func->Call(argc, argv); });
732
797
  Napi::Value value(env, ret);
733
798
 
799
+ if (RG_UNLIKELY(env.IsExceptionPending()))
800
+ return;
801
+
734
802
  // Convert the result
735
803
  switch (type->primitive) {
736
804
  case PrimitiveKind::Void: {} break;
@@ -818,14 +886,14 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
818
886
  case PrimitiveKind::Pointer: {
819
887
  uint8_t *ptr;
820
888
 
821
- if (CheckValueTag(instance, value, type)) {
889
+ if (CheckValueTag(instance, value, type->ref.marker)) {
822
890
  ptr = value.As<Napi::External<uint8_t>>().Data();
823
- } else if (IsObject(value) && type->ref->primitive == PrimitiveKind::Record) {
891
+ } else if (IsObject(value) && type->ref.type->primitive == PrimitiveKind::Record) {
824
892
  Napi::Object obj = value.As<Napi::Object>();
825
893
 
826
- ptr = AllocHeap(type->ref->size, 16);
894
+ ptr = AllocHeap(type->ref.type->size, 16);
827
895
 
828
- if (!PushObject(obj, type->ref, ptr))
896
+ if (!PushObject(obj, type->ref.type, ptr))
829
897
  return;
830
898
  } else if (IsNullOrUndefined(value)) {
831
899
  ptr = nullptr;
@@ -887,10 +955,10 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
887
955
  if (value.IsFunction()) {
888
956
  Napi::Function func2 = value.As<Napi::Function>();
889
957
 
890
- ptr = ReserveTrampoline(type->proto, func2);
958
+ ptr = ReserveTrampoline(type->ref.proto, func2);
891
959
  if (RG_UNLIKELY(!ptr))
892
960
  return;
893
- } else if (CheckValueTag(instance, value, type)) {
961
+ } else if (CheckValueTag(instance, value, type->ref.marker)) {
894
962
  ptr = value.As<Napi::External<uint8_t>>().Data();
895
963
  } else if (IsNullOrUndefined(value)) {
896
964
  ptr = nullptr;
@@ -901,7 +969,11 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
901
969
 
902
970
  out_reg->r0 = (uint32_t)ptr;
903
971
  } break;
972
+
973
+ case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
904
974
  }
975
+
976
+ err_guard.Disable();
905
977
  }
906
978
 
907
979
  void *GetTrampoline(Size idx, const FunctionInfo *proto)
@@ -56,57 +56,40 @@
56
56
  .cfi_endproc
57
57
  .endm
58
58
 
59
- # Prepare general purpose argument registers from array passed by caller.
60
- .macro forward_gpr
61
- ldr r3, [r1, 76]
62
- ldr r2, [r1, 72]
63
- ldr r0, [r1, 64]
64
- ldr r1, [r1, 68]
65
- .endm
66
-
67
- # Prepare vector argument registers from array passed by caller.
68
- .macro forward_vec
69
- vldr d7, [r1, 56]
70
- vldr d6, [r1, 48]
71
- vldr d5, [r1, 40]
72
- vldr d4, [r1, 32]
73
- vldr d3, [r1, 24]
74
- vldr d2, [r1, 16]
75
- vldr d1, [r1, 8]
76
- vldr d0, [r1, 0]
77
- .endm
78
-
79
59
  ForwardCallGG:
80
60
  prologue
81
- forward_gpr
61
+ add r1, r1, #64
62
+ ldmia r1, {r0-r3}
82
63
  epilogue
83
64
 
84
65
  ForwardCallF:
85
66
  prologue
86
- forward_gpr
67
+ add r1, r1, #64
68
+ ldmia r1, {r0-r3}
87
69
  epilogue
88
70
 
89
71
  ForwardCallDDDD:
90
72
  prologue
91
- forward_gpr
73
+ add r1, r1, #64
74
+ ldmia r1, {r0-r3}
92
75
  epilogue
93
76
 
94
77
  ForwardCallXGG:
95
78
  prologue
96
- forward_vec
97
- forward_gpr
79
+ vldmia r1!, {d0-d7}
80
+ ldmia r1, {r0-r3}
98
81
  epilogue
99
82
 
100
83
  ForwardCallXF:
101
84
  prologue
102
- forward_vec
103
- forward_gpr
85
+ vldmia r1!, {d0-d7}
86
+ ldmia r1, {r0-r3}
104
87
  epilogue
105
88
 
106
89
  ForwardCallXDDDD:
107
90
  prologue
108
- forward_vec
109
- forward_gpr
91
+ vldmia r1!, {d0-d7}
92
+ ldmia r1, {r0-r3}
110
93
  epilogue
111
94
 
112
95
  # Callback trampolines
@@ -128,6 +111,22 @@ ForwardCallXDDDD:
128
111
  .global Trampoline13
129
112
  .global Trampoline14
130
113
  .global Trampoline15
114
+ .global Trampoline16
115
+ .global Trampoline17
116
+ .global Trampoline18
117
+ .global Trampoline19
118
+ .global Trampoline20
119
+ .global Trampoline21
120
+ .global Trampoline22
121
+ .global Trampoline23
122
+ .global Trampoline24
123
+ .global Trampoline25
124
+ .global Trampoline26
125
+ .global Trampoline27
126
+ .global Trampoline28
127
+ .global Trampoline29
128
+ .global Trampoline30
129
+ .global Trampoline31
131
130
  .global TrampolineX0
132
131
  .global TrampolineX1
133
132
  .global TrampolineX2
@@ -144,6 +143,22 @@ ForwardCallXDDDD:
144
143
  .global TrampolineX13
145
144
  .global TrampolineX14
146
145
  .global TrampolineX15
146
+ .global TrampolineX16
147
+ .global TrampolineX17
148
+ .global TrampolineX18
149
+ .global TrampolineX19
150
+ .global TrampolineX20
151
+ .global TrampolineX21
152
+ .global TrampolineX22
153
+ .global TrampolineX23
154
+ .global TrampolineX24
155
+ .global TrampolineX25
156
+ .global TrampolineX26
157
+ .global TrampolineX27
158
+ .global TrampolineX28
159
+ .global TrampolineX29
160
+ .global TrampolineX30
161
+ .global TrampolineX31
147
162
  .global RelayCallback
148
163
  .global CallSwitchStack
149
164
 
@@ -160,18 +175,16 @@ ForwardCallXDDDD:
160
175
  .cfi_offset 14, 8
161
176
  sub sp, sp, #120
162
177
  .cfi_def_cfa sp, 128
163
- str r0, [sp, 64]
164
- str r1, [sp, 68]
165
- str r2, [sp, 72]
166
- str r3, [sp, 76]
178
+ add r12, sp, 64
179
+ stmia r12!, {r0-r3}
167
180
  mov r0, \id
168
181
  mov r1, sp
169
182
  add r2, sp, #128
170
- add r3, sp, #80
183
+ mov r3, r12
171
184
  bl RelayCallback
172
- ldr r0, [sp, 80]
173
- ldr r1, [sp, 84]
174
- add sp, sp, #120
185
+ add sp, sp, #80
186
+ ldmia sp!, {r0-r1}
187
+ add sp, sp, #32
175
188
  .cfi_def_cfa sp, 8
176
189
  pop {fp, lr}
177
190
  .cfi_def_cfa sp, 0
@@ -190,30 +203,17 @@ ForwardCallXDDDD:
190
203
  .cfi_offset 14, 8
191
204
  sub sp, sp, #120
192
205
  .cfi_def_cfa sp, 128
193
- str r0, [sp, 64]
194
- str r1, [sp, 68]
195
- str r2, [sp, 72]
196
- str r3, [sp, 76]
197
- vstr d0, [sp, 0]
198
- vstr d1, [sp, 8]
199
- vstr d2, [sp, 16]
200
- vstr d3, [sp, 24]
201
- vstr d4, [sp, 32]
202
- vstr d5, [sp, 40]
203
- vstr d6, [sp, 48]
204
- vstr d7, [sp, 56]
206
+ mov r12, sp
207
+ vstmia r12!, {d0-d7}
208
+ stmia r12!, {r0-r3}
205
209
  mov r0, \id
206
210
  mov r1, sp
207
211
  add r2, sp, #128
208
- add r3, sp, #80
212
+ mov r3, r12
209
213
  bl RelayCallback
210
- ldr r0, [sp, 80]
211
- ldr r1, [sp, 84]
212
- vldr d0, [sp, 88]
213
- vldr d1, [sp, 96]
214
- vldr d2, [sp, 104]
215
- vldr d3, [sp, 112]
216
- add sp, sp, #120
214
+ add sp, sp, #80
215
+ ldmia sp!, {r0-r1}
216
+ vldmia sp!, {d0-d3}
217
217
  .cfi_def_cfa sp, 8
218
218
  pop {fp, lr}
219
219
  .cfi_def_cfa sp, 0
@@ -255,6 +255,38 @@ Trampoline14:
255
255
  trampoline 14
256
256
  Trampoline15:
257
257
  trampoline 15
258
+ Trampoline16:
259
+ trampoline 16
260
+ Trampoline17:
261
+ trampoline 17
262
+ Trampoline18:
263
+ trampoline 18
264
+ Trampoline19:
265
+ trampoline 19
266
+ Trampoline20:
267
+ trampoline 20
268
+ Trampoline21:
269
+ trampoline 21
270
+ Trampoline22:
271
+ trampoline 22
272
+ Trampoline23:
273
+ trampoline 23
274
+ Trampoline24:
275
+ trampoline 24
276
+ Trampoline25:
277
+ trampoline 25
278
+ Trampoline26:
279
+ trampoline 26
280
+ Trampoline27:
281
+ trampoline 27
282
+ Trampoline28:
283
+ trampoline 28
284
+ Trampoline29:
285
+ trampoline 29
286
+ Trampoline30:
287
+ trampoline 30
288
+ Trampoline31:
289
+ trampoline 31
258
290
 
259
291
  TrampolineX0:
260
292
  trampoline_vec 0
@@ -288,6 +320,38 @@ TrampolineX14:
288
320
  trampoline_vec 14
289
321
  TrampolineX15:
290
322
  trampoline_vec 15
323
+ TrampolineX16:
324
+ trampoline_vec 16
325
+ TrampolineX17:
326
+ trampoline_vec 17
327
+ TrampolineX18:
328
+ trampoline_vec 18
329
+ TrampolineX19:
330
+ trampoline_vec 19
331
+ TrampolineX20:
332
+ trampoline_vec 20
333
+ TrampolineX21:
334
+ trampoline_vec 21
335
+ TrampolineX22:
336
+ trampoline_vec 22
337
+ TrampolineX23:
338
+ trampoline_vec 23
339
+ TrampolineX24:
340
+ trampoline_vec 24
341
+ TrampolineX25:
342
+ trampoline_vec 25
343
+ TrampolineX26:
344
+ trampoline_vec 26
345
+ TrampolineX27:
346
+ trampoline_vec 27
347
+ TrampolineX28:
348
+ trampoline_vec 28
349
+ TrampolineX29:
350
+ trampoline_vec 29
351
+ TrampolineX30:
352
+ trampoline_vec 30
353
+ TrampolineX31:
354
+ trampoline_vec 31
291
355
 
292
356
  # When a callback is relayed, Koffi will call into Node.js and V8 to execute Javascript.
293
357
  # The problem is that we're still running on the separate Koffi stack, and V8 will