koffi 1.3.12 → 2.1.0-beta.1
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.
- package/CMakeLists.txt +8 -10
- package/ChangeLog.md +48 -16
- package/README.md +6 -0
- package/benchmark/atoi_koffi.js +12 -8
- package/benchmark/atoi_napi.js +12 -8
- package/benchmark/atoi_node_ffi.js +11 -10
- package/benchmark/raylib_cc.cc +12 -9
- package/benchmark/raylib_koffi.js +15 -13
- package/benchmark/raylib_node_ffi.js +15 -13
- package/benchmark/raylib_node_raylib.js +14 -11
- package/build/qemu/2.1.0-beta.1/koffi_darwin_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_linux_arm32hf.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_linux_riscv64hf64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_openbsd_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_openbsd_x64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_win32_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.1/koffi_win32_x64.tar.gz +0 -0
- package/doc/changes.md +160 -1
- package/doc/conf.py +14 -1
- package/doc/contribute.md +0 -1
- package/doc/dist/doctrees/benchmarks.doctree +0 -0
- package/doc/dist/doctrees/changes.doctree +0 -0
- package/doc/dist/doctrees/environment.pickle +0 -0
- package/doc/dist/doctrees/functions.doctree +0 -0
- package/doc/dist/doctrees/index.doctree +0 -0
- package/doc/dist/doctrees/types.doctree +0 -0
- package/doc/dist/html/.buildinfo +1 -1
- package/doc/dist/html/_sources/benchmarks.md.txt +2 -2
- package/doc/dist/html/_sources/changes.md.txt +160 -1
- package/doc/dist/html/_sources/functions.md.txt +17 -13
- package/doc/dist/html/_sources/types.md.txt +87 -35
- package/doc/dist/html/benchmarks.html +7 -3
- package/doc/dist/html/changes.html +241 -14
- package/doc/dist/html/contribute.html +5 -1
- package/doc/dist/html/functions.html +30 -23
- package/doc/dist/html/genindex.html +5 -1
- package/doc/dist/html/index.html +13 -19
- package/doc/dist/html/memory.html +7 -3
- package/doc/dist/html/objects.inv +0 -0
- package/doc/dist/html/platforms.html +6 -2
- package/doc/dist/html/search.html +5 -1
- package/doc/dist/html/searchindex.js +1 -1
- package/doc/dist/html/start.html +5 -1
- package/doc/dist/html/types.html +104 -43
- package/doc/functions.md +139 -15
- package/doc/templates/badges.html +5 -0
- package/doc/types.md +108 -40
- package/package.json +2 -2
- package/qemu/qemu.js +1 -1
- package/qemu/registry/machines.json +5 -5
- package/qemu/registry/sha256sum.txt +16 -16
- package/src/abi_arm32.cc +91 -19
- package/src/abi_arm32_fwd.S +121 -57
- package/src/abi_arm64.cc +91 -19
- package/src/abi_arm64_fwd.S +96 -0
- package/src/abi_arm64_fwd.asm +128 -0
- package/src/abi_riscv64.cc +89 -19
- package/src/abi_riscv64_fwd.S +96 -0
- package/src/abi_x64_sysv.cc +94 -22
- package/src/abi_x64_sysv_fwd.S +96 -0
- package/src/abi_x64_win.cc +89 -19
- package/src/abi_x64_win_fwd.asm +128 -0
- package/src/abi_x86.cc +94 -19
- package/src/abi_x86_fwd.S +96 -0
- package/src/abi_x86_fwd.asm +128 -0
- package/src/call.cc +128 -78
- package/src/call.hh +17 -4
- package/src/ffi.cc +514 -145
- package/src/ffi.hh +30 -9
- package/src/index.js +4 -2
- package/src/parser.cc +19 -44
- package/src/util.cc +160 -27
- package/src/util.hh +7 -2
- package/test/async.js +1 -2
- package/test/callbacks.js +56 -11
- package/test/misc.c +50 -15
- package/test/raylib.js +2 -2
- package/test/sqlite.js +27 -19
- package/test/sync.js +71 -35
- package/vendor/libcc/libcc.cc +18 -5
- package/vendor/libcc/libcc.hh +70 -23
- package/build/qemu/1.3.12/koffi_darwin_arm64.tar.gz +0 -0
- package/build/qemu/1.3.12/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/1.3.12/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/1.3.12/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/1.3.12/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/1.3.12/koffi_linux_arm32hf.tar.gz +0 -0
- package/build/qemu/1.3.12/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/1.3.12/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/1.3.12/koffi_linux_riscv64hf64.tar.gz +0 -0
- package/build/qemu/1.3.12/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/1.3.12/koffi_openbsd_ia32.tar.gz +0 -0
- package/build/qemu/1.3.12/koffi_openbsd_x64.tar.gz +0 -0
- package/build/qemu/1.3.12/koffi_win32_arm64.tar.gz +0 -0
- package/build/qemu/1.3.12/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/1.3.12/koffi_win32_x64.tar.gz +0 -0
package/src/abi_x64_win_fwd.asm
CHANGED
|
@@ -126,6 +126,22 @@ public Trampoline12
|
|
|
126
126
|
public Trampoline13
|
|
127
127
|
public Trampoline14
|
|
128
128
|
public Trampoline15
|
|
129
|
+
public Trampoline16
|
|
130
|
+
public Trampoline17
|
|
131
|
+
public Trampoline18
|
|
132
|
+
public Trampoline19
|
|
133
|
+
public Trampoline20
|
|
134
|
+
public Trampoline21
|
|
135
|
+
public Trampoline22
|
|
136
|
+
public Trampoline23
|
|
137
|
+
public Trampoline24
|
|
138
|
+
public Trampoline25
|
|
139
|
+
public Trampoline26
|
|
140
|
+
public Trampoline27
|
|
141
|
+
public Trampoline28
|
|
142
|
+
public Trampoline29
|
|
143
|
+
public Trampoline30
|
|
144
|
+
public Trampoline31
|
|
129
145
|
public TrampolineX0
|
|
130
146
|
public TrampolineX1
|
|
131
147
|
public TrampolineX2
|
|
@@ -142,6 +158,22 @@ public TrampolineX12
|
|
|
142
158
|
public TrampolineX13
|
|
143
159
|
public TrampolineX14
|
|
144
160
|
public TrampolineX15
|
|
161
|
+
public TrampolineX16
|
|
162
|
+
public TrampolineX17
|
|
163
|
+
public TrampolineX18
|
|
164
|
+
public TrampolineX19
|
|
165
|
+
public TrampolineX20
|
|
166
|
+
public TrampolineX21
|
|
167
|
+
public TrampolineX22
|
|
168
|
+
public TrampolineX23
|
|
169
|
+
public TrampolineX24
|
|
170
|
+
public TrampolineX25
|
|
171
|
+
public TrampolineX26
|
|
172
|
+
public TrampolineX27
|
|
173
|
+
public TrampolineX28
|
|
174
|
+
public TrampolineX29
|
|
175
|
+
public TrampolineX30
|
|
176
|
+
public TrampolineX31
|
|
145
177
|
extern RelayCallback : PROC
|
|
146
178
|
public CallSwitchStack
|
|
147
179
|
|
|
@@ -242,6 +274,54 @@ Trampoline14 endp
|
|
|
242
274
|
Trampoline15 proc frame
|
|
243
275
|
trampoline 15
|
|
244
276
|
Trampoline15 endp
|
|
277
|
+
Trampoline16 proc frame
|
|
278
|
+
trampoline 16
|
|
279
|
+
Trampoline16 endp
|
|
280
|
+
Trampoline17 proc frame
|
|
281
|
+
trampoline 17
|
|
282
|
+
Trampoline17 endp
|
|
283
|
+
Trampoline18 proc frame
|
|
284
|
+
trampoline 18
|
|
285
|
+
Trampoline18 endp
|
|
286
|
+
Trampoline19 proc frame
|
|
287
|
+
trampoline 19
|
|
288
|
+
Trampoline19 endp
|
|
289
|
+
Trampoline20 proc frame
|
|
290
|
+
trampoline 20
|
|
291
|
+
Trampoline20 endp
|
|
292
|
+
Trampoline21 proc frame
|
|
293
|
+
trampoline 21
|
|
294
|
+
Trampoline21 endp
|
|
295
|
+
Trampoline22 proc frame
|
|
296
|
+
trampoline 22
|
|
297
|
+
Trampoline22 endp
|
|
298
|
+
Trampoline23 proc frame
|
|
299
|
+
trampoline 23
|
|
300
|
+
Trampoline23 endp
|
|
301
|
+
Trampoline24 proc frame
|
|
302
|
+
trampoline 24
|
|
303
|
+
Trampoline24 endp
|
|
304
|
+
Trampoline25 proc frame
|
|
305
|
+
trampoline 25
|
|
306
|
+
Trampoline25 endp
|
|
307
|
+
Trampoline26 proc frame
|
|
308
|
+
trampoline 26
|
|
309
|
+
Trampoline26 endp
|
|
310
|
+
Trampoline27 proc frame
|
|
311
|
+
trampoline 27
|
|
312
|
+
Trampoline27 endp
|
|
313
|
+
Trampoline28 proc frame
|
|
314
|
+
trampoline 28
|
|
315
|
+
Trampoline28 endp
|
|
316
|
+
Trampoline29 proc frame
|
|
317
|
+
trampoline 29
|
|
318
|
+
Trampoline29 endp
|
|
319
|
+
Trampoline30 proc frame
|
|
320
|
+
trampoline 30
|
|
321
|
+
Trampoline30 endp
|
|
322
|
+
Trampoline31 proc frame
|
|
323
|
+
trampoline 31
|
|
324
|
+
Trampoline31 endp
|
|
245
325
|
|
|
246
326
|
TrampolineX0 proc frame
|
|
247
327
|
trampoline_xmm 0
|
|
@@ -291,6 +371,54 @@ TrampolineX14 endp
|
|
|
291
371
|
TrampolineX15 proc frame
|
|
292
372
|
trampoline_xmm 15
|
|
293
373
|
TrampolineX15 endp
|
|
374
|
+
TrampolineX16 proc frame
|
|
375
|
+
trampoline_xmm 16
|
|
376
|
+
TrampolineX16 endp
|
|
377
|
+
TrampolineX17 proc frame
|
|
378
|
+
trampoline_xmm 17
|
|
379
|
+
TrampolineX17 endp
|
|
380
|
+
TrampolineX18 proc frame
|
|
381
|
+
trampoline_xmm 18
|
|
382
|
+
TrampolineX18 endp
|
|
383
|
+
TrampolineX19 proc frame
|
|
384
|
+
trampoline_xmm 19
|
|
385
|
+
TrampolineX19 endp
|
|
386
|
+
TrampolineX20 proc frame
|
|
387
|
+
trampoline_xmm 20
|
|
388
|
+
TrampolineX20 endp
|
|
389
|
+
TrampolineX21 proc frame
|
|
390
|
+
trampoline_xmm 21
|
|
391
|
+
TrampolineX21 endp
|
|
392
|
+
TrampolineX22 proc frame
|
|
393
|
+
trampoline_xmm 22
|
|
394
|
+
TrampolineX22 endp
|
|
395
|
+
TrampolineX23 proc frame
|
|
396
|
+
trampoline_xmm 23
|
|
397
|
+
TrampolineX23 endp
|
|
398
|
+
TrampolineX24 proc frame
|
|
399
|
+
trampoline_xmm 24
|
|
400
|
+
TrampolineX24 endp
|
|
401
|
+
TrampolineX25 proc frame
|
|
402
|
+
trampoline_xmm 25
|
|
403
|
+
TrampolineX25 endp
|
|
404
|
+
TrampolineX26 proc frame
|
|
405
|
+
trampoline_xmm 26
|
|
406
|
+
TrampolineX26 endp
|
|
407
|
+
TrampolineX27 proc frame
|
|
408
|
+
trampoline_xmm 27
|
|
409
|
+
TrampolineX27 endp
|
|
410
|
+
TrampolineX28 proc frame
|
|
411
|
+
trampoline_xmm 28
|
|
412
|
+
TrampolineX28 endp
|
|
413
|
+
TrampolineX29 proc frame
|
|
414
|
+
trampoline_xmm 29
|
|
415
|
+
TrampolineX29 endp
|
|
416
|
+
TrampolineX30 proc frame
|
|
417
|
+
trampoline_xmm 30
|
|
418
|
+
TrampolineX30 endp
|
|
419
|
+
TrampolineX31 proc frame
|
|
420
|
+
trampoline_xmm 31
|
|
421
|
+
TrampolineX31 endp
|
|
294
422
|
|
|
295
423
|
; When a callback is relayed, Koffi will call into Node.js and V8 to execute Javascript.
|
|
296
424
|
; The problem is that we're still running on the separate Koffi stack, and V8 will
|
package/src/abi_x86.cc
CHANGED
|
@@ -56,6 +56,22 @@ extern "C" int Trampoline12; extern "C" int TrampolineX12;
|
|
|
56
56
|
extern "C" int Trampoline13; extern "C" int TrampolineX13;
|
|
57
57
|
extern "C" int Trampoline14; extern "C" int TrampolineX14;
|
|
58
58
|
extern "C" int Trampoline15; extern "C" int TrampolineX15;
|
|
59
|
+
extern "C" int Trampoline16; extern "C" int TrampolineX16;
|
|
60
|
+
extern "C" int Trampoline17; extern "C" int TrampolineX17;
|
|
61
|
+
extern "C" int Trampoline18; extern "C" int TrampolineX18;
|
|
62
|
+
extern "C" int Trampoline19; extern "C" int TrampolineX19;
|
|
63
|
+
extern "C" int Trampoline20; extern "C" int TrampolineX20;
|
|
64
|
+
extern "C" int Trampoline21; extern "C" int TrampolineX21;
|
|
65
|
+
extern "C" int Trampoline22; extern "C" int TrampolineX22;
|
|
66
|
+
extern "C" int Trampoline23; extern "C" int TrampolineX23;
|
|
67
|
+
extern "C" int Trampoline24; extern "C" int TrampolineX24;
|
|
68
|
+
extern "C" int Trampoline25; extern "C" int TrampolineX25;
|
|
69
|
+
extern "C" int Trampoline26; extern "C" int TrampolineX26;
|
|
70
|
+
extern "C" int Trampoline27; extern "C" int TrampolineX27;
|
|
71
|
+
extern "C" int Trampoline28; extern "C" int TrampolineX28;
|
|
72
|
+
extern "C" int Trampoline29; extern "C" int TrampolineX29;
|
|
73
|
+
extern "C" int Trampoline30; extern "C" int TrampolineX30;
|
|
74
|
+
extern "C" int Trampoline31; extern "C" int TrampolineX31;
|
|
59
75
|
|
|
60
76
|
extern "C" napi_value CallSwitchStack(Napi::Function *func, size_t argc, napi_value *argv,
|
|
61
77
|
uint8_t *old_sp, Span<uint8_t> *new_stack,
|
|
@@ -77,9 +93,25 @@ static void *const Trampolines[][2] = {
|
|
|
77
93
|
{ &Trampoline12, &TrampolineX12 },
|
|
78
94
|
{ &Trampoline13, &TrampolineX13 },
|
|
79
95
|
{ &Trampoline14, &TrampolineX14 },
|
|
80
|
-
{ &Trampoline15, &TrampolineX15 }
|
|
96
|
+
{ &Trampoline15, &TrampolineX15 },
|
|
97
|
+
{ &Trampoline16, &TrampolineX16 },
|
|
98
|
+
{ &Trampoline17, &TrampolineX17 },
|
|
99
|
+
{ &Trampoline18, &TrampolineX18 },
|
|
100
|
+
{ &Trampoline19, &TrampolineX19 },
|
|
101
|
+
{ &Trampoline20, &TrampolineX20 },
|
|
102
|
+
{ &Trampoline21, &TrampolineX21 },
|
|
103
|
+
{ &Trampoline22, &TrampolineX22 },
|
|
104
|
+
{ &Trampoline23, &TrampolineX23 },
|
|
105
|
+
{ &Trampoline24, &TrampolineX24 },
|
|
106
|
+
{ &Trampoline25, &TrampolineX25 },
|
|
107
|
+
{ &Trampoline26, &TrampolineX26 },
|
|
108
|
+
{ &Trampoline27, &TrampolineX27 },
|
|
109
|
+
{ &Trampoline28, &TrampolineX28 },
|
|
110
|
+
{ &Trampoline29, &TrampolineX29 },
|
|
111
|
+
{ &Trampoline30, &TrampolineX30 },
|
|
112
|
+
{ &Trampoline31, &TrampolineX31 }
|
|
81
113
|
};
|
|
82
|
-
RG_STATIC_ASSERT(RG_LEN(Trampolines) == MaxTrampolines);
|
|
114
|
+
RG_STATIC_ASSERT(RG_LEN(Trampolines) == MaxTrampolines * 2);
|
|
83
115
|
|
|
84
116
|
static RG_THREAD_LOCAL CallData *exec_call;
|
|
85
117
|
|
|
@@ -308,10 +340,10 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
|
|
|
308
340
|
if (value.IsFunction()) {
|
|
309
341
|
Napi::Function func = value.As<Napi::Function>();
|
|
310
342
|
|
|
311
|
-
ptr = ReserveTrampoline(param.type->proto, func);
|
|
343
|
+
ptr = ReserveTrampoline(param.type->ref.proto, func);
|
|
312
344
|
if (RG_UNLIKELY(!ptr))
|
|
313
345
|
return false;
|
|
314
|
-
} else if (CheckValueTag(instance, value, param.type)) {
|
|
346
|
+
} else if (CheckValueTag(instance, value, param.type->ref.marker)) {
|
|
315
347
|
ptr = value.As<Napi::External<uint8_t>>().Data();
|
|
316
348
|
} else if (IsNullOrUndefined(value)) {
|
|
317
349
|
ptr = nullptr;
|
|
@@ -322,6 +354,8 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
|
|
|
322
354
|
|
|
323
355
|
*(void **)((param.fast ? fast_ptr : args_ptr)++) = ptr;
|
|
324
356
|
} break;
|
|
357
|
+
|
|
358
|
+
case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
|
|
325
359
|
}
|
|
326
360
|
}
|
|
327
361
|
|
|
@@ -361,6 +395,8 @@ void CallData::Execute()
|
|
|
361
395
|
case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
|
|
362
396
|
case PrimitiveKind::Float32: { result.f = PERFORM_CALL(F); } break;
|
|
363
397
|
case PrimitiveKind::Float64: { result.d = PERFORM_CALL(D); } break;
|
|
398
|
+
|
|
399
|
+
case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
|
|
364
400
|
}
|
|
365
401
|
|
|
366
402
|
#undef PERFORM_CALL
|
|
@@ -368,10 +404,16 @@ void CallData::Execute()
|
|
|
368
404
|
|
|
369
405
|
Napi::Value CallData::Complete()
|
|
370
406
|
{
|
|
371
|
-
|
|
407
|
+
RG_DEFER {
|
|
408
|
+
PopOutArguments();
|
|
409
|
+
|
|
410
|
+
if (func->ret.type->dispose) {
|
|
411
|
+
func->ret.type->dispose(env, func->ret.type, result.ptr);
|
|
412
|
+
}
|
|
413
|
+
};
|
|
372
414
|
|
|
373
415
|
switch (func->ret.type->primitive) {
|
|
374
|
-
case PrimitiveKind::Void: return env.
|
|
416
|
+
case PrimitiveKind::Void: return env.Undefined();
|
|
375
417
|
case PrimitiveKind::Bool: return Napi::Boolean::New(env, result.u32);
|
|
376
418
|
case PrimitiveKind::Int8: return Napi::Number::New(env, (double)result.i8);
|
|
377
419
|
case PrimitiveKind::UInt8: return Napi::Number::New(env, (double)result.u8);
|
|
@@ -387,7 +429,7 @@ Napi::Value CallData::Complete()
|
|
|
387
429
|
case PrimitiveKind::Callback: {
|
|
388
430
|
if (result.ptr) {
|
|
389
431
|
Napi::External<void> external = Napi::External<void>::New(env, result.ptr);
|
|
390
|
-
SetValueTag(instance, external, func->ret.type);
|
|
432
|
+
SetValueTag(instance, external, func->ret.type->ref.marker);
|
|
391
433
|
|
|
392
434
|
return external;
|
|
393
435
|
} else {
|
|
@@ -404,6 +446,8 @@ Napi::Value CallData::Complete()
|
|
|
404
446
|
case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
|
|
405
447
|
case PrimitiveKind::Float32: return Napi::Number::New(env, (double)result.f);
|
|
406
448
|
case PrimitiveKind::Float64: return Napi::Number::New(env, result.d);
|
|
449
|
+
|
|
450
|
+
case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
|
|
407
451
|
}
|
|
408
452
|
|
|
409
453
|
RG_UNREACHABLE();
|
|
@@ -411,12 +455,10 @@ Napi::Value CallData::Complete()
|
|
|
411
455
|
|
|
412
456
|
void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegisters *out_reg)
|
|
413
457
|
{
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
if (RG_UNLIKELY(trampoline.generation != mem->generation)) {
|
|
417
|
-
ThrowError<Napi::Error>(env, "Cannot use non-persistent callback beyond FFI call");
|
|
458
|
+
if (RG_UNLIKELY(env.IsExceptionPending()))
|
|
418
459
|
return;
|
|
419
|
-
|
|
460
|
+
|
|
461
|
+
const TrampolineInfo &trampoline = instance->trampolines[idx];
|
|
420
462
|
|
|
421
463
|
const FunctionInfo *proto = trampoline.proto;
|
|
422
464
|
Napi::Function func = trampoline.func.Value();
|
|
@@ -436,6 +478,18 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
436
478
|
#endif
|
|
437
479
|
}
|
|
438
480
|
|
|
481
|
+
RG_DEFER_N(err_guard) {
|
|
482
|
+
int pop = out_reg->ret_pop;
|
|
483
|
+
memset(out_reg, 0, RG_SIZE(*out_reg));
|
|
484
|
+
out_reg->x87_double = true;
|
|
485
|
+
out_reg->ret_pop = pop;
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
if (RG_UNLIKELY(trampoline.generation >= 0 && trampoline.generation != (int32_t)mem->generation)) {
|
|
489
|
+
ThrowError<Napi::Error>(env, "Cannot use non-registered callback beyond FFI call");
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
|
|
439
493
|
LocalArray<napi_value, MaxParameters> arguments;
|
|
440
494
|
|
|
441
495
|
// Convert to JS arguments
|
|
@@ -507,12 +561,20 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
507
561
|
|
|
508
562
|
Napi::Value arg = str ? Napi::String::New(env, str) : env.Null();
|
|
509
563
|
arguments.Append(arg);
|
|
564
|
+
|
|
565
|
+
if (param.type->dispose) {
|
|
566
|
+
param.type->dispose(env, param.type, str);
|
|
567
|
+
}
|
|
510
568
|
} break;
|
|
511
569
|
case PrimitiveKind::String16: {
|
|
512
570
|
const char16_t *str16 = *(const char16_t **)(args_ptr++);
|
|
513
571
|
|
|
514
572
|
Napi::Value arg = str16 ? Napi::String::New(env, str16) : env.Null();
|
|
515
573
|
arguments.Append(arg);
|
|
574
|
+
|
|
575
|
+
if (param.type->dispose) {
|
|
576
|
+
param.type->dispose(env, param.type, str16);
|
|
577
|
+
}
|
|
516
578
|
} break;
|
|
517
579
|
case PrimitiveKind::Pointer:
|
|
518
580
|
case PrimitiveKind::Callback: {
|
|
@@ -520,12 +582,16 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
520
582
|
|
|
521
583
|
if (ptr2) {
|
|
522
584
|
Napi::External<void> external = Napi::External<void>::New(env, ptr2);
|
|
523
|
-
SetValueTag(instance, external, param.type);
|
|
585
|
+
SetValueTag(instance, external, param.type->ref.marker);
|
|
524
586
|
|
|
525
587
|
arguments.Append(external);
|
|
526
588
|
} else {
|
|
527
589
|
arguments.Append(env.Null());
|
|
528
590
|
}
|
|
591
|
+
|
|
592
|
+
if (param.type->dispose) {
|
|
593
|
+
param.type->dispose(env, param.type, ptr2);
|
|
594
|
+
}
|
|
529
595
|
} break;
|
|
530
596
|
case PrimitiveKind::Record: {
|
|
531
597
|
RG_ASSERT(!param.fast);
|
|
@@ -551,6 +617,8 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
551
617
|
Napi::Value arg = Napi::Number::New(env, d);
|
|
552
618
|
arguments.Append(arg);
|
|
553
619
|
} break;
|
|
620
|
+
|
|
621
|
+
case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
|
|
554
622
|
}
|
|
555
623
|
}
|
|
556
624
|
|
|
@@ -561,6 +629,9 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
561
629
|
[](Napi::Function *func, size_t argc, napi_value *argv) { return (napi_value)func->Call(argc, argv); });
|
|
562
630
|
Napi::Value value(env, ret);
|
|
563
631
|
|
|
632
|
+
if (RG_UNLIKELY(env.IsExceptionPending()))
|
|
633
|
+
return;
|
|
634
|
+
|
|
564
635
|
switch (type->primitive) {
|
|
565
636
|
case PrimitiveKind::Void: {} break;
|
|
566
637
|
case PrimitiveKind::Bool: {
|
|
@@ -630,14 +701,14 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
630
701
|
case PrimitiveKind::Pointer: {
|
|
631
702
|
uint8_t *ptr;
|
|
632
703
|
|
|
633
|
-
if (CheckValueTag(instance, value, type)) {
|
|
704
|
+
if (CheckValueTag(instance, value, type->ref.marker)) {
|
|
634
705
|
ptr = value.As<Napi::External<uint8_t>>().Data();
|
|
635
|
-
} else if (IsObject(value) && type->ref->primitive == PrimitiveKind::Record) {
|
|
706
|
+
} else if (IsObject(value) && type->ref.type->primitive == PrimitiveKind::Record) {
|
|
636
707
|
Napi::Object obj = value.As<Napi::Object>();
|
|
637
708
|
|
|
638
|
-
ptr = AllocHeap(type->ref->size, 16);
|
|
709
|
+
ptr = AllocHeap(type->ref.type->size, 16);
|
|
639
710
|
|
|
640
|
-
if (!PushObject(obj, type->ref, ptr))
|
|
711
|
+
if (!PushObject(obj, type->ref.type, ptr))
|
|
641
712
|
return;
|
|
642
713
|
} else if (IsNullOrUndefined(value)) {
|
|
643
714
|
ptr = nullptr;
|
|
@@ -689,10 +760,10 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
689
760
|
if (value.IsFunction()) {
|
|
690
761
|
Napi::Function func2 = value.As<Napi::Function>();
|
|
691
762
|
|
|
692
|
-
ptr = ReserveTrampoline(type->proto, func2);
|
|
763
|
+
ptr = ReserveTrampoline(type->ref.proto, func2);
|
|
693
764
|
if (RG_UNLIKELY(!ptr))
|
|
694
765
|
return;
|
|
695
|
-
} else if (CheckValueTag(instance, value, type)) {
|
|
766
|
+
} else if (CheckValueTag(instance, value, type->ref.marker)) {
|
|
696
767
|
ptr = value.As<Napi::External<uint8_t>>().Data();
|
|
697
768
|
} else if (IsNullOrUndefined(value)) {
|
|
698
769
|
ptr = nullptr;
|
|
@@ -703,7 +774,11 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
703
774
|
|
|
704
775
|
out_reg->eax = (uint32_t)ptr;
|
|
705
776
|
} break;
|
|
777
|
+
|
|
778
|
+
case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
|
|
706
779
|
}
|
|
780
|
+
|
|
781
|
+
err_guard.Disable();
|
|
707
782
|
}
|
|
708
783
|
|
|
709
784
|
void *GetTrampoline(Size idx, const FunctionInfo *proto)
|
package/src/abi_x86_fwd.S
CHANGED
|
@@ -101,6 +101,22 @@ ForwardCallRD:
|
|
|
101
101
|
.global Trampoline13
|
|
102
102
|
.global Trampoline14
|
|
103
103
|
.global Trampoline15
|
|
104
|
+
.global Trampoline16
|
|
105
|
+
.global Trampoline17
|
|
106
|
+
.global Trampoline18
|
|
107
|
+
.global Trampoline19
|
|
108
|
+
.global Trampoline20
|
|
109
|
+
.global Trampoline21
|
|
110
|
+
.global Trampoline22
|
|
111
|
+
.global Trampoline23
|
|
112
|
+
.global Trampoline24
|
|
113
|
+
.global Trampoline25
|
|
114
|
+
.global Trampoline26
|
|
115
|
+
.global Trampoline27
|
|
116
|
+
.global Trampoline28
|
|
117
|
+
.global Trampoline29
|
|
118
|
+
.global Trampoline30
|
|
119
|
+
.global Trampoline31
|
|
104
120
|
.global TrampolineX0
|
|
105
121
|
.global TrampolineX1
|
|
106
122
|
.global TrampolineX2
|
|
@@ -117,6 +133,22 @@ ForwardCallRD:
|
|
|
117
133
|
.global TrampolineX13
|
|
118
134
|
.global TrampolineX14
|
|
119
135
|
.global TrampolineX15
|
|
136
|
+
.global TrampolineX16
|
|
137
|
+
.global TrampolineX17
|
|
138
|
+
.global TrampolineX18
|
|
139
|
+
.global TrampolineX19
|
|
140
|
+
.global TrampolineX20
|
|
141
|
+
.global TrampolineX21
|
|
142
|
+
.global TrampolineX22
|
|
143
|
+
.global TrampolineX23
|
|
144
|
+
.global TrampolineX24
|
|
145
|
+
.global TrampolineX25
|
|
146
|
+
.global TrampolineX26
|
|
147
|
+
.global TrampolineX27
|
|
148
|
+
.global TrampolineX28
|
|
149
|
+
.global TrampolineX29
|
|
150
|
+
.global TrampolineX30
|
|
151
|
+
.global TrampolineX31
|
|
120
152
|
.global RelayCallback
|
|
121
153
|
.global CallSwitchStack
|
|
122
154
|
|
|
@@ -224,6 +256,38 @@ Trampoline14:
|
|
|
224
256
|
trampoline 14
|
|
225
257
|
Trampoline15:
|
|
226
258
|
trampoline 15
|
|
259
|
+
Trampoline16:
|
|
260
|
+
trampoline 16
|
|
261
|
+
Trampoline17:
|
|
262
|
+
trampoline 17
|
|
263
|
+
Trampoline18:
|
|
264
|
+
trampoline 18
|
|
265
|
+
Trampoline19:
|
|
266
|
+
trampoline 19
|
|
267
|
+
Trampoline20:
|
|
268
|
+
trampoline 20
|
|
269
|
+
Trampoline21:
|
|
270
|
+
trampoline 21
|
|
271
|
+
Trampoline22:
|
|
272
|
+
trampoline 22
|
|
273
|
+
Trampoline23:
|
|
274
|
+
trampoline 23
|
|
275
|
+
Trampoline24:
|
|
276
|
+
trampoline 24
|
|
277
|
+
Trampoline25:
|
|
278
|
+
trampoline 25
|
|
279
|
+
Trampoline26:
|
|
280
|
+
trampoline 26
|
|
281
|
+
Trampoline27:
|
|
282
|
+
trampoline 27
|
|
283
|
+
Trampoline28:
|
|
284
|
+
trampoline 28
|
|
285
|
+
Trampoline29:
|
|
286
|
+
trampoline 29
|
|
287
|
+
Trampoline30:
|
|
288
|
+
trampoline 30
|
|
289
|
+
Trampoline31:
|
|
290
|
+
trampoline 31
|
|
227
291
|
|
|
228
292
|
TrampolineX0:
|
|
229
293
|
trampoline_x87 0
|
|
@@ -257,6 +321,38 @@ TrampolineX14:
|
|
|
257
321
|
trampoline_x87 14
|
|
258
322
|
TrampolineX15:
|
|
259
323
|
trampoline_x87 15
|
|
324
|
+
TrampolineX16:
|
|
325
|
+
trampoline_x87 16
|
|
326
|
+
TrampolineX17:
|
|
327
|
+
trampoline_x87 17
|
|
328
|
+
TrampolineX18:
|
|
329
|
+
trampoline_x87 18
|
|
330
|
+
TrampolineX19:
|
|
331
|
+
trampoline_x87 19
|
|
332
|
+
TrampolineX20:
|
|
333
|
+
trampoline_x87 20
|
|
334
|
+
TrampolineX21:
|
|
335
|
+
trampoline_x87 21
|
|
336
|
+
TrampolineX22:
|
|
337
|
+
trampoline_x87 22
|
|
338
|
+
TrampolineX23:
|
|
339
|
+
trampoline_x87 23
|
|
340
|
+
TrampolineX24:
|
|
341
|
+
trampoline_x87 24
|
|
342
|
+
TrampolineX25:
|
|
343
|
+
trampoline_x87 25
|
|
344
|
+
TrampolineX26:
|
|
345
|
+
trampoline_x87 26
|
|
346
|
+
TrampolineX27:
|
|
347
|
+
trampoline_x87 27
|
|
348
|
+
TrampolineX28:
|
|
349
|
+
trampoline_x87 28
|
|
350
|
+
TrampolineX29:
|
|
351
|
+
trampoline_x87 29
|
|
352
|
+
TrampolineX30:
|
|
353
|
+
trampoline_x87 30
|
|
354
|
+
TrampolineX31:
|
|
355
|
+
trampoline_x87 31
|
|
260
356
|
|
|
261
357
|
# When a callback is relayed, Koffi will call into Node.js and V8 to execute Javascript.
|
|
262
358
|
# The problem is that we're still running on the separate Koffi stack, and V8 will
|
package/src/abi_x86_fwd.asm
CHANGED
|
@@ -105,6 +105,22 @@ public Trampoline12
|
|
|
105
105
|
public Trampoline13
|
|
106
106
|
public Trampoline14
|
|
107
107
|
public Trampoline15
|
|
108
|
+
public Trampoline16
|
|
109
|
+
public Trampoline17
|
|
110
|
+
public Trampoline18
|
|
111
|
+
public Trampoline19
|
|
112
|
+
public Trampoline20
|
|
113
|
+
public Trampoline21
|
|
114
|
+
public Trampoline22
|
|
115
|
+
public Trampoline23
|
|
116
|
+
public Trampoline24
|
|
117
|
+
public Trampoline25
|
|
118
|
+
public Trampoline26
|
|
119
|
+
public Trampoline27
|
|
120
|
+
public Trampoline28
|
|
121
|
+
public Trampoline29
|
|
122
|
+
public Trampoline30
|
|
123
|
+
public Trampoline31
|
|
108
124
|
public TrampolineX0
|
|
109
125
|
public TrampolineX1
|
|
110
126
|
public TrampolineX2
|
|
@@ -121,6 +137,22 @@ public TrampolineX12
|
|
|
121
137
|
public TrampolineX13
|
|
122
138
|
public TrampolineX14
|
|
123
139
|
public TrampolineX15
|
|
140
|
+
public TrampolineX16
|
|
141
|
+
public TrampolineX17
|
|
142
|
+
public TrampolineX18
|
|
143
|
+
public TrampolineX19
|
|
144
|
+
public TrampolineX20
|
|
145
|
+
public TrampolineX21
|
|
146
|
+
public TrampolineX22
|
|
147
|
+
public TrampolineX23
|
|
148
|
+
public TrampolineX24
|
|
149
|
+
public TrampolineX25
|
|
150
|
+
public TrampolineX26
|
|
151
|
+
public TrampolineX27
|
|
152
|
+
public TrampolineX28
|
|
153
|
+
public TrampolineX29
|
|
154
|
+
public TrampolineX30
|
|
155
|
+
public TrampolineX31
|
|
124
156
|
extern RelayCallback : PROC
|
|
125
157
|
public CallSwitchStack
|
|
126
158
|
|
|
@@ -227,6 +259,54 @@ Trampoline14 endp
|
|
|
227
259
|
Trampoline15 proc
|
|
228
260
|
trampoline 15
|
|
229
261
|
Trampoline15 endp
|
|
262
|
+
Trampoline16 proc
|
|
263
|
+
trampoline 16
|
|
264
|
+
Trampoline16 endp
|
|
265
|
+
Trampoline17 proc
|
|
266
|
+
trampoline 17
|
|
267
|
+
Trampoline17 endp
|
|
268
|
+
Trampoline18 proc
|
|
269
|
+
trampoline 18
|
|
270
|
+
Trampoline18 endp
|
|
271
|
+
Trampoline19 proc
|
|
272
|
+
trampoline 19
|
|
273
|
+
Trampoline19 endp
|
|
274
|
+
Trampoline20 proc
|
|
275
|
+
trampoline 20
|
|
276
|
+
Trampoline20 endp
|
|
277
|
+
Trampoline21 proc
|
|
278
|
+
trampoline 21
|
|
279
|
+
Trampoline21 endp
|
|
280
|
+
Trampoline22 proc
|
|
281
|
+
trampoline 22
|
|
282
|
+
Trampoline22 endp
|
|
283
|
+
Trampoline23 proc
|
|
284
|
+
trampoline 23
|
|
285
|
+
Trampoline23 endp
|
|
286
|
+
Trampoline24 proc
|
|
287
|
+
trampoline 24
|
|
288
|
+
Trampoline24 endp
|
|
289
|
+
Trampoline25 proc
|
|
290
|
+
trampoline 25
|
|
291
|
+
Trampoline25 endp
|
|
292
|
+
Trampoline26 proc
|
|
293
|
+
trampoline 26
|
|
294
|
+
Trampoline26 endp
|
|
295
|
+
Trampoline27 proc
|
|
296
|
+
trampoline 27
|
|
297
|
+
Trampoline27 endp
|
|
298
|
+
Trampoline28 proc
|
|
299
|
+
trampoline 28
|
|
300
|
+
Trampoline28 endp
|
|
301
|
+
Trampoline29 proc
|
|
302
|
+
trampoline 29
|
|
303
|
+
Trampoline29 endp
|
|
304
|
+
Trampoline30 proc
|
|
305
|
+
trampoline 30
|
|
306
|
+
Trampoline30 endp
|
|
307
|
+
Trampoline31 proc
|
|
308
|
+
trampoline 31
|
|
309
|
+
Trampoline31 endp
|
|
230
310
|
|
|
231
311
|
TrampolineX0 proc
|
|
232
312
|
trampoline_x87 0
|
|
@@ -276,6 +356,54 @@ TrampolineX14 endp
|
|
|
276
356
|
TrampolineX15 proc
|
|
277
357
|
trampoline_x87 15
|
|
278
358
|
TrampolineX15 endp
|
|
359
|
+
TrampolineX16 proc
|
|
360
|
+
trampoline_x87 16
|
|
361
|
+
TrampolineX16 endp
|
|
362
|
+
TrampolineX17 proc
|
|
363
|
+
trampoline_x87 17
|
|
364
|
+
TrampolineX17 endp
|
|
365
|
+
TrampolineX18 proc
|
|
366
|
+
trampoline_x87 18
|
|
367
|
+
TrampolineX18 endp
|
|
368
|
+
TrampolineX19 proc
|
|
369
|
+
trampoline_x87 19
|
|
370
|
+
TrampolineX19 endp
|
|
371
|
+
TrampolineX20 proc
|
|
372
|
+
trampoline_x87 20
|
|
373
|
+
TrampolineX20 endp
|
|
374
|
+
TrampolineX21 proc
|
|
375
|
+
trampoline_x87 21
|
|
376
|
+
TrampolineX21 endp
|
|
377
|
+
TrampolineX22 proc
|
|
378
|
+
trampoline_x87 22
|
|
379
|
+
TrampolineX22 endp
|
|
380
|
+
TrampolineX23 proc
|
|
381
|
+
trampoline_x87 23
|
|
382
|
+
TrampolineX23 endp
|
|
383
|
+
TrampolineX24 proc
|
|
384
|
+
trampoline_x87 24
|
|
385
|
+
TrampolineX24 endp
|
|
386
|
+
TrampolineX25 proc
|
|
387
|
+
trampoline_x87 25
|
|
388
|
+
TrampolineX25 endp
|
|
389
|
+
TrampolineX26 proc
|
|
390
|
+
trampoline_x87 26
|
|
391
|
+
TrampolineX26 endp
|
|
392
|
+
TrampolineX27 proc
|
|
393
|
+
trampoline_x87 27
|
|
394
|
+
TrampolineX27 endp
|
|
395
|
+
TrampolineX28 proc
|
|
396
|
+
trampoline_x87 28
|
|
397
|
+
TrampolineX28 endp
|
|
398
|
+
TrampolineX29 proc
|
|
399
|
+
trampoline_x87 29
|
|
400
|
+
TrampolineX29 endp
|
|
401
|
+
TrampolineX30 proc
|
|
402
|
+
trampoline_x87 30
|
|
403
|
+
TrampolineX30 endp
|
|
404
|
+
TrampolineX31 proc
|
|
405
|
+
trampoline_x87 31
|
|
406
|
+
TrampolineX31 endp
|
|
279
407
|
|
|
280
408
|
; When a callback is relayed, Koffi will call into Node.js and V8 to execute Javascript.
|
|
281
409
|
; The problem is that we're still running on the separate Koffi stack, and V8 will
|