Documentation ¶
Overview ¶
Package memory contains types used for representing and simulating memory observed in the capture.
Index ¶
- Constants
- Variables
- func AlignOf(t reflect.Type, m *device.MemoryLayout) uint64
- func CharToBytes(ϟchars []Char) []byte
- func InvertMemoryRanges(inputList interval.U64RangeList) interval.U64RangeList
- func IsSize(v interface{}) bool
- func LoadPointer(ctx context.Context, p Pointer, pools Pools, l *device.MemoryLayout) (interface{}, error)
- func LoadSlice(ctx context.Context, s Slice, pools Pools, l *device.MemoryLayout) (interface{}, error)
- func PointerToString(p Pointer) string
- func Read(d *Decoder, p interface{})
- func SizeOf(t reflect.Type, m *device.MemoryLayout) uint64
- func Write(e *Encoder, v interface{})
- func Writer(p *Pool, rng Range) io.Writer
- type AlignedTy
- type Allocator
- type Char
- type CharTy
- type Data
- type Decodable
- type Decoder
- func (d *Decoder) Align(to uint64)
- func (d *Decoder) Bool() bool
- func (d *Decoder) Char() Char
- func (d *Decoder) Data(buf []byte)
- func (d *Decoder) Error() error
- func (d *Decoder) F32() float32
- func (d *Decoder) F64() float64
- func (d *Decoder) I16() int16
- func (d *Decoder) I32() int32
- func (d *Decoder) I64() int64
- func (d *Decoder) I8() int8
- func (d *Decoder) Int() Int
- func (d *Decoder) MemoryLayout() *device.MemoryLayout
- func (d *Decoder) Offset() uint64
- func (d *Decoder) Pointer() uint64
- func (d *Decoder) Size() Size
- func (d *Decoder) Skip(n uint64)
- func (d *Decoder) String() string
- func (d *Decoder) U16() uint16
- func (d *Decoder) U32() uint32
- func (d *Decoder) U64() uint64
- func (d *Decoder) U8() uint8
- func (d *Decoder) Uint() Uint
- type Encodable
- type Encoder
- func (e *Encoder) Align(to uint64)
- func (e *Encoder) Bool(v bool)
- func (e *Encoder) Char(v Char)
- func (e *Encoder) Data(buf []byte)
- func (e *Encoder) Error() error
- func (e *Encoder) F32(v float32)
- func (e *Encoder) F64(v float64)
- func (e *Encoder) I16(v int16)
- func (e *Encoder) I32(v int32)
- func (e *Encoder) I64(v int64)
- func (e *Encoder) I8(v int8)
- func (e *Encoder) Int(v Int)
- func (e *Encoder) MemoryLayout() *device.MemoryLayout
- func (e *Encoder) Offset() uint64
- func (e *Encoder) Pad(n uint64)
- func (e *Encoder) Pointer(addr uint64)
- func (e *Encoder) Size(v Size)
- func (e *Encoder) String(v string)
- func (e *Encoder) U16(v uint16)
- func (e *Encoder) U32(v uint32)
- func (e *Encoder) U64(v uint64)
- func (e *Encoder) U8(v uint8)
- func (e *Encoder) Uint(v Uint)
- type Int
- type IntTy
- type Pointer
- type Pool
- type PoolID
- type Pools
- func (m *Pools) ApplicationPool() *Pool
- func (p *Pools) Clone() Pools
- func (m *Pools) Count() int
- func (m *Pools) Get(id PoolID) (*Pool, error)
- func (m *Pools) MustGet(id PoolID) *Pool
- func (m *Pools) New() (id PoolID, p *Pool)
- func (m *Pools) NewAt(id PoolID) *Pool
- func (m *Pools) NextPoolID() PoolID
- func (m *Pools) SetOnCreate(onCreate func(PoolID, *Pool))
- func (m *Pools) String() string
- type Range
- func (i Range) Contains(addr uint64) bool
- func (i Range) End() uint64
- func (i Range) Expand(addr uint64) Range
- func (i Range) First() uint64
- func (i Range) Intersect(other Range) Range
- func (i Range) Last() uint64
- func (i Range) Overlaps(other Range) bool
- func (i Range) Span() interval.U64Span
- func (i Range) String() string
- func (i Range) TrimLeft(count uint64) Range
- func (i Range) Window(win Range) Range
- type RangeList
- type ReflectPointer
- type Size
- type SizeTy
- type SizedTy
- type Slice
- type Uint
- type UintTy
Constants ¶
const ( // ApplicationPool is the PoolID of Pool representing the application's memory // address space. ApplicationPool = PoolID(PoolNames_Application) )
Variables ¶
var Nullptr = BytePtr(0)
Nullptr is a zero-address pointer.
Functions ¶
func AlignOf ¶
func AlignOf(t reflect.Type, m *device.MemoryLayout) uint64
AlignOf returns the byte alignment of the type t.
func CharToBytes ¶
CharToBytes changes the Char values to their byte[] representation.
func InvertMemoryRanges ¶
func InvertMemoryRanges(inputList interval.U64RangeList) interval.U64RangeList
InvertMemoryRanges converts a used memory range list into a free list and the other way around.
func IsSize ¶
func IsSize(v interface{}) bool
IsSize returns true if v is a Size or alias to a Size.
func LoadPointer ¶
func LoadPointer(ctx context.Context, p Pointer, pools Pools, l *device.MemoryLayout) (interface{}, error)
LoadPointer loads the element from p.
func LoadSlice ¶
func LoadSlice(ctx context.Context, s Slice, pools Pools, l *device.MemoryLayout) (interface{}, error)
LoadSlice loads the slice elements from s into a go-slice of the slice type.
func PointerToString ¶
PointerToString returns a string representation of the pointer.
func Read ¶
func Read(d *Decoder, p interface{})
Read reads the value pointed at p from the decoder d using C alignment rules. If v is an array or slice, then each of the elements will be read, sequentially.
func SizeOf ¶
func SizeOf(t reflect.Type, m *device.MemoryLayout) uint64
SizeOf returns the byte size of the type t.
Types ¶
type AlignedTy ¶
type AlignedTy interface { // Alignment returns the alignment of the type in bytes. TypeAlignment(*device.MemoryLayout) uint64 }
AlignedTy is the interface implemented by types that can calculate their size.
type Allocator ¶
type Allocator interface { // Alloc allocates count bytes at an offset that is a multiple of align. Alloc(count, align uint64) (uint64, error) // Free marks the block starting at the given offset as free. Free(base uint64) error // AllocList returns the ranges currently allocated from this allocator. AllocList() interval.U64RangeList // FreeList returns the free ranges this allocator can allocate from. FreeList() interval.U64RangeList // ReserveRanges reserves the given ranges in the free-list, meaning // they cannot be allocated from ReserveRanges(interval.U64RangeList) }
Allocator is a memory allocator.
func NewBasicAllocator ¶
func NewBasicAllocator(freeList interval.U64RangeList) Allocator
NewBasicAllocator creates a new allocator which allocates memory from the given list of free ranges. Memory is allocated by finding the leftmost free block large enough to fit the required size with the specified alignment. The returned allocator is not thread-safe.
type CharTy ¶
type CharTy interface {
IsChar()
}
CharTy is the interface implemented by types that should be treated as char type.
type Data ¶
type Data interface { // Get writes the bytes representing the slice to out, starting at offset // bytes. This is equivalent to: copy(out, data[offset:]). Get(ctx context.Context, offset uint64, out []byte) error // NewReader returns an io.Reader to efficiently read from the slice. // There shouldn't be a need to wrap this in additional buffers. NewReader(ctx context.Context) io.Reader // ResourceID returns the identifier of the resource representing the slice, // creating a new resource if it isn't already backed by one. ResourceID(ctx context.Context) (id.ID, error) // Size returns the number of bytes that would be returned by calling Get. Size() uint64 // Slice returns a new Data referencing a subset range of the data. // The range r is relative to the base of the Slice. For example a slice of // [0, 4] would return a Slice referencing the first 5 bytes of this Slice. // Attempting to slice outside the range of this Slice will result in a // panic. Slice(r Range) Data // ValidRanges returns the list of slice-relative memory ranges that contain // valid (non-zero) data that can be read with Get. ValidRanges() RangeList // Strlen returns the number of bytes before the first zero byte in the // data. // If the Data does not contain a zero byte, then -1 is returned. Strlen(ctx context.Context) (int, error) }
Data is the interface for a data source that can be resolved to a byte slice with Get, or 'sliced' to a subset of the data source.
func NewData ¶
func NewData(layout *device.MemoryLayout, data ...interface{}) Data
NewData returns a read-only Slice that contains the encoding of data.
type Decodable ¶
type Decodable interface { // Decode decodes this object from the decoder. Decode(*Decoder) }
Decodable is the interface implemented by types that can decode themselves from an encoder.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder provides methods to read primitives from a binary.Reader, respecting a given MemoryLayout. Decoder will automatically handle alignment and types sizes.
func NewDecoder ¶
func NewDecoder(r binary.Reader, m *device.MemoryLayout) *Decoder
NewDecoder constructs and returns a new Decoder that reads from r using the memory layout m.
func (*Decoder) MemoryLayout ¶
func (d *Decoder) MemoryLayout() *device.MemoryLayout
MemoryLayout returns the MemoryLayout used by the decoder.
func (*Decoder) Offset ¶
Offset returns the byte offset of the reader from the initial Decoder creation.
type Encodable ¶
type Encodable interface { // Encode encodes this object to the encoder. Encode(*Encoder) }
Encodable is the interface implemented by types that can encode themselves to an encoder.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder provides methods to write primitives to a binary.Writer, respecting a given MemoryLayout. Encoder will automatically handle alignment and types sizes.
func NewEncoder ¶
func NewEncoder(w binary.Writer, m *device.MemoryLayout) *Encoder
NewEncoder constructs and returns a new Encoder that writes to w using the memory layout m.
func (*Encoder) MemoryLayout ¶
func (e *Encoder) MemoryLayout() *device.MemoryLayout
MemoryLayout returns the MemoryLayout used by the encoder.
type IntTy ¶
type IntTy interface {
IsInt()
}
IntTy is the interface implemented by types that should be treated as int type.
type Pointer ¶
type Pointer interface { ReflectPointer // IsNullptr returns true if the address is 0. IsNullptr() bool // Address returns the pointer's memory address. Address() uint64 // Offset returns the pointer offset by n bytes. Offset(n uint64) Pointer // ElementSize returns the size in bytes of the element type. ElementSize(m *device.MemoryLayout) uint64 // ElementType returns the type of the pointee. ElementType() reflect.Type // ISlice returns a new Slice of elements based from this pointer using // start and end indices. ISlice(start, end uint64, m *device.MemoryLayout) Slice }
Pointer is the type representing a memory pointer.
type Pool ¶
type Pool struct { OnRead func(rng Range, root uint64, t uint64, api id.ID) OnWrite func(rng Range, root uint64, t uint64, api id.ID) // contains filtered or unexported fields }
Pool represents an unbounded and isolated memory space. Pool can be used to represent the application address space, or hidden GPU Pool.
Pool can be sliced into smaller regions which can be read or written to. All writes to Pool or its slices do not actually perform binary data copies, but instead all writes are stored as lightweight records. Only when a Pool slice has Get called will any resolving, loading or copying of binary data occur.
OnRead and OnWrite functions take 3 parameters. The first is the range of memory. The second is the root of the read.
that is, the pointer from which the range was derived. For example: uint32_t* foo; foo[2]; Range(Base: foo+2, Size 4), Root foo Last is the service.type ID of the observations. This will always be a slice at this point.
func (*Pool) Strlen ¶
Strlen returns the run length of bytes starting from ptr before a 0 byte is reached.
type Pools ¶
Pools contains a collection of Pools identified by PoolIDs.
func (*Pools) ApplicationPool ¶
ApplicationPool returns the application memory pool.
func (*Pools) NextPoolID ¶
NextPoolID returns the next free pool ID (but does not assign it). All existing pools in the set have pool ID which is less then this value.
func (*Pools) SetOnCreate ¶
SetOnCreate sets the OnCreate callback and invokes it for every pool already created.
type Range ¶
type Range struct { Base uint64 // The address of the first byte in the memory range. Size uint64 // The size in bytes of the memory range. }
Range represents a region of memory.
func Store ¶
func Store(ctx context.Context, l *device.MemoryLayout, at Pointer, v ...interface{}) (Range, id.ID)
Store encodes and stores the value v to the database d, returning the memory range and new resource identifier. Data can be used to as a helper to AddRead and AddWrite methods on commands.
func (Range) Intersect ¶
Intersect returns the range that is common between this Range and other. If the two memory ranges do not intersect, then this function panics.
type RangeList ¶
type RangeList []Range
func (*RangeList) GetSpan ¶
GetSpan returns the span of the range with the specified index in the RangeList.
func (*RangeList) New ¶
New replaces the range of the span with the specified index in the RangeList.
type ReflectPointer ¶
type ReflectPointer interface {
APointer()
}
ReflectPointer is a helper interface, if you want your pointer to be reflected then it must ALSO implement this interface. Since reflection is slow having a much smaller interface to check is significantly better We name this APointer since reflect.Implements checks functions in alphabetical order, meaning this should get hit first (or close to).
type Size ¶
type Size uint64
Size is a size_t type.
func (Size) IsMemorySize ¶
func (Size) IsMemorySize()
IsMemorySize is a dummy function to make Size implement SizeTy interface
type SizeTy ¶
type SizeTy interface {
IsMemorySize()
}
SizeTy is the interface implemented by types that should be treated as size_t type.
type SizedTy ¶
type SizedTy interface { // Size returns the size of the type in bytes. TypeSize(*device.MemoryLayout) uint64 }
SizedTy is the interface implemented by types that can calculate their size.
type Slice ¶
type Slice interface { // Root returns the original pointer this slice derives from. Root() uint64 // Base returns the address of first element. Base() uint64 // Size returns the size of the slice in bytes. Size() uint64 // Count returns the number of elements in the slice. Count() uint64 // Pool returns the the pool identifier. Pool() PoolID // ElementType returns the reflect.Type of the elements in the slice. ElementType() reflect.Type // ISlice returns a sub-slice from this slice using start and end indices. ISlice(start, end uint64) Slice }
Slice is the interface implemented by types that represent a slice on a memory pool.