@amritk/nish-aarch64-linux 0.38.0 → 0.39.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/bin/nish +0 -0
- package/docs/AI.md +348 -37
- package/package.json +1 -1
- package/runtime/core/host.d.ts +11 -0
- package/runtime/core/host.mjs +35 -0
- package/runtime/nish.d.ts +301 -18
- package/runtime/nish.h +74 -10
- package/runtime/nish.mjs +69 -6
- package/runtime/node.mjs +117 -0
- package/runtime/runtime-aes.c +12 -4
- package/runtime/runtime-async.c +43 -10
- package/runtime/runtime-checksum.c +207 -15
- package/runtime/runtime-net.c +32 -3
- package/runtime/runtime-os.c +174 -27
- package/runtime/runtime-region.c +94 -10
- package/runtime/runtime-sandbox.c +377 -17
- package/runtime/runtime-sha256.c +11 -4
- package/runtime/runtime-wasm.c +15 -0
- package/runtime/runtime.c +5 -0
- package/scripts/build.sh +27 -8
- package/std/README.md +5 -4
- package/std/compress/checksum.ts +13 -0
- package/std/compress/deflate.ts +0 -2
- package/std/crypto/p256.ts +247 -74
- package/std/crypto/p384.ts +3 -1
- package/std/crypto/pki.ts +35 -9
- package/std/crypto/x25519.ts +153 -64
- package/std/crypto/x509.ts +113 -10
- package/std/json-tokenizer.ts +20 -0
- package/std/json-typed.ts +217 -8
- package/std/net/handler.ts +130 -16
- package/std/net/http1-codec.ts +499 -150
- package/std/net/http1-server.ts +495 -22
- package/std/net/http2-cleartext.ts +526 -0
- package/std/net/http2-tls.ts +48 -0
- package/std/net/http2.ts +84 -0
- package/std/net/postgres-async.ts +1304 -86
- package/std/net/postgres-carrier.ts +343 -10
- package/std/net/postgres.ts +122 -7
- package/std/net/prefork.ts +195 -11
- package/std/net/quic-datagram.ts +30 -0
- package/std/net/quic-listener.ts +38 -12
- package/std/net/quic-packet.ts +19 -6
- package/std/net/quic-recovery.ts +134 -19
- package/std/net/quic-stream.ts +174 -36
- package/std/net/quic.ts +418 -18
- package/std/net/router.ts +39 -17
- package/std/net/serve.ts +162 -58
- package/std/net/tls/codec.ts +110 -32
- package/std/net/tls/record-server.ts +37 -7
- package/std/net/tls-tcp.ts +56 -1
- package/std/net/tls.ts +196 -50
- package/std/net/websocket.ts +55 -18
- package/std/net/webtransport.ts +179 -1
- package/std/regex.ts +69 -47
- package/std/region.ts +62 -11
- package/std/secret.ts +26 -59
- package/std/text.ts +233 -0
package/runtime/core/host.mjs
CHANGED
|
@@ -137,6 +137,30 @@ export function readFileBytesSync(path) {
|
|
|
137
137
|
return host.call("readFileBytesSync", [path]);
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
export function fileOpen(path) {
|
|
141
|
+
return host.call("fileOpen", [path]);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* `fileReadAt(fd, buf, off, len, pos)`: the window checked as the compiled
|
|
146
|
+
* call checks it, `0 <= off <= off + len <= buf.length`, through the slice
|
|
147
|
+
* panic, then the host's positional read.
|
|
148
|
+
*/
|
|
149
|
+
export function fileReadAt(fd, buf, off, len, pos) {
|
|
150
|
+
const from = toIndex(off);
|
|
151
|
+
const to = from + toIndex(len);
|
|
152
|
+
if (!(from >= 0 && from <= to && to <= buf.length)) panicSlice(from, to, buf.length);
|
|
153
|
+
return host.call("fileReadAt", [fd, buf, from, to - from, BigInt(pos)]);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function fileSize(fd) {
|
|
157
|
+
return host.call("fileSize", [fd]);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function fileClose(fd) {
|
|
161
|
+
return host.call("fileClose", [fd]);
|
|
162
|
+
}
|
|
163
|
+
|
|
140
164
|
export function writeFileSync(path, data) {
|
|
141
165
|
return host.call("writeFileSync", [path, data]);
|
|
142
166
|
}
|
|
@@ -217,6 +241,17 @@ export function spawnPiped(argv, input, out, err) {
|
|
|
217
241
|
return status;
|
|
218
242
|
}
|
|
219
243
|
|
|
244
|
+
/**
|
|
245
|
+
* `spawnPipedWithin(argv, stdin, stdout, stderr, timeoutMs)`: `spawnPiped`
|
|
246
|
+
* with a deadline the host enforces, and -3 when it passed.
|
|
247
|
+
*/
|
|
248
|
+
export function spawnPipedWithin(argv, input, out, err, timeoutMs) {
|
|
249
|
+
const [status, outBytes, errBytes] = host.call("spawnPipedWithin", [argv, input, timeoutMs]);
|
|
250
|
+
for (const b of outBytes) out.push(b);
|
|
251
|
+
for (const b of errBytes) err.push(b);
|
|
252
|
+
return status;
|
|
253
|
+
}
|
|
254
|
+
|
|
220
255
|
export function kill(pid, sig) {
|
|
221
256
|
return host.call("kill", [pid, sig]);
|
|
222
257
|
}
|
package/runtime/nish.d.ts
CHANGED
|
@@ -707,7 +707,7 @@ declare function isExecutableSync(path: string): boolean;
|
|
|
707
707
|
// ---- Unsafe (`nish:unsafe`) --------------------------------------------------
|
|
708
708
|
//
|
|
709
709
|
// Declared as globals so `tsc` reads a program that imports them, as every
|
|
710
|
-
// `nish:` export is, but `nish` refuses a call to any of the
|
|
710
|
+
// `nish:` export is, but `nish` refuses a call to any of the eight that is not
|
|
711
711
|
// imported from `nish:unsafe`: the import is the module's visible opt-in. The
|
|
712
712
|
// refusal reads `` `uncheckedGet` is a `nish:unsafe` function and is called only
|
|
713
713
|
// through an import of it `` (NL2456). An import may rename (`as`) and cannot be
|
|
@@ -822,6 +822,50 @@ declare function wrappingMul<T extends i32 | i64>(a: T, b: T): T;
|
|
|
822
822
|
* @returns a copy of the bytes before the first `NUL`.
|
|
823
823
|
*/
|
|
824
824
|
declare function readCString(p: CPtr): string;
|
|
825
|
+
/**
|
|
826
|
+
* A copy of the C struct at `p`, in a new instance of the `declare class` the
|
|
827
|
+
* call's context names: `const lc: Lconv = readStruct(localeconv())`. A type
|
|
828
|
+
* argument is not written at a call site (`readStruct<Lconv>(p)` is refused,
|
|
829
|
+
* as `identity<i32>(7)` is), so the layout comes from an annotation, a
|
|
830
|
+
* parameter or a return type, as `Ok(v)`'s type does; a call with none, or one
|
|
831
|
+
* whose context is not a `declare class`, is refused. It copies the layout's
|
|
832
|
+
* size in bytes, so the class must describe the struct's first fields (a
|
|
833
|
+
* prefix is enough) and `p` must point at that many readable bytes: undefined
|
|
834
|
+
* behaviour otherwise, as with `readCString`.
|
|
835
|
+
*
|
|
836
|
+
* The copy is the program's own: C may free or overwrite its struct straight
|
|
837
|
+
* after the call, and a `CPtr` field of the copy is still C's pointer, read
|
|
838
|
+
* with `readCString` while C keeps it live. The parameter is `CPtr`, so an
|
|
839
|
+
* unnarrowed `CPtr | null` is refused and `if (p !== null)` comes first.
|
|
840
|
+
*
|
|
841
|
+
* A `NULL` `p` is tested before the copy and panics with the `ffi-null` kind,
|
|
842
|
+
* naming the layout, since a `declare function` declared to answer `CPtr` may
|
|
843
|
+
* still answer `NULL`. No proof removes that test, so `--deny-panics` refuses
|
|
844
|
+
* the call; `--emit-panics` lists it as an `ffi-null` site, with the copy's
|
|
845
|
+
* `oom` beside it.
|
|
846
|
+
*
|
|
847
|
+
* The copy is new on every call and is the calling function's allocation, held
|
|
848
|
+
* by the arena like `new`. It lowers the same on wasm32, where a pointer is 4
|
|
849
|
+
* bytes and the layout is sized to match. It has no Node form.
|
|
850
|
+
* Capability: unsafe.
|
|
851
|
+
*
|
|
852
|
+
* @param p the address of a C struct a `declare function` handed back.
|
|
853
|
+
* @returns a copy of the struct, in the `declare class` its context names.
|
|
854
|
+
*/
|
|
855
|
+
declare function readStruct<T>(p: CPtr): T;
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* `cErrno()`, from `nish:unsafe` (WP27 S5): the errno the most recent
|
|
859
|
+
* `declare function` call on this thread left, or 0 before any. Naming it
|
|
860
|
+
* anywhere in a program makes every foreign call zero errno just before it
|
|
861
|
+
* and save it just after, before the result is copied or anything allocated,
|
|
862
|
+
* so the runtime's own work after the call cannot change it. Meaningful only
|
|
863
|
+
* where the C function documents that it sets errno. Per thread; refused on a
|
|
864
|
+
* freestanding wasm32 build, which has no libc. Capability: unsafe.
|
|
865
|
+
*
|
|
866
|
+
* @returns the saved errno, an `i32`.
|
|
867
|
+
*/
|
|
868
|
+
declare function cErrno(): i32;
|
|
825
869
|
|
|
826
870
|
// ---- Streams and files (globals: Nish has no package resolution) ---------
|
|
827
871
|
|
|
@@ -923,6 +967,56 @@ declare function readFileSyncOrNull(path: string): string | null;
|
|
|
923
967
|
* @returns its bytes, or `null`.
|
|
924
968
|
*/
|
|
925
969
|
declare function readFileBytesSync(path: string): u8[] | null;
|
|
970
|
+
/**
|
|
971
|
+
* Open a regular file to read a window at a time (WP44): read-only,
|
|
972
|
+
* close-on-exec and non-blocking, so a FIFO or a device never waits. A
|
|
973
|
+
* directory is refused with `-21` and any other kind that is not a regular
|
|
974
|
+
* file with `-22`, the descriptor closed again first. Pair it with `fileClose`
|
|
975
|
+
* in a `try`/`finally`. A freestanding `wasm32` build refuses the call (NL2718);
|
|
976
|
+
* `--profile wasi` reads through WASI. Capability: fs.read.
|
|
977
|
+
*
|
|
978
|
+
* @param path the file to open; a NUL in it is refused as a missing path is.
|
|
979
|
+
* @returns a descriptor (`>= 0`), or the negated Linux errno: `-2` ENOENT,
|
|
980
|
+
* `-13` EACCES, `-20` ENOTDIR, `-21` EISDIR, `-22` EINVAL for a FIFO or
|
|
981
|
+
* device, `-6` ENXIO for a socket, `-23` ENFILE, `-24` EMFILE, `-36`
|
|
982
|
+
* ENAMETOOLONG, `-40` ELOOP; anything else is `-5` EIO.
|
|
983
|
+
*/
|
|
984
|
+
declare function fileOpen(path: string): i32;
|
|
985
|
+
/**
|
|
986
|
+
* Read up to `len` bytes from byte `pos` of the file into `buf[off .. off +
|
|
987
|
+
* len)`, without moving any shared offset (`pread`). The window is checked as
|
|
988
|
+
* `buf.slice` checks it and panics the same way when it falls outside `buf`.
|
|
989
|
+
* The array is never grown: memory follows the window. Capability: fs.read.
|
|
990
|
+
*
|
|
991
|
+
* @param fd a descriptor from `fileOpen`.
|
|
992
|
+
* @param buf the array the bytes land in; its length is unchanged.
|
|
993
|
+
* @param off where in `buf` the first byte lands.
|
|
994
|
+
* @param len the most bytes to read.
|
|
995
|
+
* @param pos the file offset to read from, an `i64`.
|
|
996
|
+
* @returns the bytes read, `0` at end of file (and for a `len` of `0`, even on
|
|
997
|
+
* a closed or negative descriptor), or a negative errno: `-22`
|
|
998
|
+
* EINVAL for a negative `pos` or one where `pos + len` overflows, `-9` EBADF
|
|
999
|
+
* for a closed or negative descriptor, `-21` EISDIR, `-29` ESPIPE; anything
|
|
1000
|
+
* else is `-5` EIO.
|
|
1001
|
+
*/
|
|
1002
|
+
declare function fileReadAt(fd: i32, buf: u8[], off: i32, len: i32, pos: i64): i32;
|
|
1003
|
+
/**
|
|
1004
|
+
* The file's size in bytes now, from `fstat`: a file may grow or shrink between
|
|
1005
|
+
* this and a read, which then answers what is there. Capability: fs.read.
|
|
1006
|
+
*
|
|
1007
|
+
* @param fd a descriptor from `fileOpen`.
|
|
1008
|
+
* @returns the size, an `i64` past 2^31 when the file is, or a negative errno
|
|
1009
|
+
* (`-9` EBADF for a closed descriptor).
|
|
1010
|
+
*/
|
|
1011
|
+
declare function fileSize(fd: i32): i64;
|
|
1012
|
+
/**
|
|
1013
|
+
* Close a descriptor `fileOpen` gave. A second close answers `-9`, unless the
|
|
1014
|
+
* number has been handed out again since, so close once. Capability: fs.read.
|
|
1015
|
+
*
|
|
1016
|
+
* @param fd a descriptor from `fileOpen`.
|
|
1017
|
+
* @returns `0`, or a negative errno (`-9` EBADF).
|
|
1018
|
+
*/
|
|
1019
|
+
declare function fileClose(fd: i32): i32;
|
|
926
1020
|
/**
|
|
927
1021
|
* The file's contents replaced by `data`, created at 0644 when missing;
|
|
928
1022
|
* statement position. A symbolic link as the last component of the path is
|
|
@@ -1108,6 +1202,14 @@ declare function realpathSync(path: string): string | null;
|
|
|
1108
1202
|
* an embedded NUL truncates one. A `wasm32` build and a WASI build have no
|
|
1109
1203
|
* processes, and a WASI build always answers `-1`. Capability: process.spawn.
|
|
1110
1204
|
*
|
|
1205
|
+
* Under `--sandbox`, a dependency's `process.spawn=<program>` grants can make
|
|
1206
|
+
* a list of the only programs the build may start. A program this builtin
|
|
1207
|
+
* starts under such a list cannot start another: an exec by it, or by
|
|
1208
|
+
* anything it forks, fails, so a granted `#!` script runs its interpreter's
|
|
1209
|
+
* builtins alone. Where the kernel or a container's seccomp profile refuses
|
|
1210
|
+
* what that takes (Docker's default profile does), the spawn fails and one
|
|
1211
|
+
* line on stderr says so.
|
|
1212
|
+
*
|
|
1111
1213
|
* @param argv the program and its arguments.
|
|
1112
1214
|
* @returns the exit status, or `128 + n` when signal `n` killed it (the shell's
|
|
1113
1215
|
* convention), or `-1` when the vector is empty — there is no `argv[0]` to
|
|
@@ -1123,6 +1225,9 @@ declare function spawnSync(argv: string[]): number;
|
|
|
1123
1225
|
* separately, with its own offset, so the streams would overwrite rather than
|
|
1124
1226
|
* interleave; capture them apart and concatenate. Capability: process.spawn.
|
|
1125
1227
|
*
|
|
1228
|
+
* Under `--sandbox` with a list of granted programs, the program started
|
|
1229
|
+
* cannot start another, as for `spawnSync`.
|
|
1230
|
+
*
|
|
1126
1231
|
* @param argv the program and its arguments.
|
|
1127
1232
|
* @param stdoutPath the file the child's stdout goes to, or `""`.
|
|
1128
1233
|
* @param stderrPath the file the child's stderr goes to, or `""`.
|
|
@@ -1149,6 +1254,9 @@ declare function spawnSyncTo(argv: string[], stdoutPath: string, stderrPath: str
|
|
|
1149
1254
|
* length is fixed. A `wasm32` build refuses it (NL2404). Capability:
|
|
1150
1255
|
* process.spawn.
|
|
1151
1256
|
*
|
|
1257
|
+
* Under `--sandbox` with a list of granted programs, the program started
|
|
1258
|
+
* cannot start another, as for `spawnSync`.
|
|
1259
|
+
*
|
|
1152
1260
|
* @param argv the program and its arguments.
|
|
1153
1261
|
* @param stdin the bytes the child reads.
|
|
1154
1262
|
* @param stdout receives what the child prints on stdout.
|
|
@@ -1158,6 +1266,43 @@ declare function spawnSyncTo(argv: string[], stdoutPath: string, stderrPath: str
|
|
|
1158
1266
|
* that fails, and a WASI build), or `-2` when a stream passed 16 MiB.
|
|
1159
1267
|
*/
|
|
1160
1268
|
declare function spawnPiped(argv: string[], stdin: readonly u8[], stdout: u8[], stderr: u8[]): i32;
|
|
1269
|
+
/**
|
|
1270
|
+
* `spawnPiped` with a deadline: the same captured run, killed once `timeoutMs`
|
|
1271
|
+
* milliseconds have passed since it started. A negative `timeoutMs` is no
|
|
1272
|
+
* deadline, as `pollWait`'s is, so `spawnPipedWithin(argv, stdin, stdout,
|
|
1273
|
+
* stderr, -1)` is `spawnPiped(argv, stdin, stdout, stderr)`. When the deadline
|
|
1274
|
+
* passes the child is killed with `SIGKILL` and reaped, the answer is `-3`, and
|
|
1275
|
+
* `stdout` and `stderr` keep every byte read before the kill.
|
|
1276
|
+
*
|
|
1277
|
+
* The deadline covers the whole run, the wait for the child's exit included,
|
|
1278
|
+
* and is measured on the monotonic clock. Only the child's own pid is killed:
|
|
1279
|
+
* a grandchild it started is not, and one that keeps an output pipe open makes
|
|
1280
|
+
* the run wait for it, so a child that exited 0 can still answer `-3`. The
|
|
1281
|
+
* rest is `spawnPiped`'s: the same environment, descriptors, SIGPIPE handling
|
|
1282
|
+
* and 16 MiB cap, `readonly` and typed-array spellings refused for the two
|
|
1283
|
+
* output arrays, refused by a `wasm32` build (NL2404). Capability:
|
|
1284
|
+
* process.spawn.
|
|
1285
|
+
*
|
|
1286
|
+
* Under `--sandbox` with a list of granted programs, the program started
|
|
1287
|
+
* cannot start another, as for `spawnSync`.
|
|
1288
|
+
*
|
|
1289
|
+
* @param argv the program and its arguments.
|
|
1290
|
+
* @param stdin the bytes the child reads.
|
|
1291
|
+
* @param stdout receives what the child prints on stdout.
|
|
1292
|
+
* @param stderr receives what the child prints on stderr.
|
|
1293
|
+
* @param timeoutMs the milliseconds the run may take, or a negative number for
|
|
1294
|
+
* no deadline.
|
|
1295
|
+
* @returns the status as `spawnPiped` answers it (the exit code, `128 + n`,
|
|
1296
|
+
* `-1` for a child that cannot be started or a WASI build, `-2` when a stream
|
|
1297
|
+
* passed 16 MiB), or `-3` when the deadline passed and the child was killed.
|
|
1298
|
+
*/
|
|
1299
|
+
declare function spawnPipedWithin(
|
|
1300
|
+
argv: string[],
|
|
1301
|
+
stdin: readonly u8[],
|
|
1302
|
+
stdout: u8[],
|
|
1303
|
+
stderr: u8[],
|
|
1304
|
+
timeoutMs: i32
|
|
1305
|
+
): i32;
|
|
1161
1306
|
/**
|
|
1162
1307
|
* `spawn` with the child holding `fds[i]` as descriptor `3 + i`, close-on-exec
|
|
1163
1308
|
* cleared there. Its streams 0 to 2 are this process's, and no other descriptor
|
|
@@ -1170,12 +1315,18 @@ declare function spawnPiped(argv: string[], stdin: readonly u8[], stdout: u8[],
|
|
|
1170
1315
|
* under Node, which throws. A `wasm32` build refuses it (NL2404).
|
|
1171
1316
|
* Capability: process.spawn.
|
|
1172
1317
|
*
|
|
1318
|
+
* Under `--sandbox` with a list of granted programs, the program started
|
|
1319
|
+
* cannot start another, as for `spawnSync`.
|
|
1320
|
+
*
|
|
1173
1321
|
* @param argv the program and its arguments.
|
|
1174
1322
|
* @param fds the descriptors handed down, at most 64.
|
|
1175
1323
|
* @returns the child's pid, or a negative errno: -22 more than 64 descriptors
|
|
1176
1324
|
* or a negative one (before anything is opened or started), -9 one that is
|
|
1177
1325
|
* not open, -24 (or -22 above the descriptor limit) a scratch descriptor the
|
|
1178
|
-
* system cannot give.
|
|
1326
|
+
* system cannot give. Under `--sandbox` with a list of granted
|
|
1327
|
+
* programs, a spawn that cannot be held to one program is refused: -11
|
|
1328
|
+
* (EAGAIN), -38 (ENOSYS), -10 (ECHILD) or the kernel's own error, with a line
|
|
1329
|
+
* on stderr.
|
|
1179
1330
|
*/
|
|
1180
1331
|
declare function spawnWithFds(argv: string[], fds: readonly i32[]): i32;
|
|
1181
1332
|
/**
|
|
@@ -1190,10 +1341,16 @@ declare function spawnWithFds(argv: string[], fds: readonly i32[]): i32;
|
|
|
1190
1341
|
* `nish:process`.
|
|
1191
1342
|
* Capability: process.spawn.
|
|
1192
1343
|
*
|
|
1344
|
+
* Under `--sandbox` with a list of granted programs, the program started
|
|
1345
|
+
* cannot start another, as for `spawnSync`.
|
|
1346
|
+
*
|
|
1193
1347
|
* @param argv the program and its arguments.
|
|
1194
1348
|
* @returns the child's pid, or a negative errno: -22 (EINVAL) for an empty
|
|
1195
1349
|
* vector or an argument holding a NUL, and `posix_spawnp`'s own error
|
|
1196
|
-
* otherwise, so a program that is not there is -2 (ENOENT).
|
|
1350
|
+
* otherwise, so a program that is not there is -2 (ENOENT). Under `--sandbox` with a list of granted
|
|
1351
|
+
* programs, a spawn that cannot be held to one program is refused: -11
|
|
1352
|
+
* (EAGAIN), -38 (ENOSYS), -10 (ECHILD) or the kernel's own error, with a line
|
|
1353
|
+
* on stderr.
|
|
1197
1354
|
*/
|
|
1198
1355
|
declare function spawn(argv: string[]): i32;
|
|
1199
1356
|
/**
|
|
@@ -1628,8 +1785,11 @@ declare function connectResult(fd: i32): i32;
|
|
|
1628
1785
|
* @param host the numeric address to bind.
|
|
1629
1786
|
* @param port the port, 0 for any.
|
|
1630
1787
|
* @param flags flag 1 `SO_REUSEPORT`, so several sockets that all ask for it share a port and
|
|
1631
|
-
* the kernel spreads the datagrams across them; flag 2 `UDP_GRO` (-95 on Darwin);
|
|
1632
|
-
*
|
|
1788
|
+
* the kernel spreads the datagrams across them; flag 2 `UDP_GRO` (-95 on Darwin); flag 4, with
|
|
1789
|
+
* flag 1 and a group size N from 1 to 255 in bits 8 to 15, steers QUIC: the port's group hands
|
|
1790
|
+
* each datagram to its socket number (byte 0 of the Destination Connection ID) mod N, in the
|
|
1791
|
+
* order the sockets were bound, and a refused attach closes the socket and answers the errno
|
|
1792
|
+
* (-95 on Darwin). Flag 4 without 1, with 2 or with N 0, N without 4, or any other bit is -22.
|
|
1633
1793
|
* @returns the socket's descriptor, or a negative errno.
|
|
1634
1794
|
*/
|
|
1635
1795
|
declare function udpBind(host: string, port: i32, flags: i32): i32;
|
|
@@ -2333,6 +2493,48 @@ declare module "nish:fs" {
|
|
|
2333
2493
|
* answers `null` for.
|
|
2334
2494
|
*/
|
|
2335
2495
|
export function readFileBytesSync(path: string): u8[] | null;
|
|
2496
|
+
/**
|
|
2497
|
+
* Open a regular file to read a window at a time: read-only, close-on-exec
|
|
2498
|
+
* and non-blocking. A directory is `-21`, any other kind that is not a
|
|
2499
|
+
* regular file `-22`. Close it with `fileClose` in a `finally`.
|
|
2500
|
+
*
|
|
2501
|
+
* @param path The file to open.
|
|
2502
|
+
* @returns A descriptor (`>= 0`), or the negated Linux errno: `-2` ENOENT,
|
|
2503
|
+
* `-13` EACCES, `-20` ENOTDIR, `-21` EISDIR, `-22` for a FIFO or device,
|
|
2504
|
+
* `-6` ENXIO for a socket, `-23` ENFILE, `-24` EMFILE, `-36` ENAMETOOLONG,
|
|
2505
|
+
* `-40` ELOOP; anything else is `-5` EIO.
|
|
2506
|
+
*/
|
|
2507
|
+
export function fileOpen(path: string): i32;
|
|
2508
|
+
/**
|
|
2509
|
+
* Read up to `len` bytes from file offset `pos` into `buf[off .. off + len)`
|
|
2510
|
+
* (`pread`). The window panics as `buf.slice` does when it falls outside
|
|
2511
|
+
* `buf`; the array is never grown.
|
|
2512
|
+
*
|
|
2513
|
+
* @param fd A descriptor from `fileOpen`.
|
|
2514
|
+
* @param buf The array the bytes land in.
|
|
2515
|
+
* @param off Where in `buf` the first byte lands.
|
|
2516
|
+
* @param len The most bytes to read.
|
|
2517
|
+
* @param pos The file offset, an `i64`.
|
|
2518
|
+
* @returns The bytes read, `0` at end of file (and for a `len` of `0`, even
|
|
2519
|
+
* on a closed or negative descriptor), or a negative errno: `-22`
|
|
2520
|
+
* for a negative or overflowing `pos`, `-9` for a closed or negative
|
|
2521
|
+
* descriptor, `-21` EISDIR, `-29` ESPIPE; anything else is `-5` EIO.
|
|
2522
|
+
*/
|
|
2523
|
+
export function fileReadAt(fd: i32, buf: u8[], off: i32, len: i32, pos: i64): i32;
|
|
2524
|
+
/**
|
|
2525
|
+
* The file's size in bytes now, from `fstat`.
|
|
2526
|
+
*
|
|
2527
|
+
* @param fd A descriptor from `fileOpen`.
|
|
2528
|
+
* @returns The size, or a negative errno.
|
|
2529
|
+
*/
|
|
2530
|
+
export function fileSize(fd: i32): i64;
|
|
2531
|
+
/**
|
|
2532
|
+
* Close a descriptor `fileOpen` gave; close it once.
|
|
2533
|
+
*
|
|
2534
|
+
* @param fd A descriptor from `fileOpen`.
|
|
2535
|
+
* @returns `0`, or a negative errno (`-9` EBADF).
|
|
2536
|
+
*/
|
|
2537
|
+
export function fileClose(fd: i32): i32;
|
|
2336
2538
|
/**
|
|
2337
2539
|
* Create or truncate the file at mode `0644` and write `data`; a statement,
|
|
2338
2540
|
* not a value. A symbolic link as the last component of `path` is refused
|
|
@@ -2620,6 +2822,32 @@ declare module "nish:process" {
|
|
|
2620
2822
|
* 16 MiB.
|
|
2621
2823
|
*/
|
|
2622
2824
|
export function spawnPiped(argv: string[], stdin: readonly u8[], stdout: u8[], stderr: u8[]): i32;
|
|
2825
|
+
/**
|
|
2826
|
+
* `spawnPiped` with a deadline: the same captured run, killed with `SIGKILL`
|
|
2827
|
+
* and reaped once `timeoutMs` milliseconds have passed since it started, and
|
|
2828
|
+
* a negative `timeoutMs` is no deadline, so `-1` makes it `spawnPiped`. The
|
|
2829
|
+
* deadline covers the whole run, the wait for the child's exit included, on
|
|
2830
|
+
* the monotonic clock. Only the child's pid is killed, never a grandchild,
|
|
2831
|
+
* and a grandchild that keeps an output pipe open makes the run wait for it
|
|
2832
|
+
* until the deadline.
|
|
2833
|
+
*
|
|
2834
|
+
* @param argv The program and its arguments.
|
|
2835
|
+
* @param stdin The bytes the child reads.
|
|
2836
|
+
* @param stdout Grows by the child's stdout, the bytes read before a kill
|
|
2837
|
+
* included; neither `readonly` nor a typed array.
|
|
2838
|
+
* @param stderr Grows by the child's stderr, under the same rule.
|
|
2839
|
+
* @param timeoutMs The milliseconds the run may take; negative for none.
|
|
2840
|
+
* @returns `spawnPiped`'s answer (the status or `128 + n`, `-1`, or `-2` for
|
|
2841
|
+
* a stream past 16 MiB), or `-3` when the deadline passed and the child was
|
|
2842
|
+
* killed.
|
|
2843
|
+
*/
|
|
2844
|
+
export function spawnPipedWithin(
|
|
2845
|
+
argv: string[],
|
|
2846
|
+
stdin: readonly u8[],
|
|
2847
|
+
stdout: u8[],
|
|
2848
|
+
stderr: u8[],
|
|
2849
|
+
timeoutMs: i32
|
|
2850
|
+
): i32;
|
|
2623
2851
|
/**
|
|
2624
2852
|
* Start `argv[0]`, searched on `PATH`, exactly as `spawnSync` does (the same
|
|
2625
2853
|
* vector, environment, streams and working directory), without waiting. The
|
|
@@ -2630,7 +2858,10 @@ declare module "nish:process" {
|
|
|
2630
2858
|
* @param argv The program and its arguments.
|
|
2631
2859
|
* @returns The child's pid, or a negative errno: `-22` EINVAL for an empty
|
|
2632
2860
|
* vector or an argument holding a NUL, `posix_spawnp`'s own error
|
|
2633
|
-
* otherwise, so a program that is not there is `-2` ENOENT.
|
|
2861
|
+
* otherwise, so a program that is not there is `-2` ENOENT. Under `--sandbox` with a list of granted
|
|
2862
|
+
* programs, a spawn that cannot be held to one program is refused: -11
|
|
2863
|
+
* (EAGAIN), -38 (ENOSYS), -10 (ECHILD) or the kernel's own error, with a line
|
|
2864
|
+
* on stderr.
|
|
2634
2865
|
*/
|
|
2635
2866
|
export function spawn(argv: string[]): i32;
|
|
2636
2867
|
/**
|
|
@@ -3310,8 +3541,9 @@ declare module "nish:net" {
|
|
|
3310
3541
|
}
|
|
3311
3542
|
|
|
3312
3543
|
/**
|
|
3313
|
-
* Element access with no bounds check, signed arithmetic that wraps,
|
|
3314
|
-
* string read through a pointer nothing proves
|
|
3544
|
+
* Element access with no bounds check, signed arithmetic that wraps, a C
|
|
3545
|
+
* string or struct read through a pointer nothing proves, and the errno a C
|
|
3546
|
+
* call left.
|
|
3315
3547
|
*
|
|
3316
3548
|
* import { uncheckedGet, uncheckedSet, wrappingAdd } from "nish:unsafe";
|
|
3317
3549
|
*
|
|
@@ -3325,12 +3557,13 @@ declare module "nish:net" {
|
|
|
3325
3557
|
* is a call a reader can find. `--emit-checked` prints an `unsafe import` line
|
|
3326
3558
|
* for each name imported and an `unsafe call` line for each site.
|
|
3327
3559
|
*
|
|
3328
|
-
* The global spelling is refused (NL2456): the
|
|
3560
|
+
* The global spelling is refused (NL2456): the eight are called only through an
|
|
3329
3561
|
* import of `nish:unsafe`. An index outside `[0, xs.length)` is undefined
|
|
3330
3562
|
* behaviour, which is the whole of the trade. There is no flag that turns the
|
|
3331
3563
|
* checks off: `--unchecked-indexing` and `--wrapping` are gone, and the CLI
|
|
3332
|
-
* refuses each with exit 2. `readCString`
|
|
3333
|
-
* `CPtr` comes only from a `declare function`, which Node
|
|
3564
|
+
* refuses each with exit 2. `readCString`, `readStruct` and `cErrno` have no Node form,
|
|
3565
|
+
* because their `CPtr` or errno comes only from a `declare function`, which Node
|
|
3566
|
+
* cannot call.
|
|
3334
3567
|
*
|
|
3335
3568
|
* **Under Node.** `runtime/nish.mjs` answers the import: the get and set are
|
|
3336
3569
|
* `xs[i]` and `xs[i] = v`, the wrapping three are `(a + b) | 0`,
|
|
@@ -3340,8 +3573,10 @@ declare module "nish:net" {
|
|
|
3340
3573
|
* **The no-panic scope.** Under `--deny-panics` or `"nish".noPanic`,
|
|
3341
3574
|
* `uncheckedGet`, `uncheckedSet` and `readCString` are allowed `unchecked`
|
|
3342
3575
|
* sites, because the import has already said that an index out of range is
|
|
3343
|
-
* the author's to rule out.
|
|
3344
|
-
*
|
|
3576
|
+
* the author's to rule out. `readStruct` is not: it tests its pointer and
|
|
3577
|
+
* panics with `ffi-null` on `NULL`, a site no proof removes, so the scope
|
|
3578
|
+
* refuses it. The wrapping three are not sites at all: they are defined for
|
|
3579
|
+
* every pair.
|
|
3345
3580
|
*
|
|
3346
3581
|
* Rules: https://github.com/amritk/nish/blob/main/docs/LANGUAGE.md#nishunsafe-unchecked-access-and-defined-wrapping
|
|
3347
3582
|
*/
|
|
@@ -3411,6 +3646,27 @@ declare module "nish:unsafe" {
|
|
|
3411
3646
|
* @returns A copy of the bytes before the `NUL`; C keeps its buffer.
|
|
3412
3647
|
*/
|
|
3413
3648
|
export function readCString(p: CPtr): string;
|
|
3649
|
+
/**
|
|
3650
|
+
* A copy of the C struct at `p` in a new instance of the `declare class` the
|
|
3651
|
+
* call's context names (`const lc: Lconv = readStruct(localeconv())`), so C
|
|
3652
|
+
* may free or overwrite its struct straight after. It reads and allocates,
|
|
3653
|
+
* and is native only.
|
|
3654
|
+
*
|
|
3655
|
+
* @param p A pointer from a `declare function`. Undefined behaviour unless
|
|
3656
|
+
* it points at the layout's size of readable bytes.
|
|
3657
|
+
* @returns A copy of the struct; C keeps its own.
|
|
3658
|
+
*/
|
|
3659
|
+
export function readStruct<T>(p: CPtr): T;
|
|
3660
|
+
/**
|
|
3661
|
+
* The errno the most recent `declare function` call on this thread left:
|
|
3662
|
+
* a program that names `cErrno` zeroes errno just before every foreign
|
|
3663
|
+
* call and saves it just after, before any result marshalling. Native and
|
|
3664
|
+
* `--profile wasi` only.
|
|
3665
|
+
*
|
|
3666
|
+
* @returns The saved errno; 0 before any foreign call, and 0 after one that
|
|
3667
|
+
* did not set it.
|
|
3668
|
+
*/
|
|
3669
|
+
export function cErrno(): i32;
|
|
3414
3670
|
}
|
|
3415
3671
|
|
|
3416
3672
|
/**
|
|
@@ -3460,8 +3716,9 @@ declare module "nish:unsafe" {
|
|
|
3460
3716
|
* **Under Node.** `runtime/nish.mjs` answers the import with
|
|
3461
3717
|
* `runtime/core.mjs`, where a vector is a fresh typed array of its lanes,
|
|
3462
3718
|
* made once and never written after, whose element type does the lane's
|
|
3463
|
-
* arithmetic
|
|
3464
|
-
*
|
|
3719
|
+
* arithmetic: an integer lane wraps through its array type (`Uint8Array` for
|
|
3720
|
+
* a `u8` lane), and an `f32` lane rounds through `Float32Array`. A mask is an
|
|
3721
|
+
* array of booleans, and a rotate is two shifts and an `or`. `tests/run.js`'s `simd` section holds the native, WASI and Node
|
|
3465
3722
|
* outputs to one.
|
|
3466
3723
|
*
|
|
3467
3724
|
* Rules: https://github.com/amritk/nish/blob/main/docs/LANGUAGE.md#nishsimd-sixteen-byte-vectors
|
|
@@ -4103,6 +4360,7 @@ declare module "nish:simd" {
|
|
|
4103
4360
|
export function shr<V extends IntegerVector>(v: V, count: i32): V;
|
|
4104
4361
|
/**
|
|
4105
4362
|
* Each lane rotated left by `count`, `llvm.fshl` with `v` as both halves.
|
|
4363
|
+
* Signed and unsigned lanes rotate alike.
|
|
4106
4364
|
*
|
|
4107
4365
|
* @param v A `u8x16`, `u16x8`, `i32x4` or `u32x4`.
|
|
4108
4366
|
* @param count An integer literal below the lane width: 0 to 7, 15 or 31
|
|
@@ -4112,6 +4370,7 @@ declare module "nish:simd" {
|
|
|
4112
4370
|
export function rotl<V extends IntegerVector>(v: V, count: i32): V;
|
|
4113
4371
|
/**
|
|
4114
4372
|
* Each lane rotated right by `count`, `llvm.fshr` with `v` as both halves.
|
|
4373
|
+
* Signed and unsigned lanes rotate alike.
|
|
4115
4374
|
*
|
|
4116
4375
|
* @param v A `u8x16`, `u16x8`, `i32x4` or `u32x4`.
|
|
4117
4376
|
* @param count An integer literal below the lane width: 0 to 7, 15 or 31
|
|
@@ -4461,8 +4720,9 @@ declare module "nish:secret" {
|
|
|
4461
4720
|
* copy.set(raw)`, then `secret(copy)`.
|
|
4462
4721
|
*
|
|
4463
4722
|
* @param value The key material, of a shape a `Secret` may hold (NL2428).
|
|
4464
|
-
* @returns The `Secret`,
|
|
4465
|
-
*
|
|
4723
|
+
* @returns The `Secret`, holding `value` itself and not a copy, so its
|
|
4724
|
+
* storage is the storage `wipe` later zeroes. It needs an owner: a
|
|
4725
|
+
* `const` or `let`, a `return`, or `wipe` (NL2439 otherwise).
|
|
4466
4726
|
*/
|
|
4467
4727
|
export function secret<T>(value: T): Secret<T>;
|
|
4468
4728
|
/**
|
|
@@ -4473,7 +4733,8 @@ declare module "nish:secret" {
|
|
|
4473
4733
|
* (NL2449), and declares a return type that holds no `Secret` (NL2451; an
|
|
4474
4734
|
* arrow writes it down, NL2452): that type is what leaves.
|
|
4475
4735
|
*
|
|
4476
|
-
* @param s The `Secret` to read, borrowed
|
|
4736
|
+
* @param s The `Secret` to read, borrowed: it can be exposed again, and is
|
|
4737
|
+
* still to be wiped.
|
|
4477
4738
|
* @param f The function the value is handed to.
|
|
4478
4739
|
* @returns What `f` answers.
|
|
4479
4740
|
*/
|
|
@@ -4603,6 +4864,28 @@ declare module "nish:region" {
|
|
|
4603
4864
|
* @returns The handle.
|
|
4604
4865
|
*/
|
|
4605
4866
|
export function regionWith<A, T>(arg: A, f: (arg: A) => T): Region<T>;
|
|
4867
|
+
/**
|
|
4868
|
+
* A new region whose parent is the region entered now: `f()` runs with every
|
|
4869
|
+
* allocation landing in it, and what it answers is the root. The child may
|
|
4870
|
+
* keep memory the parent's root reaches, and `free` of the parent frees it
|
|
4871
|
+
* too. Called outside an `enter` or `enterWith` `f` it is NL2702, and it
|
|
4872
|
+
* stops the program when no region is entered.
|
|
4873
|
+
*
|
|
4874
|
+
* @param f Makes the root. It answers memory it allocated, never the
|
|
4875
|
+
* parent's (NL2614).
|
|
4876
|
+
* @returns The handle.
|
|
4877
|
+
*/
|
|
4878
|
+
export function child<T>(f: () => T): Region<T>;
|
|
4879
|
+
/**
|
|
4880
|
+
* `child`, with one outside argument handed to `f`.
|
|
4881
|
+
*
|
|
4882
|
+
* @param arg Memory the parent's root reaches, which `f` may keep in the
|
|
4883
|
+
* child, or outer memory it may only read (NL2610).
|
|
4884
|
+
* @param f Makes the root from `arg`. It answers memory it allocated, never
|
|
4885
|
+
* `arg` itself (NL2614).
|
|
4886
|
+
* @returns The handle.
|
|
4887
|
+
*/
|
|
4888
|
+
export function childWith<A, T>(arg: A, f: (arg: A) => T): Region<T>;
|
|
4606
4889
|
/**
|
|
4607
4890
|
* `f(root)`, with every allocation landing in the region. Stops the program
|
|
4608
4891
|
* on a dead, foreign or already-entered handle.
|