Node helpers and utilities
The Node entry point, with its host, snapshot files and commands, plus the parsers, encoders, types and errors both platforms share.
warm64/warm-node
Node's host and the two commands. Import WARM itself from @warm-virtual/warm64.
import { WARM } from "@warm-virtual/warm64";
import { nodeWARMHost, fileSnapshots, main, imgMain } from "@warm-virtual/warm64/warm-node";nodeWARMHost()
The host for Node. See Hosts.
fileSnapshots()
A snapshot store that keeps each savevm as a file named NAME.warm64snap in a directory. Any character in the name other than a letter, digit, ., _ or - becomes _.
const host = { ...nodeWARMHost(), snapshots: fileSnapshots("./snapshots") };nodeWARMHost({ snapshotDir }) does the same.
main()
The complete warm-system-aarch64 command. It parses argv, launches the machine, connects the terminal, monitors and QMP servers as the command line says, and resolves with the exit status.
main(argv: string[], options?: NodeWARMHostOptions): Promise<number>process.exitCode = await main(process.argv.slice(2));To control a machine's console and monitor from your own code instead, launch it with WARM.launch() and use vm.serial, vm.qmp() and vm.hmp(). -serial stdio, -monitor stdio and -qmp unix:… on the command line work under WARM.launch() with nodeWARMHost() just as they do in the command.
imgMain()
The complete warm-img command.
imgMain(argv: string[], out?: (text) => void, err?: (text) => void): numberReturns the exit status; out and err default to standard output and error.
statKind()
statKind(stats) converts a Node fs.Stats into the form the block layer expects (kind, dev, ino, size). Use it in your own host if its statFile uses Node's fs.
Utilities
Exported from @warm-virtual/warm64.
parseWARMArgs()
parseWARMArgs(args: string | string[], hooks?: ParseHooks): WARMConfigParses a command line the way WARM.launch() does, without launching anything, and returns the WARMConfig a machine would be built from. Throws WARMError for a line that would be refused. hooks lets the parser look at the host's files, as a launch does; without them, the checks that need a file are left for the launch.
splitCommandLine()
splitCommandLine(line: string): string[]Splits a command line as a POSIX shell would (quotes and backslashes), dropping a leading qemu-system-* or warm-system-*.
parseSubopts()
parseSubopts(value: string, impliedKey?: string): Record<string, string>Splits QEMU's key=value,key=value form. ,, is a literal comma, and a leading bare word belongs to impliedKey (-drive disk.img means file=disk.img).
parseSize()
parseSize(value: string, unit = 1): numberConverts a size such as "1G" to bytes. A bare number is multiplied by unit.
encodePng() and encodePpm()
encodePng(width: number, height: number, pixels: Uint8Array): Uint8Array
encodePpm(width: number, height: number, pixels: Uint8Array): Uint8ArrayEncode a8r8g8b8 pixels (as a display's frame receives them) as a PNG or PPM image, the two formats screendump writes.
QCODE_TO_LINUX
Maps QEMU's key names ("ret", "a", "ctrl"…) to Linux key codes, as send-key and input-send-event use them.
DEVICE_DRIVERS
The -device drivers this machine builds, and the kind of each.
VERSION
Warm64's version, "1.0.0", as -version prints it.
WARMConfig
The parsed command line: what parseWARMArgs() returns and vm.config holds. WARM.launch() also accepts one instead of a command line. Its fields follow QEMU's options, with QEMU's defaults filled in: machine, cpu, memory (bytes), smp, kernel, initrd, append, drives, netdevs, devices, chardevs, fsdevs, serials, monitors, qmp, audiodevs, objects, plus one field for each other option. The package's type declarations, dist/index.d.ts, describe every field.
Its parts are exported too:
| Type | One of |
|---|---|
WARMDrive | -drive (and -hda, -cdrom, -pflash and the rest). |
WARMNetdev | -netdev, -nic or -net. |
WARMDevice | -device: the driver and its properties as given. |
WARMChardev, WARMChardevOpts, WARMChardevBackend | -chardev: its id, backend and options. |
WARMFsdev | -fsdev, or the one -virtfs makes. |
WARMSerial | -serial. |
WARMMonitor, WARMMonitorSpec, WARMQmp | -monitor, -mon and -qmp. |
WARMActions | -action and the options that set it (-no-reboot, -no-shutdown): shutdown (poweroff or pause), reboot (reset or shutdown) and panic (pause, shutdown, exit-failure or none), and QEMU's defaults are poweroff, reset and shutdown. |
Types
Every type the package exports, and where it's described:
| Type | From | Described in |
|---|---|---|
WARMHost, WARMCoreKind, WasmSource | @warm-virtual/warm64 | Hosts |
WARMDiskFile, DiskBacking | @warm-virtual/warm64 | openDisk |
WARMDisplay, WARMCursor, WARMAudio, WARMSnapshotStore | @warm-virtual/warm64 | display, audio, snapshots |
Connector, StackSocket, SocketHandlers | @warm-virtual/warm64 | connector |
ChardevBackendHandle, ChardevFrontend, ChardevEvent | @warm-virtual/warm64 | The host side of a character device, as WARMHost.chardev returns it (the other members) |
BrowserWARMHostOptions | @warm-virtual/warm64 | browserWARMHost() |
NodeWARMHostOptions | @warm-virtual/warm64/warm-node | nodeWARMHost() |
WARMRunState, QmpEvent, WARMShare, WARMGuestExecResult | @warm-virtual/warm64 | WARM |
WARMConfig and its parts | @warm-virtual/warm64 | above |
Package entry points
| Import | What |
|---|---|
@warm-virtual/warm64 | WARM, the browser host and everything shared. |
@warm-virtual/warm64/warm-node | Node's host and the commands. |
@warm-virtual/warm64/wasm, @warm-virtual/warm64/wasm64, @warm-virtual/warm64/wasm-threads, @warm-virtual/warm64/wasm64-threads, @warm-virtual/warm64/wasm-gpu, @warm-virtual/warm64/wasm-gpu-threads | The core modules' files, for bundlers that copy assets. |
The commands warm-system-aarch64 and warm-img are the package's bin entries.
Errors
WARMError
Thrown by WARM.launch() and parseWARMArgs() for a command line that is refused. Its message is what qemu-system-aarch64 would print, prefixed warm-system-aarch64: . When hintUnterminated is true, the message's last line is a hint that QEMU prints without a trailing newline, and the command prints it the same way.
try {
await WARM.launch("-M virt -enable-kvm -kernel vmlinuz-virt", host);
} catch (e) {
if (e instanceof WARMError) console.error(e.message);
// warm-system-aarch64: invalid accelerator kvm
}QmpError
vm.qmp() and vm.hmp() reject with it when QEMU would answer with an error.
| Property | Description |
|---|---|
class | QEMU's error class: GenericError, CommandNotFound, DeviceNotFound… |
desc | The message. |