cguest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

C shared-library guests

All C guest support lives in the pkg/ext-go/cengine module:

Package Responsibility
cguest Loads shared libraries exposing ext_plugin_guest_*, owns native handles and exchanges bytes.
cguest/abi Shared C ABI constants and handshake envelope.
cguest/backend Implements engine/plugin.Backend: Ext frames, descriptor and response validation, deadlines and error mapping.
cguest/guest Exports Go plugin guests through the ABI using -buildmode=c-shared.

The loader uses cgo or purego. It is specific to the Ext guest ABI; arbitrary C libraries use cengine/library. The backend and guest export packages use the shared engine/plugin contracts. On darwin/amd64 both loaders refuse Go c-shared guests because two Go runtimes share the TLS slot for g.

scripts/cshared-purego.sh checks the backend and shared host cases with and without cgo. Building a Go c-shared guest still requires cgo.

Documentation

Overview

Package cguest loads trusted C ABI libraries (lib/plugin/include/ext_plugin_guest.h), including Go -buildmode=c-shared guests, and exchanges frames with them as bytes. It knows nothing of the plugin protocol: what the frames mean, and the limits and deadlines a session applies, belong to the caller (cguest/backend makes it a plugin backend). Native code executes inside the host and cannot be forcibly stopped.

It loads with cgo on Linux, macOS, FreeBSD and Windows, and without cgo through purego on Linux, macOS and Windows for amd64 and arm64; Supported reports whether this build can load at all. The C ABI has no host callbacks, so both loaders implement all of it.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalid is a bad path, an oversized frame or a call the guest reported as invalid.
	ErrInvalid = errors.New("cguest: invalid")
	// ErrUnsupported is a library this build cannot load or that is not an ABI v1 guest.
	ErrUnsupported = errors.New("cguest: unsupported")
	// ErrDenied is a guest that refused a new handle.
	ErrDenied = errors.New("cguest: denied")
	// ErrClosed is a call on a closed guest.
	ErrClosed = errors.New("cguest: closed")
)

Functions

func Supported

func Supported() bool

Types

type Guest

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

Guest is one handle on a loaded C ABI library. It runs one call at a time.

func Open

func Open(ctx context.Context, path string) (*Guest, error)

Open loads an absolute verified library path, checks ABI v1 and creates an independent guest handle. Library images remain resident for process lifetime, even after errors: dlclose is unsafe for Go runtimes and callbacks. Use immutable revision-specific artifact paths. Cancellation returns promptly but cannot stop native initializers or open; a handle returned later is closed by the outstanding startup goroutine.

func (*Guest) Call

func (g *Guest) Call(ctx context.Context, op uint32, data []byte) ([]byte, error)

Call sends one frame for operation op (abi.Handshake or abi.Invoke) and returns the guest's frame. A frame larger than abi.MaxFrameBytes is ErrInvalid. When ctx ends first, or the guest fails the call, the guest is closed.

func (*Guest) Close

func (g *Guest) Close() error

Close stops admission and releases waiting callers immediately. Native cleanup runs after an outstanding call returns. It never unloads the image. Native code must honor request deadlines; if it hangs, cleanup stays pending.

func (*Guest) WaitClosed

func (g *Guest) WaitClosed(ctx context.Context) error

WaitClosed waits for actual guest resource cleanup after Close.

Directories

Path Synopsis
Package abi defines the language-neutral ext.plugin C ABI v1 envelope.
Package abi defines the language-neutral ext.plugin C ABI v1 envelope.
Package backend runs plugin guests built as C shared libraries (lib/plugin/include/ext_plugin_guest.h), including Go -buildmode=c-shared guests, as a plugin backend.
Package backend runs plugin guests built as C shared libraries (lib/plugin/include/ext_plugin_guest.h), including Go -buildmode=c-shared guests, as a plugin backend.
Package guest binds Go guests to the Ext C ABI.
Package guest binds Go guests to the Ext C ABI.

Jump to

Keyboard shortcuts

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