wasm

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package wasm contains the WASM host function implementations that are imported by WASM modules at runtime. Each host function follows the wazero calling convention: (ctx context.Context, mod Memory, params []uint64) → []uint64.

Go function names use camelCase with a "host" prefix. The WASM-visible import key strings (used during host module registration) are left unchanged so that existing WASM modules do not need recompilation.

Index

Constants

View Source
const ExperimentModule = "debuglet_experiment_v1"

ExperimentModule is the optional readiness ABI; the base env ABI is unchanged.

View Source
const (
	MAX_SLICE_LENGTH = 8192
)

Variables

This section is empty.

Functions

func ExtractMem

func ExtractMem[T PrimitiveType](mod api.Module, source, num uint32) ([]T, error)

func ExtractStr

func ExtractStr(mod api.Module, source, num uint32) (string, error)

func HostAcceptTCP

func HostAcceptTCP(env *WasmEnv) func(ctx context.Context) int32

HostAcceptTCP accepts one incoming TCP connection on the job's listener and registers it in the SocketRegistry. An accepted peer is admitted by the same policy as an outbound destination and accounted against the same limits: a peer the policy refuses is closed without ever being handed to the guest, and the next connection is accepted in its place. Returns the socket handle as I32. WASM key: "accept_tcp"

func HostAnswerSCIONUDPPacket

func HostAnswerSCIONUDPPacket(env *WasmEnv, addresses []string) func(ctx context.Context, mod api.Module, addrp, addrLen, sendp, sendLen uint32) int64

func HostClose

func HostClose(env *WasmEnv) func(ctx context.Context, sockID int32)

HostClose closes the socket at handle sockID. WASM key: "close_tcp", "close_ip"

func HostConnect

func HostConnect(env *WasmEnv, socketType socket.SocketType) func(ctx context.Context, mod api.Module, addrp, addrLen uint32) int32

func HostDrain

func HostDrain(env *WasmEnv) func(ctx context.Context, sockID int32)

func HostGetRemoteAddr

func HostGetRemoteAddr(env *WasmEnv) func(ctx context.Context, mod api.Module, sockID int32, bufPtr, bufLen uint32) int32

func HostGetTCPAddr

func HostGetTCPAddr(env *WasmEnv) func(ctx context.Context, mod api.Module, bufPtr, bufLen uint32) int32

func HostGetUDPAddr

func HostGetUDPAddr(env *WasmEnv) func(ctx context.Context, mod api.Module, bufPtr, bufLen uint32) int32

func HostIOAcceptTCP added in v0.3.0

func HostIOAcceptTCP(env *WasmEnv) func(context.Context, int64) uint64

HostIOAcceptTCP bounds one accept without applying its timeout to the returned connection. Refused peers share the same deadline.

func HostIOClose added in v0.3.0

func HostIOClose(env *WasmEnv) func(context.Context, int32) uint64

func HostIODeadline added in v0.3.0

func HostIODeadline(env *WasmEnv) func(context.Context, int32, uint32, int64) uint64

func HostIODial added in v0.3.0

func HostIODial(env *WasmEnv) func(context.Context, api.Module, uint32, uint32, uint32, int64) uint64

func HostIORead added in v0.3.0

func HostIORead(env *WasmEnv) func(context.Context, api.Module, int32, uint32, uint32) uint64

func HostIOWrite added in v0.3.0

func HostIOWrite(env *WasmEnv) func(context.Context, api.Module, int32, uint32, uint32) uint64

func HostReceiveData

func HostReceiveData(env *WasmEnv) func(ctx context.Context, mod api.Module, sockID int32, bufp, bufLen uint32) int32

func HostReceiveSCIONServerUDPPacket

func HostReceiveSCIONServerUDPPacket(env *WasmEnv) func(ctx context.Context, mod api.Module, recvp, recvLen uint32, timeout int32) (int32, int64)

func HostReceiveUDPFrom

func HostReceiveUDPFrom(env *WasmEnv) func(ctx context.Context, mod api.Module, recvp, recvLen, senderp, senderLen, addrLenp uint32) int32

func HostSCIONAvailablePaths

func HostSCIONAvailablePaths(env *WasmEnv) func(ctx context.Context, mod api.Module, addrp, addrLen uint32) int32

func HostSCIONGetInterfaceDetails

func HostSCIONGetInterfaceDetails(env *WasmEnv) func(ctx context.Context, mod api.Module, addrp, addrLen uint32, pathIdx int32, ifIdx int32) (int64, int64)

func HostSCIONPathLength

func HostSCIONPathLength(env *WasmEnv) func(ctx context.Context, mod api.Module, addrp, addrLen uint32, pathIdx int32) int32

func HostSCIONSelectPath

func HostSCIONSelectPath(env *WasmEnv) func(ctx context.Context, mod api.Module, addrp, addrLen uint32, pathIdx int32)

func HostSendData

func HostSendData(env *WasmEnv) func(ctx context.Context, mod api.Module, sockID int32, bufp, bufLen uint32)

func HostSendSCIONUDPPacket

func HostSendSCIONUDPPacket(env *WasmEnv) func(ctx context.Context, mod api.Module, addrp, addrLen, sendp, sendLen uint32) int64

func Register added in v0.3.0

func Register(builder wazero.HostModuleBuilder, module string, functions []Function, proxy func(context.Context, api.Module, int, []uint64)) wazero.HostModuleBuilder

Register installs the fixed imports. A nil proxy calls the local host; otherwise the worker calls its parent through the supplied bounded bridge.

func RegisterIO added in v0.3.0

func RegisterIO(builder wazero.HostModuleBuilder, env *WasmEnv) wazero.HostModuleBuilder

RegisterIO adds recoverable sockets without changing the legacy env module.

Types

type DatagramTagger

type DatagramTagger interface {
	WrapDatagram(net.Conn) (net.Conn, error)
}

DatagramTagger is the pure-Go tagger, which tags UDP and ICMP by sending them itself; the eBPF tagger tags every socket in the kernel instead.

type Drainable

type Drainable interface {
	Drain(ctx context.Context)
}

type ExperimentControl added in v0.3.0

type ExperimentControl interface {
	Ready(context.Context, []byte) (wire.Experiment, error)
}

ExperimentControl is the run-bound capability supplied by the executor. The guest can publish metadata but cannot select a run, account or session.

type Function added in v0.3.0

type Function struct {
	Module, Name    string
	Params, Results []api.ValueType
	// contains filtered or unexported fields
}

Function describes one fixed guest import. The supervisor and the local runtime use the same table and implementation; only memory access differs.

func Functions added in v0.3.0

func Functions(env *WasmEnv) []Function

func (Function) Call added in v0.3.0

func (f Function) Call(ctx context.Context, mem Memory, stack []uint64)

type Memory added in v0.3.0

type Memory interface {
	Read(uint32, uint32) ([]byte, bool)
	Write(uint32, []byte) bool
	WriteUint32Le(uint32, uint32) bool
}

Memory is the bounded memory surface used by network host calls. Read callers must write received data explicitly; a returned slice need not alias the guest.

type PrimitiveType

type PrimitiveType interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~float32 | ~float64
}

type WasmEnv

type WasmEnv struct {
	Experiment ExperimentControl

	DebugletID uuid.UUID
	Policy     scheduler.Policy
	// Net is the network policy every transport is checked against. It is the
	// operator's rules and this run's declared destinations together; without
	// it no transport is available.
	Net *netpolicy.Policy

	Limiter     *app.Limiter
	PacketCount ratelimit.PacketCount
	// Accountant covers the traffic no connection wrapper does: listener
	// datagrams and SCION packets.
	Accountant   *ratelimit.Accountant
	LastReceived net.Addr
	Logger       *zap.SugaredLogger
	TlsCfg       *tls.Config
	Tagger       tagger.TaggerInterface

	// Listeners
	PortManager *socket.PortManager
	// TCP
	TcpServer     *net.TCPListener
	TcpServerPort int
	TcpServerAddr string
	// UDP
	UdpServer     *net.UDPConn
	UdpServerPort int
	UdpServerAddr string

	ScionServer pan.ListenConn

	Budget *socket.Budget

	Registry  *socket.SocketRegistry
	ScionConn *socket.SCIONConnRegistry
	// contains filtered or unexported fields
}

func (*WasmEnv) Close

func (e *WasmEnv) Close() error

func (*WasmEnv) InstallSCION

func (e *WasmEnv) InstallSCION(conn pan.ListenConn, reservation *socket.Reservation) error

func (*WasmEnv) InstallTCP

func (e *WasmEnv) InstallTCP(lis *net.TCPListener, port int, addr string, reservation *socket.Reservation) error

Listener publication competes with terminal closure. References remain immutable after successful publication; late resources are consumed/closed. A listener arrives already marked: the PortManager marks it in its listen control hook, before the socket is bound and listening, so no handshake reply or datagram leaves it unattributed.

func (*WasmEnv) InstallUDP

func (e *WasmEnv) InstallUDP(conn *net.UDPConn, port int, addr string, reservation *socket.Reservation) error

func (*WasmEnv) RecordCleanupError

func (e *WasmEnv) RecordCleanupError(err error)

RecordCleanupError records a resource-release failure independently of the operation's selected execution/cancellation outcome. Nil is a no-op.

func (*WasmEnv) SCIONAddr

func (e *WasmEnv) SCIONAddr() string

func (*WasmEnv) TCPListenerEndpoint added in v0.3.0

func (e *WasmEnv) TCPListenerEndpoint() string

TCPListenerEndpoint returns only an installed listener's advertised endpoint. It becomes unavailable as soon as terminal resource closure begins.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL