@amritk/nish-aarch64-linux 0.41.0 → 0.42.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/package.json +2 -2
- package/runtime/nish.d.ts +84 -14
- package/runtime/nish.h +19 -3
- package/runtime/nish.mjs +2 -0
- package/runtime/runtime-cross.c +6 -0
- package/runtime/runtime-net.c +837 -9
- package/runtime/runtime-region.c +8 -0
- package/runtime/runtime-sandbox.c +112 -15
- package/runtime/runtime-uring.c +454 -56
- package/runtime/runtime.c +148 -2
- package/scripts/build.sh +14 -0
- package/std/net/fetch.ts +9 -1
- package/std/net/handler.ts +78 -14
- package/std/net/http1-server.ts +13 -0
- package/std/net/oidc.ts +1107 -0
package/bin/nish
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amritk/nish-aarch64-linux",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.0",
|
|
4
4
|
"description": "The nish native compiler for Linux on ARM64",
|
|
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/nish.d.ts
CHANGED
|
@@ -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
|
/**
|
|
@@ -1898,8 +1909,8 @@ declare function pollCreate(): i32;
|
|
|
1898
1909
|
* @param events 1 readable, 2 writable, 3 both, 0 neither.
|
|
1899
1910
|
* @param token an `i32` of the program's choosing, which `pollWait` reports it under as it went
|
|
1900
1911
|
* in.
|
|
1901
|
-
* @returns 0, or a negative errno: -17 for a descriptor the loop already watches,
|
|
1902
|
-
* event bit past 2.
|
|
1912
|
+
* @returns 0, or a negative errno: -17 for a descriptor the loop already watches, or for a slot
|
|
1913
|
+
* handle another loop watches (a slot is in one loop at a time), -22 for an event bit past 2.
|
|
1903
1914
|
*/
|
|
1904
1915
|
declare function pollAdd(loop: i32, fd: i32, events: i32, token: i32): i32;
|
|
1905
1916
|
/**
|
|
@@ -1931,7 +1942,10 @@ declare function pollRemove(loop: i32, fd: i32): i32;
|
|
|
1931
1942
|
* `i32`s) and not `readonly`. A signal that interrupts the wait makes it answer
|
|
1932
1943
|
* 0, as a timeout does, rather than wait past the deadline; the descriptor
|
|
1933
1944
|
* `signalFd()` answers can be added to the loop, and is readable when SIGTERM
|
|
1934
|
-
* or SIGINT arrives.
|
|
1945
|
+
* or SIGINT arrives. Once the process has opened a `NET_LISTEN_RING`
|
|
1946
|
+
* listener with rings, for the rest of its life, an interrupted wait goes on
|
|
1947
|
+
* to its deadline, since the rings' own work interrupts it too: watch
|
|
1948
|
+
* `signalFd()` to see a signal.
|
|
1935
1949
|
*
|
|
1936
1950
|
* A UDP socket is always writable, and on Linux one whose both sides are shut
|
|
1937
1951
|
* is readable, writable and hung up, 7. On Darwin a descriptor both readable
|
|
@@ -2196,6 +2210,28 @@ declare const NET_UNIX_STREAM: i32;
|
|
|
2196
2210
|
* Capability: none.
|
|
2197
2211
|
*/
|
|
2198
2212
|
declare const NET_UNIX_SEQPACKET: i32;
|
|
2213
|
+
/**
|
|
2214
|
+
* `tcpListenFlags` flag 8: accept into io_uring slots instead of descriptors (WP63 S2, Linux). A
|
|
2215
|
+
* connection accepted from such a listener is a slot handle, a number at or above 2^20 that
|
|
2216
|
+
* `netRead`, `netWrite`, `netWrite2`, `netClose`, `netLocalPort` and the poll loop take as they
|
|
2217
|
+
* take a descriptor, except that a slot is in one poll loop at a time (a second loop's `pollAdd`
|
|
2218
|
+
* answers -17); `netSetOption` answers -95 and every other call -9. A program can so hold
|
|
2219
|
+
* more connections than its descriptor limit. Where the kernel refuses rings the listener serves
|
|
2220
|
+
* descriptors, and `netRingState` says why. Inert on Darwin. Capability: none.
|
|
2221
|
+
*/
|
|
2222
|
+
declare const NET_LISTEN_RING: i32;
|
|
2223
|
+
/**
|
|
2224
|
+
* Whether listeners opened with `NET_LISTEN_RING` accept into rings: 1 when they do, 0 until a
|
|
2225
|
+
* listener has found rings or a refusal, or the negative errno the kernel refused rings with (-1
|
|
2226
|
+
* when a seccomp filter refuses `io_uring_setup`, -38 for a kernel without it), in which case they
|
|
2227
|
+
* serve descriptors. Decided once per process, by the first listener that finds rings or a
|
|
2228
|
+
* refusal; one that finds descriptors or memory short serves descriptors itself and leaves the
|
|
2229
|
+
* state at 0, and a later listener asks again. -95 on Darwin. Refused at
|
|
2230
|
+
* compile time on wasm32 and the WASI profile (NL2404). Capability: net.
|
|
2231
|
+
*
|
|
2232
|
+
* @returns 1, 0 or the negative errno.
|
|
2233
|
+
*/
|
|
2234
|
+
declare function netRingState(): i32;
|
|
2199
2235
|
|
|
2200
2236
|
// ---- `nish:term` ------------------------------------------------------------------
|
|
2201
2237
|
//
|
|
@@ -3115,14 +3151,27 @@ declare module "nish:net" {
|
|
|
3115
3151
|
* the index of the CPU that received it, in the order the group's listeners
|
|
3116
3152
|
* were bound; a CPU past the group's size falls back to the hash.
|
|
3117
3153
|
*
|
|
3154
|
+
* Flag 8, `NET_LISTEN_RING`, accepts into io_uring slots on Linux: each
|
|
3155
|
+
* connection is a slot handle at or above 2^20 rather than a descriptor, so
|
|
3156
|
+
* a listener holds connections past `RLIMIT_NOFILE`. `netRead`, `netWrite`,
|
|
3157
|
+
* `netWrite2`, `netClose`, `netLocalPort` and the poll loop take a slot
|
|
3158
|
+
* handle; `netSetOption` answers `-95`, and calls that need a descriptor,
|
|
3159
|
+
* `sendFd` among them, answer `-9`.
|
|
3160
|
+
* The first listener that finds rings or a refusal decides for the process:
|
|
3161
|
+
* where the kernel refuses rings it serves descriptors, and `netRingState`
|
|
3162
|
+
* answers the errno. A listener whose rings fail for want of descriptors or
|
|
3163
|
+
* memory serves descriptors itself, and a later listener asks again. Off
|
|
3164
|
+
* Linux the flag is accepted and does nothing.
|
|
3165
|
+
*
|
|
3118
3166
|
* @param host A numeric host, as for `tcpListen`.
|
|
3119
3167
|
* @param port The port.
|
|
3120
3168
|
* @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.
|
|
3169
|
+
* @param flags The sum of the flags: `3` is both, `5` and `7` steer, `8`
|
|
3170
|
+
* accepts into rings, and `0` is `tcpListen` exactly.
|
|
3123
3171
|
* @returns The listener's descriptor or the failure: `-22` for any other
|
|
3124
3172
|
* bit, a negative `flags`, or flag 4 without 1, before a socket is made;
|
|
3125
|
-
* `-95` for flag 4 off Linux
|
|
3173
|
+
* `-95` for flag 4 off Linux; `-23` once the process has opened 31 ring
|
|
3174
|
+
* listeners, closed or not.
|
|
3126
3175
|
*/
|
|
3127
3176
|
export function tcpListenFlags(host: string, port: i32, backlog: i32, flags: i32): i32;
|
|
3128
3177
|
/**
|
|
@@ -3132,9 +3181,16 @@ declare module "nish:net" {
|
|
|
3132
3181
|
*
|
|
3133
3182
|
* @param fd The listener.
|
|
3134
3183
|
* @param peer The array the peer's address form is written into.
|
|
3135
|
-
* @returns The connection's descriptor
|
|
3136
|
-
*
|
|
3137
|
-
*
|
|
3184
|
+
* @returns The connection's descriptor (a slot handle from a
|
|
3185
|
+
* `NET_LISTEN_RING` listener, whose `peer` is written as zeros), `-11`
|
|
3186
|
+
* when none is waiting, `-23` when a ring listener's slots are all
|
|
3187
|
+
* taken, `-22` for a `peer` shorter than 18 bytes before anything is
|
|
3188
|
+
* accepted (so no connection is taken and lost), or `-95` for a
|
|
3189
|
+
* datagram socket. A ring listener whose accept found memory short
|
|
3190
|
+
* answers `-12` or `-105` once, pauses for a back-off (10 ms, doubling
|
|
3191
|
+
* to 640 ms while it recurs) and accepts again. Any other errno but
|
|
3192
|
+
* `-11`, `-4`, `-103` or `-71` stops it accepting and is answered from
|
|
3193
|
+
* then on; close it and listen again.
|
|
3138
3194
|
*/
|
|
3139
3195
|
export function tcpAccept(fd: i32, peer: u8[]): i32;
|
|
3140
3196
|
/**
|
|
@@ -3316,7 +3372,9 @@ declare module "nish:net" {
|
|
|
3316
3372
|
* @param token An `i32` of the program's choosing that comes back as it went
|
|
3317
3373
|
* in.
|
|
3318
3374
|
* @returns `0`, `-17` for a descriptor the loop already watches (on Darwin
|
|
3319
|
-
* it is left under the new token)
|
|
3375
|
+
* it is left under the new token) or for a slot handle another loop
|
|
3376
|
+
* watches (a slot is in one loop at a time), or `-22` for an event bit
|
|
3377
|
+
* past `2`.
|
|
3320
3378
|
*/
|
|
3321
3379
|
export function pollAdd(loop: i32, fd: i32, events: i32, token: i32): i32;
|
|
3322
3380
|
/**
|
|
@@ -3342,7 +3400,9 @@ declare module "nish:net" {
|
|
|
3342
3400
|
* one pair per ready descriptor: `ready[2k]` its token and `ready[2k + 1]`
|
|
3343
3401
|
* its events, `1` readable and `2` writable, with `4` added for a hang-up or
|
|
3344
3402
|
* an error. A signal that interrupts the wait answers `0`, as a timeout
|
|
3345
|
-
* does
|
|
3403
|
+
* does, until the process opens a `NET_LISTEN_RING` listener with rings:
|
|
3404
|
+
* 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
|
|
3405
|
+
* `willreturn`, because it can wait forever. Nothing allocates,
|
|
3346
3406
|
* and `ready` is never written past its length.
|
|
3347
3407
|
*
|
|
3348
3408
|
* @param loop The loop.
|
|
@@ -3540,6 +3600,16 @@ declare module "nish:net" {
|
|
|
3540
3600
|
export const NET_UNIX_STREAM: i32;
|
|
3541
3601
|
/** `unixSocketPair` kind: each write one message (`SOCK_SEQPACKET`). */
|
|
3542
3602
|
export const NET_UNIX_SEQPACKET: i32;
|
|
3603
|
+
/** `tcpListenFlags` flag 8: accept into io_uring slots instead of descriptors. */
|
|
3604
|
+
export const NET_LISTEN_RING: i32;
|
|
3605
|
+
/**
|
|
3606
|
+
* Whether `NET_LISTEN_RING` listeners accept into rings.
|
|
3607
|
+
*
|
|
3608
|
+
* @returns `1` when they do, `0` until a listener has found rings or a
|
|
3609
|
+
* refusal, or the negative errno rings were refused with, in which case
|
|
3610
|
+
* they serve descriptors.
|
|
3611
|
+
*/
|
|
3612
|
+
export function netRingState(): i32;
|
|
3543
3613
|
}
|
|
3544
3614
|
|
|
3545
3615
|
/**
|
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
|
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);
|