runtime

package
v0.0.0-...-9ccd474 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: BSD-3-Clause Imports: 33 Imported by: 1

Documentation

Index

Constants

View Source
const MaxProcs = 16384 // Per Executor.
View Source
const ResultSuccess = 0

ResultSuccess is the Result.Value() which indicates success.

Variables

View Source
var DefaultConfig = Config{
	MaxProcs:  MaxProcs,
	Container: container.DefaultConfig,
}
View Source
var ErrDuplicateService error = badprogram.Error("duplicate service")

Functions

func ContextWithDummyProcessKey

func ContextWithDummyProcessKey(ctx context.Context) context.Context

ContextWithDummyProcessKey for testing.

Types

type Config

type Config struct {
	MaxProcs     int
	ConnFile     *os.File
	DaemonSocket string           // Applicable if ConnFile is not set.
	Container    container.Config // Applicable if ConnFile and DaemonSocket are not set.
	ErrorLog     Logger
}

type Executor

type Executor struct {
	// contains filtered or unexported fields
}

Executor manages Process resources in an isolated environment.

func NewExecutor

func NewExecutor(config *Config) (e *Executor, err error)

func (*Executor) Close

func (e *Executor) Close() error

Close kills all processes.

func (*Executor) Dead

func (e *Executor) Dead() <-chan struct{}

Dead channel will be closed when the executor process dies. If that wasn't requested by calling Close, it indicates an internal error.

func (*Executor) Group

func (e *Executor) Group(group *ProcessGroup) GroupExecutor

Group returns a factory type which creates processes into the specified group. If group is nil, the default group will be used.

func (*Executor) NewGroupProcess

func (e *Executor) NewGroupProcess(ctx context.Context, group *ProcessGroup) (*Process, error)

NewGroupProcess creates a process into the specified group. If group is nil, the default group will be used.

func (*Executor) NewProcess

func (e *Executor) NewProcess(ctx context.Context) (*Process, error)

NewProcess creates a process into the default group.

type GroupExecutor

type GroupExecutor struct {
	*Executor
	*ProcessGroup
}

GroupExecutor overrides the default process group of an executor.

func (GroupExecutor) NewGroupProcess

func (ge GroupExecutor) NewGroupProcess(ctx context.Context, group *ProcessGroup) (*Process, error)

NewGroupProcess creates a process into the specified group. If group is nil, ge.ProcessGroup will be used.

func (GroupExecutor) NewProcess

func (ge GroupExecutor) NewProcess(ctx context.Context) (*Process, error)

NewProcess creates a process into ge.ProcessGroup.

type GroupProcessFactory

type GroupProcessFactory interface {
	ProcessFactory
	NewGroupProcess(context.Context, *ProcessGroup) (*Process, error)
}

func DistributeGroupProcesses

func DistributeGroupProcesses(executors ...GroupProcessFactory) GroupProcessFactory

DistributeGroupProcesses among multiple executors.

type InstanceServer

type InstanceServer interface {
	Start(context.Context, chan<- packet.Thunk) error
	Discover(ctx context.Context, newNames []string) (all []ServiceState, err error)
	Handle(context.Context, chan<- packet.Thunk, packet.Buf) (packet.Buf, error)
	Shutdown(ctx context.Context, suspend bool) ([]snapshot.Service, error)
}

type Logger

type Logger interface {
	Printf(string, ...interface{})
}

type Process

type Process struct {
	// contains filtered or unexported fields
}

Process is used to execute a single program image once. Created via an Executor or a derivative ProcessFactory.

A process is idle until its Start method is called. Close must eventually be called to release resources.

func (*Process) Close

func (p *Process) Close() (err error)

Close must not be called concurrently with Start or Serve.

func (*Process) Kill

func (p *Process) Kill()

Kill the process if it is still alive. If killed, Serve call will return with the Killed trap.

This can be called multiple times, concurrently with Start, Serve, Suspend, Close and itself.

func (*Process) Serve

func (p *Process) Serve(ctx context.Context, services ServiceRegistry, buffers *snapshot.Buffers) (Result, trap.ID, error)

Serve the user program until the process terminates. Canceling the context suspends the program.

Start must have been called before this.

Buffers will be mutated (unless nil).

A meaningful trap id is returned also when an error is returned. The result is meaningful when trap is Exit.

func (*Process) Start

func (p *Process) Start(code ProgramCode, state ProgramState, policy ProcessPolicy) (err error)

Start the program. The program state will be undergoing mutation until the process terminates.

This function must be called before Serve.

func (*Process) Suspend

func (p *Process) Suspend()

Suspend the program if it is still running. If suspended, Serve call will return with the Suspended trap. (The program may get suspended also through other means.)

This can be called multiple times, concurrently with Start, Serve, Kill, Close and itself.

type ProcessChan

type ProcessChan <-chan ResultProcess

func PrepareProcesses

func PrepareProcesses(ctx context.Context, f ProcessFactory, bufsize int) ProcessChan

PrepareProcesses in advance.

func (ProcessChan) NewProcess

func (c ProcessChan) NewProcess(ctx context.Context) (*Process, error)

type ProcessFactory

type ProcessFactory interface {
	NewProcess(context.Context) (*Process, error)
}

func DistributeProcesses

func DistributeProcesses(executors ...ProcessFactory) ProcessFactory

DistributeProcesses among multiple executors.

type ProcessGroup

type ProcessGroup struct {
	// contains filtered or unexported fields
}

func OpenCgroup

func OpenCgroup(name string) (*ProcessGroup, error)

func (*ProcessGroup) Close

func (g *ProcessGroup) Close() error

type ProcessKey

type ProcessKey struct {
	// contains filtered or unexported fields
}

ProcessKey is an opaque handle to a single instance of a program image being executed.

func MustContextProcessKey

func MustContextProcessKey(ctx context.Context) ProcessKey

func (ProcessKey) Compare

func (key ProcessKey) Compare(other ProcessKey) int

type ProcessPolicy

type ProcessPolicy struct {
	TimeResolution time.Duration
	DebugLog       io.Writer
}

type ProgramCode

type ProgramCode interface {
	PageSize() int
	TextSize() int
	Random() bool
	Text() (interface{ Fd() uintptr }, error)
}

type ProgramState

type ProgramState interface {
	TextAddr() uint64
	StackSize() int
	StackUsage() int
	GlobalsSize() int
	MemorySize() int
	MaxMemorySize() int
	StartAddr() uint32
	EntryAddr() uint32
	MonotonicTime() uint64
	BeginMutation(textAddr uint64) (interface{ Fd() uintptr }, error)
}

type Result

type Result struct {
	// contains filtered or unexported fields
}

func (Result) String

func (r Result) String() string

func (Result) Terminated

func (r Result) Terminated() bool

Terminated instead of halting?

func (Result) Value

func (r Result) Value() int

type ResultProcess

type ResultProcess struct {
	Process *Process
	Err     error
}

type ServiceConfig

type ServiceConfig struct {
	MaxSendSize int // Maximum size which the program is prepared to receive.
}

ServiceConfig for program instance specific ServiceRegistry invocation.

type ServiceRegistry

type ServiceRegistry interface {
	CreateServer(context.Context, ServiceConfig, []snapshot.Service, chan<- packet.Thunk) (InstanceServer, []ServiceState, <-chan error, error)
}

ServiceRegistry is a collection of configured services.

StartServing is called once for each program instance. The receive channel is closed when the program is being shut down.

config.MaxSendSize may be used when buffering data.

The snapshot buffers must not be mutated, and references to them shouldn't be retained for long as they may be parts of a large memory allocation.

The returned channel will deliver up to one error if one occurs after initialization.

The service package contains an implementation of this interface.

type ServiceState

type ServiceState struct {
	// contains filtered or unexported fields
}

ServiceState is used to respond to a service discovery request.

func (*ServiceState) SetAvail

func (s *ServiceState) SetAvail()

Directories

Path Synopsis
abi
rt
Package rt defines a public subset of the runtime library ABI.
Package rt defines a public subset of the runtime library ABI.

Jump to

Keyboard shortcuts

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