@secure-exec/core 0.2.1 → 0.3.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/binary.d.ts +4 -0
- package/dist/binary.js +25 -0
- package/dist/bytes.d.ts +2 -0
- package/dist/bytes.js +6 -0
- package/dist/callbacks.d.ts +41 -0
- package/dist/callbacks.js +94 -0
- package/dist/cargo.d.ts +2 -0
- package/dist/cargo.js +142 -0
- package/dist/correlation.d.ts +10 -0
- package/dist/correlation.js +49 -0
- package/dist/descriptors.d.ts +34 -0
- package/dist/descriptors.js +37 -0
- package/dist/event-buffer.d.ts +90 -0
- package/dist/event-buffer.js +313 -0
- package/dist/ext.d.ts +7 -0
- package/dist/ext.js +13 -0
- package/dist/filesystem.d.ts +41 -0
- package/dist/filesystem.js +70 -0
- package/dist/frame-payload-codec.d.ts +8 -0
- package/dist/frame-payload-codec.js +14 -0
- package/dist/frame-rpc.d.ts +38 -0
- package/dist/frame-rpc.js +73 -0
- package/dist/frame-stream.d.ts +27 -0
- package/dist/frame-stream.js +99 -0
- package/dist/framing.d.ts +7 -0
- package/dist/framing.js +22 -0
- package/dist/generated/AcpLimitsConfig.d.ts +4 -0
- package/dist/generated/AcpLimitsConfig.js +2 -0
- package/dist/generated/CreateVmConfig.d.ts +19 -0
- package/dist/generated/FsPermissionRule.d.ts +6 -0
- package/dist/generated/FsPermissionRuleSet.d.ts +6 -0
- package/dist/generated/FsPermissionRuleSet.js +1 -0
- package/dist/generated/FsPermissionScope.d.ts +3 -0
- package/dist/generated/FsPermissionScope.js +1 -0
- package/dist/generated/HttpLimitsConfig.d.ts +3 -0
- package/dist/generated/HttpLimitsConfig.js +2 -0
- package/dist/generated/JsModuleResolution.d.ts +1 -0
- package/dist/generated/JsModuleResolution.js +2 -0
- package/dist/generated/JsRuntimeConfig.d.ts +26 -0
- package/dist/generated/JsRuntimeConfig.js +1 -0
- package/dist/generated/JsRuntimeLimitsConfig.d.ts +7 -0
- package/dist/generated/JsRuntimeLimitsConfig.js +2 -0
- package/dist/generated/JsRuntimePlatform.d.ts +1 -0
- package/dist/generated/JsRuntimePlatform.js +2 -0
- package/dist/generated/MountPluginDescriptor.d.ts +4 -0
- package/dist/generated/MountPluginDescriptor.js +2 -0
- package/dist/generated/NativeRootFilesystemConfig.d.ts +5 -0
- package/dist/generated/NativeRootFilesystemConfig.js +1 -0
- package/dist/generated/PatternPermissionRule.d.ts +6 -0
- package/dist/generated/PatternPermissionRule.js +1 -0
- package/dist/generated/PatternPermissionRuleSet.d.ts +6 -0
- package/dist/generated/PatternPermissionRuleSet.js +1 -0
- package/dist/generated/PatternPermissionScope.d.ts +3 -0
- package/dist/generated/PatternPermissionScope.js +1 -0
- package/dist/generated/PermissionMode.d.ts +1 -0
- package/dist/generated/PermissionMode.js +2 -0
- package/dist/generated/PermissionsPolicy.d.ts +10 -0
- package/dist/generated/PermissionsPolicy.js +1 -0
- package/dist/generated/PluginLimitsConfig.d.ts +4 -0
- package/dist/generated/PluginLimitsConfig.js +2 -0
- package/dist/generated/PythonLimitsConfig.d.ts +5 -0
- package/dist/generated/PythonLimitsConfig.js +2 -0
- package/dist/generated/ResourceLimitsConfig.d.ts +22 -0
- package/dist/generated/ResourceLimitsConfig.js +2 -0
- package/dist/generated/RootFilesystemConfig.d.ts +9 -0
- package/dist/generated/RootFilesystemConfig.js +1 -0
- package/dist/generated/RootFilesystemEntry.d.ts +13 -0
- package/dist/generated/RootFilesystemEntry.js +1 -0
- package/dist/generated/RootFilesystemEntryEncoding.d.ts +1 -0
- package/dist/generated/RootFilesystemEntryEncoding.js +2 -0
- package/dist/generated/RootFilesystemEntryKind.d.ts +1 -0
- package/dist/generated/RootFilesystemEntryKind.js +2 -0
- package/dist/generated/RootFilesystemLowerDescriptor.d.ts +7 -0
- package/dist/generated/RootFilesystemLowerDescriptor.js +1 -0
- package/dist/generated/RootFilesystemMode.d.ts +1 -0
- package/dist/generated/RootFilesystemMode.js +2 -0
- package/dist/generated/ToolLimitsConfig.d.ts +10 -0
- package/dist/generated/ToolLimitsConfig.js +2 -0
- package/dist/generated/VmDnsConfig.d.ts +6 -0
- package/dist/generated/VmDnsConfig.js +2 -0
- package/dist/generated/VmLimitsConfig.d.ts +18 -0
- package/dist/generated/VmLimitsConfig.js +1 -0
- package/dist/generated/VmListenPolicyConfig.d.ts +5 -0
- package/dist/generated/VmListenPolicyConfig.js +2 -0
- package/dist/generated/WasmLimitsConfig.d.ts +5 -0
- package/dist/generated/WasmLimitsConfig.js +2 -0
- package/dist/generated-protocol.d.ts +1037 -0
- package/dist/generated-protocol.js +2887 -0
- package/dist/index.d.ts +24 -62
- package/dist/index.js +24 -53
- package/dist/json.d.ts +2 -0
- package/dist/json.js +20 -0
- package/dist/kernel-proxy.d.ts +149 -0
- package/dist/kernel-proxy.js +1733 -0
- package/dist/native-client.d.ts +41 -0
- package/dist/native-client.js +124 -0
- package/dist/node-runtime.d.ts +443 -0
- package/dist/node-runtime.js +569 -0
- package/dist/numbers.d.ts +1 -0
- package/dist/numbers.js +8 -0
- package/dist/ownership.d.ts +18 -0
- package/dist/ownership.js +77 -0
- package/dist/permissions.d.ts +29 -0
- package/dist/permissions.js +68 -0
- package/dist/process.d.ts +35 -0
- package/dist/process.js +125 -0
- package/dist/protocol-client.d.ts +46 -0
- package/dist/protocol-client.js +180 -0
- package/dist/protocol-frames.d.ts +68 -0
- package/dist/protocol-frames.js +139 -0
- package/dist/protocol-maps.d.ts +28 -0
- package/dist/protocol-maps.js +217 -0
- package/dist/protocol-schema.d.ts +10 -0
- package/dist/protocol-schema.js +11 -0
- package/dist/request-payloads.d.ts +137 -0
- package/dist/request-payloads.js +210 -0
- package/dist/response-payloads.d.ts +107 -0
- package/dist/response-payloads.js +161 -0
- package/dist/sidecar-client.d.ts +242 -0
- package/dist/sidecar-client.js +797 -0
- package/dist/state.d.ts +40 -0
- package/dist/state.js +44 -0
- package/dist/test-runtime.d.ts +526 -0
- package/dist/test-runtime.js +2119 -0
- package/dist/vm-config.d.ts +31 -0
- package/dist/vm-config.js +1 -0
- package/fixtures/alpine-defaults.json +520 -0
- package/fixtures/base-filesystem.json +528 -0
- package/package.json +193 -115
- package/LICENSE +0 -191
- package/dist/bridge-setup.d.ts +0 -6
- package/dist/bridge-setup.js +0 -9
- package/dist/esm-compiler.d.ts +0 -18
- package/dist/esm-compiler.js +0 -72
- package/dist/fs-helpers.d.ts +0 -23
- package/dist/fs-helpers.js +0 -41
- package/dist/generated/isolate-runtime.d.ts +0 -19
- package/dist/generated/isolate-runtime.js +0 -21
- package/dist/generated/polyfills.d.ts +0 -82
- package/dist/generated/polyfills.js +0 -82
- package/dist/isolate-runtime/apply-custom-global-policy.js +0 -53
- package/dist/isolate-runtime/apply-timing-mitigation-freeze.js +0 -130
- package/dist/isolate-runtime/apply-timing-mitigation-off.js +0 -14
- package/dist/isolate-runtime/bridge-attach.js +0 -29
- package/dist/isolate-runtime/bridge-initial-globals.js +0 -385
- package/dist/isolate-runtime/eval-script-result.js +0 -8
- package/dist/isolate-runtime/global-exposure-helpers.js +0 -36
- package/dist/isolate-runtime/init-commonjs-module-globals.js +0 -28
- package/dist/isolate-runtime/override-process-cwd.js +0 -8
- package/dist/isolate-runtime/override-process-env.js +0 -8
- package/dist/isolate-runtime/require-setup.js +0 -4153
- package/dist/isolate-runtime/set-commonjs-file-globals.js +0 -36
- package/dist/isolate-runtime/set-stdin-data.js +0 -10
- package/dist/isolate-runtime/setup-dynamic-import.js +0 -123
- package/dist/isolate-runtime/setup-fs-facade.js +0 -87
- package/dist/kernel/command-registry.d.ts +0 -44
- package/dist/kernel/command-registry.js +0 -114
- package/dist/kernel/device-backend.d.ts +0 -14
- package/dist/kernel/device-backend.js +0 -251
- package/dist/kernel/device-layer.d.ts +0 -12
- package/dist/kernel/device-layer.js +0 -271
- package/dist/kernel/dns-cache.d.ts +0 -29
- package/dist/kernel/dns-cache.js +0 -52
- package/dist/kernel/fd-table.d.ts +0 -84
- package/dist/kernel/fd-table.js +0 -278
- package/dist/kernel/file-lock.d.ts +0 -34
- package/dist/kernel/file-lock.js +0 -122
- package/dist/kernel/host-adapter.d.ts +0 -50
- package/dist/kernel/host-adapter.js +0 -8
- package/dist/kernel/index.d.ts +0 -36
- package/dist/kernel/index.js +0 -34
- package/dist/kernel/kernel.d.ts +0 -9
- package/dist/kernel/kernel.js +0 -1415
- package/dist/kernel/mount-table.d.ts +0 -75
- package/dist/kernel/mount-table.js +0 -353
- package/dist/kernel/permissions.d.ts +0 -36
- package/dist/kernel/permissions.js +0 -150
- package/dist/kernel/pipe-manager.d.ts +0 -64
- package/dist/kernel/pipe-manager.js +0 -267
- package/dist/kernel/proc-backend.d.ts +0 -30
- package/dist/kernel/proc-backend.js +0 -428
- package/dist/kernel/proc-layer.d.ts +0 -11
- package/dist/kernel/proc-layer.js +0 -507
- package/dist/kernel/process-table.d.ts +0 -126
- package/dist/kernel/process-table.js +0 -651
- package/dist/kernel/pty.d.ts +0 -109
- package/dist/kernel/pty.js +0 -552
- package/dist/kernel/socket-table.d.ts +0 -312
- package/dist/kernel/socket-table.js +0 -1188
- package/dist/kernel/timer-table.d.ts +0 -54
- package/dist/kernel/timer-table.js +0 -108
- package/dist/kernel/types.d.ts +0 -541
- package/dist/kernel/types.js +0 -98
- package/dist/kernel/user.d.ts +0 -29
- package/dist/kernel/user.js +0 -35
- package/dist/kernel/vfs.d.ts +0 -82
- package/dist/kernel/vfs.js +0 -25
- package/dist/kernel/wait.d.ts +0 -45
- package/dist/kernel/wait.js +0 -112
- package/dist/kernel/wstatus.d.ts +0 -21
- package/dist/kernel/wstatus.js +0 -33
- package/dist/module-resolver.d.ts +0 -29
- package/dist/module-resolver.js +0 -314
- package/dist/package-bundler.d.ts +0 -41
- package/dist/package-bundler.js +0 -497
- package/dist/runtime-driver.d.ts +0 -66
- package/dist/shared/api-types.d.ts +0 -83
- package/dist/shared/bridge-contract.d.ts +0 -772
- package/dist/shared/bridge-contract.js +0 -169
- package/dist/shared/console-formatter.d.ts +0 -22
- package/dist/shared/console-formatter.js +0 -161
- package/dist/shared/constants.d.ts +0 -3
- package/dist/shared/constants.js +0 -3
- package/dist/shared/errors.d.ts +0 -16
- package/dist/shared/errors.js +0 -21
- package/dist/shared/esm-utils.d.ts +0 -28
- package/dist/shared/esm-utils.js +0 -97
- package/dist/shared/global-exposure.d.ts +0 -38
- package/dist/shared/global-exposure.js +0 -876
- package/dist/shared/in-memory-fs.d.ts +0 -16
- package/dist/shared/in-memory-fs.js +0 -115
- package/dist/shared/permissions.d.ts +0 -36
- package/dist/shared/permissions.js +0 -314
- package/dist/shared/require-setup.d.ts +0 -6
- package/dist/shared/require-setup.js +0 -9
- package/dist/test/block-store-conformance.d.ts +0 -34
- package/dist/test/block-store-conformance.js +0 -251
- package/dist/test/metadata-store-conformance.d.ts +0 -37
- package/dist/test/metadata-store-conformance.js +0 -646
- package/dist/test/vfs-conformance.d.ts +0 -65
- package/dist/test/vfs-conformance.js +0 -842
- package/dist/types.d.ts +0 -98
- package/dist/types.js +0 -6
- package/dist/vfs/chunked-vfs.d.ts +0 -66
- package/dist/vfs/chunked-vfs.js +0 -1290
- package/dist/vfs/host-block-store.d.ts +0 -19
- package/dist/vfs/host-block-store.js +0 -97
- package/dist/vfs/memory-block-store.d.ts +0 -16
- package/dist/vfs/memory-block-store.js +0 -45
- package/dist/vfs/memory-metadata.d.ts +0 -75
- package/dist/vfs/memory-metadata.js +0 -528
- package/dist/vfs/sqlite-metadata.d.ts +0 -91
- package/dist/vfs/sqlite-metadata.js +0 -582
- package/dist/vfs/types.d.ts +0 -210
- package/dist/vfs/types.js +0 -8
- /package/dist/{runtime-driver.js → generated/CreateVmConfig.js} +0 -0
- /package/dist/{shared/api-types.js → generated/FsPermissionRule.js} +0 -0
|
@@ -1,428 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Proc backend.
|
|
3
|
-
*
|
|
4
|
-
* Standalone VirtualFileSystem that handles /proc paths.
|
|
5
|
-
* Receives relative paths (e.g. "self/fd" not "/proc/self/fd").
|
|
6
|
-
* Designed to be mounted at /proc via MountTable.
|
|
7
|
-
*/
|
|
8
|
-
import { KernelError } from "./types.js";
|
|
9
|
-
const S_IFREG = 0o100000;
|
|
10
|
-
const S_IFDIR = 0o040000;
|
|
11
|
-
const S_IFLNK = 0o120000;
|
|
12
|
-
const PROC_INO_BASE = 0xfffe_0000;
|
|
13
|
-
const PROC_PID_ENTRIES = [
|
|
14
|
-
{ name: "fd", isDirectory: true },
|
|
15
|
-
{ name: "cwd", isDirectory: false, isSymbolicLink: true },
|
|
16
|
-
{ name: "exe", isDirectory: false, isSymbolicLink: true },
|
|
17
|
-
{ name: "environ", isDirectory: false },
|
|
18
|
-
];
|
|
19
|
-
const PROC_ROOT_ENTRIES = [
|
|
20
|
-
{ name: "self", isDirectory: false, isSymbolicLink: true },
|
|
21
|
-
{ name: "sys", isDirectory: true },
|
|
22
|
-
{ name: "mounts", isDirectory: false },
|
|
23
|
-
];
|
|
24
|
-
const PROC_SYS_ENTRIES = [
|
|
25
|
-
{ name: "kernel", isDirectory: true },
|
|
26
|
-
];
|
|
27
|
-
const PROC_SYS_KERNEL_ENTRIES = [
|
|
28
|
-
{ name: "hostname", isDirectory: false },
|
|
29
|
-
];
|
|
30
|
-
function procIno(seed) {
|
|
31
|
-
let hash = 0;
|
|
32
|
-
for (let i = 0; i < seed.length; i++) {
|
|
33
|
-
hash = ((hash * 33) ^ seed.charCodeAt(i)) >>> 0;
|
|
34
|
-
}
|
|
35
|
-
return PROC_INO_BASE + (hash & 0xffff);
|
|
36
|
-
}
|
|
37
|
-
function dirStat(seed) {
|
|
38
|
-
const now = Date.now();
|
|
39
|
-
return {
|
|
40
|
-
mode: S_IFDIR | 0o555,
|
|
41
|
-
size: 0,
|
|
42
|
-
isDirectory: true,
|
|
43
|
-
isSymbolicLink: false,
|
|
44
|
-
atimeMs: now,
|
|
45
|
-
mtimeMs: now,
|
|
46
|
-
ctimeMs: now,
|
|
47
|
-
birthtimeMs: now,
|
|
48
|
-
ino: procIno(seed),
|
|
49
|
-
nlink: 2,
|
|
50
|
-
uid: 0,
|
|
51
|
-
gid: 0,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
function fileStat(seed, size) {
|
|
55
|
-
const now = Date.now();
|
|
56
|
-
return {
|
|
57
|
-
mode: S_IFREG | 0o444,
|
|
58
|
-
size,
|
|
59
|
-
isDirectory: false,
|
|
60
|
-
isSymbolicLink: false,
|
|
61
|
-
atimeMs: now,
|
|
62
|
-
mtimeMs: now,
|
|
63
|
-
ctimeMs: now,
|
|
64
|
-
birthtimeMs: now,
|
|
65
|
-
ino: procIno(seed),
|
|
66
|
-
nlink: 1,
|
|
67
|
-
uid: 0,
|
|
68
|
-
gid: 0,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
function linkStat(seed, target) {
|
|
72
|
-
const now = Date.now();
|
|
73
|
-
return {
|
|
74
|
-
mode: S_IFLNK | 0o777,
|
|
75
|
-
size: target.length,
|
|
76
|
-
isDirectory: false,
|
|
77
|
-
isSymbolicLink: true,
|
|
78
|
-
atimeMs: now,
|
|
79
|
-
mtimeMs: now,
|
|
80
|
-
ctimeMs: now,
|
|
81
|
-
birthtimeMs: now,
|
|
82
|
-
ino: procIno(seed),
|
|
83
|
-
nlink: 1,
|
|
84
|
-
uid: 0,
|
|
85
|
-
gid: 0,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
function encodeText(content) {
|
|
89
|
-
return new TextEncoder().encode(content);
|
|
90
|
-
}
|
|
91
|
-
function encodeEnviron(env) {
|
|
92
|
-
const entries = Object.entries(env);
|
|
93
|
-
if (entries.length === 0)
|
|
94
|
-
return new Uint8Array(0);
|
|
95
|
-
return encodeText(`${entries.map(([key, value]) => `${key}=${value}`).join("\0")}\0`);
|
|
96
|
-
}
|
|
97
|
-
function resolveExecPath(command) {
|
|
98
|
-
if (!command)
|
|
99
|
-
return "";
|
|
100
|
-
return command.startsWith("/") ? command : `/bin/${command}`;
|
|
101
|
-
}
|
|
102
|
-
function notFound(path) {
|
|
103
|
-
throw new KernelError("ENOENT", `no such proc entry: ${path}`);
|
|
104
|
-
}
|
|
105
|
-
function rejectWrite(path) {
|
|
106
|
-
throw new KernelError("EPERM", `cannot modify /proc/${path}`);
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Resolve /proc/self references to the given PID.
|
|
110
|
-
* Paths are relative (no /proc prefix).
|
|
111
|
-
*/
|
|
112
|
-
export function resolveProcSelfPath(path, pid) {
|
|
113
|
-
if (path === "self")
|
|
114
|
-
return `${pid}`;
|
|
115
|
-
if (path.startsWith("self/"))
|
|
116
|
-
return `${pid}${path.slice(4)}`;
|
|
117
|
-
return path;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Parse a relative proc path into PID + tail components.
|
|
121
|
-
* "1/fd/0" -> { pid: 1, tail: ["fd", "0"] }
|
|
122
|
-
*/
|
|
123
|
-
function parsePidPath(path) {
|
|
124
|
-
const parts = path.split("/");
|
|
125
|
-
const pid = Number(parts[0]);
|
|
126
|
-
if (!Number.isInteger(pid) || pid < 0)
|
|
127
|
-
return null;
|
|
128
|
-
return { pid, tail: parts.slice(1) };
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Format mount entries in Linux /proc/mounts format.
|
|
132
|
-
*/
|
|
133
|
-
function formatMounts(mounts) {
|
|
134
|
-
return mounts
|
|
135
|
-
.map((m) => {
|
|
136
|
-
const fsType = m.path === "/" ? "rootfs" : "mount";
|
|
137
|
-
const opts = m.readOnly ? "ro" : "rw";
|
|
138
|
-
return `${fsType} ${m.path} ${fsType} ${opts} 0 0`;
|
|
139
|
-
})
|
|
140
|
-
.join("\n")
|
|
141
|
-
.concat("\n");
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Create a standalone proc backend VFS.
|
|
145
|
-
* All paths are relative to /proc (e.g. "self/fd", "1/environ", "mounts").
|
|
146
|
-
* Mount at /proc via MountTable.
|
|
147
|
-
*/
|
|
148
|
-
export function createProcBackend(options) {
|
|
149
|
-
const kernelHostname = encodeText(`${options.hostname ?? "sandbox"}\n`);
|
|
150
|
-
const getProcess = (pid) => {
|
|
151
|
-
const entry = options.processTable.get(pid);
|
|
152
|
-
if (!entry)
|
|
153
|
-
throw new KernelError("ENOENT", `no such process ${pid}`);
|
|
154
|
-
return entry;
|
|
155
|
-
};
|
|
156
|
-
const listPids = () => Array.from(options.processTable.listProcesses().keys()).sort((a, b) => a - b);
|
|
157
|
-
const listOpenFds = (pid) => {
|
|
158
|
-
const table = options.fdTableManager.get(pid);
|
|
159
|
-
if (!table)
|
|
160
|
-
return [];
|
|
161
|
-
const fds = [];
|
|
162
|
-
for (const entry of table)
|
|
163
|
-
fds.push(entry.fd);
|
|
164
|
-
return fds.sort((a, b) => a - b);
|
|
165
|
-
};
|
|
166
|
-
const getFdEntry = (pid, fd) => {
|
|
167
|
-
const table = options.fdTableManager.get(pid);
|
|
168
|
-
const entry = table?.get(fd);
|
|
169
|
-
if (!entry)
|
|
170
|
-
throw new KernelError("ENOENT", `no such fd ${fd} for process ${pid}`);
|
|
171
|
-
return entry;
|
|
172
|
-
};
|
|
173
|
-
const getLinkTarget = (pid, tail) => {
|
|
174
|
-
if (tail.length === 1 && tail[0] === "cwd")
|
|
175
|
-
return getProcess(pid).cwd;
|
|
176
|
-
if (tail.length === 1 && tail[0] === "exe")
|
|
177
|
-
return resolveExecPath(getProcess(pid).command);
|
|
178
|
-
if (tail.length === 2 && tail[0] === "fd") {
|
|
179
|
-
const fd = Number(tail[1]);
|
|
180
|
-
if (!Number.isInteger(fd) || fd < 0)
|
|
181
|
-
throw new KernelError("ENOENT", `invalid fd ${tail[1]}`);
|
|
182
|
-
return getFdEntry(pid, fd).description.path;
|
|
183
|
-
}
|
|
184
|
-
throw new KernelError("ENOENT", `unsupported proc link ${tail.join("/")}`);
|
|
185
|
-
};
|
|
186
|
-
const getProcFile = (pid, tail) => {
|
|
187
|
-
if (tail.length === 1 && tail[0] === "cwd")
|
|
188
|
-
return encodeText(getProcess(pid).cwd);
|
|
189
|
-
if (tail.length === 1 && tail[0] === "exe")
|
|
190
|
-
return encodeText(resolveExecPath(getProcess(pid).command));
|
|
191
|
-
if (tail.length === 1 && tail[0] === "environ")
|
|
192
|
-
return encodeEnviron(getProcess(pid).env);
|
|
193
|
-
if (tail.length === 2 && tail[0] === "fd")
|
|
194
|
-
return encodeText(getLinkTarget(pid, tail));
|
|
195
|
-
throw new KernelError("ENOENT", `unsupported proc file ${tail.join("/")}`);
|
|
196
|
-
};
|
|
197
|
-
const getMountsContent = () => {
|
|
198
|
-
if (!options.mountTable) {
|
|
199
|
-
return encodeText("rootfs / rootfs rw 0 0\n");
|
|
200
|
-
}
|
|
201
|
-
return encodeText(formatMounts(options.mountTable.getMounts()));
|
|
202
|
-
};
|
|
203
|
-
const getProcStat = (path, followSymlinks) => {
|
|
204
|
-
// Root /proc directory
|
|
205
|
-
if (path === "")
|
|
206
|
-
return dirStat("proc");
|
|
207
|
-
// /proc/self symlink
|
|
208
|
-
if (path === "self") {
|
|
209
|
-
return followSymlinks
|
|
210
|
-
? dirStat("proc-self")
|
|
211
|
-
: linkStat("proc-self-link", "self");
|
|
212
|
-
}
|
|
213
|
-
// /proc/mounts
|
|
214
|
-
if (path === "mounts") {
|
|
215
|
-
const content = getMountsContent();
|
|
216
|
-
return fileStat("proc:mounts", content.length);
|
|
217
|
-
}
|
|
218
|
-
// /proc/sys tree
|
|
219
|
-
if (path === "sys")
|
|
220
|
-
return dirStat("proc:sys");
|
|
221
|
-
if (path === "sys/kernel")
|
|
222
|
-
return dirStat("proc:sys:kernel");
|
|
223
|
-
if (path === "sys/kernel/hostname") {
|
|
224
|
-
return fileStat("proc:sys:kernel:hostname", kernelHostname.length);
|
|
225
|
-
}
|
|
226
|
-
// /proc/[pid]/...
|
|
227
|
-
const parsed = parsePidPath(path);
|
|
228
|
-
if (!parsed)
|
|
229
|
-
notFound(path);
|
|
230
|
-
const { pid, tail } = parsed;
|
|
231
|
-
getProcess(pid);
|
|
232
|
-
if (tail.length === 0)
|
|
233
|
-
return dirStat(`proc:${pid}`);
|
|
234
|
-
if (tail.length === 1 && tail[0] === "fd")
|
|
235
|
-
return dirStat(`proc:${pid}:fd`);
|
|
236
|
-
if (tail.length === 1 && tail[0] === "environ") {
|
|
237
|
-
return fileStat(`proc:${pid}:environ`, encodeEnviron(getProcess(pid).env).length);
|
|
238
|
-
}
|
|
239
|
-
if ((tail.length === 1 && (tail[0] === "cwd" || tail[0] === "exe")) ||
|
|
240
|
-
(tail.length === 2 && tail[0] === "fd")) {
|
|
241
|
-
const target = getLinkTarget(pid, tail);
|
|
242
|
-
if (!followSymlinks)
|
|
243
|
-
return linkStat(`proc:${pid}:${tail.join(":")}`, target);
|
|
244
|
-
// For symlinks when following, return file stat for the target
|
|
245
|
-
return linkStat(`proc:${pid}:${tail.join(":")}`, target);
|
|
246
|
-
}
|
|
247
|
-
notFound(path);
|
|
248
|
-
};
|
|
249
|
-
const backend = {
|
|
250
|
-
async readFile(path) {
|
|
251
|
-
// Directories
|
|
252
|
-
if (path === "" ||
|
|
253
|
-
path === "self" ||
|
|
254
|
-
path === "sys" ||
|
|
255
|
-
path === "sys/kernel") {
|
|
256
|
-
throw new KernelError("EISDIR", `illegal operation on a directory, read '/proc/${path}'`);
|
|
257
|
-
}
|
|
258
|
-
// /proc/mounts
|
|
259
|
-
if (path === "mounts")
|
|
260
|
-
return getMountsContent();
|
|
261
|
-
// /proc/sys/kernel/hostname
|
|
262
|
-
if (path === "sys/kernel/hostname")
|
|
263
|
-
return kernelHostname;
|
|
264
|
-
// /proc/[pid]/...
|
|
265
|
-
const parsed = parsePidPath(path);
|
|
266
|
-
if (!parsed)
|
|
267
|
-
notFound(path);
|
|
268
|
-
const { pid, tail } = parsed;
|
|
269
|
-
if (tail.length === 0 || (tail.length === 1 && tail[0] === "fd")) {
|
|
270
|
-
throw new KernelError("EISDIR", `illegal operation on a directory, read '/proc/${path}'`);
|
|
271
|
-
}
|
|
272
|
-
return getProcFile(pid, tail);
|
|
273
|
-
},
|
|
274
|
-
async pread(path, offset, length) {
|
|
275
|
-
const content = await this.readFile(path);
|
|
276
|
-
if (offset >= content.length)
|
|
277
|
-
return new Uint8Array(0);
|
|
278
|
-
return content.slice(offset, offset + length);
|
|
279
|
-
},
|
|
280
|
-
async readTextFile(path) {
|
|
281
|
-
const content = await this.readFile(path);
|
|
282
|
-
return new TextDecoder().decode(content);
|
|
283
|
-
},
|
|
284
|
-
async readDir(path) {
|
|
285
|
-
return (await this.readDirWithTypes(path)).map((entry) => entry.name);
|
|
286
|
-
},
|
|
287
|
-
async readDirWithTypes(path) {
|
|
288
|
-
if (path === "") {
|
|
289
|
-
return [
|
|
290
|
-
...PROC_ROOT_ENTRIES,
|
|
291
|
-
...listPids().map((pid) => ({
|
|
292
|
-
name: String(pid),
|
|
293
|
-
isDirectory: true,
|
|
294
|
-
})),
|
|
295
|
-
];
|
|
296
|
-
}
|
|
297
|
-
if (path === "sys")
|
|
298
|
-
return PROC_SYS_ENTRIES;
|
|
299
|
-
if (path === "sys/kernel")
|
|
300
|
-
return PROC_SYS_KERNEL_ENTRIES;
|
|
301
|
-
if (path === "self") {
|
|
302
|
-
throw new KernelError("ENOENT", `no such file or directory: /proc/${path}`);
|
|
303
|
-
}
|
|
304
|
-
const parsed = parsePidPath(path);
|
|
305
|
-
if (!parsed)
|
|
306
|
-
throw new KernelError("ENOENT", `no such file or directory: /proc/${path}`);
|
|
307
|
-
const { pid, tail } = parsed;
|
|
308
|
-
getProcess(pid);
|
|
309
|
-
if (tail.length === 0)
|
|
310
|
-
return PROC_PID_ENTRIES;
|
|
311
|
-
if (tail.length === 1 && tail[0] === "fd") {
|
|
312
|
-
return listOpenFds(pid).map((fd) => ({
|
|
313
|
-
name: String(fd),
|
|
314
|
-
isDirectory: false,
|
|
315
|
-
isSymbolicLink: true,
|
|
316
|
-
}));
|
|
317
|
-
}
|
|
318
|
-
throw new KernelError("ENOTDIR", `not a directory: /proc/${path}`);
|
|
319
|
-
},
|
|
320
|
-
async writeFile(path, _content) {
|
|
321
|
-
rejectWrite(path);
|
|
322
|
-
},
|
|
323
|
-
async createDir(path) {
|
|
324
|
-
rejectWrite(path);
|
|
325
|
-
},
|
|
326
|
-
async mkdir(path, _options) {
|
|
327
|
-
rejectWrite(path);
|
|
328
|
-
},
|
|
329
|
-
async exists(path) {
|
|
330
|
-
if (path === "" || path === "self" || path === "mounts")
|
|
331
|
-
return true;
|
|
332
|
-
if (path === "sys" ||
|
|
333
|
-
path === "sys/kernel" ||
|
|
334
|
-
path === "sys/kernel/hostname") {
|
|
335
|
-
return true;
|
|
336
|
-
}
|
|
337
|
-
const parsed = parsePidPath(path);
|
|
338
|
-
if (!parsed)
|
|
339
|
-
return false;
|
|
340
|
-
const { pid, tail } = parsed;
|
|
341
|
-
if (!options.processTable.get(pid))
|
|
342
|
-
return false;
|
|
343
|
-
if (tail.length === 0 || (tail.length === 1 && tail[0] === "fd"))
|
|
344
|
-
return true;
|
|
345
|
-
if (tail.length === 1 &&
|
|
346
|
-
(tail[0] === "cwd" || tail[0] === "exe" || tail[0] === "environ"))
|
|
347
|
-
return true;
|
|
348
|
-
if (tail.length === 2 && tail[0] === "fd") {
|
|
349
|
-
const fd = Number(tail[1]);
|
|
350
|
-
return (Number.isInteger(fd) &&
|
|
351
|
-
fd >= 0 &&
|
|
352
|
-
options.fdTableManager.get(pid)?.get(fd) !== undefined);
|
|
353
|
-
}
|
|
354
|
-
return false;
|
|
355
|
-
},
|
|
356
|
-
async stat(path) {
|
|
357
|
-
return getProcStat(path, true);
|
|
358
|
-
},
|
|
359
|
-
async removeFile(path) {
|
|
360
|
-
rejectWrite(path);
|
|
361
|
-
},
|
|
362
|
-
async removeDir(path) {
|
|
363
|
-
rejectWrite(path);
|
|
364
|
-
},
|
|
365
|
-
async rename(_oldPath, _newPath) {
|
|
366
|
-
throw new KernelError("EPERM", "cannot rename in /proc");
|
|
367
|
-
},
|
|
368
|
-
async realpath(path) {
|
|
369
|
-
if (path === "" || path === "mounts")
|
|
370
|
-
return path;
|
|
371
|
-
if (path === "self")
|
|
372
|
-
return path;
|
|
373
|
-
if (path === "sys" ||
|
|
374
|
-
path === "sys/kernel" ||
|
|
375
|
-
path === "sys/kernel/hostname") {
|
|
376
|
-
return path;
|
|
377
|
-
}
|
|
378
|
-
const parsed = parsePidPath(path);
|
|
379
|
-
if (!parsed)
|
|
380
|
-
notFound(path);
|
|
381
|
-
const { pid, tail } = parsed;
|
|
382
|
-
getProcess(pid);
|
|
383
|
-
if (tail.length === 0 || (tail.length === 1 && tail[0] === "fd"))
|
|
384
|
-
return path;
|
|
385
|
-
if (tail.length === 1 && tail[0] === "environ")
|
|
386
|
-
return path;
|
|
387
|
-
if ((tail.length === 1 && (tail[0] === "cwd" || tail[0] === "exe")) ||
|
|
388
|
-
(tail.length === 2 && tail[0] === "fd")) {
|
|
389
|
-
return getLinkTarget(pid, tail);
|
|
390
|
-
}
|
|
391
|
-
notFound(path);
|
|
392
|
-
},
|
|
393
|
-
async symlink(_target, _linkPath) {
|
|
394
|
-
throw new KernelError("EPERM", "cannot create symlink in /proc");
|
|
395
|
-
},
|
|
396
|
-
async readlink(path) {
|
|
397
|
-
if (path === "self")
|
|
398
|
-
return "self";
|
|
399
|
-
const parsed = parsePidPath(path);
|
|
400
|
-
if (!parsed)
|
|
401
|
-
throw new KernelError("EINVAL", `invalid argument: /proc/${path}`);
|
|
402
|
-
const { pid, tail } = parsed;
|
|
403
|
-
return getLinkTarget(pid, tail);
|
|
404
|
-
},
|
|
405
|
-
async lstat(path) {
|
|
406
|
-
return getProcStat(path, false);
|
|
407
|
-
},
|
|
408
|
-
async link(_oldPath, _newPath) {
|
|
409
|
-
throw new KernelError("EPERM", "cannot link in /proc");
|
|
410
|
-
},
|
|
411
|
-
async chmod(path, _mode) {
|
|
412
|
-
rejectWrite(path);
|
|
413
|
-
},
|
|
414
|
-
async chown(path, _uid, _gid) {
|
|
415
|
-
rejectWrite(path);
|
|
416
|
-
},
|
|
417
|
-
async utimes(path, _atime, _mtime) {
|
|
418
|
-
rejectWrite(path);
|
|
419
|
-
},
|
|
420
|
-
async truncate(path, _length) {
|
|
421
|
-
rejectWrite(path);
|
|
422
|
-
},
|
|
423
|
-
async pwrite(path, _offset, _data) {
|
|
424
|
-
rejectWrite(path);
|
|
425
|
-
},
|
|
426
|
-
};
|
|
427
|
-
return backend;
|
|
428
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { FDTableManager } from "./fd-table.js";
|
|
2
|
-
import type { ProcessTable } from "./process-table.js";
|
|
3
|
-
import type { VirtualFileSystem } from "./vfs.js";
|
|
4
|
-
export interface ProcLayerOptions {
|
|
5
|
-
processTable: ProcessTable;
|
|
6
|
-
fdTableManager: FDTableManager;
|
|
7
|
-
hostname?: string;
|
|
8
|
-
}
|
|
9
|
-
export declare function resolveProcSelfPath(path: string, pid: number): string;
|
|
10
|
-
export declare function createProcessScopedFileSystem(vfs: VirtualFileSystem, pid: number): VirtualFileSystem;
|
|
11
|
-
export declare function createProcLayer(vfs: VirtualFileSystem, options: ProcLayerOptions): VirtualFileSystem;
|