@pgxsinkit/pgwasm 0.5.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/LICENSE +21 -0
- package/LICENSE-APACHE-2.0 +202 -0
- package/NOTICE +111 -0
- package/README.md +56 -0
- package/dist/build/index.d.ts +8 -0
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +21 -0
- package/dist/build/index.js.map +9 -0
- package/dist/build/seam.d.ts +174 -0
- package/dist/build/seam.d.ts.map +1 -0
- package/dist/chunk-0w227vw2.js +233 -0
- package/dist/chunk-0w227vw2.js.map +11 -0
- package/dist/chunk-74gcrk47.js +563 -0
- package/dist/chunk-74gcrk47.js.map +14 -0
- package/dist/chunk-at1py5s5.js +373 -0
- package/dist/chunk-at1py5s5.js.map +12 -0
- package/dist/chunk-cpsnmzrf.js +126 -0
- package/dist/chunk-cpsnmzrf.js.map +10 -0
- package/dist/chunk-d82gg1hx.js +306 -0
- package/dist/chunk-d82gg1hx.js.map +10 -0
- package/dist/chunk-gjf102c9.js +1005 -0
- package/dist/chunk-gjf102c9.js.map +16 -0
- package/dist/chunk-kb3rsr7n.js +19 -0
- package/dist/chunk-kb3rsr7n.js.map +9 -0
- package/dist/chunk-tdvrvgt5.js +83 -0
- package/dist/chunk-tdvrvgt5.js.map +11 -0
- package/dist/chunk-z0c40tja.js +50 -0
- package/dist/chunk-z0c40tja.js.map +10 -0
- package/dist/core/data-dir-archive.d.ts +17 -0
- package/dist/core/data-dir-archive.d.ts.map +1 -0
- package/dist/core/internals.d.ts +59 -0
- package/dist/core/internals.d.ts.map +1 -0
- package/dist/core/marker.d.ts +35 -0
- package/dist/core/marker.d.ts.map +1 -0
- package/dist/core/mutex.d.ts +9 -0
- package/dist/core/mutex.d.ts.map +1 -0
- package/dist/core/names.d.ts +11 -0
- package/dist/core/names.d.ts.map +1 -0
- package/dist/core/parse.d.ts +11 -0
- package/dist/core/parse.d.ts.map +1 -0
- package/dist/core/pgwasm.d.ts +53 -0
- package/dist/core/pgwasm.d.ts.map +1 -0
- package/dist/core/storage.d.ts +14 -0
- package/dist/core/storage.d.ts.map +1 -0
- package/dist/create.d.ts +10 -0
- package/dist/create.d.ts.map +1 -0
- package/dist/drizzle/codecs.d.ts +9 -0
- package/dist/drizzle/codecs.d.ts.map +1 -0
- package/dist/drizzle/driver.d.ts +50 -0
- package/dist/drizzle/driver.d.ts.map +1 -0
- package/dist/drizzle/index.d.ts +4 -0
- package/dist/drizzle/index.d.ts.map +1 -0
- package/dist/drizzle/index.js +261 -0
- package/dist/drizzle/index.js.map +12 -0
- package/dist/drizzle/session.d.ts +39 -0
- package/dist/drizzle/session.d.ts.map +1 -0
- package/dist/errors.d.ts +115 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/fs/base-filesystem.d.ts +118 -0
- package/dist/fs/base-filesystem.d.ts.map +1 -0
- package/dist/fs/index.d.ts +2 -0
- package/dist/fs/index.d.ts.map +1 -0
- package/dist/fs/index.js +11 -0
- package/dist/fs/index.js.map +9 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +9 -0
- package/dist/interface.d.ts +165 -0
- package/dist/interface.d.ts.map +1 -0
- package/dist/live/debounce-mutex.d.ts +6 -0
- package/dist/live/debounce-mutex.d.ts.map +1 -0
- package/dist/live/format-query.d.ts +8 -0
- package/dist/live/format-query.d.ts.map +1 -0
- package/dist/live/index.d.ts +9 -0
- package/dist/live/index.d.ts.map +1 -0
- package/dist/live/index.js +601 -0
- package/dist/live/index.js.map +12 -0
- package/dist/live/interface.d.ts +86 -0
- package/dist/live/interface.d.ts.map +1 -0
- package/dist/opfs/broker/client.d.ts +163 -0
- package/dist/opfs/broker/client.d.ts.map +1 -0
- package/dist/opfs/broker/protocol.d.ts +326 -0
- package/dist/opfs/broker/protocol.d.ts.map +1 -0
- package/dist/opfs/broker/server.d.ts +84 -0
- package/dist/opfs/broker/server.d.ts.map +1 -0
- package/dist/opfs/core/checksum.d.ts +3 -0
- package/dist/opfs/core/checksum.d.ts.map +1 -0
- package/dist/opfs/core/codec.d.ts +73 -0
- package/dist/opfs/core/codec.d.ts.map +1 -0
- package/dist/opfs/core/errors.d.ts +80 -0
- package/dist/opfs/core/errors.d.ts.map +1 -0
- package/dist/opfs/core/limits.d.ts +35 -0
- package/dist/opfs/core/limits.d.ts.map +1 -0
- package/dist/opfs/core/memory-port.d.ts +51 -0
- package/dist/opfs/core/memory-port.d.ts.map +1 -0
- package/dist/opfs/core/metadata-store.d.ts +19 -0
- package/dist/opfs/core/metadata-store.d.ts.map +1 -0
- package/dist/opfs/core/mounted-vfs.d.ts +119 -0
- package/dist/opfs/core/mounted-vfs.d.ts.map +1 -0
- package/dist/opfs/core/path.d.ts +14 -0
- package/dist/opfs/core/path.d.ts.map +1 -0
- package/dist/opfs/core/port.d.ts +30 -0
- package/dist/opfs/core/port.d.ts.map +1 -0
- package/dist/opfs/core/repacked-vfs.d.ts +138 -0
- package/dist/opfs/core/repacked-vfs.d.ts.map +1 -0
- package/dist/opfs/core/state-machine.d.ts +296 -0
- package/dist/opfs/core/state-machine.d.ts.map +1 -0
- package/dist/opfs/create.d.ts +50 -0
- package/dist/opfs/create.d.ts.map +1 -0
- package/dist/opfs/file-port.d.ts +14 -0
- package/dist/opfs/file-port.d.ts.map +1 -0
- package/dist/opfs/index.d.ts +37 -0
- package/dist/opfs/index.d.ts.map +1 -0
- package/dist/opfs/index.js +6671 -0
- package/dist/opfs/index.js.map +28 -0
- package/dist/opfs/opfs-port.d.ts +34 -0
- package/dist/opfs/opfs-port.d.ts.map +1 -0
- package/dist/opfs/opfs-repacked-fs.d.ts +55 -0
- package/dist/opfs/opfs-repacked-fs.d.ts.map +1 -0
- package/dist/opfs/wasi/preview1.d.ts +228 -0
- package/dist/opfs/wasi/preview1.d.ts.map +1 -0
- package/dist/protocol/index.d.ts +15 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +23 -0
- package/dist/protocol/index.js.map +10 -0
- package/dist/protocol/wire/buffer-reader.d.ts +13 -0
- package/dist/protocol/wire/buffer-reader.d.ts.map +1 -0
- package/dist/protocol/wire/buffer-writer.d.ts +12 -0
- package/dist/protocol/wire/buffer-writer.d.ts.map +1 -0
- package/dist/protocol/wire/index.d.ts +5 -0
- package/dist/protocol/wire/index.d.ts.map +1 -0
- package/dist/protocol/wire/messages.d.ts +194 -0
- package/dist/protocol/wire/messages.d.ts.map +1 -0
- package/dist/protocol/wire/parser.d.ts +12 -0
- package/dist/protocol/wire/parser.d.ts.map +1 -0
- package/dist/protocol/wire/serializer.d.ts +61 -0
- package/dist/protocol/wire/serializer.d.ts.map +1 -0
- package/dist/protocol/wire/string-utils.d.ts +6 -0
- package/dist/protocol/wire/string-utils.d.ts.map +1 -0
- package/dist/protocol/wire/types.d.ts +7 -0
- package/dist/protocol/wire/types.d.ts.map +1 -0
- package/dist/tar/gzip.d.ts +7 -0
- package/dist/tar/gzip.d.ts.map +1 -0
- package/dist/tar/tar.d.ts +39 -0
- package/dist/tar/tar.d.ts.map +1 -0
- package/dist/templating.d.ts +42 -0
- package/dist/templating.d.ts.map +1 -0
- package/dist/types.d.ts +76 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +69 -0
- package/skills/opfs/SKILL.md +138 -0
- package/src/build/index.ts +23 -0
- package/src/build/seam.ts +179 -0
- package/src/core/data-dir-archive.ts +68 -0
- package/src/core/internals.ts +87 -0
- package/src/core/marker.ts +94 -0
- package/src/core/mutex.ts +16 -0
- package/src/core/names.ts +26 -0
- package/src/core/parse.ts +79 -0
- package/src/core/pgwasm.ts +876 -0
- package/src/core/storage.ts +70 -0
- package/src/create.ts +134 -0
- package/src/drizzle/codecs.ts +114 -0
- package/src/drizzle/driver.ts +141 -0
- package/src/drizzle/index.ts +15 -0
- package/src/drizzle/session.ts +133 -0
- package/src/errors.ts +201 -0
- package/src/fs/base-filesystem.ts +149 -0
- package/src/fs/index.ts +7 -0
- package/src/index.ts +44 -0
- package/src/interface.ts +186 -0
- package/src/live/debounce-mutex.ts +45 -0
- package/src/live/format-query.ts +47 -0
- package/src/live/index.ts +707 -0
- package/src/live/interface.ts +109 -0
- package/src/opfs/broker/client.ts +482 -0
- package/src/opfs/broker/protocol.ts +624 -0
- package/src/opfs/broker/server.ts +522 -0
- package/src/opfs/core/checksum.ts +85 -0
- package/src/opfs/core/codec.ts +1051 -0
- package/src/opfs/core/errors.ts +134 -0
- package/src/opfs/core/limits.ts +68 -0
- package/src/opfs/core/memory-port.ts +459 -0
- package/src/opfs/core/metadata-store.ts +512 -0
- package/src/opfs/core/mounted-vfs.ts +407 -0
- package/src/opfs/core/path.ts +82 -0
- package/src/opfs/core/port.ts +114 -0
- package/src/opfs/core/repacked-vfs.ts +1464 -0
- package/src/opfs/core/state-machine.ts +1699 -0
- package/src/opfs/create.ts +125 -0
- package/src/opfs/file-port.ts +183 -0
- package/src/opfs/index.ts +113 -0
- package/src/opfs/opfs-port.ts +90 -0
- package/src/opfs/opfs-repacked-fs.ts +210 -0
- package/src/opfs/wasi/preview1.ts +1016 -0
- package/src/protocol/index.ts +24 -0
- package/src/protocol/wire/buffer-reader.ts +60 -0
- package/src/protocol/wire/buffer-writer.ts +93 -0
- package/src/protocol/wire/index.ts +15 -0
- package/src/protocol/wire/messages.ts +332 -0
- package/src/protocol/wire/parser.ts +373 -0
- package/src/protocol/wire/serializer.ts +233 -0
- package/src/protocol/wire/string-utils.ts +18 -0
- package/src/protocol/wire/types.ts +12 -0
- package/src/tar/gzip.ts +36 -0
- package/src/tar/tar.ts +253 -0
- package/src/templating.ts +103 -0
- package/src/types.ts +283 -0
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `RepackedSyncBroker` — the single owner of one `RepackedVfs`, answering synchronous file requests
|
|
3
|
+
* that arrive over `SharedArrayBuffer` channels.
|
|
4
|
+
*
|
|
5
|
+
* The broker is meant to be the only thing on its thread. A backend running wasm parks in futexes and
|
|
6
|
+
* cannot await anything, so it publishes a request and blocks; the broker must therefore never block on
|
|
7
|
+
* a promise between reading a request and writing its answer. Every handler here is synchronous, and
|
|
8
|
+
* the store's own API is synchronous end to end.
|
|
9
|
+
*
|
|
10
|
+
* Three loop shapes are offered:
|
|
11
|
+
*
|
|
12
|
+
* - `serveForever()` parks the thread in `Atomics.wait` between requests. It is the shape for a
|
|
13
|
+
* dedicated coordinator worker, and while it runs the thread never reaches its event loop — so
|
|
14
|
+
* `postMessage` cannot reach it and every channel must be attached BEFORE entering it. Ask it to
|
|
15
|
+
* return with `doorbell.requestStop()` from any thread holding the doorbell.
|
|
16
|
+
* - `serve()` is the same loop built on `Atomics.waitAsync`, for a host that must keep its event loop
|
|
17
|
+
* alive. Channels may be attached and detached at any time.
|
|
18
|
+
* - `serveOnce()` scans every attached channel once and returns without waiting, for a host that
|
|
19
|
+
* drives its own loop.
|
|
20
|
+
*
|
|
21
|
+
* Failure separation is the point of the class. A file rejection (`FsError`) becomes an errno in the
|
|
22
|
+
* reply header and nothing else happens. A store failure becomes `FAULT_STORE` in the reply, and the
|
|
23
|
+
* loop keeps running because every later request will fail the same way and the client decides what to
|
|
24
|
+
* do. A protocol violation detaches only the offending client, with a logged reason.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { FS_ERRNO, FsError } from "../core/errors";
|
|
28
|
+
import type { RepackedFileSystem, RepackedStat } from "../core/repacked-vfs";
|
|
29
|
+
import {
|
|
30
|
+
FAULT_DETACHED,
|
|
31
|
+
FAULT_NONE,
|
|
32
|
+
FAULT_PROTOCOL,
|
|
33
|
+
FAULT_STORE,
|
|
34
|
+
HEADER_ERRNO,
|
|
35
|
+
HEADER_FAULT,
|
|
36
|
+
HEADER_OPCODE,
|
|
37
|
+
HEADER_REQUEST,
|
|
38
|
+
HEADER_RESPONSE,
|
|
39
|
+
HEADER_RESULT_HI,
|
|
40
|
+
HEADER_RESULT_LO,
|
|
41
|
+
HEADER_STATE,
|
|
42
|
+
OPCODE_CLOSE,
|
|
43
|
+
OPCODE_FSTAT,
|
|
44
|
+
OPCODE_FSYNC,
|
|
45
|
+
OPCODE_LSTAT,
|
|
46
|
+
OPCODE_MKDIR,
|
|
47
|
+
OPCODE_OPEN,
|
|
48
|
+
OPCODE_READ,
|
|
49
|
+
OPCODE_READDIR,
|
|
50
|
+
OPCODE_READLINK,
|
|
51
|
+
OPCODE_RENAME,
|
|
52
|
+
OPCODE_RMDIR,
|
|
53
|
+
OPCODE_SIZE,
|
|
54
|
+
OPCODE_STAT,
|
|
55
|
+
OPCODE_SYMLINK,
|
|
56
|
+
OPCODE_TRUNCATE,
|
|
57
|
+
OPCODE_UNLINK,
|
|
58
|
+
OPCODE_WRITE,
|
|
59
|
+
PayloadDecodeError,
|
|
60
|
+
PayloadOverflowError,
|
|
61
|
+
PayloadReader,
|
|
62
|
+
PayloadWriter,
|
|
63
|
+
READDIR_DONE,
|
|
64
|
+
STATE_DETACHED,
|
|
65
|
+
STATE_REQUEST,
|
|
66
|
+
STATE_RESPONSE,
|
|
67
|
+
isKnownOpcode,
|
|
68
|
+
planOpen,
|
|
69
|
+
splitResult,
|
|
70
|
+
writeStat,
|
|
71
|
+
} from "./protocol";
|
|
72
|
+
import type { RepackedChannel, RepackedDoorbell } from "./protocol";
|
|
73
|
+
|
|
74
|
+
/** A descriptor the broker opened on behalf of one client. */
|
|
75
|
+
interface BrokerFd {
|
|
76
|
+
/** The core's descriptor number. */
|
|
77
|
+
readonly fd: number;
|
|
78
|
+
/** The access the CLIENT asked for, which may be narrower than what the core descriptor grants. */
|
|
79
|
+
readonly readable: boolean;
|
|
80
|
+
readonly writable: boolean;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface AttachedClient {
|
|
84
|
+
readonly channel: RepackedChannel;
|
|
85
|
+
readonly fds: Map<number, BrokerFd>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** What a handler produced: an errno-only rejection, or a result plus optional response bytes. */
|
|
89
|
+
interface Answer {
|
|
90
|
+
readonly errno: number;
|
|
91
|
+
readonly result: bigint;
|
|
92
|
+
readonly responseBytes: number;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const OK: Answer = { errno: 0, result: 0n, responseBytes: 0 };
|
|
96
|
+
|
|
97
|
+
function ok(result: bigint | number = 0n, responseBytes = 0): Answer {
|
|
98
|
+
return { errno: 0, result: typeof result === "bigint" ? result : BigInt(result), responseBytes };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** A client's request could not be understood; the client is detached, the loop survives. */
|
|
102
|
+
class ProtocolViolation extends Error {
|
|
103
|
+
constructor(message: string) {
|
|
104
|
+
super(message);
|
|
105
|
+
this.name = "ProtocolViolation";
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface RepackedSyncBrokerOptions {
|
|
110
|
+
/**
|
|
111
|
+
* The store this broker owns. Nothing else may hold it. A `RepackedVfs` is the one-store form; a
|
|
112
|
+
* `MountedRepackedVfs` serves several stores as one tree, and the broker cannot tell them apart.
|
|
113
|
+
*/
|
|
114
|
+
readonly vfs: RepackedFileSystem;
|
|
115
|
+
/** The shared doorbell every attached channel rings. */
|
|
116
|
+
readonly doorbell: RepackedDoorbell;
|
|
117
|
+
/** The timestamp the broker supplies to every core call. Defaults to the wall clock. */
|
|
118
|
+
readonly now?: () => bigint;
|
|
119
|
+
/** Where a detach reason goes. Defaults to `console.warn`. */
|
|
120
|
+
readonly log?: (message: string) => void;
|
|
121
|
+
/**
|
|
122
|
+
* How long one blocking iteration parks before re-scanning anyway. Defaults to 250 ms. The protocol
|
|
123
|
+
* has no missed-wakeup window — the server observes the doorbell ticket BEFORE it scans, so a
|
|
124
|
+
* request published during the scan makes the wait return `not-equal` at once — so this is purely a
|
|
125
|
+
* heartbeat: it costs four idle wakeups a second and turns any future slip into a latency blip
|
|
126
|
+
* instead of a permanently parked backend. `Infinity` makes the loop a pure park.
|
|
127
|
+
*/
|
|
128
|
+
readonly pollIntervalMs?: number;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export class RepackedSyncBroker {
|
|
132
|
+
readonly doorbell: RepackedDoorbell;
|
|
133
|
+
readonly #vfs: RepackedFileSystem;
|
|
134
|
+
readonly #now: () => bigint;
|
|
135
|
+
readonly #log: (message: string) => void;
|
|
136
|
+
readonly #pollIntervalMs: number;
|
|
137
|
+
readonly #clients = new Map<number, AttachedClient>();
|
|
138
|
+
#serving = false;
|
|
139
|
+
|
|
140
|
+
constructor(options: RepackedSyncBrokerOptions) {
|
|
141
|
+
this.#vfs = options.vfs;
|
|
142
|
+
this.doorbell = options.doorbell;
|
|
143
|
+
this.#now = options.now ?? (() => BigInt(Date.now()));
|
|
144
|
+
this.#log = options.log ?? ((message) => console.warn(message));
|
|
145
|
+
this.#pollIntervalMs = options.pollIntervalMs ?? 250;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Channel ids the broker currently serves. */
|
|
149
|
+
attachedIds(): number[] {
|
|
150
|
+
return [...this.#clients.keys()].sort((left, right) => left - right);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Descriptors the broker currently holds for one client — the leak check after a detach. */
|
|
154
|
+
openFdCount(channelId?: number): number {
|
|
155
|
+
if (channelId === undefined) {
|
|
156
|
+
let total = 0;
|
|
157
|
+
for (const client of this.#clients.values()) total += client.fds.size;
|
|
158
|
+
return total;
|
|
159
|
+
}
|
|
160
|
+
return this.#clients.get(channelId)?.fds.size ?? 0;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
attach(channel: RepackedChannel): void {
|
|
164
|
+
if (this.#clients.has(channel.id)) throw new Error(`broker channel ${channel.id} is already attached`);
|
|
165
|
+
if (channel.doorbell.buffer !== this.doorbell.buffer) {
|
|
166
|
+
throw new Error(`broker channel ${channel.id} rings a different doorbell`);
|
|
167
|
+
}
|
|
168
|
+
this.#clients.set(channel.id, { channel, fds: new Map() });
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Drop a client and close every descriptor it still holds. A backend that dies mid-query never leaks
|
|
173
|
+
* a descriptor into the store, and the store's exclusive handles are released the moment the LAST
|
|
174
|
+
* owner goes away rather than whenever a stale fd happens to be noticed.
|
|
175
|
+
*/
|
|
176
|
+
detach(channel: RepackedChannel | number, reason = "detached by the host"): void {
|
|
177
|
+
this.#detach(typeof channel === "number" ? channel : channel.id, reason, FAULT_DETACHED);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
#detach(id: number, reason: string, fault: number): void {
|
|
181
|
+
const client = this.#clients.get(id);
|
|
182
|
+
if (client === undefined) return;
|
|
183
|
+
this.#clients.delete(id);
|
|
184
|
+
this.#releaseFds(client);
|
|
185
|
+
const header = client.channel.header;
|
|
186
|
+
Atomics.store(header, HEADER_FAULT, fault);
|
|
187
|
+
Atomics.store(header, HEADER_ERRNO, 0);
|
|
188
|
+
Atomics.store(header, HEADER_RESPONSE, 0);
|
|
189
|
+
Atomics.store(header, HEADER_STATE, STATE_DETACHED);
|
|
190
|
+
Atomics.notify(header, HEADER_STATE);
|
|
191
|
+
this.#log(`repacked broker detached channel ${id}: ${reason}`);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** Detach every client, closing all descriptors. The store itself is NOT closed. */
|
|
195
|
+
detachAll(reason = "broker shutting down"): void {
|
|
196
|
+
for (const id of this.attachedIds()) this.detach(id, reason);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Scan every attached channel once and answer whatever is pending. Never blocks, never throws for a
|
|
201
|
+
* file or store error. Returns how many requests were answered.
|
|
202
|
+
*/
|
|
203
|
+
serveOnce(): number {
|
|
204
|
+
let served = 0;
|
|
205
|
+
for (const client of [...this.#clients.values()]) {
|
|
206
|
+
if (Atomics.load(client.channel.header, HEADER_STATE) !== STATE_REQUEST) continue;
|
|
207
|
+
this.#answer(client);
|
|
208
|
+
served += 1;
|
|
209
|
+
}
|
|
210
|
+
return served;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* The blocking coordinator loop. Parks the thread in `Atomics.wait` on the doorbell between
|
|
215
|
+
* requests, so this thread's event loop never runs: attach every channel before calling it, and stop
|
|
216
|
+
* it with `doorbell.requestStop()` from another thread.
|
|
217
|
+
*/
|
|
218
|
+
serveForever(): void {
|
|
219
|
+
this.#enterLoop();
|
|
220
|
+
try {
|
|
221
|
+
while (this.doorbell.running()) {
|
|
222
|
+
const observed = this.doorbell.ticket();
|
|
223
|
+
if (this.serveOnce() > 0) continue;
|
|
224
|
+
this.doorbell.wait(observed, this.#pollIntervalMs);
|
|
225
|
+
}
|
|
226
|
+
} finally {
|
|
227
|
+
this.#serving = false;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* The same loop on `Atomics.waitAsync`, for a host that must not park its thread — the tab's main
|
|
233
|
+
* thread, or a worker that also has to receive `postMessage`. Channels may be attached and detached
|
|
234
|
+
* while it runs. Resolves when `doorbell.requestStop()` is called.
|
|
235
|
+
*/
|
|
236
|
+
async serve(): Promise<void> {
|
|
237
|
+
this.#enterLoop();
|
|
238
|
+
try {
|
|
239
|
+
while (this.doorbell.running()) {
|
|
240
|
+
const observed = this.doorbell.ticket();
|
|
241
|
+
if (this.serveOnce() > 0) continue;
|
|
242
|
+
await this.doorbell.waitAsync(observed, this.#pollIntervalMs);
|
|
243
|
+
}
|
|
244
|
+
} finally {
|
|
245
|
+
this.#serving = false;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
#enterLoop(): void {
|
|
250
|
+
if (this.#serving) throw new Error("the repacked broker is already serving");
|
|
251
|
+
this.#serving = true;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
#releaseFds(client: AttachedClient): void {
|
|
255
|
+
for (const entry of client.fds.values()) {
|
|
256
|
+
try {
|
|
257
|
+
this.#vfs.close(entry.fd);
|
|
258
|
+
} catch {
|
|
259
|
+
// A descriptor the store already dropped (or a poisoned store) must not stop the release of
|
|
260
|
+
// the rest — the client is going away either way.
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
client.fds.clear();
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** Read one pending request, run it, and publish the reply. Never throws. */
|
|
267
|
+
#answer(client: AttachedClient): void {
|
|
268
|
+
const header = client.channel.header;
|
|
269
|
+
const opcode = Atomics.load(header, HEADER_OPCODE);
|
|
270
|
+
const requestBytes = Atomics.load(header, HEADER_REQUEST);
|
|
271
|
+
let fault = FAULT_NONE;
|
|
272
|
+
let answer = OK;
|
|
273
|
+
try {
|
|
274
|
+
if (!isKnownOpcode(opcode)) throw new ProtocolViolation(`unknown opcode ${opcode}`);
|
|
275
|
+
if (requestBytes < 0 || requestBytes > client.channel.payloadBytes) {
|
|
276
|
+
throw new ProtocolViolation(`request length ${requestBytes} is outside the payload region`);
|
|
277
|
+
}
|
|
278
|
+
const reader = new PayloadReader(client.channel.payload, requestBytes);
|
|
279
|
+
const writer = new PayloadWriter(client.channel.payload);
|
|
280
|
+
answer = this.#dispatch(client, opcode, reader, writer);
|
|
281
|
+
} catch (cause) {
|
|
282
|
+
if (cause instanceof ProtocolViolation || cause instanceof PayloadDecodeError) {
|
|
283
|
+
// Only the offending client goes; every other backend keeps its descriptors and its store.
|
|
284
|
+
this.#detach(client.channel.id, cause.message, FAULT_PROTOCOL);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
if (cause instanceof FsError) {
|
|
288
|
+
answer = { errno: cause.code, result: 0n, responseBytes: 0 };
|
|
289
|
+
} else {
|
|
290
|
+
// Everything else — a poisoned store, a limit, a corrupt store, or a reply that did not fit
|
|
291
|
+
// the client's own channel — is not a file rejection and not this client's fault. Report it
|
|
292
|
+
// as a fault and keep the loop alive; a poisoned store answers every later request the same
|
|
293
|
+
// way, and the client decides whether to give up.
|
|
294
|
+
fault = FAULT_STORE;
|
|
295
|
+
answer = this.#faultAnswer(client, cause);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
const { lo, hi } = splitResult(answer.result);
|
|
299
|
+
Atomics.store(header, HEADER_ERRNO, answer.errno);
|
|
300
|
+
Atomics.store(header, HEADER_RESULT_LO, lo);
|
|
301
|
+
Atomics.store(header, HEADER_RESULT_HI, hi);
|
|
302
|
+
Atomics.store(header, HEADER_RESPONSE, answer.responseBytes);
|
|
303
|
+
Atomics.store(header, HEADER_FAULT, fault);
|
|
304
|
+
Atomics.store(header, HEADER_STATE, STATE_RESPONSE);
|
|
305
|
+
Atomics.notify(header, HEADER_STATE);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** Put a fault message in the payload, truncating rather than overflowing a small channel. */
|
|
309
|
+
#faultAnswer(client: AttachedClient, cause: unknown): Answer {
|
|
310
|
+
const message = cause instanceof Error ? `${cause.name}: ${cause.message}` : String(cause);
|
|
311
|
+
const writer = new PayloadWriter(client.channel.payload);
|
|
312
|
+
const room = client.channel.payloadBytes - 4;
|
|
313
|
+
try {
|
|
314
|
+
writer.string(message.length > room ? message.slice(0, Math.max(0, room)) : message);
|
|
315
|
+
} catch {
|
|
316
|
+
return { errno: 0, result: 0n, responseBytes: 0 };
|
|
317
|
+
}
|
|
318
|
+
return { errno: 0, result: 0n, responseBytes: writer.length };
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
#dispatch(client: AttachedClient, opcode: number, reader: PayloadReader, writer: PayloadWriter): Answer {
|
|
322
|
+
switch (opcode) {
|
|
323
|
+
case OPCODE_OPEN:
|
|
324
|
+
return this.#open(client, reader);
|
|
325
|
+
case OPCODE_CLOSE:
|
|
326
|
+
return this.#close(client, reader);
|
|
327
|
+
case OPCODE_READ:
|
|
328
|
+
return this.#read(client, reader);
|
|
329
|
+
case OPCODE_WRITE:
|
|
330
|
+
return this.#write(client, reader);
|
|
331
|
+
case OPCODE_FSYNC:
|
|
332
|
+
return this.#fsync(client, reader);
|
|
333
|
+
case OPCODE_FSTAT:
|
|
334
|
+
return this.#stat(writer, this.#vfs.fstat(this.#fd(client, reader.u32()).fd));
|
|
335
|
+
case OPCODE_STAT:
|
|
336
|
+
return this.#stat(writer, this.#vfs.stat(reader.string()));
|
|
337
|
+
case OPCODE_LSTAT:
|
|
338
|
+
return this.#stat(writer, this.#vfs.lstat(reader.string()));
|
|
339
|
+
case OPCODE_READDIR:
|
|
340
|
+
return this.#readdir(reader, writer);
|
|
341
|
+
case OPCODE_MKDIR:
|
|
342
|
+
return this.#mkdir(reader);
|
|
343
|
+
case OPCODE_RMDIR:
|
|
344
|
+
this.#vfs.rmdir(reader.string(), this.#now());
|
|
345
|
+
return OK;
|
|
346
|
+
case OPCODE_UNLINK:
|
|
347
|
+
this.#vfs.unlink(reader.string(), this.#now());
|
|
348
|
+
return OK;
|
|
349
|
+
case OPCODE_RENAME: {
|
|
350
|
+
const oldPath = reader.string();
|
|
351
|
+
this.#vfs.rename(oldPath, reader.string(), this.#now());
|
|
352
|
+
return OK;
|
|
353
|
+
}
|
|
354
|
+
case OPCODE_TRUNCATE: {
|
|
355
|
+
const path = reader.string();
|
|
356
|
+
this.#vfs.truncate(path, reader.u64(), this.#now());
|
|
357
|
+
return OK;
|
|
358
|
+
}
|
|
359
|
+
case OPCODE_SIZE:
|
|
360
|
+
return this.#size(reader);
|
|
361
|
+
case OPCODE_SYMLINK: {
|
|
362
|
+
const target = reader.string();
|
|
363
|
+
this.#vfs.symlink(target, reader.string(), this.#now());
|
|
364
|
+
return OK;
|
|
365
|
+
}
|
|
366
|
+
case OPCODE_READLINK:
|
|
367
|
+
return this.#readlink(reader, writer);
|
|
368
|
+
default:
|
|
369
|
+
throw new ProtocolViolation(`unhandled opcode ${opcode}`);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
#open(client: AttachedClient, reader: PayloadReader): Answer {
|
|
374
|
+
const path = reader.string();
|
|
375
|
+
const flags = reader.u32();
|
|
376
|
+
const mode = reader.u32();
|
|
377
|
+
const plan = planOpen(flags);
|
|
378
|
+
const nowMs = this.#now();
|
|
379
|
+
// `O_NOFOLLOW`: the core always follows a final link, so the refusal is proved here first. A
|
|
380
|
+
// path that does not exist is not a link, and `O_CREAT` must still be free to create it.
|
|
381
|
+
if (!plan.follow) {
|
|
382
|
+
try {
|
|
383
|
+
if (this.#vfs.lstat(path).kind === "symlink") {
|
|
384
|
+
throw new FsError("ELOOP", "path is a symbolic link and O_NOFOLLOW was requested", { path });
|
|
385
|
+
}
|
|
386
|
+
} catch (cause) {
|
|
387
|
+
if (!(cause instanceof FsError) || cause.code !== FS_ERRNO.ENOENT) throw cause;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
if (plan.requireExisting) this.#vfs.lstat(path);
|
|
391
|
+
if (plan.truncateFirst) this.#vfs.truncate(path, 0n, nowMs);
|
|
392
|
+
let fd: number;
|
|
393
|
+
try {
|
|
394
|
+
fd = this.#vfs.open(path, plan.coreFlags, mode, nowMs);
|
|
395
|
+
} catch (cause) {
|
|
396
|
+
if (plan.fallbackFlags === undefined || !(cause instanceof FsError) || cause.code !== FS_ERRNO.ENOENT) {
|
|
397
|
+
throw cause;
|
|
398
|
+
}
|
|
399
|
+
fd = this.#vfs.open(path, plan.fallbackFlags, mode, nowMs);
|
|
400
|
+
}
|
|
401
|
+
client.fds.set(fd, { fd, readable: plan.readable, writable: plan.writable });
|
|
402
|
+
return ok(fd);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
#close(client: AttachedClient, reader: PayloadReader): Answer {
|
|
406
|
+
const entry = this.#fd(client, reader.u32());
|
|
407
|
+
this.#vfs.close(entry.fd);
|
|
408
|
+
client.fds.delete(entry.fd);
|
|
409
|
+
return OK;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
#read(client: AttachedClient, reader: PayloadReader): Answer {
|
|
413
|
+
const entry = this.#fd(client, reader.u32());
|
|
414
|
+
if (!entry.readable) throw new FsError("EBADF", "descriptor was not opened for reading");
|
|
415
|
+
const hasPosition = reader.u8() === 1;
|
|
416
|
+
const position = reader.u64();
|
|
417
|
+
const length = reader.u32();
|
|
418
|
+
if (length > client.channel.payloadBytes) {
|
|
419
|
+
throw new ProtocolViolation(`read length ${length} exceeds the payload region`);
|
|
420
|
+
}
|
|
421
|
+
const target = client.channel.payload.subarray(0, length);
|
|
422
|
+
const count = hasPosition
|
|
423
|
+
? this.#vfs.read(entry.fd, target, 0, length, position)
|
|
424
|
+
: this.#vfs.read(entry.fd, target, 0, length);
|
|
425
|
+
return ok(count, count);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
#write(client: AttachedClient, reader: PayloadReader): Answer {
|
|
429
|
+
const entry = this.#fd(client, reader.u32());
|
|
430
|
+
if (!entry.writable) throw new FsError("EBADF", "descriptor was not opened for writing");
|
|
431
|
+
const hasPosition = reader.u8() === 1;
|
|
432
|
+
const position = reader.u64();
|
|
433
|
+
const length = reader.u32();
|
|
434
|
+
const source = reader.bytes(length);
|
|
435
|
+
const count = this.#vfs.write(entry.fd, source, 0, length, hasPosition ? position : undefined, this.#now());
|
|
436
|
+
return ok(count);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* `fsync` is store-wide. The core's only durability primitive is `strictSync()`, which flushes the
|
|
441
|
+
* arena and then the active metadata log, so a successful `fsync` promises that EVERY byte written
|
|
442
|
+
* through this broker by ANY client before the call returned is recoverable — not just this
|
|
443
|
+
* descriptor's. WASI `fd_sync` and `fd_datasync` both map to it; the fd is carried only so the call
|
|
444
|
+
* still fails with `EBADF` on a descriptor the client does not own, exactly as `fd_sync` must.
|
|
445
|
+
*/
|
|
446
|
+
#fsync(client: AttachedClient, reader: PayloadReader): Answer {
|
|
447
|
+
if (reader.u8() === 1) this.#fd(client, reader.u32());
|
|
448
|
+
this.#vfs.strictSync();
|
|
449
|
+
return OK;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
#stat(writer: PayloadWriter, stat: RepackedStat): Answer {
|
|
453
|
+
writeStat(writer, stat);
|
|
454
|
+
return ok(stat.size, writer.length);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* One page of a directory listing. The cursor is an index into the store's own sorted listing, which
|
|
459
|
+
* the store recomputes on every call — so, exactly as POSIX `readdir` allows, a listing spread over
|
|
460
|
+
* several pages is not an atomic snapshot of the directory.
|
|
461
|
+
*/
|
|
462
|
+
#readdir(reader: PayloadReader, writer: PayloadWriter): Answer {
|
|
463
|
+
const path = reader.string();
|
|
464
|
+
const cursor = reader.u32();
|
|
465
|
+
const names = this.#vfs.readdir(path);
|
|
466
|
+
if (cursor > names.length) throw new ProtocolViolation(`readdir cursor ${cursor} is past the listing`);
|
|
467
|
+
// Reserve the two counters written after the entries are known to fit.
|
|
468
|
+
const countAt = writer.length;
|
|
469
|
+
writer.u32(0);
|
|
470
|
+
writer.i32(READDIR_DONE);
|
|
471
|
+
let emitted = 0;
|
|
472
|
+
let next = READDIR_DONE;
|
|
473
|
+
for (let index = cursor; index < names.length; index += 1) {
|
|
474
|
+
const before = writer.length;
|
|
475
|
+
try {
|
|
476
|
+
writer.string(names[index]!);
|
|
477
|
+
} catch (cause) {
|
|
478
|
+
if (!(cause instanceof PayloadOverflowError)) throw cause;
|
|
479
|
+
writer.rewind(before);
|
|
480
|
+
if (emitted === 0) throw cause; // one name alone cannot fit: the channel is too small
|
|
481
|
+
next = index;
|
|
482
|
+
break;
|
|
483
|
+
}
|
|
484
|
+
emitted += 1;
|
|
485
|
+
}
|
|
486
|
+
const counters = writer.patch(countAt, 8);
|
|
487
|
+
counters.setUint32(0, emitted, true);
|
|
488
|
+
counters.setInt32(4, next, true);
|
|
489
|
+
return ok(emitted, writer.length);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
#mkdir(reader: PayloadReader): Answer {
|
|
493
|
+
const path = reader.string();
|
|
494
|
+
const recursive = reader.u8() === 1;
|
|
495
|
+
const mode = reader.u32();
|
|
496
|
+
this.#vfs.mkdir(path, { recursive, mode, nowMs: this.#now() });
|
|
497
|
+
return OK;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/** The target of one symbolic link. The result is the target's byte length; the payload is it. */
|
|
501
|
+
#readlink(reader: PayloadReader, writer: PayloadWriter): Answer {
|
|
502
|
+
writer.string(this.#vfs.readlink(reader.string()));
|
|
503
|
+
return ok(writer.length, writer.length);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
#size(reader: PayloadReader): Answer {
|
|
507
|
+
const stat = this.#vfs.stat(reader.string());
|
|
508
|
+
if (stat.kind !== "file") throw new FsError("EISDIR", "size is a file query");
|
|
509
|
+
return ok(stat.size);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Resolve a descriptor the CLIENT owns. A descriptor that belongs to another client is `EBADF`, not
|
|
514
|
+
* a protocol violation: fd numbers are per-store, so a client guessing one is an ordinary bad-fd
|
|
515
|
+
* mistake and never a reason to reach into another backend's files.
|
|
516
|
+
*/
|
|
517
|
+
#fd(client: AttachedClient, fd: number): BrokerFd {
|
|
518
|
+
const entry = client.fds.get(fd);
|
|
519
|
+
if (entry === undefined) throw new FsError("EBADF", `descriptor ${fd} is not owned by this client`);
|
|
520
|
+
return entry;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const CRC32_TABLE = new Uint32Array(256);
|
|
2
|
+
|
|
3
|
+
for (let value = 0; value < CRC32_TABLE.length; value += 1) {
|
|
4
|
+
let remainder = value;
|
|
5
|
+
for (let bit = 0; bit < 8; bit += 1) {
|
|
6
|
+
remainder = (remainder & 1) === 1 ? 0xedb88320 ^ (remainder >>> 1) : remainder >>> 1;
|
|
7
|
+
}
|
|
8
|
+
CRC32_TABLE[value] = remainder >>> 0;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const CRC32_SLICES: Uint32Array[] = [CRC32_TABLE];
|
|
12
|
+
for (let slice = 1; slice < 8; slice += 1) {
|
|
13
|
+
const previous = CRC32_SLICES[slice - 1]!;
|
|
14
|
+
const current = new Uint32Array(256);
|
|
15
|
+
for (let value = 0; value < current.length; value += 1) {
|
|
16
|
+
const remainder = previous[value]!;
|
|
17
|
+
current[value] = (CRC32_TABLE[remainder & 0xff]! ^ (remainder >>> 8)) >>> 0;
|
|
18
|
+
}
|
|
19
|
+
CRC32_SLICES.push(current);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const CRC32_SLICE_1 = CRC32_SLICES[1]!;
|
|
23
|
+
const CRC32_SLICE_2 = CRC32_SLICES[2]!;
|
|
24
|
+
const CRC32_SLICE_3 = CRC32_SLICES[3]!;
|
|
25
|
+
const CRC32_SLICE_4 = CRC32_SLICES[4]!;
|
|
26
|
+
const CRC32_SLICE_5 = CRC32_SLICES[5]!;
|
|
27
|
+
const CRC32_SLICE_6 = CRC32_SLICES[6]!;
|
|
28
|
+
const CRC32_SLICE_7 = CRC32_SLICES[7]!;
|
|
29
|
+
|
|
30
|
+
function updateCrc32(remainder: number, bytes: Uint8Array, start: number, end: number): number {
|
|
31
|
+
let index = start;
|
|
32
|
+
while (index + 8 <= end) {
|
|
33
|
+
const word =
|
|
34
|
+
remainder ^ (bytes[index]! | (bytes[index + 1]! << 8) | (bytes[index + 2]! << 16) | (bytes[index + 3]! << 24));
|
|
35
|
+
remainder =
|
|
36
|
+
CRC32_SLICE_7[word & 0xff]! ^
|
|
37
|
+
CRC32_SLICE_6[(word >>> 8) & 0xff]! ^
|
|
38
|
+
CRC32_SLICE_5[(word >>> 16) & 0xff]! ^
|
|
39
|
+
CRC32_SLICE_4[word >>> 24]! ^
|
|
40
|
+
CRC32_SLICE_3[bytes[index + 4]!]! ^
|
|
41
|
+
CRC32_SLICE_2[bytes[index + 5]!]! ^
|
|
42
|
+
CRC32_SLICE_1[bytes[index + 6]!]! ^
|
|
43
|
+
CRC32_TABLE[bytes[index + 7]!]!;
|
|
44
|
+
index += 8;
|
|
45
|
+
}
|
|
46
|
+
for (; index < end; index += 1) {
|
|
47
|
+
remainder = CRC32_TABLE[(remainder ^ bytes[index]!) & 0xff]! ^ (remainder >>> 8);
|
|
48
|
+
}
|
|
49
|
+
return remainder;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function updateCrc32WithZeros(remainder: number, length: number): number {
|
|
53
|
+
while (length >= 8) {
|
|
54
|
+
remainder =
|
|
55
|
+
CRC32_SLICE_7[remainder & 0xff]! ^
|
|
56
|
+
CRC32_SLICE_6[(remainder >>> 8) & 0xff]! ^
|
|
57
|
+
CRC32_SLICE_5[(remainder >>> 16) & 0xff]! ^
|
|
58
|
+
CRC32_SLICE_4[remainder >>> 24]!;
|
|
59
|
+
length -= 8;
|
|
60
|
+
}
|
|
61
|
+
while (length > 0) {
|
|
62
|
+
remainder = CRC32_TABLE[remainder & 0xff]! ^ (remainder >>> 8);
|
|
63
|
+
length -= 1;
|
|
64
|
+
}
|
|
65
|
+
return remainder;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function crc32(bytes: Uint8Array): number {
|
|
69
|
+
const remainder = updateCrc32(0xffff_ffff, bytes, 0, bytes.byteLength);
|
|
70
|
+
return (remainder ^ 0xffff_ffff) >>> 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function crc32WithZeroedRange(bytes: Uint8Array, offset: number, length: number): number {
|
|
74
|
+
if (!Number.isSafeInteger(offset) || !Number.isSafeInteger(length) || offset < 0 || length < 0) {
|
|
75
|
+
throw new TypeError("checksum range must use non-negative safe integers");
|
|
76
|
+
}
|
|
77
|
+
if (offset + length > bytes.byteLength) {
|
|
78
|
+
throw new RangeError("checksum range exceeds the input");
|
|
79
|
+
}
|
|
80
|
+
const zeroEnd = offset + length;
|
|
81
|
+
let remainder = updateCrc32(0xffff_ffff, bytes, 0, offset);
|
|
82
|
+
remainder = updateCrc32WithZeros(remainder, length);
|
|
83
|
+
remainder = updateCrc32(remainder, bytes, zeroEnd, bytes.byteLength);
|
|
84
|
+
return (remainder ^ 0xffff_ffff) >>> 0;
|
|
85
|
+
}
|