@ai-ecoverse/slicc-kernel 1.68.0 → 1.70.0
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 +2 -1
- package/dist/kernel-worker.js +57 -7
- package/dist/kernel-worker.js.map +3 -3
- package/dist/node-process-worker.js +525 -63
- package/dist/node-process-worker.js.map +4 -4
- package/dist/node.js +57 -7
- package/dist/node.js.map +3 -3
- package/dist/process-worker.js +522 -60
- package/dist/process-worker.js.map +4 -4
- package/package.json +1 -1
|
@@ -1164,6 +1164,34 @@ var init_cred = __esm({
|
|
|
1164
1164
|
}
|
|
1165
1165
|
});
|
|
1166
1166
|
|
|
1167
|
+
// src/kernel/pipe.ts
|
|
1168
|
+
var PIPE_CAPACITY;
|
|
1169
|
+
var init_pipe = __esm({
|
|
1170
|
+
"src/kernel/pipe.ts"() {
|
|
1171
|
+
"use strict";
|
|
1172
|
+
PIPE_CAPACITY = 64 * 1024;
|
|
1173
|
+
}
|
|
1174
|
+
});
|
|
1175
|
+
|
|
1176
|
+
// src/kernel/fd-table.ts
|
|
1177
|
+
function deviceAt(path) {
|
|
1178
|
+
return DEVICE_PATHS.get(path);
|
|
1179
|
+
}
|
|
1180
|
+
var DEVICE_PATHS;
|
|
1181
|
+
var init_fd_table = __esm({
|
|
1182
|
+
"src/kernel/fd-table.ts"() {
|
|
1183
|
+
"use strict";
|
|
1184
|
+
init_pipe();
|
|
1185
|
+
DEVICE_PATHS = /* @__PURE__ */ new Map([
|
|
1186
|
+
["/dev/null", "null"],
|
|
1187
|
+
["/dev/zero", "zero"],
|
|
1188
|
+
["/dev/full", "full"],
|
|
1189
|
+
["/dev/urandom", "urandom"],
|
|
1190
|
+
["/dev/random", "urandom"]
|
|
1191
|
+
]);
|
|
1192
|
+
}
|
|
1193
|
+
});
|
|
1194
|
+
|
|
1167
1195
|
// src/realm/sync-fs-wire.ts
|
|
1168
1196
|
function parseSyncFsUsage(json2) {
|
|
1169
1197
|
const u = json2;
|
|
@@ -1247,7 +1275,7 @@ function stdioAlias(path) {
|
|
|
1247
1275
|
return m[1] ? 0 : m[2] ? 1 : m[3] ? 2 : Number(m[4]);
|
|
1248
1276
|
}
|
|
1249
1277
|
function deviceOf(path) {
|
|
1250
|
-
return
|
|
1278
|
+
return deviceAt(path);
|
|
1251
1279
|
}
|
|
1252
1280
|
function within(path, root) {
|
|
1253
1281
|
return path === root || path.startsWith(root === "/" ? "/" : `${root}/`);
|
|
@@ -1315,10 +1343,11 @@ function promoteRequest(fd, f, handed) {
|
|
|
1315
1343
|
...f.buffer.handle !== void 0 ? { handle: f.buffer.handle } : {}
|
|
1316
1344
|
};
|
|
1317
1345
|
}
|
|
1318
|
-
var SYNTHETIC_DIRS, O_NONBLOCK, O_WRONLY, O_RDWR, O_APPEND,
|
|
1346
|
+
var SYNTHETIC_DIRS, O_NONBLOCK, O_WRONLY, O_RDWR, O_APPEND, SEALED_PATH, WasiFds, GEN;
|
|
1319
1347
|
var init_wasi_fds = __esm({
|
|
1320
1348
|
"src/process/wasi/wasi-fds.ts"() {
|
|
1321
1349
|
"use strict";
|
|
1350
|
+
init_fd_table();
|
|
1322
1351
|
init_sync_fs_wire();
|
|
1323
1352
|
init_wasi_abi();
|
|
1324
1353
|
init_wasi_files();
|
|
@@ -1327,13 +1356,6 @@ var init_wasi_fds = __esm({
|
|
|
1327
1356
|
O_WRONLY = 1;
|
|
1328
1357
|
O_RDWR = 2;
|
|
1329
1358
|
O_APPEND = 1024;
|
|
1330
|
-
DEVICES = {
|
|
1331
|
-
"/dev/null": "null",
|
|
1332
|
-
"/dev/zero": "zero",
|
|
1333
|
-
"/dev/full": "full",
|
|
1334
|
-
"/dev/urandom": "urandom",
|
|
1335
|
-
"/dev/random": "urandom"
|
|
1336
|
-
};
|
|
1337
1359
|
SEALED_PATH = "/dev/sealed";
|
|
1338
1360
|
WasiFds = class {
|
|
1339
1361
|
table = /* @__PURE__ */ new Map();
|
|
@@ -2446,11 +2468,11 @@ var init_wasi_host = __esm({
|
|
|
2446
2468
|
this.writeFilestat(statOut, this.fdFilestat(fd));
|
|
2447
2469
|
owner(fdOwned(fd), out);
|
|
2448
2470
|
},
|
|
2449
|
-
path_filestat_owner: (dirfd,
|
|
2471
|
+
path_filestat_owner: (dirfd, lookup2, p, l, statOut, out) => {
|
|
2450
2472
|
if (!this.o.fs.owners) throw new WasiError("ENOTSUP");
|
|
2451
2473
|
const path = at(dirfd, p, l);
|
|
2452
|
-
this.writeFilestat(statOut, this.pathFilestat(path,
|
|
2453
|
-
owner(pathOwned(path, (
|
|
2474
|
+
this.writeFilestat(statOut, this.pathFilestat(path, lookup2));
|
|
2475
|
+
owner(pathOwned(path, (lookup2 & LOOKUP_SYMLINK_FOLLOW) !== 0), out);
|
|
2454
2476
|
},
|
|
2455
2477
|
path_owner: (dirfd, p, l, flags, out) => {
|
|
2456
2478
|
if (!this.o.fs.owners) throw new WasiError("ENOTSUP");
|
|
@@ -2676,11 +2698,11 @@ var init_wasi_host = __esm({
|
|
|
2676
2698
|
mem.view().setUint32(out, fds.open(path, oflags, rights, fdflags), true);
|
|
2677
2699
|
if (fresh) this.created(path, 438);
|
|
2678
2700
|
},
|
|
2679
|
-
path_filestat_get: (dirfd,
|
|
2680
|
-
path_filestat_set_times: (dirfd,
|
|
2701
|
+
path_filestat_get: (dirfd, lookup2, p, l, out) => void this.writeFilestat(out, this.pathFilestat(at(dirfd, p, l), lookup2)),
|
|
2702
|
+
path_filestat_set_times: (dirfd, lookup2, p, l, atim, mtim, flags) => {
|
|
2681
2703
|
const path = at(dirfd, p, l);
|
|
2682
2704
|
fds.flushPath(path);
|
|
2683
|
-
this.setTimes(path, atim, mtim, flags, (
|
|
2705
|
+
this.setTimes(path, atim, mtim, flags, (lookup2 & LOOKUP_SYMLINK_FOLLOW) !== 0);
|
|
2684
2706
|
},
|
|
2685
2707
|
path_create_directory: (dirfd, p, l) => {
|
|
2686
2708
|
const path = at(dirfd, p, l);
|
|
@@ -2713,10 +2735,10 @@ var init_wasi_host = __esm({
|
|
|
2713
2735
|
mem.bytes(buf, n).set(target.subarray(0, n));
|
|
2714
2736
|
mem.view().setUint32(used, n, true);
|
|
2715
2737
|
},
|
|
2716
|
-
path_link: (fd,
|
|
2738
|
+
path_link: (fd, lookup2, p, l, fd2, p2, l2) => {
|
|
2717
2739
|
const from = at(fd, p, l);
|
|
2718
2740
|
const to = at(fd2, p2, l2);
|
|
2719
|
-
const follow2 = (
|
|
2741
|
+
const follow2 = (lookup2 & LOOKUP_SYMLINK_FOLLOW) !== 0;
|
|
2720
2742
|
const source = follow2 ? physicalPath(o.fs, from) : from;
|
|
2721
2743
|
fds.flushPath(from);
|
|
2722
2744
|
if (source !== from) fds.flushPath(source);
|
|
@@ -2984,7 +3006,7 @@ var init_wasi_host = __esm({
|
|
|
2984
3006
|
synthetic(path) {
|
|
2985
3007
|
return deviceOf(path) !== void 0 || path === SEALED_PATH && !!this.o.kernel.sys.openSealed;
|
|
2986
3008
|
}
|
|
2987
|
-
pathFilestat(path,
|
|
3009
|
+
pathFilestat(path, lookup2) {
|
|
2988
3010
|
if (this.synthetic(path)) {
|
|
2989
3011
|
return this.local({
|
|
2990
3012
|
filetype: FILETYPE.CHARACTER_DEVICE,
|
|
@@ -2994,7 +3016,7 @@ var init_wasi_host = __esm({
|
|
|
2994
3016
|
});
|
|
2995
3017
|
}
|
|
2996
3018
|
this.fds.flushPath(path);
|
|
2997
|
-
const follow2 = (
|
|
3019
|
+
const follow2 = (lookup2 & LOOKUP_SYMLINK_FOLLOW) !== 0;
|
|
2998
3020
|
return filestatOf(path, follow2 ? this.o.fs.stat(path) : this.o.fs.lstat(path));
|
|
2999
3021
|
}
|
|
3000
3022
|
setTimes(path, atim, mtim, flags, follow2 = true) {
|
|
@@ -3121,12 +3143,12 @@ var init_wasix_process = __esm({
|
|
|
3121
3143
|
fds.promoteFiles();
|
|
3122
3144
|
const map = fds.inheritable();
|
|
3123
3145
|
const nulls = /* @__PURE__ */ new Set();
|
|
3124
|
-
const
|
|
3146
|
+
const opened2 = [];
|
|
3125
3147
|
let cwd = this.host.cwd;
|
|
3126
3148
|
try {
|
|
3127
|
-
for (const op of ops) cwd = this.applyFdOp(op, { map, nulls, opened }, cwd);
|
|
3149
|
+
for (const op of ops) cwd = this.applyFdOp(op, { map, nulls, opened: opened2 }, cwd);
|
|
3128
3150
|
} catch (e) {
|
|
3129
|
-
for (const kfd of
|
|
3151
|
+
for (const kfd of opened2) this.host.o.kernel.sys.close(kfd);
|
|
3130
3152
|
throw e;
|
|
3131
3153
|
}
|
|
3132
3154
|
const stdio = [0, 1, 2].map((fd) => {
|
|
@@ -3137,10 +3159,10 @@ var init_wasix_process = __esm({
|
|
|
3137
3159
|
...[...map].filter(([fd]) => fd > 2).map(([fd, kernel]) => ({ fd, kernel })),
|
|
3138
3160
|
...[...nulls].filter((fd) => fd > 2).map((fd) => ({ fd, device: "null" }))
|
|
3139
3161
|
];
|
|
3140
|
-
return { stdio, inherit, cwd, opened };
|
|
3162
|
+
return { stdio, inherit, cwd, opened: opened2 };
|
|
3141
3163
|
}
|
|
3142
3164
|
applyFdOp(op, slots3, cwd) {
|
|
3143
|
-
const { map, nulls, opened } = slots3;
|
|
3165
|
+
const { map, nulls, opened: opened2 } = slots3;
|
|
3144
3166
|
const { fds } = this.host;
|
|
3145
3167
|
const point = (fd, kfd) => {
|
|
3146
3168
|
if (kfd === void 0) {
|
|
@@ -3163,7 +3185,7 @@ var init_wasix_process = __esm({
|
|
|
3163
3185
|
point(op.fd, void 0);
|
|
3164
3186
|
} else if (op.cmd === "open") {
|
|
3165
3187
|
const kfd = this.openFor(op, cwd);
|
|
3166
|
-
|
|
3188
|
+
opened2.push(kfd);
|
|
3167
3189
|
point(op.fd, kfd);
|
|
3168
3190
|
} else if (op.cmd === "chdir") return this.physicalFrom(cwd, op.path);
|
|
3169
3191
|
else return physicalPath(this.host.o.fs, fds.dir(op.fd).path);
|
|
@@ -3185,7 +3207,7 @@ var init_wasix_process = __esm({
|
|
|
3185
3207
|
});
|
|
3186
3208
|
}
|
|
3187
3209
|
spawn(req, exec = false) {
|
|
3188
|
-
const { stdio, inherit, cwd, opened } = this.childFds(req.ops ?? []);
|
|
3210
|
+
const { stdio, inherit, cwd, opened: opened2 } = this.childFds(req.ops ?? []);
|
|
3189
3211
|
try {
|
|
3190
3212
|
const spawn = {
|
|
3191
3213
|
op: "proc-spawn",
|
|
@@ -3200,7 +3222,7 @@ var init_wasix_process = __esm({
|
|
|
3200
3222
|
};
|
|
3201
3223
|
return restarted(() => this.call(spawn));
|
|
3202
3224
|
} finally {
|
|
3203
|
-
for (const kfd of
|
|
3225
|
+
for (const kfd of opened2) this.host.o.kernel.sys.close(kfd);
|
|
3204
3226
|
this.host.o.fs.invalidate?.();
|
|
3205
3227
|
}
|
|
3206
3228
|
}
|
|
@@ -3721,6 +3743,11 @@ function untilAborted(work, signal) {
|
|
|
3721
3743
|
work.then(done, done);
|
|
3722
3744
|
});
|
|
3723
3745
|
}
|
|
3746
|
+
function caughtOf(handlers) {
|
|
3747
|
+
let caught = 0;
|
|
3748
|
+
for (const sig of handlers.keys()) caught |= sigbit(sig);
|
|
3749
|
+
return caught;
|
|
3750
|
+
}
|
|
3724
3751
|
var JsCallError, JsKernel;
|
|
3725
3752
|
var init_js_kernel = __esm({
|
|
3726
3753
|
"src/process/js/js-kernel.ts"() {
|
|
@@ -3748,6 +3775,7 @@ var init_js_kernel = __esm({
|
|
|
3748
3775
|
reported = { caught: 0, ignored: 0 };
|
|
3749
3776
|
watching = false;
|
|
3750
3777
|
faulted = false;
|
|
3778
|
+
syncLane;
|
|
3751
3779
|
constructor(o) {
|
|
3752
3780
|
this.header = new Int32Array(o.sab, 0, SAB_HEADER_I32);
|
|
3753
3781
|
this.transport = o.transport;
|
|
@@ -3850,16 +3878,41 @@ var init_js_kernel = __esm({
|
|
|
3850
3878
|
if (sig === SIG.KILL || sig === SIG.STOP) {
|
|
3851
3879
|
return Promise.reject(new JsCallError("EINVAL", "signal"));
|
|
3852
3880
|
}
|
|
3881
|
+
if (this.syncLane) {
|
|
3882
|
+
try {
|
|
3883
|
+
this.changeNow(this.syncLane, sig, handler);
|
|
3884
|
+
return Promise.resolve();
|
|
3885
|
+
} catch (err) {
|
|
3886
|
+
return Promise.reject(err);
|
|
3887
|
+
}
|
|
3888
|
+
}
|
|
3853
3889
|
const run = this.changing.then(() => this.change(sig, handler));
|
|
3854
3890
|
this.changing = run.catch(() => void 0);
|
|
3855
3891
|
return run;
|
|
3856
3892
|
}
|
|
3857
|
-
|
|
3893
|
+
changeNow(lane, sig, handler) {
|
|
3894
|
+
const { handlers, ignored } = this.disposed(sig, handler);
|
|
3895
|
+
const defaults = handler === "default" ? sigbit(sig) : 0;
|
|
3896
|
+
const caught = caughtOf(handlers);
|
|
3897
|
+
if (caught !== this.reported.caught || ignored !== this.reported.ignored || defaults !== 0) {
|
|
3898
|
+
const r = lane({ op: "sig-mask", caught, ignored, ...defaults ? { defaults } : {} });
|
|
3899
|
+
if (!r.ok) throw new JsCallError(r.errno, "sig-mask");
|
|
3900
|
+
this.reported = { caught, ignored };
|
|
3901
|
+
}
|
|
3902
|
+
this.handlers = handlers;
|
|
3903
|
+
this.ignored = ignored;
|
|
3904
|
+
if (handlers.size > 0) void this.watch();
|
|
3905
|
+
}
|
|
3906
|
+
disposed(sig, handler) {
|
|
3858
3907
|
const handlers = new Map(this.handlers);
|
|
3859
3908
|
handlers.delete(sig);
|
|
3860
3909
|
let ignored = this.ignored & ~sigbit(sig);
|
|
3861
3910
|
if (handler === "ignore") ignored |= sigbit(sig);
|
|
3862
3911
|
else if (handler !== "default") handlers.set(sig, handler);
|
|
3912
|
+
return { handlers, ignored };
|
|
3913
|
+
}
|
|
3914
|
+
async change(sig, handler) {
|
|
3915
|
+
const { handlers, ignored } = this.disposed(sig, handler);
|
|
3863
3916
|
await this.report(handlers, ignored, handler === "default" ? sigbit(sig) : 0);
|
|
3864
3917
|
this.handlers = handlers;
|
|
3865
3918
|
this.ignored = ignored;
|
|
@@ -3869,8 +3922,7 @@ var init_js_kernel = __esm({
|
|
|
3869
3922
|
this.call({ op: "proc-kill", pid: this.pid, sig }).catch(this.onError);
|
|
3870
3923
|
}
|
|
3871
3924
|
async report(handlers, ignored, defaults) {
|
|
3872
|
-
|
|
3873
|
-
for (const sig of handlers.keys()) caught |= sigbit(sig);
|
|
3925
|
+
const caught = caughtOf(handlers);
|
|
3874
3926
|
const same = caught === this.reported.caught && ignored === this.reported.ignored;
|
|
3875
3927
|
if (same && defaults === 0) return;
|
|
3876
3928
|
this.reported = { caught, ignored };
|
|
@@ -4090,6 +4142,344 @@ var init_js_io = __esm({
|
|
|
4090
4142
|
}
|
|
4091
4143
|
});
|
|
4092
4144
|
|
|
4145
|
+
// src/process/js/js-dev.ts
|
|
4146
|
+
function inDev(abs) {
|
|
4147
|
+
return abs.startsWith("/dev") && (abs.length === 4 || abs[4] === "/");
|
|
4148
|
+
}
|
|
4149
|
+
function missing(path) {
|
|
4150
|
+
throw new JsCallError("ENOENT", path);
|
|
4151
|
+
}
|
|
4152
|
+
function nodeStat(mode, size = 0, owner) {
|
|
4153
|
+
return {
|
|
4154
|
+
isFile: false,
|
|
4155
|
+
isDirectory: (mode & S_IFMT) === DIR,
|
|
4156
|
+
isSymbolicLink: (mode & S_IFMT) === LINK,
|
|
4157
|
+
size,
|
|
4158
|
+
mode,
|
|
4159
|
+
mtimeMs: BORN,
|
|
4160
|
+
atimeMs: BORN,
|
|
4161
|
+
ctimeMs: BORN,
|
|
4162
|
+
nlink: 1,
|
|
4163
|
+
uid: owner?.uid ?? 0,
|
|
4164
|
+
gid: owner?.gid ?? 0
|
|
4165
|
+
};
|
|
4166
|
+
}
|
|
4167
|
+
function* lookup(abs) {
|
|
4168
|
+
if (abs === "/dev") return { kind: "dir", mode: DIR | 493 };
|
|
4169
|
+
const name2 = abs.slice("/dev/".length);
|
|
4170
|
+
if (DEVICES.includes(name2)) return { kind: "device" };
|
|
4171
|
+
if (name2 === "tty") return { kind: "tty" };
|
|
4172
|
+
const std = STDIO3.indexOf(name2);
|
|
4173
|
+
if (std >= 0) return { kind: "link", target: `${SELF_FD}/${std}`, fd: std };
|
|
4174
|
+
if (name2 === "fd") return { kind: "link", target: SELF_FD };
|
|
4175
|
+
const fd = /^fd\/(\d+)$/.exec(name2)?.[1];
|
|
4176
|
+
if (fd !== void 0) return { kind: "fd", fd: Number(fd) };
|
|
4177
|
+
if (/^tty\d+$/.test(name2)) {
|
|
4178
|
+
const names = yield { op: "fd-tty-names" };
|
|
4179
|
+
if (names.includes(abs)) return { kind: "terminal", name: abs };
|
|
4180
|
+
}
|
|
4181
|
+
const pts = /^pts\/(\d+)$/.exec(name2)?.[1];
|
|
4182
|
+
if (pts !== void 0) {
|
|
4183
|
+
const open = yield { op: "pty-list" };
|
|
4184
|
+
if (open.includes(Number(pts))) return { kind: "terminal", name: abs, pts: Number(pts) };
|
|
4185
|
+
}
|
|
4186
|
+
return missing(abs);
|
|
4187
|
+
}
|
|
4188
|
+
function* fdInfo(fd, path) {
|
|
4189
|
+
try {
|
|
4190
|
+
return yield { op: "fd-info", fd };
|
|
4191
|
+
} catch (err) {
|
|
4192
|
+
if (err instanceof JsCallError && err.code === "EBADF") return missing(path);
|
|
4193
|
+
throw err;
|
|
4194
|
+
}
|
|
4195
|
+
}
|
|
4196
|
+
function* pathStat(path) {
|
|
4197
|
+
const s = parseSyncFsStat(yield { op: "stat", path });
|
|
4198
|
+
if (!s) throw new JsCallError("EIO", "stat");
|
|
4199
|
+
return s;
|
|
4200
|
+
}
|
|
4201
|
+
function* terminalStat(name2) {
|
|
4202
|
+
const owner = yield { op: "fd-tty-owner", name: name2 };
|
|
4203
|
+
if (owner) return nodeStat(CHAR | (owner.mode ?? 400), 0, owner);
|
|
4204
|
+
return nodeStat(CHAR | (name2.startsWith("/dev/pts/") ? 400 : 438));
|
|
4205
|
+
}
|
|
4206
|
+
function* fdStat(fd, path) {
|
|
4207
|
+
const info = yield* fdInfo(fd, path);
|
|
4208
|
+
if (info.meta && "dir" in info.meta) return yield* pathStat(info.meta.dir);
|
|
4209
|
+
if (info.kind === "file") {
|
|
4210
|
+
const file = yield { op: "fd-vfs-stat", fd };
|
|
4211
|
+
if (file.orphan) return { ...nodeStat(33152, file.size), isFile: true };
|
|
4212
|
+
return yield* pathStat(file.path);
|
|
4213
|
+
}
|
|
4214
|
+
if (info.terminal) return yield* terminalStat(info.terminal);
|
|
4215
|
+
if (info.kind === "device" || info.kind === "tty") return nodeStat(CHAR | 438);
|
|
4216
|
+
if (info.kind === "socket") return nodeStat(49663);
|
|
4217
|
+
return nodeStat(4480);
|
|
4218
|
+
}
|
|
4219
|
+
function* fdTarget(fd, path) {
|
|
4220
|
+
const info = yield* fdInfo(fd, path);
|
|
4221
|
+
if (info.meta && "dir" in info.meta) return info.meta.dir;
|
|
4222
|
+
if (info.kind === "file") return (yield { op: "fd-vfs-stat", fd }).path;
|
|
4223
|
+
if (info.terminal) return info.terminal;
|
|
4224
|
+
if (info.meta && "device" in info.meta) return `/dev/${info.meta.device}`;
|
|
4225
|
+
return `${info.kind === "socket" ? "socket" : "pipe"}:[${fd}]`;
|
|
4226
|
+
}
|
|
4227
|
+
function linkStat(target) {
|
|
4228
|
+
return nodeStat(LINK | 511, target.length);
|
|
4229
|
+
}
|
|
4230
|
+
function* devStat(abs, follow2) {
|
|
4231
|
+
const node = yield* lookup(abs);
|
|
4232
|
+
switch (node.kind) {
|
|
4233
|
+
case "dir":
|
|
4234
|
+
return nodeStat(node.mode);
|
|
4235
|
+
case "device":
|
|
4236
|
+
case "tty":
|
|
4237
|
+
return nodeStat(CHAR | 438);
|
|
4238
|
+
case "terminal":
|
|
4239
|
+
return yield* terminalStat(node.name);
|
|
4240
|
+
case "link":
|
|
4241
|
+
if (!follow2) return linkStat(node.target);
|
|
4242
|
+
return node.fd === void 0 ? nodeStat(DIR | 365) : yield* fdStat(node.fd, abs);
|
|
4243
|
+
case "fd":
|
|
4244
|
+
return follow2 ? yield* fdStat(node.fd, abs) : linkStat(yield* fdTarget(node.fd, abs));
|
|
4245
|
+
}
|
|
4246
|
+
}
|
|
4247
|
+
function* devExists(abs) {
|
|
4248
|
+
try {
|
|
4249
|
+
yield* devStat(abs, true);
|
|
4250
|
+
return true;
|
|
4251
|
+
} catch (err) {
|
|
4252
|
+
if (err instanceof JsCallError) return false;
|
|
4253
|
+
throw err;
|
|
4254
|
+
}
|
|
4255
|
+
}
|
|
4256
|
+
function* devReadlink(abs) {
|
|
4257
|
+
const node = yield* lookup(abs);
|
|
4258
|
+
if (node.kind === "link") return node.target;
|
|
4259
|
+
if (node.kind === "fd") return yield* fdTarget(node.fd, abs);
|
|
4260
|
+
throw new JsCallError("EINVAL", abs);
|
|
4261
|
+
}
|
|
4262
|
+
function* devReaddir(abs) {
|
|
4263
|
+
if (abs === "/dev/fd") {
|
|
4264
|
+
const fds = yield { op: "fd-list" };
|
|
4265
|
+
return fds.map(({ fd }) => String(fd));
|
|
4266
|
+
}
|
|
4267
|
+
const node = yield* lookup(abs);
|
|
4268
|
+
if (node.kind !== "dir") throw new JsCallError("ENOTDIR", abs);
|
|
4269
|
+
const names = yield { op: "fd-tty-names" };
|
|
4270
|
+
const ttys = names.filter((n) => /^\/dev\/tty\d+$/.test(n)).map((n) => n.slice(5));
|
|
4271
|
+
return [...DEVICES, "tty", "fd", ...STDIO3, ...ttys].sort();
|
|
4272
|
+
}
|
|
4273
|
+
function* aliasOf(fd, abs, o) {
|
|
4274
|
+
const info = yield* fdInfo(fd, abs);
|
|
4275
|
+
const file = info.kind === "file";
|
|
4276
|
+
if (file) {
|
|
4277
|
+
const at = yield { op: "fd-vfs-stat", fd };
|
|
4278
|
+
if (!at.orphan)
|
|
4279
|
+
return { fd: yield openRequest(at.path, { ...o, create: false }), file };
|
|
4280
|
+
}
|
|
4281
|
+
const copy2 = yield { op: "fd-dup", fd, min: 3 };
|
|
4282
|
+
if (file && o.truncate) {
|
|
4283
|
+
try {
|
|
4284
|
+
yield { op: "fd-resize", fd: copy2, size: 0 };
|
|
4285
|
+
} catch (err) {
|
|
4286
|
+
yield { op: "fd-close", fd: copy2 };
|
|
4287
|
+
throw err;
|
|
4288
|
+
}
|
|
4289
|
+
}
|
|
4290
|
+
return { fd: copy2, file };
|
|
4291
|
+
}
|
|
4292
|
+
function* opened(abs, o) {
|
|
4293
|
+
const node = yield* lookup(abs);
|
|
4294
|
+
if (isExclusive(o)) throw new JsCallError("EEXIST", abs);
|
|
4295
|
+
switch (node.kind) {
|
|
4296
|
+
case "device":
|
|
4297
|
+
return { fd: yield openRequest(abs, { ...o, create: false }), file: false };
|
|
4298
|
+
case "tty":
|
|
4299
|
+
return { fd: yield { op: "fd-open-tty" }, file: false };
|
|
4300
|
+
case "terminal": {
|
|
4301
|
+
const req = node.pts === void 0 ? { op: "fd-open-tty", name: node.name } : { op: "pty-slave-open", n: node.pts, noctty: true };
|
|
4302
|
+
return { fd: yield req, file: false };
|
|
4303
|
+
}
|
|
4304
|
+
case "fd":
|
|
4305
|
+
return yield* aliasOf(node.fd, abs, o);
|
|
4306
|
+
case "link":
|
|
4307
|
+
if (node.fd !== void 0) return yield* aliasOf(node.fd, abs, o);
|
|
4308
|
+
throw new JsCallError("EISDIR", abs);
|
|
4309
|
+
case "dir":
|
|
4310
|
+
throw new JsCallError("EISDIR", abs);
|
|
4311
|
+
}
|
|
4312
|
+
}
|
|
4313
|
+
function* devOpen(abs, o) {
|
|
4314
|
+
const write2 = o.write === true || o.append === true || o.truncate === true;
|
|
4315
|
+
return { ...yield* opened(abs, o), read: o.read === true || !write2, write: write2 };
|
|
4316
|
+
}
|
|
4317
|
+
async function devAsync(kernel, step) {
|
|
4318
|
+
let next2 = step.next();
|
|
4319
|
+
while (!next2.done) {
|
|
4320
|
+
let answer2;
|
|
4321
|
+
try {
|
|
4322
|
+
answer2 = { value: await kernel.json(next2.value) };
|
|
4323
|
+
} catch (error) {
|
|
4324
|
+
answer2 = { error };
|
|
4325
|
+
}
|
|
4326
|
+
next2 = "value" in answer2 ? step.next(answer2.value) : step.throw(answer2.error);
|
|
4327
|
+
}
|
|
4328
|
+
return next2.value;
|
|
4329
|
+
}
|
|
4330
|
+
function devSync(kernel, step) {
|
|
4331
|
+
let next2 = step.next();
|
|
4332
|
+
while (!next2.done) {
|
|
4333
|
+
let answer2;
|
|
4334
|
+
try {
|
|
4335
|
+
answer2 = { value: kernel.json(next2.value) };
|
|
4336
|
+
} catch (error) {
|
|
4337
|
+
answer2 = { error };
|
|
4338
|
+
}
|
|
4339
|
+
next2 = "value" in answer2 ? step.next(answer2.value) : step.throw(answer2.error);
|
|
4340
|
+
}
|
|
4341
|
+
return next2.value;
|
|
4342
|
+
}
|
|
4343
|
+
function tooLarge(got) {
|
|
4344
|
+
if (got > DEV_READ_MAX) throw new JsCallError("EFBIG", "readFile");
|
|
4345
|
+
}
|
|
4346
|
+
function liveness(path) {
|
|
4347
|
+
let open = true;
|
|
4348
|
+
return {
|
|
4349
|
+
live: () => {
|
|
4350
|
+
if (!open) throw new JsCallError("EBADF", path);
|
|
4351
|
+
},
|
|
4352
|
+
end: () => {
|
|
4353
|
+
open = false;
|
|
4354
|
+
}
|
|
4355
|
+
};
|
|
4356
|
+
}
|
|
4357
|
+
function allowed(may, what) {
|
|
4358
|
+
if (!may) throw new JsCallError("EBADF", what);
|
|
4359
|
+
}
|
|
4360
|
+
function streamFile(fd, path, io, access) {
|
|
4361
|
+
const { live, end } = liveness(path);
|
|
4362
|
+
const file = {
|
|
4363
|
+
fd,
|
|
4364
|
+
path,
|
|
4365
|
+
async size() {
|
|
4366
|
+
live();
|
|
4367
|
+
return 0;
|
|
4368
|
+
},
|
|
4369
|
+
async read(position, length) {
|
|
4370
|
+
index2(position, "read");
|
|
4371
|
+
index2(length, "read");
|
|
4372
|
+
live();
|
|
4373
|
+
allowed(access.read, "read");
|
|
4374
|
+
return length === 0 ? new Uint8Array(0) : io.read(fd, Math.min(length, MAX_IO));
|
|
4375
|
+
},
|
|
4376
|
+
async write(position, data) {
|
|
4377
|
+
index2(position, "write");
|
|
4378
|
+
live();
|
|
4379
|
+
allowed(access.write, "write");
|
|
4380
|
+
await io.write(fd, data);
|
|
4381
|
+
return data.length;
|
|
4382
|
+
},
|
|
4383
|
+
async truncate(size) {
|
|
4384
|
+
live();
|
|
4385
|
+
index2(size, "truncate");
|
|
4386
|
+
throw new JsCallError("EINVAL", "truncate");
|
|
4387
|
+
},
|
|
4388
|
+
sync: async () => live(),
|
|
4389
|
+
async close() {
|
|
4390
|
+
live();
|
|
4391
|
+
end();
|
|
4392
|
+
await io.close(fd);
|
|
4393
|
+
}
|
|
4394
|
+
};
|
|
4395
|
+
return { file, invalidate: end };
|
|
4396
|
+
}
|
|
4397
|
+
function streamSyncFile(fd, path, io, access) {
|
|
4398
|
+
const { live, end } = liveness(path);
|
|
4399
|
+
const file = {
|
|
4400
|
+
fd,
|
|
4401
|
+
path,
|
|
4402
|
+
size() {
|
|
4403
|
+
live();
|
|
4404
|
+
return 0;
|
|
4405
|
+
},
|
|
4406
|
+
read(position, length) {
|
|
4407
|
+
index2(position, "read");
|
|
4408
|
+
index2(length, "read");
|
|
4409
|
+
live();
|
|
4410
|
+
allowed(access.read, "read");
|
|
4411
|
+
return length === 0 ? new Uint8Array(0) : io.read(fd, Math.min(length, MAX_IO));
|
|
4412
|
+
},
|
|
4413
|
+
write(position, data) {
|
|
4414
|
+
index2(position, "write");
|
|
4415
|
+
live();
|
|
4416
|
+
allowed(access.write, "write");
|
|
4417
|
+
io.write(fd, data);
|
|
4418
|
+
return data.length;
|
|
4419
|
+
},
|
|
4420
|
+
truncate(size) {
|
|
4421
|
+
live();
|
|
4422
|
+
index2(size, "truncate");
|
|
4423
|
+
throw new JsCallError("EINVAL", "truncate");
|
|
4424
|
+
},
|
|
4425
|
+
sync: () => live(),
|
|
4426
|
+
close() {
|
|
4427
|
+
live();
|
|
4428
|
+
end();
|
|
4429
|
+
io.close(fd);
|
|
4430
|
+
}
|
|
4431
|
+
};
|
|
4432
|
+
return { file, invalidate: end };
|
|
4433
|
+
}
|
|
4434
|
+
async function readWhole(file) {
|
|
4435
|
+
try {
|
|
4436
|
+
const parts = [];
|
|
4437
|
+
let got = 0;
|
|
4438
|
+
for (; ; ) {
|
|
4439
|
+
const chunk = await file.read(got, MAX_IO);
|
|
4440
|
+
if (chunk.length === 0) return joined(parts, got);
|
|
4441
|
+
got += chunk.length;
|
|
4442
|
+
tooLarge(got);
|
|
4443
|
+
parts.push(chunk);
|
|
4444
|
+
}
|
|
4445
|
+
} finally {
|
|
4446
|
+
await file.close();
|
|
4447
|
+
}
|
|
4448
|
+
}
|
|
4449
|
+
function readWholeSync(file) {
|
|
4450
|
+
try {
|
|
4451
|
+
const parts = [];
|
|
4452
|
+
let got = 0;
|
|
4453
|
+
for (; ; ) {
|
|
4454
|
+
const chunk = file.read(got, MAX_IO);
|
|
4455
|
+
if (chunk.length === 0) return joined(parts, got);
|
|
4456
|
+
got += chunk.length;
|
|
4457
|
+
tooLarge(got);
|
|
4458
|
+
parts.push(chunk);
|
|
4459
|
+
}
|
|
4460
|
+
} finally {
|
|
4461
|
+
file.close();
|
|
4462
|
+
}
|
|
4463
|
+
}
|
|
4464
|
+
var DEV_READ_MAX, DEVICES, STDIO3, SELF_FD, S_IFMT, DIR, LINK, CHAR, BORN;
|
|
4465
|
+
var init_js_dev = __esm({
|
|
4466
|
+
"src/process/js/js-dev.ts"() {
|
|
4467
|
+
"use strict";
|
|
4468
|
+
init_sync_fs_wire();
|
|
4469
|
+
init_js_io();
|
|
4470
|
+
init_js_kernel();
|
|
4471
|
+
DEV_READ_MAX = 64 * 1024 * 1024;
|
|
4472
|
+
DEVICES = ["null", "zero", "full", "random", "urandom"];
|
|
4473
|
+
STDIO3 = ["stdin", "stdout", "stderr"];
|
|
4474
|
+
SELF_FD = "/proc/self/fd";
|
|
4475
|
+
S_IFMT = 61440;
|
|
4476
|
+
DIR = 16384;
|
|
4477
|
+
LINK = 40960;
|
|
4478
|
+
CHAR = 8192;
|
|
4479
|
+
BORN = Date.now();
|
|
4480
|
+
}
|
|
4481
|
+
});
|
|
4482
|
+
|
|
4093
4483
|
// src/process/js/js-exit.ts
|
|
4094
4484
|
function json(r) {
|
|
4095
4485
|
return r.ok && r.kind === "json" ? r.json : void 0;
|
|
@@ -4102,10 +4492,10 @@ function restoreMode(lane, { terminal, fd, termios }) {
|
|
|
4102
4492
|
lane({ op: "tty-set", fd: at, termios });
|
|
4103
4493
|
return;
|
|
4104
4494
|
}
|
|
4105
|
-
const
|
|
4106
|
-
if (typeof
|
|
4107
|
-
lane({ op: "tty-set", fd:
|
|
4108
|
-
lane({ op: "fd-close", fd:
|
|
4495
|
+
const opened2 = json(lane({ op: "fd-open-tty", name: terminal }));
|
|
4496
|
+
if (typeof opened2 !== "number") return;
|
|
4497
|
+
lane({ op: "tty-set", fd: opened2, termios });
|
|
4498
|
+
lane({ op: "fd-close", fd: opened2 });
|
|
4109
4499
|
}
|
|
4110
4500
|
function writeOut(lane, fd, data) {
|
|
4111
4501
|
let at = 0;
|
|
@@ -4554,7 +4944,7 @@ function netOps(kernel, io) {
|
|
|
4554
4944
|
const r = await kernel.blocking({ op: "sock-resolve", name: host, family: 4 }, signal);
|
|
4555
4945
|
return (r.ok && r.kind === "json" ? r.json : [])[0];
|
|
4556
4946
|
};
|
|
4557
|
-
const
|
|
4947
|
+
const opened2 = async (use) => {
|
|
4558
4948
|
const fd = await kernel.json({ op: "sock-open", domain: "inet" });
|
|
4559
4949
|
try {
|
|
4560
4950
|
return await use(fd);
|
|
@@ -4596,7 +4986,7 @@ function netOps(kernel, io) {
|
|
|
4596
4986
|
};
|
|
4597
4987
|
};
|
|
4598
4988
|
return {
|
|
4599
|
-
listen: (options = {}) =>
|
|
4989
|
+
listen: (options = {}) => opened2(async (fd) => {
|
|
4600
4990
|
const addr = {
|
|
4601
4991
|
family: "inet",
|
|
4602
4992
|
host: options.host ?? "127.0.0.1",
|
|
@@ -4616,7 +5006,7 @@ function netOps(kernel, io) {
|
|
|
4616
5006
|
host: await resolve(host, signal),
|
|
4617
5007
|
port: port(options.port)
|
|
4618
5008
|
};
|
|
4619
|
-
return
|
|
5009
|
+
return opened2(async (fd) => {
|
|
4620
5010
|
const r = await kernel.raw({ op: "sock-connect", fd, addr, nonblock: true });
|
|
4621
5011
|
if (!r.ok && r.errno !== "EINPROGRESS") throw new JsCallError(r.errno, "connect");
|
|
4622
5012
|
await kernel.blocking({ op: "fd-select", read: [], write: [fd], timeoutMs: -1 }, signal);
|
|
@@ -4650,9 +5040,13 @@ var init_js_net = __esm({
|
|
|
4650
5040
|
// src/process/js/js-run.ts
|
|
4651
5041
|
function stdioOf(how) {
|
|
4652
5042
|
if (how === void 0) return "pipe";
|
|
4653
|
-
if (
|
|
5043
|
+
if (typeof how === "number" && Number.isInteger(how) && how >= 0) return how;
|
|
5044
|
+
if (!STDIO4.has(how)) throw new JsCallError("EINVAL", "run");
|
|
4654
5045
|
return how;
|
|
4655
5046
|
}
|
|
5047
|
+
function stderrOf(how) {
|
|
5048
|
+
return how === "stdout" ? how : stdioOf(how);
|
|
5049
|
+
}
|
|
4656
5050
|
function limit(value2) {
|
|
4657
5051
|
if (value2 === void 0 || value2 === Number.POSITIVE_INFINITY) return value2;
|
|
4658
5052
|
if (!(value2 >= 0)) throw new JsCallError("EINVAL", "run");
|
|
@@ -4677,7 +5071,7 @@ function runSync(kernel, d, o) {
|
|
|
4677
5071
|
const [file] = o.argv;
|
|
4678
5072
|
if (file === void 0) throw new JsCallError("EINVAL", "run");
|
|
4679
5073
|
const stdout = stdioOf(o.stdout);
|
|
4680
|
-
const stderr =
|
|
5074
|
+
const stderr = stderrOf(o.stderr);
|
|
4681
5075
|
const input = typeof o.input === "string" ? encoder2.encode(o.input) : o.input;
|
|
4682
5076
|
const maxBuffer = limit(o.maxBuffer);
|
|
4683
5077
|
const timeout = limit(o.timeout);
|
|
@@ -4698,13 +5092,13 @@ function runSync(kernel, d, o) {
|
|
|
4698
5092
|
});
|
|
4699
5093
|
return decodeRun(bytes, stdout, stderr);
|
|
4700
5094
|
}
|
|
4701
|
-
var encoder2,
|
|
5095
|
+
var encoder2, STDIO4;
|
|
4702
5096
|
var init_js_run = __esm({
|
|
4703
5097
|
"src/process/js/js-run.ts"() {
|
|
4704
5098
|
"use strict";
|
|
4705
5099
|
init_js_kernel();
|
|
4706
5100
|
encoder2 = new TextEncoder();
|
|
4707
|
-
|
|
5101
|
+
STDIO4 = /* @__PURE__ */ new Set(["pipe", "ignore", "inherit"]);
|
|
4708
5102
|
}
|
|
4709
5103
|
});
|
|
4710
5104
|
|
|
@@ -4998,13 +5392,30 @@ function syncOps(kernel, shared) {
|
|
|
4998
5392
|
};
|
|
4999
5393
|
const statOf = (op, path) => {
|
|
5000
5394
|
const abs = resolve(path);
|
|
5395
|
+
if (inDev(abs)) return devSync(kernel, devStat(abs, op === "stat"));
|
|
5001
5396
|
kernel.call({ op: "fd-path-flush", path: abs });
|
|
5002
5397
|
const s = parseSyncFsStat(kernel.json({ op, path: abs }));
|
|
5003
5398
|
if (!s) throw new JsCallError("EIO", op);
|
|
5004
5399
|
return s;
|
|
5005
5400
|
};
|
|
5401
|
+
const openDev2 = (abs, options) => {
|
|
5402
|
+
const { fd, file, ...access } = devSync(kernel, devOpen(abs, options));
|
|
5403
|
+
const forget = () => {
|
|
5404
|
+
infos.delete(fd);
|
|
5405
|
+
handles.delete(fd);
|
|
5406
|
+
};
|
|
5407
|
+
if (file) infos.set(fd, { kind: "file" });
|
|
5408
|
+
const close = (n) => {
|
|
5409
|
+
forget();
|
|
5410
|
+
kernel.call({ op: "fd-close", fd: n });
|
|
5411
|
+
};
|
|
5412
|
+
const handle = file ? syncFile(kernel, fd, abs, options.append === true, forget) : streamSyncFile(fd, abs, { read: (n, max) => read2(n, max), write: write2, close }, access);
|
|
5413
|
+
handles.set(fd, handle.invalidate);
|
|
5414
|
+
return handle.file;
|
|
5415
|
+
};
|
|
5006
5416
|
const open = (path, options = {}) => {
|
|
5007
5417
|
const abs = resolve(path);
|
|
5418
|
+
if (inDev(abs)) return openDev2(abs, options);
|
|
5008
5419
|
let existing;
|
|
5009
5420
|
try {
|
|
5010
5421
|
existing = statOf(isExclusive(options) ? "lstat" : "stat", abs);
|
|
@@ -5108,17 +5519,30 @@ function syncPathOps(kernel, resolve, statOf, open) {
|
|
|
5108
5519
|
return {
|
|
5109
5520
|
stat: (path) => statOf("stat", path),
|
|
5110
5521
|
lstat: (path) => statOf("lstat", path),
|
|
5111
|
-
exists
|
|
5112
|
-
|
|
5522
|
+
exists(path) {
|
|
5523
|
+
const abs = resolve(path);
|
|
5524
|
+
if (inDev(abs)) return devSync(kernel, devExists(abs));
|
|
5525
|
+
return kernel.json({ op: "exists", path: abs }) === true;
|
|
5526
|
+
},
|
|
5527
|
+
readdir(path) {
|
|
5528
|
+
const abs = resolve(path);
|
|
5529
|
+
if (inDev(abs)) return devSync(kernel, devReaddir(abs));
|
|
5530
|
+
return kernel.json({ op: "readdir", path: abs });
|
|
5531
|
+
},
|
|
5113
5532
|
mkdir: (path) => void kernel.call({ op: "mkdir", path: resolve(path) }),
|
|
5114
5533
|
rm: (path) => void kernel.call({ op: "rm", path: resolve(path) }),
|
|
5115
5534
|
unlink: (path) => void kernel.call({ op: "unlink", path: resolve(path) }),
|
|
5116
5535
|
rename: (from, to) => void kernel.call({ op: "rename", path: resolve(from), arg2: resolve(to) }),
|
|
5117
5536
|
link: (from, to) => void kernel.call({ op: "link", path: resolve(from), arg2: resolve(to) }),
|
|
5118
5537
|
symlink: (target, path) => void kernel.call({ op: "symlink", path: resolve(path), arg2: target }),
|
|
5119
|
-
readlink
|
|
5538
|
+
readlink(path) {
|
|
5539
|
+
const abs = resolve(path);
|
|
5540
|
+
if (inDev(abs)) return devSync(kernel, devReadlink(abs));
|
|
5541
|
+
return String(kernel.json({ op: "readlink", path: abs }));
|
|
5542
|
+
},
|
|
5120
5543
|
readFile(path) {
|
|
5121
5544
|
const abs = resolve(path);
|
|
5545
|
+
if (inDev(abs)) return readWholeSync(open(abs));
|
|
5122
5546
|
kernel.call({ op: "fd-path-flush", path: abs });
|
|
5123
5547
|
return kernel.bytes({ op: "read", path: abs });
|
|
5124
5548
|
},
|
|
@@ -5139,6 +5563,7 @@ var init_js_sync = __esm({
|
|
|
5139
5563
|
init_signals();
|
|
5140
5564
|
init_sync_fs_wire();
|
|
5141
5565
|
init_sync_sab_bridge();
|
|
5566
|
+
init_js_dev();
|
|
5142
5567
|
init_js_io();
|
|
5143
5568
|
init_js_kernel();
|
|
5144
5569
|
encoder3 = new TextEncoder();
|
|
@@ -5539,6 +5964,7 @@ function createContext(o) {
|
|
|
5539
5964
|
const writable2 = (fd) => new WritableStream({ write: (chunk) => write2(fd, chunk) });
|
|
5540
5965
|
const statOf = async (op, path) => {
|
|
5541
5966
|
const abs = resolve(path);
|
|
5967
|
+
if (inDev(abs)) return devAsync(kernel, devStat(abs, op === "stat"));
|
|
5542
5968
|
await kernel.call({ op: "fd-path-flush", path: abs });
|
|
5543
5969
|
const s = parseSyncFsStat(await kernel.json({ op, path: abs }));
|
|
5544
5970
|
if (!s) throw new JsCallError("EIO", op);
|
|
@@ -5546,6 +5972,7 @@ function createContext(o) {
|
|
|
5546
5972
|
};
|
|
5547
5973
|
const open = async (path, options = {}) => {
|
|
5548
5974
|
const abs = resolve(path);
|
|
5975
|
+
if (inDev(abs)) return openDev(kernel, abs, options, { infos, handles, read: read2, write: writeAll });
|
|
5549
5976
|
const existing = await statOf(isExclusive(options) ? "lstat" : "stat", abs).catch(absent);
|
|
5550
5977
|
checkOpen(abs, options, existing);
|
|
5551
5978
|
const fd = await kernel.json(openRequest(abs, options));
|
|
@@ -5565,6 +5992,7 @@ function createContext(o) {
|
|
|
5565
5992
|
};
|
|
5566
5993
|
const fs = pathOps(kernel, resolve, statOf, open);
|
|
5567
5994
|
const lane = o.lane ?? laneOf(void 0);
|
|
5995
|
+
if (o.lane) kernel.syncLane = o.lane;
|
|
5568
5996
|
const syncKernel = new JsSyncKernel(lane, kernel, unwind);
|
|
5569
5997
|
const terminal = ttyOps(kernel);
|
|
5570
5998
|
const sync = {
|
|
@@ -5645,6 +6073,26 @@ function createContext(o) {
|
|
|
5645
6073
|
};
|
|
5646
6074
|
return { ctx, drain: drain2 };
|
|
5647
6075
|
}
|
|
6076
|
+
async function openDev(kernel, abs, options, state) {
|
|
6077
|
+
const { fd, file, ...access } = await devAsync(kernel, devOpen(abs, options));
|
|
6078
|
+
const forget = () => {
|
|
6079
|
+
state.infos.delete(fd);
|
|
6080
|
+
state.handles.delete(fd);
|
|
6081
|
+
};
|
|
6082
|
+
if (file) state.infos.set(fd, { kind: "file" });
|
|
6083
|
+
const close = async (n) => {
|
|
6084
|
+
forget();
|
|
6085
|
+
await kernel.call({ op: "fd-close", fd: n });
|
|
6086
|
+
};
|
|
6087
|
+
const handle = file ? fileHandle(kernel, fd, abs, options.append === true, forget) : streamFile(
|
|
6088
|
+
fd,
|
|
6089
|
+
abs,
|
|
6090
|
+
{ read: (n, max) => state.read(n, max), write: state.write, close },
|
|
6091
|
+
access
|
|
6092
|
+
);
|
|
6093
|
+
state.handles.set(fd, handle.invalidate);
|
|
6094
|
+
return handle.file;
|
|
6095
|
+
}
|
|
5648
6096
|
function fileHandle(kernel, fd, path, append, forget) {
|
|
5649
6097
|
let open = true;
|
|
5650
6098
|
const live = () => {
|
|
@@ -5737,17 +6185,30 @@ function pathOps(kernel, resolve, statOf, open) {
|
|
|
5737
6185
|
return {
|
|
5738
6186
|
stat: (path) => statOf("stat", path),
|
|
5739
6187
|
lstat: (path) => statOf("lstat", path),
|
|
5740
|
-
|
|
5741
|
-
|
|
6188
|
+
async exists(path) {
|
|
6189
|
+
const abs = resolve(path);
|
|
6190
|
+
if (inDev(abs)) return devAsync(kernel, devExists(abs));
|
|
6191
|
+
return await kernel.json({ op: "exists", path: abs }) === true;
|
|
6192
|
+
},
|
|
6193
|
+
async readdir(path) {
|
|
6194
|
+
const abs = resolve(path);
|
|
6195
|
+
if (inDev(abs)) return devAsync(kernel, devReaddir(abs));
|
|
6196
|
+
return await kernel.json({ op: "readdir", path: abs });
|
|
6197
|
+
},
|
|
5742
6198
|
mkdir: async (path) => void await kernel.call({ op: "mkdir", path: resolve(path) }),
|
|
5743
6199
|
rm: async (path) => void await kernel.call({ op: "rm", path: resolve(path) }),
|
|
5744
6200
|
unlink: async (path) => void await kernel.call({ op: "unlink", path: resolve(path) }),
|
|
5745
6201
|
rename: async (from, to) => void await kernel.call({ op: "rename", path: resolve(from), arg2: resolve(to) }),
|
|
5746
6202
|
link: async (from, to) => void await kernel.call({ op: "link", path: resolve(from), arg2: resolve(to) }),
|
|
5747
6203
|
symlink: async (target, path) => void await kernel.call({ op: "symlink", path: resolve(path), arg2: target }),
|
|
5748
|
-
|
|
6204
|
+
async readlink(path) {
|
|
6205
|
+
const abs = resolve(path);
|
|
6206
|
+
if (inDev(abs)) return devAsync(kernel, devReadlink(abs));
|
|
6207
|
+
return String(await kernel.json({ op: "readlink", path: abs }));
|
|
6208
|
+
},
|
|
5749
6209
|
async readFile(path) {
|
|
5750
6210
|
const abs = resolve(path);
|
|
6211
|
+
if (inDev(abs)) return readWhole(await open(abs));
|
|
5751
6212
|
await kernel.call({ op: "fd-path-flush", path: abs });
|
|
5752
6213
|
return kernel.bytes({ op: "read", path: abs });
|
|
5753
6214
|
},
|
|
@@ -5768,6 +6229,7 @@ var init_js_context = __esm({
|
|
|
5768
6229
|
init_signals();
|
|
5769
6230
|
init_sync_fs_wire();
|
|
5770
6231
|
init_js_children();
|
|
6232
|
+
init_js_dev();
|
|
5771
6233
|
init_js_exit();
|
|
5772
6234
|
init_js_fetch();
|
|
5773
6235
|
init_js_io();
|
|
@@ -6422,7 +6884,7 @@ function createStreamOps(h) {
|
|
|
6422
6884
|
}
|
|
6423
6885
|
}
|
|
6424
6886
|
};
|
|
6425
|
-
const
|
|
6887
|
+
const opened2 = (node, on, want = 0) => {
|
|
6426
6888
|
const s = node.live;
|
|
6427
6889
|
try {
|
|
6428
6890
|
const handle = bridgeOf(node).hold?.(liveNodePath(node), on, true, s.handle, want);
|
|
@@ -6473,7 +6935,7 @@ function createStreamOps(h) {
|
|
|
6473
6935
|
const want = permitted(stream, created);
|
|
6474
6936
|
live.openCount++;
|
|
6475
6937
|
counted = true;
|
|
6476
|
-
if (live.openCount === 1)
|
|
6938
|
+
if (live.openCount === 1) opened2(stream.node, true, want);
|
|
6477
6939
|
} catch (err) {
|
|
6478
6940
|
if (counted) live.openCount--;
|
|
6479
6941
|
if (stream.fd !== void 0) Fs.closeStream?.(stream.fd);
|
|
@@ -6504,7 +6966,7 @@ function createStreamOps(h) {
|
|
|
6504
6966
|
s.len = 0;
|
|
6505
6967
|
s.loaded = false;
|
|
6506
6968
|
held(stream, -1);
|
|
6507
|
-
|
|
6969
|
+
opened2(node, false);
|
|
6508
6970
|
}
|
|
6509
6971
|
},
|
|
6510
6972
|
read(stream, buffer, offset, length, position) {
|
|
@@ -7028,8 +7490,8 @@ var init_kernel_streams = __esm({
|
|
|
7028
7490
|
fs.readdir = (path) => {
|
|
7029
7491
|
const names = readdir.call(fs, path);
|
|
7030
7492
|
if (path.replace(/\/+$/, "") !== "/dev") return names;
|
|
7031
|
-
const
|
|
7032
|
-
return [...names, ...
|
|
7493
|
+
const missing2 = ttyNames().map((tty) => tty.slice("/dev/".length)).filter((name2) => TTY_NAME.test(name2) && !names.includes(name2));
|
|
7494
|
+
return [...names, ...missing2];
|
|
7033
7495
|
};
|
|
7034
7496
|
}
|
|
7035
7497
|
ttyNode(name2) {
|
|
@@ -7807,13 +8269,13 @@ function describeFdDir(Fs) {
|
|
|
7807
8269
|
return;
|
|
7808
8270
|
}
|
|
7809
8271
|
const ops = dir?.node_ops;
|
|
7810
|
-
const
|
|
7811
|
-
if (!dir || !
|
|
8272
|
+
const lookup2 = ops?.lookup;
|
|
8273
|
+
if (!dir || !lookup2 || ops.getattr) return;
|
|
7812
8274
|
dir.node_ops = {
|
|
7813
8275
|
...ops,
|
|
7814
8276
|
getattr: () => syntheticAttr(DIR_MODE, 1),
|
|
7815
8277
|
lookup: (parent, name2) => {
|
|
7816
|
-
const entry =
|
|
8278
|
+
const entry = lookup2(parent, name2);
|
|
7817
8279
|
entry.node_ops = {
|
|
7818
8280
|
...entry.node_ops,
|
|
7819
8281
|
getattr: () => syntheticAttr(LINK_MODE, entry.id ?? 0)
|
|
@@ -8353,7 +8815,7 @@ function createProcessKernel(deps) {
|
|
|
8353
8815
|
if (!stream) return { none: true };
|
|
8354
8816
|
promote?.(stream);
|
|
8355
8817
|
if (stream.sliccKernelFd !== void 0) return { fd: stream.sliccKernelFd };
|
|
8356
|
-
if (((stream.node?.mode ?? 0) &
|
|
8818
|
+
if (((stream.node?.mode ?? 0) & S_IFMT2) === S_IFDIR2 && stream.path) return { dir: stream.path };
|
|
8357
8819
|
const device2 = deviceOfStream(stream);
|
|
8358
8820
|
if (device2) return device2;
|
|
8359
8821
|
return n === 0 ? { input: drain(Fs, stream) } : { capture: true };
|
|
@@ -8500,13 +8962,13 @@ function createProcessKernel(deps) {
|
|
|
8500
8962
|
}
|
|
8501
8963
|
};
|
|
8502
8964
|
}
|
|
8503
|
-
var
|
|
8965
|
+
var S_IFMT2, S_IFDIR2, POLLIN2, POLLOUT2, POLLERR2, POLLHUP2, POLLNVAL, SELECT_SLICE_MS, WUNTRACED, WCONTINUED;
|
|
8504
8966
|
var init_process_children = __esm({
|
|
8505
8967
|
"src/process/process-children.ts"() {
|
|
8506
8968
|
"use strict";
|
|
8507
8969
|
init_process_fork();
|
|
8508
8970
|
init_wasi_errno();
|
|
8509
|
-
|
|
8971
|
+
S_IFMT2 = 61440;
|
|
8510
8972
|
S_IFDIR2 = 16384;
|
|
8511
8973
|
POLLIN2 = 1;
|
|
8512
8974
|
POLLOUT2 = 4;
|
|
@@ -9081,7 +9543,7 @@ function useProcfs(Fs, sys, pid, memory = memorySource()) {
|
|
|
9081
9543
|
return found;
|
|
9082
9544
|
};
|
|
9083
9545
|
const procOps = proc.node_ops;
|
|
9084
|
-
const
|
|
9546
|
+
const lookup2 = procOps.lookup?.bind(procOps);
|
|
9085
9547
|
const readdir = procOps.readdir?.bind(procOps);
|
|
9086
9548
|
const listAll = (node) => {
|
|
9087
9549
|
const names = new Set(readdir ? readdir(node) : [".", ".."]);
|
|
@@ -9104,8 +9566,8 @@ function useProcfs(Fs, sys, pid, memory = memorySource()) {
|
|
|
9104
9566
|
() => systemFile(name2, procList(), Date.now(), memory)
|
|
9105
9567
|
);
|
|
9106
9568
|
}
|
|
9107
|
-
if (!
|
|
9108
|
-
return
|
|
9569
|
+
if (!lookup2) throw error();
|
|
9570
|
+
return lookup2(parent, name2);
|
|
9109
9571
|
},
|
|
9110
9572
|
readdir: (node) => listAll(node)
|
|
9111
9573
|
};
|
|
@@ -11840,8 +12302,8 @@ var init_wasix_host = __esm({
|
|
|
11840
12302
|
mem.view().setUint16(out, host.fds.cloexec.has(fd) ? FDFLAGSEXT_CLOEXEC : 0, true);
|
|
11841
12303
|
},
|
|
11842
12304
|
fd_fdflags_set: (fd, flags) => void host.fds.setCloexec(fd, (flags & FDFLAGSEXT_CLOEXEC) !== 0),
|
|
11843
|
-
path_open2: (dirfd,
|
|
11844
|
-
const r = preview1.path_open(dirfd,
|
|
12305
|
+
path_open2: (dirfd, lookup2, p, l, oflags, rights, inheriting, fdflags, fdflagsext, out) => {
|
|
12306
|
+
const r = preview1.path_open(dirfd, lookup2, p, l, oflags, rights, inheriting, fdflags, out);
|
|
11845
12307
|
if (r === E.SUCCESS && fdflagsext & FDFLAGSEXT_CLOEXEC)
|
|
11846
12308
|
host.fds.setCloexec(mem.view().getUint32(out, true), true);
|
|
11847
12309
|
return r;
|