loader

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: Apache-2.0 Imports: 13 Imported by: 4

Documentation

Index

Constants

View Source
const (
	FuncFlag_TOPFRAME = 1 << iota
	FuncFlag_SPWRITE
	FuncFlag_ASM
)

Note: This list must match the list in runtime/symtab.go.

View Source
const (
	// PCDATA_UnsafePoint values.
	PCDATA_UnsafePointSafe   = -1 // Safe for async preemption
	PCDATA_UnsafePointUnsafe = -2 // Unsafe for async preemption

	// PCDATA_Restart1(2) apply on a sequence of instructions, within
	// which if an async preemption happens, we should back off the PC
	// to the start of the sequence when resume.
	// We need two so we can distinguish the start/end of the sequence
	// in case that two sequences are next to each other.
	PCDATA_Restart1 = -3
	PCDATA_Restart2 = -4

	// Like PCDATA_RestartAtEntry, but back to function entry if async
	// preempted.
	PCDATA_RestartAtEntry = -5
)
View Source
const (

	// ArgsSizeUnknown is set in Func.argsize to mark all functions
	// whose argument size is unknown (C vararg functions, and
	// assembly code without an explicit specification).
	// This value is generated by the compiler, assembler, or linker.
	ArgsSizeUnknown = -0x80000000
)

PCDATA and FUNCDATA table indexes.

See funcdata.h and $GROOT/src/cmd/internal/objabi/funcdata.go.

Variables

This section is empty.

Functions

func WrapGoC

func WrapGoC(text []byte, natives []CFunc, stubs []GoC, modulename string, filename string)

WrapGoC wraps C functions and loader it into Go stubs

Types

type CFunc

type CFunc struct {
	// C function name
	Name string

	// entry pc relative to entire text segment
	EntryOff uint32

	// function text size in bytes
	TextSize uint32

	// maximum stack depth of the function
	MaxStack uintptr

	// PC->SP delta lists of the function
	Pcsp [][2]uint32
}

CFunc is a function information for C func

type Func

type Func struct {
	ID          uint8  // see runtime/symtab.go
	Flag        uint8  // see runtime/symtab.go
	ArgsSize    int32  // args byte size
	EntryOff    uint32 // start pc, offset to moduledata.text
	TextSize    uint32 // size of func text
	DeferReturn uint32 // offset of start of a deferreturn call instruction from entry, if any.
	FileIndex   uint32 // index into filetab
	Name        string // name of function

	// PC data
	Pcsp            *Pcdata // PC -> SP delta
	Pcfile          *Pcdata // PC -> file index
	Pcline          *Pcdata // PC -> line number
	PcUnsafePoint   *Pcdata // PC -> unsafe point, must be PCDATA_UnsafePointSafe or PCDATA_UnsafePointUnsafe
	PcStackMapIndex *Pcdata // PC -> stack map index, relative to ArgsPointerMaps and LocalsPointerMaps
	PcInlTreeIndex  *Pcdata // PC -> inlining tree index, relative to InlTree
	PcArgLiveIndex  *Pcdata // PC -> arg live index, relative to ArgLiveInfo

	// Func data, must implement encoding.BinaryMarshaler
	ArgsPointerMaps    encoding.BinaryMarshaler // concrete type: *StackMap
	LocalsPointerMaps  encoding.BinaryMarshaler // concrete type: *StackMap
	StackObjects       encoding.BinaryMarshaler
	InlTree            encoding.BinaryMarshaler
	OpenCodedDeferInfo encoding.BinaryMarshaler
	ArgInfo            encoding.BinaryMarshaler
	ArgLiveInfo        encoding.BinaryMarshaler
	WrapInfo           encoding.BinaryMarshaler
}

Func contains information about a function.

type Function

type Function unsafe.Pointer

Function is a function pointer

func Load

func Load(text []byte, funcs []Func, modulename string, filenames []string) (out []Function)

Load loads given machine codes and corresponding function information into go moduledata and returns runnable function pointer WARN: this API is experimental, use it carefully

type GoC

type GoC struct {
	// CName is the name of corresponding C function
	CName string

	// CEntry points out where to store the entry address of corresponding C function.
	// It won't be set if nil
	CEntry *uintptr

	// GoFunc is the POINTER of corresponding go stub function.
	// It is used to generate Go-C ABI conversion wrapper and receive the wrapper's address
	//   eg. &func(a int, b int) int
	//     FOR
	//     int add(int a, int b)
	// It won't be set if nil
	GoFunc interface{}
}

GoC is the wrapper for Go calls to C

type Loader

type Loader struct {
	Name string // module name
	File string // file name
	Options
}

Loader is a helper used to load a module simply

func (Loader) LoadOne

func (self Loader) LoadOne(text []byte, funcName string, frameSize int, argSize int, argPtrs []bool, localPtrs []bool) Function

LoadFuncs loads only one function as module, and returns the function pointer

  • text: machine code
  • funcName: function name
  • frameSize: stack frame size.
  • argSize: argument total size (in bytes)
  • argPtrs: indicates if a slot (8 Bytes) of arguments memory stores pointer, from low to high
  • localPtrs: indicates if a slot (8 Bytes) of local variants memory stores pointer, from low to high

WARN:

  • the function MUST has fixed SP offset equaling to this, otherwise it go.gentraceback will fail
  • the function MUST has only one stack map for all arguments and local variants

type Options

type Options struct {
	// NoPreempt is used to disable async preemption for this module
	NoPreempt bool
}

Options used to load a module

type Pcdata

type Pcdata []Pcvalue

Pcdata represents pc->value mapping table.

WARN: we use ** [Pcdata[i].PC, Pcdata[i+1].PC) **
as the range where the Pcdata[i].Val is effective.

type Pcvalue

type Pcvalue struct {
	PC  uint32 // program count relative to function entry
	Val int32  // value relative to the value in function entry
}

Pcvalue is the program count corresponding to the value Val

WARN: we use relative value here (to function entry)

Directories

Path Synopsis
internal
abi
rt

Jump to

Keyboard shortcuts

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