mem

package
v0.0.0-...-9ad5c47 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PermRead    Permissions = 0b001
	PermWrite   Permissions = 0b010
	PermExecute Permissions = 0b100

	PermReadWrite        = PermRead | PermWrite
	PermReadExecute      = PermRead | PermExecute
	PermReadWriteExecute = PermRead | PermWrite | PermExecute
)

Functions

This section is empty.

Types

type Mem

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

Mem is a memory management system that acts as a MMU. Mem translates virtual to physical addresses and provide an interface to read and write to that virtual memory space

func NewMem

func NewMem(allocator allocator.Allocator) *Mem

Creates a new memory management

func NewMemFromMemory

func NewMemFromMemory() *Mem

Creates a new memory management that uses MemoryAllocator

func (*Mem) Alloc

func (m *Mem) Alloc(addr uint64, size int, permissions Permissions) error

Allocates a new memory block and map it to a virtual address This method uses the underlying Allocator to allocated memory blocks

func (*Mem) Close

func (m *Mem) Close() error

Closes the memory manager, thus freeing all allocated resources

func (*Mem) Free

func (m *Mem) Free(address uint64) error

Free a memory block and from both the underlying Allocator and the memory manager. address must be the address used in the Alloc method.

func (*Mem) Raw

func (m *Mem) Raw() *MemRW

Read operations using execute permission

func (*Mem) ReadAt

func (m *Mem) ReadAt(p []byte, addr int64) (int, error)

Reads from a specific virtual address with read permissions. Returns SegmentationFaultError if trying to access unallocated or memory without permission

func (*Mem) Reader

func (m *Mem) Reader() io.ReaderAt

Read operations using read permission

func (*Mem) ReaderX

func (m *Mem) ReaderX() io.ReaderAt

Read operations using execute permission

func (*Mem) WriteAt

func (m *Mem) WriteAt(p []byte, addr int64) (int, error)

Writes to a specific virtual address. Returns SegmentationFaultError if trying to access unallocated or memory without permission

func (*Mem) Writer

func (m *Mem) Writer() io.WriterAt

Read operations using execute permission

type MemRW

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

MemRW is the gateway to all the memory operations with read/execute permissions it implements ReadAt

func (*MemRW) ReadAt

func (m *MemRW) ReadAt(p []byte, addr int64) (int, error)

Reads from a specific virtual address. Returns SegmentationFaultError if trying to access unallocated or memory without permission

func (*MemRW) WriteAt

func (m *MemRW) WriteAt(p []byte, addr int64) (int, error)

Writes to a specific virtual address. Returns SegmentationFaultError if trying to access unallocated or memory without permission

type Permissions

type Permissions int

Memory operation permissions Permissions can be joined via | (p := PermRead | PermWrite) Permissions can be checked via & (ok := p & PermWrite)

func (Permissions) Has

func (p Permissions) Has(permissions Permissions) bool

Check if this permissions has permissions

func (Permissions) String

func (p Permissions) String() string

type SegmentationFaultError

type SegmentationFaultError struct {
	Address           int64
	AccessPermissions Permissions
}

Represents a segmentation fault. Invalid access to a either an unallocated memory or memory segments with wrong permissions

func NewSegmentationFaultError

func NewSegmentationFaultError(address int64, permissions Permissions) *SegmentationFaultError

func (*SegmentationFaultError) Error

func (s *SegmentationFaultError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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