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_arm64_fwd.asm
CHANGED
|
@@ -130,6 +130,22 @@ ForwardCallXDDDD PROC
|
|
|
130
130
|
EXPORT Trampoline13
|
|
131
131
|
EXPORT Trampoline14
|
|
132
132
|
EXPORT Trampoline15
|
|
133
|
+
EXPORT Trampoline16
|
|
134
|
+
EXPORT Trampoline17
|
|
135
|
+
EXPORT Trampoline18
|
|
136
|
+
EXPORT Trampoline19
|
|
137
|
+
EXPORT Trampoline20
|
|
138
|
+
EXPORT Trampoline21
|
|
139
|
+
EXPORT Trampoline22
|
|
140
|
+
EXPORT Trampoline23
|
|
141
|
+
EXPORT Trampoline24
|
|
142
|
+
EXPORT Trampoline25
|
|
143
|
+
EXPORT Trampoline26
|
|
144
|
+
EXPORT Trampoline27
|
|
145
|
+
EXPORT Trampoline28
|
|
146
|
+
EXPORT Trampoline29
|
|
147
|
+
EXPORT Trampoline30
|
|
148
|
+
EXPORT Trampoline31
|
|
133
149
|
EXPORT TrampolineX0
|
|
134
150
|
EXPORT TrampolineX1
|
|
135
151
|
EXPORT TrampolineX2
|
|
@@ -146,6 +162,22 @@ ForwardCallXDDDD PROC
|
|
|
146
162
|
EXPORT TrampolineX13
|
|
147
163
|
EXPORT TrampolineX14
|
|
148
164
|
EXPORT TrampolineX15
|
|
165
|
+
EXPORT TrampolineX16
|
|
166
|
+
EXPORT TrampolineX17
|
|
167
|
+
EXPORT TrampolineX18
|
|
168
|
+
EXPORT TrampolineX19
|
|
169
|
+
EXPORT TrampolineX20
|
|
170
|
+
EXPORT TrampolineX21
|
|
171
|
+
EXPORT TrampolineX22
|
|
172
|
+
EXPORT TrampolineX23
|
|
173
|
+
EXPORT TrampolineX24
|
|
174
|
+
EXPORT TrampolineX25
|
|
175
|
+
EXPORT TrampolineX26
|
|
176
|
+
EXPORT TrampolineX27
|
|
177
|
+
EXPORT TrampolineX28
|
|
178
|
+
EXPORT TrampolineX29
|
|
179
|
+
EXPORT TrampolineX30
|
|
180
|
+
EXPORT TrampolineX31
|
|
149
181
|
EXPORT RelayCallback
|
|
150
182
|
EXTERN RelayCallback
|
|
151
183
|
EXPORT CallSwitchStack
|
|
@@ -252,6 +284,54 @@ Trampoline14 PROC
|
|
|
252
284
|
Trampoline15 PROC
|
|
253
285
|
trampoline 15
|
|
254
286
|
ENDP
|
|
287
|
+
Trampoline16 PROC
|
|
288
|
+
trampoline 16
|
|
289
|
+
ENDP
|
|
290
|
+
Trampoline17 PROC
|
|
291
|
+
trampoline 17
|
|
292
|
+
ENDP
|
|
293
|
+
Trampoline18 PROC
|
|
294
|
+
trampoline 18
|
|
295
|
+
ENDP
|
|
296
|
+
Trampoline19 PROC
|
|
297
|
+
trampoline 19
|
|
298
|
+
ENDP
|
|
299
|
+
Trampoline20 PROC
|
|
300
|
+
trampoline 20
|
|
301
|
+
ENDP
|
|
302
|
+
Trampoline21 PROC
|
|
303
|
+
trampoline 21
|
|
304
|
+
ENDP
|
|
305
|
+
Trampoline22 PROC
|
|
306
|
+
trampoline 22
|
|
307
|
+
ENDP
|
|
308
|
+
Trampoline23 PROC
|
|
309
|
+
trampoline 23
|
|
310
|
+
ENDP
|
|
311
|
+
Trampoline24 PROC
|
|
312
|
+
trampoline 24
|
|
313
|
+
ENDP
|
|
314
|
+
Trampoline25 PROC
|
|
315
|
+
trampoline 25
|
|
316
|
+
ENDP
|
|
317
|
+
Trampoline26 PROC
|
|
318
|
+
trampoline 26
|
|
319
|
+
ENDP
|
|
320
|
+
Trampoline27 PROC
|
|
321
|
+
trampoline 27
|
|
322
|
+
ENDP
|
|
323
|
+
Trampoline28 PROC
|
|
324
|
+
trampoline 28
|
|
325
|
+
ENDP
|
|
326
|
+
Trampoline29 PROC
|
|
327
|
+
trampoline 29
|
|
328
|
+
ENDP
|
|
329
|
+
Trampoline30 PROC
|
|
330
|
+
trampoline 30
|
|
331
|
+
ENDP
|
|
332
|
+
Trampoline31 PROC
|
|
333
|
+
trampoline 31
|
|
334
|
+
ENDP
|
|
255
335
|
|
|
256
336
|
TrampolineX0 PROC
|
|
257
337
|
trampoline_vec 0
|
|
@@ -301,6 +381,54 @@ TrampolineX14 PROC
|
|
|
301
381
|
TrampolineX15 PROC
|
|
302
382
|
trampoline_vec 15
|
|
303
383
|
ENDP
|
|
384
|
+
TrampolineX16 PROC
|
|
385
|
+
trampoline_vec 16
|
|
386
|
+
ENDP
|
|
387
|
+
TrampolineX17 PROC
|
|
388
|
+
trampoline_vec 17
|
|
389
|
+
ENDP
|
|
390
|
+
TrampolineX18 PROC
|
|
391
|
+
trampoline_vec 18
|
|
392
|
+
ENDP
|
|
393
|
+
TrampolineX19 PROC
|
|
394
|
+
trampoline_vec 19
|
|
395
|
+
ENDP
|
|
396
|
+
TrampolineX20 PROC
|
|
397
|
+
trampoline_vec 20
|
|
398
|
+
ENDP
|
|
399
|
+
TrampolineX21 PROC
|
|
400
|
+
trampoline_vec 21
|
|
401
|
+
ENDP
|
|
402
|
+
TrampolineX22 PROC
|
|
403
|
+
trampoline_vec 22
|
|
404
|
+
ENDP
|
|
405
|
+
TrampolineX23 PROC
|
|
406
|
+
trampoline_vec 23
|
|
407
|
+
ENDP
|
|
408
|
+
TrampolineX24 PROC
|
|
409
|
+
trampoline_vec 24
|
|
410
|
+
ENDP
|
|
411
|
+
TrampolineX25 PROC
|
|
412
|
+
trampoline_vec 25
|
|
413
|
+
ENDP
|
|
414
|
+
TrampolineX26 PROC
|
|
415
|
+
trampoline_vec 26
|
|
416
|
+
ENDP
|
|
417
|
+
TrampolineX27 PROC
|
|
418
|
+
trampoline_vec 27
|
|
419
|
+
ENDP
|
|
420
|
+
TrampolineX28 PROC
|
|
421
|
+
trampoline_vec 28
|
|
422
|
+
ENDP
|
|
423
|
+
TrampolineX29 PROC
|
|
424
|
+
trampoline_vec 29
|
|
425
|
+
ENDP
|
|
426
|
+
TrampolineX30 PROC
|
|
427
|
+
trampoline_vec 30
|
|
428
|
+
ENDP
|
|
429
|
+
TrampolineX31 PROC
|
|
430
|
+
trampoline_vec 31
|
|
431
|
+
ENDP
|
|
304
432
|
|
|
305
433
|
; When a callback is relayed, Koffi will call into Node.js and V8 to execute Javascript.
|
|
306
434
|
; The problem is that we're still running on the separate Koffi stack, and V8 will
|
package/src/abi_riscv64.cc
CHANGED
|
@@ -74,6 +74,22 @@ extern "C" int Trampoline12; extern "C" int TrampolineX12;
|
|
|
74
74
|
extern "C" int Trampoline13; extern "C" int TrampolineX13;
|
|
75
75
|
extern "C" int Trampoline14; extern "C" int TrampolineX14;
|
|
76
76
|
extern "C" int Trampoline15; extern "C" int TrampolineX15;
|
|
77
|
+
extern "C" int Trampoline16; extern "C" int TrampolineX16;
|
|
78
|
+
extern "C" int Trampoline17; extern "C" int TrampolineX17;
|
|
79
|
+
extern "C" int Trampoline18; extern "C" int TrampolineX18;
|
|
80
|
+
extern "C" int Trampoline19; extern "C" int TrampolineX19;
|
|
81
|
+
extern "C" int Trampoline20; extern "C" int TrampolineX20;
|
|
82
|
+
extern "C" int Trampoline21; extern "C" int TrampolineX21;
|
|
83
|
+
extern "C" int Trampoline22; extern "C" int TrampolineX22;
|
|
84
|
+
extern "C" int Trampoline23; extern "C" int TrampolineX23;
|
|
85
|
+
extern "C" int Trampoline24; extern "C" int TrampolineX24;
|
|
86
|
+
extern "C" int Trampoline25; extern "C" int TrampolineX25;
|
|
87
|
+
extern "C" int Trampoline26; extern "C" int TrampolineX26;
|
|
88
|
+
extern "C" int Trampoline27; extern "C" int TrampolineX27;
|
|
89
|
+
extern "C" int Trampoline28; extern "C" int TrampolineX28;
|
|
90
|
+
extern "C" int Trampoline29; extern "C" int TrampolineX29;
|
|
91
|
+
extern "C" int Trampoline30; extern "C" int TrampolineX30;
|
|
92
|
+
extern "C" int Trampoline31; extern "C" int TrampolineX31;
|
|
77
93
|
|
|
78
94
|
extern "C" napi_value CallSwitchStack(Napi::Function *func, size_t argc, napi_value *argv,
|
|
79
95
|
uint8_t *old_sp, Span<uint8_t> *new_stack,
|
|
@@ -95,9 +111,25 @@ static void *const Trampolines[][2] = {
|
|
|
95
111
|
{ &Trampoline12, &TrampolineX12 },
|
|
96
112
|
{ &Trampoline13, &TrampolineX13 },
|
|
97
113
|
{ &Trampoline14, &TrampolineX14 },
|
|
98
|
-
{ &Trampoline15, &TrampolineX15 }
|
|
114
|
+
{ &Trampoline15, &TrampolineX15 },
|
|
115
|
+
{ &Trampoline16, &TrampolineX16 },
|
|
116
|
+
{ &Trampoline17, &TrampolineX17 },
|
|
117
|
+
{ &Trampoline18, &TrampolineX18 },
|
|
118
|
+
{ &Trampoline19, &TrampolineX19 },
|
|
119
|
+
{ &Trampoline20, &TrampolineX20 },
|
|
120
|
+
{ &Trampoline21, &TrampolineX21 },
|
|
121
|
+
{ &Trampoline22, &TrampolineX22 },
|
|
122
|
+
{ &Trampoline23, &TrampolineX23 },
|
|
123
|
+
{ &Trampoline24, &TrampolineX24 },
|
|
124
|
+
{ &Trampoline25, &TrampolineX25 },
|
|
125
|
+
{ &Trampoline26, &TrampolineX26 },
|
|
126
|
+
{ &Trampoline27, &TrampolineX27 },
|
|
127
|
+
{ &Trampoline28, &TrampolineX28 },
|
|
128
|
+
{ &Trampoline29, &TrampolineX29 },
|
|
129
|
+
{ &Trampoline30, &TrampolineX30 },
|
|
130
|
+
{ &Trampoline31, &TrampolineX31 }
|
|
99
131
|
};
|
|
100
|
-
RG_STATIC_ASSERT(RG_LEN(Trampolines) == MaxTrampolines);
|
|
132
|
+
RG_STATIC_ASSERT(RG_LEN(Trampolines) == MaxTrampolines * 2);
|
|
101
133
|
|
|
102
134
|
static RG_THREAD_LOCAL CallData *exec_call;
|
|
103
135
|
|
|
@@ -354,10 +386,10 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
|
|
|
354
386
|
if (value.IsFunction()) {
|
|
355
387
|
Napi::Function func = value.As<Napi::Function>();
|
|
356
388
|
|
|
357
|
-
ptr = ReserveTrampoline(param.type->proto, func);
|
|
389
|
+
ptr = ReserveTrampoline(param.type->ref.proto, func);
|
|
358
390
|
if (RG_UNLIKELY(!ptr))
|
|
359
391
|
return false;
|
|
360
|
-
} else if (CheckValueTag(instance, value, param.type)) {
|
|
392
|
+
} else if (CheckValueTag(instance, value, param.type->ref.marker)) {
|
|
361
393
|
ptr = value.As<Napi::External<void>>().Data();
|
|
362
394
|
} else if (IsNullOrUndefined(value)) {
|
|
363
395
|
ptr = nullptr;
|
|
@@ -368,6 +400,8 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
|
|
|
368
400
|
|
|
369
401
|
*(void **)((param.gpr_count ? gpr_ptr : args_ptr)++) = ptr;
|
|
370
402
|
} break;
|
|
403
|
+
|
|
404
|
+
case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
|
|
371
405
|
}
|
|
372
406
|
}
|
|
373
407
|
|
|
@@ -421,6 +455,8 @@ void CallData::Execute()
|
|
|
421
455
|
case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
|
|
422
456
|
case PrimitiveKind::Float32: { result.f = PERFORM_CALL(F); } break;
|
|
423
457
|
case PrimitiveKind::Float64: { result.d = PERFORM_CALL(DD).fa0; } break;
|
|
458
|
+
|
|
459
|
+
case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
|
|
424
460
|
}
|
|
425
461
|
|
|
426
462
|
#undef PERFORM_CALL
|
|
@@ -428,10 +464,16 @@ void CallData::Execute()
|
|
|
428
464
|
|
|
429
465
|
Napi::Value CallData::Complete()
|
|
430
466
|
{
|
|
431
|
-
|
|
467
|
+
RG_DEFER {
|
|
468
|
+
PopOutArguments();
|
|
469
|
+
|
|
470
|
+
if (func->ret.type->dispose) {
|
|
471
|
+
func->ret.type->dispose(env, func->ret.type, result.ptr);
|
|
472
|
+
}
|
|
473
|
+
};
|
|
432
474
|
|
|
433
475
|
switch (func->ret.type->primitive) {
|
|
434
|
-
case PrimitiveKind::Void: return env.
|
|
476
|
+
case PrimitiveKind::Void: return env.Undefined();
|
|
435
477
|
case PrimitiveKind::Bool: return Napi::Boolean::New(env, result.u32);
|
|
436
478
|
case PrimitiveKind::Int8: return Napi::Number::New(env, (double)result.i8);
|
|
437
479
|
case PrimitiveKind::UInt8: return Napi::Number::New(env, (double)result.u8);
|
|
@@ -447,7 +489,7 @@ Napi::Value CallData::Complete()
|
|
|
447
489
|
case PrimitiveKind::Callback: {
|
|
448
490
|
if (result.ptr) {
|
|
449
491
|
Napi::External<void> external = Napi::External<void>::New(env, result.ptr);
|
|
450
|
-
SetValueTag(instance, external, func->ret.type);
|
|
492
|
+
SetValueTag(instance, external, func->ret.type->ref.marker);
|
|
451
493
|
|
|
452
494
|
return external;
|
|
453
495
|
} else {
|
|
@@ -469,6 +511,8 @@ Napi::Value CallData::Complete()
|
|
|
469
511
|
case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
|
|
470
512
|
case PrimitiveKind::Float32: return Napi::Number::New(env, (double)result.f);
|
|
471
513
|
case PrimitiveKind::Float64: return Napi::Number::New(env, result.d);
|
|
514
|
+
|
|
515
|
+
case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
|
|
472
516
|
}
|
|
473
517
|
|
|
474
518
|
RG_UNREACHABLE();
|
|
@@ -476,12 +520,10 @@ Napi::Value CallData::Complete()
|
|
|
476
520
|
|
|
477
521
|
void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegisters *out_reg)
|
|
478
522
|
{
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
if (RG_UNLIKELY(trampoline.generation != mem->generation)) {
|
|
482
|
-
ThrowError<Napi::Error>(env, "Cannot use non-persistent callback beyond FFI call");
|
|
523
|
+
if (RG_UNLIKELY(env.IsExceptionPending()))
|
|
483
524
|
return;
|
|
484
|
-
|
|
525
|
+
|
|
526
|
+
const TrampolineInfo &trampoline = instance->trampolines[idx];
|
|
485
527
|
|
|
486
528
|
const FunctionInfo *proto = trampoline.proto;
|
|
487
529
|
Napi::Function func = trampoline.func.Value();
|
|
@@ -493,6 +535,13 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
493
535
|
uint8_t *return_ptr = proto->ret.use_memory ? (uint8_t *)gpr_ptr[0] : nullptr;
|
|
494
536
|
gpr_ptr += proto->ret.use_memory;
|
|
495
537
|
|
|
538
|
+
RG_DEFER_N(err_guard) { memset(out_reg, 0, RG_SIZE(*out_reg)); };
|
|
539
|
+
|
|
540
|
+
if (RG_UNLIKELY(trampoline.generation >= 0 && trampoline.generation != (int32_t)mem->generation)) {
|
|
541
|
+
ThrowError<Napi::Error>(env, "Cannot use non-registered callback beyond FFI call");
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
|
|
496
545
|
LocalArray<napi_value, MaxParameters> arguments;
|
|
497
546
|
|
|
498
547
|
// Convert to JS arguments
|
|
@@ -562,12 +611,20 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
562
611
|
|
|
563
612
|
Napi::Value arg = str ? Napi::String::New(env, str) : env.Null();
|
|
564
613
|
arguments.Append(arg);
|
|
614
|
+
|
|
615
|
+
if (param.type->dispose) {
|
|
616
|
+
param.type->dispose(env, param.type, str);
|
|
617
|
+
}
|
|
565
618
|
} break;
|
|
566
619
|
case PrimitiveKind::String16: {
|
|
567
620
|
const char16_t *str16 = *(const char16_t **)((param.gpr_count ? gpr_ptr : args_ptr)++);
|
|
568
621
|
|
|
569
622
|
Napi::Value arg = str16 ? Napi::String::New(env, str16) : env.Null();
|
|
570
623
|
arguments.Append(arg);
|
|
624
|
+
|
|
625
|
+
if (param.type->dispose) {
|
|
626
|
+
param.type->dispose(env, param.type, str16);
|
|
627
|
+
}
|
|
571
628
|
} break;
|
|
572
629
|
case PrimitiveKind::Pointer:
|
|
573
630
|
case PrimitiveKind::Callback: {
|
|
@@ -575,12 +632,16 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
575
632
|
|
|
576
633
|
if (ptr2) {
|
|
577
634
|
Napi::External<void> external = Napi::External<void>::New(env, ptr2);
|
|
578
|
-
SetValueTag(instance, external, param.type);
|
|
635
|
+
SetValueTag(instance, external, param.type->ref.marker);
|
|
579
636
|
|
|
580
637
|
arguments.Append(external);
|
|
581
638
|
} else {
|
|
582
639
|
arguments.Append(env.Null());
|
|
583
640
|
}
|
|
641
|
+
|
|
642
|
+
if (param.type->dispose) {
|
|
643
|
+
param.type->dispose(env, param.type, ptr2);
|
|
644
|
+
}
|
|
584
645
|
} break;
|
|
585
646
|
case PrimitiveKind::Record: {
|
|
586
647
|
if (!param.use_memory) {
|
|
@@ -640,6 +701,8 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
640
701
|
Napi::Value arg = Napi::Number::New(env, d);
|
|
641
702
|
arguments.Append(arg);
|
|
642
703
|
} break;
|
|
704
|
+
|
|
705
|
+
case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
|
|
643
706
|
}
|
|
644
707
|
}
|
|
645
708
|
|
|
@@ -650,6 +713,9 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
650
713
|
[](Napi::Function *func, size_t argc, napi_value *argv) { return (napi_value)func->Call(argc, argv); });
|
|
651
714
|
Napi::Value value(env, ret);
|
|
652
715
|
|
|
716
|
+
if (RG_UNLIKELY(env.IsExceptionPending()))
|
|
717
|
+
return;
|
|
718
|
+
|
|
653
719
|
// Convert the result
|
|
654
720
|
switch (type->primitive) {
|
|
655
721
|
case PrimitiveKind::Void: {} break;
|
|
@@ -711,14 +777,14 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
711
777
|
case PrimitiveKind::Pointer: {
|
|
712
778
|
uint8_t *ptr;
|
|
713
779
|
|
|
714
|
-
if (CheckValueTag(instance, value, type)) {
|
|
780
|
+
if (CheckValueTag(instance, value, type->ref.marker)) {
|
|
715
781
|
ptr = value.As<Napi::External<uint8_t>>().Data();
|
|
716
|
-
} else if (IsObject(value) && type->ref->primitive == PrimitiveKind::Record) {
|
|
782
|
+
} else if (IsObject(value) && type->ref.type->primitive == PrimitiveKind::Record) {
|
|
717
783
|
Napi::Object obj = value.As<Napi::Object>();
|
|
718
784
|
|
|
719
|
-
ptr = AllocHeap(type->ref->size, 16);
|
|
785
|
+
ptr = AllocHeap(type->ref.type->size, 16);
|
|
720
786
|
|
|
721
|
-
if (!PushObject(obj, type->ref, ptr))
|
|
787
|
+
if (!PushObject(obj, type->ref.type, ptr))
|
|
722
788
|
return;
|
|
723
789
|
} else if (IsNullOrUndefined(value)) {
|
|
724
790
|
ptr = nullptr;
|
|
@@ -773,10 +839,10 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
773
839
|
if (value.IsFunction()) {
|
|
774
840
|
Napi::Function func2 = value.As<Napi::Function>();
|
|
775
841
|
|
|
776
|
-
ptr = ReserveTrampoline(type->proto, func2);
|
|
842
|
+
ptr = ReserveTrampoline(type->ref.proto, func2);
|
|
777
843
|
if (RG_UNLIKELY(!ptr))
|
|
778
844
|
return;
|
|
779
|
-
} else if (CheckValueTag(instance, value, type)) {
|
|
845
|
+
} else if (CheckValueTag(instance, value, type->ref.marker)) {
|
|
780
846
|
ptr = value.As<Napi::External<uint8_t>>().Data();
|
|
781
847
|
} else if (IsNullOrUndefined(value)) {
|
|
782
848
|
ptr = nullptr;
|
|
@@ -787,7 +853,11 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
787
853
|
|
|
788
854
|
out_reg->a0 = (uint64_t)ptr;
|
|
789
855
|
} break;
|
|
856
|
+
|
|
857
|
+
case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
|
|
790
858
|
}
|
|
859
|
+
|
|
860
|
+
err_guard.Disable();
|
|
791
861
|
}
|
|
792
862
|
|
|
793
863
|
void *GetTrampoline(Size idx, const FunctionInfo *proto)
|
package/src/abi_riscv64_fwd.S
CHANGED
|
@@ -152,6 +152,22 @@ ForwardCallXDD:
|
|
|
152
152
|
.global Trampoline13
|
|
153
153
|
.global Trampoline14
|
|
154
154
|
.global Trampoline15
|
|
155
|
+
.global Trampoline16
|
|
156
|
+
.global Trampoline17
|
|
157
|
+
.global Trampoline18
|
|
158
|
+
.global Trampoline19
|
|
159
|
+
.global Trampoline20
|
|
160
|
+
.global Trampoline21
|
|
161
|
+
.global Trampoline22
|
|
162
|
+
.global Trampoline23
|
|
163
|
+
.global Trampoline24
|
|
164
|
+
.global Trampoline25
|
|
165
|
+
.global Trampoline26
|
|
166
|
+
.global Trampoline27
|
|
167
|
+
.global Trampoline28
|
|
168
|
+
.global Trampoline29
|
|
169
|
+
.global Trampoline30
|
|
170
|
+
.global Trampoline31
|
|
155
171
|
.global TrampolineX0
|
|
156
172
|
.global TrampolineX1
|
|
157
173
|
.global TrampolineX2
|
|
@@ -168,6 +184,22 @@ ForwardCallXDD:
|
|
|
168
184
|
.global TrampolineX13
|
|
169
185
|
.global TrampolineX14
|
|
170
186
|
.global TrampolineX15
|
|
187
|
+
.global TrampolineX16
|
|
188
|
+
.global TrampolineX17
|
|
189
|
+
.global TrampolineX18
|
|
190
|
+
.global TrampolineX19
|
|
191
|
+
.global TrampolineX20
|
|
192
|
+
.global TrampolineX21
|
|
193
|
+
.global TrampolineX22
|
|
194
|
+
.global TrampolineX23
|
|
195
|
+
.global TrampolineX24
|
|
196
|
+
.global TrampolineX25
|
|
197
|
+
.global TrampolineX26
|
|
198
|
+
.global TrampolineX27
|
|
199
|
+
.global TrampolineX28
|
|
200
|
+
.global TrampolineX29
|
|
201
|
+
.global TrampolineX30
|
|
202
|
+
.global TrampolineX31
|
|
171
203
|
.global RelayCallback
|
|
172
204
|
.global CallSwitchStack
|
|
173
205
|
|
|
@@ -265,6 +297,38 @@ Trampoline14:
|
|
|
265
297
|
trampoline 14
|
|
266
298
|
Trampoline15:
|
|
267
299
|
trampoline 15
|
|
300
|
+
Trampoline16:
|
|
301
|
+
trampoline 16
|
|
302
|
+
Trampoline17:
|
|
303
|
+
trampoline 17
|
|
304
|
+
Trampoline18:
|
|
305
|
+
trampoline 18
|
|
306
|
+
Trampoline19:
|
|
307
|
+
trampoline 19
|
|
308
|
+
Trampoline20:
|
|
309
|
+
trampoline 20
|
|
310
|
+
Trampoline21:
|
|
311
|
+
trampoline 21
|
|
312
|
+
Trampoline22:
|
|
313
|
+
trampoline 22
|
|
314
|
+
Trampoline23:
|
|
315
|
+
trampoline 23
|
|
316
|
+
Trampoline24:
|
|
317
|
+
trampoline 24
|
|
318
|
+
Trampoline25:
|
|
319
|
+
trampoline 25
|
|
320
|
+
Trampoline26:
|
|
321
|
+
trampoline 26
|
|
322
|
+
Trampoline27:
|
|
323
|
+
trampoline 27
|
|
324
|
+
Trampoline28:
|
|
325
|
+
trampoline 28
|
|
326
|
+
Trampoline29:
|
|
327
|
+
trampoline 29
|
|
328
|
+
Trampoline30:
|
|
329
|
+
trampoline 30
|
|
330
|
+
Trampoline31:
|
|
331
|
+
trampoline 31
|
|
268
332
|
|
|
269
333
|
TrampolineX0:
|
|
270
334
|
trampoline_vec 0
|
|
@@ -298,6 +362,38 @@ TrampolineX14:
|
|
|
298
362
|
trampoline_vec 14
|
|
299
363
|
TrampolineX15:
|
|
300
364
|
trampoline_vec 15
|
|
365
|
+
TrampolineX16:
|
|
366
|
+
trampoline_vec 16
|
|
367
|
+
TrampolineX17:
|
|
368
|
+
trampoline_vec 17
|
|
369
|
+
TrampolineX18:
|
|
370
|
+
trampoline_vec 18
|
|
371
|
+
TrampolineX19:
|
|
372
|
+
trampoline_vec 19
|
|
373
|
+
TrampolineX20:
|
|
374
|
+
trampoline_vec 20
|
|
375
|
+
TrampolineX21:
|
|
376
|
+
trampoline_vec 21
|
|
377
|
+
TrampolineX22:
|
|
378
|
+
trampoline_vec 22
|
|
379
|
+
TrampolineX23:
|
|
380
|
+
trampoline_vec 23
|
|
381
|
+
TrampolineX24:
|
|
382
|
+
trampoline_vec 24
|
|
383
|
+
TrampolineX25:
|
|
384
|
+
trampoline_vec 25
|
|
385
|
+
TrampolineX26:
|
|
386
|
+
trampoline_vec 26
|
|
387
|
+
TrampolineX27:
|
|
388
|
+
trampoline_vec 27
|
|
389
|
+
TrampolineX28:
|
|
390
|
+
trampoline_vec 28
|
|
391
|
+
TrampolineX29:
|
|
392
|
+
trampoline_vec 29
|
|
393
|
+
TrampolineX30:
|
|
394
|
+
trampoline_vec 30
|
|
395
|
+
TrampolineX31:
|
|
396
|
+
trampoline_vec 31
|
|
301
397
|
|
|
302
398
|
# When a callback is relayed, Koffi will call into Node.js and V8 to execute Javascript.
|
|
303
399
|
# The problem is that we're still running on the separate Koffi stack, and V8 will
|