@ai-ecoverse/slicc-kernel 1.68.0 → 1.69.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 +1 -0
- package/dist/kernel-worker.js +20 -0
- package/dist/kernel-worker.js.map +3 -3
- package/dist/node-process-worker.js +520 -62
- package/dist/node-process-worker.js.map +4 -4
- package/dist/node.js +20 -0
- package/dist/node.js.map +3 -3
- package/dist/process-worker.js +517 -59
- 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,7 +5040,7 @@ 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 (!STDIO4.has(how)) throw new JsCallError("EINVAL", "run");
|
|
4654
5044
|
return how;
|
|
4655
5045
|
}
|
|
4656
5046
|
function limit(value2) {
|
|
@@ -4698,13 +5088,13 @@ function runSync(kernel, d, o) {
|
|
|
4698
5088
|
});
|
|
4699
5089
|
return decodeRun(bytes, stdout, stderr);
|
|
4700
5090
|
}
|
|
4701
|
-
var encoder2,
|
|
5091
|
+
var encoder2, STDIO4;
|
|
4702
5092
|
var init_js_run = __esm({
|
|
4703
5093
|
"src/process/js/js-run.ts"() {
|
|
4704
5094
|
"use strict";
|
|
4705
5095
|
init_js_kernel();
|
|
4706
5096
|
encoder2 = new TextEncoder();
|
|
4707
|
-
|
|
5097
|
+
STDIO4 = /* @__PURE__ */ new Set(["pipe", "ignore", "inherit"]);
|
|
4708
5098
|
}
|
|
4709
5099
|
});
|
|
4710
5100
|
|
|
@@ -4998,13 +5388,30 @@ function syncOps(kernel, shared) {
|
|
|
4998
5388
|
};
|
|
4999
5389
|
const statOf = (op, path) => {
|
|
5000
5390
|
const abs = resolve(path);
|
|
5391
|
+
if (inDev(abs)) return devSync(kernel, devStat(abs, op === "stat"));
|
|
5001
5392
|
kernel.call({ op: "fd-path-flush", path: abs });
|
|
5002
5393
|
const s = parseSyncFsStat(kernel.json({ op, path: abs }));
|
|
5003
5394
|
if (!s) throw new JsCallError("EIO", op);
|
|
5004
5395
|
return s;
|
|
5005
5396
|
};
|
|
5397
|
+
const openDev2 = (abs, options) => {
|
|
5398
|
+
const { fd, file, ...access } = devSync(kernel, devOpen(abs, options));
|
|
5399
|
+
const forget = () => {
|
|
5400
|
+
infos.delete(fd);
|
|
5401
|
+
handles.delete(fd);
|
|
5402
|
+
};
|
|
5403
|
+
if (file) infos.set(fd, { kind: "file" });
|
|
5404
|
+
const close = (n) => {
|
|
5405
|
+
forget();
|
|
5406
|
+
kernel.call({ op: "fd-close", fd: n });
|
|
5407
|
+
};
|
|
5408
|
+
const handle = file ? syncFile(kernel, fd, abs, options.append === true, forget) : streamSyncFile(fd, abs, { read: (n, max) => read2(n, max), write: write2, close }, access);
|
|
5409
|
+
handles.set(fd, handle.invalidate);
|
|
5410
|
+
return handle.file;
|
|
5411
|
+
};
|
|
5006
5412
|
const open = (path, options = {}) => {
|
|
5007
5413
|
const abs = resolve(path);
|
|
5414
|
+
if (inDev(abs)) return openDev2(abs, options);
|
|
5008
5415
|
let existing;
|
|
5009
5416
|
try {
|
|
5010
5417
|
existing = statOf(isExclusive(options) ? "lstat" : "stat", abs);
|
|
@@ -5108,17 +5515,30 @@ function syncPathOps(kernel, resolve, statOf, open) {
|
|
|
5108
5515
|
return {
|
|
5109
5516
|
stat: (path) => statOf("stat", path),
|
|
5110
5517
|
lstat: (path) => statOf("lstat", path),
|
|
5111
|
-
exists
|
|
5112
|
-
|
|
5518
|
+
exists(path) {
|
|
5519
|
+
const abs = resolve(path);
|
|
5520
|
+
if (inDev(abs)) return devSync(kernel, devExists(abs));
|
|
5521
|
+
return kernel.json({ op: "exists", path: abs }) === true;
|
|
5522
|
+
},
|
|
5523
|
+
readdir(path) {
|
|
5524
|
+
const abs = resolve(path);
|
|
5525
|
+
if (inDev(abs)) return devSync(kernel, devReaddir(abs));
|
|
5526
|
+
return kernel.json({ op: "readdir", path: abs });
|
|
5527
|
+
},
|
|
5113
5528
|
mkdir: (path) => void kernel.call({ op: "mkdir", path: resolve(path) }),
|
|
5114
5529
|
rm: (path) => void kernel.call({ op: "rm", path: resolve(path) }),
|
|
5115
5530
|
unlink: (path) => void kernel.call({ op: "unlink", path: resolve(path) }),
|
|
5116
5531
|
rename: (from, to) => void kernel.call({ op: "rename", path: resolve(from), arg2: resolve(to) }),
|
|
5117
5532
|
link: (from, to) => void kernel.call({ op: "link", path: resolve(from), arg2: resolve(to) }),
|
|
5118
5533
|
symlink: (target, path) => void kernel.call({ op: "symlink", path: resolve(path), arg2: target }),
|
|
5119
|
-
readlink
|
|
5534
|
+
readlink(path) {
|
|
5535
|
+
const abs = resolve(path);
|
|
5536
|
+
if (inDev(abs)) return devSync(kernel, devReadlink(abs));
|
|
5537
|
+
return String(kernel.json({ op: "readlink", path: abs }));
|
|
5538
|
+
},
|
|
5120
5539
|
readFile(path) {
|
|
5121
5540
|
const abs = resolve(path);
|
|
5541
|
+
if (inDev(abs)) return readWholeSync(open(abs));
|
|
5122
5542
|
kernel.call({ op: "fd-path-flush", path: abs });
|
|
5123
5543
|
return kernel.bytes({ op: "read", path: abs });
|
|
5124
5544
|
},
|
|
@@ -5139,6 +5559,7 @@ var init_js_sync = __esm({
|
|
|
5139
5559
|
init_signals();
|
|
5140
5560
|
init_sync_fs_wire();
|
|
5141
5561
|
init_sync_sab_bridge();
|
|
5562
|
+
init_js_dev();
|
|
5142
5563
|
init_js_io();
|
|
5143
5564
|
init_js_kernel();
|
|
5144
5565
|
encoder3 = new TextEncoder();
|
|
@@ -5539,6 +5960,7 @@ function createContext(o) {
|
|
|
5539
5960
|
const writable2 = (fd) => new WritableStream({ write: (chunk) => write2(fd, chunk) });
|
|
5540
5961
|
const statOf = async (op, path) => {
|
|
5541
5962
|
const abs = resolve(path);
|
|
5963
|
+
if (inDev(abs)) return devAsync(kernel, devStat(abs, op === "stat"));
|
|
5542
5964
|
await kernel.call({ op: "fd-path-flush", path: abs });
|
|
5543
5965
|
const s = parseSyncFsStat(await kernel.json({ op, path: abs }));
|
|
5544
5966
|
if (!s) throw new JsCallError("EIO", op);
|
|
@@ -5546,6 +5968,7 @@ function createContext(o) {
|
|
|
5546
5968
|
};
|
|
5547
5969
|
const open = async (path, options = {}) => {
|
|
5548
5970
|
const abs = resolve(path);
|
|
5971
|
+
if (inDev(abs)) return openDev(kernel, abs, options, { infos, handles, read: read2, write: writeAll });
|
|
5549
5972
|
const existing = await statOf(isExclusive(options) ? "lstat" : "stat", abs).catch(absent);
|
|
5550
5973
|
checkOpen(abs, options, existing);
|
|
5551
5974
|
const fd = await kernel.json(openRequest(abs, options));
|
|
@@ -5565,6 +5988,7 @@ function createContext(o) {
|
|
|
5565
5988
|
};
|
|
5566
5989
|
const fs = pathOps(kernel, resolve, statOf, open);
|
|
5567
5990
|
const lane = o.lane ?? laneOf(void 0);
|
|
5991
|
+
if (o.lane) kernel.syncLane = o.lane;
|
|
5568
5992
|
const syncKernel = new JsSyncKernel(lane, kernel, unwind);
|
|
5569
5993
|
const terminal = ttyOps(kernel);
|
|
5570
5994
|
const sync = {
|
|
@@ -5645,6 +6069,26 @@ function createContext(o) {
|
|
|
5645
6069
|
};
|
|
5646
6070
|
return { ctx, drain: drain2 };
|
|
5647
6071
|
}
|
|
6072
|
+
async function openDev(kernel, abs, options, state) {
|
|
6073
|
+
const { fd, file, ...access } = await devAsync(kernel, devOpen(abs, options));
|
|
6074
|
+
const forget = () => {
|
|
6075
|
+
state.infos.delete(fd);
|
|
6076
|
+
state.handles.delete(fd);
|
|
6077
|
+
};
|
|
6078
|
+
if (file) state.infos.set(fd, { kind: "file" });
|
|
6079
|
+
const close = async (n) => {
|
|
6080
|
+
forget();
|
|
6081
|
+
await kernel.call({ op: "fd-close", fd: n });
|
|
6082
|
+
};
|
|
6083
|
+
const handle = file ? fileHandle(kernel, fd, abs, options.append === true, forget) : streamFile(
|
|
6084
|
+
fd,
|
|
6085
|
+
abs,
|
|
6086
|
+
{ read: (n, max) => state.read(n, max), write: state.write, close },
|
|
6087
|
+
access
|
|
6088
|
+
);
|
|
6089
|
+
state.handles.set(fd, handle.invalidate);
|
|
6090
|
+
return handle.file;
|
|
6091
|
+
}
|
|
5648
6092
|
function fileHandle(kernel, fd, path, append, forget) {
|
|
5649
6093
|
let open = true;
|
|
5650
6094
|
const live = () => {
|
|
@@ -5737,17 +6181,30 @@ function pathOps(kernel, resolve, statOf, open) {
|
|
|
5737
6181
|
return {
|
|
5738
6182
|
stat: (path) => statOf("stat", path),
|
|
5739
6183
|
lstat: (path) => statOf("lstat", path),
|
|
5740
|
-
|
|
5741
|
-
|
|
6184
|
+
async exists(path) {
|
|
6185
|
+
const abs = resolve(path);
|
|
6186
|
+
if (inDev(abs)) return devAsync(kernel, devExists(abs));
|
|
6187
|
+
return await kernel.json({ op: "exists", path: abs }) === true;
|
|
6188
|
+
},
|
|
6189
|
+
async readdir(path) {
|
|
6190
|
+
const abs = resolve(path);
|
|
6191
|
+
if (inDev(abs)) return devAsync(kernel, devReaddir(abs));
|
|
6192
|
+
return await kernel.json({ op: "readdir", path: abs });
|
|
6193
|
+
},
|
|
5742
6194
|
mkdir: async (path) => void await kernel.call({ op: "mkdir", path: resolve(path) }),
|
|
5743
6195
|
rm: async (path) => void await kernel.call({ op: "rm", path: resolve(path) }),
|
|
5744
6196
|
unlink: async (path) => void await kernel.call({ op: "unlink", path: resolve(path) }),
|
|
5745
6197
|
rename: async (from, to) => void await kernel.call({ op: "rename", path: resolve(from), arg2: resolve(to) }),
|
|
5746
6198
|
link: async (from, to) => void await kernel.call({ op: "link", path: resolve(from), arg2: resolve(to) }),
|
|
5747
6199
|
symlink: async (target, path) => void await kernel.call({ op: "symlink", path: resolve(path), arg2: target }),
|
|
5748
|
-
|
|
6200
|
+
async readlink(path) {
|
|
6201
|
+
const abs = resolve(path);
|
|
6202
|
+
if (inDev(abs)) return devAsync(kernel, devReadlink(abs));
|
|
6203
|
+
return String(await kernel.json({ op: "readlink", path: abs }));
|
|
6204
|
+
},
|
|
5749
6205
|
async readFile(path) {
|
|
5750
6206
|
const abs = resolve(path);
|
|
6207
|
+
if (inDev(abs)) return readWhole(await open(abs));
|
|
5751
6208
|
await kernel.call({ op: "fd-path-flush", path: abs });
|
|
5752
6209
|
return kernel.bytes({ op: "read", path: abs });
|
|
5753
6210
|
},
|
|
@@ -5768,6 +6225,7 @@ var init_js_context = __esm({
|
|
|
5768
6225
|
init_signals();
|
|
5769
6226
|
init_sync_fs_wire();
|
|
5770
6227
|
init_js_children();
|
|
6228
|
+
init_js_dev();
|
|
5771
6229
|
init_js_exit();
|
|
5772
6230
|
init_js_fetch();
|
|
5773
6231
|
init_js_io();
|
|
@@ -6422,7 +6880,7 @@ function createStreamOps(h) {
|
|
|
6422
6880
|
}
|
|
6423
6881
|
}
|
|
6424
6882
|
};
|
|
6425
|
-
const
|
|
6883
|
+
const opened2 = (node, on, want = 0) => {
|
|
6426
6884
|
const s = node.live;
|
|
6427
6885
|
try {
|
|
6428
6886
|
const handle = bridgeOf(node).hold?.(liveNodePath(node), on, true, s.handle, want);
|
|
@@ -6473,7 +6931,7 @@ function createStreamOps(h) {
|
|
|
6473
6931
|
const want = permitted(stream, created);
|
|
6474
6932
|
live.openCount++;
|
|
6475
6933
|
counted = true;
|
|
6476
|
-
if (live.openCount === 1)
|
|
6934
|
+
if (live.openCount === 1) opened2(stream.node, true, want);
|
|
6477
6935
|
} catch (err) {
|
|
6478
6936
|
if (counted) live.openCount--;
|
|
6479
6937
|
if (stream.fd !== void 0) Fs.closeStream?.(stream.fd);
|
|
@@ -6504,7 +6962,7 @@ function createStreamOps(h) {
|
|
|
6504
6962
|
s.len = 0;
|
|
6505
6963
|
s.loaded = false;
|
|
6506
6964
|
held(stream, -1);
|
|
6507
|
-
|
|
6965
|
+
opened2(node, false);
|
|
6508
6966
|
}
|
|
6509
6967
|
},
|
|
6510
6968
|
read(stream, buffer, offset, length, position) {
|
|
@@ -7028,8 +7486,8 @@ var init_kernel_streams = __esm({
|
|
|
7028
7486
|
fs.readdir = (path) => {
|
|
7029
7487
|
const names = readdir.call(fs, path);
|
|
7030
7488
|
if (path.replace(/\/+$/, "") !== "/dev") return names;
|
|
7031
|
-
const
|
|
7032
|
-
return [...names, ...
|
|
7489
|
+
const missing2 = ttyNames().map((tty) => tty.slice("/dev/".length)).filter((name2) => TTY_NAME.test(name2) && !names.includes(name2));
|
|
7490
|
+
return [...names, ...missing2];
|
|
7033
7491
|
};
|
|
7034
7492
|
}
|
|
7035
7493
|
ttyNode(name2) {
|
|
@@ -7807,13 +8265,13 @@ function describeFdDir(Fs) {
|
|
|
7807
8265
|
return;
|
|
7808
8266
|
}
|
|
7809
8267
|
const ops = dir?.node_ops;
|
|
7810
|
-
const
|
|
7811
|
-
if (!dir || !
|
|
8268
|
+
const lookup2 = ops?.lookup;
|
|
8269
|
+
if (!dir || !lookup2 || ops.getattr) return;
|
|
7812
8270
|
dir.node_ops = {
|
|
7813
8271
|
...ops,
|
|
7814
8272
|
getattr: () => syntheticAttr(DIR_MODE, 1),
|
|
7815
8273
|
lookup: (parent, name2) => {
|
|
7816
|
-
const entry =
|
|
8274
|
+
const entry = lookup2(parent, name2);
|
|
7817
8275
|
entry.node_ops = {
|
|
7818
8276
|
...entry.node_ops,
|
|
7819
8277
|
getattr: () => syntheticAttr(LINK_MODE, entry.id ?? 0)
|
|
@@ -8353,7 +8811,7 @@ function createProcessKernel(deps) {
|
|
|
8353
8811
|
if (!stream) return { none: true };
|
|
8354
8812
|
promote?.(stream);
|
|
8355
8813
|
if (stream.sliccKernelFd !== void 0) return { fd: stream.sliccKernelFd };
|
|
8356
|
-
if (((stream.node?.mode ?? 0) &
|
|
8814
|
+
if (((stream.node?.mode ?? 0) & S_IFMT2) === S_IFDIR2 && stream.path) return { dir: stream.path };
|
|
8357
8815
|
const device2 = deviceOfStream(stream);
|
|
8358
8816
|
if (device2) return device2;
|
|
8359
8817
|
return n === 0 ? { input: drain(Fs, stream) } : { capture: true };
|
|
@@ -8500,13 +8958,13 @@ function createProcessKernel(deps) {
|
|
|
8500
8958
|
}
|
|
8501
8959
|
};
|
|
8502
8960
|
}
|
|
8503
|
-
var
|
|
8961
|
+
var S_IFMT2, S_IFDIR2, POLLIN2, POLLOUT2, POLLERR2, POLLHUP2, POLLNVAL, SELECT_SLICE_MS, WUNTRACED, WCONTINUED;
|
|
8504
8962
|
var init_process_children = __esm({
|
|
8505
8963
|
"src/process/process-children.ts"() {
|
|
8506
8964
|
"use strict";
|
|
8507
8965
|
init_process_fork();
|
|
8508
8966
|
init_wasi_errno();
|
|
8509
|
-
|
|
8967
|
+
S_IFMT2 = 61440;
|
|
8510
8968
|
S_IFDIR2 = 16384;
|
|
8511
8969
|
POLLIN2 = 1;
|
|
8512
8970
|
POLLOUT2 = 4;
|
|
@@ -9081,7 +9539,7 @@ function useProcfs(Fs, sys, pid, memory = memorySource()) {
|
|
|
9081
9539
|
return found;
|
|
9082
9540
|
};
|
|
9083
9541
|
const procOps = proc.node_ops;
|
|
9084
|
-
const
|
|
9542
|
+
const lookup2 = procOps.lookup?.bind(procOps);
|
|
9085
9543
|
const readdir = procOps.readdir?.bind(procOps);
|
|
9086
9544
|
const listAll = (node) => {
|
|
9087
9545
|
const names = new Set(readdir ? readdir(node) : [".", ".."]);
|
|
@@ -9104,8 +9562,8 @@ function useProcfs(Fs, sys, pid, memory = memorySource()) {
|
|
|
9104
9562
|
() => systemFile(name2, procList(), Date.now(), memory)
|
|
9105
9563
|
);
|
|
9106
9564
|
}
|
|
9107
|
-
if (!
|
|
9108
|
-
return
|
|
9565
|
+
if (!lookup2) throw error();
|
|
9566
|
+
return lookup2(parent, name2);
|
|
9109
9567
|
},
|
|
9110
9568
|
readdir: (node) => listAll(node)
|
|
9111
9569
|
};
|
|
@@ -11840,8 +12298,8 @@ var init_wasix_host = __esm({
|
|
|
11840
12298
|
mem.view().setUint16(out, host.fds.cloexec.has(fd) ? FDFLAGSEXT_CLOEXEC : 0, true);
|
|
11841
12299
|
},
|
|
11842
12300
|
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,
|
|
12301
|
+
path_open2: (dirfd, lookup2, p, l, oflags, rights, inheriting, fdflags, fdflagsext, out) => {
|
|
12302
|
+
const r = preview1.path_open(dirfd, lookup2, p, l, oflags, rights, inheriting, fdflags, out);
|
|
11845
12303
|
if (r === E.SUCCESS && fdflagsext & FDFLAGSEXT_CLOEXEC)
|
|
11846
12304
|
host.fds.setCloexec(mem.view().getUint32(out, true), true);
|
|
11847
12305
|
return r;
|