koffi 2.3.8 → 2.3.10-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.
Files changed (83) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/LICENSE.txt +22 -165
  3. package/README.md +2 -2
  4. package/{src/koffi/build/2.3.8 → build/2.3.10-beta.1}/koffi_darwin_arm64/koffi.node +0 -0
  5. package/{src/koffi/build/2.3.8 → build/2.3.10-beta.1}/koffi_darwin_x64/koffi.node +0 -0
  6. package/build/2.3.10-beta.1/koffi_freebsd_arm64/koffi.node +0 -0
  7. package/build/2.3.10-beta.1/koffi_freebsd_ia32/koffi.node +0 -0
  8. package/build/2.3.10-beta.1/koffi_freebsd_x64/koffi.node +0 -0
  9. package/build/2.3.10-beta.1/koffi_linux_arm32hf/koffi.node +0 -0
  10. package/build/2.3.10-beta.1/koffi_linux_arm64/koffi.node +0 -0
  11. package/build/2.3.10-beta.1/koffi_linux_ia32/koffi.node +0 -0
  12. package/build/2.3.10-beta.1/koffi_linux_riscv64hf64/koffi.node +0 -0
  13. package/build/2.3.10-beta.1/koffi_linux_x64/koffi.node +0 -0
  14. package/build/2.3.10-beta.1/koffi_openbsd_ia32/koffi.node +0 -0
  15. package/build/2.3.10-beta.1/koffi_openbsd_x64/koffi.node +0 -0
  16. package/{src/koffi/build/2.3.8 → build/2.3.10-beta.1}/koffi_win32_arm64/koffi.node +0 -0
  17. package/{src/koffi/build/2.3.8 → build/2.3.10-beta.1}/koffi_win32_ia32/koffi.node +0 -0
  18. package/{src/koffi/build/2.3.8 → build/2.3.10-beta.1}/koffi_win32_x64/koffi.node +0 -0
  19. package/doc/index.rst +2 -2
  20. package/doc/static/custom.css +18 -10
  21. package/package.json +7 -7
  22. package/src/cnoke/LICENSE.txt +22 -165
  23. package/src/cnoke/assets/FindCNoke.cmake +18 -10
  24. package/src/cnoke/assets/win_delay_hook.c +18 -10
  25. package/src/cnoke/cnoke.js +18 -10
  26. package/src/cnoke/package.json +1 -1
  27. package/src/cnoke/src/builder.js +18 -10
  28. package/src/cnoke/src/index.js +18 -10
  29. package/src/cnoke/src/tools.js +18 -10
  30. package/src/core/libcc/libcc.cc +93 -33
  31. package/src/core/libcc/libcc.hh +31 -14
  32. package/src/{koffi/src/index.d.ts → index.d.ts} +22 -14
  33. package/src/index.js +50 -0
  34. package/src/koffi/CMakeLists.txt +27 -19
  35. package/src/koffi/src/abi_arm32.cc +19 -11
  36. package/src/koffi/src/abi_arm32_asm.S +211 -0
  37. package/src/koffi/src/abi_arm64.cc +19 -11
  38. package/src/koffi/src/abi_arm64_asm.S +238 -0
  39. package/src/koffi/src/abi_arm64_asm.asm +207 -0
  40. package/src/koffi/src/abi_riscv64.cc +19 -11
  41. package/src/koffi/src/abi_riscv64_asm.S +239 -0
  42. package/src/koffi/src/abi_x64_sysv.cc +19 -11
  43. package/src/koffi/src/abi_x64_sysv_asm.S +272 -0
  44. package/src/koffi/src/abi_x64_win.cc +19 -11
  45. package/src/koffi/src/abi_x64_win_asm.asm +203 -0
  46. package/src/koffi/src/abi_x86.cc +19 -11
  47. package/src/koffi/src/abi_x86_asm.S +213 -0
  48. package/src/koffi/src/abi_x86_asm.asm +191 -0
  49. package/src/koffi/src/call.cc +18 -10
  50. package/src/koffi/src/call.hh +18 -10
  51. package/src/koffi/src/ffi.cc +18 -10
  52. package/src/koffi/src/ffi.hh +18 -10
  53. package/src/koffi/src/parser.cc +18 -10
  54. package/src/koffi/src/parser.hh +18 -10
  55. package/src/koffi/src/{abi_arm64_fwd.asm → trampolines/armasm.inc} +18 -193
  56. package/src/koffi/src/{abi_arm64_fwd.S → trampolines/gnu.inc} +18 -226
  57. package/src/koffi/src/{abi_x86_fwd.asm → trampolines/masm32.inc} +1042 -1203
  58. package/src/koffi/src/{abi_x64_win_fwd.asm → trampolines/masm64.inc} +1042 -1215
  59. package/src/koffi/src/{abi_trampolines.inc → trampolines/prototypes.inc} +18 -10
  60. package/src/koffi/src/util.cc +18 -10
  61. package/src/koffi/src/util.hh +18 -10
  62. package/src/koffi/src/win32.hh +18 -10
  63. package/src/koffi/build/2.3.8/koffi_freebsd_arm64/koffi.node +0 -0
  64. package/src/koffi/build/2.3.8/koffi_freebsd_ia32/koffi.node +0 -0
  65. package/src/koffi/build/2.3.8/koffi_freebsd_x64/koffi.node +0 -0
  66. package/src/koffi/build/2.3.8/koffi_linux_arm32hf/koffi.node +0 -0
  67. package/src/koffi/build/2.3.8/koffi_linux_arm64/koffi.node +0 -0
  68. package/src/koffi/build/2.3.8/koffi_linux_ia32/koffi.node +0 -0
  69. package/src/koffi/build/2.3.8/koffi_linux_riscv64hf64/koffi.node +0 -0
  70. package/src/koffi/build/2.3.8/koffi_linux_x64/koffi.node +0 -0
  71. package/src/koffi/build/2.3.8/koffi_openbsd_ia32/koffi.node +0 -0
  72. package/src/koffi/build/2.3.8/koffi_openbsd_x64/koffi.node +0 -0
  73. package/src/koffi/src/abi_arm32_fwd.S +0 -6344
  74. package/src/koffi/src/abi_riscv64_fwd.S +0 -6375
  75. package/src/koffi/src/abi_x64_sysv_fwd.S +0 -6410
  76. package/src/koffi/src/abi_x86_fwd.S +0 -6346
  77. package/src/koffi/src/index.js +0 -57
  78. /package/{src/koffi/build/2.3.8 → build/2.3.10-beta.1}/koffi_win32_arm64/koffi.exp +0 -0
  79. /package/{src/koffi/build/2.3.8 → build/2.3.10-beta.1}/koffi_win32_arm64/koffi.lib +0 -0
  80. /package/{src/koffi/build/2.3.8 → build/2.3.10-beta.1}/koffi_win32_ia32/koffi.exp +0 -0
  81. /package/{src/koffi/build/2.3.8 → build/2.3.10-beta.1}/koffi_win32_ia32/koffi.lib +0 -0
  82. /package/{src/koffi/build/2.3.8 → build/2.3.10-beta.1}/koffi_win32_x64/koffi.exp +0 -0
  83. /package/{src/koffi/build/2.3.8 → build/2.3.10-beta.1}/koffi_win32_x64/koffi.lib +0 -0
@@ -1,15 +1,23 @@
1
- // This program is free software: you can redistribute it and/or modify
2
- // it under the terms of the GNU Lesser 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.
1
+ // Copyright 2023 Niels Martignène <niels.martignene@protonmail.com>
5
2
  //
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 Lesser General Public License for more details.
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:
10
9
  //
11
- // You should have received a copy of the GNU Lesser General Public License
12
- // along with this program. If not, see https://www.gnu.org/licenses/.
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.
13
21
 
14
22
  'use strict';
15
23
 
@@ -1,15 +1,23 @@
1
- // This program is free software: you can redistribute it and/or modify
2
- // it under the terms of the GNU Lesser 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.
1
+ // Copyright 2023 Niels Martignène <niels.martignene@protonmail.com>
5
2
  //
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 Lesser General Public License for more details.
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:
10
9
  //
11
- // You should have received a copy of the GNU Lesser General Public License
12
- // along with this program. If not, see https://www.gnu.org/licenses/.
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.
13
21
 
14
22
  const builder = require('./builder.js');
15
23
  const tools = require('./tools.js');
@@ -1,15 +1,23 @@
1
- // This program is free software: you can redistribute it and/or modify
2
- // it under the terms of the GNU Lesser 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.
1
+ // Copyright 2023 Niels Martignène <niels.martignene@protonmail.com>
5
2
  //
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 Lesser General Public License for more details.
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:
10
9
  //
11
- // You should have received a copy of the GNU Lesser General Public License
12
- // along with this program. If not, see https://www.gnu.org/licenses/.
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.
13
21
 
14
22
  'use strict';
15
23
 
@@ -1,15 +1,23 @@
1
- // This program is free software: you can redistribute it and/or modify
2
- // it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
10
- //
11
- // You should have received a copy of the GNU Lesser General Public License
12
- // along with this program. If not, see <https://www.gnu.org/licenses/>.
1
+ // Copyright 2023 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.
13
21
 
14
22
  #include "libcc.hh"
15
23
  #if !defined(LIBCC_NO_MINIZ) && __has_include("vendor/miniz/miniz.h")
@@ -7407,51 +7415,103 @@ void InitPackedMap(Span<const AssetInfo> assets)
7407
7415
 
7408
7416
  #endif
7409
7417
 
7410
- // This won't win any beauty or speed contest (especially when writing
7411
- // a compressed stream) but whatever.
7412
- Span<const uint8_t> PatchAsset(const AssetInfo &asset, Allocator *alloc,
7413
- FunctionRef<void(const char *, StreamWriter *)> func)
7418
+ bool PatchFile(StreamReader *reader, StreamWriter *writer,
7419
+ FunctionRef<void(Span<const char>, StreamWriter *)> func)
7414
7420
  {
7415
- RG_ASSERT(alloc);
7416
-
7417
- HeapArray<uint8_t> buf(alloc);
7418
-
7419
- StreamReader reader(asset.data, nullptr, asset.compression_type);
7420
- StreamWriter writer(&buf, nullptr, asset.compression_type);
7421
-
7422
7421
  char c;
7423
- while (reader.Read(1, &c) == 1) {
7422
+ while (reader->Read(1, &c) == 1) {
7424
7423
  if (c == '{') {
7425
7424
  char name[33] = {};
7426
- Size name_len = reader.Read(1, &name[0]);
7425
+ Size name_len = reader->Read(1, &name[0]);
7427
7426
  RG_ASSERT(name_len >= 0);
7428
7427
 
7429
7428
  if (IsAsciiAlpha(name[0]) || name[0] == '_') {
7430
7429
  do {
7431
- Size read_len = reader.Read(1, &name[name_len]);
7430
+ Size read_len = reader->Read(1, &name[name_len]);
7432
7431
  RG_ASSERT(read_len >= 0);
7433
7432
 
7434
7433
  if (name[name_len] == '}') {
7435
7434
  name[name_len] = 0;
7436
- func(name, &writer);
7435
+
7436
+ Span<const char> key = MakeSpan(name, name_len);
7437
+ func(key, writer);
7437
7438
 
7438
7439
  break;
7439
7440
  } else if (!IsAsciiAlphaOrDigit(name[name_len]) && name[name_len] != '_') {
7440
- writer.Write('{');
7441
- writer.Write(name, name_len + 1);
7441
+ writer->Write('{');
7442
+ writer->Write(name, name_len + 1);
7442
7443
 
7443
7444
  break;
7444
7445
  }
7445
7446
  } while (++name_len < RG_SIZE(name));
7446
7447
  } else {
7447
- writer.Write('{');
7448
- writer.Write(name[0]);
7448
+ writer->Write('{');
7449
+ writer->Write(name[0]);
7449
7450
  }
7450
7451
  } else {
7451
- writer.Write(c);
7452
+ writer->Write(c);
7452
7453
  }
7453
7454
  }
7454
- RG_ASSERT(reader.IsValid());
7455
+
7456
+ if (!reader->IsValid())
7457
+ return false;
7458
+ if (!writer->IsValid())
7459
+ return false;
7460
+
7461
+ return true;
7462
+ }
7463
+
7464
+ bool PatchFile(Span<const uint8_t> data, StreamWriter *writer,
7465
+ FunctionRef<void(Span<const char>, StreamWriter *)> func)
7466
+ {
7467
+ StreamReader reader(data, nullptr);
7468
+
7469
+ if (!PatchFile(&reader, writer, func)) {
7470
+ RG_ASSERT(reader.IsValid());
7471
+ return false;
7472
+ }
7473
+
7474
+ return true;
7475
+ }
7476
+
7477
+ bool PatchFile(const AssetInfo &asset, StreamWriter *writer,
7478
+ FunctionRef<void(Span<const char>, StreamWriter *)> func)
7479
+ {
7480
+ StreamReader reader(asset.data, nullptr, asset.compression_type);
7481
+
7482
+ if (!PatchFile(&reader, writer, func)) {
7483
+ RG_ASSERT(reader.IsValid());
7484
+ return false;
7485
+ }
7486
+
7487
+ return true;
7488
+ }
7489
+
7490
+ Span<const uint8_t> PatchFile(Span<const uint8_t> data, Allocator *alloc,
7491
+ FunctionRef<void(Span<const char>, StreamWriter *)> func)
7492
+ {
7493
+ RG_ASSERT(alloc);
7494
+
7495
+ HeapArray<uint8_t> buf(alloc);
7496
+ StreamWriter writer(&buf, nullptr);
7497
+
7498
+ PatchFile(data, &writer, func);
7499
+
7500
+ bool success = writer.Close();
7501
+ RG_ASSERT(success);
7502
+
7503
+ return buf.Leak();
7504
+ }
7505
+
7506
+ Span<const uint8_t> PatchFile(const AssetInfo &asset, Allocator *alloc,
7507
+ FunctionRef<void(Span<const char>, StreamWriter *)> func)
7508
+ {
7509
+ RG_ASSERT(alloc);
7510
+
7511
+ HeapArray<uint8_t> buf(alloc);
7512
+ StreamWriter writer(&buf, nullptr, asset.compression_type);
7513
+
7514
+ PatchFile(asset, &writer, func);
7455
7515
 
7456
7516
  bool success = writer.Close();
7457
7517
  RG_ASSERT(success);
@@ -1,15 +1,23 @@
1
- // This program is free software: you can redistribute it and/or modify
2
- // it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
10
- //
11
- // You should have received a copy of the GNU Lesser General Public License
12
- // along with this program. If not, see <https://www.gnu.org/licenses/>.
1
+ // Copyright 2023 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.
13
21
 
14
22
  #pragma once
15
23
 
@@ -4602,8 +4610,17 @@ static inline const AssetInfo *FindPackedAsset(const char *name)
4602
4610
 
4603
4611
  #endif
4604
4612
 
4605
- Span<const uint8_t> PatchAsset(const AssetInfo &asset, Allocator *alloc,
4606
- FunctionRef<void(const char *, StreamWriter *)> func);
4613
+ // These functions won't win any beauty or speed contest but whatever
4614
+ bool PatchFile(StreamReader *reader, StreamWriter *writer,
4615
+ FunctionRef<void(Span<const char>, StreamWriter *)> func);
4616
+ bool PatchFile(Span<const uint8_t> data, StreamWriter *writer,
4617
+ FunctionRef<void(Span<const char>, StreamWriter *)> func);
4618
+ bool PatchFile(const AssetInfo &asset, StreamWriter *writer,
4619
+ FunctionRef<void(Span<const char>, StreamWriter *)> func);
4620
+ Span<const uint8_t> PatchFile(Span<const uint8_t> data, Allocator *alloc,
4621
+ FunctionRef<void(Span<const char> key, StreamWriter *)> func);
4622
+ Span<const uint8_t> PatchFile(const AssetInfo &asset, Allocator *alloc,
4623
+ FunctionRef<void(Span<const char> key, StreamWriter *)> func);
4607
4624
 
4608
4625
  // ------------------------------------------------------------------------
4609
4626
  // Options
@@ -1,22 +1,30 @@
1
- // This program is free software: you can redistribute it and/or modify
2
- // it under the terms of the GNU Lesser 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.
1
+ // Copyright 2023 Niels Martignène <niels.martignene@protonmail.com>
5
2
  //
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 Lesser General Public License for more details.
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:
10
9
  //
11
- // You should have received a copy of the GNU Lesser General Public License
12
- // along with this program. If not, see https://www.gnu.org/licenses/.
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.
13
21
 
14
22
  declare module 'koffi' {
15
23
  export function load(path: string): IKoffiLib;
16
24
 
17
- interface IKoffiCType { __brand: 'IKoffiCType' }
18
- interface IKoffiPointerCast { __brand: 'IKoffiPointerCast' }
19
- interface IKoffiRegisteredCallback { __brand: 'IKoffiRegisteredCallback' }
25
+ interface IKoffiCType { __brand: 'IKoffiCType' };
26
+ interface IKoffiPointerCast { __brand: 'IKoffiPointerCast' };
27
+ interface IKoffiRegisteredCallback { __brand: 'IKoffiRegisteredCallback' };
20
28
 
21
29
  type PrimitiveKind = 'Void' | 'Bool' | 'Int8' | 'UInt8' | 'Int16' | 'Int16S' | 'UInt16' | 'UInt16S' |
22
30
  'Int32' | 'Int32S' | 'UInt32' | 'UInt32S' | 'Int64' | 'Int64S' | 'UInt64' | 'UInt64S' |
@@ -71,7 +79,7 @@ declare module 'koffi' {
71
79
 
72
80
  thiscall(definition: string): KoffiFunction;
73
81
  thiscall(name: string, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
74
- }
82
+ };
75
83
 
76
84
  export function struct(name: string, def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
77
85
  export function struct(def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
package/src/index.js ADDED
@@ -0,0 +1,50 @@
1
+ // Copyright 2023 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.
21
+
22
+ 'use strict';
23
+
24
+ const cnoke = require('./cnoke/src/index.js');
25
+ const util = require('util');
26
+ const fs = require('fs');
27
+ const pkg = require('../package.json');
28
+
29
+ if (process.versions.napi == null || process.versions.napi < pkg.cnoke.napi) {
30
+ let major = parseInt(process.versions.node, 10);
31
+ let required = cnoke.get_napi_version(pkg.cnoke.napi, major);
32
+
33
+ if (required != null) {
34
+ throw new Error(`Project ${pkg.name} requires Node >= ${required} in the Node ${major}.x branch (N-API >= ${pkg.cnoke.napi})`);
35
+ } else {
36
+ throw new Error(`Project ${pkg.name} does not support the Node ${major}.x branch (N-API < ${pkg.cnoke.napi})`);
37
+ }
38
+ }
39
+
40
+ let arch = cnoke.determine_arch();
41
+ let filename = __dirname + `/../build/${pkg.version}/koffi_${process.platform}_${arch}/koffi.node`;
42
+
43
+ let native = require(filename);
44
+
45
+ module.exports = {
46
+ ...native,
47
+
48
+ // Deprecated functions
49
+ handle: util.deprecate(native.opaque, 'The koffi.handle() function was deprecated in Koffi 2.1, use koffi.opaque() instead', 'KOFFI001')
50
+ };
@@ -1,15 +1,23 @@
1
- # This program is free software: you can redistribute it and/or modify
2
- # it under the terms of the GNU Lesser 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.
1
+ # Copyright 2023 Niels Martignène <niels.martignene@protonmail.com>
5
2
  #
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 Lesser General Public License for more details.
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:
10
9
  #
11
- # You should have received a copy of the GNU Lesser General Public License
12
- # along with this program. If not, see https://www.gnu.org/licenses/.
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.
13
21
 
14
22
  cmake_minimum_required(VERSION 3.6)
15
23
  project(koffi C CXX ASM)
@@ -61,8 +69,8 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
61
69
 
62
70
  message(STATUS "Using ARMASM64 compiler: ${asm_compiler}")
63
71
 
64
- file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src/abi_arm64_fwd.asm" asm_source)
65
- file(TO_CMAKE_PATH "${CMAKE_CURRENT_BINARY_DIR}/abi_arm64_fwd.obj" asm_object)
72
+ file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src/abi_arm64_asm.asm" asm_source)
73
+ file(TO_CMAKE_PATH "${CMAKE_CURRENT_BINARY_DIR}/abi_arm64_asm.obj" asm_object)
66
74
 
67
75
  add_custom_command(
68
76
  OUTPUT "${asm_object}"
@@ -74,25 +82,25 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
74
82
 
75
83
  list(APPEND KOFFI_SRC src/abi_arm64.cc "${asm_object}")
76
84
  else()
77
- list(APPEND KOFFI_SRC src/abi_arm64.cc src/abi_arm64_fwd.S)
85
+ list(APPEND KOFFI_SRC src/abi_arm64.cc src/abi_arm64_asm.S)
78
86
  endif()
79
87
  elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "riscv")
80
- list(APPEND KOFFI_SRC src/abi_riscv64.cc src/abi_riscv64_fwd.S)
88
+ list(APPEND KOFFI_SRC src/abi_riscv64.cc src/abi_riscv64_asm.S)
81
89
  else()
82
90
  if(WIN32)
83
- list(APPEND KOFFI_SRC src/abi_x64_win.cc src/abi_x64_win_fwd.asm)
91
+ list(APPEND KOFFI_SRC src/abi_x64_win.cc src/abi_x64_win_asm.asm)
84
92
  else()
85
- list(APPEND KOFFI_SRC src/abi_x64_sysv.cc src/abi_x64_sysv_fwd.S)
93
+ list(APPEND KOFFI_SRC src/abi_x64_sysv.cc src/abi_x64_sysv_asm.S)
86
94
  endif()
87
95
  endif()
88
96
  elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
89
97
  if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
90
- list(APPEND KOFFI_SRC src/abi_arm32.cc src/abi_arm32_fwd.S)
98
+ list(APPEND KOFFI_SRC src/abi_arm32.cc src/abi_arm32_asm.S)
91
99
  else()
92
100
  if(WIN32)
93
- list(APPEND KOFFI_SRC src/abi_x86.cc src/abi_x86_fwd.asm)
101
+ list(APPEND KOFFI_SRC src/abi_x86.cc src/abi_x86_asm.asm)
94
102
  else()
95
- list(APPEND KOFFI_SRC src/abi_x86.cc src/abi_x86_fwd.S)
103
+ list(APPEND KOFFI_SRC src/abi_x86.cc src/abi_x86_asm.S)
96
104
  endif()
97
105
  endif()
98
106
  endif()
@@ -1,15 +1,23 @@
1
- // This program is free software: you can redistribute it and/or modify
2
- // it under the terms of the GNU Lesser 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.
1
+ // Copyright 2023 Niels Martignène <niels.martignene@protonmail.com>
5
2
  //
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 Lesser General Public License for more details.
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:
10
9
  //
11
- // You should have received a copy of the GNU Lesser General Public License
12
- // along with this program. If not, see https://www.gnu.org/licenses/.
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.
13
21
 
14
22
  #if defined(__arm__) || (defined(__M_ARM) && !defined(_M_ARM64))
15
23
 
@@ -52,7 +60,7 @@ extern "C" napi_value CallSwitchStack(Napi::Function *func, size_t argc, napi_va
52
60
  uint8_t *old_sp, Span<uint8_t> *new_stack,
53
61
  napi_value (*call)(Napi::Function *func, size_t argc, napi_value *argv));
54
62
 
55
- #include "abi_trampolines.inc"
63
+ #include "trampolines/prototypes.inc"
56
64
 
57
65
  static int IsHFA(const TypeInfo *type)
58
66
  {