@secure-exec/wasmvm 0.2.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.
Files changed (70) hide show
  1. package/LICENSE +191 -0
  2. package/dist/browser-driver.d.ts +68 -0
  3. package/dist/browser-driver.d.ts.map +1 -0
  4. package/dist/browser-driver.js +293 -0
  5. package/dist/browser-driver.js.map +1 -0
  6. package/dist/driver.d.ts +43 -0
  7. package/dist/driver.d.ts.map +1 -0
  8. package/dist/driver.js +1420 -0
  9. package/dist/driver.js.map +1 -0
  10. package/dist/fd-table.d.ts +67 -0
  11. package/dist/fd-table.d.ts.map +1 -0
  12. package/dist/fd-table.js +171 -0
  13. package/dist/fd-table.js.map +1 -0
  14. package/dist/index.d.ts +26 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +19 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/kernel-worker.d.ts +14 -0
  19. package/dist/kernel-worker.d.ts.map +1 -0
  20. package/dist/kernel-worker.js +1205 -0
  21. package/dist/kernel-worker.js.map +1 -0
  22. package/dist/module-cache.d.ts +21 -0
  23. package/dist/module-cache.d.ts.map +1 -0
  24. package/dist/module-cache.js +51 -0
  25. package/dist/module-cache.js.map +1 -0
  26. package/dist/permission-check.d.ts +36 -0
  27. package/dist/permission-check.d.ts.map +1 -0
  28. package/dist/permission-check.js +84 -0
  29. package/dist/permission-check.js.map +1 -0
  30. package/dist/ring-buffer.d.ts +64 -0
  31. package/dist/ring-buffer.d.ts.map +1 -0
  32. package/dist/ring-buffer.js +160 -0
  33. package/dist/ring-buffer.js.map +1 -0
  34. package/dist/syscall-rpc.d.ts +95 -0
  35. package/dist/syscall-rpc.d.ts.map +1 -0
  36. package/dist/syscall-rpc.js +48 -0
  37. package/dist/syscall-rpc.js.map +1 -0
  38. package/dist/user.d.ts +58 -0
  39. package/dist/user.d.ts.map +1 -0
  40. package/dist/user.js +143 -0
  41. package/dist/user.js.map +1 -0
  42. package/dist/wasi-constants.d.ts +77 -0
  43. package/dist/wasi-constants.d.ts.map +1 -0
  44. package/dist/wasi-constants.js +122 -0
  45. package/dist/wasi-constants.js.map +1 -0
  46. package/dist/wasi-file-io.d.ts +50 -0
  47. package/dist/wasi-file-io.d.ts.map +1 -0
  48. package/dist/wasi-file-io.js +10 -0
  49. package/dist/wasi-file-io.js.map +1 -0
  50. package/dist/wasi-polyfill.d.ts +368 -0
  51. package/dist/wasi-polyfill.d.ts.map +1 -0
  52. package/dist/wasi-polyfill.js +1438 -0
  53. package/dist/wasi-polyfill.js.map +1 -0
  54. package/dist/wasi-process-io.d.ts +35 -0
  55. package/dist/wasi-process-io.d.ts.map +1 -0
  56. package/dist/wasi-process-io.js +11 -0
  57. package/dist/wasi-process-io.js.map +1 -0
  58. package/dist/wasi-types.d.ts +175 -0
  59. package/dist/wasi-types.d.ts.map +1 -0
  60. package/dist/wasi-types.js +68 -0
  61. package/dist/wasi-types.js.map +1 -0
  62. package/dist/wasm-magic.d.ts +12 -0
  63. package/dist/wasm-magic.d.ts.map +1 -0
  64. package/dist/wasm-magic.js +53 -0
  65. package/dist/wasm-magic.js.map +1 -0
  66. package/dist/worker-adapter.d.ts +32 -0
  67. package/dist/worker-adapter.d.ts.map +1 -0
  68. package/dist/worker-adapter.js +147 -0
  69. package/dist/worker-adapter.js.map +1 -0
  70. package/package.json +35 -0
@@ -0,0 +1,95 @@
1
+ /**
2
+ * SharedArrayBuffer-based RPC protocol for worker ↔ main-thread syscalls.
3
+ *
4
+ * Workers run synchronous WASI code but the kernel's FD/VFS operations
5
+ * are async. The RPC protocol bridges this gap:
6
+ * 1. Worker posts a syscall request via postMessage
7
+ * 2. Worker blocks via Atomics.wait on the signal buffer
8
+ * 3. Main thread handles the request, writes response to shared buffers
9
+ * 4. Main thread signals via Atomics.notify
10
+ * 5. Worker reads response and continues
11
+ */
12
+ export declare const SIG_IDX_STATE = 0;
13
+ export declare const SIG_IDX_ERRNO = 1;
14
+ export declare const SIG_IDX_INT_RESULT = 2;
15
+ export declare const SIG_IDX_DATA_LEN = 3;
16
+ export declare const SIG_IDX_PENDING_SIGNAL = 4;
17
+ export declare const SIG_STATE_IDLE = 0;
18
+ export declare const SIG_STATE_READY = 1;
19
+ export declare const SIGNAL_BUFFER_BYTES: number;
20
+ export declare const DATA_BUFFER_BYTES: number;
21
+ /** Wait timeout per Atomics.wait attempt (ms). */
22
+ export declare const RPC_WAIT_TIMEOUT_MS = 30000;
23
+ export declare const SYSCALL_FD_READ = "fdRead";
24
+ export declare const SYSCALL_FD_WRITE = "fdWrite";
25
+ export declare const SYSCALL_FD_OPEN = "fdOpen";
26
+ export declare const SYSCALL_FD_SEEK = "fdSeek";
27
+ export declare const SYSCALL_FD_CLOSE = "fdClose";
28
+ export declare const SYSCALL_FD_PREAD = "fdPread";
29
+ export declare const SYSCALL_FD_PWRITE = "fdPwrite";
30
+ export declare const SYSCALL_FD_STAT = "fdStat";
31
+ export declare const SYSCALL_SPAWN = "spawn";
32
+ export declare const SYSCALL_WAITPID = "waitpid";
33
+ export declare const SYSCALL_VFS_STAT = "vfsStat";
34
+ export declare const SYSCALL_VFS_READDIR = "vfsReaddir";
35
+ export declare const SYSCALL_VFS_MKDIR = "vfsMkdir";
36
+ export declare const SYSCALL_VFS_UNLINK = "vfsUnlink";
37
+ export declare const SYSCALL_VFS_RMDIR = "vfsRmdir";
38
+ export declare const SYSCALL_VFS_RENAME = "vfsRename";
39
+ export declare const SYSCALL_VFS_SYMLINK = "vfsSymlink";
40
+ export declare const SYSCALL_VFS_READLINK = "vfsReadlink";
41
+ export declare const SYSCALL_VFS_READ_FILE = "vfsReadFile";
42
+ export declare const SYSCALL_VFS_WRITE_FILE = "vfsWriteFile";
43
+ export declare const SYSCALL_VFS_EXISTS = "vfsExists";
44
+ export declare const SYSCALL_VFS_CHMOD = "vfsChmod";
45
+ export declare const SYSCALL_VFS_REALPATH = "vfsRealpath";
46
+ export interface SyscallRequest {
47
+ type: 'syscall';
48
+ call: string;
49
+ args: Record<string, unknown>;
50
+ }
51
+ export interface StdoutMessage {
52
+ type: 'stdout';
53
+ data: Uint8Array;
54
+ }
55
+ export interface StderrMessage {
56
+ type: 'stderr';
57
+ data: Uint8Array;
58
+ }
59
+ export interface ExitMessage {
60
+ type: 'exit';
61
+ code: number;
62
+ }
63
+ export interface ReadyMessage {
64
+ type: 'ready';
65
+ }
66
+ export type WorkerMessage = SyscallRequest | StdoutMessage | StderrMessage | ExitMessage | ReadyMessage;
67
+ export interface StartMessage {
68
+ type: 'start';
69
+ }
70
+ /** Permission tier controlling what a command can access. */
71
+ export type PermissionTier = 'full' | 'read-write' | 'read-only' | 'isolated';
72
+ export interface WorkerInitData {
73
+ wasmBinaryPath: string;
74
+ command: string;
75
+ args: string[];
76
+ pid: number;
77
+ ppid: number;
78
+ env: Record<string, string>;
79
+ cwd: string;
80
+ signalBuf: SharedArrayBuffer;
81
+ dataBuf: SharedArrayBuffer;
82
+ /** FD override for stdin (pipe read end in parent's table, or undefined). */
83
+ stdinFd?: number;
84
+ /** FD override for stdout (pipe write end in parent's table, or undefined). */
85
+ stdoutFd?: number;
86
+ /** FD override for stderr (pipe write end in parent's table, or undefined). */
87
+ stderrFd?: number;
88
+ /** Which stdio FDs are TTYs (for brush-shell interactive mode detection). */
89
+ ttyFds?: number[];
90
+ /** Pre-compiled WebAssembly.Module from main thread's ModuleCache (transferable via structured clone). */
91
+ wasmModule?: WebAssembly.Module;
92
+ /** Permission tier for this command (default: 'read-write'). */
93
+ permissionTier?: PermissionTier;
94
+ }
95
+ //# sourceMappingURL=syscall-rpc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syscall-rpc.d.ts","sourceRoot":"","sources":["../src/syscall-rpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,eAAO,MAAM,aAAa,IAAI,CAAC;AAC/B,eAAO,MAAM,aAAa,IAAI,CAAC;AAC/B,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,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0G;IAC1G,UAAU,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC;IAChC,gEAAgE;IAChE,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * SharedArrayBuffer-based RPC protocol for worker ↔ main-thread syscalls.
3
+ *
4
+ * Workers run synchronous WASI code but the kernel's FD/VFS operations
5
+ * are async. The RPC protocol bridges this gap:
6
+ * 1. Worker posts a syscall request via postMessage
7
+ * 2. Worker blocks via Atomics.wait on the signal buffer
8
+ * 3. Main thread handles the request, writes response to shared buffers
9
+ * 4. Main thread signals via Atomics.notify
10
+ * 5. Worker reads response and continues
11
+ */
12
+ // Signal buffer layout (Int32Array over SharedArrayBuffer, 5 slots)
13
+ export const SIG_IDX_STATE = 0; // 0=idle, 1=response-ready
14
+ export const SIG_IDX_ERRNO = 1; // errno from kernel call
15
+ export const SIG_IDX_INT_RESULT = 2; // integer result (fd, written bytes, etc.)
16
+ export const SIG_IDX_DATA_LEN = 3; // length of response data in data buffer
17
+ export const SIG_IDX_PENDING_SIGNAL = 4; // pending signal for cooperative delivery (0=none)
18
+ export const SIG_STATE_IDLE = 0;
19
+ export const SIG_STATE_READY = 1;
20
+ export const SIGNAL_BUFFER_BYTES = 5 * Int32Array.BYTES_PER_ELEMENT;
21
+ export const DATA_BUFFER_BYTES = 1024 * 1024; // 1MB response data buffer
22
+ /** Wait timeout per Atomics.wait attempt (ms). */
23
+ export const RPC_WAIT_TIMEOUT_MS = 30_000;
24
+ // Syscall IDs — used in postMessage to identify the call
25
+ export const SYSCALL_FD_READ = 'fdRead';
26
+ export const SYSCALL_FD_WRITE = 'fdWrite';
27
+ export const SYSCALL_FD_OPEN = 'fdOpen';
28
+ export const SYSCALL_FD_SEEK = 'fdSeek';
29
+ export const SYSCALL_FD_CLOSE = 'fdClose';
30
+ export const SYSCALL_FD_PREAD = 'fdPread';
31
+ export const SYSCALL_FD_PWRITE = 'fdPwrite';
32
+ export const SYSCALL_FD_STAT = 'fdStat';
33
+ export const SYSCALL_SPAWN = 'spawn';
34
+ export const SYSCALL_WAITPID = 'waitpid';
35
+ export const SYSCALL_VFS_STAT = 'vfsStat';
36
+ export const SYSCALL_VFS_READDIR = 'vfsReaddir';
37
+ export const SYSCALL_VFS_MKDIR = 'vfsMkdir';
38
+ export const SYSCALL_VFS_UNLINK = 'vfsUnlink';
39
+ export const SYSCALL_VFS_RMDIR = 'vfsRmdir';
40
+ export const SYSCALL_VFS_RENAME = 'vfsRename';
41
+ export const SYSCALL_VFS_SYMLINK = 'vfsSymlink';
42
+ export const SYSCALL_VFS_READLINK = 'vfsReadlink';
43
+ export const SYSCALL_VFS_READ_FILE = 'vfsReadFile';
44
+ export const SYSCALL_VFS_WRITE_FILE = 'vfsWriteFile';
45
+ export const SYSCALL_VFS_EXISTS = 'vfsExists';
46
+ export const SYSCALL_VFS_CHMOD = 'vfsChmod';
47
+ export const SYSCALL_VFS_REALPATH = 'vfsRealpath';
48
+ //# sourceMappingURL=syscall-rpc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syscall-rpc.js","sourceRoot":"","sources":["../src/syscall-rpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,oEAAoE;AACpE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,CAAI,2BAA2B;AAC9D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,CAAI,yBAAyB;AAC5D,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,CAAC,2CAA2C;AAChF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,CAAE,yCAAyC;AAC7E,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,CAAC,mDAAmD;AAE5F,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAChC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC;AAEjC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,G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B,GAAG,WAAW,CAAC;AAC9C,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC;AAC5C,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAC"}
package/dist/user.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * JS host_user syscall implementations.
3
+ *
4
+ * Provides configurable user/group identity and terminal detection
5
+ * for the WASM module via the host_user import functions:
6
+ * getuid, getgid, geteuid, getegid, isatty, getpwuid.
7
+ */
8
+ import type { WasiFDTable } from './wasi-types.js';
9
+ export interface UserManagerOptions {
10
+ getMemory: () => WebAssembly.Memory | null;
11
+ fdTable?: WasiFDTable;
12
+ uid?: number;
13
+ gid?: number;
14
+ euid?: number;
15
+ egid?: number;
16
+ username?: string;
17
+ homedir?: string;
18
+ shell?: string;
19
+ gecos?: string;
20
+ ttyFds?: Set<number> | boolean;
21
+ }
22
+ export interface HostUserImports {
23
+ getuid: (ret_uid: number) => number;
24
+ getgid: (ret_gid: number) => number;
25
+ geteuid: (ret_uid: number) => number;
26
+ getegid: (ret_gid: number) => number;
27
+ isatty: (fd: number, ret_bool: number) => number;
28
+ getpwuid: (uid: number, buf_ptr: number, buf_len: number, ret_len: number) => number;
29
+ }
30
+ /**
31
+ * Manages user/group identity and terminal detection for WASM processes.
32
+ */
33
+ export declare class UserManager {
34
+ private _getMemory;
35
+ private _fdTable;
36
+ private _uid;
37
+ private _gid;
38
+ private _euid;
39
+ private _egid;
40
+ private _username;
41
+ private _homedir;
42
+ private _shell;
43
+ private _gecos;
44
+ private _ttyFds;
45
+ constructor(options: UserManagerOptions);
46
+ /**
47
+ * Get the WASI import object for host_user functions.
48
+ * All functions follow the wasi-ext signatures (return errno, out-params via pointers).
49
+ */
50
+ getImports(): HostUserImports;
51
+ private _getuid;
52
+ private _getgid;
53
+ private _geteuid;
54
+ private _getegid;
55
+ private _isatty;
56
+ private _getpwuid;
57
+ }
58
+ //# sourceMappingURL=user.d.ts.map
@@ -0,0 +1 @@
1
+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B,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAc;gBAEjB,OAAO,EAAE,kBAAkB;IAsBvC;;;OAGG;IACH,UAAU,IAAI,eAAe;IAY7B,OAAO,CAAC,OAAO;IAOf,OAAO,CAAC,OAAO;IAOf,OAAO,CAAC,QAAQ;IAOhB,OAAO,CAAC,QAAQ;IAOhB,OAAO,CAAC,OAAO;IAyBf,OAAO,CAAC,SAAS;CA8BlB"}
package/dist/user.js ADDED
@@ -0,0 +1,143 @@
1
+ /**
2
+ * JS host_user syscall implementations.
3
+ *
4
+ * Provides configurable user/group identity and terminal detection
5
+ * for the WASM module via the host_user import functions:
6
+ * getuid, getgid, geteuid, getegid, isatty, getpwuid.
7
+ */
8
+ import { FILETYPE_CHARACTER_DEVICE } from './wasi-constants.js';
9
+ const ERRNO_SUCCESS = 0;
10
+ const ERRNO_EBADF = 8;
11
+ const ERRNO_ENOSYS = 52;
12
+ /**
13
+ * Manages user/group identity and terminal detection for WASM processes.
14
+ */
15
+ export class UserManager {
16
+ _getMemory;
17
+ _fdTable;
18
+ _uid;
19
+ _gid;
20
+ _euid;
21
+ _egid;
22
+ _username;
23
+ _homedir;
24
+ _shell;
25
+ _gecos;
26
+ _ttyFds;
27
+ constructor(options) {
28
+ this._getMemory = options.getMemory;
29
+ this._fdTable = options.fdTable || null;
30
+ this._uid = options.uid ?? 1000;
31
+ this._gid = options.gid ?? 1000;
32
+ this._euid = options.euid ?? this._uid;
33
+ this._egid = options.egid ?? this._gid;
34
+ this._username = options.username ?? 'user';
35
+ this._homedir = options.homedir ?? '/home/user';
36
+ this._shell = options.shell ?? '/bin/sh';
37
+ this._gecos = options.gecos ?? '';
38
+ // Configure which fds are TTYs
39
+ if (options.ttyFds === true) {
40
+ this._ttyFds = new Set([0, 1, 2]);
41
+ }
42
+ else if (options.ttyFds instanceof Set) {
43
+ this._ttyFds = options.ttyFds;
44
+ }
45
+ else {
46
+ this._ttyFds = new Set(); // default: nothing is a TTY
47
+ }
48
+ }
49
+ /**
50
+ * Get the WASI import object for host_user functions.
51
+ * All functions follow the wasi-ext signatures (return errno, out-params via pointers).
52
+ */
53
+ getImports() {
54
+ return {
55
+ getuid: (ret_uid) => this._getuid(ret_uid),
56
+ getgid: (ret_gid) => this._getgid(ret_gid),
57
+ geteuid: (ret_uid) => this._geteuid(ret_uid),
58
+ getegid: (ret_gid) => this._getegid(ret_gid),
59
+ isatty: (fd, ret_bool) => this._isatty(fd, ret_bool),
60
+ getpwuid: (uid, buf_ptr, buf_len, ret_len) => this._getpwuid(uid, buf_ptr, buf_len, ret_len),
61
+ };
62
+ }
63
+ _getuid(ret_uid) {
64
+ const mem = this._getMemory();
65
+ if (!mem)
66
+ return ERRNO_ENOSYS;
67
+ new DataView(mem.buffer).setUint32(ret_uid, this._uid, true);
68
+ return ERRNO_SUCCESS;
69
+ }
70
+ _getgid(ret_gid) {
71
+ const mem = this._getMemory();
72
+ if (!mem)
73
+ return ERRNO_ENOSYS;
74
+ new DataView(mem.buffer).setUint32(ret_gid, this._gid, true);
75
+ return ERRNO_SUCCESS;
76
+ }
77
+ _geteuid(ret_uid) {
78
+ const mem = this._getMemory();
79
+ if (!mem)
80
+ return ERRNO_ENOSYS;
81
+ new DataView(mem.buffer).setUint32(ret_uid, this._euid, true);
82
+ return ERRNO_SUCCESS;
83
+ }
84
+ _getegid(ret_gid) {
85
+ const mem = this._getMemory();
86
+ if (!mem)
87
+ return ERRNO_ENOSYS;
88
+ new DataView(mem.buffer).setUint32(ret_gid, this._egid, true);
89
+ return ERRNO_SUCCESS;
90
+ }
91
+ _isatty(fd, ret_bool) {
92
+ const mem = this._getMemory();
93
+ if (!mem)
94
+ return ERRNO_ENOSYS;
95
+ let isTty = 0;
96
+ if (this._fdTable) {
97
+ const entry = this._fdTable.get(fd);
98
+ if (!entry) {
99
+ new DataView(mem.buffer).setUint32(ret_bool, 0, true);
100
+ return ERRNO_EBADF;
101
+ }
102
+ // Only character devices can be TTYs
103
+ if (entry.filetype === FILETYPE_CHARACTER_DEVICE && this._ttyFds.has(fd)) {
104
+ isTty = 1;
105
+ }
106
+ }
107
+ else {
108
+ // No fdTable — just check ttyFds set
109
+ isTty = this._ttyFds.has(fd) ? 1 : 0;
110
+ }
111
+ new DataView(mem.buffer).setUint32(ret_bool, isTty, true);
112
+ return ERRNO_SUCCESS;
113
+ }
114
+ _getpwuid(uid, buf_ptr, buf_len, ret_len) {
115
+ const mem = this._getMemory();
116
+ if (!mem)
117
+ return ERRNO_ENOSYS;
118
+ // Build passwd string for the requested uid
119
+ let username, homedir, gecos, shell, gid;
120
+ if (uid === this._uid) {
121
+ username = this._username;
122
+ homedir = this._homedir;
123
+ gecos = this._gecos;
124
+ shell = this._shell;
125
+ gid = this._gid;
126
+ }
127
+ else {
128
+ // Generic entry for unknown uids
129
+ username = `user${uid}`;
130
+ homedir = `/home/${username}`;
131
+ gecos = '';
132
+ shell = '/bin/sh';
133
+ gid = uid; // assume gid == uid for unknown users
134
+ }
135
+ const passwd = `${username}:x:${uid}:${gid}:${gecos}:${homedir}:${shell}`;
136
+ const bytes = new TextEncoder().encode(passwd);
137
+ const len = Math.min(bytes.length, buf_len);
138
+ new Uint8Array(mem.buffer).set(bytes.subarray(0, len), buf_ptr);
139
+ new DataView(mem.buffer).setUint32(ret_len, len, true);
140
+ return ERRNO_SUCCESS;
141
+ }
142
+ }
143
+ //# sourceMappingURL=user.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.js","sourceRoot":"","sources":["../src/user.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAGhE,MAAM,aAAa,GAAG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;YAClB,GAAG,GAAG,GAAG,CAAC,CAAC,sCAAsC;QACnD,CAAC;QAED,MAAM,MAAM,GAAG,GAAG,QAAQ,MAAM,GAAG,IAAI,GAAG,IAAI,KAAK,IAAI,OAAO,IAAI,KAAK,EAAE,CAAC;QAC1E,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC/C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAE5C,IAAI,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;QAChE,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;QAEvD,OAAO,aAAa,CAAC;IACvB,CAAC;CACF"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * WASI protocol constants.
3
+ *
4
+ * All constants from the wasi_snapshot_preview1 specification:
5
+ * file types, fd flags, rights bitmasks, errno codes.
6
+ */
7
+ export declare const FILETYPE_UNKNOWN: 0;
8
+ export declare const FILETYPE_BLOCK_DEVICE: 1;
9
+ export declare const FILETYPE_CHARACTER_DEVICE: 2;
10
+ export declare const FILETYPE_DIRECTORY: 3;
11
+ export declare const FILETYPE_REGULAR_FILE: 4;
12
+ export declare const FILETYPE_SOCKET_DGRAM: 5;
13
+ export declare const FILETYPE_SOCKET_STREAM: 6;
14
+ export declare const FILETYPE_SYMBOLIC_LINK: 7;
15
+ export type WasiFiletype = typeof FILETYPE_UNKNOWN | typeof FILETYPE_BLOCK_DEVICE | typeof FILETYPE_CHARACTER_DEVICE | typeof FILETYPE_DIRECTORY | typeof FILETYPE_REGULAR_FILE | typeof FILETYPE_SOCKET_DGRAM | typeof FILETYPE_SOCKET_STREAM | typeof FILETYPE_SYMBOLIC_LINK;
16
+ export declare const FDFLAG_APPEND: number;
17
+ export declare const FDFLAG_DSYNC: number;
18
+ export declare const FDFLAG_NONBLOCK: number;
19
+ export declare const FDFLAG_RSYNC: number;
20
+ export declare const FDFLAG_SYNC: number;
21
+ export declare const RIGHT_FD_DATASYNC: bigint;
22
+ export declare const RIGHT_FD_READ: bigint;
23
+ export declare const RIGHT_FD_SEEK: bigint;
24
+ export declare const RIGHT_FD_FDSTAT_SET_FLAGS: bigint;
25
+ export declare const RIGHT_FD_SYNC: bigint;
26
+ export declare const RIGHT_FD_TELL: bigint;
27
+ export declare const RIGHT_FD_WRITE: bigint;
28
+ export declare const RIGHT_FD_ADVISE: bigint;
29
+ export declare const RIGHT_FD_ALLOCATE: bigint;
30
+ export declare const RIGHT_PATH_CREATE_DIRECTORY: bigint;
31
+ export declare const RIGHT_PATH_CREATE_FILE: bigint;
32
+ export declare const RIGHT_PATH_LINK_SOURCE: bigint;
33
+ export declare const RIGHT_PATH_LINK_TARGET: bigint;
34
+ export declare const RIGHT_PATH_OPEN: bigint;
35
+ export declare const RIGHT_FD_READDIR: bigint;
36
+ export declare const RIGHT_PATH_READLINK: bigint;
37
+ export declare const RIGHT_PATH_RENAME_SOURCE: bigint;
38
+ export declare const RIGHT_PATH_RENAME_TARGET: bigint;
39
+ export declare const RIGHT_PATH_FILESTAT_GET: bigint;
40
+ export declare const RIGHT_PATH_FILESTAT_SET_SIZE: bigint;
41
+ export declare const RIGHT_PATH_FILESTAT_SET_TIMES: bigint;
42
+ export declare const RIGHT_FD_FILESTAT_GET: bigint;
43
+ export declare const RIGHT_FD_FILESTAT_SET_SIZE: bigint;
44
+ export declare const RIGHT_FD_FILESTAT_SET_TIMES: bigint;
45
+ export declare const RIGHT_PATH_SYMLINK: bigint;
46
+ export declare const RIGHT_PATH_REMOVE_DIRECTORY: bigint;
47
+ export declare const RIGHT_PATH_UNLINK_FILE: bigint;
48
+ export declare const RIGHT_POLL_FD_READWRITE: bigint;
49
+ export declare const RIGHT_SOCK_SHUTDOWN: bigint;
50
+ export declare const RIGHT_SOCK_ACCEPT: bigint;
51
+ export declare const RIGHTS_STDIO: bigint;
52
+ export declare const RIGHTS_FILE_ALL: bigint;
53
+ export declare const RIGHTS_DIR_ALL: bigint;
54
+ export declare const ERRNO_SUCCESS = 0;
55
+ export declare const ERRNO_EADDRINUSE = 3;
56
+ export declare const ERRNO_EACCES = 2;
57
+ export declare const ERRNO_EAGAIN = 6;
58
+ export declare const ERRNO_EBADF = 8;
59
+ export declare const ERRNO_ECHILD = 10;
60
+ export declare const ERRNO_ECONNREFUSED = 14;
61
+ export declare const ERRNO_EEXIST = 20;
62
+ export declare const ERRNO_EINVAL = 28;
63
+ export declare const ERRNO_EIO = 76;
64
+ export declare const ERRNO_EISDIR = 31;
65
+ export declare const ERRNO_ENOENT = 44;
66
+ export declare const ERRNO_ENOSPC = 51;
67
+ export declare const ERRNO_ENOSYS = 52;
68
+ export declare const ERRNO_ENOTDIR = 54;
69
+ export declare const ERRNO_ENOTEMPTY = 55;
70
+ export declare const ERRNO_EPERM = 63;
71
+ export declare const ERRNO_EPIPE = 64;
72
+ export declare const ERRNO_ESPIPE = 70;
73
+ export declare const ERRNO_ESRCH = 71;
74
+ export declare const ERRNO_ETIMEDOUT = 73;
75
+ /** Map POSIX error code strings to WASI errno numbers. */
76
+ export declare const ERRNO_MAP: Record<string, number>;
77
+ //# sourceMappingURL=wasi-constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasi-constants.d.ts","sourceRoot":"","sources":["../src/wasi-constants.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,eAAO,MAAM,gBAAgB,EAAG,CAAU,CAAC;AAC3C,eAAO,MAAM,qBAAqB,EAAG,CAAU,CAAC;AAChD,eAAO,MAAM,yBAAyB,EAAG,CAAU,CAAC;AACpD,eAAO,MAAM,kBAAkB,EAAG,CAAU,CAAC;AAC7C,eAAO,MAAM,qBAAqB,E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AAW,KAAK,CAAC;AAC9B,eAAO,MAAM,YAAY,KAAK,CAAC;AAC/B,eAAO,MAAM,WAAW,KAAK,CAAC;AAC9B,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC,0DAA0D;AAC1D,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAqB5C,CAAC"}
@@ -0,0 +1,122 @@
1
+ /**
2
+ * WASI protocol constants.
3
+ *
4
+ * All constants from the wasi_snapshot_preview1 specification:
5
+ * file types, fd flags, rights bitmasks, errno codes.
6
+ */
7
+ // ---------------------------------------------------------------------------
8
+ // WASI file types (filetype enum)
9
+ // ---------------------------------------------------------------------------
10
+ export const FILETYPE_UNKNOWN = 0;
11
+ export const FILETYPE_BLOCK_DEVICE = 1;
12
+ export const FILETYPE_CHARACTER_DEVICE = 2;
13
+ export const FILETYPE_DIRECTORY = 3;
14
+ export const FILETYPE_REGULAR_FILE = 4;
15
+ export const FILETYPE_SOCKET_DGRAM = 5;
16
+ export const FILETYPE_SOCKET_STREAM = 6;
17
+ export const FILETYPE_SYMBOLIC_LINK = 7;
18
+ // ---------------------------------------------------------------------------
19
+ // WASI fd flags (fdflags bitmask, u16)
20
+ // ---------------------------------------------------------------------------
21
+ export const FDFLAG_APPEND = 1 << 0;
22
+ export const FDFLAG_DSYNC = 1 << 1;
23
+ export const FDFLAG_NONBLOCK = 1 << 2;
24
+ export const FDFLAG_RSYNC = 1 << 3;
25
+ export const FDFLAG_SYNC = 1 << 4;
26
+ // ---------------------------------------------------------------------------
27
+ // WASI rights (rights bitmask, u64 — we use BigInt)
28
+ // ---------------------------------------------------------------------------
29
+ export const RIGHT_FD_DATASYNC = 1n << 0n;
30
+ export const RIGHT_FD_READ = 1n << 1n;
31
+ export const RIGHT_FD_SEEK = 1n << 2n;
32
+ export const RIGHT_FD_FDSTAT_SET_FLAGS = 1n << 3n;
33
+ export const RIGHT_FD_SYNC = 1n << 4n;
34
+ export const RIGHT_FD_TELL = 1n << 5n;
35
+ export const RIGHT_FD_WRITE = 1n << 6n;
36
+ export const RIGHT_FD_ADVISE = 1n << 7n;
37
+ export const RIGHT_FD_ALLOCATE = 1n << 8n;
38
+ export const RIGHT_PATH_CREATE_DIRECTORY = 1n << 9n;
39
+ export const RIGHT_PATH_CREATE_FILE = 1n << 10n;
40
+ export const RIGHT_PATH_LINK_SOURCE = 1n << 11n;
41
+ export const RIGHT_PATH_LINK_TARGET = 1n << 12n;
42
+ export const RIGHT_PATH_OPEN = 1n << 13n;
43
+ export const RIGHT_FD_READDIR = 1n << 14n;
44
+ export const RIGHT_PATH_READLINK = 1n << 15n;
45
+ export const RIGHT_PATH_RENAME_SOURCE = 1n << 16n;
46
+ export const RIGHT_PATH_RENAME_TARGET = 1n << 17n;
47
+ export const RIGHT_PATH_FILESTAT_GET = 1n << 18n;
48
+ export const RIGHT_PATH_FILESTAT_SET_SIZE = 1n << 19n;
49
+ export const RIGHT_PATH_FILESTAT_SET_TIMES = 1n << 20n;
50
+ export const RIGHT_FD_FILESTAT_GET = 1n << 21n;
51
+ export const RIGHT_FD_FILESTAT_SET_SIZE = 1n << 22n;
52
+ export const RIGHT_FD_FILESTAT_SET_TIMES = 1n << 23n;
53
+ export const RIGHT_PATH_SYMLINK = 1n << 24n;
54
+ export const RIGHT_PATH_REMOVE_DIRECTORY = 1n << 25n;
55
+ export const RIGHT_PATH_UNLINK_FILE = 1n << 26n;
56
+ export const RIGHT_POLL_FD_READWRITE = 1n << 27n;
57
+ export const RIGHT_SOCK_SHUTDOWN = 1n << 28n;
58
+ export const RIGHT_SOCK_ACCEPT = 1n << 29n;
59
+ // Convenience right sets
60
+ export const RIGHTS_STDIO = RIGHT_FD_READ | RIGHT_FD_WRITE | RIGHT_FD_FDSTAT_SET_FLAGS |
61
+ RIGHT_FD_FILESTAT_GET | RIGHT_POLL_FD_READWRITE;
62
+ export const RIGHTS_FILE_ALL = RIGHT_FD_DATASYNC | RIGHT_FD_READ | RIGHT_FD_SEEK |
63
+ RIGHT_FD_FDSTAT_SET_FLAGS | RIGHT_FD_SYNC | RIGHT_FD_TELL | RIGHT_FD_WRITE |
64
+ RIGHT_FD_ADVISE | RIGHT_FD_ALLOCATE | RIGHT_FD_FILESTAT_GET |
65
+ RIGHT_FD_FILESTAT_SET_SIZE | RIGHT_FD_FILESTAT_SET_TIMES |
66
+ RIGHT_POLL_FD_READWRITE;
67
+ export const RIGHTS_DIR_ALL = RIGHT_FD_FDSTAT_SET_FLAGS | RIGHT_FD_SYNC |
68
+ RIGHT_FD_READDIR | RIGHT_PATH_CREATE_DIRECTORY | RIGHT_PATH_CREATE_FILE |
69
+ RIGHT_PATH_LINK_SOURCE | RIGHT_PATH_LINK_TARGET | RIGHT_PATH_OPEN |
70
+ RIGHT_PATH_READLINK | RIGHT_PATH_RENAME_SOURCE | RIGHT_PATH_RENAME_TARGET |
71
+ RIGHT_PATH_FILESTAT_GET | RIGHT_PATH_FILESTAT_SET_SIZE |
72
+ RIGHT_PATH_FILESTAT_SET_TIMES | RIGHT_PATH_SYMLINK |
73
+ RIGHT_PATH_REMOVE_DIRECTORY | RIGHT_PATH_UNLINK_FILE |
74
+ RIGHT_FD_FILESTAT_GET | RIGHT_FD_FILESTAT_SET_TIMES;
75
+ // ---------------------------------------------------------------------------
76
+ // WASI errno codes (wasi_snapshot_preview1)
77
+ // ---------------------------------------------------------------------------
78
+ export const ERRNO_SUCCESS = 0;
79
+ export const ERRNO_EADDRINUSE = 3;
80
+ export const ERRNO_EACCES = 2;
81
+ export const ERRNO_EAGAIN = 6;
82
+ export const ERRNO_EBADF = 8;
83
+ export const ERRNO_ECHILD = 10;
84
+ export const ERRNO_ECONNREFUSED = 14;
85
+ export const ERRNO_EEXIST = 20;
86
+ export const ERRNO_EINVAL = 28;
87
+ export const ERRNO_EIO = 76;
88
+ export const ERRNO_EISDIR = 31;
89
+ export const ERRNO_ENOENT = 44;
90
+ export const ERRNO_ENOSPC = 51;
91
+ export const ERRNO_ENOSYS = 52;
92
+ export const ERRNO_ENOTDIR = 54;
93
+ export const ERRNO_ENOTEMPTY = 55;
94
+ export const ERRNO_EPERM = 63;
95
+ export const ERRNO_EPIPE = 64;
96
+ export const ERRNO_ESPIPE = 70;
97
+ export const ERRNO_ESRCH = 71;
98
+ export const ERRNO_ETIMEDOUT = 73;
99
+ /** Map POSIX error code strings to WASI errno numbers. */
100
+ export const ERRNO_MAP = {
101
+ EACCES: ERRNO_EACCES,
102
+ EADDRINUSE: ERRNO_EADDRINUSE,
103
+ EAGAIN: ERRNO_EAGAIN,
104
+ EBADF: ERRNO_EBADF,
105
+ ECHILD: ERRNO_ECHILD,
106
+ ECONNREFUSED: ERRNO_ECONNREFUSED,
107
+ EEXIST: ERRNO_EEXIST,
108
+ EINVAL: ERRNO_EINVAL,
109
+ EIO: ERRNO_EIO,
110
+ EISDIR: ERRNO_EISDIR,
111
+ ENOENT: ERRNO_ENOENT,
112
+ ENOSPC: ERRNO_ENOSPC,
113
+ ENOSYS: ERRNO_ENOSYS,
114
+ ENOTDIR: ERRNO_ENOTDIR,
115
+ ENOTEMPTY: ERRNO_ENOTEMPTY,
116
+ EPERM: ERRNO_EPERM,
117
+ EPIPE: ERRNO_EPIPE,
118
+ ESPIPE: ERRNO_ESPIPE,
119
+ ESRCH: ERRNO_ESRCH,
120
+ ETIMEDOUT: ERRNO_ETIMEDOUT,
121
+ };
122
+ //# sourceMappingURL=wasi-constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasi-constants.js","sourceRoot":"","sources":["../src/wasi-constants.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,8EAA8E;AAC9E,kCAAkC;AAClC,8EAA8E;AAC9E,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAU,CAAC;AAC3C,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAU,CAAC;AAChD,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAU,CAAC;AACpD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAU,CAAC;AAC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C/B,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAC;AAC/B,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAC;AAC/B,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAC;AAC/B,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,CAAC;AAChC,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAClC,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,CAAC;AAC9B,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,CAAC;AAC9B,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAC;AAC/B,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,CAAC;AAC9B,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAElC,0DAA0D;AAC1D,MAAM,CAAC,MAAM,SAAS,GAA2B;IAChD,MAAM,EAAE,YAAY;IACpB,UAAU,EAAE,gBAAgB;IAC5B,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,WAAW;IAClB,MAAM,EAAE,YAAY;IACpB,YAAY,EAAE,kBAAkB;IAChC,MAAM,EAAE,YAAY;IACpB,MAAM,EAAE,YAAY;IACpB,GAAG,EAAE,SAAS;IACd,MAAM,EAAE,YAAY;IACpB,MAAM,EAAE,YAAY;IACpB,MAAM,EAAE,YAAY;IACpB,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,aAAa;IACtB,SAAS,EAAE,eAAe;IAC1B,KAAK,EAAE,WAAW;IAClB,KAAK,EAAE,WAAW;IAClB,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,WAAW;IAClB,SAAS,EAAE,eAAe;CAC1B,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * File I/O bridge interface for WASI polyfill kernel delegation.
3
+ *
4
+ * Abstracts file data access so the polyfill does not directly touch
5
+ * VFS inodes. When mounted in the kernel, implementations wrap
6
+ * KernelInterface with a bound pid. For testing, a standalone
7
+ * implementation wraps an in-memory VFS + FDTable.
8
+ */
9
+ /**
10
+ * Synchronous file I/O interface for the WASI polyfill.
11
+ *
12
+ * Method signatures are designed to map cleanly to KernelInterface
13
+ * fdRead/fdWrite/fdOpen/fdSeek/fdClose when the kernel is connected.
14
+ */
15
+ export interface WasiFileIO {
16
+ /** Read up to maxBytes from fd at current cursor. Advances cursor. */
17
+ fdRead(fd: number, maxBytes: number): {
18
+ errno: number;
19
+ data: Uint8Array;
20
+ };
21
+ /** Write data to fd at current cursor (or end if append). Advances cursor. */
22
+ fdWrite(fd: number, data: Uint8Array): {
23
+ errno: number;
24
+ written: number;
25
+ };
26
+ /** Open file at resolved path. Handles CREAT/EXCL/TRUNC/DIRECTORY. */
27
+ fdOpen(path: string, dirflags: number, oflags: number, fdflags: number, rightsBase: bigint, rightsInheriting: bigint): {
28
+ errno: number;
29
+ fd: number;
30
+ filetype: number;
31
+ };
32
+ /** Seek within fd. Returns new cursor position. */
33
+ fdSeek(fd: number, offset: bigint, whence: number): {
34
+ errno: number;
35
+ newOffset: bigint;
36
+ };
37
+ /** Close fd. */
38
+ fdClose(fd: number): number;
39
+ /** Positional read (no cursor change). */
40
+ fdPread(fd: number, maxBytes: number, offset: bigint): {
41
+ errno: number;
42
+ data: Uint8Array;
43
+ };
44
+ /** Positional write (no cursor change). */
45
+ fdPwrite(fd: number, data: Uint8Array, offset: bigint): {
46
+ errno: number;
47
+ written: number;
48
+ };
49
+ }
50
+ //# sourceMappingURL=wasi-file-io.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasi-file-io.d.ts","sourceRoot":"","sources":["../src/wasi-file-io.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,sEAAsE;IACtE,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,UAAU,CAAA;KAAE,CAAC;IAE1E,8EAA8E;IAC9E,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAE1E,sEAAsE;IACtE,MAAM,CACJ,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAC/D,UAAU,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAC3C;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAEnD,mDAAmD;IACnD,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAEzF,gBAAgB;IAChB,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IAE5B,0CAA0C;IAC1C,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,UAAU,CAAA;KAAE,CAAC;IAE3F,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5F"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * File I/O bridge interface for WASI polyfill kernel delegation.
3
+ *
4
+ * Abstracts file data access so the polyfill does not directly touch
5
+ * VFS inodes. When mounted in the kernel, implementations wrap
6
+ * KernelInterface with a bound pid. For testing, a standalone
7
+ * implementation wraps an in-memory VFS + FDTable.
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=wasi-file-io.js.map