koffi 2.14.0 → 2.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/CHANGELOG.md +26 -1
  2. package/README.md +1 -1
  3. package/build/koffi/darwin_arm64/koffi.node +0 -0
  4. package/build/koffi/darwin_x64/koffi.node +0 -0
  5. package/build/koffi/freebsd_arm64/koffi.node +0 -0
  6. package/build/koffi/freebsd_ia32/koffi.node +0 -0
  7. package/build/koffi/freebsd_x64/koffi.node +0 -0
  8. package/build/koffi/linux_arm64/koffi.node +0 -0
  9. package/build/koffi/linux_armhf/koffi.node +0 -0
  10. package/build/koffi/linux_ia32/koffi.node +0 -0
  11. package/build/koffi/linux_loong64/koffi.node +0 -0
  12. package/build/koffi/linux_riscv64d/koffi.node +0 -0
  13. package/build/koffi/linux_x64/koffi.node +0 -0
  14. package/build/koffi/musl_arm64/koffi.node +0 -0
  15. package/build/koffi/musl_x64/koffi.node +0 -0
  16. package/build/koffi/openbsd_ia32/koffi.node +0 -0
  17. package/build/koffi/openbsd_x64/koffi.node +0 -0
  18. package/build/koffi/win32_arm64/koffi.node +0 -0
  19. package/build/koffi/win32_ia32/koffi.node +0 -0
  20. package/build/koffi/win32_x64/koffi.node +0 -0
  21. package/doc/assets.ini +2 -1
  22. package/doc/build.sh +9 -0
  23. package/doc/pages/404.md +17 -0
  24. package/doc/pages/index.md +43 -4
  25. package/doc/pages/misc.md +16 -11
  26. package/doc/pages/platforms.md +8 -19
  27. package/doc/pages.ini +4 -7
  28. package/doc/static/highlight.js +2 -14
  29. package/doc/static/koffi.css +3 -15
  30. package/doc/static/perf_windows.png +0 -0
  31. package/doc/static/print.css +2 -14
  32. package/index.d.ts +29 -24
  33. package/index.js +10 -9
  34. package/indirect.js +10 -9
  35. package/{src/core → lib/native}/base/base.cc +1753 -1089
  36. package/{src/core → lib/native}/base/base.hh +868 -572
  37. package/{src/core → lib/native}/base/crc.inc +3 -21
  38. package/lib/native/base/crc_gen.py +72 -0
  39. package/{src/core → lib/native}/base/mimetypes.inc +2 -20
  40. package/{src/core → lib/native}/base/mimetypes_gen.py +2 -21
  41. package/lib/native/base/tower.cc +821 -0
  42. package/lib/native/base/tower.hh +81 -0
  43. package/{src/core → lib/native}/base/unicode.inc +3 -21
  44. package/{src/core → lib/native}/base/unicode_gen.py +5 -42
  45. package/package.json +3 -2
  46. package/src/cnoke/assets/FindCNoke.cmake +8 -20
  47. package/src/cnoke/assets/win_delay_hook.c +2 -20
  48. package/src/cnoke/cnoke.js +2 -21
  49. package/src/cnoke/src/builder.js +3 -22
  50. package/src/cnoke/src/index.js +2 -20
  51. package/src/cnoke/src/tools.js +2 -20
  52. package/src/koffi/CMakeLists.txt +19 -22
  53. package/src/koffi/cmake/raylib.cmake +5 -22
  54. package/src/koffi/cmake/sqlite3.cmake +2 -20
  55. package/src/koffi/src/abi_arm32.cc +31 -49
  56. package/src/koffi/src/abi_arm32_asm.S +2 -20
  57. package/src/koffi/src/abi_arm64.cc +36 -54
  58. package/src/koffi/src/abi_arm64_asm.S +2 -20
  59. package/src/koffi/src/abi_arm64_asm.asm +2 -20
  60. package/src/koffi/src/abi_loong64.cc +2 -20
  61. package/src/koffi/src/abi_loong64_asm.S +2 -20
  62. package/src/koffi/src/abi_riscv64.cc +34 -52
  63. package/src/koffi/src/abi_riscv64_asm.S +2 -20
  64. package/src/koffi/src/abi_x64_sysv.cc +36 -54
  65. package/src/koffi/src/abi_x64_sysv_asm.S +2 -20
  66. package/src/koffi/src/abi_x64_win.cc +32 -50
  67. package/src/koffi/src/abi_x64_win_asm.asm +2 -20
  68. package/src/koffi/src/abi_x86.cc +33 -51
  69. package/src/koffi/src/abi_x86_asm.S +2 -20
  70. package/src/koffi/src/abi_x86_asm.asm +2 -20
  71. package/src/koffi/src/call.cc +107 -281
  72. package/src/koffi/src/call.hh +9 -27
  73. package/src/koffi/src/errno.inc +2 -20
  74. package/src/koffi/src/ffi.cc +121 -121
  75. package/src/koffi/src/ffi.hh +23 -38
  76. package/src/koffi/src/init.js +2 -20
  77. package/src/koffi/src/parser.cc +15 -29
  78. package/src/koffi/src/parser.hh +4 -22
  79. package/src/koffi/src/trampolines/armasm.inc +0 -21
  80. package/src/koffi/src/trampolines/gnu.inc +0 -21
  81. package/src/koffi/src/trampolines/masm32.inc +0 -21
  82. package/src/koffi/src/trampolines/masm64.inc +0 -21
  83. package/src/koffi/src/trampolines/prototypes.inc +1 -22
  84. package/src/koffi/src/util.cc +87 -102
  85. package/src/koffi/src/util.hh +11 -29
  86. package/src/koffi/src/uv.cc +193 -0
  87. package/src/koffi/src/uv.def +10 -0
  88. package/src/koffi/src/uv.hh +40 -0
  89. package/src/koffi/src/win32.cc +7 -25
  90. package/src/koffi/src/win32.hh +4 -22
  91. package/vendor/node-api-headers/include/uv/aix.h +32 -0
  92. package/vendor/node-api-headers/include/uv/bsd.h +34 -0
  93. package/vendor/node-api-headers/include/uv/darwin.h +61 -0
  94. package/vendor/node-api-headers/include/uv/errno.h +483 -0
  95. package/vendor/node-api-headers/include/uv/linux.h +34 -0
  96. package/vendor/node-api-headers/include/uv/os390.h +33 -0
  97. package/vendor/node-api-headers/include/uv/posix.h +31 -0
  98. package/vendor/node-api-headers/include/uv/sunos.h +44 -0
  99. package/vendor/node-api-headers/include/uv/threadpool.h +37 -0
  100. package/vendor/node-api-headers/include/uv/tree.h +521 -0
  101. package/vendor/node-api-headers/include/uv/unix.h +512 -0
  102. package/vendor/node-api-headers/include/uv/version.h +43 -0
  103. package/vendor/node-api-headers/include/uv/win.h +698 -0
  104. package/vendor/node-api-headers/include/uv.h +1990 -0
  105. package/src/core/base/crc_gen.py +0 -109
@@ -1,27 +1,9 @@
1
- // Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
- //
3
- // Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- // this software and associated documentation files (the “Software”), to deal in
5
- // the Software without restriction, including without limitation the rights to use,
6
- // copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
- // Software, and to permit persons to whom the Software is furnished to do so,
8
- // subject to the following conditions:
9
- //
10
- // The above copyright notice and this permission notice shall be included in all
11
- // copies or substantial portions of the Software.
12
- //
13
- // THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
14
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
- // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17
- // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
- // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
- // OTHER DEALINGS IN THE SOFTWARE.
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
21
3
 
22
4
  #if defined(__arm__) || (defined(__M_ARM) && !defined(_M_ARM64))
23
5
 
24
- #include "src/core/base/base.hh"
6
+ #include "lib/native/base/base.hh"
25
7
  #include "ffi.hh"
26
8
  #include "call.hh"
27
9
  #include "util.hh"
@@ -30,7 +12,7 @@
30
12
  #include <signal.h>
31
13
  #include <setjmp.h>
32
14
 
33
- namespace RG {
15
+ namespace K {
34
16
 
35
17
  struct HfaRet {
36
18
  double d0;
@@ -110,7 +92,7 @@ bool AnalyseFunction(Napi::Env, InstanceData *, FunctionInfo *func)
110
92
 
111
93
  for (ParameterInfo &param: func->parameters) {
112
94
  switch (param.type->primitive) {
113
- case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
95
+ case PrimitiveKind::Void: { K_UNREACHABLE(); } break;
114
96
 
115
97
  case PrimitiveKind::Bool:
116
98
  case PrimitiveKind::Int8:
@@ -176,7 +158,7 @@ bool AnalyseFunction(Napi::Env, InstanceData *, FunctionInfo *func)
176
158
  }
177
159
  }
178
160
  } break;
179
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
161
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
180
162
  case PrimitiveKind::Float32:
181
163
  case PrimitiveKind::Float64: {
182
164
  #if defined(__ARM_PCS_VFP)
@@ -206,7 +188,7 @@ bool AnalyseFunction(Napi::Env, InstanceData *, FunctionInfo *func)
206
188
  }
207
189
  } break;
208
190
 
209
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
191
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
210
192
  }
211
193
 
212
194
  func->args_size += AlignLen(param.type->size, 16);
@@ -300,12 +282,12 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
300
282
  // Push arguments
301
283
  for (Size i = 0; i < func->parameters.len; i++) {
302
284
  const ParameterInfo &param = func->parameters[i];
303
- RG_ASSERT(param.directions >= 1 && param.directions <= 3);
285
+ K_ASSERT(param.directions >= 1 && param.directions <= 3);
304
286
 
305
287
  Napi::Value value = info[param.offset];
306
288
 
307
289
  switch (param.type->primitive) {
308
- case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
290
+ case PrimitiveKind::Void: { K_UNREACHABLE(); } break;
309
291
 
310
292
  case PrimitiveKind::Bool: {
311
293
  if (!value.IsBoolean()) [[unlikely]] {
@@ -372,7 +354,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
372
354
  return false;
373
355
  vec_ptr += param.vec_count;
374
356
  } else if (param.gpr_count) {
375
- RG_ASSERT(param.type->align <= 8);
357
+ K_ASSERT(param.type->align <= 8);
376
358
 
377
359
  int16_t align = (param.type->align <= 4) ? 4 : 8;
378
360
  gpr_ptr = AlignUp(gpr_ptr, align);
@@ -391,7 +373,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
391
373
  args_ptr += (param.type->size + 3) / 4;
392
374
  }
393
375
  } break;
394
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
376
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
395
377
  case PrimitiveKind::Float32: {
396
378
  if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
397
379
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
@@ -437,7 +419,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
437
419
  *(void **)((param.gpr_count ? gpr_ptr : args_ptr)++) = ptr;
438
420
  } break;
439
421
 
440
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
422
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
441
423
  }
442
424
  }
443
425
 
@@ -487,16 +469,16 @@ void CallData::Execute(const FunctionInfo *func, void *native)
487
469
  case PrimitiveKind::Union: {
488
470
  if (func->ret.vec_count) {
489
471
  HfaRet ret = PERFORM_CALL(DDDD);
490
- memcpy(&result.buf, &ret, RG_SIZE(ret));
472
+ memcpy(&result.buf, &ret, K_SIZE(ret));
491
473
  } else {
492
474
  result.u64 = PERFORM_CALL(GG);
493
475
  }
494
476
  } break;
495
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
477
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
496
478
  case PrimitiveKind::Float32: { result.f = PERFORM_CALL(F); } break;
497
479
  case PrimitiveKind::Float64: { result.d = PERFORM_CALL(DDDD).d0; } break;
498
480
 
499
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
481
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
500
482
  }
501
483
 
502
484
  #undef PERFORM_CALL
@@ -504,7 +486,7 @@ void CallData::Execute(const FunctionInfo *func, void *native)
504
486
 
505
487
  Napi::Value CallData::Complete(const FunctionInfo *func)
506
488
  {
507
- RG_DEFER {
489
+ K_DEFER {
508
490
  PopOutArguments();
509
491
 
510
492
  if (func->ret.type->dispose) {
@@ -536,7 +518,7 @@ Napi::Value CallData::Complete(const FunctionInfo *func)
536
518
  case PrimitiveKind::Callback: {
537
519
  if (result.ptr) {
538
520
  Napi::External<void> external = Napi::External<void>::New(env, result.ptr);
539
- SetValueTag(instance, external, func->ret.type->ref.marker);
521
+ SetValueTag(external, func->ret.type->ref.marker);
540
522
 
541
523
  return external;
542
524
  } else {
@@ -551,14 +533,14 @@ Napi::Value CallData::Complete(const FunctionInfo *func)
551
533
  Napi::Object obj = DecodeObject(env, ptr, func->ret.type);
552
534
  return obj;
553
535
  } break;
554
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
536
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
555
537
  case PrimitiveKind::Float32: return Napi::Number::New(env, (double)result.f);
556
538
  case PrimitiveKind::Float64: return Napi::Number::New(env, result.d);
557
539
 
558
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
540
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
559
541
  }
560
542
 
561
- RG_UNREACHABLE();
543
+ K_UNREACHABLE();
562
544
  }
563
545
 
564
546
  void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_stack, BackRegisters *out_reg)
@@ -578,7 +560,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
578
560
  uint8_t *return_ptr = proto->ret.use_memory ? (uint8_t *)gpr_ptr[0] : nullptr;
579
561
  gpr_ptr += proto->ret.use_memory;
580
562
 
581
- RG_DEFER_N(err_guard) { memset(out_reg, 0, RG_SIZE(*out_reg)); };
563
+ K_DEFER_N(err_guard) { memset(out_reg, 0, K_SIZE(*out_reg)); };
582
564
 
583
565
  if (trampoline.generation >= 0 && trampoline.generation != (int32_t)mem->generation) [[unlikely]] {
584
566
  ThrowError<Napi::Error>(env, "Cannot use non-registered callback beyond FFI call");
@@ -592,10 +574,10 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
592
574
  // Convert to JS arguments
593
575
  for (Size i = 0; i < proto->parameters.len; i++) {
594
576
  const ParameterInfo &param = proto->parameters[i];
595
- RG_ASSERT(param.directions >= 1 && param.directions <= 3);
577
+ K_ASSERT(param.directions >= 1 && param.directions <= 3);
596
578
 
597
579
  switch (param.type->primitive) {
598
- case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
580
+ case PrimitiveKind::Void: { K_UNREACHABLE(); } break;
599
581
 
600
582
  case PrimitiveKind::Bool: {
601
583
  bool b = *(bool *)((param.gpr_count ? gpr_ptr : args_ptr)++);
@@ -735,7 +717,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
735
717
 
736
718
  if (ptr2) {
737
719
  Napi::External<void> external = Napi::External<void>::New(env, ptr2);
738
- SetValueTag(instance, external, param.type->ref.marker);
720
+ SetValueTag(external, param.type->ref.marker);
739
721
 
740
722
  arguments.Append(external);
741
723
  } else {
@@ -754,7 +736,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
754
736
 
755
737
  vec_ptr += param.vec_count;
756
738
  } else if (param.gpr_count) {
757
- RG_ASSERT(param.type->align <= 8);
739
+ K_ASSERT(param.type->align <= 8);
758
740
 
759
741
  int16_t gpr_size = param.gpr_count * 4;
760
742
  int16_t align = (param.type->align <= 4) ? 4 : 8;
@@ -789,7 +771,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
789
771
  args_ptr += (param.type->size + 3) / 4;
790
772
  }
791
773
  } break;
792
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
774
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
793
775
  case PrimitiveKind::Float32: {
794
776
  float f;
795
777
  if (param.vec_count) [[likely]] {
@@ -822,7 +804,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
822
804
  arguments.Append(arg);
823
805
  } break;
824
806
 
825
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
807
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
826
808
  }
827
809
  }
828
810
 
@@ -936,7 +918,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
936
918
  case PrimitiveKind::Pointer: {
937
919
  uint8_t *ptr;
938
920
 
939
- if (CheckValueTag(instance, value, type->ref.marker)) {
921
+ if (CheckValueTag(value, type->ref.marker)) {
940
922
  ptr = value.As<Napi::External<uint8_t>>().Data();
941
923
  } else if (IsObject(value) && (type->ref.type->primitive == PrimitiveKind::Record ||
942
924
  type->ref.type->primitive == PrimitiveKind::Union)) {
@@ -974,7 +956,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
974
956
  PushObject(obj, type, (uint8_t *)&out_reg->r0);
975
957
  }
976
958
  } break;
977
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
959
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
978
960
  case PrimitiveKind::Float32: {
979
961
  if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
980
962
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
@@ -1010,7 +992,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1010
992
  ptr = ReserveTrampoline(type->ref.proto, func2);
1011
993
  if (!ptr) [[unlikely]]
1012
994
  return;
1013
- } else if (CheckValueTag(instance, value, type->ref.marker)) {
995
+ } else if (CheckValueTag(value, type->ref.marker)) {
1014
996
  ptr = value.As<Napi::External<void>>().Data();
1015
997
  } else if (IsNullOrUndefined(value)) {
1016
998
  ptr = nullptr;
@@ -1022,7 +1004,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1022
1004
  out_reg->r0 = (uint32_t)ptr;
1023
1005
  } break;
1024
1006
 
1025
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
1007
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
1026
1008
  }
1027
1009
 
1028
1010
  #undef RETURN_INTEGER_64_SWAP
@@ -1,23 +1,5 @@
1
- # Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- # this software and associated documentation files (the “Software”), to deal in
5
- # the Software without restriction, including without limitation the rights to use,
6
- # copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
- # Software, and to permit persons to whom the Software is furnished to do so,
8
- # subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
14
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
- # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17
- # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
- # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
- # OTHER DEALINGS IN THE SOFTWARE.
1
+ # SPDX-License-Identifier: MIT
2
+ # SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
21
3
 
22
4
  .syntax unified
23
5
 
@@ -1,27 +1,9 @@
1
- // Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
- //
3
- // Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- // this software and associated documentation files (the “Software”), to deal in
5
- // the Software without restriction, including without limitation the rights to use,
6
- // copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
- // Software, and to permit persons to whom the Software is furnished to do so,
8
- // subject to the following conditions:
9
- //
10
- // The above copyright notice and this permission notice shall be included in all
11
- // copies or substantial portions of the Software.
12
- //
13
- // THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
14
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
- // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17
- // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
- // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
- // OTHER DEALINGS IN THE SOFTWARE.
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
21
3
 
22
4
  #if defined(__aarch64__) || defined(_M_ARM64)
23
5
 
24
- #include "src/core/base/base.hh"
6
+ #include "lib/native/base/base.hh"
25
7
  #include "ffi.hh"
26
8
  #include "call.hh"
27
9
  #include "util.hh"
@@ -31,7 +13,7 @@
31
13
 
32
14
  #include <napi.h>
33
15
 
34
- namespace RG {
16
+ namespace K {
35
17
 
36
18
  struct HfaInfo {
37
19
  int count;
@@ -143,7 +125,7 @@ bool AnalyseFunction(Napi::Env, InstanceData *, FunctionInfo *func)
143
125
 
144
126
  for (ParameterInfo &param: func->parameters) {
145
127
  switch (param.type->primitive) {
146
- case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
128
+ case PrimitiveKind::Void: { K_UNREACHABLE(); } break;
147
129
 
148
130
  case PrimitiveKind::Bool:
149
131
  case PrimitiveKind::Int8:
@@ -233,7 +215,7 @@ bool AnalyseFunction(Napi::Env, InstanceData *, FunctionInfo *func)
233
215
  param.use_memory = true;
234
216
  }
235
217
  } break;
236
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
218
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
237
219
  case PrimitiveKind::Float32:
238
220
  case PrimitiveKind::Float64: {
239
221
  #if defined(_WIN32)
@@ -255,7 +237,7 @@ bool AnalyseFunction(Napi::Env, InstanceData *, FunctionInfo *func)
255
237
  }
256
238
  } break;
257
239
 
258
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
240
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
259
241
  }
260
242
  }
261
243
 
@@ -356,12 +338,12 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
356
338
  // Push arguments
357
339
  for (Size i = 0; i < func->parameters.len; i++) {
358
340
  const ParameterInfo &param = func->parameters[i];
359
- RG_ASSERT(param.directions >= 1 && param.directions <= 3);
341
+ K_ASSERT(param.directions >= 1 && param.directions <= 3);
360
342
 
361
343
  Napi::Value value = info[param.offset];
362
344
 
363
345
  switch (param.type->primitive) {
364
- case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
346
+ case PrimitiveKind::Void: { K_UNREACHABLE(); } break;
365
347
 
366
348
  case PrimitiveKind::Bool: {
367
349
  if (!value.IsBoolean()) [[unlikely]] {
@@ -455,7 +437,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
455
437
  vec_ptr += param.vec_count;
456
438
  } else if (!param.use_memory) {
457
439
  if (param.gpr_count) {
458
- RG_ASSERT(param.type->align <= 8);
440
+ K_ASSERT(param.type->align <= 8);
459
441
 
460
442
  if (!PushObject(obj, param.type, (uint8_t *)gpr_ptr))
461
443
  return false;
@@ -472,8 +454,8 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
472
454
  uint8_t *ptr = AllocHeap(param.type->size, 16);
473
455
 
474
456
  if (param.gpr_count) {
475
- RG_ASSERT(param.gpr_count == 1);
476
- RG_ASSERT(param.vec_count == 0);
457
+ K_ASSERT(param.gpr_count == 1);
458
+ K_ASSERT(param.vec_count == 0);
477
459
 
478
460
  *(uint8_t **)(gpr_ptr++) = ptr;
479
461
  } else {
@@ -487,7 +469,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
487
469
  return false;
488
470
  }
489
471
  } break;
490
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
472
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
491
473
  case PrimitiveKind::Float32: {
492
474
  if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
493
475
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
@@ -547,7 +529,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
547
529
  *(void **)((param.gpr_count ? gpr_ptr : args_ptr)++) = ptr;
548
530
  } break;
549
531
 
550
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
532
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
551
533
  }
552
534
  }
553
535
 
@@ -565,7 +547,7 @@ void CallData::Execute(const FunctionInfo *func, void *native)
565
547
  TEB *teb = GetTEB();
566
548
 
567
549
  // Restore previous stack limits at the end
568
- RG_DEFER_C(exception_list = teb->ExceptionList,
550
+ K_DEFER_C(exception_list = teb->ExceptionList,
569
551
  base = teb->StackBase,
570
552
  limit = teb->StackLimit,
571
553
  dealloc = teb->DeallocationStack,
@@ -623,19 +605,19 @@ void CallData::Execute(const FunctionInfo *func, void *native)
623
605
  case PrimitiveKind::Union: {
624
606
  if (func->ret.gpr_count) {
625
607
  X0X1Ret ret = PERFORM_CALL(GG);
626
- memcpy(&result.buf, &ret, RG_SIZE(ret));
608
+ memcpy(&result.buf, &ret, K_SIZE(ret));
627
609
  } else if (func->ret.vec_count) {
628
610
  HfaRet ret = PERFORM_CALL(DDDD);
629
- memcpy(&result.buf, &ret, RG_SIZE(ret));
611
+ memcpy(&result.buf, &ret, K_SIZE(ret));
630
612
  } else {
631
613
  PERFORM_CALL(GG);
632
614
  }
633
615
  } break;
634
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
616
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
635
617
  case PrimitiveKind::Float32: { result.f = PERFORM_CALL(F); } break;
636
618
  case PrimitiveKind::Float64: { result.d = PERFORM_CALL(DDDD).d0; } break;
637
619
 
638
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
620
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
639
621
  }
640
622
 
641
623
  #undef PERFORM_CALL
@@ -643,7 +625,7 @@ void CallData::Execute(const FunctionInfo *func, void *native)
643
625
 
644
626
  Napi::Value CallData::Complete(const FunctionInfo *func)
645
627
  {
646
- RG_DEFER {
628
+ K_DEFER {
647
629
  PopOutArguments();
648
630
 
649
631
  if (func->ret.type->dispose) {
@@ -675,7 +657,7 @@ Napi::Value CallData::Complete(const FunctionInfo *func)
675
657
  case PrimitiveKind::Callback: {
676
658
  if (result.ptr) {
677
659
  Napi::External<void> external = Napi::External<void>::New(env, result.ptr);
678
- SetValueTag(instance, external, func->ret.type->ref.marker);
660
+ SetValueTag(external, func->ret.type->ref.marker);
679
661
 
680
662
  return external;
681
663
  } else {
@@ -699,14 +681,14 @@ Napi::Value CallData::Complete(const FunctionInfo *func)
699
681
  return obj;
700
682
  }
701
683
  } break;
702
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
684
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
703
685
  case PrimitiveKind::Float32: return Napi::Number::New(env, (double)result.f);
704
686
  case PrimitiveKind::Float64: return Napi::Number::New(env, result.d);
705
687
 
706
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
688
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
707
689
  }
708
690
 
709
- RG_UNREACHABLE();
691
+ K_UNREACHABLE();
710
692
  }
711
693
 
712
694
  void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_stack, BackRegisters *out_reg)
@@ -718,7 +700,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
718
700
  TEB *teb = GetTEB();
719
701
 
720
702
  // Restore previous stack limits at the end
721
- RG_DEFER_C(base = teb->StackBase,
703
+ K_DEFER_C(base = teb->StackBase,
722
704
  limit = teb->StackLimit,
723
705
  dealloc = teb->DeallocationStack) {
724
706
  teb->StackBase = base;
@@ -743,7 +725,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
743
725
 
744
726
  uint8_t *return_ptr = proto->ret.use_memory ? (uint8_t *)gpr_ptr[8] : nullptr;
745
727
 
746
- RG_DEFER_N(err_guard) { memset(out_reg, 0, RG_SIZE(*out_reg)); };
728
+ K_DEFER_N(err_guard) { memset(out_reg, 0, K_SIZE(*out_reg)); };
747
729
 
748
730
  if (trampoline.generation >= 0 && trampoline.generation != (int32_t)mem->generation) [[unlikely]] {
749
731
  ThrowError<Napi::Error>(env, "Cannot use non-registered callback beyond FFI call");
@@ -757,10 +739,10 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
757
739
  // Convert to JS arguments
758
740
  for (Size i = 0; i < proto->parameters.len; i++) {
759
741
  const ParameterInfo &param = proto->parameters[i];
760
- RG_ASSERT(param.directions >= 1 && param.directions <= 3);
742
+ K_ASSERT(param.directions >= 1 && param.directions <= 3);
761
743
 
762
744
  switch (param.type->primitive) {
763
- case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
745
+ case PrimitiveKind::Void: { K_UNREACHABLE(); } break;
764
746
 
765
747
  case PrimitiveKind::Bool: {
766
748
  #if defined(__APPLE__)
@@ -1054,7 +1036,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1054
1036
 
1055
1037
  if (ptr2) {
1056
1038
  Napi::External<void> external = Napi::External<void>::New(env, ptr2);
1057
- SetValueTag(instance, external, param.type->ref.marker);
1039
+ SetValueTag(external, param.type->ref.marker);
1058
1040
 
1059
1041
  arguments.Append(external);
1060
1042
  } else {
@@ -1078,7 +1060,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1078
1060
  vec_ptr += param.vec_count;
1079
1061
  } else if (!param.use_memory) {
1080
1062
  if (param.gpr_count) {
1081
- RG_ASSERT(param.type->align <= 8);
1063
+ K_ASSERT(param.type->align <= 8);
1082
1064
 
1083
1065
  Napi::Object obj = DecodeObject(env, (uint8_t *)gpr_ptr, param.type);
1084
1066
  arguments.Append(obj);
@@ -1103,7 +1085,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1103
1085
  arguments.Append(obj);
1104
1086
  }
1105
1087
  } break;
1106
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
1088
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
1107
1089
  case PrimitiveKind::Float32: {
1108
1090
  float f;
1109
1091
  if (param.vec_count) [[likely]] {
@@ -1145,7 +1127,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1145
1127
  arguments.Append(arg);
1146
1128
  } break;
1147
1129
 
1148
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
1130
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
1149
1131
  }
1150
1132
  }
1151
1133
 
@@ -1235,7 +1217,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1235
1217
  case PrimitiveKind::Pointer: {
1236
1218
  uint8_t *ptr;
1237
1219
 
1238
- if (CheckValueTag(instance, value, type->ref.marker)) {
1220
+ if (CheckValueTag(value, type->ref.marker)) {
1239
1221
  ptr = value.As<Napi::External<uint8_t>>().Data();
1240
1222
  } else if (IsObject(value) && (type->ref.type->primitive == PrimitiveKind::Record ||
1241
1223
  type->ref.type->primitive == PrimitiveKind::Union)) {
@@ -1276,7 +1258,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1276
1258
  PushObject(obj, type, (uint8_t *)&out_reg->x0);
1277
1259
  }
1278
1260
  } break;
1279
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
1261
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
1280
1262
  case PrimitiveKind::Float32: {
1281
1263
  if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
1282
1264
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
@@ -1306,7 +1288,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1306
1288
  ptr = ReserveTrampoline(type->ref.proto, func2);
1307
1289
  if (!ptr) [[unlikely]]
1308
1290
  return;
1309
- } else if (CheckValueTag(instance, value, type->ref.marker)) {
1291
+ } else if (CheckValueTag(value, type->ref.marker)) {
1310
1292
  ptr = value.As<Napi::External<void>>().Data();
1311
1293
  } else if (IsNullOrUndefined(value)) {
1312
1294
  ptr = nullptr;
@@ -1318,7 +1300,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1318
1300
  out_reg->x0 = (uint64_t)ptr;
1319
1301
  } break;
1320
1302
 
1321
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
1303
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
1322
1304
  }
1323
1305
 
1324
1306
  #undef RETURN_INTEGER_SWAP
@@ -1,23 +1,5 @@
1
- # Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- # this software and associated documentation files (the “Software”), to deal in
5
- # the Software without restriction, including without limitation the rights to use,
6
- # copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
- # Software, and to permit persons to whom the Software is furnished to do so,
8
- # subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
14
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
- # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17
- # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
- # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
- # OTHER DEALINGS IN THE SOFTWARE.
1
+ # SPDX-License-Identifier: MIT
2
+ # SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
21
3
 
22
4
  #if defined(__APPLE__)
23
5
  #define SYMBOL(Symbol) _ ## Symbol
@@ -1,23 +1,5 @@
1
- ; Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
- ;
3
- ; Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- ; this software and associated documentation files (the “Software”), to deal in
5
- ; the Software without restriction, including without limitation the rights to use,
6
- ; copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
- ; Software, and to permit persons to whom the Software is furnished to do so,
8
- ; subject to the following conditions:
9
- ;
10
- ; The above copyright notice and this permission notice shall be included in all
11
- ; copies or substantial portions of the Software.
12
- ;
13
- ; THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
14
- ; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
- ; OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
- ; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17
- ; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
- ; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
- ; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
- ; OTHER DEALINGS IN THE SOFTWARE.
1
+ ; SPDX-License-Identifier: MIT
2
+ ; SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
21
3
 
22
4
  AREA |.text|, CODE
23
5
 
@@ -1,23 +1,5 @@
1
- // Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
- //
3
- // Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- // this software and associated documentation files (the “Software”), to deal in
5
- // the Software without restriction, including without limitation the rights to use,
6
- // copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
- // Software, and to permit persons to whom the Software is furnished to do so,
8
- // subject to the following conditions:
9
- //
10
- // The above copyright notice and this permission notice shall be included in all
11
- // copies or substantial portions of the Software.
12
- //
13
- // THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
14
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
- // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17
- // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
- // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
- // OTHER DEALINGS IN THE SOFTWARE.
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
21
3
 
22
4
  // There's nothing to see here, this architecture uses the ABI code in abi_riscv64.cc!
23
5
  // This file only exists to avoid leaving abi_loong64_asm.S alone :)
@@ -1,23 +1,5 @@
1
- # Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- # this software and associated documentation files (the “Software”), to deal in
5
- # the Software without restriction, including without limitation the rights to use,
6
- # copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
- # Software, and to permit persons to whom the Software is furnished to do so,
8
- # subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
14
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
- # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17
- # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
- # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
- # OTHER DEALINGS IN THE SOFTWARE.
1
+ # SPDX-License-Identifier: MIT
2
+ # SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
21
3
 
22
4
  #define SYMBOL(Symbol) Symbol
23
5