@psnext/slingcli 2.4.20260526-1 → 2.4.20260527-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/bin/sling.js +4 -1
- package/node_modules/@aws-sdk/core/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-env/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-http/dist-cjs/fromHttp/fromHttp.js +12 -6
- package/node_modules/@aws-sdk/credential-provider-http/dist-es/fromHttp/fromHttp.js +12 -6
- package/node_modules/@aws-sdk/credential-provider-http/package.json +3 -2
- package/node_modules/@aws-sdk/credential-provider-ini/package.json +9 -9
- package/node_modules/@aws-sdk/credential-provider-login/package.json +3 -3
- package/node_modules/@aws-sdk/credential-provider-node/package.json +7 -7
- package/node_modules/@aws-sdk/credential-provider-process/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/package.json +3 -3
- package/node_modules/@aws-sdk/credential-provider-sso/package.json +4 -4
- package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -3
- package/node_modules/@aws-sdk/middleware-websocket/package.json +2 -2
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/cognito-identity/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/package.json +3 -3
- package/node_modules/@aws-sdk/signature-v4-multi-region/package.json +1 -2
- package/node_modules/@aws-sdk/xml-builder/package.json +2 -2
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/compaction.js +18 -24
- package/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
- package/node_modules/@earendil-works/pi-ai/dist/cli.js +14 -0
- package/node_modules/@earendil-works/pi-ai/dist/models.generated.js +73 -58
- package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.js +2 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.js +8 -22
- package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/images/openrouter.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex-responses.js +60 -40
- package/node_modules/@earendil-works/pi-ai/dist/providers/openai-completions.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/openai-responses.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/device-code.js +55 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.js +45 -69
- package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/index.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +5 -2
- package/node_modules/@earendil-works/pi-ai/package.json +4 -3
- package/node_modules/@earendil-works/pi-coding-agent/dist/cli/file-processor.js +2 -3
- package/node_modules/@earendil-works/pi-coding-agent/dist/config.js +18 -12
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session-runtime.js +2 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session-services.js +3 -2
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session.js +8 -2
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/auth-storage.js +2 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/compaction/compaction.js +18 -24
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/export-html/index.js +8 -6
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/export-html/template.js +6 -3
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/loader.js +12 -29
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/model-registry.js +5 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/output-guard.js +52 -22
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/package-manager.js +63 -36
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/prompt-templates.js +6 -20
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/resource-loader.js +38 -31
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/sdk.js +9 -4
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/session-manager.js +32 -24
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/settings-manager.js +6 -13
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/skills.js +8 -22
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/bash.js +54 -53
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/edit-diff.js +8 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/edit.js +44 -81
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/file-mutation-queue.js +27 -12
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/find.js +2 -3
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/grep.js +3 -3
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/ls.js +5 -5
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/output-accumulator.js +9 -3
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/path-utils.js +39 -21
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/read.js +9 -8
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/truncate.js +12 -2
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/write.js +20 -35
- package/node_modules/@earendil-works/pi-coding-agent/dist/main.js +5 -6
- package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/config-selector.js +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/footer.js +14 -5
- package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/login-dialog.js +29 -4
- package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/user-message.js +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/interactive-mode.js +4 -4
- package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.js +37 -28
- package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-client.js +64 -7
- package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-mode.js +15 -3
- package/node_modules/@earendil-works/pi-coding-agent/dist/utils/clipboard-native.js +14 -8
- package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize-core.js +124 -0
- package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize-worker.js +31 -0
- package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize.js +75 -115
- package/node_modules/@earendil-works/pi-coding-agent/dist/utils/paths.js +33 -7
- package/node_modules/@earendil-works/pi-coding-agent/npm-shrinkwrap.json +13 -26
- package/node_modules/@earendil-works/pi-coding-agent/package.json +6 -6
- package/node_modules/@earendil-works/pi-tui/dist/components/editor.js +40 -55
- package/node_modules/@earendil-works/pi-tui/dist/components/input.js +2 -2
- package/node_modules/@earendil-works/pi-tui/dist/components/markdown.js +12 -2
- package/node_modules/@earendil-works/pi-tui/dist/native-modifiers.js +53 -0
- package/node_modules/@earendil-works/pi-tui/dist/terminal-image.js +4 -1
- package/node_modules/@earendil-works/pi-tui/dist/terminal.js +38 -16
- package/node_modules/@earendil-works/pi-tui/dist/utils.js +19 -12
- package/node_modules/@earendil-works/pi-tui/native/darwin/prebuilds/darwin-arm64/darwin-modifiers.node +0 -0
- package/node_modules/@earendil-works/pi-tui/native/darwin/prebuilds/darwin-x64/darwin-modifiers.node +0 -0
- package/node_modules/@earendil-works/pi-tui/native/win32/prebuilds/win32-arm64/win32-console-mode.node +0 -0
- package/node_modules/@earendil-works/pi-tui/native/win32/prebuilds/win32-x64/win32-console-mode.node +0 -0
- package/node_modules/@earendil-works/pi-tui/package.json +3 -5
- package/node_modules/@smithy/node-http-handler/package.json +2 -2
- package/package.json +6 -6
- package/slingshot/index.js +246 -244
- package/node_modules/koffi/CHANGELOG.md +0 -1093
- package/node_modules/koffi/LICENSE.txt +0 -22
- package/node_modules/koffi/README.md +0 -43
- package/node_modules/koffi/build/koffi/darwin_arm64/koffi.node +0 -0
- package/node_modules/koffi/build/koffi/darwin_x64/koffi.node +0 -0
- package/node_modules/koffi/build/koffi/freebsd_arm64/koffi.node +0 -0
- package/node_modules/koffi/build/koffi/freebsd_ia32/koffi.node +0 -0
- package/node_modules/koffi/build/koffi/freebsd_x64/koffi.node +0 -0
- package/node_modules/koffi/build/koffi/linux_arm64/koffi.node +0 -0
- package/node_modules/koffi/build/koffi/linux_armhf/koffi.node +0 -0
- package/node_modules/koffi/build/koffi/linux_ia32/koffi.node +0 -0
- package/node_modules/koffi/build/koffi/linux_loong64/koffi.node +0 -0
- package/node_modules/koffi/build/koffi/linux_riscv64d/koffi.node +0 -0
- package/node_modules/koffi/build/koffi/linux_x64/koffi.node +0 -0
- package/node_modules/koffi/build/koffi/musl_arm64/koffi.node +0 -0
- package/node_modules/koffi/build/koffi/musl_x64/koffi.node +0 -0
- package/node_modules/koffi/build/koffi/openbsd_ia32/koffi.node +0 -0
- package/node_modules/koffi/build/koffi/openbsd_x64/koffi.node +0 -0
- package/node_modules/koffi/build/koffi/win32_arm64/koffi.exp +0 -0
- package/node_modules/koffi/build/koffi/win32_arm64/koffi.lib +0 -0
- package/node_modules/koffi/build/koffi/win32_arm64/koffi.node +0 -0
- package/node_modules/koffi/build/koffi/win32_ia32/koffi.exp +0 -0
- package/node_modules/koffi/build/koffi/win32_ia32/koffi.lib +0 -0
- package/node_modules/koffi/build/koffi/win32_ia32/koffi.node +0 -0
- package/node_modules/koffi/build/koffi/win32_x64/koffi.exp +0 -0
- package/node_modules/koffi/build/koffi/win32_x64/koffi.lib +0 -0
- package/node_modules/koffi/build/koffi/win32_x64/koffi.node +0 -0
- package/node_modules/koffi/doc/benchmarks.md +0 -126
- package/node_modules/koffi/doc/callbacks.md +0 -210
- package/node_modules/koffi/doc/contribute.md +0 -148
- package/node_modules/koffi/doc/functions.md +0 -250
- package/node_modules/koffi/doc/index.md +0 -61
- package/node_modules/koffi/doc/input.md +0 -471
- package/node_modules/koffi/doc/migration.md +0 -159
- package/node_modules/koffi/doc/misc.md +0 -180
- package/node_modules/koffi/doc/output.md +0 -305
- package/node_modules/koffi/doc/packaging.md +0 -88
- package/node_modules/koffi/doc/platforms.md +0 -36
- package/node_modules/koffi/doc/pointers.md +0 -328
- package/node_modules/koffi/doc/start.md +0 -118
- package/node_modules/koffi/doc/unions.md +0 -186
- package/node_modules/koffi/doc/variables.md +0 -102
- package/node_modules/koffi/index.d.ts +0 -288
- package/node_modules/koffi/index.js +0 -634
- package/node_modules/koffi/indirect.js +0 -533
- package/node_modules/koffi/lib/native/base/base.cc +0 -11015
- package/node_modules/koffi/lib/native/base/base.hh +0 -6003
- package/node_modules/koffi/lib/native/base/crc.inc +0 -2214
- package/node_modules/koffi/lib/native/base/crc_gen.py +0 -72
- package/node_modules/koffi/lib/native/base/mimetypes.inc +0 -1248
- package/node_modules/koffi/lib/native/base/mimetypes_gen.py +0 -58
- package/node_modules/koffi/lib/native/base/tower.cc +0 -821
- package/node_modules/koffi/lib/native/base/tower.hh +0 -81
- package/node_modules/koffi/lib/native/base/unicode.inc +0 -408
- package/node_modules/koffi/lib/native/base/unicode_gen.py +0 -152
- package/node_modules/koffi/package.json +0 -38
- package/node_modules/koffi/src/cnoke/LICENSE.txt +0 -22
- package/node_modules/koffi/src/cnoke/README.md +0 -99
- package/node_modules/koffi/src/cnoke/assets/FindCNoke.cmake +0 -127
- package/node_modules/koffi/src/cnoke/assets/toolchains.json +0 -126
- package/node_modules/koffi/src/cnoke/assets/win_delay_hook.c +0 -36
- package/node_modules/koffi/src/cnoke/cnoke.js +0 -170
- package/node_modules/koffi/src/cnoke/package.json +0 -24
- package/node_modules/koffi/src/cnoke/src/builder.js +0 -511
- package/node_modules/koffi/src/cnoke/src/index.js +0 -10
- package/node_modules/koffi/src/cnoke/src/tools.js +0 -407
- package/node_modules/koffi/src/koffi/CMakeLists.txt +0 -182
- package/node_modules/koffi/src/koffi/src/abi_arm32.cc +0 -1018
- package/node_modules/koffi/src/koffi/src/abi_arm32_asm.S +0 -169
- package/node_modules/koffi/src/koffi/src/abi_arm64.cc +0 -1295
- package/node_modules/koffi/src/koffi/src/abi_arm64_asm.S +0 -195
- package/node_modules/koffi/src/koffi/src/abi_arm64_asm.asm +0 -174
- package/node_modules/koffi/src/koffi/src/abi_loong64.cc +0 -5
- package/node_modules/koffi/src/koffi/src/abi_loong64_asm.S +0 -204
- package/node_modules/koffi/src/koffi/src/abi_riscv64.cc +0 -915
- package/node_modules/koffi/src/koffi/src/abi_riscv64_asm.S +0 -203
- package/node_modules/koffi/src/koffi/src/abi_x64_sysv.cc +0 -939
- package/node_modules/koffi/src/koffi/src/abi_x64_sysv_asm.S +0 -231
- package/node_modules/koffi/src/koffi/src/abi_x64_win.cc +0 -715
- package/node_modules/koffi/src/koffi/src/abi_x64_win_asm.S +0 -166
- package/node_modules/koffi/src/koffi/src/abi_x64_win_asm.asm +0 -192
- package/node_modules/koffi/src/koffi/src/abi_x86.cc +0 -860
- package/node_modules/koffi/src/koffi/src/abi_x86_asm.S +0 -193
- package/node_modules/koffi/src/koffi/src/abi_x86_asm.asm +0 -177
- package/node_modules/koffi/src/koffi/src/call.cc +0 -1326
- package/node_modules/koffi/src/koffi/src/call.hh +0 -179
- package/node_modules/koffi/src/koffi/src/errno.inc +0 -462
- package/node_modules/koffi/src/koffi/src/ffi.cc +0 -2702
- package/node_modules/koffi/src/koffi/src/ffi.hh +0 -354
- package/node_modules/koffi/src/koffi/src/init.js +0 -105
- package/node_modules/koffi/src/koffi/src/parser.cc +0 -220
- package/node_modules/koffi/src/koffi/src/parser.hh +0 -54
- package/node_modules/koffi/src/koffi/src/util.cc +0 -1807
- package/node_modules/koffi/src/koffi/src/util.hh +0 -221
- package/node_modules/koffi/src/koffi/src/uv.cc +0 -193
- package/node_modules/koffi/src/koffi/src/uv.def +0 -10
- package/node_modules/koffi/src/koffi/src/uv.hh +0 -40
- package/node_modules/koffi/src/koffi/src/win32.cc +0 -198
- package/node_modules/koffi/src/koffi/src/win32.hh +0 -119
- package/node_modules/koffi/src/koffi/tools/write_trampolines.js +0 -77
- package/node_modules/koffi/vendor/node-addon-api/LICENSE.md +0 -9
- package/node_modules/koffi/vendor/node-addon-api/README.md +0 -95
- package/node_modules/koffi/vendor/node-addon-api/napi-inl.deprecated.h +0 -186
- package/node_modules/koffi/vendor/node-addon-api/napi-inl.h +0 -7033
- package/node_modules/koffi/vendor/node-addon-api/napi.h +0 -3309
- package/node_modules/koffi/vendor/node-api-headers/LICENSE +0 -21
- package/node_modules/koffi/vendor/node-api-headers/README.md +0 -95
- package/node_modules/koffi/vendor/node-api-headers/def/js_native_api.def +0 -125
- package/node_modules/koffi/vendor/node-api-headers/def/node_api.def +0 -157
- package/node_modules/koffi/vendor/node-api-headers/include/js_native_api.h +0 -591
- package/node_modules/koffi/vendor/node-api-headers/include/js_native_api_types.h +0 -210
- package/node_modules/koffi/vendor/node-api-headers/include/node_api.h +0 -265
- package/node_modules/koffi/vendor/node-api-headers/include/node_api_types.h +0 -58
- package/node_modules/koffi/vendor/node-api-headers/include/uv/aix.h +0 -32
- package/node_modules/koffi/vendor/node-api-headers/include/uv/bsd.h +0 -34
- package/node_modules/koffi/vendor/node-api-headers/include/uv/darwin.h +0 -61
- package/node_modules/koffi/vendor/node-api-headers/include/uv/errno.h +0 -483
- package/node_modules/koffi/vendor/node-api-headers/include/uv/linux.h +0 -34
- package/node_modules/koffi/vendor/node-api-headers/include/uv/os390.h +0 -33
- package/node_modules/koffi/vendor/node-api-headers/include/uv/posix.h +0 -31
- package/node_modules/koffi/vendor/node-api-headers/include/uv/sunos.h +0 -44
- package/node_modules/koffi/vendor/node-api-headers/include/uv/threadpool.h +0 -37
- package/node_modules/koffi/vendor/node-api-headers/include/uv/tree.h +0 -521
- package/node_modules/koffi/vendor/node-api-headers/include/uv/unix.h +0 -512
- package/node_modules/koffi/vendor/node-api-headers/include/uv/version.h +0 -43
- package/node_modules/koffi/vendor/node-api-headers/include/uv/win.h +0 -698
- package/node_modules/koffi/vendor/node-api-headers/include/uv.h +0 -1990
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
// SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
|
|
3
|
-
|
|
4
|
-
#pragma once
|
|
5
|
-
|
|
6
|
-
#include "lib/native/base/base.hh"
|
|
7
|
-
#include "ffi.hh"
|
|
8
|
-
|
|
9
|
-
#include <napi.h>
|
|
10
|
-
|
|
11
|
-
namespace K {
|
|
12
|
-
|
|
13
|
-
extern const napi_type_tag TypeInfoMarker;
|
|
14
|
-
extern const napi_type_tag CastMarker;
|
|
15
|
-
extern const napi_type_tag MagicUnionMarker;
|
|
16
|
-
|
|
17
|
-
class MagicUnion: public Napi::ObjectWrap<MagicUnion> {
|
|
18
|
-
const TypeInfo *type;
|
|
19
|
-
|
|
20
|
-
Napi::Reference<Napi::Symbol> active_symbol;
|
|
21
|
-
Size active_idx = -1;
|
|
22
|
-
|
|
23
|
-
HeapArray<uint8_t> raw;
|
|
24
|
-
|
|
25
|
-
public:
|
|
26
|
-
static Napi::Function InitClass(Napi::Env env, const TypeInfo *type);
|
|
27
|
-
|
|
28
|
-
MagicUnion(const Napi::CallbackInfo &info);
|
|
29
|
-
|
|
30
|
-
const TypeInfo *GetType() { return type; }
|
|
31
|
-
const RecordMember *GetMember() const { return (active_idx >= 0) ? &type->members[active_idx] : nullptr; }
|
|
32
|
-
|
|
33
|
-
void SetRaw(const uint8_t *ptr);
|
|
34
|
-
const uint8_t *GetRaw() const { return raw.ptr; }
|
|
35
|
-
|
|
36
|
-
private:
|
|
37
|
-
Napi::Value Getter(const Napi::CallbackInfo &info);
|
|
38
|
-
void Setter(const Napi::CallbackInfo &info, const Napi::Value &value);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
template <typename T, typename... Args>
|
|
42
|
-
void ThrowError(Napi::Env env, const char *msg, Args... args)
|
|
43
|
-
{
|
|
44
|
-
char buf[1024];
|
|
45
|
-
Fmt(buf, msg, args...);
|
|
46
|
-
|
|
47
|
-
auto err = T::New(env, buf);
|
|
48
|
-
err.ThrowAsJavaScriptException();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
static inline bool IsInteger(const TypeInfo *type)
|
|
52
|
-
{
|
|
53
|
-
bool integer = ((int)type->primitive >= (int)PrimitiveKind::Int8 &&
|
|
54
|
-
(int)type->primitive <= (int)PrimitiveKind::UInt64);
|
|
55
|
-
return integer;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
static inline bool IsFloat(const TypeInfo *type)
|
|
59
|
-
{
|
|
60
|
-
bool fp = (type->primitive == PrimitiveKind::Float32 ||
|
|
61
|
-
type->primitive == PrimitiveKind::Float64);
|
|
62
|
-
return fp;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
static inline bool IsRegularSize(Size size, Size max)
|
|
66
|
-
{
|
|
67
|
-
bool regular = (size <= max && !(size & (size - 1)));
|
|
68
|
-
return regular;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
int ResolveDirections(Span<const char> str);
|
|
72
|
-
const TypeInfo *ResolveType(Napi::Value value, int *out_directions = nullptr);
|
|
73
|
-
const TypeInfo *ResolveType(Napi::Env env, Span<const char> str);
|
|
74
|
-
|
|
75
|
-
TypeInfo *MakePointerType(InstanceData *instance, const TypeInfo *ref, int count = 1);
|
|
76
|
-
TypeInfo *MakeArrayType(InstanceData *instance, const TypeInfo *ref, Size len);
|
|
77
|
-
TypeInfo *MakeArrayType(InstanceData *instance, const TypeInfo *ref, Size len, ArrayHint hint);
|
|
78
|
-
|
|
79
|
-
Napi::External<TypeInfo> WrapType(Napi::Env env, const TypeInfo *type);
|
|
80
|
-
|
|
81
|
-
bool CanPassType(const TypeInfo *type, int directions);
|
|
82
|
-
bool CanReturnType(const TypeInfo *type);
|
|
83
|
-
bool CanStoreType(const TypeInfo *type);
|
|
84
|
-
|
|
85
|
-
// Can be slow, only use for error messages
|
|
86
|
-
const char *GetValueType(const InstanceData *instance, Napi::Value value);
|
|
87
|
-
|
|
88
|
-
void SetValueTag(Napi::Value value, const void *marker);
|
|
89
|
-
bool CheckValueTag(Napi::Value value, const void *marker);
|
|
90
|
-
|
|
91
|
-
static inline bool IsNullOrUndefined(Napi::Value value)
|
|
92
|
-
{
|
|
93
|
-
return value.IsNull() || value.IsUndefined();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
static inline bool IsObject(Napi::Value value)
|
|
97
|
-
{
|
|
98
|
-
return value.IsObject() && !IsNullOrUndefined(value) && !value.IsArray();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
static inline bool IsRawBuffer(Napi::Value value)
|
|
102
|
-
{
|
|
103
|
-
return value.IsTypedArray() || value.IsArrayBuffer();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
static inline Span<uint8_t> GetRawBuffer(Napi::Value value)
|
|
107
|
-
{
|
|
108
|
-
if (value.IsBuffer()) {
|
|
109
|
-
void *ptr = nullptr;
|
|
110
|
-
size_t length = 0;
|
|
111
|
-
|
|
112
|
-
// Assume it works
|
|
113
|
-
napi_get_buffer_info(value.Env(), value, &ptr, &length);
|
|
114
|
-
|
|
115
|
-
return MakeSpan((uint8_t *)ptr, (Size)length);
|
|
116
|
-
} else if (value.IsArrayBuffer()) {
|
|
117
|
-
Napi::ArrayBuffer buffer = value.As<Napi::ArrayBuffer>();
|
|
118
|
-
|
|
119
|
-
return MakeSpan((uint8_t *)buffer.Data(), (Size)buffer.ByteLength());
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
K_UNREACHABLE();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
int GetTypedArrayType(const TypeInfo *type);
|
|
126
|
-
|
|
127
|
-
template <typename T>
|
|
128
|
-
T GetNumber(Napi::Value value)
|
|
129
|
-
{
|
|
130
|
-
K_ASSERT(value.IsNumber() || value.IsBigInt());
|
|
131
|
-
|
|
132
|
-
if (value.IsNumber()) [[likely]] {
|
|
133
|
-
return (T)value.As<Napi::Number>().DoubleValue();
|
|
134
|
-
} else if (value.IsBigInt()) {
|
|
135
|
-
Napi::BigInt bigint = value.As<Napi::BigInt>();
|
|
136
|
-
|
|
137
|
-
bool lossless;
|
|
138
|
-
return (T)bigint.Uint64Value(&lossless);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
K_UNREACHABLE();
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
template <typename T>
|
|
145
|
-
Size NullTerminatedLength(const T *ptr)
|
|
146
|
-
{
|
|
147
|
-
Size len = 0;
|
|
148
|
-
while (ptr[len]) {
|
|
149
|
-
len++;
|
|
150
|
-
}
|
|
151
|
-
return len;
|
|
152
|
-
}
|
|
153
|
-
template <typename T>
|
|
154
|
-
Size NullTerminatedLength(const T *ptr, Size max)
|
|
155
|
-
{
|
|
156
|
-
Size len = 0;
|
|
157
|
-
while (len < max && ptr[len]) {
|
|
158
|
-
len++;
|
|
159
|
-
}
|
|
160
|
-
return len;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
Napi::String MakeStringFromUTF32(Napi::Env env, const char32_t *ptr, Size len);
|
|
164
|
-
static inline Napi::String MakeStringFromUTF32(Napi::Env env, const char32_t *ptr)
|
|
165
|
-
{ return MakeStringFromUTF32(env, ptr, NullTerminatedLength(ptr)); }
|
|
166
|
-
|
|
167
|
-
Napi::Object DecodeObject(Napi::Env env, const uint8_t *origin, const TypeInfo *type);
|
|
168
|
-
void DecodeObject(Napi::Object obj, const uint8_t *origin, const TypeInfo *type);
|
|
169
|
-
Napi::Value DecodeArray(Napi::Env env, const uint8_t *origin, const TypeInfo *type, uint32_t len);
|
|
170
|
-
Napi::Value DecodeArray(Napi::Env env, const uint8_t *origin, const TypeInfo *type);
|
|
171
|
-
void DecodeNormalArray(Napi::Array array, const uint8_t *origin, const TypeInfo *ref);
|
|
172
|
-
void DecodeBuffer(Span<uint8_t> buffer, const uint8_t *origin, const TypeInfo *ref);
|
|
173
|
-
|
|
174
|
-
Napi::Value Decode(Napi::Value value, Size offset, const TypeInfo *type, const Size *len = nullptr);
|
|
175
|
-
Napi::Value Decode(Napi::Env env, const uint8_t *ptr, const TypeInfo *type, const Size *len = nullptr);
|
|
176
|
-
|
|
177
|
-
bool Encode(Napi::Value ref, Size offset, Napi::Value value, const TypeInfo *type, const Size *len = nullptr);
|
|
178
|
-
bool Encode(Napi::Env env, uint8_t *ptr, Napi::Value value, const TypeInfo *type, const Size *len = nullptr);
|
|
179
|
-
|
|
180
|
-
static inline Napi::Value NewBigInt(Napi::Env env, int64_t value)
|
|
181
|
-
{
|
|
182
|
-
if (value <= 9007199254740992ll && value >= -9007199254740992ll) {
|
|
183
|
-
double d = (double)value;
|
|
184
|
-
return Napi::Number::New(env, d);
|
|
185
|
-
} else {
|
|
186
|
-
return Napi::BigInt::New(env, value);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
static inline Napi::Value NewBigInt(Napi::Env env, uint64_t value)
|
|
191
|
-
{
|
|
192
|
-
if (value <= 9007199254740992ull) {
|
|
193
|
-
double d = (double)value;
|
|
194
|
-
return Napi::Number::New(env, d);
|
|
195
|
-
} else {
|
|
196
|
-
return Napi::BigInt::New(env, value);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
static inline Napi::Array GetOwnPropertyNames(Napi::Object obj)
|
|
201
|
-
{
|
|
202
|
-
Napi::Env env = obj.Env();
|
|
203
|
-
|
|
204
|
-
napi_value result;
|
|
205
|
-
napi_status status = napi_get_all_property_names(env, obj, napi_key_own_only,
|
|
206
|
-
(napi_key_filter)(napi_key_enumerable | napi_key_skip_symbols),
|
|
207
|
-
napi_key_numbers_to_strings, &result);
|
|
208
|
-
K_ASSERT(status == napi_ok);
|
|
209
|
-
|
|
210
|
-
return Napi::Array(env, result);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
Napi::Function WrapFunction(Napi::Env env, const FunctionInfo *func);
|
|
214
|
-
|
|
215
|
-
bool DetectCallConvention(Span<const char> name, CallConvention *out_convention);
|
|
216
|
-
|
|
217
|
-
int AnalyseFlat(const TypeInfo *type, FunctionRef<void(const TypeInfo *type, int offset, int count)> func);
|
|
218
|
-
|
|
219
|
-
void DumpMemory(const char *type, Span<const uint8_t> bytes);
|
|
220
|
-
|
|
221
|
-
}
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
|
|
3
|
-
#include "uv.hh"
|
|
4
|
-
#include "util.hh"
|
|
5
|
-
|
|
6
|
-
#include <uv.h>
|
|
7
|
-
|
|
8
|
-
namespace K {
|
|
9
|
-
|
|
10
|
-
Napi::Function PollHandle::Define(Napi::Env env)
|
|
11
|
-
{
|
|
12
|
-
return DefineClass(env, "PollHandle", {
|
|
13
|
-
InstanceMethod("start", &PollHandle::Start),
|
|
14
|
-
InstanceMethod("stop", &PollHandle::Stop),
|
|
15
|
-
InstanceMethod("close", &PollHandle::Close),
|
|
16
|
-
InstanceMethod("unref", &PollHandle::Unref),
|
|
17
|
-
InstanceMethod("ref", &PollHandle::Ref)
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
PollHandle::PollHandle(const Napi::CallbackInfo &info)
|
|
22
|
-
: Napi::ObjectWrap<PollHandle>(info), env(info.Env())
|
|
23
|
-
{
|
|
24
|
-
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
25
|
-
|
|
26
|
-
if (info.Length() < 1 || !info[0].IsNumber()) {
|
|
27
|
-
ThrowError<Napi::Error>(env, "Expected 1 argument, got %1", info.Length());
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (!info[0].IsNumber()) {
|
|
31
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for descriptor, expected number", GetValueType(instance, info[0]));
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
int fd = info[0].As<Napi::Number>().Int32Value();
|
|
36
|
-
|
|
37
|
-
uv_loop_t *loop = nullptr;
|
|
38
|
-
if (napi_get_uv_event_loop(env, &loop) != napi_ok || !loop) {
|
|
39
|
-
ThrowError<Napi::Error>(env, "napi_get_uv_event_loop() failed");
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// We would store it inside the class, but the definition of uv_poll_t involves windows.h...
|
|
44
|
-
// and we won't want that on Windows. Heap allocation it is!
|
|
45
|
-
// Also, it may have to outlive the object, because uv_close() is asynchronous.
|
|
46
|
-
handle = new uv_poll_t();
|
|
47
|
-
|
|
48
|
-
if (int ret = uv_poll_init_socket(loop, handle, (uv_os_sock_t)fd); ret != 0) {
|
|
49
|
-
ThrowError<Napi::Error>(env, "Failed to init UV poll: %1", uv_strerror(ret));
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
handle->data = this;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
void PollHandle::Start(const Napi::CallbackInfo &info)
|
|
57
|
-
{
|
|
58
|
-
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
59
|
-
|
|
60
|
-
bool has_opts = (info.Length() >= 2 && info[0].IsObject());
|
|
61
|
-
|
|
62
|
-
if (info.Length() < 1u + has_opts) {
|
|
63
|
-
ThrowError<Napi::TypeError>(env, "Expected 1 to 2 arguments, got %1", info.Length());
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
if (!info[0u + has_opts].IsFunction()) {
|
|
67
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for callback, expected function", GetValueType(instance, info[0u + has_opts]));
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
int events = 0;
|
|
72
|
-
Napi::Function cb = info[0 + has_opts].As<Napi::Function>();
|
|
73
|
-
|
|
74
|
-
if (has_opts) {
|
|
75
|
-
Napi::Object opts = has_opts ? info[0].As<Napi::Object>() : Napi::Object::New(env);
|
|
76
|
-
|
|
77
|
-
events |= opts.Get("readable").ToBoolean() ? UV_READABLE : 0;
|
|
78
|
-
events |= opts.Get("writable").ToBoolean() ? UV_WRITABLE : 0;
|
|
79
|
-
events |= opts.Get("disconnect").ToBoolean() ? UV_DISCONNECT : 0;
|
|
80
|
-
} else {
|
|
81
|
-
events = UV_READABLE;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
callback.Reset(cb, 1);
|
|
85
|
-
|
|
86
|
-
if (int ret = uv_poll_start(handle, events, &PollHandle::OnPoll); ret != 0) {
|
|
87
|
-
callback.Reset();
|
|
88
|
-
ThrowError<Napi::Error>(env, "Failed to start UV poll: %1", uv_strerror(ret));
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
void PollHandle::Stop(const Napi::CallbackInfo &)
|
|
93
|
-
{
|
|
94
|
-
uv_poll_stop(handle);
|
|
95
|
-
callback.Reset();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
void PollHandle::Close(const Napi::CallbackInfo &)
|
|
99
|
-
{
|
|
100
|
-
Close();
|
|
101
|
-
callback.Reset();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
void PollHandle::Ref(const Napi::CallbackInfo &)
|
|
105
|
-
{
|
|
106
|
-
uv_ref((uv_handle_t *)handle);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
void PollHandle::Unref(const Napi::CallbackInfo &)
|
|
110
|
-
{
|
|
111
|
-
uv_unref((uv_handle_t *)handle);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
void PollHandle::Close()
|
|
115
|
-
{
|
|
116
|
-
if (!handle)
|
|
117
|
-
return;
|
|
118
|
-
|
|
119
|
-
const auto release = [](uv_handle_t *ptr) {
|
|
120
|
-
uv_poll_t *handle = (uv_poll_t *)ptr;
|
|
121
|
-
delete handle;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
uv_poll_stop(handle);
|
|
125
|
-
uv_close((uv_handle_t *)handle, release);
|
|
126
|
-
|
|
127
|
-
handle = nullptr;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
void PollHandle::OnPoll(uv_poll_t *h, int status, int events)
|
|
131
|
-
{
|
|
132
|
-
PollHandle *poll = (PollHandle *)h->data;
|
|
133
|
-
|
|
134
|
-
if (poll->callback.IsEmpty()) [[unlikely]]
|
|
135
|
-
return;
|
|
136
|
-
|
|
137
|
-
Napi::Env env = poll->env;
|
|
138
|
-
Napi::HandleScope scope(env);
|
|
139
|
-
|
|
140
|
-
Napi::Object obj = Napi::Object::New(env);
|
|
141
|
-
|
|
142
|
-
obj.Set("readable", !!(events & UV_READABLE));
|
|
143
|
-
obj.Set("writable", !!(events & UV_WRITABLE));
|
|
144
|
-
obj.Set("disconnect", !!(events & UV_DISCONNECT));
|
|
145
|
-
|
|
146
|
-
napi_value args[] = { Napi::Number::New(env, status), obj };
|
|
147
|
-
poll->callback.Call(poll->Value(), K_LEN(args), args);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
Napi::Value Poll(const Napi::CallbackInfo &info)
|
|
151
|
-
{
|
|
152
|
-
Napi::Env env = info.Env();
|
|
153
|
-
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
154
|
-
|
|
155
|
-
bool has_opts = (info.Length() >= 3 && info[1].IsObject());
|
|
156
|
-
|
|
157
|
-
if (info.Length() < 2u + has_opts) {
|
|
158
|
-
ThrowError<Napi::TypeError>(env, "Expected 2 to 3 arguments, got %1", info.Length());
|
|
159
|
-
return env.Null();
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (!info[0].IsNumber()) {
|
|
163
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for descriptor, expected number", GetValueType(instance, info[0]));
|
|
164
|
-
return env.Null();
|
|
165
|
-
}
|
|
166
|
-
if (!info[1 + has_opts].IsFunction()) {
|
|
167
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for callback, expected function", GetValueType(instance, info[1 + has_opts]));
|
|
168
|
-
return env.Null();
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
int fd = info[0].As<Napi::Number>().Int32Value();
|
|
172
|
-
|
|
173
|
-
Napi::Function ctor = PollHandle::Define(env);
|
|
174
|
-
Napi::Object inst = ctor.New({ Napi::Number::New(env, fd) });
|
|
175
|
-
Napi::Function start = inst.Get("start").As<Napi::Function>();
|
|
176
|
-
|
|
177
|
-
if (env.IsExceptionPending()) [[unlikely]]
|
|
178
|
-
return env.Null();
|
|
179
|
-
|
|
180
|
-
if (has_opts) {
|
|
181
|
-
Napi::Value opts = info[1];
|
|
182
|
-
Napi::Function cb = info[2].As<Napi::Function>();
|
|
183
|
-
|
|
184
|
-
start.Call(inst, { opts, cb });
|
|
185
|
-
} else {
|
|
186
|
-
Napi::Function cb = info[1].As<Napi::Function>();
|
|
187
|
-
start.Call(inst, { cb });
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return inst;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
|
|
3
|
-
#pragma once
|
|
4
|
-
|
|
5
|
-
#include "lib/native/base/base.hh"
|
|
6
|
-
|
|
7
|
-
#include <napi.h>
|
|
8
|
-
|
|
9
|
-
struct uv_poll_s;
|
|
10
|
-
typedef struct uv_poll_s uv_poll_t;
|
|
11
|
-
|
|
12
|
-
namespace K {
|
|
13
|
-
|
|
14
|
-
class PollHandle: public Napi::ObjectWrap<PollHandle> {
|
|
15
|
-
Napi::Env env = nullptr;
|
|
16
|
-
|
|
17
|
-
uv_poll_t *handle = nullptr;
|
|
18
|
-
Napi::FunctionReference callback;
|
|
19
|
-
|
|
20
|
-
public:
|
|
21
|
-
static Napi::Function Define(Napi::Env env);
|
|
22
|
-
|
|
23
|
-
PollHandle(const Napi::CallbackInfo &info);
|
|
24
|
-
~PollHandle() { Close(); }
|
|
25
|
-
|
|
26
|
-
void Start(const Napi::CallbackInfo &info);
|
|
27
|
-
void Stop(const Napi::CallbackInfo &info);
|
|
28
|
-
void Close(const Napi::CallbackInfo &info);
|
|
29
|
-
void Ref(const Napi::CallbackInfo &info);
|
|
30
|
-
void Unref(const Napi::CallbackInfo &info);
|
|
31
|
-
|
|
32
|
-
private:
|
|
33
|
-
void Close();
|
|
34
|
-
|
|
35
|
-
static void OnPoll(uv_poll_t *handle, int status, int events);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
Napi::Value Poll(const Napi::CallbackInfo &info);
|
|
39
|
-
|
|
40
|
-
}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
// SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
|
|
3
|
-
|
|
4
|
-
#if defined(_WIN32)
|
|
5
|
-
|
|
6
|
-
#include "util.hh"
|
|
7
|
-
#include "win32.hh"
|
|
8
|
-
|
|
9
|
-
#if !defined(NOMINMAX)
|
|
10
|
-
#define NOMINMAX
|
|
11
|
-
#endif
|
|
12
|
-
#if !defined(WIN32_LEAN_AND_MEAN)
|
|
13
|
-
#define WIN32_LEAN_AND_MEAN
|
|
14
|
-
#endif
|
|
15
|
-
#include <windows.h>
|
|
16
|
-
#include <ntsecapi.h>
|
|
17
|
-
#include <processthreadsapi.h>
|
|
18
|
-
|
|
19
|
-
namespace K {
|
|
20
|
-
|
|
21
|
-
const HashMap<int, const char *> WindowsMachineNames = {
|
|
22
|
-
{ 0x184, "Alpha AXP, 32-bit" },
|
|
23
|
-
{ 0x284, "Alpha 64" },
|
|
24
|
-
{ 0x1d3, "Matsushita AM33" },
|
|
25
|
-
{ 0x8664, "AMD x64" },
|
|
26
|
-
{ 0x1c0, "ARM little endian" },
|
|
27
|
-
{ 0xaa64, "ARM64 little endian" },
|
|
28
|
-
{ 0x1c4, "ARM Thumb-2 little endian" },
|
|
29
|
-
{ 0x284, "AXP 64" },
|
|
30
|
-
{ 0xebc, "EFI byte code" },
|
|
31
|
-
{ 0x14c, "Intel 386+" },
|
|
32
|
-
{ 0x200, "Intel Itanium" },
|
|
33
|
-
{ 0x6232, "LoongArch 32-bit" },
|
|
34
|
-
{ 0x6264, "LoongArch 64-bit" },
|
|
35
|
-
{ 0x9041, "Mitsubishi M32R little endian" },
|
|
36
|
-
{ 0x266, "MIPS16" },
|
|
37
|
-
{ 0x366, "MIPS with FPU" },
|
|
38
|
-
{ 0x466, "MIPS16 with FPU" },
|
|
39
|
-
{ 0x1f0, "Power PC little endian" },
|
|
40
|
-
{ 0x1f1, "Power PC with FP support" },
|
|
41
|
-
{ 0x166, "MIPS little endian" },
|
|
42
|
-
{ 0x5032, "RISC-V 32-bit" },
|
|
43
|
-
{ 0x5064, "RISC-V 64-bit" },
|
|
44
|
-
{ 0x5128, "RISC-V 128-bit" },
|
|
45
|
-
{ 0x1a2, "Hitachi SH3" },
|
|
46
|
-
{ 0x1a3, "Hitachi SH3 DSP" },
|
|
47
|
-
{ 0x1a6, "Hitachi SH4" },
|
|
48
|
-
{ 0x1a8, "Hitachi SH5" },
|
|
49
|
-
{ 0x1c2, "Thumb" },
|
|
50
|
-
{ 0x169, "MIPS little-endian WCE v2" }
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
HANDLE LoadWindowsLibrary(Napi::Env env, Span<const char> path)
|
|
54
|
-
{
|
|
55
|
-
BlockAllocator temp_alloc;
|
|
56
|
-
|
|
57
|
-
Span<wchar_t> filename_w = AllocateSpan<wchar_t>(&temp_alloc, path.len + 1);
|
|
58
|
-
|
|
59
|
-
if (ConvertUtf8ToWin32Wide(path, filename_w) < 0) {
|
|
60
|
-
ThrowError<Napi::Error>(env, "Invalid path string");
|
|
61
|
-
return nullptr;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
HMODULE module = LoadLibraryW(filename_w.ptr);
|
|
65
|
-
|
|
66
|
-
if (!module) {
|
|
67
|
-
DWORD flags = LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR;
|
|
68
|
-
|
|
69
|
-
Span<const char> filename = NormalizePath(path, GetWorkingDirectory(), &temp_alloc);
|
|
70
|
-
Span<wchar_t> filename_w = AllocateSpan<wchar_t>(&temp_alloc, filename.len + 1);
|
|
71
|
-
|
|
72
|
-
if (ConvertUtf8ToWin32Wide(filename, filename_w) < 0) {
|
|
73
|
-
ThrowError<Napi::Error>(env, "Invalid path string");
|
|
74
|
-
return nullptr;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
module = LoadLibraryExW(filename_w.ptr, nullptr, flags);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (!module) {
|
|
81
|
-
if (GetLastError() == ERROR_BAD_EXE_FORMAT) {
|
|
82
|
-
int process = GetSelfMachine();
|
|
83
|
-
int dll = GetDllMachine(filename_w.ptr);
|
|
84
|
-
|
|
85
|
-
if (process >= 0 && dll >= 0 && dll != process) {
|
|
86
|
-
ThrowError<Napi::Error>(env, "Cannot load '%1' DLL in '%2' process",
|
|
87
|
-
WindowsMachineNames.FindValue(dll, "Unknown"),
|
|
88
|
-
WindowsMachineNames.FindValue(process, "Unknown"));
|
|
89
|
-
return nullptr;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
ThrowError<Napi::Error>(env, "Failed to load shared library: %1", GetWin32ErrorString());
|
|
94
|
-
return nullptr;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return module;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Fails silently on purpose
|
|
101
|
-
static bool ReadAt(HANDLE h, int32_t offset, void *buf, int len)
|
|
102
|
-
{
|
|
103
|
-
OVERLAPPED ov = {};
|
|
104
|
-
DWORD read;
|
|
105
|
-
|
|
106
|
-
ov.Offset = offset & 0x7FFFFFFFu;
|
|
107
|
-
|
|
108
|
-
if (offset < 0)
|
|
109
|
-
return false;
|
|
110
|
-
if (!ReadFile(h, buf, (DWORD)len, &read, &ov))
|
|
111
|
-
return false;
|
|
112
|
-
if (read != (DWORD)len)
|
|
113
|
-
return false;
|
|
114
|
-
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
static int GetFileMachine(HANDLE h, bool check_dll)
|
|
119
|
-
{
|
|
120
|
-
PE_DOS_HEADER dos = {};
|
|
121
|
-
PE_NT_HEADERS nt = {};
|
|
122
|
-
|
|
123
|
-
if (!ReadAt(h, 0, &dos, K_SIZE(dos)))
|
|
124
|
-
goto generic;
|
|
125
|
-
if (!ReadAt(h, dos.e_lfanew, &nt, K_SIZE(nt)))
|
|
126
|
-
goto generic;
|
|
127
|
-
|
|
128
|
-
if (dos.e_magic != 0x5A4D) // MZ
|
|
129
|
-
goto generic;
|
|
130
|
-
if (nt.Signature != 0x00004550) // PE\0\0
|
|
131
|
-
goto generic;
|
|
132
|
-
if (check_dll && !(nt.FileHeader.Characteristics & IMAGE_FILE_DLL))
|
|
133
|
-
goto generic;
|
|
134
|
-
|
|
135
|
-
return (int)nt.FileHeader.Machine;
|
|
136
|
-
|
|
137
|
-
generic:
|
|
138
|
-
LogError("Invalid or forbidden %1 file: %2", check_dll ? "DLL" : "executable", GetWin32ErrorString());
|
|
139
|
-
return -1;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
int GetSelfMachine()
|
|
143
|
-
{
|
|
144
|
-
const char *filename = GetApplicationExecutable();
|
|
145
|
-
|
|
146
|
-
HANDLE h;
|
|
147
|
-
if (IsWin32Utf8()) {
|
|
148
|
-
h = CreateFileA(filename, GENERIC_READ,
|
|
149
|
-
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
|
150
|
-
nullptr, OPEN_EXISTING, 0, nullptr);
|
|
151
|
-
} else {
|
|
152
|
-
wchar_t filename_w[4096];
|
|
153
|
-
if (ConvertUtf8ToWin32Wide(filename, filename_w) < 0)
|
|
154
|
-
return -1;
|
|
155
|
-
|
|
156
|
-
h = CreateFileW(filename_w, GENERIC_READ,
|
|
157
|
-
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
|
158
|
-
nullptr, OPEN_EXISTING, 0, nullptr);
|
|
159
|
-
}
|
|
160
|
-
if (h == INVALID_HANDLE_VALUE) {
|
|
161
|
-
LogError("Cannot open '%1': %2", filename, GetWin32ErrorString());
|
|
162
|
-
return -1;
|
|
163
|
-
}
|
|
164
|
-
K_DEFER { CloseHandle(h); };
|
|
165
|
-
|
|
166
|
-
return GetFileMachine(h, false);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
int GetDllMachine(const wchar_t *filename)
|
|
170
|
-
{
|
|
171
|
-
HANDLE h = CreateFileW((LPCWSTR)filename, GENERIC_READ,
|
|
172
|
-
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
|
173
|
-
nullptr, OPEN_EXISTING, 0, nullptr);
|
|
174
|
-
if (h == INVALID_HANDLE_VALUE) {
|
|
175
|
-
LogError("Cannot open '%1': %2", filename, GetWin32ErrorString());
|
|
176
|
-
return -1;
|
|
177
|
-
}
|
|
178
|
-
K_DEFER { CloseHandle(h); };
|
|
179
|
-
|
|
180
|
-
return GetFileMachine(h, true);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
extern "C" int __cdecl SehHandler(void *ptr, void *, void *ctx, void *)
|
|
184
|
-
{
|
|
185
|
-
EXCEPTION_RECORD *rec = (EXCEPTION_RECORD *)ptr;
|
|
186
|
-
|
|
187
|
-
if (!(rec->ExceptionFlags & (EXCEPTION_UNWINDING | EXCEPTION_EXIT_UNWIND))) {
|
|
188
|
-
EXCEPTION_POINTERS ep = { rec, (CONTEXT *)ctx };
|
|
189
|
-
UnhandledExceptionFilter(&ep);
|
|
190
|
-
ExitProcess(rec->ExceptionCode);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return ExceptionContinueSearch;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
#endif
|