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
  #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
  #include "src/core/libcc/libcc.hh"
15
23
  #include "ffi.hh"
@@ -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
  #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
  #include "src/core/libcc/libcc.hh"
15
23
  #include "ffi.hh"
@@ -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
  #pragma once
15
23
 
@@ -1,198 +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/.
13
-
14
- AREA |.text|, CODE
15
-
16
- ; Forward
17
- ; ----------------------------
18
-
19
- ; These three are the same, but they differ (in the C side) by their return type.
20
- ; Unlike the three next functions, these ones don't forward XMM argument registers.
21
- EXPORT ForwardCallGG
22
- EXPORT ForwardCallF
23
- EXPORT ForwardCallDDDD
24
-
25
- ; The X variants are slightly slower, and are used when XMM arguments must be forwarded.
26
- EXPORT ForwardCallXGG
27
- EXPORT ForwardCallXF
28
- EXPORT ForwardCallXDDDD
29
-
30
- ; Copy function pointer to r9, in order to save it through argument forwarding.
31
- ; Save RSP in r29 (non-volatile), and use carefully assembled stack provided by caller.
32
- MACRO
33
- prologue
34
-
35
- stp x29, x30, [sp, -16]!
36
- mov x29, sp
37
- str x29, [x2, 0]
38
- mov x9, x0
39
- add sp, x1, #136
40
- MEND
41
-
42
- ; Call native function.
43
- ; Once done, restore normal stack pointer and return.
44
- ; The return value is passed untouched through r0, r1, v0 and/or v1.
45
- MACRO
46
- epilogue
47
-
48
- blr x9
49
- mov sp, x29
50
- ldp x29, x30, [sp], 16
51
- ret
52
- MEND
53
-
54
- ; Prepare general purpose argument registers from array passed by caller.
55
- MACRO
56
- forward_gpr
57
-
58
- ldr x8, [x1, 64]
59
- ldp x6, x7, [x1, 48]
60
- ldp x4, x5, [x1, 32]
61
- ldp x2, x3, [x1, 16]
62
- ldp x0, x1, [x1, 0]
63
- MEND
64
-
65
- ; Prepare vector argument registers from array passed by caller.
66
- MACRO
67
- forward_vec
68
-
69
- ldp d6, d7, [x1, 120]
70
- ldp d4, d5, [x1, 104]
71
- ldp d2, d3, [x1, 88]
72
- ldp d0, d1, [x1, 72]
73
- MEND
74
-
75
- ForwardCallGG PROC
76
- prologue
77
- forward_gpr
78
- epilogue
79
- ENDP
80
-
81
- ForwardCallF PROC
82
- prologue
83
- forward_gpr
84
- epilogue
85
- ENDP
86
-
87
- ForwardCallDDDD PROC
88
- prologue
89
- forward_gpr
90
- epilogue
91
- ENDP
92
-
93
- ForwardCallXGG PROC
94
- prologue
95
- forward_vec
96
- forward_gpr
97
- epilogue
98
- ENDP
99
-
100
- ForwardCallXF PROC
101
- prologue
102
- forward_vec
103
- forward_gpr
104
- epilogue
105
- ENDP
106
-
107
- ForwardCallXDDDD PROC
108
- prologue
109
- forward_vec
110
- forward_gpr
111
- epilogue
112
- ENDP
113
-
114
- ; Callbacks
115
- ; ----------------------------
116
-
117
- EXPORT RelayCallback
118
- EXTERN RelayCallback
119
- EXPORT CallSwitchStack
120
-
121
- ; First, make a copy of the GPR argument registers (x0 to x7).
122
- ; Then call the C function RelayCallback with the following arguments:
123
- ; static trampoline ID, a pointer to the saved GPR array, a pointer to the stack
124
- ; arguments of this call, and a pointer to a struct that will contain the result registers.
125
- ; After the call, simply load these registers from the output struct.
126
- MACRO
127
- trampoline $ID
128
-
129
- stp x29, x30, [sp, -16]!
130
- sub sp, sp, #192
131
- stp x0, x1, [sp, 0]
132
- stp x2, x3, [sp, 16]
133
- stp x4, x5, [sp, 32]
134
- stp x6, x7, [sp, 48]
135
- str x8, [sp, 64]
136
- mov x0, $ID
137
- mov x1, sp
138
- add x2, sp, #208
139
- add x3, sp, #136
140
- bl RelayCallback
141
- ldp x0, x1, [sp, 136]
142
- add sp, sp, #192
143
- ldp x29, x30, [sp], 16
144
- ret
145
- MEND
146
-
147
- ; Same thing, but also forwards the floating-point argument registers and loads them at the end.
148
- MACRO
149
- trampoline_vec $ID
150
-
151
- stp x29, x30, [sp, -16]!
152
- sub sp, sp, #192
153
- stp x0, x1, [sp, 0]
154
- stp x2, x3, [sp, 16]
155
- stp x4, x5, [sp, 32]
156
- stp x6, x7, [sp, 48]
157
- str x8, [sp, 64]
158
- stp d0, d1, [sp, 72]
159
- stp d2, d3, [sp, 88]
160
- stp d4, d5, [sp, 104]
161
- stp d6, d7, [sp, 120]
162
- mov x0, $ID
163
- mov x1, sp
164
- add x2, sp, #208
165
- add x3, sp, #136
166
- bl RelayCallback
167
- ldp x0, x1, [sp, 136]
168
- ldp d0, d1, [sp, 152]
169
- ldp d2, d3, [sp, 168]
170
- add sp, sp, #192
171
- ldp x29, x30, [sp], 16
172
- ret
173
- MEND
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 (x0, x1, x2) are passed through untouched.
180
- CallSwitchStack PROC
181
- stp x29, x30, [sp, -16]!
182
- mov x29, sp
183
- ldr x9, [x4, 0]
184
- sub x9, sp, x9
185
- and x9, x9, #-16
186
- str x9, [x4, 8]
187
- mov sp, x3
188
- blr x5
189
- mov sp, x29
190
- ldp x29, x30, [sp], 16
191
- ret
192
- ENDP
193
-
194
- ; Trampolines
195
- ; ----------------------------
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.
196
21
 
197
22
  EXPORT Trampoline0
198
23
  EXPORT Trampoline1
@@ -1,231 +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/.
13
-
14
- #ifdef __APPLE__
15
- #define SYMBOL(Symbol) _ ## Symbol
16
- #else
17
- #define SYMBOL(Symbol) Symbol
18
- #endif
19
-
20
- # Forward
21
- # ----------------------------
22
-
23
- #ifdef __APPLE__
24
- # Fix "arm64 function not 4-byte aligned" linker warnings
25
- .p2align 2
26
- #endif
27
-
28
- # These three are the same, but they differ (in the C side) by their return type.
29
- # Unlike the three next functions, these ones don't forward XMM argument registers.
30
- .global SYMBOL(ForwardCallGG)
31
- .global SYMBOL(ForwardCallF)
32
- .global SYMBOL(ForwardCallDDDD)
33
-
34
- # The X variants are slightly slower, and are used when XMM arguments must be forwarded.
35
- .global SYMBOL(ForwardCallXGG)
36
- .global SYMBOL(ForwardCallXF)
37
- .global SYMBOL(ForwardCallXDDDD)
38
-
39
- # Copy function pointer to r9, in order to save it through argument forwarding.
40
- # Also make a copy of the SP to CallData::old_sp because the callback system might need it.
41
- # Save RSP in r29 (non-volatile), and use carefully assembled stack provided by caller.
42
- .macro prologue
43
- .cfi_startproc
44
- hint #34
45
- stp x29, x30, [sp, -16]!
46
- .cfi_def_cfa sp, 16
47
- .cfi_offset 29, 16
48
- .cfi_offset 30, 8
49
- mov x29, sp
50
- .cfi_def_cfa x29, 16
51
- str x29, [x2, 0]
52
- mov x9, x0
53
- add sp, x1, #136
54
- .endm
55
-
56
- # Call native function.
57
- # Once done, restore normal stack pointer and return.
58
- # The return value is passed untouched through r0, r1, v0 and/or v1.
59
- .macro epilogue
60
- blr x9
61
- mov sp, x29
62
- .cfi_def_cfa sp, 16
63
- ldp x29, x30, [sp], 16
64
- .cfi_def_cfa sp, 0
65
- .cfi_restore 30
66
- .cfi_restore 29
67
- ret
68
- .cfi_endproc
69
- .endm
70
-
71
- # Prepare general purpose argument registers from array passed by caller.
72
- .macro forward_gpr
73
- ldr x8, [x1, 64]
74
- ldp x6, x7, [x1, 48]
75
- ldp x4, x5, [x1, 32]
76
- ldp x2, x3, [x1, 16]
77
- ldp x0, x1, [x1, 0]
78
- .endm
79
-
80
- # Prepare vector argument registers from array passed by caller.
81
- .macro forward_vec
82
- ldp d6, d7, [x1, 120]
83
- ldp d4, d5, [x1, 104]
84
- ldp d2, d3, [x1, 88]
85
- ldp d0, d1, [x1, 72]
86
- .endm
87
-
88
- SYMBOL(ForwardCallGG):
89
- prologue
90
- forward_gpr
91
- epilogue
92
-
93
- SYMBOL(ForwardCallF):
94
- prologue
95
- forward_gpr
96
- epilogue
97
-
98
- SYMBOL(ForwardCallDDDD):
99
- prologue
100
- forward_gpr
101
- epilogue
102
-
103
- SYMBOL(ForwardCallXGG):
104
- prologue
105
- forward_vec
106
- forward_gpr
107
- epilogue
108
-
109
- SYMBOL(ForwardCallXF):
110
- prologue
111
- forward_vec
112
- forward_gpr
113
- epilogue
114
-
115
- SYMBOL(ForwardCallXDDDD):
116
- prologue
117
- forward_vec
118
- forward_gpr
119
- epilogue
120
-
121
- # Callbacks
122
- # ----------------------------
123
-
124
- .global SYMBOL(RelayCallback)
125
- .global SYMBOL(CallSwitchStack)
126
-
127
- # First, make a copy of the GPR argument registers (x0 to x7).
128
- # Then call the C function RelayCallback with the following arguments:
129
- # static trampoline ID, a pointer to the saved GPR array, a pointer to the stack
130
- # arguments of this call, and a pointer to a struct that will contain the result registers.
131
- # After the call, simply load these registers from the output struct.
132
- .macro trampoline id
133
- .cfi_startproc
134
- hint #34
135
- stp x29, x30, [sp, -16]!
136
- .cfi_def_cfa sp, 16
137
- .cfi_offset 29, 16
138
- .cfi_offset 30, 8
139
- sub sp, sp, #192
140
- .cfi_def_cfa sp, 208
141
- stp x0, x1, [sp, 0]
142
- stp x2, x3, [sp, 16]
143
- stp x4, x5, [sp, 32]
144
- stp x6, x7, [sp, 48]
145
- str x8, [sp, 64]
146
- mov x0, \id
147
- mov x1, sp
148
- add x2, sp, #208
149
- add x3, sp, #136
150
- bl SYMBOL(RelayCallback)
151
- ldp x0, x1, [sp, 136]
152
- add sp, sp, #192
153
- .cfi_def_cfa sp, 16
154
- ldp x29, x30, [sp], 16
155
- .cfi_def_cfa sp, 0
156
- .cfi_restore 30
157
- .cfi_restore 29
158
- ret
159
- .cfi_endproc
160
- .endm
161
-
162
- # Same thing, but also forwards the floating-point argument registers and loads them at the end.
163
- .macro trampoline_vec id
164
- .cfi_startproc
165
- hint #34
166
- stp x29, x30, [sp, -16]!
167
- .cfi_def_cfa sp, 16
168
- .cfi_offset 29, 16
169
- .cfi_offset 30, 8
170
- sub sp, sp, #192
171
- .cfi_def_cfa sp, 208
172
- stp x0, x1, [sp, 0]
173
- stp x2, x3, [sp, 16]
174
- stp x4, x5, [sp, 32]
175
- stp x6, x7, [sp, 48]
176
- str x8, [sp, 64]
177
- stp d0, d1, [sp, 72]
178
- stp d2, d3, [sp, 88]
179
- stp d4, d5, [sp, 104]
180
- stp d6, d7, [sp, 120]
181
- mov x0, \id
182
- mov x1, sp
183
- add x2, sp, #208
184
- add x3, sp, #136
185
- bl SYMBOL(RelayCallback)
186
- ldp x0, x1, [sp, 136]
187
- ldp d0, d1, [sp, 152]
188
- ldp d2, d3, [sp, 168]
189
- add sp, sp, #192
190
- .cfi_def_cfa sp, 16
191
- ldp x29, x30, [sp], 16
192
- .cfi_def_cfa sp, 0
193
- .cfi_restore 30
194
- .cfi_restore 29
195
- ret
196
- .cfi_endproc
197
- .endm
198
-
199
- # When a callback is relayed, Koffi will call into Node.js and V8 to execute Javascript.
200
- # The problem is that we're still running on the separate Koffi stack, and V8 will
201
- # probably misdetect this as a "stack overflow". We have to restore the old
202
- # stack pointer, call Node.js/V8 and go back to ours.
203
- # The first three parameters (x0, x1, x2) are passed through untouched.
204
- SYMBOL(CallSwitchStack):
205
- .cfi_startproc
206
- hint #34
207
- stp x29, x30, [sp, -16]!
208
- .cfi_def_cfa sp, 16
209
- .cfi_offset 29, 16
210
- .cfi_offset 30, 8
211
- mov x29, sp
212
- ldr x9, [x4, 0]
213
- sub x9, sp, x9
214
- and x9, x9, #-16
215
- str x9, [x4, 8]
216
- mov sp, x3
217
- blr x5
218
- mov sp, x29
219
- .cfi_def_cfa sp, 16
220
- ldp x29, x30, [sp], 16
221
- .cfi_def_cfa sp, 0
222
- .cfi_restore 30
223
- .cfi_restore 29
224
- ret
225
- .cfi_endproc
226
-
227
- # Trampolines
228
- # ----------------------------
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.
229
21
 
230
22
  .global SYMBOL(Trampoline0)
231
23
  .global SYMBOL(Trampoline1)