Documentation ¶
Overview ¶
Package pointer exchange pointer between cgo and go
Index ¶
- Variables
- func CaptureTrap(err *error)
- func PointerDelete(token uintptr)
- func PointerRestore(token uintptr) interface{}
- func PointerSave(p interface{}) uintptr
- func Throw(trap Trap)
- func ThrowError(err error)
- func ThrowMessage(msg string)
- type Code
- type Codec
- func (c Codec) Bytes(addr, length uint32) []byte
- func (c Codec) CString(addr uint32) string
- func (c Codec) GoBytes(sp uint32) []byte
- func (c Codec) GoString(sp uint32) string
- func (c Codec) SetUint32(addr uint32, val uint32)
- func (c Codec) String(addr, length uint32) string
- func (c Codec) Uint32(addr uint32) uint32
- func (c Codec) Uint64(addr uint32) uint64
- type Context
- type ContextConfig
- type ErrFuncNotFound
- type MapResolver
- type MultiResolver
- type Resolver
- type Trap
- type TrapError
- type TrapFuncSignatureNotMatch
- type TrapInvalidAddress
- type TrapSymbolNotFound
Constants ¶
This section is empty.
Variables ¶
var ( // TrapOOB is raised when memory access out of bound TrapOOB = NewTrap("memory access out of bound") // TrapIntOverflow is raised when math overflow TrapIntOverflow = NewTrap("integer overflow on divide or truncation") // TrapDivByZero is raised when divide by zero TrapDivByZero = NewTrap("integer divide by zero") // TrapInvalidConvert is raised when convert from NaN to integer TrapInvalidConvert = NewTrap("conversion from NaN to integer") // TrapUnreachable is raised when unreachable instruction executed TrapUnreachable = NewTrap("unreachable instruction executed") // TrapInvalidIndirectCall is raised when run invalid call_indirect instruction TrapInvalidIndirectCall = NewTrap("invalid call_indirect") // TrapCallStackExhaustion is raised when call stack exhausted TrapCallStackExhaustion = NewTrap("call stack exhausted") // TrapGasExhaustion is raised when runnning out of gas limit TrapGasExhaustion = NewTrap("run out of gas limit") // TrapInvalidArgument is raised when running function with invalid argument TrapInvalidArgument = NewTrap("invalid function argument") )
Functions ¶
func PointerDelete ¶
func PointerDelete(token uintptr)
PointerDelete deletes token from internal cache
func PointerRestore ¶
func PointerRestore(token uintptr) interface{}
PointerRestore restore the token to go object, a invalid token will return nil
Types ¶
type Code ¶
type Code interface { NewContext(cfg *ContextConfig) (ictx Context, err error) Release() }
type Codec ¶
type Codec struct {
// contains filtered or unexported fields
}
Codec helps encoding and decoding data between wasm code and go code
func NewCodec ¶
NewCodec instances a Codec, if memory of ctx is nil, trapNilMemory will be raised
func (Codec) Bytes ¶
Bytes returns memory region starting from addr, limiting by length
func (Codec) CString ¶
CString decodes a '\x00' terminated c style string
func (Codec) GoBytes ¶
GoBytes decodes Go []byte start from sp
func (Codec) GoString ¶
GoString decodes Go string start from sp
func (Codec) SetUint32 ¶
SetUint32 set val to memory[addr:addr+4]
func (Codec) String ¶
String decodes memory[addr:addr+length] to string
func (Codec) Uint32 ¶
Uint32 decodes memory[addr:addr+4] to uint32
type Context ¶
type Context interface { Exec(name string, param []int64) (ret int64, err error) GasUsed() uint64 ResetGasUsed() SetGasUsed(uint64) Memory() []byte StaticTop() uint32 SetUserData(key string, value interface{}) GetUserData(key string) interface{} Release() }
Context hold the context data when running a wasm instance
type ContextConfig ¶
type ContextConfig struct {
GasLimit int64
}
ContextConfig configures an execution context
type ErrFuncNotFound ¶
type ErrFuncNotFound struct {
Name string
}
func (*ErrFuncNotFound) Error ¶
func (e *ErrFuncNotFound) Error() string
type MapResolver ¶
type MapResolver map[string]interface{}
MapResolver is the Resolver which stores symbols in map
func (MapResolver) ResolveFunc ¶
func (m MapResolver) ResolveFunc(module, name string) (interface{}, bool)
ResolveFunc implements Resolver interface
func (MapResolver) ResolveGlobal ¶
func (m MapResolver) ResolveGlobal(module, name string) (int64, bool)
ResolveGlobal implements Resolver interface
type MultiResolver ¶
type MultiResolver []Resolver
MultiResolver chains multiple Resolvers, symbol looking up is according to the order of resolvers. The first found symbol will be returned.
func NewMultiResolver ¶
func NewMultiResolver(resolvers ...Resolver) MultiResolver
NewMultiResolver instance a MultiResolver from resolves
func (MultiResolver) ResolveFunc ¶
func (m MultiResolver) ResolveFunc(module, name string) (interface{}, bool)
ResolveFunc implements Resolver interface
func (MultiResolver) ResolveGlobal ¶
func (m MultiResolver) ResolveGlobal(module, name string) (int64, bool)
ResolveGlobal implements Resolver interface
type Resolver ¶
type Resolver interface { ResolveFunc(module, name string) (interface{}, bool) ResolveGlobal(module, name string) (int64, bool) }
A Resolver resolves global and function symbols imported by wasm code
type TrapFuncSignatureNotMatch ¶
TrapFuncSignatureNotMatch is raised when calling function signature is not matched
func (*TrapFuncSignatureNotMatch) Reason ¶
func (s *TrapFuncSignatureNotMatch) Reason() string
Reason implements Trap interface
type TrapInvalidAddress ¶
type TrapInvalidAddress uint32
TrapInvalidAddress is the trap raised when encounter an invalid address
func (TrapInvalidAddress) Reason ¶
func (t TrapInvalidAddress) Reason() string
Reason implements Trap interface