wasm

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: Apache-2.0 Imports: 22 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 api.Module, 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 (
	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

HostAnswerSCIONUDPPacket replies to the last received SCION packet, or falls back to dialling the given address if no packet has been received yet. Either way the peer is admitted again and the reply is accounted, so the answer path carries the same policy and limits as an ordinary send. WASM key: "answer_scion_udp_packet"

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

HostConnect dials an IP/UDP/TCP(+TLS) connection to the given address and registers it in the SocketRegistry. The destination is admitted by the network policy first: the address the guest wrote is resolved, checked against the operator's rules and the job's declared destinations, and the connection is then made to the address that was checked rather than to the name, so nothing else can be reached in between. A refused destination is never contacted. Returns the socket handle as I32. WASM key: "connect_tcp", "connect_ip", "connect_udp", "connect_tls"

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

HostGetRemoteAddr writes the socket peer's full "host:port" address into the guest buffer and returns its length, or -1 if unavailable/too small. WASM key: "get_remote_addr"

func HostGetTCPAddr

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

HostGetTCPAddr writes the public "host:port" of the TCP listener into the guest buffer and returns its length, or -1 if unavailable/too small. WASM key: "get_tcp_addr"

func HostGetUDPAddr

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

HostGetUDPAddr writes the public "host:port" of the UDP listener into the guest buffer and returns its length, or -1 if unavailable/too small. WASM key: "get_udp_addr"

func HostReceiveData

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

HostReceiveData performs one underlying read of up to bufLen bytes from the socket at sockID into the guest buffer at bufp and returns the number of bytes read as I32. For TCP/TLS sockets io.EOF is the normal end of stream: bytes returned together with EOF are delivered with their count and a clean EOF returns 0, so the guest sees the stream end on the next read. A TCP/TLS read that makes no progress into a nonempty buffer, (0,nil), traps with io.ErrNoProgress instead of being reported as a false EOF or retried. For UDP/ICMP sockets a zero-length datagram returns 0 and EOF remains an error. Any other error, on any socket type, traps per the host-function convention. WASM key: "receive_tcp_data", "receive_udp_data", "receive_icmp4_data"

func HostReceiveSCIONServerUDPPacket

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

HostReceiveSCIONServerUDPPacket reads one admitted packet from the SCION server listener into udp_receive_buffer. timeout is the deadline in milliseconds. Packets from a peer the policy refuses are dropped and the read continues until the deadline. Returns (bytesRead I32, timestamp I64). lastReceived is updated in place. WASM key: "receive_scion_server_udp_packet"

func HostReceiveUDPFrom

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

HostReceiveUDPFrom reads one admitted datagram from the job's UDP listener into the buffer at recvp and writes the sender's "host:port" into senderp. The address length is stored as a little-endian uint32 at addrLenp so the guest can slice senderp precisely and avoid trailing NULs. Senders the policy refuses are dropped and never delivered; an admitted datagram is accounted against the same limits as the rest of the run's traffic. Returns the number of bytes read as I32; a read error panics per the host-function convention. No deadline handling is applied: the executor's debuglet timeout closes UdpServer, which unblocks a pending read. WASM key: "receive_udp_from"

func HostSCIONAvailablePaths

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

HostSCIONAvailablePaths returns the number of available SCION paths to the admitted destination. WASM key: "scion_available_paths"

func HostSCIONGetInterfaceDetails

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

HostSCIONGetInterfaceDetails returns the IA and IfID of interface ifIdx on path pathIdx for the connection to the admitted destination, or zeros when there is no such interface. WASM key: "scion_get_interface_details"

func HostSCIONPathLength

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

HostSCIONPathLength returns the hop count of path at index pathIdx for the connection to the admitted destination, or -1 when there is no such path or its interfaces are unknown. WASM key: "scion_path_length"

func HostSCIONSelectPath

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

HostSCIONSelectPath forces the path selector for the admitted destination to use path index pathIdx. WASM key: "scion_select_path"

func HostSendData

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

HostSendData writes size bytes starting at offset ptr from the WASM memory to the socket at sockID. WASM key: "send_tcp_data", "send_icmp4_data"

func HostSendSCIONUDPPacket

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

HostSendSCIONUDPPacket dials (or reuses) a SCION connection to the admitted destination and writes size bytes from udp_send_buffer. The packet is accounted against the run's limits before it is written, so a SCION send is not an unmetered path around the ordinary socket wrappers. Returns the send timestamp as I64. WASM key: "send_scion_udp_packet"

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 PrimitiveType

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

type WasmEnv

type WasmEnv struct {
	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

	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) error

func (*WasmEnv) InstallTCP

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

Listener publication competes with terminal closure. References remain immutable after successful publication; late resources are consumed/closed. A listener is marked before it is published, and never after closure; one that cannot be marked is closed. Handshake replies sent between listen and marking can still escape attribution.

func (*WasmEnv) InstallUDP

func (e *WasmEnv) InstallUDP(conn *net.UDPConn, port int, addr string) 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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