virtual-machine 0.0.36 → 0.1.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/build/index.d.ts CHANGED
@@ -85,6 +85,12 @@ declare class WasmVm {
85
85
  * Called from JavaScript when the native WebTransport addon receives a packet.
86
86
  */
87
87
  inject_network_packet(packet: Uint8Array): boolean;
88
+ /**
89
+ * Signal that workers can start executing.
90
+ * Called by the main thread after hart 0 has finished initializing
91
+ * kernel data structures.
92
+ */
93
+ allow_workers_to_start(): void;
88
94
  /**
89
95
  * Extract a network packet sent by the guest.
90
96
  * Returns the packet data or null if no packet is pending.
@@ -155,6 +161,11 @@ declare class WasmVm {
155
161
  * JS-WASM boundary crossings.
156
162
  */
157
163
  step_n(count: number): number;
164
+ /**
165
+ * Get the entry PC address for workers.
166
+ * This is the address where secondary harts should start executing.
167
+ */
168
+ entry_pc(): bigint;
158
169
  /**
159
170
  * Get the halt code if the VM has halted.
160
171
  * Code 0x5555 typically means successful shutdown (PASS).
@@ -185,6 +196,11 @@ declare class WorkerState {
185
196
  * the event loop to yield between batches. This prevents the worker
186
197
  * from blocking indefinitely and allows it to respond to messages.
187
198
  *
199
+ * Performance optimization: We reduce atomic operations by:
200
+ * - Only checking halt signals every HALT_CHECK_INTERVAL instructions
201
+ * - Only checking interrupts every INTERRUPT_CHECK_INTERVAL instructions
202
+ * - Doing a full interrupt check at the end of each batch
203
+ *
188
204
  * Returns a WorkerStepResult indicating whether to continue, halt, etc.
189
205
  */
190
206
  step_batch(batch_size: number): WorkerStepResult;
@@ -247,8 +263,10 @@ interface InitOutput {
247
263
  readonly memory: WebAssembly.Memory;
248
264
  readonly __wbg_wasmvm_free: (a: number, b: number) => void;
249
265
  readonly __wbg_workerstate_free: (a: number, b: number) => void;
266
+ readonly wasmvm_allow_workers_to_start: (a: number) => void;
250
267
  readonly wasmvm_connect_webtransport: (a: number, b: number, c: number, d: number, e: number) => [number, number];
251
268
  readonly wasmvm_disconnect_network: (a: number) => void;
269
+ readonly wasmvm_entry_pc: (a: number) => bigint;
252
270
  readonly wasmvm_external_network_rx_pending: (a: number) => number;
253
271
  readonly wasmvm_external_network_tx_pending: (a: number) => number;
254
272
  readonly wasmvm_extract_all_network_packets: (a: number) => any;
@@ -282,12 +300,12 @@ interface InitOutput {
282
300
  readonly workerstate_new: (a: number, b: any, c: bigint) => number;
283
301
  readonly workerstate_step_batch: (a: number, b: number) => number;
284
302
  readonly workerstate_step_count: (a: number) => bigint;
303
+ readonly wasm_bindgen__convert__closures_____invoke__h8a077b496ee6a629: (a: number, b: number) => void;
304
+ readonly wasm_bindgen__closure__destroy__h54a2706e25dd10b8: (a: number, b: number) => void;
305
+ readonly wasm_bindgen__convert__closures_____invoke__h38b3d5c42439bcf4: (a: number, b: number) => void;
306
+ readonly wasm_bindgen__convert__closures_____invoke__he860240c5b649134: (a: number, b: number, c: any) => void;
285
307
  readonly wasm_bindgen__convert__closures_____invoke__h39d3e89751b07765: (a: number, b: number, c: any) => void;
286
308
  readonly wasm_bindgen__closure__destroy__hf225e18fc5ab9bc1: (a: number, b: number) => void;
287
- readonly wasm_bindgen__convert__closures_____invoke__h2d5a3433881a07dc: (a: number, b: number) => void;
288
- readonly wasm_bindgen__closure__destroy__h4a8089319832ef98: (a: number, b: number) => void;
289
- readonly wasm_bindgen__convert__closures_____invoke__hd016cca7bbf341cd: (a: number, b: number) => void;
290
- readonly wasm_bindgen__convert__closures_____invoke__h07c9b936df37d4f2: (a: number, b: number, c: any) => void;
291
309
  readonly __wbindgen_malloc: (a: number, b: number) => number;
292
310
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
293
311
  readonly __wbindgen_exn_store: (a: number) => void;
@@ -400,6 +418,10 @@ interface VmOptions {
400
418
  * If SharedArrayBuffer is available (requires COOP/COEP headers), the VM
401
419
  * will run in true parallel mode with Web Workers for secondary harts.
402
420
  *
421
+ * NOTE: In WASM, multi-hart mode is significantly slower due to
422
+ * SharedArrayBuffer/Atomics overhead (see tasks/improvements.md).
423
+ * Default is 1 hart unless explicitly specified.
424
+ *
403
425
  * @param kernelData - ELF kernel binary
404
426
  * @param options - VM configuration options
405
427
  * @returns WasmVm instance