Documentation
¶
Overview ¶
Package capcompute is the processor: it runs Extism wasm programs as processes whose only access to the outside world is host-dispatched syscalls.
The design docs call the processor's role "kernel", in the library operating system model (docs/ARCHITECTURE.md). In code the component is the processor.
Three calls:
- NewProgram compiles a program image. It refuses any ambient authority: no allowed hosts or paths. The processor pins the clock, the RNG and the environment, and the caller cannot supply them.
- NewProcess makes a process from a program, with posix_spawn semantics: explicit input, an explicit credential and an explicit syscall dispatcher. Nothing is inherited.
- Resume gives a process the CPU for one cooperative quantum, until it completes, yields, fails, or is stopped.
The guest reports how a quantum ended in its output: {"status":"completed"} gives ResumeCompleted and {"status":"yielded"} gives ResumeYielded. Any other output, and any guest or runtime error, gives ResumeFailed. A quantum whose ctx ends gives ResumeStopped and terminates the process.
The wrapping system owns process lookup, replay scheduling, async completion, journal policy and cleanup. This package owns none of them.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrAmbientAuthority = errors.New("image grants ambient authority") ErrImageMemoryOverride = errors.New("image overrides the program-owned memory cap") ErrInvalidGuestOutput = errors.New("invalid guest output") ErrProcessActive = errors.New("process is already active") ErrProcessTerminated = errors.New("process is terminated") )
Functions ¶
func Resume ¶
Resume gives a process the CPU in its own goroutine and returns the channel its outcome arrives on. The process runs until it completes, yields, fails, or is stopped — cooperative scheduling, no preemption. ctx is the only way to stop it: a guest still running when ctx ends is stopped, and a stopped process is terminated.
Types ¶
type Config ¶
type Config struct {
Image extism.Manifest
PluginConfig extism.PluginConfig
// MaxMemoryPages caps each process's linear memory in 64KiB wasm pages
// (0 = runtime default). A guest allocating past the cap traps and the
// resume reports ResumeFailed.
MaxMemoryPages uint32
}
Config contains everything needed to compile a program image.
Image is the program image (an Extism manifest naming the wasm and static config). It must not grant ambient authority: AllowedHosts and AllowedPaths must be empty — network and filesystem access are capabilities served by the dispatcher, never ambient rights. Guest module configuration (clock, RNG, env) is owned by the processor and cannot be supplied by the caller.
type Process ¶
type Process[K any] struct { // contains filtered or unexported fields }
Process owns the reusable Extism plugin instance for one spawned program. Its quanta are serialized: a second Resume while one runs is refused.
func NewProcess ¶
func NewProcess[K any](ctx context.Context, program *Program, spec ProcessSpec[K]) (*Process[K], error)
NewProcess instantiates a fresh process from the program image — posix_spawn semantics: a named program, explicit input, explicitly handed authority (the dispatcher), nothing inherited.
type ProcessSpec ¶
type ProcessSpec[K any] struct { Input json.RawMessage Entrypoint string Cred K Dispatcher sys.Dispatcher[K] }
ProcessSpec describes one process: its program input, entrypoint, credential, and the dispatcher that will serve its syscalls.
Cred is the host-side credential for the process: it identifies the process and carries whatever authority context the app attaches. It is never visible to or supplied by the guest.
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program is one compiled program image: a factory of processes. Many processes may run one program, and they need not share a credential type — the image is just code, so the credential lives on the Process.
func NewProgram ¶
NewProgram compiles a program image and registers the syscall host function. It rejects images that grant ambient authority (non-empty AllowedHosts or AllowedPaths) with ErrAmbientAuthority.
type ResumeResult ¶
type ResumeResult struct {
Status ResumeStatus
Output json.RawMessage
Err error
}
ResumeResult is how one quantum ended. Output is the guest's own output. Err says why a quantum failed or was stopped.
type ResumeStatus ¶
type ResumeStatus string
ResumeStatus is how one quantum ended.
const ( ResumeCompleted ResumeStatus = "completed" ResumeYielded ResumeStatus = "yielded" ResumeStopped ResumeStatus = "stopped" ResumeFailed ResumeStatus = "failed" )
Directories
¶
| Path | Synopsis |
|---|---|
|
Package sys defines the vocabulary of the syscall boundary: a Syscall from the guest, a SyscallResult (result, yield, or failure) back, and the Dispatcher interface that turns one into the other.
|
Package sys defines the vocabulary of the syscall boundary: a Syscall from the guest, a SyscallResult (result, yield, or failure) back, and the Dispatcher interface that turns one into the other. |