runtime

package
v0.0.0-...-0e4e454 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2020 License: BSD-3-Clause Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultCgroupTitle = "gate-runtime"
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,
	LibDir:   DefaultLibDir,
	Cgroup: CgroupConfig{
		Title: DefaultCgroupTitle,
	},
}
View Source
var DefaultLibDir string = func() string {
	var parent string
	if filename, err := os.Executable(); err == nil {
		parent = path.Join(path.Dir(filename), "..")
	}
	return path.Join(parent, "lib", "gate", "runtime")
}()
View Source
var ErrDuplicateService error = badprogram.Errorf("duplicate service")

Functions

This section is empty.

Types

type CgroupConfig

type CgroupConfig struct {
	Parent string
	Title  string
}

CgroupConfig is effective if gate-runtime-container was compiled with cgroup support.

type Config

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

	// These are applicable if ConnFile and DaemonSocket are not set:
	NoNamespaces bool
	Container    struct{ Cred }
	Executor     struct{ Cred }
	LibDir       string
	Cgroup       CgroupConfig
}

type Cred

type Cred = runtimeapi.Cred

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

func (e *Executor) NewProcess(ctx context.Context) (*Process, 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 Result, trapID trap.ID, err 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 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 ServiceDiscoverer

type ServiceDiscoverer interface {
	Discover(ctx context.Context, newNames []string) (all []ServiceState, err error)
	NumServices() int
	Suspend() (snapshots []snapshot.Service)
	Shutdown()
}

ServiceDiscoverer is used to look up service availability when responding to a program's service discovery packet. It modifies the internal state of the ServiceRegistry server.

type ServiceRegistry

type ServiceRegistry interface {
	StartServing(
		ctx context.Context,
		config ServiceConfig,
		snapshots []snapshot.Service,
		send chan<- packet.Buf,
		recv <-chan packet.Buf,
	) (
		ServiceDiscoverer,
		[]ServiceState,
		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 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

Jump to

Keyboard shortcuts

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