koffi 2.16.1 → 3.0.0-alpha.2
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 +2 -2
- package/README.md +8 -8
- package/build/koffi/darwin_arm64/koffi.node +0 -0
- package/build/koffi/darwin_x64/koffi.node +0 -0
- package/build/koffi/freebsd_arm64/koffi.node +0 -0
- package/build/koffi/freebsd_ia32/koffi.node +0 -0
- package/build/koffi/freebsd_x64/koffi.node +0 -0
- package/build/koffi/linux_arm64/koffi.node +0 -0
- package/build/koffi/linux_ia32/koffi.node +0 -0
- package/build/koffi/linux_x64/koffi.node +0 -0
- package/build/koffi/musl_arm64/koffi.node +0 -0
- package/build/koffi/musl_x64/koffi.node +0 -0
- package/build/koffi/openbsd_ia32/koffi.node +0 -0
- package/build/koffi/openbsd_x64/koffi.node +0 -0
- package/build/koffi/win32_ia32/koffi.node +0 -0
- package/build/koffi/win32_x64/koffi.node +0 -0
- package/doc/benchmarks.md +33 -33
- package/doc/benchmarks.xlsx +0 -0
- package/doc/contribute.md +37 -25
- package/doc/index.md +8 -8
- package/doc/variables.md +1 -1
- package/index.d.ts +11 -9
- package/index.js +1 -634
- package/indirect.js +1 -533
- package/lib/native/base/base.cc +63 -85
- package/lib/native/base/base.hh +178 -151
- package/package.json +3 -4
- package/src/build.js +1178 -0
- package/src/koffi/CMakeLists.txt +97 -34
- package/src/koffi/index.js +359 -0
- package/src/koffi/indirect.js +216 -0
- package/src/koffi/src/{abi_arm32.cc → abi/arm32.cc} +279 -275
- package/src/koffi/src/{abi_arm32_asm.S → abi/arm32_asm.S} +2 -5
- package/src/koffi/src/abi/arm64.cc +1511 -0
- package/src/koffi/src/{abi_arm64_asm.S → abi/arm64_asm.S} +44 -23
- package/src/koffi/src/{abi_arm64_asm.asm → abi/arm64_asm.asm} +32 -25
- package/src/koffi/src/{abi_loong64_asm.S → abi/loong64_asm.S} +1 -5
- package/src/koffi/src/{abi_riscv64.cc → abi/riscv64.cc} +279 -273
- package/src/koffi/src/{abi_riscv64_asm.S → abi/riscv64_asm.S} +1 -4
- package/src/koffi/src/abi/x64sysv.cc +1456 -0
- package/src/koffi/src/{abi_x64_sysv_asm.S → abi/x64sysv_asm.S} +30 -33
- package/src/koffi/src/abi/x64win.cc +1121 -0
- package/src/koffi/src/{abi_x64_win_asm.S → abi/x64win_asm.S} +8 -12
- package/src/koffi/src/{abi_x64_win_asm.asm → abi/x64win_asm.asm} +11 -14
- package/src/koffi/src/abi/x86.cc +1233 -0
- package/src/koffi/src/{abi_x86_asm.S → abi/x86_asm.S} +49 -25
- package/src/koffi/src/{abi_x86_asm.asm → abi/x86_asm.asm} +11 -14
- package/src/koffi/src/call.cc +458 -598
- package/src/koffi/src/call.hh +61 -82
- package/src/koffi/src/ffi.cc +595 -309
- package/src/koffi/src/ffi.hh +103 -89
- package/src/koffi/src/parser.cc +0 -4
- package/src/koffi/src/primitives.inc +39 -0
- package/src/koffi/{tools/write_trampolines.js → src/trampolines.js} +1 -1
- package/src/koffi/src/util.cc +503 -446
- package/src/koffi/src/util.hh +269 -57
- package/src/koffi/src/uv.cc +2 -2
- package/src/koffi/src/uv.def +3 -0
- package/src/koffi/src/win32.hh +30 -1
- package/vendor/node-addon-api/napi-inl.h +4 -0
- package/vendor/node-addon-api/napi.h +1 -0
- package/build/koffi/linux_armhf/koffi.node +0 -0
- package/build/koffi/linux_loong64/koffi.node +0 -0
- package/build/koffi/linux_riscv64d/koffi.node +0 -0
- package/build/koffi/win32_arm64/koffi.exp +0 -0
- package/build/koffi/win32_arm64/koffi.lib +0 -0
- package/build/koffi/win32_arm64/koffi.node +0 -0
- package/doc/platforms.md +0 -36
- package/src/cnoke/LICENSE.txt +0 -22
- package/src/cnoke/README.md +0 -99
- package/src/cnoke/assets/FindCNoke.cmake +0 -127
- package/src/cnoke/assets/toolchains.json +0 -126
- package/src/cnoke/assets/win_delay_hook.c +0 -36
- package/src/cnoke/cnoke.js +0 -170
- package/src/cnoke/package.json +0 -24
- package/src/cnoke/src/builder.js +0 -511
- package/src/cnoke/src/index.js +0 -10
- package/src/cnoke/src/tools.js +0 -407
- package/src/koffi/src/abi_arm64.cc +0 -1295
- package/src/koffi/src/abi_x64_sysv.cc +0 -939
- package/src/koffi/src/abi_x64_win.cc +0 -715
- package/src/koffi/src/abi_x86.cc +0 -860
- package/src/koffi/src/init.js +0 -105
- /package/src/koffi/src/{abi_loong64.cc → abi/loong64.cc} +0 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
11
|
+
var __commonJS = (cb, mod3) => function __require() {
|
|
12
|
+
return mod3 || (0, cb[__getOwnPropNames(cb)[0]])((mod3 = { exports: {} }).exports, mod3), mod3.exports;
|
|
13
|
+
};
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toESM = (mod3, isNodeMode, target) => (target = mod3 != null ? __create(__getProtoOf(mod3)) : {}, __copyProps(
|
|
27
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
28
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
29
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
30
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
31
|
+
isNodeMode || !mod3 || !mod3.__esModule ? __defProp(target, "default", { value: mod3, enumerable: true }) : target,
|
|
32
|
+
mod3
|
|
33
|
+
));
|
|
34
|
+
var __toCommonJS = (mod3) => __copyProps(__defProp({}, "__esModule", { value: true }), mod3);
|
|
35
|
+
|
|
36
|
+
// ../cnoke/src/abi.js
|
|
37
|
+
var abi_exports = {};
|
|
38
|
+
__export(abi_exports, {
|
|
39
|
+
determineAbi: () => determineAbi2
|
|
40
|
+
});
|
|
41
|
+
function determineAbi2() {
|
|
42
|
+
let abi = process.arch;
|
|
43
|
+
if (abi == "riscv32" || abi == "riscv64") {
|
|
44
|
+
let buf = readFileHeader(process.execPath, 512);
|
|
45
|
+
let header = decodeElfHeader(buf);
|
|
46
|
+
let float_abi = header.e_flags & 6;
|
|
47
|
+
switch (float_abi) {
|
|
48
|
+
case 0:
|
|
49
|
+
{
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
case 2:
|
|
53
|
+
{
|
|
54
|
+
abi += "f";
|
|
55
|
+
}
|
|
56
|
+
break;
|
|
57
|
+
case 4:
|
|
58
|
+
{
|
|
59
|
+
abi += "d";
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
62
|
+
case 6:
|
|
63
|
+
{
|
|
64
|
+
abi += "q";
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
} else if (abi == "arm") {
|
|
69
|
+
let buf = readFileHeader(process.execPath, 512);
|
|
70
|
+
let header = decodeElfHeader(buf);
|
|
71
|
+
if (header.e_flags & 1024) {
|
|
72
|
+
abi += "hf";
|
|
73
|
+
} else if (header.e_flags & 512) {
|
|
74
|
+
abi += "sf";
|
|
75
|
+
} else {
|
|
76
|
+
throw new Error("Unknown ARM floating-point ABI");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return abi;
|
|
80
|
+
}
|
|
81
|
+
function readFileHeader(filename2, read) {
|
|
82
|
+
let fd = null;
|
|
83
|
+
try {
|
|
84
|
+
let fd2 = import_fs.default.openSync(filename2);
|
|
85
|
+
let buf = Buffer.allocUnsafe(read);
|
|
86
|
+
let len = import_fs.default.readSync(fd2, buf);
|
|
87
|
+
return buf.subarray(0, len);
|
|
88
|
+
} finally {
|
|
89
|
+
if (fd != null)
|
|
90
|
+
import_fs.default.closeSync(fd);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function decodeElfHeader(buf) {
|
|
94
|
+
let header = {};
|
|
95
|
+
if (buf.length < 16)
|
|
96
|
+
throw new Error("Truncated header");
|
|
97
|
+
if (buf[0] != 127 || buf[1] != 69 || buf[2] != 76 || buf[3] != 70)
|
|
98
|
+
throw new Error("Invalid magic number");
|
|
99
|
+
if (buf[6] != 1)
|
|
100
|
+
throw new Error("Invalid ELF version");
|
|
101
|
+
if (buf[5] != 1)
|
|
102
|
+
throw new Error("Big-endian architectures are not supported");
|
|
103
|
+
header.e_machine = buf.readUInt16LE(18);
|
|
104
|
+
switch (buf[4]) {
|
|
105
|
+
case 1:
|
|
106
|
+
{
|
|
107
|
+
buf = buf.subarray(0, 68);
|
|
108
|
+
if (buf.length < 68)
|
|
109
|
+
throw new Error("Truncated ELF header");
|
|
110
|
+
header.ei_class = 32;
|
|
111
|
+
header.e_flags = buf.readUInt32LE(36);
|
|
112
|
+
}
|
|
113
|
+
break;
|
|
114
|
+
case 2:
|
|
115
|
+
{
|
|
116
|
+
buf = buf.subarray(0, 120);
|
|
117
|
+
if (buf.length < 120)
|
|
118
|
+
throw new Error("Truncated ELF header");
|
|
119
|
+
header.ei_class = 64;
|
|
120
|
+
header.e_flags = buf.readUInt32LE(48);
|
|
121
|
+
}
|
|
122
|
+
break;
|
|
123
|
+
default:
|
|
124
|
+
throw new Error("Invalid ELF class");
|
|
125
|
+
}
|
|
126
|
+
return header;
|
|
127
|
+
}
|
|
128
|
+
var import_fs;
|
|
129
|
+
var init_abi = __esm({
|
|
130
|
+
"../cnoke/src/abi.js"() {
|
|
131
|
+
import_fs = __toESM(require("fs"), 1);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// src/init.js
|
|
136
|
+
var require_init = __commonJS({
|
|
137
|
+
"src/init.js"(exports, module) {
|
|
138
|
+
"use strict";
|
|
139
|
+
var fs = require("fs");
|
|
140
|
+
var path = require("path");
|
|
141
|
+
var util = require("util");
|
|
142
|
+
var { determineAbi } = (init_abi(), __toCommonJS(abi_exports));
|
|
143
|
+
var PACKAGE = require("./package.json");
|
|
144
|
+
function detect() {
|
|
145
|
+
if (process.versions.napi == null || process.versions.napi < PACKAGE.cnoke.napi) {
|
|
146
|
+
let major = parseInt(process.versions.node, 10);
|
|
147
|
+
throw new Error(`This engine is based on Node ${process.versions.node}, but ${PACKAGE.name} does not support the Node ${major}.x branch (N-API < ${PACKAGE.cnoke.napi})`);
|
|
148
|
+
}
|
|
149
|
+
let abi = determineAbi();
|
|
150
|
+
let pkg3 = `${process.platform}-${process.arch}`;
|
|
151
|
+
let triplets3 = [`${process.platform}_${abi}`];
|
|
152
|
+
if (process.platform == "linux")
|
|
153
|
+
triplets3.push(`musl_${abi}`);
|
|
154
|
+
return [pkg3, triplets3];
|
|
155
|
+
}
|
|
156
|
+
function init(root, pkg, triplets, native) {
|
|
157
|
+
let err = null;
|
|
158
|
+
if (native == null) {
|
|
159
|
+
let roots = [root];
|
|
160
|
+
if (process.resourcesPath != null)
|
|
161
|
+
roots.push(process.resourcesPath);
|
|
162
|
+
let filenames = roots.flatMap((dir) => triplets.flatMap((triplet) => [
|
|
163
|
+
`${dir}/build/koffi/${triplet}/koffi.node`,
|
|
164
|
+
`${dir}/bin/Koffi/${triplet}/koffi.node`,
|
|
165
|
+
`${dir}/node_modules/koffi/build/koffi/${triplet}/koffi.node`,
|
|
166
|
+
`${dir}/../@koromix/koffi-${pkg}/${triplet}/koffi.node`
|
|
167
|
+
]));
|
|
168
|
+
for (let filename of filenames) {
|
|
169
|
+
if (!fs.existsSync(filename))
|
|
170
|
+
continue;
|
|
171
|
+
try {
|
|
172
|
+
native = eval("require")(filename);
|
|
173
|
+
break;
|
|
174
|
+
} catch (e) {
|
|
175
|
+
err ??= e;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (native == null) {
|
|
180
|
+
err ??= new Error("Cannot find the native Koffi module; did you bundle it correctly?");
|
|
181
|
+
throw err;
|
|
182
|
+
}
|
|
183
|
+
if (native.version != PACKAGE.version)
|
|
184
|
+
throw new Error("Mismatched native Koffi modules");
|
|
185
|
+
let mod = wrap(native);
|
|
186
|
+
return mod;
|
|
187
|
+
}
|
|
188
|
+
function wrap(native2) {
|
|
189
|
+
let obj = {
|
|
190
|
+
...native2,
|
|
191
|
+
// Deprecated functions
|
|
192
|
+
handle: util.deprecate(native2.opaque, "The koffi.handle() function was deprecated in Koffi 2.1, use koffi.opaque() instead", "KOFFI001"),
|
|
193
|
+
callback: util.deprecate(native2.proto, "The koffi.callback() function was deprecated in Koffi 2.4, use koffi.proto() instead", "KOFFI002")
|
|
194
|
+
};
|
|
195
|
+
obj.load = (...args) => {
|
|
196
|
+
let lib = native2.load(...args);
|
|
197
|
+
lib.cdecl = util.deprecate((...args2) => lib.func("__cdecl", ...args2), "The koffi.cdecl() function was deprecated in Koffi 2.7, use koffi.func(...) instead", "KOFFI003");
|
|
198
|
+
lib.stdcall = util.deprecate((...args2) => lib.func("__stdcall", ...args2), 'The koffi.stdcall() function was deprecated in Koffi 2.7, use koffi.func("__stdcall", ...) instead', "KOFFI004");
|
|
199
|
+
lib.fastcall = util.deprecate((...args2) => lib.func("__fastcall", ...args2), 'The koffi.fastcall() function was deprecated in Koffi 2.7, use koffi.func("__fastcall", ...) instead', "KOFFI005");
|
|
200
|
+
lib.thiscall = util.deprecate((...args2) => lib.func("__thiscall", ...args2), 'The koffi.thiscall() function was deprecated in Koffi 2.7, use koffi.func("__thiscall", ...) instead', "KOFFI006");
|
|
201
|
+
return lib;
|
|
202
|
+
};
|
|
203
|
+
return obj;
|
|
204
|
+
}
|
|
205
|
+
module.exports = {
|
|
206
|
+
detect,
|
|
207
|
+
init
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// indirect.js
|
|
213
|
+
var { detect: detect2, init: init2 } = require_init();
|
|
214
|
+
var [pkg2, triplets2] = detect2();
|
|
215
|
+
var mod2 = init2(__dirname + "/../..", pkg2, triplets2, null);
|
|
216
|
+
module.exports = mod2;
|