wasm_storage_host (wasm_storage v0.1.0)
View SourceThe wasm_storage imports: storage devices as seen by a guest.
A guest names a device by a small integer. This module keeps the table from
those integers to wasm_storage handles, and gives the imports that read and
write guest memory on one side and call the device on the other.
Host functions run in the process that calls into the guest, so the table
lives in that process's dictionary. It belongs to the guest owner
(wasm_storage_guest): register devices from that process, before or during
the calls that use them. Only the lock import messages another process,
the device's lock table (wasm_storage_lock), which never calls a guest; no
import calls the guest's owner, so a guest call cannot deadlock on it. A
lock that is not granted at once waits, within the deadline of the call.
Errors reach the guest as the negative codes of
include/wasm_storage_abi.hrl. The full reason of the last failure is kept
for the owner: see last_error/0.
Summary
Functions
Make handle H reachable by the guest as device Id.
The ABI code for a provider error reason.
The handle of device Id.
Every registered device, by id.
The import map: wasm_storage size, pread, pwrite, resize, sync,
close, lock, and wsg panic, random, now. Merge it with any other
imports the guest needs.
The last failure an import reported to the guest: the operation, the device and the reason the provider returned. Cleared by reading it.
The imports of a guest that opens files by name: wasm_storage open,
delete and exists, inside the root given to set_namespace/1. Devices it
opens get ids from 1 up, skipping ids already in use.
Forget device Id. The handle is not closed.
Give device Id the lock table Server (wasm_storage_lock). Its lock
calls then go there, owned by this process and the device.
The namespace root the namespace imports work in, for this process.
The message the guest reported before trapping, if any.
Functions
-spec add_device(non_neg_integer(), wasm_storage:handle()) -> ok.
Make handle H reachable by the guest as device Id.
-spec code(term()) -> neg_integer().
The ABI code for a provider error reason.
-spec device(integer()) -> {ok, wasm_storage:handle()} | error.
The handle of device Id.
-spec devices() -> [{non_neg_integer(), wasm_storage:handle()}].
Every registered device, by id.
-spec imports() -> map().
The import map: wasm_storage size, pread, pwrite, resize, sync,
close, lock, and wsg panic, random, now. Merge it with any other
imports the guest needs.
lock answers ENOTSUP for a device that has no lock table
(set_locks/2), so a guest that tries to lock runs as if alone.
The last failure an import reported to the guest: the operation, the device and the reason the provider returned. Cleared by reading it.
-spec namespace_imports() -> map().
The imports of a guest that opens files by name: wasm_storage open,
delete and exists, inside the root given to set_namespace/1. Devices it
opens get ids from 1 up, skipping ids already in use.
open with an empty path opens an anonymous memory device (SQLite's
temporary files). delete returns 0 once the entry is gone and, if asked,
its directory synced; ENOTSUP when it is gone but the directory cannot be
synced (wasm_storage_dir); ENOENT when there was nothing to delete.
-spec remove_device(non_neg_integer()) -> ok.
Forget device Id. The handle is not closed.
-spec set_locks(non_neg_integer(), pid()) -> ok.
Give device Id the lock table Server (wasm_storage_lock). Its lock
calls then go there, owned by this process and the device.
-spec set_namespace(wasm_storage_ns:root()) -> ok.
The namespace root the namespace imports work in, for this process.
-spec take_panic() -> binary() | none.
The message the guest reported before trapping, if any.