@amritk/nish-x86_64-linux 0.41.0 → 0.44.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 +282 -126
- package/package.json +2 -2
- package/runtime/core.d.ts +16 -0
- package/runtime/core.mjs +5 -0
- package/runtime/nish.d.ts +204 -33
- package/runtime/nish.h +19 -3
- package/runtime/nish.mjs +5 -1
- package/runtime/runtime-cross.c +15 -0
- package/runtime/runtime-net.c +876 -10
- package/runtime/runtime-region.c +21 -0
- package/runtime/runtime-sandbox.c +112 -15
- package/runtime/runtime-text.c +11 -0
- package/runtime/runtime-uring.c +533 -77
- package/runtime/runtime-wasm.c +3 -0
- package/runtime/runtime.c +474 -5
- package/runtime/sqlite/README.md +16 -3
- package/runtime/sqlite/nish-sqlite.c +940 -29
- package/scripts/build.sh +125 -29
- package/std/README.md +3 -3
- package/std/crypto/base64url.ts +102 -1
- package/std/crypto/scram.ts +142 -0
- package/std/crypto/sha1.ts +99 -41
- package/std/host/ring.ts +1 -1
- package/std/host/text.ts +1 -1
- package/std/net/fetch.ts +9 -1
- package/std/net/handler.ts +79 -15
- package/std/net/http-server.ts +2 -3
- package/std/net/http1-server.ts +294 -51
- package/std/net/http3-server.ts +26 -15
- package/std/net/http3.ts +2 -2
- package/std/net/oidc.ts +1107 -0
- package/std/net/postgres-async.ts +64 -33
- package/std/net/postgres.ts +65 -76
- package/std/net/quic-conn-ack.ts +57 -7
- package/std/net/quic-frame.ts +104 -2
- package/std/net/quic-listener.ts +9 -2
- package/std/net/quic.ts +16 -1
- package/std/net/serve.ts +10 -8
- package/std/net/websocket.ts +188 -49
- package/std/sqlite.ts +325 -0
- package/std/text.ts +80 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amritk/nish-x86_64-linux",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.0",
|
|
4
4
|
"description": "The nish native compiler for Linux on x86_64",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"os": [
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"bugs": {
|
|
29
29
|
"url": "https://github.com/amritk/nish/issues"
|
|
30
30
|
},
|
|
31
|
-
"homepage": "https://
|
|
31
|
+
"homepage": "https://nishlang.com/"
|
|
32
32
|
}
|
package/runtime/core.d.ts
CHANGED
|
@@ -8,6 +8,22 @@ export * from "./core/numbers.js";
|
|
|
8
8
|
export * from "./core/result.js";
|
|
9
9
|
export * from "./core/strings.js";
|
|
10
10
|
|
|
11
|
+
// `nish:compact`: what `--emit-ts` writes for a program's `import ... from "nish:compact"`.
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The marker a class implements to store its links as 32-bit offsets in a
|
|
15
|
+
* native build. It has no members, so `implements Compact` adds nothing a
|
|
16
|
+
* TypeScript checker sees.
|
|
17
|
+
*/
|
|
18
|
+
export interface Compact {}
|
|
19
|
+
/** The value `core.mjs` exports under the marker's name, so an emitted import of it resolves. */
|
|
20
|
+
export declare const Compact: Compact;
|
|
21
|
+
|
|
22
|
+
/** Reserved for WP48 stage 3, which lets a class refuse the compiler's choice. */
|
|
23
|
+
export interface Wide {}
|
|
24
|
+
/** The value `core.mjs` exports under the reserved marker's name. */
|
|
25
|
+
export declare const Wide: Wide;
|
|
26
|
+
|
|
11
27
|
// `nish:simd`: what `--emit-ts` writes for a program's `import ... from "nish:simd"`.
|
|
12
28
|
import type { f32, f64, i32, u16, u32, u8 } from "./core/numbers.js";
|
|
13
29
|
|
package/runtime/core.mjs
CHANGED
|
@@ -84,6 +84,11 @@ const simdLoad = (Lanes) => (xs, i) => {
|
|
|
84
84
|
return out;
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
+
// `nish:compact`: the marker interfaces pick a native layout and mean nothing
|
|
88
|
+
// under Node, where every reference is the engine's own.
|
|
89
|
+
export const Compact = Object.freeze({});
|
|
90
|
+
export const Wide = Object.freeze({});
|
|
91
|
+
|
|
87
92
|
export const u8x16 = simdMake(Uint8Array);
|
|
88
93
|
export const u16x8 = simdMake(Uint16Array);
|
|
89
94
|
export const i32x4 = simdMake(Int32Array);
|
package/runtime/nish.d.ts
CHANGED
|
@@ -712,8 +712,8 @@ declare function isExecutableSync(path: string): boolean;
|
|
|
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
|
|
714
714
|
// shadowed; a user function of the same name, with no import, is the user's.
|
|
715
|
-
// Every import and call is a recorded fact in `--emit-checked`.
|
|
716
|
-
//
|
|
715
|
+
// Every import and call is a recorded fact in `--emit-checked`. In
|
|
716
|
+
// the no-panic scope, the default, the import is the opt-in the scope takes.
|
|
717
717
|
|
|
718
718
|
/**
|
|
719
719
|
* `xs[i]` with no bounds check: undefined behaviour when `i` is out of range,
|
|
@@ -726,7 +726,7 @@ declare function isExecutableSync(path: string): boolean;
|
|
|
726
726
|
*
|
|
727
727
|
* To the bounds proof it is the load `xs[i]` is, less the check: it moves no
|
|
728
728
|
* length, and it records no passed check, so a checked `xs[i]` after it keeps
|
|
729
|
-
* its check.
|
|
729
|
+
* its check. In the no-panic scope it is an allowed `unchecked` site. Under
|
|
730
730
|
* Node the runtime shim reads `xs[i]`. Capability: unsafe.
|
|
731
731
|
*
|
|
732
732
|
* @param xs the array of numbers to read.
|
|
@@ -746,7 +746,7 @@ declare function uncheckedGet<T extends number>(xs: readonly T[], i: i32): T;
|
|
|
746
746
|
* The store is a write of the array for every rule that asks, the rule for a
|
|
747
747
|
* parallel body included. To the bounds proof it is the store `xs[i] = v` is,
|
|
748
748
|
* less the check, and a resize in the value stored still takes the length away.
|
|
749
|
-
*
|
|
749
|
+
* In the no-panic scope it is an allowed `unchecked` site. Under Node the
|
|
750
750
|
* runtime shim stores `xs[i] = v`. Capability: unsafe.
|
|
751
751
|
*
|
|
752
752
|
* @param xs the array of numbers to write.
|
|
@@ -766,7 +766,7 @@ declare function uncheckedSet<T extends number>(xs: T[], i: i32, v: T): void;
|
|
|
766
766
|
*
|
|
767
767
|
* In a module constant's initialiser the call folds, wrapping, where
|
|
768
768
|
* `2147483647 + 1` is refused; it is the one call such an initialiser may make.
|
|
769
|
-
* It is not a site
|
|
769
|
+
* It is not a site in the no-panic scope, as it cannot panic. Under Node the
|
|
770
770
|
* runtime shim computes `(a + b) | 0` on an `i32` and `BigInt.asIntN(64, ...)`
|
|
771
771
|
* on the BigInt an `i64` is there. Capability: unsafe.
|
|
772
772
|
*
|
|
@@ -813,7 +813,7 @@ declare function wrappingMul<T extends i32 | i64>(a: T, b: T): T;
|
|
|
813
813
|
* The copy is new on every call and is the calling function's allocation, and
|
|
814
814
|
* it is refused inside a `using a = arena()` block that would release one held
|
|
815
815
|
* outside it (`` `readCString(p)` may be allocated inside the `using arena()`
|
|
816
|
-
* block ``).
|
|
816
|
+
* block ``). In the no-panic scope its `NULL` test is an `ffi-null` site no
|
|
817
817
|
* proof removes, so the scope refuses the call (the copy's `oom` beside it is
|
|
818
818
|
* allowed), and the pointer it reads is `ffi`. It lowers the same
|
|
819
819
|
* on wasm32, where whether the program links is the `declare function`'s
|
|
@@ -842,7 +842,7 @@ declare function readCString(p: CPtr): string;
|
|
|
842
842
|
*
|
|
843
843
|
* A `NULL` `p` is tested before the copy and panics with the `ffi-null` kind,
|
|
844
844
|
* naming the layout, since a `declare function` declared to answer `CPtr` may
|
|
845
|
-
* still answer `NULL`. No proof removes that test, so
|
|
845
|
+
* still answer `NULL`. No proof removes that test, so the no-panic scope refuses
|
|
846
846
|
* the call; `--emit-panics` lists it as an `ffi-null` site, with the copy's
|
|
847
847
|
* `oom` beside it.
|
|
848
848
|
*
|
|
@@ -1641,13 +1641,18 @@ declare function tcpListen(host: string, port: i32, backlog: i32): i32;
|
|
|
1641
1641
|
* (NL2404). Not callable in a `scope()` task or a parallel body. Capability:
|
|
1642
1642
|
* net.
|
|
1643
1643
|
*
|
|
1644
|
+
* Flag 8 (`NET_LISTEN_RING` in `nish:net`) accepts into io_uring slots on
|
|
1645
|
+
* Linux, so connections are not bound by the descriptor limit; where rings are
|
|
1646
|
+
* refused the listener serves descriptors and `netRingState` says why. Elsewhere
|
|
1647
|
+
* the flag is accepted and does nothing.
|
|
1648
|
+
*
|
|
1644
1649
|
* @param host the numeric address to bind.
|
|
1645
1650
|
* @param port the port, 0 for any.
|
|
1646
1651
|
* @param backlog the kernel's queue of unaccepted connections.
|
|
1647
|
-
* @param flags 1, 2 and
|
|
1652
|
+
* @param flags 1, 2, 4 and 8 as above.
|
|
1648
1653
|
* @returns the listener's descriptor, or a negative errno: -22 for any other bit (a negative
|
|
1649
1654
|
* `flags` included) or 4 without 1, before a socket is made; -95 for flag 4 off Linux; -98
|
|
1650
|
-
* for a port in use.
|
|
1655
|
+
* for a port in use; -23 once the process has opened 31 ring listeners, closed or not.
|
|
1651
1656
|
*/
|
|
1652
1657
|
declare function tcpListenFlags(host: string, port: i32, backlog: i32, flags: i32): i32;
|
|
1653
1658
|
/**
|
|
@@ -1661,7 +1666,13 @@ declare function tcpListenFlags(host: string, port: i32, backlog: i32, flags: i3
|
|
|
1661
1666
|
* @param peer at least 18 bytes, receiving the peer's address in the 18-byte form; it must not
|
|
1662
1667
|
* be `readonly`. A shorter `peer` is -22 before anything is accepted, so no connection is
|
|
1663
1668
|
* taken and lost.
|
|
1664
|
-
* @returns the connection's descriptor
|
|
1669
|
+
* @returns the connection's descriptor, or a slot handle at or above 2^20 from a `NET_LISTEN_RING`
|
|
1670
|
+
* listener, whose `peer` is written as zeros; -11 when none waits; -23 when a ring listener's
|
|
1671
|
+
* slots are all taken; -95 for a datagram socket. A ring listener whose accept found memory
|
|
1672
|
+
* short answers -12 or -105 once, as a descriptor does, then pauses accepting for a back-off of
|
|
1673
|
+
* 10 ms, doubling to 640 ms while it recurs, and accepts again. Any other errno but -11, -4,
|
|
1674
|
+
* -103 or -71 means the listener is broken: it stops accepting and answers that errno from then
|
|
1675
|
+
* on, so close it and listen again.
|
|
1665
1676
|
*/
|
|
1666
1677
|
declare function tcpAccept(fd: i32, peer: u8[]): i32;
|
|
1667
1678
|
/**
|
|
@@ -1726,9 +1737,14 @@ declare function netWrite2(
|
|
|
1726
1737
|
* Shut one or both directions of a connection. Not callable in a `scope()` task or a parallel body.
|
|
1727
1738
|
* Refused at compile time on wasm32 and the WASI profile (NL2404). Capability: net.
|
|
1728
1739
|
*
|
|
1740
|
+
* On a connection a `NET_LISTEN_RING` listener accepted, the shutdown goes behind the
|
|
1741
|
+
* bytes already written, so the peer reads them and then the end of the stream; a later
|
|
1742
|
+
* `netWrite` answers -32 once the write side is shut, and `netRead` answers what is queued
|
|
1743
|
+
* and then 0 once the read side is.
|
|
1744
|
+
*
|
|
1729
1745
|
* @param fd the socket.
|
|
1730
1746
|
* @param how the read side (0), the write side (1) or both (2).
|
|
1731
|
-
* @returns 0, or a negative errno; -22 for any other `how
|
|
1747
|
+
* @returns 0, or a negative errno; -22 for any other `how`, -9 for a closed ring connection.
|
|
1732
1748
|
*/
|
|
1733
1749
|
declare function netShutdown(fd: i32, how: i32): i32;
|
|
1734
1750
|
/**
|
|
@@ -1898,8 +1914,8 @@ declare function pollCreate(): i32;
|
|
|
1898
1914
|
* @param events 1 readable, 2 writable, 3 both, 0 neither.
|
|
1899
1915
|
* @param token an `i32` of the program's choosing, which `pollWait` reports it under as it went
|
|
1900
1916
|
* in.
|
|
1901
|
-
* @returns 0, or a negative errno: -17 for a descriptor the loop already watches,
|
|
1902
|
-
* event bit past 2.
|
|
1917
|
+
* @returns 0, or a negative errno: -17 for a descriptor the loop already watches, or for a slot
|
|
1918
|
+
* handle another loop watches (a slot is in one loop at a time), -22 for an event bit past 2.
|
|
1903
1919
|
*/
|
|
1904
1920
|
declare function pollAdd(loop: i32, fd: i32, events: i32, token: i32): i32;
|
|
1905
1921
|
/**
|
|
@@ -1931,7 +1947,10 @@ declare function pollRemove(loop: i32, fd: i32): i32;
|
|
|
1931
1947
|
* `i32`s) and not `readonly`. A signal that interrupts the wait makes it answer
|
|
1932
1948
|
* 0, as a timeout does, rather than wait past the deadline; the descriptor
|
|
1933
1949
|
* `signalFd()` answers can be added to the loop, and is readable when SIGTERM
|
|
1934
|
-
* or SIGINT arrives.
|
|
1950
|
+
* or SIGINT arrives. Once the process has opened a `NET_LISTEN_RING`
|
|
1951
|
+
* listener with rings, for the rest of its life, an interrupted wait goes on
|
|
1952
|
+
* to its deadline, since the rings' own work interrupts it too: watch
|
|
1953
|
+
* `signalFd()` to see a signal.
|
|
1935
1954
|
*
|
|
1936
1955
|
* A UDP socket is always writable, and on Linux one whose both sides are shut
|
|
1937
1956
|
* is readable, writable and hung up, 7. On Darwin a descriptor both readable
|
|
@@ -1992,7 +2011,8 @@ declare function netSetOption(fd: i32, option: i32, value: i32): i32;
|
|
|
1992
2011
|
* @param fd the socket.
|
|
1993
2012
|
* @returns the MSS; -1, never an errno, for anything else (a descriptor that is not open, a
|
|
1994
2013
|
* socket with no peer such as a listener or one never connected, though the kernel answers
|
|
1995
|
-
* its default `536` for those, a socket that is not TCP
|
|
2014
|
+
* its default `536` for those, a socket that is not TCP, a connection a `NET_LISTEN_RING`
|
|
2015
|
+
* listener accepted, whose ring cannot ask for it), and always on wasm.
|
|
1996
2016
|
*/
|
|
1997
2017
|
declare function netMss(fd: i32): i32;
|
|
1998
2018
|
/**
|
|
@@ -2196,6 +2216,28 @@ declare const NET_UNIX_STREAM: i32;
|
|
|
2196
2216
|
* Capability: none.
|
|
2197
2217
|
*/
|
|
2198
2218
|
declare const NET_UNIX_SEQPACKET: i32;
|
|
2219
|
+
/**
|
|
2220
|
+
* `tcpListenFlags` flag 8: accept into io_uring slots instead of descriptors (WP63 S2, Linux). A
|
|
2221
|
+
* connection accepted from such a listener is a slot handle, a number at or above 2^20 that
|
|
2222
|
+
* `netRead`, `netWrite`, `netWrite2`, `netClose`, `netLocalPort` and the poll loop take as they
|
|
2223
|
+
* take a descriptor, except that a slot is in one poll loop at a time (a second loop's `pollAdd`
|
|
2224
|
+
* answers -17); `netSetOption` answers -95 and every other call -9. A program can so hold
|
|
2225
|
+
* more connections than its descriptor limit. Where the kernel refuses rings the listener serves
|
|
2226
|
+
* descriptors, and `netRingState` says why. Inert on Darwin. Capability: none.
|
|
2227
|
+
*/
|
|
2228
|
+
declare const NET_LISTEN_RING: i32;
|
|
2229
|
+
/**
|
|
2230
|
+
* Whether listeners opened with `NET_LISTEN_RING` accept into rings: 1 when they do, 0 until a
|
|
2231
|
+
* listener has found rings or a refusal, or the negative errno the kernel refused rings with (-1
|
|
2232
|
+
* when a seccomp filter refuses `io_uring_setup`, -38 for a kernel without it), in which case they
|
|
2233
|
+
* serve descriptors. Decided once per process, by the first listener that finds rings or a
|
|
2234
|
+
* refusal; one that finds descriptors or memory short serves descriptors itself and leaves the
|
|
2235
|
+
* state at 0, and a later listener asks again. -95 on Darwin. Refused at
|
|
2236
|
+
* compile time on wasm32 and the WASI profile (NL2404). Capability: net.
|
|
2237
|
+
*
|
|
2238
|
+
* @returns 1, 0 or the negative errno.
|
|
2239
|
+
*/
|
|
2240
|
+
declare function netRingState(): i32;
|
|
2199
2241
|
|
|
2200
2242
|
// ---- `nish:term` ------------------------------------------------------------------
|
|
2201
2243
|
//
|
|
@@ -3115,14 +3157,27 @@ declare module "nish:net" {
|
|
|
3115
3157
|
* the index of the CPU that received it, in the order the group's listeners
|
|
3116
3158
|
* were bound; a CPU past the group's size falls back to the hash.
|
|
3117
3159
|
*
|
|
3160
|
+
* Flag 8, `NET_LISTEN_RING`, accepts into io_uring slots on Linux: each
|
|
3161
|
+
* connection is a slot handle at or above 2^20 rather than a descriptor, so
|
|
3162
|
+
* a listener holds connections past `RLIMIT_NOFILE`. `netRead`, `netWrite`,
|
|
3163
|
+
* `netWrite2`, `netClose`, `netLocalPort` and the poll loop take a slot
|
|
3164
|
+
* handle; `netSetOption` answers `-95`, and calls that need a descriptor,
|
|
3165
|
+
* `sendFd` among them, answer `-9`.
|
|
3166
|
+
* The first listener that finds rings or a refusal decides for the process:
|
|
3167
|
+
* where the kernel refuses rings it serves descriptors, and `netRingState`
|
|
3168
|
+
* answers the errno. A listener whose rings fail for want of descriptors or
|
|
3169
|
+
* memory serves descriptors itself, and a later listener asks again. Off
|
|
3170
|
+
* Linux the flag is accepted and does nothing.
|
|
3171
|
+
*
|
|
3118
3172
|
* @param host A numeric host, as for `tcpListen`.
|
|
3119
3173
|
* @param port The port.
|
|
3120
3174
|
* @param backlog The length of the accept queue.
|
|
3121
|
-
* @param flags The sum of the flags: `3` is both, `5` and `7` steer,
|
|
3122
|
-
* is `tcpListen` exactly.
|
|
3175
|
+
* @param flags The sum of the flags: `3` is both, `5` and `7` steer, `8`
|
|
3176
|
+
* accepts into rings, and `0` is `tcpListen` exactly.
|
|
3123
3177
|
* @returns The listener's descriptor or the failure: `-22` for any other
|
|
3124
3178
|
* bit, a negative `flags`, or flag 4 without 1, before a socket is made;
|
|
3125
|
-
* `-95` for flag 4 off Linux
|
|
3179
|
+
* `-95` for flag 4 off Linux; `-23` once the process has opened 31 ring
|
|
3180
|
+
* listeners, closed or not.
|
|
3126
3181
|
*/
|
|
3127
3182
|
export function tcpListenFlags(host: string, port: i32, backlog: i32, flags: i32): i32;
|
|
3128
3183
|
/**
|
|
@@ -3132,9 +3187,16 @@ declare module "nish:net" {
|
|
|
3132
3187
|
*
|
|
3133
3188
|
* @param fd The listener.
|
|
3134
3189
|
* @param peer The array the peer's address form is written into.
|
|
3135
|
-
* @returns The connection's descriptor
|
|
3136
|
-
*
|
|
3137
|
-
*
|
|
3190
|
+
* @returns The connection's descriptor (a slot handle from a
|
|
3191
|
+
* `NET_LISTEN_RING` listener, whose `peer` is written as zeros), `-11`
|
|
3192
|
+
* when none is waiting, `-23` when a ring listener's slots are all
|
|
3193
|
+
* taken, `-22` for a `peer` shorter than 18 bytes before anything is
|
|
3194
|
+
* accepted (so no connection is taken and lost), or `-95` for a
|
|
3195
|
+
* datagram socket. A ring listener whose accept found memory short
|
|
3196
|
+
* answers `-12` or `-105` once, pauses for a back-off (10 ms, doubling
|
|
3197
|
+
* to 640 ms while it recurs) and accepts again. Any other errno but
|
|
3198
|
+
* `-11`, `-4`, `-103` or `-71` stops it accepting and is answered from
|
|
3199
|
+
* then on; close it and listen again.
|
|
3138
3200
|
*/
|
|
3139
3201
|
export function tcpAccept(fd: i32, peer: u8[]): i32;
|
|
3140
3202
|
/**
|
|
@@ -3190,11 +3252,14 @@ declare module "nish:net" {
|
|
|
3190
3252
|
bLen: i32
|
|
3191
3253
|
): i32;
|
|
3192
3254
|
/**
|
|
3193
|
-
* Shut one side of a connection, or both.
|
|
3255
|
+
* Shut one side of a connection, or both. On a connection a
|
|
3256
|
+
* `NET_LISTEN_RING` listener accepted, the shutdown goes behind the bytes
|
|
3257
|
+
* already written, so the peer reads them and then the end of the stream.
|
|
3194
3258
|
*
|
|
3195
3259
|
* @param fd A connected socket.
|
|
3196
3260
|
* @param how `0` the read side, `1` the write side, `2` both.
|
|
3197
|
-
* @returns `0`, `-22` for any other `how`,
|
|
3261
|
+
* @returns `0`, `-22` for any other `how`, `-9` for a closed ring
|
|
3262
|
+
* connection, or the failure.
|
|
3198
3263
|
*/
|
|
3199
3264
|
export function netShutdown(fd: i32, how: i32): i32;
|
|
3200
3265
|
/**
|
|
@@ -3316,7 +3381,9 @@ declare module "nish:net" {
|
|
|
3316
3381
|
* @param token An `i32` of the program's choosing that comes back as it went
|
|
3317
3382
|
* in.
|
|
3318
3383
|
* @returns `0`, `-17` for a descriptor the loop already watches (on Darwin
|
|
3319
|
-
* it is left under the new token)
|
|
3384
|
+
* it is left under the new token) or for a slot handle another loop
|
|
3385
|
+
* watches (a slot is in one loop at a time), or `-22` for an event bit
|
|
3386
|
+
* past `2`.
|
|
3320
3387
|
*/
|
|
3321
3388
|
export function pollAdd(loop: i32, fd: i32, events: i32, token: i32): i32;
|
|
3322
3389
|
/**
|
|
@@ -3342,7 +3409,9 @@ declare module "nish:net" {
|
|
|
3342
3409
|
* one pair per ready descriptor: `ready[2k]` its token and `ready[2k + 1]`
|
|
3343
3410
|
* its events, `1` readable and `2` writable, with `4` added for a hang-up or
|
|
3344
3411
|
* an error. A signal that interrupts the wait answers `0`, as a timeout
|
|
3345
|
-
* does
|
|
3412
|
+
* does, until the process opens a `NET_LISTEN_RING` listener with rings:
|
|
3413
|
+
* from then on, for the rest of its life, the wait goes on to its deadline, and `signalFd()` is how a loop sees a signal. Not
|
|
3414
|
+
* `willreturn`, because it can wait forever. Nothing allocates,
|
|
3346
3415
|
* and `ready` is never written past its length.
|
|
3347
3416
|
*
|
|
3348
3417
|
* @param loop The loop.
|
|
@@ -3385,8 +3454,9 @@ declare module "nish:net" {
|
|
|
3385
3454
|
* @returns The size, or a plain `-1`, never an errno, for anything else: a
|
|
3386
3455
|
* descriptor that is not open, a socket with no peer (a listener, or one
|
|
3387
3456
|
* never connected, though the kernel answers its default `536` for
|
|
3388
|
-
* those), a socket that is not TCP,
|
|
3389
|
-
*
|
|
3457
|
+
* those), a socket that is not TCP, a connection a `NET_LISTEN_RING`
|
|
3458
|
+
* listener accepted, whose ring cannot ask for it, and every call on
|
|
3459
|
+
* wasm, where it compiles to the constant with the descriptor still evaluated. It throws
|
|
3390
3460
|
* under Node.
|
|
3391
3461
|
*/
|
|
3392
3462
|
export function netMss(fd: i32): i32;
|
|
@@ -3540,6 +3610,16 @@ declare module "nish:net" {
|
|
|
3540
3610
|
export const NET_UNIX_STREAM: i32;
|
|
3541
3611
|
/** `unixSocketPair` kind: each write one message (`SOCK_SEQPACKET`). */
|
|
3542
3612
|
export const NET_UNIX_SEQPACKET: i32;
|
|
3613
|
+
/** `tcpListenFlags` flag 8: accept into io_uring slots instead of descriptors. */
|
|
3614
|
+
export const NET_LISTEN_RING: i32;
|
|
3615
|
+
/**
|
|
3616
|
+
* Whether `NET_LISTEN_RING` listeners accept into rings.
|
|
3617
|
+
*
|
|
3618
|
+
* @returns `1` when they do, `0` until a listener has found rings or a
|
|
3619
|
+
* refusal, or the negative errno rings were refused with, in which case
|
|
3620
|
+
* they serve descriptors.
|
|
3621
|
+
*/
|
|
3622
|
+
export function netRingState(): i32;
|
|
3543
3623
|
}
|
|
3544
3624
|
|
|
3545
3625
|
/**
|
|
@@ -3572,7 +3652,7 @@ declare module "nish:net" {
|
|
|
3572
3652
|
* `(a - b) | 0` and `Math.imul` on an `i32` and `BigInt.asIntN(64, …)` on an
|
|
3573
3653
|
* `i64`. A program that stays in range prints the same as natively.
|
|
3574
3654
|
*
|
|
3575
|
-
* **The no-panic scope.**
|
|
3655
|
+
* **The no-panic scope.** In the scope, every module of the package by default,
|
|
3576
3656
|
* `uncheckedGet` and `uncheckedSet` are allowed `unchecked` sites, because
|
|
3577
3657
|
* the import has already said that an index out of range is the author's to
|
|
3578
3658
|
* rule out. `readCString` and `readStruct` are not: each tests its pointer and
|
|
@@ -3672,6 +3752,52 @@ declare module "nish:unsafe" {
|
|
|
3672
3752
|
export function cErrno(): i32;
|
|
3673
3753
|
}
|
|
3674
3754
|
|
|
3755
|
+
/**
|
|
3756
|
+
* `nish:compact`: the marker interfaces that pick a class's layout (WP48).
|
|
3757
|
+
* `class R implements Compact` stores every field typed exactly `R` or
|
|
3758
|
+
* `R | null`, in any class, as a 32-bit offset into one reserved address range,
|
|
3759
|
+
* so a tree or list node of an `i32` and two links is 12 bytes, not 24. Locals,
|
|
3760
|
+
* parameters, returns, arrays, maps and other unions stay full pointers.
|
|
3761
|
+
*
|
|
3762
|
+
* A native `--link` build also compacts, with no marker, each class whose
|
|
3763
|
+
* links take at least a quarter off a class made in a loop or recursion
|
|
3764
|
+
* (`--explain-layout` prints each pick and why the others are left alone).
|
|
3765
|
+
* `implements Wide` keeps one class out of that, and `--compact off` keeps
|
|
3766
|
+
* every class, `implements Compact` included, at full pointers.
|
|
3767
|
+
*
|
|
3768
|
+
* A `--emit-header` build keeps a compact class, and every class holding one
|
|
3769
|
+
* of its links, opaque: C holds it as a full `struct X *` handle and links the
|
|
3770
|
+
* range runtime (`scripts/build.sh --arena-range`). The compiler refuses a
|
|
3771
|
+
* compact class where Node or the runtime would read its layout: a build with
|
|
3772
|
+
* `--emit-napi` or `--emit-napi-async` (also beside `--emit-header`), an
|
|
3773
|
+
* N-API export whose signature holds one, a `declare class`, and a class
|
|
3774
|
+
* holding a `Secret`. wasm32, a host `--emit-dts` page module and an ASAN build compile
|
|
3775
|
+
* it uncompressed: a pointer there is already 4 bytes, the page runs on the
|
|
3776
|
+
* wasm runtime, or the range cannot hold the sanitizer's blocks.
|
|
3777
|
+
*
|
|
3778
|
+
* **Under Node.** `runtime/nish.mjs` answers the import with
|
|
3779
|
+
* `runtime/core.mjs`, where both names are empty values: a reference is the
|
|
3780
|
+
* engine's own and the marker changes nothing a program prints.
|
|
3781
|
+
*
|
|
3782
|
+
* Rules: https://github.com/amritk/nish/blob/main/docs/LANGUAGE.md#compact-classes
|
|
3783
|
+
*/
|
|
3784
|
+
declare module "nish:compact" {
|
|
3785
|
+
/**
|
|
3786
|
+
* The marker a class implements to store its links as 32-bit offsets. It
|
|
3787
|
+
* has no members, so `implements Compact` adds no field.
|
|
3788
|
+
*/
|
|
3789
|
+
export interface Compact {}
|
|
3790
|
+
|
|
3791
|
+
/**
|
|
3792
|
+
* The marker a class implements to keep its links full pointers. The
|
|
3793
|
+
* compiler compacts a class on its own when its rule finds the saving pays
|
|
3794
|
+
* (`--explain-layout` names each pick); `implements Wide` refuses that
|
|
3795
|
+
* pick, the way `--compact off` refuses every one. It has no members, so it
|
|
3796
|
+
* adds no field, and a class cannot write it with `Compact`.
|
|
3797
|
+
*/
|
|
3798
|
+
export interface Wide {}
|
|
3799
|
+
}
|
|
3800
|
+
|
|
3675
3801
|
/**
|
|
3676
3802
|
* Sixteen-byte vectors of one lane type, and the lane-wise operations on them,
|
|
3677
3803
|
* each lowered to target-independent LLVM vector IR.
|
|
@@ -4929,15 +5055,15 @@ declare module "nish:region" {
|
|
|
4929
5055
|
*
|
|
4930
5056
|
* import { awaitAll, spawn } from "nish:async";
|
|
4931
5057
|
*
|
|
4932
|
-
* async
|
|
5058
|
+
* const double = async (x: i32): Promise<i32> => {
|
|
4933
5059
|
* return x * 2;
|
|
4934
5060
|
* }
|
|
4935
5061
|
*
|
|
4936
|
-
* async
|
|
5062
|
+
* const log = async (x: i32): Promise<void> => {
|
|
4937
5063
|
* console.log(x);
|
|
4938
5064
|
* }
|
|
4939
5065
|
*
|
|
4940
|
-
* async
|
|
5066
|
+
* const run = async (): Promise<void> => {
|
|
4941
5067
|
* const [c, d] = await awaitAll(double(1), double(2));
|
|
4942
5068
|
* spawn(log(c + d));
|
|
4943
5069
|
* }
|
|
@@ -4954,7 +5080,7 @@ declare module "nish:region" {
|
|
|
4954
5080
|
*
|
|
4955
5081
|
* import { readable, sleep } from "nish:async";
|
|
4956
5082
|
*
|
|
4957
|
-
* async
|
|
5083
|
+
* const tick = async (): Promise<void> => {
|
|
4958
5084
|
* await sleep(10);
|
|
4959
5085
|
* console.log("tick");
|
|
4960
5086
|
* }
|
|
@@ -5801,6 +5927,22 @@ interface Array<T> {
|
|
|
5801
5927
|
* @returns the first such index, or `-1`.
|
|
5802
5928
|
*/
|
|
5803
5929
|
findIndex(predicate: (value: T, index: number) => boolean): number;
|
|
5930
|
+
/**
|
|
5931
|
+
* Call `callbackfn` with each element in order, as `Array.prototype.forEach`
|
|
5932
|
+
* does, up to the length the array had when the call began: an element the
|
|
5933
|
+
* callback pushes is not visited, and one that shrinks the array ends the
|
|
5934
|
+
* walk at its new length. The call answers `void`, and so does the
|
|
5935
|
+
* callback; what a concise arrow body computes is dropped. The callback takes the element, or the element and its
|
|
5936
|
+
* index; one that declares a third parameter, JavaScript's array, is refused
|
|
5937
|
+
* (NL2698). It is `map`'s callback otherwise: a top-level function or an arrow
|
|
5938
|
+
* written at the call, which may not assign a name of the function around it
|
|
5939
|
+
* (NL2586), so a running total is a `for...of` loop. The call compiles to a
|
|
5940
|
+
* counted loop with the callback inlined (`std/array`'s `forEach`, or
|
|
5941
|
+
* `forEachIndexed` for a two-parameter callback). Capability: none.
|
|
5942
|
+
*
|
|
5943
|
+
* @param callbackfn called once per element, with the element and its index.
|
|
5944
|
+
*/
|
|
5945
|
+
forEach(callbackfn: (value: T, index: number) => void): void;
|
|
5804
5946
|
/**
|
|
5805
5947
|
* A copy of the elements from `start` up to `end`, in a new array, with
|
|
5806
5948
|
* string `slice`'s rule: the range must satisfy `0 <= start <= end <=
|
|
@@ -5825,7 +5967,7 @@ interface Array<T> {
|
|
|
5825
5967
|
* nish_array *`.
|
|
5826
5968
|
*
|
|
5827
5969
|
* Everything that reads works (`length`, `a[i]`, `for...of`, `indexOf`, `join`,
|
|
5828
|
-
* `map`, `filter`, `some`, `every`, `findIndex`, `slice`, passing it on to
|
|
5970
|
+
* `map`, `filter`, `some`, `every`, `findIndex`, `forEach`, `slice`, passing it on to
|
|
5829
5971
|
* another `readonly T[]`); every write is refused under its own name, an
|
|
5830
5972
|
* element store ("Cannot assign to an element of readonly i32[]
|
|
5831
5973
|
* (declare it i32[] to write through it)"), `push`, `pop`, `set`, `fill` and
|
|
@@ -5911,6 +6053,22 @@ interface ReadonlyArray<T> {
|
|
|
5911
6053
|
* @returns the first such index, or `-1`.
|
|
5912
6054
|
*/
|
|
5913
6055
|
findIndex(predicate: (value: T, index: number) => boolean): number;
|
|
6056
|
+
/**
|
|
6057
|
+
* Call `callbackfn` with each element in order, as `Array.prototype.forEach`
|
|
6058
|
+
* does, up to the length the array had when the call began: an element the
|
|
6059
|
+
* callback pushes is not visited, and one that shrinks the array ends the
|
|
6060
|
+
* walk at its new length. The call answers `void`, and so does the
|
|
6061
|
+
* callback; what a concise arrow body computes is dropped. The callback takes the element, or the element and its
|
|
6062
|
+
* index; one that declares a third parameter, JavaScript's array, is refused
|
|
6063
|
+
* (NL2698). It is `map`'s callback otherwise: a top-level function or an arrow
|
|
6064
|
+
* written at the call, which may not assign a name of the function around it
|
|
6065
|
+
* (NL2586), so a running total is a `for...of` loop. The call compiles to a
|
|
6066
|
+
* counted loop with the callback inlined (`std/array`'s `forEach`, or
|
|
6067
|
+
* `forEachIndexed` for a two-parameter callback). Capability: none.
|
|
6068
|
+
*
|
|
6069
|
+
* @param callbackfn called once per element, with the element and its index.
|
|
6070
|
+
*/
|
|
6071
|
+
forEach(callbackfn: (value: T, index: number) => void): void;
|
|
5914
6072
|
/**
|
|
5915
6073
|
* A copy of the elements from `start` up to `end`, in a new array, with
|
|
5916
6074
|
* string `slice`'s rule: the range must satisfy `0 <= start <= end <=
|
|
@@ -6177,6 +6335,19 @@ interface Set<T> {
|
|
|
6177
6335
|
delete(value: T): boolean;
|
|
6178
6336
|
/** Remove every member. Capability: none. */
|
|
6179
6337
|
clear(): void;
|
|
6338
|
+
/**
|
|
6339
|
+
* Call `callbackfn` with each member in insertion order, as
|
|
6340
|
+
* `Set.prototype.forEach` does: the `for...of` walk over the set with the
|
|
6341
|
+
* callback inlined (`std/collections`' `forEachElement`), so a member added
|
|
6342
|
+
* during the walk is visited and one deleted before the walk reaches it is
|
|
6343
|
+
* not. The callback takes the member alone; JavaScript passes it again as a
|
|
6344
|
+
* second argument and the set as a third, and a callback that declares a
|
|
6345
|
+
* second parameter is refused (NL2772). The callback rules are those of an
|
|
6346
|
+
* array's `forEach`. Capability: none.
|
|
6347
|
+
*
|
|
6348
|
+
* @param callbackfn called once per member, with the member.
|
|
6349
|
+
*/
|
|
6350
|
+
forEach(callbackfn: (value: T) => void): void;
|
|
6180
6351
|
}
|
|
6181
6352
|
|
|
6182
6353
|
// ---- What this file cannot say ----------------------------------------------
|
package/runtime/nish.h
CHANGED
|
@@ -822,7 +822,16 @@ bool nish_is_executable(const nish_str *path);
|
|
|
822
822
|
* with `SO_REUSEPORT` for flag 1, `TCP_NODELAY` on each accepted socket for
|
|
823
823
|
* flag 2, and, for flag 4 with flag 1, a reuseport program steering each new
|
|
824
824
|
* connection to the listener bound at the index of the CPU that received it
|
|
825
|
-
* (Linux; -95 elsewhere).
|
|
825
|
+
* (Linux; -95 elsewhere). Flag 8 accepts into io_uring slots on Linux,
|
|
826
|
+
* whose handles are at or above 2^20; any other bit, or 4 without 1, is -22.
|
|
827
|
+
* `nish_net_ring_state()`: 1 when flag 8 listeners get rings, 0 before one
|
|
828
|
+
* has asked, or the negative errno that refused them; -95 on Darwin.
|
|
829
|
+
* `nish_net_ring_premake(n, fds)`: `--sandbox`'s call, before its filter,
|
|
830
|
+
* that makes the `n` restricted rings every flag 8 listener then takes (WP63
|
|
831
|
+
* S3), writing each ring's descriptor to `fds`, then the descriptor of the
|
|
832
|
+
* keeper ring a freed one is replaced with (room for 65, NURING-36); 0
|
|
833
|
+
* records that no ring may be made. The rings made, or the errno of the step
|
|
834
|
+
* that failed; -95 on Darwin.
|
|
826
835
|
* `nish_tcp_accept(fd, peer)`: a new descriptor and the peer's address.
|
|
827
836
|
* `nish_net_read` / `nish_net_write(fd, buf, off, len)`: bytes `[off, off +
|
|
828
837
|
* len)` of `buf`, which the compiled call has range-checked; a write to a
|
|
@@ -895,6 +904,8 @@ int32_t nish_net_address(nish_array *out, const nish_str *host, int32_t port);
|
|
|
895
904
|
int32_t nish_net_local_port(int32_t fd);
|
|
896
905
|
int32_t nish_tcp_listen(const nish_str *host, int32_t port, int32_t backlog);
|
|
897
906
|
int32_t nish_tcp_listen_flags(const nish_str *host, int32_t port, int32_t backlog, int32_t flags);
|
|
907
|
+
int32_t nish_net_ring_state(void);
|
|
908
|
+
int32_t nish_net_ring_premake(int32_t n, int32_t *fds);
|
|
898
909
|
int32_t nish_tcp_accept(int32_t fd, nish_array *peer);
|
|
899
910
|
int32_t nish_net_read(int32_t fd, nish_array *buf, int64_t off, int64_t len);
|
|
900
911
|
int32_t nish_net_write(int32_t fd, const nish_array *buf, int64_t off, int64_t len);
|
|
@@ -1011,8 +1022,13 @@ int64_t nish_cpu_online(void);
|
|
|
1011
1022
|
Landlock scopes `fs.read` and `fs.write` to, `exec_paths` the programs
|
|
1012
1023
|
`process.spawn` may execute, each a run of NUL-terminated paths ended by an
|
|
1013
1024
|
empty one; null leaves the capability whole.
|
|
1014
|
-
`nish_cpu_prime` caches the pool's CPU count while /sys is still readable.
|
|
1015
|
-
|
|
1025
|
+
`nish_cpu_prime` caches the pool's CPU count while /sys is still readable.
|
|
1026
|
+
`net_rings` (WP63 S3) is how many restricted io_uring rings to make before
|
|
1027
|
+
the filter loads, for `NET_LISTEN_RING`: the compiler passes 0 unless `net`
|
|
1028
|
+
is granted and `main` may reach the bit; rings are made only when
|
|
1029
|
+
`process.spawn` is not granted, since that filter keeps setup allowed. */
|
|
1030
|
+
void nish_sandbox(int32_t caps, int32_t mode, const char *read_dirs, const char *write_dirs, const char *exec_paths,
|
|
1031
|
+
int32_t net_rings);
|
|
1016
1032
|
void nish_sandbox_check(void);
|
|
1017
1033
|
/* SBX-1: set by `nish_sandbox` when the program has an exec allowlist;
|
|
1018
1034
|
`nish_spawn_start` (runtime-os.c) then leaves the spawn to it. It checks
|
package/runtime/nish.mjs
CHANGED
|
@@ -169,6 +169,7 @@ for (const name of [
|
|
|
169
169
|
"sendFd",
|
|
170
170
|
"recvFd",
|
|
171
171
|
"peerCredentials",
|
|
172
|
+
"netRingState",
|
|
172
173
|
]) {
|
|
173
174
|
provide(name, () => shim.noNetReading(name));
|
|
174
175
|
}
|
|
@@ -182,6 +183,7 @@ provide("NET_SO_RCVBUF", 5);
|
|
|
182
183
|
provide("NET_UNIX_UNLINK_STALE", 1);
|
|
183
184
|
provide("NET_UNIX_STREAM", 1);
|
|
184
185
|
provide("NET_UNIX_SEQPACKET", 2);
|
|
186
|
+
provide("NET_LISTEN_RING", 8);
|
|
185
187
|
|
|
186
188
|
// `nish:term`. Whether a descriptor is a terminal and how big stdout's is have
|
|
187
189
|
// Node's answers; reading stdin, waiting for it and raw mode throw, each naming
|
|
@@ -343,6 +345,8 @@ provide("arena", shim.arena);
|
|
|
343
345
|
// `nish:simd` is `runtime/core.mjs`, whose vectors are typed arrays made once
|
|
344
346
|
// and never written after, so `--emit-ts` output and a program run as it was
|
|
345
347
|
// written share one implementation.
|
|
348
|
+
// `nish:compact` is `runtime/core.mjs` too: its two marker interfaces pick a
|
|
349
|
+
// native layout and are empty values under Node.
|
|
346
350
|
const UNSAFE_EXPORTS = ["uncheckedGet", "uncheckedSet", "wrappingAdd", "wrappingSub", "wrappingMul"];
|
|
347
351
|
const unsafeSource = UNSAFE_EXPORTS.map((name) => `export const ${name} = globalThis.${name};`).join("\n");
|
|
348
352
|
// `nish:region` has no allocator to swap under Node: a region is an entry in a
|
|
@@ -440,7 +444,7 @@ registerHooks({
|
|
|
440
444
|
if (specifier === "nish:unsafe") {
|
|
441
445
|
return { url: `data:text/javascript,${encodeURIComponent(unsafeSource)}`, shortCircuit: true };
|
|
442
446
|
}
|
|
443
|
-
if (specifier === "nish:simd") {
|
|
447
|
+
if (specifier === "nish:simd" || specifier === "nish:compact") {
|
|
444
448
|
return next(new URL("./core.mjs", import.meta.url).href, context);
|
|
445
449
|
}
|
|
446
450
|
if (specifier === "nish:async") {
|
package/runtime/runtime-cross.c
CHANGED
|
@@ -177,6 +177,12 @@ void nish_cross_end(void *state) {
|
|
|
177
177
|
* in no chunk below the newest leaves the arena as it was, as the release
|
|
178
178
|
* does. */
|
|
179
179
|
static void nish_rewind(uint64_t mark) {
|
|
180
|
+
#ifdef NISH_ARENA_DEBUG
|
|
181
|
+
/* Keeping a chunk to bump in would let the next element's rewind stay in
|
|
182
|
+
compiled code, and never retire what it gave back. */
|
|
183
|
+
nish_arena_release(mark);
|
|
184
|
+
return;
|
|
185
|
+
#endif
|
|
180
186
|
struct nish_arena *a = &nish_arena;
|
|
181
187
|
nish_xchunk *top = a->chunks;
|
|
182
188
|
char *buf = (char *)(top + 1);
|
|
@@ -210,6 +216,8 @@ void *nish_cross_keep(void *v, uint64_t esize, uint64_t mark) {
|
|
|
210
216
|
if (!x) {
|
|
211
217
|
v = nish_cross_copy(v, esize);
|
|
212
218
|
} else {
|
|
219
|
+
/* `x->off` needs no realigning under NISH_ARENA_RANGE: only this
|
|
220
|
+
code bumps a transfer block, by `nish_cross_size`'s 8-byte multiples. */
|
|
213
221
|
uint64_t n = nish_cross_size(v, esize);
|
|
214
222
|
if (!x->block || x->block->cap - x->off < n) {
|
|
215
223
|
uint64_t want = x->block && x->block->cap < 32768 ? x->block->cap * 2 : x->block ? 65536 : 4096;
|
|
@@ -237,7 +245,14 @@ void *nish_cross_in(void *p, uint64_t esize) {
|
|
|
237
245
|
void *v = (void *)((uintptr_t)p & ~(uintptr_t)1);
|
|
238
246
|
nish_xchunk *c = (nish_xchunk *)v - 1;
|
|
239
247
|
uint64_t n = c->cap;
|
|
248
|
+
#ifdef NISH_ARENA_RANGE
|
|
249
|
+
/* What `nish_alloc_struct` would have left: it starts at `off` rounded up
|
|
250
|
+
to 8 (runtime.c gives the reason). */
|
|
251
|
+
uint64_t at = (nish_arena.off + 7) & ~(uint64_t)7;
|
|
252
|
+
if (n >= 65536 && (at > nish_arena.cap || n > nish_arena.cap - at)) {
|
|
253
|
+
#else
|
|
240
254
|
if (n >= 65536 && n > nish_arena.cap - nish_arena.off) {
|
|
255
|
+
#endif
|
|
241
256
|
nish_cross_link(c);
|
|
242
257
|
return v;
|
|
243
258
|
}
|