koffi 1.1.2 → 1.1.5
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 +23 -19
- package/README.md +16 -27
- package/benchmark/CMakeLists.txt +11 -3
- package/benchmark/raylib_cc.cc +9 -9
- package/build/qemu/1.1.5/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/1.1.5/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/1.1.5/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/1.1.5/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/1.1.5/koffi_linux_arm.tar.gz +0 -0
- package/build/qemu/1.1.5/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/1.1.5/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/1.1.5/koffi_linux_riscv64.tar.gz +0 -0
- package/build/qemu/1.1.5/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/1.1.5/koffi_openbsd_ia32.tar.gz +0 -0
- package/build/qemu/1.1.5/koffi_openbsd_x64.tar.gz +0 -0
- package/build/qemu/1.1.5/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/1.1.5/koffi_win32_x64.tar.gz +0 -0
- package/package.json +2 -2
- package/qemu/qemu.js +18 -10
- package/qemu/registry/machines.json +138 -3
- package/qemu/registry/sha256sum.txt +27 -12
- package/src/abi_arm32.cc +29 -16
- package/src/abi_arm32_fwd.S +1 -1
- package/src/abi_arm64.cc +33 -17
- package/src/abi_arm64_fwd.S +1 -1
- package/src/abi_arm64_fwd.asm +107 -0
- package/src/abi_riscv64.cc +468 -0
- package/src/abi_riscv64_fwd.S +129 -0
- package/src/abi_x64_sysv.cc +9 -10
- package/src/abi_x64_sysv_fwd.S +113 -1
- package/src/abi_x64_win.cc +5 -8
- package/src/abi_x86.cc +11 -6
- package/src/call.cc +6 -18
- package/src/call.hh +13 -23
- package/src/ffi.cc +87 -25
- package/src/ffi.hh +14 -4
- package/src/parser.cc +18 -6
- package/src/util.cc +26 -57
- package/src/util.hh +17 -1
- package/test/CMakeLists.txt +4 -1
- package/test/misc.c +34 -0
- package/vendor/_patches/glfw_001_fix_openbsd_xlib_soname.patch +145 -0
- package/vendor/libcc/libcc.cc +7 -7
- package/vendor/libcc/libcc.hh +8 -2
- package/vendor/raylib/src/external/glfw/src/egl_context.c +6 -0
- package/vendor/raylib/src/external/glfw/src/osmesa_context.c +2 -0
- package/vendor/raylib/src/external/glfw/src/vulkan.c +2 -0
- package/vendor/raylib/src/external/glfw/src/x11_init.c +20 -0
- package/build/qemu/1.1.2/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/1.1.2/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/1.1.2/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/1.1.2/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/1.1.2/koffi_linux_arm.tar.gz +0 -0
- package/build/qemu/1.1.2/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/1.1.2/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/1.1.2/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/1.1.2/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/1.1.2/koffi_win32_x64.tar.gz +0 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// This program is free software: you can redistribute it and/or modify
|
|
2
|
+
// it under the terms of the GNU Affero General Public License as published by
|
|
3
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
4
|
+
// (at your option) any later version.
|
|
5
|
+
//
|
|
6
|
+
// This program is distributed in the hope that it will be useful,
|
|
7
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
8
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
9
|
+
// GNU Affero General Public License for more details.
|
|
10
|
+
//
|
|
11
|
+
// You should have received a copy of the GNU Affero General Public License
|
|
12
|
+
// along with this program. If not, see https://www.gnu.org/licenses/.
|
|
13
|
+
|
|
14
|
+
// These three are the same, but they differ (in the C side) by their return type.
|
|
15
|
+
// Unlike the three next functions, these ones don't forward FA argument registers.
|
|
16
|
+
.global ForwardCallGG
|
|
17
|
+
.global ForwardCallF
|
|
18
|
+
.global ForwardCallDG
|
|
19
|
+
.global ForwardCallGD
|
|
20
|
+
.global ForwardCallDD
|
|
21
|
+
|
|
22
|
+
// The X variants are slightly slower, and are used when FA arguments must be forwarded.
|
|
23
|
+
.global ForwardCallXGG
|
|
24
|
+
.global ForwardCallXF
|
|
25
|
+
.global ForwardCallXDG
|
|
26
|
+
.global ForwardCallXGD
|
|
27
|
+
.global ForwardCallXDD
|
|
28
|
+
|
|
29
|
+
// Copy function pointer to t0, in order to save it through argument forwarding.
|
|
30
|
+
// Save SP in s1, and use carefully assembled stack provided by caller.
|
|
31
|
+
.macro prologue
|
|
32
|
+
addi sp, sp, -16
|
|
33
|
+
mv t0, a0
|
|
34
|
+
sd ra, 0(sp)
|
|
35
|
+
sd s1, 8(sp)
|
|
36
|
+
mv s1, sp
|
|
37
|
+
addi sp, a1, 128
|
|
38
|
+
.endm
|
|
39
|
+
|
|
40
|
+
// Call native function.
|
|
41
|
+
// Once done, restore normal stack pointer and return.
|
|
42
|
+
// The return value is passed untouched through registers.
|
|
43
|
+
.macro epilogue
|
|
44
|
+
jalr t0
|
|
45
|
+
mv sp, s1
|
|
46
|
+
ld ra, 0(sp)
|
|
47
|
+
ld s1, 8(sp)
|
|
48
|
+
addi sp, sp, 16
|
|
49
|
+
ret
|
|
50
|
+
.endm
|
|
51
|
+
|
|
52
|
+
// Prepare general purpose argument registers from array passed by caller.
|
|
53
|
+
.macro forward_int
|
|
54
|
+
ld a7, 120(a1)
|
|
55
|
+
ld a6, 112(a1)
|
|
56
|
+
ld a5, 104(a1)
|
|
57
|
+
ld a4, 96(a1)
|
|
58
|
+
ld a3, 88(a1)
|
|
59
|
+
ld a2, 80(a1)
|
|
60
|
+
ld a0, 64(a1)
|
|
61
|
+
ld a1, 72(a1)
|
|
62
|
+
.endm
|
|
63
|
+
|
|
64
|
+
// Prepare vector argument registers from array passed by caller.
|
|
65
|
+
.macro forward_vec
|
|
66
|
+
fld fa7, 56(a1)
|
|
67
|
+
fld fa6, 48(a1)
|
|
68
|
+
fld fa5, 40(a1)
|
|
69
|
+
fld fa4, 32(a1)
|
|
70
|
+
fld fa3, 24(a1)
|
|
71
|
+
fld fa2, 16(a1)
|
|
72
|
+
fld fa1, 8(a1)
|
|
73
|
+
fld fa0, 0(a1)
|
|
74
|
+
.endm
|
|
75
|
+
|
|
76
|
+
ForwardCallGG:
|
|
77
|
+
prologue
|
|
78
|
+
forward_int
|
|
79
|
+
epilogue
|
|
80
|
+
|
|
81
|
+
ForwardCallF:
|
|
82
|
+
prologue
|
|
83
|
+
forward_int
|
|
84
|
+
epilogue
|
|
85
|
+
|
|
86
|
+
ForwardCallDG:
|
|
87
|
+
prologue
|
|
88
|
+
forward_int
|
|
89
|
+
epilogue
|
|
90
|
+
|
|
91
|
+
ForwardCallGD:
|
|
92
|
+
prologue
|
|
93
|
+
forward_int
|
|
94
|
+
epilogue
|
|
95
|
+
|
|
96
|
+
ForwardCallDD:
|
|
97
|
+
prologue
|
|
98
|
+
forward_int
|
|
99
|
+
epilogue
|
|
100
|
+
|
|
101
|
+
ForwardCallXGG:
|
|
102
|
+
prologue
|
|
103
|
+
forward_vec
|
|
104
|
+
forward_int
|
|
105
|
+
epilogue
|
|
106
|
+
|
|
107
|
+
ForwardCallXF:
|
|
108
|
+
prologue
|
|
109
|
+
forward_vec
|
|
110
|
+
forward_int
|
|
111
|
+
epilogue
|
|
112
|
+
|
|
113
|
+
ForwardCallXDG:
|
|
114
|
+
prologue
|
|
115
|
+
forward_vec
|
|
116
|
+
forward_int
|
|
117
|
+
epilogue
|
|
118
|
+
|
|
119
|
+
ForwardCallXGD:
|
|
120
|
+
prologue
|
|
121
|
+
forward_vec
|
|
122
|
+
forward_int
|
|
123
|
+
epilogue
|
|
124
|
+
|
|
125
|
+
ForwardCallXDD:
|
|
126
|
+
prologue
|
|
127
|
+
forward_vec
|
|
128
|
+
forward_int
|
|
129
|
+
epilogue
|
package/src/abi_x64_sysv.cc
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// You should have received a copy of the GNU Affero General Public License
|
|
12
12
|
// along with this program. If not, see https://www.gnu.org/licenses/.
|
|
13
13
|
|
|
14
|
-
#if defined(__x86_64__) && !defined(
|
|
14
|
+
#if defined(__x86_64__) && !defined(_WIN32)
|
|
15
15
|
|
|
16
16
|
#include "vendor/libcc/libcc.hh"
|
|
17
17
|
#include "ffi.hh"
|
|
@@ -165,7 +165,7 @@ static void AnalyseParameter(ParameterInfo *param, int gpr_avail, int xmm_avail)
|
|
|
165
165
|
xmm_count += (cls == RegisterClass::SSE);
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
if (gpr_count <= gpr_avail && xmm_count <= xmm_avail){
|
|
168
|
+
if (gpr_count <= gpr_avail && xmm_count <= xmm_avail) {
|
|
169
169
|
param->gpr_count = (int8_t)gpr_count;
|
|
170
170
|
param->xmm_count = (int8_t)xmm_count;
|
|
171
171
|
param->gpr_first = (classes[0] == RegisterClass::Integer);
|
|
@@ -420,8 +420,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
|
|
|
420
420
|
}
|
|
421
421
|
}
|
|
422
422
|
|
|
423
|
-
|
|
424
|
-
heap = MakeSpan(old_heap_mem.ptr, mem->heap.ptr - old_heap_mem.ptr);
|
|
423
|
+
sp = mem->stack.end();
|
|
425
424
|
|
|
426
425
|
return true;
|
|
427
426
|
}
|
|
@@ -430,8 +429,8 @@ void CallData::Execute()
|
|
|
430
429
|
{
|
|
431
430
|
#define PERFORM_CALL(Suffix) \
|
|
432
431
|
([&]() { \
|
|
433
|
-
auto ret = (func->forward_fp ? ForwardCallX ## Suffix(func->func,
|
|
434
|
-
: ForwardCall ## Suffix(func->func,
|
|
432
|
+
auto ret = (func->forward_fp ? ForwardCallX ## Suffix(func->func, sp) \
|
|
433
|
+
: ForwardCall ## Suffix(func->func, sp)); \
|
|
435
434
|
return ret; \
|
|
436
435
|
})()
|
|
437
436
|
|
|
@@ -453,16 +452,16 @@ void CallData::Execute()
|
|
|
453
452
|
case PrimitiveKind::Record: {
|
|
454
453
|
if (func->ret.gpr_first && !func->ret.xmm_count) {
|
|
455
454
|
RaxRdxRet ret = PERFORM_CALL(GG);
|
|
456
|
-
|
|
455
|
+
memcpy(&result.buf, &ret, RG_SIZE(ret));
|
|
457
456
|
} else if (func->ret.gpr_first) {
|
|
458
457
|
RaxXmm0Ret ret = PERFORM_CALL(GD);
|
|
459
|
-
|
|
458
|
+
memcpy(&result.buf, &ret, RG_SIZE(ret));
|
|
460
459
|
} else if (func->ret.xmm_count == 2) {
|
|
461
460
|
Xmm0Xmm1Ret ret = PERFORM_CALL(DD);
|
|
462
|
-
|
|
461
|
+
memcpy(&result.buf, &ret, RG_SIZE(ret));
|
|
463
462
|
} else {
|
|
464
463
|
Xmm0RaxRet ret = PERFORM_CALL(DG);
|
|
465
|
-
|
|
464
|
+
memcpy(&result.buf, &ret, RG_SIZE(ret));
|
|
466
465
|
}
|
|
467
466
|
} break;
|
|
468
467
|
case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
|
package/src/abi_x64_sysv_fwd.S
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
8
8
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
9
9
|
// GNU Affero General Public License for more details.
|
|
10
|
-
|
|
10
|
+
//
|
|
11
11
|
// You should have received a copy of the GNU Affero General Public License
|
|
12
12
|
// along with this program. If not, see https://www.gnu.org/licenses/.
|
|
13
13
|
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
#define SYMBOL(Symbol) Symbol
|
|
18
18
|
#endif
|
|
19
19
|
|
|
20
|
+
// Forward
|
|
21
|
+
|
|
20
22
|
// These five are the same, but they differ (in the C side) by their return type.
|
|
21
23
|
// Unlike the five next functions, these ones don't forward XMM argument registers.
|
|
22
24
|
.global SYMBOL(ForwardCallGG)
|
|
@@ -144,3 +146,113 @@ SYMBOL(ForwardCallXDD):
|
|
|
144
146
|
forward_int
|
|
145
147
|
movb $8, %al
|
|
146
148
|
epilogue
|
|
149
|
+
|
|
150
|
+
// Callbacks
|
|
151
|
+
|
|
152
|
+
.global SYMBOL(CallBack0)
|
|
153
|
+
.global SYMBOL(CallBack1)
|
|
154
|
+
.global SYMBOL(CallBack2)
|
|
155
|
+
.global SYMBOL(CallBack3)
|
|
156
|
+
.global SYMBOL(CallBack4)
|
|
157
|
+
.global SYMBOL(CallBack5)
|
|
158
|
+
.global SYMBOL(CallBack6)
|
|
159
|
+
.global SYMBOL(CallBack7)
|
|
160
|
+
.global SYMBOL(CallBackX0)
|
|
161
|
+
.global SYMBOL(CallBackX1)
|
|
162
|
+
.global SYMBOL(CallBackX2)
|
|
163
|
+
.global SYMBOL(CallBackX3)
|
|
164
|
+
.global SYMBOL(CallBackX4)
|
|
165
|
+
.global SYMBOL(CallBackX5)
|
|
166
|
+
.global SYMBOL(CallBackX6)
|
|
167
|
+
.global SYMBOL(CallBackX7)
|
|
168
|
+
.global SYMBOL(RelayCallBack)
|
|
169
|
+
|
|
170
|
+
.macro jumper id
|
|
171
|
+
.cfi_startproc
|
|
172
|
+
.cfi_def_cfa rsp, 8
|
|
173
|
+
endbr64
|
|
174
|
+
subq $152, %rsp
|
|
175
|
+
.cfi_def_cfa rsp, 160
|
|
176
|
+
movq %rdi, 0(%rsp)
|
|
177
|
+
movq %rsi, 8(%rsp)
|
|
178
|
+
movq %rdx, 16(%rsp)
|
|
179
|
+
movq %rcx, 24(%rsp)
|
|
180
|
+
movq %r8, 32(%rsp)
|
|
181
|
+
movq %r9, 40(%rsp)
|
|
182
|
+
leaq 112(%rsp), %rdi
|
|
183
|
+
movq $\id, %rsi
|
|
184
|
+
movq %rsp, %rdx
|
|
185
|
+
call SYMBOL(RelayCallBack)
|
|
186
|
+
movq 8(%rax), %rdx
|
|
187
|
+
movq 0(%rax), %rax
|
|
188
|
+
addq $152, %rsp
|
|
189
|
+
ret
|
|
190
|
+
.cfi_endproc
|
|
191
|
+
.endm
|
|
192
|
+
|
|
193
|
+
.macro jumperx id
|
|
194
|
+
.cfi_startproc
|
|
195
|
+
.cfi_def_cfa rsp, 8
|
|
196
|
+
endbr64
|
|
197
|
+
subq $152, %rsp
|
|
198
|
+
.cfi_def_cfa rsp, 160
|
|
199
|
+
movq %rdi, 0(%rsp)
|
|
200
|
+
movq %rsi, 8(%rsp)
|
|
201
|
+
movq %rdx, 16(%rsp)
|
|
202
|
+
movq %rcx, 24(%rsp)
|
|
203
|
+
movq %r8, 32(%rsp)
|
|
204
|
+
movq %r9, 40(%rsp)
|
|
205
|
+
movsd %xmm0, 48(%rsp)
|
|
206
|
+
movsd %xmm1, 56(%rsp)
|
|
207
|
+
movsd %xmm2, 64(%rsp)
|
|
208
|
+
movsd %xmm3, 72(%rsp)
|
|
209
|
+
movsd %xmm4, 80(%rsp)
|
|
210
|
+
movsd %xmm5, 88(%rsp)
|
|
211
|
+
movsd %xmm6, 96(%rsp)
|
|
212
|
+
movsd %xmm7, 104(%rsp)
|
|
213
|
+
leaq 112(%rsp), %rdi
|
|
214
|
+
movq $\id, %rsi
|
|
215
|
+
movq %rsp, %rdx
|
|
216
|
+
call SYMBOL(RelayCallBack)
|
|
217
|
+
movsd 16(%rax), %xmm0
|
|
218
|
+
movsd 24(%rax), %xmm1
|
|
219
|
+
movq 8(%rax), %rdx
|
|
220
|
+
movq 0(%rax), %rax
|
|
221
|
+
addq $152, %rsp
|
|
222
|
+
ret
|
|
223
|
+
.cfi_endproc
|
|
224
|
+
.endm
|
|
225
|
+
|
|
226
|
+
SYMBOL(CallBack0):
|
|
227
|
+
jumper 0
|
|
228
|
+
SYMBOL(CallBack1):
|
|
229
|
+
jumper 1
|
|
230
|
+
SYMBOL(CallBack2):
|
|
231
|
+
jumper 2
|
|
232
|
+
SYMBOL(CallBack3):
|
|
233
|
+
jumper 3
|
|
234
|
+
SYMBOL(CallBack4):
|
|
235
|
+
jumper 4
|
|
236
|
+
SYMBOL(CallBack5):
|
|
237
|
+
jumper 5
|
|
238
|
+
SYMBOL(CallBack6):
|
|
239
|
+
jumper 6
|
|
240
|
+
SYMBOL(CallBack7):
|
|
241
|
+
jumper 7
|
|
242
|
+
|
|
243
|
+
SYMBOL(CallBackX0):
|
|
244
|
+
jumperx 0
|
|
245
|
+
SYMBOL(CallBackX1):
|
|
246
|
+
jumperx 1
|
|
247
|
+
SYMBOL(CallBackX2):
|
|
248
|
+
jumperx 2
|
|
249
|
+
SYMBOL(CallBackX3):
|
|
250
|
+
jumperx 3
|
|
251
|
+
SYMBOL(CallBackX4):
|
|
252
|
+
jumperx 4
|
|
253
|
+
SYMBOL(CallBackX5):
|
|
254
|
+
jumperx 5
|
|
255
|
+
SYMBOL(CallBackX6):
|
|
256
|
+
jumperx 6
|
|
257
|
+
SYMBOL(CallBackX7):
|
|
258
|
+
jumperx 7
|
package/src/abi_x64_win.cc
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// You should have received a copy of the GNU Affero General Public License
|
|
12
12
|
// along with this program. If not, see https://www.gnu.org/licenses/.
|
|
13
13
|
|
|
14
|
-
#
|
|
14
|
+
#if defined(_WIN32) && (defined(__x86_64__) || defined(_M_AMD64))
|
|
15
15
|
|
|
16
16
|
#include "vendor/libcc/libcc.hh"
|
|
17
17
|
#include "ffi.hh"
|
|
@@ -41,9 +41,7 @@ bool AnalyseFunction(InstanceData *, FunctionInfo *func)
|
|
|
41
41
|
|
|
42
42
|
for (ParameterInfo ¶m: func->parameters) {
|
|
43
43
|
param.regular = IsRegular(param.type->size);
|
|
44
|
-
|
|
45
|
-
func->forward_fp |= (param.type->primitive == PrimitiveKind::Float32 ||
|
|
46
|
-
param.type->primitive == PrimitiveKind::Float64);
|
|
44
|
+
func->forward_fp |= IsFloat(param.type);
|
|
47
45
|
}
|
|
48
46
|
|
|
49
47
|
func->args_size = AlignLen(8 * std::max((Size)4, func->parameters.len + !func->ret.regular), 16);
|
|
@@ -204,8 +202,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
|
|
|
204
202
|
}
|
|
205
203
|
}
|
|
206
204
|
|
|
207
|
-
|
|
208
|
-
heap = MakeSpan(old_heap_mem.ptr, mem->heap.ptr - old_heap_mem.ptr);
|
|
205
|
+
sp = mem->stack.end();
|
|
209
206
|
|
|
210
207
|
return true;
|
|
211
208
|
}
|
|
@@ -214,8 +211,8 @@ void CallData::Execute()
|
|
|
214
211
|
{
|
|
215
212
|
#define PERFORM_CALL(Suffix) \
|
|
216
213
|
([&]() { \
|
|
217
|
-
auto ret = (func->forward_fp ? ForwardCallX ## Suffix(func->func,
|
|
218
|
-
: ForwardCall ## Suffix(func->func,
|
|
214
|
+
auto ret = (func->forward_fp ? ForwardCallX ## Suffix(func->func, sp) \
|
|
215
|
+
: ForwardCall ## Suffix(func->func, sp)); \
|
|
219
216
|
return ret; \
|
|
220
217
|
})()
|
|
221
218
|
|
package/src/abi_x86.cc
CHANGED
|
@@ -37,7 +37,9 @@ static inline bool IsRegular(Size size)
|
|
|
37
37
|
|
|
38
38
|
bool AnalyseFunction(InstanceData *instance, FunctionInfo *func)
|
|
39
39
|
{
|
|
40
|
-
int fast = (func->convention == CallConvention::Fastcall) ? 2 :
|
|
40
|
+
int fast = (func->convention == CallConvention::Fastcall) ? 2 :
|
|
41
|
+
(func->convention == CallConvention::Thiscall) ? 1 : 0;
|
|
42
|
+
func->fast = fast;
|
|
41
43
|
|
|
42
44
|
if (func->ret.type->primitive != PrimitiveKind::Record) {
|
|
43
45
|
func->ret.trivial = true;
|
|
@@ -77,6 +79,10 @@ bool AnalyseFunction(InstanceData *instance, FunctionInfo *func)
|
|
|
77
79
|
func->decorated_name = Fmt(&instance->str_alloc, "@%1@%2", func->name, params_size).ptr;
|
|
78
80
|
func->args_size += 16;
|
|
79
81
|
} break;
|
|
82
|
+
case CallConvention::Thiscall: {
|
|
83
|
+
RG_ASSERT(!func->variadic);
|
|
84
|
+
func->args_size += 16;
|
|
85
|
+
} break;
|
|
80
86
|
}
|
|
81
87
|
|
|
82
88
|
return true;
|
|
@@ -90,7 +96,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
|
|
|
90
96
|
// Pass return value in register or through memory
|
|
91
97
|
if (RG_UNLIKELY(!AllocStack(func->args_size, 16, &args_ptr)))
|
|
92
98
|
return false;
|
|
93
|
-
if (func->
|
|
99
|
+
if (func->fast) {
|
|
94
100
|
fast_ptr = args_ptr;
|
|
95
101
|
args_ptr += 4;
|
|
96
102
|
}
|
|
@@ -249,8 +255,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
|
|
|
249
255
|
}
|
|
250
256
|
}
|
|
251
257
|
|
|
252
|
-
|
|
253
|
-
heap = MakeSpan(old_heap_mem.ptr, mem->heap.ptr - old_heap_mem.ptr);
|
|
258
|
+
sp = mem->stack.end();
|
|
254
259
|
|
|
255
260
|
return true;
|
|
256
261
|
}
|
|
@@ -259,8 +264,8 @@ void CallData::Execute()
|
|
|
259
264
|
{
|
|
260
265
|
#define PERFORM_CALL(Suffix) \
|
|
261
266
|
([&]() { \
|
|
262
|
-
auto ret = (func->
|
|
263
|
-
|
|
267
|
+
auto ret = (func->fast ? ForwardCallR ## Suffix(func->func, sp) \
|
|
268
|
+
: ForwardCall ## Suffix(func->func, sp)); \
|
|
264
269
|
return ret; \
|
|
265
270
|
})()
|
|
266
271
|
|
package/src/call.cc
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
namespace RG {
|
|
22
22
|
|
|
23
23
|
CallData::CallData(Napi::Env env, InstanceData *instance, const FunctionInfo *func, InstanceMemory *mem)
|
|
24
|
-
: env(env), instance(instance), func(func),
|
|
24
|
+
: env(env), instance(instance), func(func),
|
|
25
25
|
mem(mem), old_stack_mem(mem->stack), old_heap_mem(mem->heap)
|
|
26
26
|
{
|
|
27
27
|
mem->depth++;
|
|
@@ -565,13 +565,11 @@ void CallData::PopObject(Napi::Object obj, const uint8_t *src, const TypeInfo *t
|
|
|
565
565
|
obj.Set(member.name, value);
|
|
566
566
|
} break;
|
|
567
567
|
case PrimitiveKind::Float32: {
|
|
568
|
-
float f;
|
|
569
|
-
memcpy(&f, src, 4);
|
|
568
|
+
float f = *(float *)src;
|
|
570
569
|
obj.Set(member.name, Napi::Number::New(env, (double)f));
|
|
571
570
|
} break;
|
|
572
571
|
case PrimitiveKind::Float64: {
|
|
573
|
-
double d;
|
|
574
|
-
memcpy(&d, src, 8);
|
|
572
|
+
double d = *(double *)src;
|
|
575
573
|
obj.Set(member.name, Napi::Number::New(env, d));
|
|
576
574
|
} break;
|
|
577
575
|
}
|
|
@@ -762,19 +760,6 @@ Napi::Value CallData::PopArray(const uint8_t *src, const TypeInfo *type, int16_t
|
|
|
762
760
|
RG_UNREACHABLE();
|
|
763
761
|
}
|
|
764
762
|
|
|
765
|
-
Napi::Value CallData::Run(const Napi::CallbackInfo &info)
|
|
766
|
-
{
|
|
767
|
-
if (!RG_UNLIKELY(Prepare(info)))
|
|
768
|
-
return env.Null();
|
|
769
|
-
|
|
770
|
-
if (debug) {
|
|
771
|
-
DumpDebug();
|
|
772
|
-
}
|
|
773
|
-
Execute();
|
|
774
|
-
|
|
775
|
-
return Complete();
|
|
776
|
-
}
|
|
777
|
-
|
|
778
763
|
static void DumpMemory(const char *type, Span<const uint8_t> bytes)
|
|
779
764
|
{
|
|
780
765
|
if (bytes.len) {
|
|
@@ -805,6 +790,9 @@ void CallData::DumpDebug() const
|
|
|
805
790
|
}
|
|
806
791
|
PrintLn(stderr, "Return: %1 (%2)", func->ret.type->name, FmtMemSize(func->ret.type->size));
|
|
807
792
|
|
|
793
|
+
Span<const uint8_t> stack = MakeSpan(mem->stack.end(), old_stack_mem.end() - mem->stack.end());
|
|
794
|
+
Span<const uint8_t> heap = MakeSpan(old_heap_mem.ptr, mem->heap.ptr - old_heap_mem.ptr);
|
|
795
|
+
|
|
808
796
|
DumpMemory("Stack", stack);
|
|
809
797
|
DumpMemory("Heap", heap);
|
|
810
798
|
}
|
package/src/call.hh
CHANGED
|
@@ -34,16 +34,12 @@ class CallData {
|
|
|
34
34
|
InstanceData *instance;
|
|
35
35
|
const FunctionInfo *func;
|
|
36
36
|
|
|
37
|
-
bool debug;
|
|
38
|
-
|
|
39
37
|
InstanceMemory *mem;
|
|
40
38
|
Span<uint8_t> old_stack_mem;
|
|
41
39
|
Span<uint8_t> old_heap_mem;
|
|
42
40
|
|
|
43
41
|
LocalArray<OutObject, MaxOutParameters> out_objects;
|
|
44
|
-
|
|
45
|
-
Span<uint8_t> heap;
|
|
46
|
-
Span<uint8_t> stack;
|
|
42
|
+
uint8_t *sp;
|
|
47
43
|
|
|
48
44
|
union {
|
|
49
45
|
uint32_t u32;
|
|
@@ -65,15 +61,13 @@ public:
|
|
|
65
61
|
void Execute();
|
|
66
62
|
Napi::Value Complete();
|
|
67
63
|
|
|
68
|
-
Napi::Value Run(const Napi::CallbackInfo &info);
|
|
69
|
-
|
|
70
64
|
void DumpDebug() const;
|
|
71
65
|
|
|
72
66
|
private:
|
|
73
67
|
template <typename T = void>
|
|
74
|
-
bool AllocStack(Size size, Size align, T **out_ptr
|
|
68
|
+
bool AllocStack(Size size, Size align, T **out_ptr);
|
|
75
69
|
template <typename T = void>
|
|
76
|
-
bool AllocHeap(Size size, Size align, T **out_ptr
|
|
70
|
+
bool AllocHeap(Size size, Size align, T **out_ptr);
|
|
77
71
|
|
|
78
72
|
const char *PushString(const Napi::Value &value);
|
|
79
73
|
const char16_t *PushString16(const Napi::Value &value);
|
|
@@ -86,7 +80,7 @@ private:
|
|
|
86
80
|
};
|
|
87
81
|
|
|
88
82
|
template <typename T>
|
|
89
|
-
bool CallData::AllocStack(Size size, Size align, T **out_ptr)
|
|
83
|
+
inline bool CallData::AllocStack(Size size, Size align, T **out_ptr)
|
|
90
84
|
{
|
|
91
85
|
uint8_t *ptr = AlignDown(mem->stack.end() - size, align);
|
|
92
86
|
Size delta = mem->stack.end() - ptr;
|
|
@@ -96,20 +90,18 @@ bool CallData::AllocStack(Size size, Size align, T **out_ptr)
|
|
|
96
90
|
return false;
|
|
97
91
|
}
|
|
98
92
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
93
|
+
#ifdef RG_DEBUG
|
|
94
|
+
memset(ptr, 0, delta);
|
|
95
|
+
#endif
|
|
102
96
|
|
|
103
97
|
mem->stack.len -= delta;
|
|
104
98
|
|
|
105
|
-
|
|
106
|
-
*out_ptr = (T *)ptr;
|
|
107
|
-
}
|
|
99
|
+
*out_ptr = (T *)ptr;
|
|
108
100
|
return true;
|
|
109
101
|
}
|
|
110
102
|
|
|
111
103
|
template <typename T>
|
|
112
|
-
bool CallData::AllocHeap(Size size, Size align, T **out_ptr)
|
|
104
|
+
inline bool CallData::AllocHeap(Size size, Size align, T **out_ptr)
|
|
113
105
|
{
|
|
114
106
|
uint8_t *ptr = AlignUp(mem->heap.ptr, align);
|
|
115
107
|
Size delta = size + (ptr - mem->heap.ptr);
|
|
@@ -119,16 +111,14 @@ bool CallData::AllocHeap(Size size, Size align, T **out_ptr)
|
|
|
119
111
|
return false;
|
|
120
112
|
}
|
|
121
113
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
114
|
+
#ifdef RG_DEBUG
|
|
115
|
+
memset(mem->heap.ptr, 0, (size_t)delta);
|
|
116
|
+
#endif
|
|
125
117
|
|
|
126
118
|
mem->heap.ptr += delta;
|
|
127
119
|
mem->heap.len -= delta;
|
|
128
120
|
|
|
129
|
-
|
|
130
|
-
*out_ptr = (T *)ptr;
|
|
131
|
-
}
|
|
121
|
+
*out_ptr = (T *)ptr;
|
|
132
122
|
return true;
|
|
133
123
|
}
|
|
134
124
|
|