hostarch

package
v0.0.0-...-ba09d25 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2021 License: Apache-2.0, MIT Imports: 6 Imported by: 0

Documentation

Overview

Package hostarch contains host arch address operations for user memory.

Index

Constants

View Source
const (
	// PageSize is the system page size.
	PageSize = 1 << PageShift

	// HugePageSize is the system huge page size.
	HugePageSize = 1 << HugePageShift

	// PageShift is the binary log of the system page size.
	PageShift = 12

	// HugePageShift is the binary log of the system huge page size.
	HugePageShift = 21
)

Variables

View Source
var (
	NoAccess  = AccessType{}
	Read      = AccessType{Read: true}
	Write     = AccessType{Write: true}
	Execute   = AccessType{Execute: true}
	ReadWrite = AccessType{Read: true, Write: true}
	AnyAccess = AccessType{Read: true, Write: true, Execute: true}
)

Convenient access types.

View Source
var (
	// ByteOrder is the native byte order (little endian).
	ByteOrder = binary.LittleEndian
)

Functions

func PageRoundDown

func PageRoundDown(x uint64) uint64

PageRoundDown returns x rounded down to the nearest page boundary.

func PageRoundUp

func PageRoundUp(x uint64) (addr uint64, ok bool)

PageRoundUp returns x rounded up to the nearest page boundary. ok is true iff rounding up did not wrap around.

Types

type AccessType

type AccessType struct {
	// Read is read access.
	Read bool

	// Write is write access.
	Write bool

	// Execute is executable access.
	Execute bool
}

AccessType specifies memory access types. This is used for setting mapping permissions, as well as communicating faults.

+stateify savable

func (AccessType) Any

func (a AccessType) Any() bool

Any returns true iff at least one of Read, Write or Execute is true.

func (AccessType) Effective

func (a AccessType) Effective() AccessType

Effective returns the set of effective access types allowed by a, even if some types are not explicitly allowed.

func (AccessType) Intersect

func (a AccessType) Intersect(other AccessType) AccessType

Intersect returns the access types set in both a and other.

func (AccessType) Prot

func (a AccessType) Prot() int

Prot returns the system prot (unix.PROT_READ, etc.) for this access.

func (AccessType) String

func (a AccessType) String() string

String returns a pretty representation of access. This looks like the familiar r-x, rw-, etc. and can be relied on as such.

func (AccessType) SupersetOf

func (a AccessType) SupersetOf(other AccessType) bool

SupersetOf returns true iff the access types in a are a superset of the access types in other.

func (AccessType) Union

func (a AccessType) Union(other AccessType) AccessType

Union returns the access types set in either a or other.

type Addr

type Addr uintptr

Addr represents a generic virtual address.

+stateify savable

func (Addr) AddLength

func (v Addr) AddLength(length uint64) (end Addr, ok bool)

AddLength adds the given length to start and returns the result. ok is true iff adding the length did not overflow the range of Addr.

Note: This function is usually used to get the end of an address range defined by its start address and length. Since the resulting end is exclusive, end == 0 is technically valid, and corresponds to a range that extends to the end of the address space, but ok will be false. This isn't expected to ever come up in practice.

func (Addr) HugeRoundDown

func (v Addr) HugeRoundDown() Addr

HugeRoundDown returns the address rounded down to the nearest huge page boundary.

func (Addr) HugeRoundUp

func (v Addr) HugeRoundUp() (addr Addr, ok bool)

HugeRoundUp returns the address rounded up to the nearest huge page boundary. ok is true iff rounding up did not wrap around.

func (Addr) IsPageAligned

func (v Addr) IsPageAligned() bool

IsPageAligned returns true if v.PageOffset() == 0.

func (Addr) MustRoundUp

func (v Addr) MustRoundUp() Addr

MustRoundUp is equivalent to RoundUp, but panics if rounding up wraps around.

func (Addr) PageOffset

func (v Addr) PageOffset() uint64

PageOffset returns the offset of v into the current page.

func (Addr) RoundDown

func (v Addr) RoundDown() Addr

RoundDown returns the address rounded down to the nearest page boundary.

func (Addr) RoundUp

func (v Addr) RoundUp() (addr Addr, ok bool)

RoundUp returns the address rounded up to the nearest page boundary. ok is true iff rounding up did not wrap around.

func (Addr) ToRange

func (v Addr) ToRange(length uint64) (AddrRange, bool)

ToRange returns [v, v+length).

type AddrRangeSeq

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

An AddrRangeSeq represents a sequence of AddrRanges.

AddrRangeSeqs are immutable and may be copied by value. The zero value of AddrRangeSeq represents an empty sequence.

An AddrRangeSeq may contain AddrRanges with a length of 0. This is necessary since zero-length AddrRanges are significant to MM bounds checks.

func AddrRangeSeqFromSlice

func AddrRangeSeqFromSlice(slice []AddrRange) AddrRangeSeq

AddrRangeSeqFromSlice returns an AddrRangeSeq representing all AddrRanges in slice.

Whether the returned AddrRangeSeq shares memory with slice is unspecified; clients should avoid mutating slices passed to AddrRangeSeqFromSlice.

Preconditions: The combined length of all AddrRanges in slice <= math.MaxInt64.

func AddrRangeSeqOf

func AddrRangeSeqOf(ar AddrRange) AddrRangeSeq

AddrRangeSeqOf returns an AddrRangeSeq representing the single AddrRange ar.

func (AddrRangeSeq) DropFirst

func (ars AddrRangeSeq) DropFirst(n int) AddrRangeSeq

DropFirst returns an AddrRangeSeq equivalent to ars, but with the first n bytes omitted. If n > ars.NumBytes(), DropFirst returns an empty AddrRangeSeq.

If !ars.IsEmpty() and ars.Head().Length() == 0, DropFirst will always omit at least ars.Head(), even if n == 0. This guarantees that the basic pattern of:

for !ars.IsEmpty() {
  n, err = doIOWith(ars.Head())
  if err != nil {
    return err
  }
  ars = ars.DropFirst(n)
}

works even in the presence of zero-length AddrRanges.

Preconditions: n >= 0.

func (AddrRangeSeq) DropFirst64

func (ars AddrRangeSeq) DropFirst64(n int64) AddrRangeSeq

DropFirst64 is equivalent to DropFirst but takes an int64.

func (AddrRangeSeq) Head

func (ars AddrRangeSeq) Head() AddrRange

Head returns the first AddrRange in ars.

Preconditions: !ars.IsEmpty().

func (AddrRangeSeq) IsEmpty

func (ars AddrRangeSeq) IsEmpty() bool

IsEmpty returns true if ars.NumRanges() == 0.

Note that since AddrRangeSeq may contain AddrRanges with a length of zero, an AddrRange representing 0 bytes (AddrRangeSeq.NumBytes() == 0) is not necessarily empty.

func (AddrRangeSeq) NumBytes

func (ars AddrRangeSeq) NumBytes() int64

NumBytes returns the number of bytes represented by ars.

func (AddrRangeSeq) NumRanges

func (ars AddrRangeSeq) NumRanges() int

NumRanges returns the number of AddrRanges in ars.

func (AddrRangeSeq) String

func (ars AddrRangeSeq) String() string

String implements fmt.Stringer.String.

func (AddrRangeSeq) Tail

func (ars AddrRangeSeq) Tail() AddrRangeSeq

Tail returns an AddrRangeSeq consisting of all AddrRanges in ars after the first.

Preconditions: !ars.IsEmpty().

func (AddrRangeSeq) TakeFirst

func (ars AddrRangeSeq) TakeFirst(n int) AddrRangeSeq

TakeFirst returns an AddrRangeSeq equivalent to ars, but iterating at most n bytes. TakeFirst never removes AddrRanges from ars; AddrRanges beyond the first n bytes are reduced to a length of zero, but will still be iterated.

Preconditions: n >= 0.

func (AddrRangeSeq) TakeFirst64

func (ars AddrRangeSeq) TakeFirst64(n int64) AddrRangeSeq

TakeFirst64 is equivalent to TakeFirst but takes an int64.

Jump to

Keyboard shortcuts

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