koffi 2.3.7 → 2.3.9

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 (87) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/LICENSE.txt +22 -165
  3. package/README.md +2 -2
  4. package/doc/index.rst +2 -2
  5. package/doc/static/custom.css +18 -10
  6. package/package.json +3 -3
  7. package/src/cnoke/LICENSE.txt +22 -165
  8. package/src/cnoke/assets/FindCNoke.cmake +18 -10
  9. package/src/cnoke/assets/win_delay_hook.c +18 -10
  10. package/src/cnoke/cnoke.js +18 -10
  11. package/src/cnoke/package.json +1 -1
  12. package/src/cnoke/src/builder.js +18 -10
  13. package/src/cnoke/src/index.js +18 -10
  14. package/src/cnoke/src/tools.js +18 -10
  15. package/src/core/libcc/libcc.cc +20 -12
  16. package/src/core/libcc/libcc.hh +20 -12
  17. package/src/koffi/CMakeLists.txt +27 -19
  18. package/src/koffi/build/2.3.9/koffi_darwin_arm64/koffi.node +0 -0
  19. package/src/koffi/build/2.3.9/koffi_darwin_x64/koffi.node +0 -0
  20. package/src/koffi/build/2.3.9/koffi_freebsd_arm64/koffi.node +0 -0
  21. package/src/koffi/build/2.3.9/koffi_freebsd_ia32/koffi.node +0 -0
  22. package/src/koffi/build/2.3.9/koffi_freebsd_x64/koffi.node +0 -0
  23. package/src/koffi/build/2.3.9/koffi_linux_arm32hf/koffi.node +0 -0
  24. package/src/koffi/build/2.3.9/koffi_linux_arm64/koffi.node +0 -0
  25. package/src/koffi/build/2.3.9/koffi_linux_ia32/koffi.node +0 -0
  26. package/src/koffi/build/2.3.9/koffi_linux_riscv64hf64/koffi.node +0 -0
  27. package/src/koffi/build/2.3.9/koffi_linux_x64/koffi.node +0 -0
  28. package/src/koffi/build/2.3.9/koffi_openbsd_ia32/koffi.node +0 -0
  29. package/src/koffi/build/2.3.9/koffi_openbsd_x64/koffi.node +0 -0
  30. package/src/koffi/build/2.3.9/koffi_win32_arm64/koffi.node +0 -0
  31. package/src/koffi/build/2.3.9/koffi_win32_ia32/koffi.node +0 -0
  32. package/src/koffi/build/2.3.9/koffi_win32_x64/koffi.node +0 -0
  33. package/src/koffi/src/abi_arm32.cc +19 -11
  34. package/src/koffi/src/abi_arm32_asm.S +211 -0
  35. package/src/koffi/src/abi_arm64.cc +27 -13
  36. package/src/koffi/src/abi_arm64_asm.S +238 -0
  37. package/src/koffi/src/abi_arm64_asm.asm +207 -0
  38. package/src/koffi/src/abi_riscv64.cc +19 -11
  39. package/src/koffi/src/abi_riscv64_asm.S +239 -0
  40. package/src/koffi/src/abi_x64_sysv.cc +19 -11
  41. package/src/koffi/src/abi_x64_sysv_asm.S +272 -0
  42. package/src/koffi/src/abi_x64_win.cc +27 -13
  43. package/src/koffi/src/abi_x64_win_asm.asm +203 -0
  44. package/src/koffi/src/abi_x86.cc +27 -13
  45. package/src/koffi/src/abi_x86_asm.S +213 -0
  46. package/src/koffi/src/abi_x86_asm.asm +191 -0
  47. package/src/koffi/src/call.cc +18 -10
  48. package/src/koffi/src/call.hh +18 -10
  49. package/src/koffi/src/ffi.cc +23 -34
  50. package/src/koffi/src/ffi.hh +18 -10
  51. package/src/koffi/src/index.d.ts +25 -17
  52. package/src/koffi/src/index.js +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 +28 -14
  63. package/src/koffi/build/2.3.7/koffi_darwin_arm64/koffi.node +0 -0
  64. package/src/koffi/build/2.3.7/koffi_darwin_x64/koffi.node +0 -0
  65. package/src/koffi/build/2.3.7/koffi_freebsd_arm64/koffi.node +0 -0
  66. package/src/koffi/build/2.3.7/koffi_freebsd_ia32/koffi.node +0 -0
  67. package/src/koffi/build/2.3.7/koffi_freebsd_x64/koffi.node +0 -0
  68. package/src/koffi/build/2.3.7/koffi_linux_arm32hf/koffi.node +0 -0
  69. package/src/koffi/build/2.3.7/koffi_linux_arm64/koffi.node +0 -0
  70. package/src/koffi/build/2.3.7/koffi_linux_ia32/koffi.node +0 -0
  71. package/src/koffi/build/2.3.7/koffi_linux_riscv64hf64/koffi.node +0 -0
  72. package/src/koffi/build/2.3.7/koffi_linux_x64/koffi.node +0 -0
  73. package/src/koffi/build/2.3.7/koffi_openbsd_ia32/koffi.node +0 -0
  74. package/src/koffi/build/2.3.7/koffi_openbsd_x64/koffi.node +0 -0
  75. package/src/koffi/build/2.3.7/koffi_win32_arm64/koffi.node +0 -0
  76. package/src/koffi/build/2.3.7/koffi_win32_ia32/koffi.node +0 -0
  77. package/src/koffi/build/2.3.7/koffi_win32_x64/koffi.node +0 -0
  78. package/src/koffi/src/abi_arm32_fwd.S +0 -6344
  79. package/src/koffi/src/abi_riscv64_fwd.S +0 -6375
  80. package/src/koffi/src/abi_x64_sysv_fwd.S +0 -6410
  81. package/src/koffi/src/abi_x86_fwd.S +0 -6346
  82. /package/src/koffi/build/{2.3.7 → 2.3.9}/koffi_win32_arm64/koffi.exp +0 -0
  83. /package/src/koffi/build/{2.3.7 → 2.3.9}/koffi_win32_arm64/koffi.lib +0 -0
  84. /package/src/koffi/build/{2.3.7 → 2.3.9}/koffi_win32_ia32/koffi.exp +0 -0
  85. /package/src/koffi/build/{2.3.7 → 2.3.9}/koffi_win32_ia32/koffi.lib +0 -0
  86. /package/src/koffi/build/{2.3.7 → 2.3.9}/koffi_win32_x64/koffi.exp +0 -0
  87. /package/src/koffi/build/{2.3.7 → 2.3.9}/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
  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")
@@ -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
 
@@ -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
  {
@@ -0,0 +1,211 @@
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
+ .syntax unified
23
+
24
+ #define SYMBOL(Symbol) Symbol
25
+
26
+ # Forward
27
+ # ----------------------------
28
+
29
+ # These three are the same, but they differ (in the C side) by their return type.
30
+ # Unlike the three next functions, these ones don't forward XMM argument registers.
31
+ .global ForwardCallGG
32
+ .global ForwardCallF
33
+ .global ForwardCallDDDD
34
+
35
+ # The X variants are slightly slower, and are used when XMM arguments must be forwarded.
36
+ .global ForwardCallXGG
37
+ .global ForwardCallXF
38
+ .global ForwardCallXDDDD
39
+
40
+ # Copy function pointer to r12, in order to save it through argument forwarding.
41
+ # Also make a copy of the SP to CallData::old_sp because the callback system might need it.
42
+ # Save RSP in fp (non-volatile), and use carefully assembled stack provided by caller.
43
+ .macro prologue
44
+ .cfi_startproc
45
+ push {fp, lr}
46
+ .cfi_def_cfa sp, 8
47
+ .cfi_offset 11, 4
48
+ .cfi_offset 14, 8
49
+ mov fp, sp
50
+ .cfi_def_cfa fp, 8
51
+ str fp, [r2, 0]
52
+ mov r12, r0
53
+ mov sp, r1
54
+ add sp, sp, #80
55
+ .endm
56
+
57
+ # Call native function.
58
+ # Once done, restore normal stack pointer and return.
59
+ # The return value is passed untouched through r0, r1, and or FP registers
60
+ .macro epilogue
61
+ blx r12
62
+ mov sp, fp
63
+ .cfi_def_cfa sp, 8
64
+ pop {fp, lr}
65
+ .cfi_def_cfa sp, 0
66
+ .cfi_restore 11
67
+ .cfi_restore 14
68
+ bx lr
69
+ .cfi_endproc
70
+ .endm
71
+
72
+ ForwardCallGG:
73
+ prologue
74
+ add r1, r1, #64
75
+ ldmia r1, {r0-r3}
76
+ epilogue
77
+
78
+ ForwardCallF:
79
+ prologue
80
+ add r1, r1, #64
81
+ ldmia r1, {r0-r3}
82
+ epilogue
83
+
84
+ ForwardCallDDDD:
85
+ prologue
86
+ add r1, r1, #64
87
+ ldmia r1, {r0-r3}
88
+ epilogue
89
+
90
+ ForwardCallXGG:
91
+ prologue
92
+ vldmia r1!, {d0-d7}
93
+ ldmia r1, {r0-r3}
94
+ epilogue
95
+
96
+ ForwardCallXF:
97
+ prologue
98
+ vldmia r1!, {d0-d7}
99
+ ldmia r1, {r0-r3}
100
+ epilogue
101
+
102
+ ForwardCallXDDDD:
103
+ prologue
104
+ vldmia r1!, {d0-d7}
105
+ ldmia r1, {r0-r3}
106
+ epilogue
107
+
108
+ # Callbacks
109
+ # ----------------------------
110
+
111
+ .global RelayCallback
112
+ .global CallSwitchStack
113
+
114
+ # First, make a copy of the GPR argument registers (r0 to r7).
115
+ # Then call the C function RelayCallback with the following arguments:
116
+ # static trampoline ID, a pointer to the saved GPR array, a pointer to the stack
117
+ # arguments of this call, and a pointer to a struct that will contain the result registers.
118
+ # After the call, simply load these registers from the output struct.
119
+ .macro trampoline id
120
+ .cfi_startproc
121
+ push {fp, lr}
122
+ .cfi_def_cfa sp, 8
123
+ .cfi_offset 11, 4
124
+ .cfi_offset 14, 8
125
+ sub sp, sp, #120
126
+ .cfi_def_cfa sp, 128
127
+ add r12, sp, 64
128
+ stmia r12!, {r0-r3}
129
+ mov r0, \id
130
+ mov r1, sp
131
+ add r2, sp, #128
132
+ mov r3, r12
133
+ bl RelayCallback
134
+ add sp, sp, #80
135
+ ldmia sp!, {r0-r1}
136
+ add sp, sp, #32
137
+ .cfi_def_cfa sp, 8
138
+ pop {fp, lr}
139
+ .cfi_def_cfa sp, 0
140
+ .cfi_restore 11
141
+ .cfi_restore 14
142
+ bx lr
143
+ .cfi_endproc
144
+ .endm
145
+
146
+ # Same thing, but also forwards the floating-point argument registers and loads them at the end.
147
+ .macro trampoline_vec id
148
+ .cfi_startproc
149
+ push {fp, lr}
150
+ .cfi_def_cfa sp, 8
151
+ .cfi_offset 11, 4
152
+ .cfi_offset 14, 8
153
+ sub sp, sp, #120
154
+ .cfi_def_cfa sp, 128
155
+ mov r12, sp
156
+ vstmia r12!, {d0-d7}
157
+ stmia r12!, {r0-r3}
158
+ mov r0, \id
159
+ mov r1, sp
160
+ add r2, sp, #128
161
+ mov r3, r12
162
+ bl RelayCallback
163
+ add sp, sp, #80
164
+ ldmia sp!, {r0-r1}
165
+ vldmia sp!, {d0-d3}
166
+ .cfi_def_cfa sp, 8
167
+ pop {fp, lr}
168
+ .cfi_def_cfa sp, 0
169
+ .cfi_restore 11
170
+ .cfi_restore 14
171
+ bx lr
172
+ .cfi_endproc
173
+ .endm
174
+
175
+ # When a callback is relayed, Koffi will call into Node.js and V8 to execute Javascript.
176
+ # The problem is that we're still running on the separate Koffi stack, and V8 will
177
+ # probably misdetect this as a "stack overflow". We have to restore the old
178
+ # stack pointer, call Node.js/V8 and go back to ours.
179
+ # The first three parameters (r0, r1, r2) are passed through untouched.
180
+ CallSwitchStack:
181
+ .cfi_startproc
182
+ push {fp, lr}
183
+ .cfi_def_cfa sp, 8
184
+ push {r4, r5}
185
+ .cfi_def_cfa sp, 16
186
+ .cfi_offset 11, 4
187
+ .cfi_offset 14, 8
188
+ mov fp, sp
189
+ ldr r4, [sp, 16]
190
+ ldr r5, [r4, 0]
191
+ sub r5, sp, r5
192
+ and r5, r5, #-16
193
+ str r5, [r4, 4]
194
+ ldr r4, [sp, 20]
195
+ mov sp, r3
196
+ blx r4
197
+ mov sp, fp
198
+ .cfi_def_cfa sp, 16
199
+ pop {r4, r5}
200
+ .cfi_def_cfa sp, 8
201
+ pop {fp, lr}
202
+ .cfi_def_cfa sp, 0
203
+ .cfi_restore 11
204
+ .cfi_restore 14
205
+ bx lr
206
+ .cfi_endproc
207
+
208
+ # Trampolines
209
+ # ----------------------------
210
+
211
+ #include "trampolines/gnu.inc"
@@ -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(__aarch64__) || defined(_M_ARM64)
15
23
 
@@ -62,7 +70,7 @@ extern "C" napi_value CallSwitchStack(Napi::Function *func, size_t argc, napi_va
62
70
  uint8_t *old_sp, Span<uint8_t> *new_stack,
63
71
  napi_value (*call)(Napi::Function *func, size_t argc, napi_value *argv));
64
72
 
65
- #include "abi_trampolines.inc"
73
+ #include "trampolines/prototypes.inc"
66
74
 
67
75
  static HfaInfo IsHFA(const TypeInfo *type)
68
76
  {
@@ -559,18 +567,24 @@ void CallData::Execute(const FunctionInfo *func)
559
567
  TEB *teb = GetTEB();
560
568
 
561
569
  // Restore previous stack limits at the end
562
- RG_DEFER_C(base = teb->StackBase,
570
+ RG_DEFER_C(exception_list = teb->ExceptionList,
571
+ base = teb->StackBase,
563
572
  limit = teb->StackLimit,
564
- dealloc = teb->DeallocationStack) {
573
+ dealloc = teb->DeallocationStack,
574
+ guaranteed = teb->GuaranteedStackBytes) {
575
+ teb->ExceptionList = exception_list;
565
576
  teb->StackBase = base;
566
577
  teb->StackLimit = limit;
567
578
  teb->DeallocationStack = dealloc;
579
+ teb->GuaranteedStackBytes = guaranteed;
568
580
  };
569
581
 
570
582
  // Adjust stack limits so SEH works correctly
583
+ teb->ExceptionList = (void *)-1; // EXCEPTION_CHAIN_END
571
584
  teb->StackBase = mem->stack0.end();
572
585
  teb->StackLimit = mem->stack0.ptr;
573
586
  teb->DeallocationStack = mem->stack0.ptr;
587
+ teb->GuaranteedStackBytes = 0;
574
588
  #endif
575
589
 
576
590
  #define PERFORM_CALL(Suffix) \