nish 0.35.0 → 0.36.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/docs/AI.md +9 -2
- package/docs/INSTALL.md +6 -1
- package/package.json +15 -5
- package/runtime/nish.d.ts +4612 -430
- package/runtime/vite.d.ts +30 -0
- package/runtime/vite.mjs +150 -0
- package/scripts/build.sh +108 -13
- package/std/base64.ts +34 -5
- package/std/bytes.ts +256 -40
- package/std/cli-args.ts +296 -70
- package/std/cli-flags.ts +184 -19
- package/std/cli.ts +475 -54
- package/std/collections.ts +121 -23
- package/std/compress/checksum.ts +44 -14
- package/std/compress/deflate.ts +224 -111
- package/std/compress/gzip.ts +217 -53
- package/std/compress/zlib.ts +63 -7
- package/std/crypto/aes.ts +80 -9
- package/std/crypto/base64url.ts +22 -0
- package/std/crypto/bcrypt-batch.ts +88 -21
- package/std/crypto/bcrypt.ts +60 -0
- package/std/crypto/chacha20poly1305.ts +53 -0
- package/std/crypto/ct.ts +32 -13
- package/std/crypto/ed25519.ts +47 -0
- package/std/crypto/hkdf.ts +198 -13
- package/std/crypto/hmac.ts +235 -31
- package/std/crypto/jwt.ts +192 -63
- package/std/crypto/p256.ts +159 -16
- package/std/crypto/p384.ts +28 -3
- package/std/crypto/pki-roots.ts +32 -2
- package/std/crypto/pki.ts +81 -15
- package/std/crypto/rsa.ts +33 -3
- package/std/crypto/sha1.ts +3 -0
- package/std/crypto/sha256.ts +24 -1
- package/std/crypto/sha512.ts +99 -14
- package/std/crypto/x25519.ts +152 -14
- package/std/crypto/x509-random.ts +10 -0
- package/std/crypto/x509.ts +67 -7
- package/std/json-equal.ts +19 -0
- package/std/json-format.ts +112 -13
- package/std/json-number.ts +64 -14
- package/std/json-pointer.ts +23 -1
- package/std/json-tokenizer.ts +100 -29
- package/std/json-typed.ts +713 -66
- package/std/json-value.ts +400 -124
- package/std/json.ts +138 -10
- package/std/map.ts +25 -7
- package/std/math.ts +36 -4
- package/std/net/buffer-pool.ts +42 -11
- package/std/net/dns-config.ts +109 -23
- package/std/net/dns-message.ts +62 -7
- package/std/net/dns-resolver.ts +247 -53
- package/std/net/dns.ts +203 -35
- package/std/net/fetch.ts +151 -61
- package/std/net/handler.ts +278 -80
- package/std/net/hpack.ts +262 -52
- package/std/net/http-compress.ts +125 -15
- package/std/net/http-fields.ts +85 -9
- package/std/net/http1-client-codec.ts +100 -19
- package/std/net/http1-codec.ts +235 -27
- package/std/net/http1-server.ts +343 -85
- package/std/net/http2-frame.ts +272 -35
- package/std/net/http2-tls.ts +135 -34
- package/std/net/http2.ts +247 -106
- package/std/net/http3-frame.ts +154 -17
- package/std/net/http3-server.ts +246 -96
- package/std/net/http3.ts +307 -115
- package/std/net/outbound.ts +37 -3
- package/std/net/postgres-carrier.ts +144 -8
- package/std/net/postgres.ts +723 -103
- package/std/net/prefork.ts +164 -31
- package/std/net/qpack.ts +105 -18
- package/std/net/quic-conn-ack.ts +59 -12
- package/std/net/quic-conn-cid.ts +124 -27
- package/std/net/quic-conn-params.ts +70 -10
- package/std/net/quic-datagram.ts +43 -3
- package/std/net/quic-frame.ts +286 -12
- package/std/net/quic-listener.ts +101 -32
- package/std/net/quic-packet.ts +302 -21
- package/std/net/quic-recovery.ts +228 -44
- package/std/net/quic-stream.ts +353 -91
- package/std/net/quic.ts +489 -171
- package/std/net/router.ts +87 -40
- package/std/net/tls/client.ts +166 -51
- package/std/net/tls/codec.ts +413 -56
- package/std/net/tls/record-client.ts +110 -55
- package/std/net/tls/record-server.ts +159 -59
- package/std/net/tls/record.ts +109 -12
- package/std/net/tls/schedule.ts +235 -26
- package/std/net/tls/ticket.ts +159 -40
- package/std/net/tls/verify.ts +49 -3
- package/std/net/tls-tcp.ts +250 -45
- package/std/net/tls.ts +221 -59
- package/std/net/upstream.ts +81 -45
- package/std/net/url.ts +97 -13
- package/std/net/websocket.ts +122 -12
- package/std/net/webtransport.ts +220 -89
- package/std/pair.ts +10 -2
- package/std/random.ts +34 -9
- package/std/regex.ts +352 -198
- package/std/region.ts +70 -15
- package/std/secret.ts +52 -11
- package/std/sort.ts +17 -2
- package/std/sqlite.ts +256 -35
- package/std/sync/ring.ts +205 -35
- package/std/sync/shm.ts +194 -16
- package/std/term-io.ts +137 -64
- package/std/term-pixels.ts +144 -19
- package/std/term-probe.ts +66 -25
- package/std/term-rate.ts +128 -57
- package/std/term.ts +332 -121
- package/std/testing.ts +130 -32
- package/std/text.ts +73 -7
- package/std/threads.ts +229 -41
- package/std/yaml-json.ts +94 -82
- package/std/yaml-lines.ts +47 -15
- package/std/yaml-write.ts +24 -16
- package/std/yaml.ts +764 -384
package/std/sync/shm.ts
CHANGED
|
@@ -139,6 +139,12 @@ export class ShmError {
|
|
|
139
139
|
/** What it means, such as `File exists`. */
|
|
140
140
|
message: string
|
|
141
141
|
|
|
142
|
+
/**
|
|
143
|
+
* The error for one errno, with its text: `strerror`'s, except that 95
|
|
144
|
+
* (`SHM_UNSUPPORTED` negated) reads "not supported on this platform".
|
|
145
|
+
* @param code the errno the runtime answered, positive (the negation of a
|
|
146
|
+
* failed call's result), such as `SHM_EXISTS`
|
|
147
|
+
*/
|
|
142
148
|
constructor(code: i32) {
|
|
143
149
|
this.code = code
|
|
144
150
|
this.message = code === 95 ? "not supported on this platform" : strerror(code)
|
|
@@ -156,6 +162,15 @@ const shmDone = (rc: i32): Result<void, ShmError> => {
|
|
|
156
162
|
/**
|
|
157
163
|
* Creates the region `name`, `bytes` long and zeroed, mode 0600, and maps it.
|
|
158
164
|
* `SHM_EXISTS` when the name is taken: unlink a stale one first.
|
|
165
|
+
* @param name the region's name, 1 to 30 of `A-Z a-z 0-9 . _ -`, not
|
|
166
|
+
* starting with `.`; anything else is `SHM_INVALID`
|
|
167
|
+
* @param bytes the region's length, from 1 to 1 GiB; outside that is
|
|
168
|
+
* `SHM_INVALID`
|
|
169
|
+
* @returns a new `SharedRegion` mapping the fresh region, which this thread
|
|
170
|
+
* alone can use and which stays mapped until its `close` or the process
|
|
171
|
+
* ends; or the `ShmError`: `SHM_EXISTS`, `SHM_INVALID`, `SHM_TOO_MANY`
|
|
172
|
+
* when this thread has 63 regions open, code 95 on wasi, or the errno the
|
|
173
|
+
* system gave
|
|
159
174
|
*/
|
|
160
175
|
export const createRegion = (name: string, bytes: i32): Result<SharedRegion, ShmError> => {
|
|
161
176
|
const h: i32 = nishshm_create(name, bytes)
|
|
@@ -168,6 +183,15 @@ export const createRegion = (name: string, bytes: i32): Result<SharedRegion, Shm
|
|
|
168
183
|
/**
|
|
169
184
|
* Maps the region `name` that some process of this user created. Its size is
|
|
170
185
|
* the region's (on Darwin, rounded up to a page).
|
|
186
|
+
* @param name the name the region was created under, with `createRegion`'s
|
|
187
|
+
* rules (`SHM_INVALID` otherwise)
|
|
188
|
+
* @returns a new `SharedRegion` on the same bytes every other mapping of the
|
|
189
|
+
* name sees, which this thread alone can use until its `close`; or the
|
|
190
|
+
* `ShmError`: `SHM_NOT_FOUND`, `SHM_ACCESS` for a region another user owns,
|
|
191
|
+
* that others may read or write, or (on Linux) that is not a regular file
|
|
192
|
+
* or has a second hard link, `SHM_INVALID` for a bad name or a region of
|
|
193
|
+
* size 0 or over 1 GiB, `SHM_TOO_MANY`, code 95 on wasi, or the errno the
|
|
194
|
+
* system gave
|
|
171
195
|
*/
|
|
172
196
|
export const openRegion = (name: string): Result<SharedRegion, ShmError> => {
|
|
173
197
|
const h: i32 = nishshm_open(name)
|
|
@@ -180,10 +204,21 @@ export const openRegion = (name: string): Result<SharedRegion, ShmError> => {
|
|
|
180
204
|
/**
|
|
181
205
|
* Removes the name, so no process can open it again; every mapping of it
|
|
182
206
|
* stays valid until it is closed. `SHM_NOT_FOUND` when there is none.
|
|
207
|
+
* @param name the region's name, with `createRegion`'s rules (`SHM_INVALID`
|
|
208
|
+
* otherwise)
|
|
209
|
+
* @returns `Ok()` once the name is gone, or the `ShmError`: `SHM_NOT_FOUND`,
|
|
210
|
+
* `SHM_INVALID`, code 95 on wasi, or the errno the system gave
|
|
183
211
|
*/
|
|
184
212
|
export const unlinkRegion = (name: string): Result<void, ShmError> => shmDone(nishshm_unlink(name))
|
|
185
213
|
|
|
186
|
-
/**
|
|
214
|
+
/**
|
|
215
|
+
* A fence of `order`, for the accesses around it: C11's
|
|
216
|
+
* `atomic_thread_fence`, so it orders the calling thread's accesses, to
|
|
217
|
+
* regions and to its own memory, exactly as that fence does; `RELAXED` is no
|
|
218
|
+
* fence at all.
|
|
219
|
+
* @param order `RELAXED`, `ACQUIRE`, `RELEASE`, `ACQ_REL` or `SEQ_CST`; any
|
|
220
|
+
* other value panics
|
|
221
|
+
*/
|
|
187
222
|
export const fence = (order: i32): void => {
|
|
188
223
|
nishshm_fence(order)
|
|
189
224
|
}
|
|
@@ -194,33 +229,72 @@ export const fence = (order: i32): void => {
|
|
|
194
229
|
*/
|
|
195
230
|
export class SharedRegion {
|
|
196
231
|
/** The runtime's handle; it names nothing after `close`. */
|
|
197
|
-
handle: i32
|
|
232
|
+
private handle: i32
|
|
198
233
|
|
|
234
|
+
/**
|
|
235
|
+
* Wraps a handle the runtime answered. A program gets a region from
|
|
236
|
+
* `createRegion` or `openRegion` instead; a handle that names no region
|
|
237
|
+
* open on this thread makes every access panic, and `close` answer code 9.
|
|
238
|
+
* @param handle the runtime's handle for a mapped region, as
|
|
239
|
+
* `nishshm_create` or `nishshm_open` answered it
|
|
240
|
+
*/
|
|
199
241
|
constructor(handle: i32) {
|
|
200
242
|
this.handle = handle
|
|
201
243
|
}
|
|
202
244
|
|
|
203
|
-
/**
|
|
245
|
+
/**
|
|
246
|
+
* The region's length in bytes.
|
|
247
|
+
* @returns the mapped length: what `createRegion` was given, or what
|
|
248
|
+
* `openRegion` found (on Darwin, rounded up to a page)
|
|
249
|
+
*/
|
|
204
250
|
size(): i32 {
|
|
205
251
|
return nishshm_size(this.handle)
|
|
206
252
|
}
|
|
207
253
|
|
|
208
|
-
/**
|
|
254
|
+
/**
|
|
255
|
+
* Loads the 32-bit slot at `at`, one atomic load.
|
|
256
|
+
* @param at the slot's byte offset from the region's start, a multiple of
|
|
257
|
+
* 4 with the whole slot inside the region; anything else panics
|
|
258
|
+
* @param order `RELAXED`, `ACQUIRE` or `SEQ_CST`; another panics
|
|
259
|
+
* @returns the value the slot held
|
|
260
|
+
*/
|
|
209
261
|
loadI32(at: i32, order: i32): i32 {
|
|
210
262
|
return nishshm_load_i32(this.handle, at, order)
|
|
211
263
|
}
|
|
212
264
|
|
|
213
|
-
/**
|
|
265
|
+
/**
|
|
266
|
+
* Sets the 32-bit slot at `at` to `value`, one atomic store.
|
|
267
|
+
* @param at the slot's byte offset from the region's start, a multiple of
|
|
268
|
+
* 4 with the whole slot inside the region; anything else panics
|
|
269
|
+
* @param value what the slot holds after
|
|
270
|
+
* @param order `RELAXED`, `RELEASE` or `SEQ_CST`; another panics
|
|
271
|
+
*/
|
|
214
272
|
storeI32(at: i32, value: i32, order: i32): void {
|
|
215
273
|
nishshm_store_i32(this.handle, at, value, order)
|
|
216
274
|
}
|
|
217
275
|
|
|
218
|
-
/**
|
|
276
|
+
/**
|
|
277
|
+
* Adds `delta` to the 32-bit slot at `at`, wrapping, and answers the value
|
|
278
|
+
* before, as one atomic read-modify-write.
|
|
279
|
+
* @param at the slot's byte offset from the region's start, a multiple of
|
|
280
|
+
* 4 with the whole slot inside the region; anything else panics
|
|
281
|
+
* @param delta what is added; negative subtracts
|
|
282
|
+
* @param order any of the five orderings; another value panics
|
|
283
|
+
* @returns the value the slot held just before the add
|
|
284
|
+
*/
|
|
219
285
|
addI32(at: i32, delta: i32, order: i32): i32 {
|
|
220
286
|
return nishshm_add_i32(this.handle, at, delta, order)
|
|
221
287
|
}
|
|
222
288
|
|
|
223
|
-
/**
|
|
289
|
+
/**
|
|
290
|
+
* Sets the 32-bit slot at `at` to `value` and answers the value before, as
|
|
291
|
+
* one atomic read-modify-write.
|
|
292
|
+
* @param at the slot's byte offset from the region's start, a multiple of
|
|
293
|
+
* 4 with the whole slot inside the region; anything else panics
|
|
294
|
+
* @param value what the slot holds after
|
|
295
|
+
* @param order any of the five orderings; another value panics
|
|
296
|
+
* @returns the value the slot held just before
|
|
297
|
+
*/
|
|
224
298
|
exchangeI32(at: i32, value: i32, order: i32): i32 {
|
|
225
299
|
return nishshm_exchange_i32(this.handle, at, value, order)
|
|
226
300
|
}
|
|
@@ -228,27 +302,65 @@ export class SharedRegion {
|
|
|
228
302
|
/**
|
|
229
303
|
* Sets the 32-bit slot at `at` to `desired` if it holds `expected`, and
|
|
230
304
|
* answers what it held: the exchange happened when that is `expected`.
|
|
305
|
+
* It never fails spuriously (a strong compare-exchange).
|
|
306
|
+
* @param at the slot's byte offset from the region's start, a multiple of
|
|
307
|
+
* 4 with the whole slot inside the region; anything else panics
|
|
308
|
+
* @param expected the value the slot must hold for the store to happen
|
|
309
|
+
* @param desired what the slot holds after, when it held `expected`
|
|
310
|
+
* @param order the ordering of a successful exchange, any of the five
|
|
311
|
+
* (another value panics); a failed one is a load ordered as C++ derives
|
|
312
|
+
* it (`ACQ_REL` fails `ACQUIRE`, `RELEASE` fails `RELAXED`, the others
|
|
313
|
+
* fail as themselves)
|
|
314
|
+
* @returns what the slot held: `expected` when the exchange happened
|
|
231
315
|
*/
|
|
232
316
|
compareExchangeI32(at: i32, expected: i32, desired: i32, order: i32): i32 {
|
|
233
317
|
return nishshm_cas_i32(this.handle, at, expected, desired, order)
|
|
234
318
|
}
|
|
235
319
|
|
|
236
|
-
/**
|
|
320
|
+
/**
|
|
321
|
+
* Loads the 64-bit slot at `at`, one atomic load.
|
|
322
|
+
* @param at the slot's byte offset from the region's start, a multiple of
|
|
323
|
+
* 8 with the whole slot inside the region; anything else panics
|
|
324
|
+
* @param order `RELAXED`, `ACQUIRE` or `SEQ_CST`; another panics
|
|
325
|
+
* @returns the value the slot held
|
|
326
|
+
*/
|
|
237
327
|
loadI64(at: i32, order: i32): i64 {
|
|
238
328
|
return nishshm_load_i64(this.handle, at, order)
|
|
239
329
|
}
|
|
240
330
|
|
|
241
|
-
/**
|
|
331
|
+
/**
|
|
332
|
+
* Sets the 64-bit slot at `at` to `value`, one atomic store.
|
|
333
|
+
* @param at the slot's byte offset from the region's start, a multiple of
|
|
334
|
+
* 8 with the whole slot inside the region; anything else panics
|
|
335
|
+
* @param value what the slot holds after
|
|
336
|
+
* @param order `RELAXED`, `RELEASE` or `SEQ_CST`; another panics
|
|
337
|
+
*/
|
|
242
338
|
storeI64(at: i32, value: i64, order: i32): void {
|
|
243
339
|
nishshm_store_i64(this.handle, at, value, order)
|
|
244
340
|
}
|
|
245
341
|
|
|
246
|
-
/**
|
|
342
|
+
/**
|
|
343
|
+
* Adds `delta` to the 64-bit slot at `at`, wrapping, and answers the value
|
|
344
|
+
* before, as one atomic read-modify-write.
|
|
345
|
+
* @param at the slot's byte offset from the region's start, a multiple of
|
|
346
|
+
* 8 with the whole slot inside the region; anything else panics
|
|
347
|
+
* @param delta what is added; negative subtracts
|
|
348
|
+
* @param order any of the five orderings; another value panics
|
|
349
|
+
* @returns the value the slot held just before the add
|
|
350
|
+
*/
|
|
247
351
|
addI64(at: i32, delta: i64, order: i32): i64 {
|
|
248
352
|
return nishshm_add_i64(this.handle, at, delta, order)
|
|
249
353
|
}
|
|
250
354
|
|
|
251
|
-
/**
|
|
355
|
+
/**
|
|
356
|
+
* Sets the 64-bit slot at `at` to `value` and answers the value before, as
|
|
357
|
+
* one atomic read-modify-write.
|
|
358
|
+
* @param at the slot's byte offset from the region's start, a multiple of
|
|
359
|
+
* 8 with the whole slot inside the region; anything else panics
|
|
360
|
+
* @param value what the slot holds after
|
|
361
|
+
* @param order any of the five orderings; another value panics
|
|
362
|
+
* @returns the value the slot held just before
|
|
363
|
+
*/
|
|
252
364
|
exchangeI64(at: i32, value: i64, order: i32): i64 {
|
|
253
365
|
return nishshm_exchange_i64(this.handle, at, value, order)
|
|
254
366
|
}
|
|
@@ -256,17 +368,45 @@ export class SharedRegion {
|
|
|
256
368
|
/**
|
|
257
369
|
* Sets the 64-bit slot at `at` to `desired` if it holds `expected`, and
|
|
258
370
|
* answers what it held: the exchange happened when that is `expected`.
|
|
371
|
+
* It never fails spuriously (a strong compare-exchange).
|
|
372
|
+
* @param at the slot's byte offset from the region's start, a multiple of
|
|
373
|
+
* 8 with the whole slot inside the region; anything else panics
|
|
374
|
+
* @param expected the value the slot must hold for the store to happen
|
|
375
|
+
* @param desired what the slot holds after, when it held `expected`
|
|
376
|
+
* @param order the ordering of a successful exchange, any of the five
|
|
377
|
+
* (another value panics); a failed one is a load ordered as C++ derives
|
|
378
|
+
* it (`ACQ_REL` fails `ACQUIRE`, `RELEASE` fails `RELAXED`, the others
|
|
379
|
+
* fail as themselves)
|
|
380
|
+
* @returns what the slot held: `expected` when the exchange happened
|
|
259
381
|
*/
|
|
260
382
|
compareExchangeI64(at: i32, expected: i64, desired: i64, order: i32): i64 {
|
|
261
383
|
return nishshm_cas_i64(this.handle, at, expected, desired, order)
|
|
262
384
|
}
|
|
263
385
|
|
|
264
|
-
/**
|
|
386
|
+
/**
|
|
387
|
+
* Copies `len` bytes of the region at `at` into `dst[off, off + len)`. A
|
|
388
|
+
* plain copy, not atomic: a writer in another process racing it can tear
|
|
389
|
+
* what it reads, and only the atomics around it order it.
|
|
390
|
+
* @param at where in the region the copy starts, in bytes
|
|
391
|
+
* @param dst the buffer the bytes land in
|
|
392
|
+
* @param off where in `dst` the first byte goes
|
|
393
|
+
* @param len how many bytes to copy; the range must fit both the region from
|
|
394
|
+
* `at` and `dst` from `off`, or it panics
|
|
395
|
+
*/
|
|
265
396
|
read(at: i32, dst: u8[], off: i32, len: i32): void {
|
|
266
397
|
nishshm_read(this.handle, at, dst, toU64(dst.length), toU64(off), toU64(len))
|
|
267
398
|
}
|
|
268
399
|
|
|
269
|
-
/**
|
|
400
|
+
/**
|
|
401
|
+
* Copies `src[off, off + len)` into the region at `at`. A plain copy, not
|
|
402
|
+
* atomic: publish it to another process with a `RELEASE` (or `SEQ_CST`)
|
|
403
|
+
* store after it.
|
|
404
|
+
* @param at where in the region the first byte goes
|
|
405
|
+
* @param src the bytes to copy
|
|
406
|
+
* @param off where in `src` the copy starts
|
|
407
|
+
* @param len how many bytes to copy; the range must fit both `src` from `off`
|
|
408
|
+
* and the region from `at`, or it panics
|
|
409
|
+
*/
|
|
270
410
|
write(at: i32, src: readonly u8[], off: i32, len: i32): void {
|
|
271
411
|
nishshm_write(this.handle, at, src, toU64(src.length), toU64(off), toU64(len))
|
|
272
412
|
}
|
|
@@ -274,7 +414,17 @@ export class SharedRegion {
|
|
|
274
414
|
/**
|
|
275
415
|
* Sleeps while the 32-bit slot at `at` holds `expected`, at most
|
|
276
416
|
* `timeoutMs` (negative: no limit): `SHM_WOKEN`, `SHM_NOT_EQUAL`,
|
|
277
|
-
* `SHM_TIMED_OUT`, or `SHM_UNSUPPORTED` off Linux.
|
|
417
|
+
* `SHM_TIMED_OUT`, or `SHM_UNSUPPORTED` off Linux. It promises no
|
|
418
|
+
* ordering: load the slot again, with the ordering the caller needs, after
|
|
419
|
+
* it returns.
|
|
420
|
+
* @param at the 32-bit slot's byte offset, a multiple of 4 inside the
|
|
421
|
+
* region; anything else panics, off Linux too
|
|
422
|
+
* @param expected the value the slot must still hold for the call to sleep
|
|
423
|
+
* @param timeoutMs the longest sleep, in milliseconds; negative for no limit
|
|
424
|
+
* @returns `SHM_WOKEN` when woken, interrupted by a signal or for no reason
|
|
425
|
+
* the caller can see; `SHM_NOT_EQUAL` when the slot did not hold
|
|
426
|
+
* `expected`; `SHM_TIMED_OUT`; `SHM_UNSUPPORTED` off Linux; or another
|
|
427
|
+
* negated errno the futex gave
|
|
278
428
|
*/
|
|
279
429
|
waitI32(at: i32, expected: i32, timeoutMs: i32): i32 {
|
|
280
430
|
return nishshm_wait_i32(this.handle, at, expected, timeoutMs)
|
|
@@ -283,6 +433,11 @@ export class SharedRegion {
|
|
|
283
433
|
/**
|
|
284
434
|
* Wakes at most `count` of the processes sleeping on the 32-bit slot at
|
|
285
435
|
* `at`: how many it woke, or `SHM_UNSUPPORTED` off Linux.
|
|
436
|
+
* @param at the 32-bit slot's byte offset, a multiple of 4 inside the
|
|
437
|
+
* region; anything else panics, off Linux too
|
|
438
|
+
* @param count the most sleepers to wake; negative wakes none
|
|
439
|
+
* @returns how many it woke, in any process; `SHM_UNSUPPORTED` off Linux, or
|
|
440
|
+
* another negated errno the futex gave
|
|
286
441
|
*/
|
|
287
442
|
wake(at: i32, count: i32): i32 {
|
|
288
443
|
return nishshm_wake(this.handle, at, count)
|
|
@@ -296,17 +451,40 @@ export class SharedRegion {
|
|
|
296
451
|
* memory, after which it is no window and `giveBack` panics. Pass a window
|
|
297
452
|
* already given back as `reuse` to lend it again without a new header: each
|
|
298
453
|
* lend without one keeps a few bytes for the life of the process.
|
|
454
|
+
* @param at where in the region the window starts, in bytes
|
|
455
|
+
* @param len the window's length in bytes; `[at, at + len)` must lie inside
|
|
456
|
+
* the region, or it panics
|
|
457
|
+
* @param reuse null for a new window, or a window this region lent and that
|
|
458
|
+
* was given back, to re-point; any other array panics
|
|
459
|
+
* @returns the window: `reuse` itself when one was passed, otherwise a new
|
|
460
|
+
* array. Its bytes are the region's, shared with every process that maps
|
|
461
|
+
* it, until `giveBack` or `close`
|
|
299
462
|
*/
|
|
300
463
|
lend(at: i32, len: i32, reuse: u8[] | null = null): u8[] {
|
|
301
464
|
return shmLend(this.handle, at, len, reuse)
|
|
302
465
|
}
|
|
303
466
|
|
|
304
|
-
/**
|
|
467
|
+
/**
|
|
468
|
+
* Empties `window`, which this region lent, and answers the length it had.
|
|
469
|
+
* After it the array has length 0 and may be passed to `lend` as `reuse`.
|
|
470
|
+
* @param window a window this region lent and that is still lent; one given
|
|
471
|
+
* back already, lent by another region, or moved off the region by a
|
|
472
|
+
* `push` panics
|
|
473
|
+
* @returns the window's length just before (a `pop` may have shortened it)
|
|
474
|
+
*/
|
|
305
475
|
giveBack(window: u8[]): i32 {
|
|
306
476
|
return shmGiveBack(this.handle, window)
|
|
307
477
|
}
|
|
308
478
|
|
|
309
|
-
/**
|
|
479
|
+
/**
|
|
480
|
+
* Unmaps the region; the handle names nothing after. The name stays until
|
|
481
|
+
* `unlinkRegion`. Every window still lent from it is emptied first, so an
|
|
482
|
+
* index into one after this panics rather than reading unmapped memory (a
|
|
483
|
+
* window a `push` moved off the region is the program's own array, and is
|
|
484
|
+
* left alone); any other access through this object panics too.
|
|
485
|
+
* @returns `Ok()` once it is unmapped, or a `ShmError` of code 9 when it was
|
|
486
|
+
* closed already (or on wasi, where no region opens)
|
|
487
|
+
*/
|
|
310
488
|
close(): Result<void, ShmError> {
|
|
311
489
|
return shmDone(nishshm_close(this.handle))
|
|
312
490
|
}
|