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.
- package/CHANGELOG.md +14 -0
- package/LICENSE.txt +22 -165
- package/README.md +2 -2
- package/doc/index.rst +2 -2
- package/doc/static/custom.css +18 -10
- package/package.json +3 -3
- package/src/cnoke/LICENSE.txt +22 -165
- package/src/cnoke/assets/FindCNoke.cmake +18 -10
- package/src/cnoke/assets/win_delay_hook.c +18 -10
- package/src/cnoke/cnoke.js +18 -10
- package/src/cnoke/package.json +1 -1
- package/src/cnoke/src/builder.js +18 -10
- package/src/cnoke/src/index.js +18 -10
- package/src/cnoke/src/tools.js +18 -10
- package/src/core/libcc/libcc.cc +20 -12
- package/src/core/libcc/libcc.hh +20 -12
- package/src/koffi/CMakeLists.txt +27 -19
- package/src/koffi/build/2.3.9/koffi_darwin_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.9/koffi_darwin_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.9/koffi_freebsd_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.9/koffi_freebsd_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.9/koffi_freebsd_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.9/koffi_linux_arm32hf/koffi.node +0 -0
- package/src/koffi/build/2.3.9/koffi_linux_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.9/koffi_linux_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.9/koffi_linux_riscv64hf64/koffi.node +0 -0
- package/src/koffi/build/2.3.9/koffi_linux_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.9/koffi_openbsd_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.9/koffi_openbsd_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.9/koffi_win32_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.9/koffi_win32_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.9/koffi_win32_x64/koffi.node +0 -0
- package/src/koffi/src/abi_arm32.cc +19 -11
- package/src/koffi/src/abi_arm32_asm.S +211 -0
- package/src/koffi/src/abi_arm64.cc +27 -13
- package/src/koffi/src/abi_arm64_asm.S +238 -0
- package/src/koffi/src/abi_arm64_asm.asm +207 -0
- package/src/koffi/src/abi_riscv64.cc +19 -11
- package/src/koffi/src/abi_riscv64_asm.S +239 -0
- package/src/koffi/src/abi_x64_sysv.cc +19 -11
- package/src/koffi/src/abi_x64_sysv_asm.S +272 -0
- package/src/koffi/src/abi_x64_win.cc +27 -13
- package/src/koffi/src/abi_x64_win_asm.asm +203 -0
- package/src/koffi/src/abi_x86.cc +27 -13
- package/src/koffi/src/abi_x86_asm.S +213 -0
- package/src/koffi/src/abi_x86_asm.asm +191 -0
- package/src/koffi/src/call.cc +18 -10
- package/src/koffi/src/call.hh +18 -10
- package/src/koffi/src/ffi.cc +23 -34
- package/src/koffi/src/ffi.hh +18 -10
- package/src/koffi/src/index.d.ts +25 -17
- package/src/koffi/src/index.js +18 -10
- package/src/koffi/src/parser.cc +18 -10
- package/src/koffi/src/parser.hh +18 -10
- package/src/koffi/src/{abi_arm64_fwd.asm → trampolines/armasm.inc} +18 -193
- package/src/koffi/src/{abi_arm64_fwd.S → trampolines/gnu.inc} +18 -226
- package/src/koffi/src/{abi_x86_fwd.asm → trampolines/masm32.inc} +1042 -1203
- package/src/koffi/src/{abi_x64_win_fwd.asm → trampolines/masm64.inc} +1042 -1215
- package/src/koffi/src/{abi_trampolines.inc → trampolines/prototypes.inc} +18 -10
- package/src/koffi/src/util.cc +18 -10
- package/src/koffi/src/util.hh +18 -10
- package/src/koffi/src/win32.hh +28 -14
- package/src/koffi/build/2.3.7/koffi_darwin_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_darwin_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_freebsd_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_freebsd_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_freebsd_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_linux_arm32hf/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_linux_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_linux_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_linux_riscv64hf64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_linux_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_openbsd_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_openbsd_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_win32_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_win32_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_win32_x64/koffi.node +0 -0
- package/src/koffi/src/abi_arm32_fwd.S +0 -6344
- package/src/koffi/src/abi_riscv64_fwd.S +0 -6375
- package/src/koffi/src/abi_x64_sysv_fwd.S +0 -6410
- package/src/koffi/src/abi_x86_fwd.S +0 -6346
- /package/src/koffi/build/{2.3.7 → 2.3.9}/koffi_win32_arm64/koffi.exp +0 -0
- /package/src/koffi/build/{2.3.7 → 2.3.9}/koffi_win32_arm64/koffi.lib +0 -0
- /package/src/koffi/build/{2.3.7 → 2.3.9}/koffi_win32_ia32/koffi.exp +0 -0
- /package/src/koffi/build/{2.3.7 → 2.3.9}/koffi_win32_ia32/koffi.lib +0 -0
- /package/src/koffi/build/{2.3.7 → 2.3.9}/koffi_win32_x64/koffi.exp +0 -0
- /package/src/koffi/build/{2.3.7 → 2.3.9}/koffi_win32_x64/koffi.lib +0 -0
package/src/koffi/src/call.cc
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
//
|
|
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
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
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
|
-
//
|
|
12
|
-
//
|
|
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 "call.hh"
|
package/src/koffi/src/call.hh
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
//
|
|
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
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
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
|
-
//
|
|
12
|
-
//
|
|
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
|
|
package/src/koffi/src/ffi.cc
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
//
|
|
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
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
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
|
-
//
|
|
12
|
-
//
|
|
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"
|
|
@@ -1144,30 +1152,11 @@ static InstanceMemory *AllocateMemory(InstanceData *instance, Size stack_size, S
|
|
|
1144
1152
|
stack_size = AlignLen(stack_size, Kibibytes(64));
|
|
1145
1153
|
|
|
1146
1154
|
#if defined(_WIN32)
|
|
1147
|
-
static const int PageSize = ([]() {
|
|
1148
|
-
SYSTEM_INFO info = {};
|
|
1149
|
-
|
|
1150
|
-
GetNativeSystemInfo(&info);
|
|
1151
|
-
RG_ASSERT(info.dwPageSize);
|
|
1152
|
-
|
|
1153
|
-
return (int)info.dwPageSize;
|
|
1154
|
-
})();
|
|
1155
|
-
|
|
1156
1155
|
// Allocate stack memory
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
mem->stack.ptr = (uint8_t *)VirtualAlloc(nullptr, mem->stack.len + 2 * PageSize, MEM_RESERVE, PAGE_NOACCESS);
|
|
1160
|
-
|
|
1161
|
-
RG_CRITICAL(mem->stack.ptr, "Failed to allocate %1 of memory", mem->stack.len);
|
|
1162
|
-
|
|
1163
|
-
bool success = true;
|
|
1164
|
-
|
|
1165
|
-
success &= !!VirtualAlloc(mem->stack.ptr + 0 * PageSize, PageSize, MEM_COMMIT, PAGE_NOACCESS);
|
|
1166
|
-
success &= !!VirtualAlloc(mem->stack.ptr + 1 * PageSize, PageSize, MEM_COMMIT, PAGE_READWRITE | PAGE_GUARD);
|
|
1167
|
-
success &= !!VirtualAlloc(mem->stack.ptr + 2 * PageSize, mem->stack.len, MEM_COMMIT, PAGE_READWRITE);
|
|
1156
|
+
mem->stack.len = stack_size;
|
|
1157
|
+
mem->stack.ptr = (uint8_t *)VirtualAlloc(nullptr, mem->stack.len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
|
|
1168
1158
|
|
|
1169
|
-
|
|
1170
|
-
}
|
|
1159
|
+
RG_CRITICAL(mem->stack.ptr, "Failed to allocate %1 of memory", mem->stack.len);
|
|
1171
1160
|
#else
|
|
1172
1161
|
mem->stack.len = stack_size;
|
|
1173
1162
|
mem->stack.ptr = (uint8_t *)mmap(nullptr, mem->stack.len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_STACK, -1, 0);
|
|
@@ -2021,8 +2010,8 @@ static void SetExports(Napi::Env env, Func func)
|
|
|
2021
2010
|
|
|
2022
2011
|
func("struct", Napi::Function::New(env, CreatePaddedStructType));
|
|
2023
2012
|
func("pack", Napi::Function::New(env, CreatePackedStructType));
|
|
2024
|
-
func("union", Napi::Function::New(env, CreateUnionType));
|
|
2025
|
-
func("Union", Napi::Function::New(env, InstantiateUnion));
|
|
2013
|
+
// func("union", Napi::Function::New(env, CreateUnionType));
|
|
2014
|
+
// func("Union", Napi::Function::New(env, InstantiateUnion));
|
|
2026
2015
|
func("opaque", Napi::Function::New(env, CreateOpaqueType));
|
|
2027
2016
|
func("pointer", Napi::Function::New(env, CreatePointerType));
|
|
2028
2017
|
func("array", Napi::Function::New(env, CreateArrayType));
|
package/src/koffi/src/ffi.hh
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
//
|
|
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
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
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
|
-
//
|
|
12
|
-
//
|
|
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
|
|
package/src/koffi/src/index.d.ts
CHANGED
|
@@ -1,26 +1,34 @@
|
|
|
1
|
-
//
|
|
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
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
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
|
-
//
|
|
12
|
-
//
|
|
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' |
|
|
23
|
-
'String' | 'String16' | 'Pointer' | 'Record' | 'Union' | 'Array' | 'Float32' | 'Float64' |
|
|
31
|
+
'String' | 'String16' | 'Pointer' | 'Record' /* | 'Union' */ | 'Array' | 'Float32' | 'Float64' |
|
|
24
32
|
'Prototype' | 'Callback';
|
|
25
33
|
type ArrayHint = 'Array' | 'Typed' | 'String';
|
|
26
34
|
|
|
@@ -71,15 +79,15 @@ 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;
|
|
78
86
|
export function pack(name: string, def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
|
|
79
87
|
export function pack(def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
|
|
80
88
|
|
|
81
|
-
export function union(name: string, def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
|
|
82
|
-
export function union(def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
|
|
89
|
+
// export function union(name: string, def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
|
|
90
|
+
// export function union(def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
|
|
83
91
|
|
|
84
92
|
export function array(ref: TypeSpec, len: number, hint?: ArrayHint | null): IKoffiCType;
|
|
85
93
|
|
package/src/koffi/src/index.js
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
//
|
|
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
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
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
|
-
//
|
|
12
|
-
//
|
|
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
|
|
package/src/koffi/src/parser.cc
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
//
|
|
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
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
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
|
-
//
|
|
12
|
-
//
|
|
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"
|
package/src/koffi/src/parser.hh
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
//
|
|
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
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
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
|
-
//
|
|
12
|
-
//
|
|
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
|
-
;
|
|
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
|
-
;
|
|
7
|
-
;
|
|
8
|
-
;
|
|
9
|
-
;
|
|
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
|
-
;
|
|
12
|
-
;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
;
|
|
17
|
-
;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|