@finogeeks2026/finshield-opencode 0.0.0-stage → 0.11.50
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/DESIGN.md +593 -0
- package/LICENSE.rtf +28 -0
- package/README.md +132 -2
- package/THIRD-PARTY-NOTICES.md +3131 -0
- package/bin/node.exe +4 -0
- package/dist/gui-experimental.cjs +96 -0
- package/dist/updater/server.js +1046 -0
- package/install/download-source.json +3 -0
- package/install/runtime.js +60 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/LICENSE.rtf +28 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/README.md +116 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/bin/finsafe_native.dll +0 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/native-build.json +5 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/@koromix/koffi-win32-x64/README.md +6 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/@koromix/koffi-win32-x64/index.js +12 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/@koromix/koffi-win32-x64/package.json +24 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/@koromix/koffi-win32-x64/win32_x64/koffi.lib +0 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/@koromix/koffi-win32-x64/win32_x64/koffi.node +0 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/CHANGELOG.md +1183 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/LICENSE.txt +22 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/README.md +42 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/cnoke.cjs +816 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/benchmarks.md +80 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/callbacks.md +182 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/composites.md +549 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/contribute.md +163 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/index.md +46 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/load.md +191 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/migration.md +256 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/misc.md +76 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/output.md +299 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/pointers.md +385 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/primitives.md +151 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/start.md +110 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/types.md +88 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/unions.md +0 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/values.md +134 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/index.cjs +1 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/index.d.ts +389 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/index.js +2 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/indirect.cjs +1 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/indirect.js +2 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/lib/native/base/base.cc +11064 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/lib/native/base/base.hh +5951 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/lib/native/base/unicode.inc +408 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/package.json +68 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/CMakeLists.txt +249 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/index.cjs +296 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/index.js +281 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/indirect.cjs +295 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/indirect.js +280 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/arm64.cc +1408 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/arm64_asm.S +216 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/arm64_asm.asm +181 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/loong64.cc +5 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/loong64_asm.S +200 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/riscv64.cc +1345 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/riscv64_asm.S +200 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x64sysv.cc +1434 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x64sysv_asm.S +224 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x64win.cc +1086 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x64win_asm.S +162 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x64win_asm.asm +189 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x86.cc +1185 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x86_asm.S +217 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x86_asm.asm +174 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/call.cc +2094 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/call.hh +179 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/errno.inc +462 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/ffi.cc +3009 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/ffi.hh +461 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/parser.cc +218 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/parser.hh +54 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/primitives.inc +36 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/static.cjs +130 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/static.js +133 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/trampolines.cjs +77 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/type.cc +725 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/type.hh +71 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/util.cc +1040 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/util.hh +493 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/uv.cc +214 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/uv.def +11 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/uv.hh +112 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/win32.cc +198 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/win32.hh +148 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-addon-api/LICENSE.md +9 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-addon-api/README.md +95 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-addon-api/napi-inl.deprecated.h +186 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-addon-api/napi-inl.h +7211 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-addon-api/napi.h +3421 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/LICENSE +21 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/README.md +95 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/def/js_native_api.def +125 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/def/node_api.def +157 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/include/js_native_api.h +591 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/include/js_native_api_types.h +210 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/include/node_api.h +265 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/include/node_api_types.h +58 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/package.json +36 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/release.json +4 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/src/native.js +85 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/src/shell.js +20 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/src/status.js +57 -0
- package/package.json +47 -4
- package/policy/candidate.yaml +347 -0
- package/release.json +4 -0
- package/src/activation.js +2 -0
- package/src/attachment.js +34 -0
- package/src/connector.js +91 -0
- package/src/contract.js +8 -0
- package/src/desktop-contract.js +4 -0
- package/src/desktop.js +25 -0
- package/src/gui.tsx +58 -0
- package/src/host.js +38 -0
- package/src/index.js +12 -0
- package/src/instance-settings.js +27 -0
- package/src/known-folders.js +22 -0
- package/src/management.js +17 -0
- package/src/preparation.js +18 -0
- package/src/presentation.js +153 -0
- package/src/settings.js +18 -0
- package/ui/feedback.cjs +45 -0
- package/ui/page.cjs +225 -0
- package/ui/state.cjs +44 -0
- package/updater/bootstrap.js +41 -0
- package/updater/common/activation.js +81 -0
- package/updater/common/coordinator.js +329 -0
- package/updater/common/download.js +57 -0
- package/updater/common/index.js +12 -0
- package/updater/common/package.js +53 -0
- package/updater/common/protocol.js +38 -0
- package/updater/common/transport.js +65 -0
- package/updater/coordinator.js +2 -0
- package/updater/launch.js +40 -0
- package/updater/management.js +9 -0
- package/updater/native.js +18 -0
- package/updater/operations.js +45 -0
- package/updater/protocol.js +1 -0
- package/updater/server.js +100 -0
- package/updater/transport.js +10 -0
- package/updater/windows-launch-reader.js +40 -0
- package/updater/windows-launch.js +96 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Overview
|
|
2
|
+
|
|
3
|
+
Koffi is a **fast and easy-to-use dynamic C FFI module for Node.js**, featuring:
|
|
4
|
+
|
|
5
|
+
* Low-overhead compared to a static Node-API implementation (see [benchmarks](benchmarks))
|
|
6
|
+
* Support for primitive and aggregate data types (structs and fixed-size arrays), both by reference (pointer) and by value
|
|
7
|
+
* Support for synchronous and asynchronous calls
|
|
8
|
+
* Javascript functions can be used as C callbacks
|
|
9
|
+
* Well-tested code base for popular OS/architecture combinations
|
|
10
|
+
|
|
11
|
+
If you like this project, consider supporting me:
|
|
12
|
+
|
|
13
|
+
<p style="display: flex; gap: 1em; justify-content: center; align-items: center;">
|
|
14
|
+
<a href="https://liberapay.com/Koromix/donate" target="_blank"><img alt="Donate using Liberapay" src="https://liberapay.com/assets/widgets/donate.svg"></a>
|
|
15
|
+
<a href="https://github.com/sponsors/koromix" target="_blank"><img src="https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86"></a>
|
|
16
|
+
<a href="https://buymeacoffee.com/koromix" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-yellow.png" alt="Buy Me A Coffee" height="30" width="108" style="border-radius: 12px;"></a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
Koffi requires [Node.js](https://nodejs.org/) version 16 or later. Use [NVM](https://github.com/nvm-sh/nvm) to install more recent Node versions on older Linux distributions.
|
|
20
|
+
|
|
21
|
+
The following combinations of OS and architectures __are officially supported and tested__ at the moment:
|
|
22
|
+
|
|
23
|
+
ISA / OS | Windows | Linux/glibc | Linux/musl | macOS | FreeBSD | OpenBSD
|
|
24
|
+
------------------ | ------- | ----------- | ---------- | ----- | ------- | -------
|
|
25
|
+
x86 (IA32) [^1] | ✅ | ✅ | 🟨 | ⬜️ | ✅ | ✅
|
|
26
|
+
x86_64 (AMD64) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅
|
|
27
|
+
ARM64 (AArch64) LE | ✅ | ✅ | ✅ | ✅ | ✅ | 🟨
|
|
28
|
+
RISC-V 64 [^2] | ⬜️ | ✅ | 🟨 | ⬜️ | 🟨 | 🟨
|
|
29
|
+
LoongArch64 | ⬜️ | ✅ | 🟨 | ⬜️ | 🟨 | 🟨
|
|
30
|
+
|
|
31
|
+
<div class="legend">✅ Yes | 🟨 Probably | ⬜️ Not applicable</div>
|
|
32
|
+
|
|
33
|
+
[^1]: The following call conventions are supported for forward calls: cdecl, stdcall, MS fastcall, thiscall. Only cdecl and stdcall can be used for C to JS callbacks.
|
|
34
|
+
[^2]: The prebuilt binary uses the LP64D (double-precision float) ABI. The LP64 ABI is supported in theory if you build Koffi from source (untested), the LP64F ABI is not supported.
|
|
35
|
+
|
|
36
|
+
For all fully supported platforms (green check marks), a prebuilt binary is included in the NPM package which means you can install Koffi without a C++ compiler.
|
|
37
|
+
|
|
38
|
+
# License
|
|
39
|
+
|
|
40
|
+
This program is free software: you can redistribute it and/or modify it under the terms of the **MIT License**.
|
|
41
|
+
|
|
42
|
+
Find more information here: https://choosealicense.com/licenses/mit/
|
|
43
|
+
|
|
44
|
+
<style>
|
|
45
|
+
table td:not(:first-child) { text-align: center; }
|
|
46
|
+
</style>
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# Loading libraries
|
|
2
|
+
|
|
3
|
+
To declare functions, start by loading the shared library with `koffi.load(filename)`.
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
import koffi from 'koffi';
|
|
7
|
+
// CJS: const koffi = require('koffi');
|
|
8
|
+
|
|
9
|
+
const lib = koffi.load('/path/to/shared/library'); // File extension depends on platforms: .so, .dll, .dylib, etc.
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
This library will be automatically unloaded once all references to it are gone (including all the functions that use it, as described below).
|
|
13
|
+
|
|
14
|
+
## Load options
|
|
15
|
+
|
|
16
|
+
The `load` function can take an optional object argument, with the following options:
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
const options = {
|
|
20
|
+
lazy: true, // Use RTLD_LAZY (lazy-binding) on POSIX platforms (by default, use RTLD_NOW)
|
|
21
|
+
global: true, // Use RTLD_GLOBAL on POSIX platforms (by default, use RTLD_LOCAL)
|
|
22
|
+
deep: true // Use RTLD_DEEPBIND if supported (Linux, FreeBSD)
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const lib = koffi.load('/path/to/shared/library.so', options);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
More options may be added if needed.
|
|
29
|
+
|
|
30
|
+
## Unloading
|
|
31
|
+
|
|
32
|
+
Use `lib.unload()` to can explicitly unload a library. Any attempt to find or call a function from this library after unloading it will crash.
|
|
33
|
+
|
|
34
|
+
> [!NOTE]
|
|
35
|
+
> On some platforms (such as with the [musl C library on Linux](https://wiki.musl-libc.org/functional-differences-from-glibc.html#Unloading-libraries)), shared libraries cannot be unloaded, so the library will remain loaded and memory mapped after the call to `lib.unload()`.
|
|
36
|
+
|
|
37
|
+
# Functions
|
|
38
|
+
|
|
39
|
+
## Definition syntax
|
|
40
|
+
|
|
41
|
+
Use the object returned by `koffi.load()` to load C functions from the library. To do so, you can use two syntaxes:
|
|
42
|
+
|
|
43
|
+
- The classic syntax, inspired by node-ffi
|
|
44
|
+
- C-like prototypes
|
|
45
|
+
|
|
46
|
+
### Classic syntax
|
|
47
|
+
|
|
48
|
+
To declare a function, you need to specify its non-mangled name, its return type, and its parameters. Use an ellipsis as the last parameter for variadic functions.
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
const atoi = lib.func('atoi', 'int', ['str']);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Once a native function has been declared, you can simply call it as you would any other JS function:
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
let value = atoi('1257'); // Returns 1257 as number
|
|
58
|
+
console.log(typeof value); // Print number
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Koffi automatically tries mangled names for non-standard x86 calling conventions. See the section on [calling conventions](#calling-conventions) for more information on this subject.
|
|
62
|
+
|
|
63
|
+
### C-like prototypes
|
|
64
|
+
|
|
65
|
+
If you prefer, you can declare functions using simple C-like prototype strings, as shown below:
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
// The parameter name (nptn below) is not used by Koffi, and optional, but can be nice for documentation
|
|
69
|
+
const atoi = lib.func('int atoi(const char *nptr)');
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Once a native function has been declared, you can simply call it as you would any other JS function:
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
let value = atoi('1257'); // Returns 1257 as number
|
|
76
|
+
console.log(typeof value); // Print number
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
You can use `()` or `(void)` for functions that take no argument.
|
|
80
|
+
|
|
81
|
+
## Variadic functions
|
|
82
|
+
|
|
83
|
+
Variadic functions are declared with an ellipsis as the last argument.
|
|
84
|
+
|
|
85
|
+
In order to call a variadic function, you must provide two Javascript arguments for each additional C parameter, the first one is the expected type and the second one is the value.
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
// These two declarations are identical
|
|
89
|
+
const printf1 = lib.func('printf', 'int', ['str', '...']);
|
|
90
|
+
const printf2 = lib.func('int printf(str fmt, ...)');
|
|
91
|
+
|
|
92
|
+
// The variadic arguments are: 6 (int), 8.5 (double), 'THE END' (const char *)
|
|
93
|
+
printf1('Integer %d, double %g, str %s', 'int', 6, 'double', 8.5, 'str', 'THE END');
|
|
94
|
+
printf2('Integer %d, double %g, str %s', 'int', 6, 'double', 8.5, 'str', 'THE END');
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
On x86 platforms, only the Cdecl convention can be used for variadic functions.
|
|
98
|
+
|
|
99
|
+
## Calling conventions
|
|
100
|
+
|
|
101
|
+
Most architectures only support one procedure call standard per process. The 32-bit x86 platform is an exception to this, and Koffi supports several x86 conventions:
|
|
102
|
+
|
|
103
|
+
Convention | Classic form | Prototype form | Description
|
|
104
|
+
------------- | --------------------------------------------- | -------------- | -------------------------------------------------------------------
|
|
105
|
+
**Cdecl** | `koffi.func(name, ret, params)` | _(default)_ | This is the default convention, and the only one on other platforms
|
|
106
|
+
**Stdcall** | `koffi.func('__stdcall', name, ret, params)` | __stdcall | This convention is used extensively within the Win32 API
|
|
107
|
+
**Fastcall** | `koffi.func('__fastcall', name, ret, params)` | __fastcall | Rarely used, uses ECX and EDX for first two parameters
|
|
108
|
+
**Thiscall** | `koffi.func('__thiscall', name, ret, params)` | __thiscall | Rarely used, uses ECX for first parameter
|
|
109
|
+
|
|
110
|
+
You can safely use these on non-x86 platforms, they are simply ignored.
|
|
111
|
+
|
|
112
|
+
Below you can find a small example showing how to use a non-default calling convention, with the two syntaxes:
|
|
113
|
+
|
|
114
|
+
```js
|
|
115
|
+
import koffi from 'koffi';
|
|
116
|
+
// CJS: const koffi = require('koffi');
|
|
117
|
+
|
|
118
|
+
const lib = koffi.load('user32.dll');
|
|
119
|
+
|
|
120
|
+
// The following two declarations are equivalent, and use stdcall on x86 (and the default ABI on other platforms)
|
|
121
|
+
const MessageBoxA1 = lib.func('__stdcall', 'MessageBoxA', 'int', ['void *', 'str', 'str', 'uint']);
|
|
122
|
+
const MessageBoxA2 = lib.func('int __stdcall MessageBoxA(void *hwnd, str text, str caption, uint type)');
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Asynchronous calls
|
|
126
|
+
|
|
127
|
+
You can issue asynchronous calls by calling the function through its async member. In this case, you need to provide a callback function as the last argument, with `(err, res)` parameters.
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
import koffi from 'koffi';
|
|
131
|
+
// CJS: const koffi = require('koffi');
|
|
132
|
+
|
|
133
|
+
const lib = koffi.load('libc.so.6');
|
|
134
|
+
|
|
135
|
+
const atoi = lib.func('int atoi(const char *str)');
|
|
136
|
+
|
|
137
|
+
atoi.async('1257', (err, res) => {
|
|
138
|
+
console.log('Result:', res);
|
|
139
|
+
})
|
|
140
|
+
console.log('Hello World!');
|
|
141
|
+
|
|
142
|
+
// This program will print:
|
|
143
|
+
// Hello World!
|
|
144
|
+
// Result: 1257
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
These calls are executed by worker threads. It is **your responsibility to deal with data sharing issues** in the native code that may be caused by multi-threading.
|
|
148
|
+
|
|
149
|
+
You can easily convert this callback-style async function to a promise-based version with `util.promisify()` from the Node.js standard library.
|
|
150
|
+
|
|
151
|
+
Variadic functions cannot be called asynchronously.
|
|
152
|
+
|
|
153
|
+
> [!WARNING]
|
|
154
|
+
> Asynchronous functions run on worker threads. You need to deal with thread safety issues if you share data between threads.
|
|
155
|
+
|
|
156
|
+
## Conversion of parameters
|
|
157
|
+
|
|
158
|
+
By default, Koffi will only forward and translate arguments from Javascript to C. However, many C functions use pointer arguments for output values, or input/output values.
|
|
159
|
+
|
|
160
|
+
Among other thing, in the the following pages you will learn more about:
|
|
161
|
+
|
|
162
|
+
- The [primitives types](primitives) supported by Koffi
|
|
163
|
+
- How to define [composite types](composites): structs, arrays and unions
|
|
164
|
+
- How you can [define and use pointers](pointers)
|
|
165
|
+
- How to deal with [output parameters](output)
|
|
166
|
+
|
|
167
|
+
# Variables
|
|
168
|
+
|
|
169
|
+
*Changed in Koffi 3.1.0*
|
|
170
|
+
|
|
171
|
+
To find an exported variable symbol, use `lib.symbol(name)`. You need to specify its name and its type.
|
|
172
|
+
|
|
173
|
+
```c
|
|
174
|
+
int my_int = 42;
|
|
175
|
+
const char *my_string = NULL;
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
```js
|
|
179
|
+
const my_int = lib.symbol('my_int');
|
|
180
|
+
const my_string = lib.symbol('my_string');
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
This function returns a pointer (a BigInt value in Koffi 3). To read or change the value of the variable, you can use:
|
|
184
|
+
|
|
185
|
+
- [koffi.decode()](values#decode-to-js-values) to read the value
|
|
186
|
+
- [koffi.encode()](values#encode-to-c-memory) to change the value
|
|
187
|
+
|
|
188
|
+
> [!NOTE]
|
|
189
|
+
> Until Koffi 3.1.0, the `symbol()` function required you to give a type, even though it did nothing with this information. This was a leftover from Koffi 2.
|
|
190
|
+
>
|
|
191
|
+
> For compatibility, you can still call `lib.symbol(name, type)`, but this is deprecated.
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
# Koffi 2.x to 3.x
|
|
2
|
+
|
|
3
|
+
Most programs should work as-is with Koffi 3.x.
|
|
4
|
+
|
|
5
|
+
However, some changes could impact your code:
|
|
6
|
+
|
|
7
|
+
- Koffi is now distributed in [split packages](#split-packages) to reduce install size/bloat.
|
|
8
|
+
- Pointers are now [BigInt values](#bigint-pointers) instead of opaque V8 external values.
|
|
9
|
+
- Types created by koffi are now [type objects](#type-objects) instead of opaque V8 external values.
|
|
10
|
+
- Using `koffi.register()` with a [receiver value](#registered-callback-binding) is deprecated.
|
|
11
|
+
- Several old [deprecated functions](#removed-functions) have been removed.
|
|
12
|
+
|
|
13
|
+
## Split packages
|
|
14
|
+
|
|
15
|
+
The main koffi package does not contain native code any longer. Instead, it depends on platform-specific packages (such as `@koromix/koffi-linux-x64`) for platform support, specified through `optionalDependencies`.
|
|
16
|
+
|
|
17
|
+
Your package manager should automatically install the binary package relevant to your platform. Importing koffi should work transparently, just as before.
|
|
18
|
+
|
|
19
|
+
However, if you redistribute software that uses Koffi, you will probably **need to change your packaging system** or configure your bundler differently.
|
|
20
|
+
|
|
21
|
+
## BigInt pointers
|
|
22
|
+
|
|
23
|
+
For performance reasons, Koffi now uses BigInt numbers for pointers instead of V8 external objects.
|
|
24
|
+
|
|
25
|
+
Most code should work without any change, but there are two cases where this might impact you:
|
|
26
|
+
|
|
27
|
+
- If you use a **type system**, for example in TypeScript code (e.g. for parameters), you may need to accept BigInt values now if you pass pointer values around.
|
|
28
|
+
- BigInt pointers **do not carry the C type around**. In Koffi 2.x, trying to pass a pointer to an integer to a `void Myfunc(MyStruct *)` function would have triggerd an exception, but in Koffi 3.x this will "work" (and probably crash).
|
|
29
|
+
|
|
30
|
+
## Type objects
|
|
31
|
+
|
|
32
|
+
Type functions, such as `koffi.struct()`, now create *TypeObject* objects, and type information is directly available without `koffi.introspect()`.
|
|
33
|
+
|
|
34
|
+
You can resolve type strings to type objects with `koffi.type()`. This function replaces `koffi.resolve()`, which is now a deprecated alias for `koffi.type()`.
|
|
35
|
+
|
|
36
|
+
> [!NOTE]
|
|
37
|
+
> For compatibility reasons, both `koffi.resolve()` and `koffi.introspect()` still exist, as aliases for `koffi.type()`. Using them will emit a deprecation warning.
|
|
38
|
+
|
|
39
|
+
Read the documentation about [type specifiers](types#type-specifiers) for more information.
|
|
40
|
+
|
|
41
|
+
The two versions below illustrate the API difference between Koffi 2.x and Koffi 3.x:
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
// Koffi 2.x
|
|
45
|
+
|
|
46
|
+
const MyStruct = koffi.struct('MyStruct', {
|
|
47
|
+
a: 'int',
|
|
48
|
+
b: 'int'
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
console.log(koffi.introspect(MyStruct).members); // Prints MyStruct members
|
|
52
|
+
console.log(koffi.introspect('MyStruct').members); // Prints MyStruct members
|
|
53
|
+
|
|
54
|
+
console.log(koffi.introspect(koffi.types.int).alignment); // Prints MyStruct members
|
|
55
|
+
console.log(koffi.introspect('int').alignment); // Prints alignment of int type
|
|
56
|
+
|
|
57
|
+
// Koffi 3.x
|
|
58
|
+
|
|
59
|
+
const MyStruct = koffi.struct('MyStruct', {
|
|
60
|
+
a: 'int',
|
|
61
|
+
b: 'int'
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
console.log(MyStruct.members); // Prints MyStruct members
|
|
65
|
+
console.log(koffi.type('MyStruct').members); // Prints MyStruct members
|
|
66
|
+
|
|
67
|
+
console.log(koffi.types.int.alignment); // Prints alignment of int type
|
|
68
|
+
console.log(koffi.type('int').alignment); // Prints alignment of int type
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Registered callback binding
|
|
72
|
+
|
|
73
|
+
In Koffi 2.x, it was possible to bind a specific `this` value to the callback function when using `koffi.register()`, by passing an object as the first argument. This feature has been deprecated, it still works but will emit a warning.
|
|
74
|
+
|
|
75
|
+
You should replace these calls with an explicit call to the `bind()` method:
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
class ValueStore {
|
|
79
|
+
constructor(value) { this.value = value; }
|
|
80
|
+
get() { return this.value; }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let store = new ValueStore(42);
|
|
84
|
+
|
|
85
|
+
// Koffi 2.x
|
|
86
|
+
|
|
87
|
+
let cb = koffi.register(store, store.get, 'IntCallback *');
|
|
88
|
+
|
|
89
|
+
// Koffi 3.x
|
|
90
|
+
|
|
91
|
+
let cb = koffi.register(store.get.bind(store), 'IntCallback *');
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Removed functions
|
|
95
|
+
|
|
96
|
+
Two deprecated functions have been removed:
|
|
97
|
+
|
|
98
|
+
- `koffi.callback()`: if you still use it, replace with `koffi.proto()`.
|
|
99
|
+
- `koffi.handle()`: if you still use it, replace with `koffi.opaque()`.
|
|
100
|
+
|
|
101
|
+
# Koffi 1.x to 2.x
|
|
102
|
+
|
|
103
|
+
The API was changed in 2.x in a few ways, in order to reduce some excessively "magic" behavior and reduce the syntax differences between C and the C-like prototypes.
|
|
104
|
+
|
|
105
|
+
You may need to change your code if you use:
|
|
106
|
+
|
|
107
|
+
- Callback functions
|
|
108
|
+
- Opaque types
|
|
109
|
+
- `koffi.introspect()`
|
|
110
|
+
|
|
111
|
+
## Callback types
|
|
112
|
+
|
|
113
|
+
In Koffi 1.x, callbacks were defined in a way that made them usable directly as parameter and return types, obscuring the underlying pointer. Now, you must use them through a pointer: `void CallIt(CallbackType func)` in Koffi 1.x becomes `void CallIt(CallbackType *func)` in version 2.0 and newer.
|
|
114
|
+
|
|
115
|
+
Given the following C code:
|
|
116
|
+
|
|
117
|
+
```c
|
|
118
|
+
#include <string.h>
|
|
119
|
+
|
|
120
|
+
int TransferToJS(const char *name, int age, int (*cb)(const char *str, int age))
|
|
121
|
+
{
|
|
122
|
+
char buf[64];
|
|
123
|
+
snprintf(buf, sizeof(buf), "Hello %s!", str);
|
|
124
|
+
return cb(buf, age);
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The two versions below illustrate the API difference between Koffi 1.x and Koffi 2.x:
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
// Koffi 1.x
|
|
132
|
+
|
|
133
|
+
const TransferCallback = koffi.proto('int TransferCallback(const char *str, int age)');
|
|
134
|
+
|
|
135
|
+
const TransferToJS = lib.func('TransferToJS', 'int', ['str', 'int', TransferCallback]);
|
|
136
|
+
// Equivalent to: const TransferToJS = lib.func('int TransferToJS(str s, int x, TransferCallback cb)');
|
|
137
|
+
|
|
138
|
+
let ret = TransferToJS('Niels', 27, (str, age) => {
|
|
139
|
+
console.log(str);
|
|
140
|
+
console.log('Your age is:', age);
|
|
141
|
+
return 42;
|
|
142
|
+
});
|
|
143
|
+
console.log(ret);
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
```js
|
|
147
|
+
// Koffi 2.x
|
|
148
|
+
|
|
149
|
+
const TransferCallback = koffi.proto('int TransferCallback(const char *str, int age)');
|
|
150
|
+
|
|
151
|
+
const TransferToJS = lib.func('TransferToJS', 'int', ['str', 'int', koffi.pointer(TransferCallback)]);
|
|
152
|
+
// Equivalent to: const TransferToJS = lib.func('int TransferToJS(str s, int x, TransferCallback *cb)');
|
|
153
|
+
|
|
154
|
+
let ret = TransferToJS('Niels', 27, (str, age) => {
|
|
155
|
+
console.log(str);
|
|
156
|
+
console.log('Your age is:', age);
|
|
157
|
+
return 42;
|
|
158
|
+
});
|
|
159
|
+
console.log(ret);
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Koffi 1.x only supported [transient callbacks](callbacks#javascript-callbacks), you must use Koffi 2.x for registered callbacks.
|
|
163
|
+
|
|
164
|
+
## Opaque types
|
|
165
|
+
|
|
166
|
+
In Koffi 1.x, opaque handles were defined in a way that made them usable directly as parameter and return types, obscuring the underlying pointer. Now, in Koffi 2.0, you must use them through a pointer, and use an array for output parameters.
|
|
167
|
+
|
|
168
|
+
In addition to that, `koffi.handle()` has been deprecated in Koffi 2.1 and replaced with `koffi.opaque()`. They work the same but new code should use `koffi.opaque()`, the former one will eventually be removed in Koffi 3.0.
|
|
169
|
+
|
|
170
|
+
For functions that return opaque pointers or pass them by parameter:
|
|
171
|
+
|
|
172
|
+
```js
|
|
173
|
+
// Koffi 1.x
|
|
174
|
+
|
|
175
|
+
const FILE = koffi.handle('FILE');
|
|
176
|
+
const fopen = lib.func('fopen', 'FILE', ['str', 'str']);
|
|
177
|
+
const fopen = lib.func('fclose', 'int', ['FILE']);
|
|
178
|
+
|
|
179
|
+
let fp = fopen('EMPTY', 'wb');
|
|
180
|
+
if (!fp)
|
|
181
|
+
throw new Error('Failed to open file');
|
|
182
|
+
fclose(fp);
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
```js
|
|
186
|
+
// Koffi 2.1
|
|
187
|
+
|
|
188
|
+
// If you use Koffi 2.0: const FILE = koffi.handle('FILE');
|
|
189
|
+
const FILE = koffi.opaque('FILE');
|
|
190
|
+
const fopen = lib.func('fopen', 'FILE *', ['str', 'str']);
|
|
191
|
+
const fopen = lib.func('fclose', 'int', ['FILE *']);
|
|
192
|
+
|
|
193
|
+
let fp = fopen('EMPTY', 'wb');
|
|
194
|
+
if (!fp)
|
|
195
|
+
throw new Error('Failed to open file');
|
|
196
|
+
fclose(fp);
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
For functions that set opaque handles through output parameters (such as `sqlite3_open_v2`), you must now use a single element array as shown below:
|
|
200
|
+
|
|
201
|
+
```js
|
|
202
|
+
// Koffi 1.x
|
|
203
|
+
|
|
204
|
+
const sqlite3 = koffi.handle('sqlite3');
|
|
205
|
+
|
|
206
|
+
const sqlite3_open_v2 = lib.func('int sqlite3_open_v2(const char *, _Out_ sqlite3 *db, int, const char *)');
|
|
207
|
+
const sqlite3_close_v2 = lib.func('int sqlite3_close_v2(sqlite3 db)');
|
|
208
|
+
|
|
209
|
+
const SQLITE_OPEN_READWRITE = 0x2;
|
|
210
|
+
const SQLITE_OPEN_CREATE = 0x4;
|
|
211
|
+
|
|
212
|
+
let db = {};
|
|
213
|
+
|
|
214
|
+
if (sqlite3_open_v2(':memory:', db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, null) != 0)
|
|
215
|
+
throw new Error('Failed to open database');
|
|
216
|
+
|
|
217
|
+
sqlite3_close_v2(db);
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
```js
|
|
221
|
+
// Koffi 2.1
|
|
222
|
+
|
|
223
|
+
// If you use Koffi 2.0: const sqlite3 = koffi.handle('sqlite3');
|
|
224
|
+
const sqlite3 = koffi.opaque('sqlite3');
|
|
225
|
+
|
|
226
|
+
const sqlite3_open_v2 = lib.func('int sqlite3_open_v2(const char *, _Out_ sqlite3 **db, int, const char *)');
|
|
227
|
+
const sqlite3_close_v2 = lib.func('int sqlite3_close_v2(sqlite3 *db)');
|
|
228
|
+
|
|
229
|
+
const SQLITE_OPEN_READWRITE = 0x2;
|
|
230
|
+
const SQLITE_OPEN_CREATE = 0x4;
|
|
231
|
+
|
|
232
|
+
let db = null;
|
|
233
|
+
|
|
234
|
+
let ptr = [null];
|
|
235
|
+
if (sqlite3_open_v2(':memory:', ptr, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, null) != 0)
|
|
236
|
+
throw new Error('Failed to open database');
|
|
237
|
+
db = ptr[0];
|
|
238
|
+
|
|
239
|
+
sqlite3_close_v2(db);
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## New koffi.introspect()
|
|
243
|
+
|
|
244
|
+
In Koffi 1.x, `koffi.introspect()` would only work with struct types, and return the object passed to `koffi.struct()` to initialize the type. Now this function works with all types.
|
|
245
|
+
|
|
246
|
+
You can still get the list of struct members:
|
|
247
|
+
|
|
248
|
+
```js
|
|
249
|
+
const StructType = koffi.struct('StructType', { dummy: 'int' });
|
|
250
|
+
|
|
251
|
+
// Koffi 1.x
|
|
252
|
+
let members = koffi.introspect(StructType);
|
|
253
|
+
|
|
254
|
+
// Koffi 2.x
|
|
255
|
+
let members = koffi.introspect(StructType).members;
|
|
256
|
+
```
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Settings
|
|
2
|
+
|
|
3
|
+
## Memory usage
|
|
4
|
+
|
|
5
|
+
For synchronous/normal calls, Koffi uses two preallocated memory blocks:
|
|
6
|
+
|
|
7
|
+
- One to construct the C stack and assign registers, subsequently used by the platform-specific assembly code (1 MiB by default)
|
|
8
|
+
- One to allocate strings and objects/structs (2 MiB by default)
|
|
9
|
+
|
|
10
|
+
Unless very big strings or objects (at least more than one page of memory) are used, Koffi does not directly allocate any extra memory during calls or callbacks. However, please note that the JS engine (V8) might.
|
|
11
|
+
|
|
12
|
+
The size (in bytes) of these preallocated blocks can be changed. Use `koffi.config()` to get an object with the settings, and `koffi.config(obj)` to apply new settings.
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
let config = koffi.config();
|
|
16
|
+
console.log(config);
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The same is true for asynchronous calls. When an asynchronous call is made, Koffi will allocate new blocks unless there is an unused (resident) set of blocks still available. Once the asynchronous call is finished, these blocks are freed if there are more than `resident_async_pools` sets of blocks left around. By default, the preallocated stack and heap blocks are much smaller than for synchronous calls (see [default settings](#default-settings)).
|
|
20
|
+
|
|
21
|
+
> [!CAUTION]
|
|
22
|
+
> The **memory usage can blow up easily** if you increase the size of async memory blocks and many async calls are running or queued at the same time !
|
|
23
|
+
>
|
|
24
|
+
> For example, with 4096 running/queued async calls, a stack size of 256 kiB and a heap size of 512 kiB, the memory usage will reach approximately _4096 * (256 + 512) kiB ≈ 3 GiB_ just for Koffi, even though most of it will be freed once the number of queued calls goes down.
|
|
25
|
+
|
|
26
|
+
Async calls run on worker threads, the number of which depends on the number of cores in your machine. Additional async calls are queued, up to `max_async_calls` can run and be queued at the same time. If you try to make an async call once the queue if full, an exception will be thrown.
|
|
27
|
+
|
|
28
|
+
## Default settings
|
|
29
|
+
|
|
30
|
+
Setting | Default | Maximum | Description
|
|
31
|
+
-------------------- | ------- | ------- | ----------------------------------------------------
|
|
32
|
+
sync_stack_size | 1 MiB | 16 MiB | Stack size for synchronous calls
|
|
33
|
+
sync_heap_size | 2 MiB | 16 MiB | Heap size for synchronous calls
|
|
34
|
+
async_stack_size | 128 kiB | 16 MiB | Stack size for asynchronous calls
|
|
35
|
+
async_heap_size | 128 kiB | 16 MiB | Heap size for asynchronous calls
|
|
36
|
+
resident_async_pools | 4 | 16 | Number of resident pools for asynchronous calls
|
|
37
|
+
max_async_calls | 256 | 4096 | Maximum number of queued asynchronous calls
|
|
38
|
+
max_type_size | 64 MiB | 512 MiB | Maximum size of Koffi types (for arrays and structs)
|
|
39
|
+
|
|
40
|
+
# Usage statistics
|
|
41
|
+
|
|
42
|
+
You can use `koffi.stats()` to get a few statistics related to Koffi.
|
|
43
|
+
|
|
44
|
+
# POSIX error codes
|
|
45
|
+
|
|
46
|
+
You can use `koffi.errno()` to get the current errno value, and `koffi.errno(value)` to change it.
|
|
47
|
+
|
|
48
|
+
The standard POSIX error codes are available in `koffi.os.errno`, as shown below:
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
const assert = require('assert');
|
|
52
|
+
|
|
53
|
+
import koffi from 'koffi';
|
|
54
|
+
// CJS: const koffi = require('koffi');
|
|
55
|
+
|
|
56
|
+
const lib = koffi.load('libc.so.6');
|
|
57
|
+
|
|
58
|
+
const close = lib.func('int close(int fd)');
|
|
59
|
+
|
|
60
|
+
close(-1);
|
|
61
|
+
assert.equal(koffi.errno(), koffi.os.errno.EBADF);
|
|
62
|
+
|
|
63
|
+
console.log('close() with invalid FD is POSIX compliant!');
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
# Reset internal state
|
|
67
|
+
|
|
68
|
+
You can use `koffi.reset()` to clear some Koffi internal state such as:
|
|
69
|
+
|
|
70
|
+
- Parser type names
|
|
71
|
+
- Asynchronous function broker (useful to avoid false positive with `jest --detectOpenHandles`)
|
|
72
|
+
|
|
73
|
+
This function is mainly intended for test code, when you execute the same code over and over and you need to reuse type names.
|
|
74
|
+
|
|
75
|
+
> [!WARNING]
|
|
76
|
+
> Trying to use a function or a type that was initially defined before the reset is undefined behavior and will likely lead to a crash!
|