koffi 2.15.3 → 2.15.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/build/koffi/darwin_arm64/koffi.node +0 -0
  3. package/build/koffi/darwin_x64/koffi.node +0 -0
  4. package/build/koffi/freebsd_arm64/koffi.node +0 -0
  5. package/build/koffi/freebsd_ia32/koffi.node +0 -0
  6. package/build/koffi/freebsd_x64/koffi.node +0 -0
  7. package/build/koffi/linux_arm64/koffi.node +0 -0
  8. package/build/koffi/linux_armhf/koffi.node +0 -0
  9. package/build/koffi/linux_ia32/koffi.node +0 -0
  10. package/build/koffi/linux_loong64/koffi.node +0 -0
  11. package/build/koffi/linux_riscv64d/koffi.node +0 -0
  12. package/build/koffi/linux_x64/koffi.node +0 -0
  13. package/build/koffi/musl_arm64/koffi.node +0 -0
  14. package/build/koffi/musl_x64/koffi.node +0 -0
  15. package/build/koffi/openbsd_ia32/koffi.node +0 -0
  16. package/build/koffi/openbsd_x64/koffi.node +0 -0
  17. package/build/koffi/win32_arm64/koffi.node +0 -0
  18. package/build/koffi/win32_ia32/koffi.node +0 -0
  19. package/build/koffi/win32_x64/koffi.node +0 -0
  20. package/index.js +8 -8
  21. package/indirect.js +8 -8
  22. package/package.json +1 -1
  23. package/src/koffi/src/abi_arm32.cc +0 -8
  24. package/src/koffi/src/abi_arm32_asm.S +8 -29
  25. package/src/koffi/src/abi_arm64.cc +4 -11
  26. package/src/koffi/src/abi_arm64_asm.S +5 -28
  27. package/src/koffi/src/abi_arm64_asm.asm +6 -21
  28. package/src/koffi/src/abi_loong64_asm.S +5 -23
  29. package/src/koffi/src/abi_riscv64.cc +0 -8
  30. package/src/koffi/src/abi_riscv64_asm.S +5 -23
  31. package/src/koffi/src/abi_x64_sysv.cc +0 -8
  32. package/src/koffi/src/abi_x64_sysv_asm.S +5 -26
  33. package/src/koffi/src/abi_x64_win.cc +0 -8
  34. package/src/koffi/src/abi_x64_win_asm.S +5 -16
  35. package/src/koffi/src/abi_x64_win_asm.asm +7 -19
  36. package/src/koffi/src/abi_x86.cc +17 -13
  37. package/src/koffi/src/abi_x86_asm.S +15 -24
  38. package/src/koffi/src/abi_x86_asm.asm +14 -20
  39. package/src/koffi/src/call.cc +8 -2
  40. package/src/koffi/src/call.hh +1 -1
  41. package/src/koffi/src/ffi.cc +1 -1
  42. package/src/koffi/src/trampolines/armasm.inc +0 -32770
  43. package/src/koffi/src/trampolines/gnu.inc +0 -24578
  44. package/src/koffi/src/trampolines/masm32.inc +0 -32770
  45. package/src/koffi/src/trampolines/masm64.inc +0 -32770
  46. package/src/koffi/src/trampolines/prototypes.inc +16385 -16385
package/CHANGELOG.md CHANGED
@@ -7,6 +7,22 @@
7
7
 
8
8
  ### Koffi 2.15
9
9
 
10
+ #### Koffi 2.15.5
11
+
12
+ *Released on 2026-04-05*
13
+
14
+ - Reduce repeated trampoline code size:
15
+ * Use single set of trampolines to forward general and floating-point values
16
+ * Minimize trampoline size by jumping early to common handling code
17
+ - This reduces decompressed Koffi package size from 85.9 MB to 41.4 MB
18
+
19
+ #### Koffi 2.15.4
20
+
21
+ *Released on 2026-04-03*
22
+
23
+ - Fix ABI issue with variadic parameters that are passed on the stack on Apple ARM64 platforms
24
+ - Remove erroneous assertion from debug builds
25
+
10
26
  #### Koffi 2.15.3
11
27
 
12
28
  *Released on 2026-04-03*
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/index.js CHANGED
@@ -4,9 +4,9 @@ var __commonJS = (cb, mod3) => function __require() {
4
4
  return mod3 || (0, cb[__getOwnPropNames(cb)[0]])((mod3 = { exports: {} }).exports, mod3), mod3.exports;
5
5
  };
6
6
 
7
- // bin/Koffi/package/src/cnoke/src/tools.js
7
+ // ../../../bin/Koffi/package/src/cnoke/src/tools.js
8
8
  var require_tools = __commonJS({
9
- "bin/Koffi/package/src/cnoke/src/tools.js"(exports2, module2) {
9
+ "../../../bin/Koffi/package/src/cnoke/src/tools.js"(exports2, module2) {
10
10
  "use strict";
11
11
  var crypto = require("crypto");
12
12
  var fs2 = require("fs");
@@ -393,12 +393,12 @@ var require_tools = __commonJS({
393
393
  }
394
394
  });
395
395
 
396
- // bin/Koffi/package/src/koffi/package.json
396
+ // ../../../bin/Koffi/package/src/koffi/package.json
397
397
  var require_package = __commonJS({
398
- "bin/Koffi/package/src/koffi/package.json"(exports2, module2) {
398
+ "../../../bin/Koffi/package/src/koffi/package.json"(exports2, module2) {
399
399
  module2.exports = {
400
400
  name: "koffi",
401
- version: "2.15.3",
401
+ version: "2.15.5",
402
402
  description: "Fast and simple C FFI (foreign function interface) for Node.js",
403
403
  keywords: [
404
404
  "foreign",
@@ -440,9 +440,9 @@ var require_package = __commonJS({
440
440
  }
441
441
  });
442
442
 
443
- // bin/Koffi/package/src/koffi/src/init.js
443
+ // ../../../bin/Koffi/package/src/koffi/src/init.js
444
444
  var require_init = __commonJS({
445
- "bin/Koffi/package/src/koffi/src/init.js"(exports, module) {
445
+ "../../../bin/Koffi/package/src/koffi/src/init.js"(exports, module) {
446
446
  var fs = require("fs");
447
447
  var path = require("path");
448
448
  var util = require("util");
@@ -526,7 +526,7 @@ var require_init = __commonJS({
526
526
  }
527
527
  });
528
528
 
529
- // bin/Koffi/package/src/koffi/index.js
529
+ // ../../../bin/Koffi/package/src/koffi/index.js
530
530
  var { detect: detect2, init: init2 } = require_init();
531
531
  var triplet2 = detect2();
532
532
  var native2 = null;
package/indirect.js CHANGED
@@ -4,9 +4,9 @@ var __commonJS = (cb, mod3) => function __require() {
4
4
  return mod3 || (0, cb[__getOwnPropNames(cb)[0]])((mod3 = { exports: {} }).exports, mod3), mod3.exports;
5
5
  };
6
6
 
7
- // bin/Koffi/package/src/cnoke/src/tools.js
7
+ // ../../../bin/Koffi/package/src/cnoke/src/tools.js
8
8
  var require_tools = __commonJS({
9
- "bin/Koffi/package/src/cnoke/src/tools.js"(exports2, module2) {
9
+ "../../../bin/Koffi/package/src/cnoke/src/tools.js"(exports2, module2) {
10
10
  "use strict";
11
11
  var crypto = require("crypto");
12
12
  var fs2 = require("fs");
@@ -393,12 +393,12 @@ var require_tools = __commonJS({
393
393
  }
394
394
  });
395
395
 
396
- // bin/Koffi/package/src/koffi/package.json
396
+ // ../../../bin/Koffi/package/src/koffi/package.json
397
397
  var require_package = __commonJS({
398
- "bin/Koffi/package/src/koffi/package.json"(exports2, module2) {
398
+ "../../../bin/Koffi/package/src/koffi/package.json"(exports2, module2) {
399
399
  module2.exports = {
400
400
  name: "koffi",
401
- version: "2.15.3",
401
+ version: "2.15.5",
402
402
  description: "Fast and simple C FFI (foreign function interface) for Node.js",
403
403
  keywords: [
404
404
  "foreign",
@@ -440,9 +440,9 @@ var require_package = __commonJS({
440
440
  }
441
441
  });
442
442
 
443
- // bin/Koffi/package/src/koffi/src/init.js
443
+ // ../../../bin/Koffi/package/src/koffi/src/init.js
444
444
  var require_init = __commonJS({
445
- "bin/Koffi/package/src/koffi/src/init.js"(exports, module) {
445
+ "../../../bin/Koffi/package/src/koffi/src/init.js"(exports, module) {
446
446
  var fs = require("fs");
447
447
  var path = require("path");
448
448
  var util = require("util");
@@ -526,7 +526,7 @@ var require_init = __commonJS({
526
526
  }
527
527
  });
528
528
 
529
- // bin/Koffi/package/src/koffi/indirect.js
529
+ // ../../../bin/Koffi/package/src/koffi/indirect.js
530
530
  var { detect: detect2, init: init2 } = require_init();
531
531
  var triplet2 = detect2();
532
532
  var mod2 = init2(triplet2, null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koffi",
3
- "version": "2.15.3",
3
+ "version": "2.15.5",
4
4
  "description": "Fast and simple C FFI (foreign function interface) for Node.js",
5
5
  "keywords": [
6
6
  "foreign",
@@ -38,8 +38,6 @@ extern "C" uint64_t ForwardCallXGG(const void *func, uint8_t *sp, uint8_t **out_
38
38
  extern "C" float ForwardCallXF(const void *func, uint8_t *sp, uint8_t **out_old_sp);
39
39
  extern "C" HfaRet ForwardCallXDDDD(const void *func, uint8_t *sp, uint8_t **out_old_sp);
40
40
 
41
- #include "trampolines/prototypes.inc"
42
-
43
41
  static int IsHFA(const TypeInfo *type)
44
42
  {
45
43
  #if defined(__ARM_PCS_VFP)
@@ -1008,12 +1006,6 @@ void CallData::Relay(Size idx, uint8_t *sp)
1008
1006
  err_guard.Disable();
1009
1007
  }
1010
1008
 
1011
- void *GetTrampoline(int16_t idx, const FunctionInfo *proto)
1012
- {
1013
- bool vec = proto->forward_fp || IsFloat(proto->ret.type);
1014
- return Trampolines[idx][vec];
1015
- }
1016
-
1017
1009
  }
1018
1010
 
1019
1011
  #endif
@@ -94,49 +94,29 @@ ForwardCallXDDDD:
94
94
  .global SwitchAndRelay
95
95
  .global RelayDirect
96
96
 
97
- # First, make a copy of the GPR argument registers (r0 to r7).
97
+ # First, make a copy of the argument registers.
98
98
  # Then call the C function RelayCallback with the following arguments:
99
99
  # static trampoline ID, a pointer to the saved GPR array, a pointer to the stack
100
100
  # arguments of this call, and a pointer to a struct that will contain the result registers.
101
101
  # After the call, simply load these registers from the output struct.
102
102
  .macro trampoline id
103
103
  .cfi_startproc
104
- push {fp, lr}
105
- .cfi_def_cfa sp, 8
106
- .cfi_offset 11, 4
107
- .cfi_offset 14, 8
108
- sub sp, sp, #120
109
- .cfi_def_cfa sp, 128
110
- add r12, sp, 64
111
- stmia r12, {r0-r3}
112
- mov r0, \id
113
- mov r1, sp
114
- bl RelayCallback
115
- add sp, sp, #80
116
- ldmia sp!, {r0-r1}
117
- add sp, sp, #32
118
- .cfi_def_cfa sp, 8
119
- pop {fp, lr}
120
- .cfi_def_cfa sp, 0
121
- .cfi_restore 11
122
- .cfi_restore 14
123
- bx lr
104
+ mov r12, \id
105
+ b RelayTrampoline
124
106
  .cfi_endproc
125
107
  .endm
126
108
 
127
- # Same thing, but also forwards the floating-point argument registers and loads them at the end.
128
- .macro trampoline_vec id
109
+ RelayTrampoline:
129
110
  .cfi_startproc
130
111
  push {fp, lr}
131
112
  .cfi_def_cfa sp, 8
132
113
  .cfi_offset 11, 4
133
114
  .cfi_offset 14, 8
134
- sub sp, sp, #120
115
+ sub sp, sp, #40
116
+ stmdb sp!, {r0-r3}
117
+ vstmdb sp!, {d0-d7}
135
118
  .cfi_def_cfa sp, 128
136
- mov r12, sp
137
- vstmia r12!, {d0-d7}
138
- stmia r12, {r0-r3}
139
- mov r0, \id
119
+ mov r0, r12
140
120
  mov r1, sp
141
121
  bl RelayCallback
142
122
  add sp, sp, #80
@@ -149,7 +129,6 @@ ForwardCallXDDDD:
149
129
  .cfi_restore 14
150
130
  bx lr
151
131
  .cfi_endproc
152
- .endm
153
132
 
154
133
  # When a callback is relayed, Koffi will call into Node.js and V8 to execute Javascript.
155
134
  # The problem is that we're still running on the separate Koffi stack, and V8 will
@@ -48,8 +48,6 @@ extern "C" X0X1Ret ForwardCallXGG(const void *func, uint8_t *sp, uint8_t **out_o
48
48
  extern "C" float ForwardCallXF(const void *func, uint8_t *sp, uint8_t **out_old_sp);
49
49
  extern "C" HfaRet ForwardCallXDDDD(const void *func, uint8_t *sp, uint8_t **out_old_sp);
50
50
 
51
- #include "trampolines/prototypes.inc"
52
-
53
51
  static HfaInfo IsHFA(const TypeInfo *type)
54
52
  {
55
53
  bool float32 = false;
@@ -286,7 +284,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
286
284
  if (param.gpr_count) [[likely]] { \
287
285
  *(gpr_ptr++) = (uint64_t)v; \
288
286
  } else { \
289
- args_ptr = AlignUp(args_ptr, param.type->align); \
287
+ args_ptr = AlignUp(args_ptr, param.variadic ? 8 : param.type->align); \
290
288
  *args_ptr = (uint64_t)v; \
291
289
  args_ptr = (uint64_t *)((uint8_t *)args_ptr + param.type->size); \
292
290
  } \
@@ -303,7 +301,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
303
301
  if (param.gpr_count) [[likely]] { \
304
302
  *(gpr_ptr++) = (uint64_t)ReverseBytes(v); \
305
303
  } else { \
306
- args_ptr = AlignUp(args_ptr, param.type->align); \
304
+ args_ptr = AlignUp(args_ptr, param.variadic ? 8 : param.type->align); \
307
305
  *args_ptr = (uint64_t)ReverseBytes(v); \
308
306
  args_ptr = (uint64_t *)((uint8_t *)args_ptr + param.type->size); \
309
307
  } \
@@ -353,6 +351,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
353
351
  if (param.gpr_count) [[likely]] {
354
352
  *(gpr_ptr++) = (uint64_t)b;
355
353
  } else {
354
+ args_ptr = AlignUp(args_ptr, param.variadic ? 8 : 1);
356
355
  *(uint8_t *)args_ptr = b;
357
356
  args_ptr = (uint64_t *)((uint8_t *)args_ptr + 1);
358
357
  }
@@ -484,7 +483,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
484
483
  #endif
485
484
  } else {
486
485
  #if defined(__APPLE__)
487
- args_ptr = AlignUp(args_ptr, 4);
486
+ args_ptr = AlignUp(args_ptr, param.variadic ? 8 : 4);
488
487
  *(float *)args_ptr = f;
489
488
  args_ptr = (uint64_t *)((uint8_t *)args_ptr + 4);
490
489
  #else
@@ -1302,12 +1301,6 @@ void CallData::Relay(Size idx, uint8_t *sp)
1302
1301
  err_guard.Disable();
1303
1302
  }
1304
1303
 
1305
- void *GetTrampoline(int16_t idx, const FunctionInfo *proto)
1306
- {
1307
- bool vec = proto->forward_fp || IsFloat(proto->ret.type);
1308
- return Trampolines[idx][vec];
1309
- }
1310
-
1311
1304
  }
1312
1305
 
1313
1306
  #endif
@@ -115,7 +115,7 @@ SYMBOL(ForwardCallXDDDD):
115
115
  .global SYMBOL(SwitchAndRelay)
116
116
  .global SYMBOL(RelayDirect)
117
117
 
118
- # First, make a copy of the GPR argument registers (x0 to x7).
118
+ # First, make a copy of the argument registers.
119
119
  # Then call the C function RelayCallback with the following arguments:
120
120
  # static trampoline ID, a pointer to the saved GPR array, a pointer to the stack
121
121
  # arguments of this call, and a pointer to a struct that will contain the result registers.
@@ -123,35 +123,13 @@ SYMBOL(ForwardCallXDDDD):
123
123
  .macro trampoline id
124
124
  .cfi_startproc
125
125
  hint #34
126
- stp x29, x30, [sp, -16]!
127
- .cfi_def_cfa sp, 16
128
- .cfi_offset 29, 16
129
- .cfi_offset 30, 8
130
- sub sp, sp, #192
131
- .cfi_def_cfa sp, 208
132
- stp x0, x1, [sp, 0]
133
- stp x2, x3, [sp, 16]
134
- stp x4, x5, [sp, 32]
135
- stp x6, x7, [sp, 48]
136
- str x8, [sp, 64]
137
- mov x0, \id
138
- mov x1, sp
139
- bl SYMBOL(RelayCallback)
140
- ldp x0, x1, [sp, 136]
141
- add sp, sp, #192
142
- .cfi_def_cfa sp, 16
143
- ldp x29, x30, [sp], 16
144
- .cfi_def_cfa sp, 0
145
- .cfi_restore 30
146
- .cfi_restore 29
147
- ret
126
+ mov x9, \id
127
+ b RelayTrampoline
148
128
  .cfi_endproc
149
129
  .endm
150
130
 
151
- # Same thing, but also forwards the floating-point argument registers and loads them at the end.
152
- .macro trampoline_vec id
131
+ RelayTrampoline:
153
132
  .cfi_startproc
154
- hint #34
155
133
  stp x29, x30, [sp, -16]!
156
134
  .cfi_def_cfa sp, 16
157
135
  .cfi_offset 29, 16
@@ -167,7 +145,7 @@ SYMBOL(ForwardCallXDDDD):
167
145
  stp d2, d3, [sp, 88]
168
146
  stp d4, d5, [sp, 104]
169
147
  stp d6, d7, [sp, 120]
170
- mov x0, \id
148
+ mov x0, x9
171
149
  mov x1, sp
172
150
  bl SYMBOL(RelayCallback)
173
151
  ldp x0, x1, [sp, 136]
@@ -181,7 +159,6 @@ SYMBOL(ForwardCallXDDDD):
181
159
  .cfi_restore 29
182
160
  ret
183
161
  .cfi_endproc
184
- .endm
185
162
 
186
163
  # When a callback is relayed, Koffi will call into Node.js and V8 to execute Javascript.
187
164
  # The problem is that we're still running on the separate Koffi stack, and V8 will
@@ -110,7 +110,7 @@ ForwardCallXDDDD PROC
110
110
  EXPORT RelayDirect
111
111
  EXTERN RelayDirect
112
112
 
113
- ; First, make a copy of the GPR argument registers (x0 to x7).
113
+ ; First, make a copy of the argument registers.
114
114
  ; Then call the C function RelayCallback with the following arguments:
115
115
  ; static trampoline ID, a pointer to the saved GPR array, a pointer to the stack
116
116
  ; arguments of this call, and a pointer to a struct that will contain the result registers.
@@ -118,26 +118,11 @@ ForwardCallXDDDD PROC
118
118
  MACRO
119
119
  trampoline $ID
120
120
 
121
- stp x29, x30, [sp, -16]!
122
- sub sp, sp, #192
123
- stp x0, x1, [sp, 0]
124
- stp x2, x3, [sp, 16]
125
- stp x4, x5, [sp, 32]
126
- stp x6, x7, [sp, 48]
127
- str x8, [sp, 64]
128
- mov x0, $ID
129
- mov x1, sp
130
- bl RelayCallback
131
- ldp x0, x1, [sp, 136]
132
- add sp, sp, #192
133
- ldp x29, x30, [sp], 16
134
- ret
121
+ mov x9, $ID
122
+ b RelayTrampoline
135
123
  MEND
136
124
 
137
- ; Same thing, but also forwards the floating-point argument registers and loads them at the end.
138
- MACRO
139
- trampoline_vec $ID
140
-
125
+ RelayTrampoline PROC
141
126
  stp x29, x30, [sp, -16]!
142
127
  sub sp, sp, #192
143
128
  stp x0, x1, [sp, 0]
@@ -149,7 +134,7 @@ ForwardCallXDDDD PROC
149
134
  stp d2, d3, [sp, 88]
150
135
  stp d4, d5, [sp, 104]
151
136
  stp d6, d7, [sp, 120]
152
- mov x0, $ID
137
+ mov x0, x9
153
138
  mov x1, sp
154
139
  bl RelayCallback
155
140
  ldp x0, x1, [sp, 136]
@@ -158,7 +143,7 @@ ForwardCallXDDDD PROC
158
143
  add sp, sp, #192
159
144
  ldp x29, x30, [sp], 16
160
145
  ret
161
- MEND
146
+ ENDP
162
147
 
163
148
  ; When a callback is relayed, Koffi will call into Node.js and V8 to execute Javascript.
164
149
  ; The problem is that we're still running on the separate Koffi stack, and V8 will
@@ -132,34 +132,17 @@ ForwardCallXDD:
132
132
  .global SwitchAndRelay
133
133
  .global RelayDirect
134
134
 
135
- # First, make a copy of the GPR argument registers (a0 to a7).
135
+ # First, make a copy of the argument registers.
136
136
  # Then call the C function RelayCallback with the following arguments:
137
137
  # static trampoline ID, a pointer to the saved GPR array, a pointer to the stack
138
138
  # arguments of this call, and a pointer to a struct that will contain the result registers.
139
139
  # After the call, simply load these registers from the output struct.
140
140
  .macro trampoline id
141
- addi.d $sp, $sp, -176
142
- st.d $ra, $sp, 0
143
- st.d $a0, $sp, 8
144
- st.d $a1, $sp, 16
145
- st.d $a2, $sp, 24
146
- st.d $a3, $sp, 32
147
- st.d $a4, $sp, 40
148
- st.d $a5, $sp, 48
149
- st.d $a6, $sp, 56
150
- st.d $a7, $sp, 64
151
- li.d $a0, \id
152
- addi.d $a1, $sp, 8
153
- bl RelayCallback
154
- ld.d $ra, $sp, 0
155
- ld.d $a0, $sp, 136
156
- ld.d $a1, $sp, 144
157
- addi.d $sp, $sp, 176
158
- jr $ra
141
+ li.d $t0, \id
142
+ b RelayTrampoline
159
143
  .endm
160
144
 
161
- # Same thing, but also forwards the floating-point argument registers and loads them at the end.
162
- .macro trampoline_vec id
145
+ RelayTrampoline:
163
146
  addi.d $sp, $sp, -176
164
147
  st.d $ra, $sp, 0
165
148
  st.d $a0, $sp, 8
@@ -178,7 +161,7 @@ ForwardCallXDD:
178
161
  fst.d $fa5, $sp, 112
179
162
  fst.d $fa6, $sp, 120
180
163
  fst.d $fa7, $sp, 128
181
- li.d $a0, \id
164
+ move $a0, $t0
182
165
  addi.d $a1, $sp, 8
183
166
  bl RelayCallback
184
167
  ld.d $ra, $sp, 0
@@ -188,7 +171,6 @@ ForwardCallXDD:
188
171
  fld.d $fa1, $sp, 160
189
172
  addi.d $sp, $sp, 176
190
173
  jr $ra
191
- .endm
192
174
 
193
175
  # When a callback is relayed, Koffi will call into Node.js and V8 to execute Javascript.
194
176
  # The problem is that we're still running on the separate Koffi stack, and V8 will
@@ -48,8 +48,6 @@ extern "C" Fa0A0Ret ForwardCallXDG(const void *func, uint8_t *sp, uint8_t **out_
48
48
  extern "C" A0Fa0Ret ForwardCallXGD(const void *func, uint8_t *sp, uint8_t **out_old_sp);
49
49
  extern "C" Fa0Fa1Ret ForwardCallXDD(const void *func, uint8_t *sp, uint8_t **out_old_sp);
50
50
 
51
- #include "trampolines/prototypes.inc"
52
-
53
51
  static inline void ExpandPair(const uint8_t raw[16], int size1, int size2, uint64_t out_regs[2])
54
52
  {
55
53
  memcpy(out_regs + 0, raw, size1);
@@ -905,12 +903,6 @@ void CallData::Relay(Size idx, uint8_t *sp)
905
903
  err_guard.Disable();
906
904
  }
907
905
 
908
- void *GetTrampoline(int16_t idx, const FunctionInfo *proto)
909
- {
910
- bool fp = proto->forward_fp || proto->ret.vec_count;
911
- return Trampolines[idx][fp];
912
- }
913
-
914
906
  }
915
907
 
916
908
  #endif
@@ -132,34 +132,17 @@ ForwardCallXDD:
132
132
  .global SwitchAndRelay
133
133
  .global RelayDirect
134
134
 
135
- # First, make a copy of the GPR argument registers (a0 to a7).
135
+ # First, make a copy of argument registers.
136
136
  # Then call the C function RelayCallback with the following arguments:
137
137
  # static trampoline ID, a pointer to the saved GPR array, a pointer to the stack
138
138
  # arguments of this call, and a pointer to a struct that will contain the result registers.
139
139
  # After the call, simply load these registers from the output struct.
140
140
  .macro trampoline id
141
- addi sp, sp, -176
142
- sd ra, 0(sp)
143
- sd a0, 8(sp)
144
- sd a1, 16(sp)
145
- sd a2, 24(sp)
146
- sd a3, 32(sp)
147
- sd a4, 40(sp)
148
- sd a5, 48(sp)
149
- sd a6, 56(sp)
150
- sd a7, 64(sp)
151
- li a0, \id
152
- addi a1, sp, 8
153
- call RelayCallback
154
- ld ra, 0(sp)
155
- ld a0, 136(sp)
156
- ld a1, 144(sp)
157
- addi sp, sp, 176
158
- ret
141
+ li t0, \id
142
+ j RelayTrampoline
159
143
  .endm
160
144
 
161
- # Same thing, but also forwards the floating-point argument registers and loads them at the end.
162
- .macro trampoline_vec id
145
+ RelayTrampoline:
163
146
  addi sp, sp, -176
164
147
  sd ra, 0(sp)
165
148
  sd a0, 8(sp)
@@ -178,7 +161,7 @@ ForwardCallXDD:
178
161
  fsd fa5, 112(sp)
179
162
  fsd fa6, 120(sp)
180
163
  fsd fa7, 128(sp)
181
- li a0, \id
164
+ mv a0, t0
182
165
  addi a1, sp, 8
183
166
  call RelayCallback
184
167
  ld ra, 0(sp)
@@ -188,7 +171,6 @@ ForwardCallXDD:
188
171
  fld fa1, 160(sp)
189
172
  addi sp, sp, 176
190
173
  ret
191
- .endm
192
174
 
193
175
  # When a callback is relayed, Koffi will call into Node.js and V8 to execute Javascript.
194
176
  # The problem is that we're still running on the separate Koffi stack, and V8 will
@@ -55,8 +55,6 @@ extern "C" Xmm0RaxRet ForwardCallXDG(const void *func, uint8_t *sp, uint8_t **ou
55
55
  extern "C" RaxXmm0Ret ForwardCallXGD(const void *func, uint8_t *sp, uint8_t **out_old_sp);
56
56
  extern "C" Xmm0Xmm1Ret ForwardCallXDD(const void *func, uint8_t *sp, uint8_t **out_old_sp);
57
57
 
58
- #include "trampolines/prototypes.inc"
59
-
60
58
  static inline RegisterClass MergeClasses(RegisterClass cls1, RegisterClass cls2)
61
59
  {
62
60
  if (cls1 == cls2)
@@ -929,12 +927,6 @@ void CallData::Relay(Size idx, uint8_t *sp)
929
927
  err_guard.Disable();
930
928
  }
931
929
 
932
- void *GetTrampoline(int16_t idx, const FunctionInfo *proto)
933
- {
934
- bool xmm = proto->forward_fp || IsFloat(proto->ret.type);
935
- return Trampolines[idx][xmm];
936
- }
937
-
938
930
  }
939
931
 
940
932
  #endif
@@ -149,7 +149,7 @@ SYMBOL(ForwardCallXDD):
149
149
  .global SYMBOL(SwitchAndRelay)
150
150
  .global SYMBOL(RelayDirect)
151
151
 
152
- # First, make a copy of the GPR argument registers (rdi, rsi, rdx, rcx, r8, r9).
152
+ # First, make a copy of argument registers.
153
153
  # Then call the C function RelayCallback with the following arguments:
154
154
  # static trampoline ID, a pointer to the saved GPR array, a pointer to the stack
155
155
  # arguments of this call, and a pointer to a struct that will contain the result registers.
@@ -158,34 +158,14 @@ SYMBOL(ForwardCallXDD):
158
158
  .cfi_startproc
159
159
  .cfi_def_cfa rsp, 8
160
160
  ENDBR64
161
- subq $152, %rsp
162
- .cfi_def_cfa rsp, 160
163
- movq %rdi, 0(%rsp)
164
- movq %rsi, 8(%rsp)
165
- movq %rdx, 16(%rsp)
166
- movq %rcx, 24(%rsp)
167
- movq %r8, 32(%rsp)
168
- movq %r9, 40(%rsp)
169
- movq $\id, %rdi
170
- movq %rsp, %rsi
171
- #if defined(__linux__)
172
- call *RelayCallback@GOTPCREL(%rip)
173
- #else
174
- call SYMBOL(RelayCallback)
175
- #endif
176
- movq 112(%rsp), %rax
177
- movq 120(%rsp), %rdx
178
- addq $152, %rsp
179
- .cfi_def_cfa rsp, 8
180
- ret
161
+ movq $\id, %rax
162
+ jmp RelayTrampoline
181
163
  .cfi_endproc
182
164
  .endm
183
165
 
184
- # Same thing, but also forward the XMM argument registers and load the XMM result registers.
185
- .macro trampoline_vec id
166
+ RelayTrampoline:
186
167
  .cfi_startproc
187
168
  .cfi_def_cfa rsp, 8
188
- ENDBR64
189
169
  subq $152, %rsp
190
170
  .cfi_def_cfa rsp, 160
191
171
  movq %rdi, 0(%rsp)
@@ -202,7 +182,7 @@ SYMBOL(ForwardCallXDD):
202
182
  movsd %xmm5, 88(%rsp)
203
183
  movsd %xmm6, 96(%rsp)
204
184
  movsd %xmm7, 104(%rsp)
205
- movq $\id, %rdi
185
+ movq %rax, %rdi
206
186
  movq %rsp, %rsi
207
187
  #if defined(__linux__)
208
188
  call *RelayCallback@GOTPCREL(%rip)
@@ -217,7 +197,6 @@ SYMBOL(ForwardCallXDD):
217
197
  .cfi_def_cfa rsp, 8
218
198
  ret
219
199
  .cfi_endproc
220
- .endm
221
200
 
222
201
  # When a callback is relayed, Koffi will call into Node.js and V8 to execute Javascript.
223
202
  # The problem is that we're still running on the separate Koffi stack, and V8 will