Documentation ¶
Overview ¶
Package hostarch contains host arch address operations for user memory.
Index ¶
- Constants
- Variables
- func PageRoundDown(x uint64) uint64
- func PageRoundUp(x uint64) (addr uint64, ok bool)
- type AccessType
- func (a AccessType) Any() bool
- func (a AccessType) Effective() AccessType
- func (a AccessType) Intersect(other AccessType) AccessType
- func (a AccessType) Prot() int
- func (a AccessType) String() string
- func (a AccessType) SupersetOf(other AccessType) bool
- func (a AccessType) Union(other AccessType) AccessType
- type Addr
- func (v Addr) AddLength(length uint64) (end Addr, ok bool)
- func (v Addr) HugeRoundDown() Addr
- func (v Addr) HugeRoundUp() (addr Addr, ok bool)
- func (v Addr) IsPageAligned() bool
- func (v Addr) MustRoundUp() Addr
- func (v Addr) PageOffset() uint64
- func (v Addr) RoundDown() Addr
- func (v Addr) RoundUp() (addr Addr, ok bool)
- func (v Addr) ToRange(length uint64) (AddrRange, bool)
- type AddrRangeSeq
- func (ars AddrRangeSeq) DropFirst(n int) AddrRangeSeq
- func (ars AddrRangeSeq) DropFirst64(n int64) AddrRangeSeq
- func (ars AddrRangeSeq) Head() AddrRange
- func (ars AddrRangeSeq) IsEmpty() bool
- func (ars AddrRangeSeq) NumBytes() int64
- func (ars AddrRangeSeq) NumRanges() int
- func (ars AddrRangeSeq) String() string
- func (ars AddrRangeSeq) Tail() AddrRangeSeq
- func (ars AddrRangeSeq) TakeFirst(n int) AddrRangeSeq
- func (ars AddrRangeSeq) TakeFirst64(n int64) AddrRangeSeq
Constants ¶
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 ¶
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.
var ( // ByteOrder is the native byte order (little endian). ByteOrder = binary.LittleEndian )
Functions ¶
func PageRoundDown ¶
PageRoundDown returns x rounded down to the nearest page boundary.
func PageRoundUp ¶
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 ¶
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 ¶
HugeRoundDown returns the address rounded down to the nearest huge page boundary.
func (Addr) HugeRoundUp ¶
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 ¶
IsPageAligned returns true if v.PageOffset() == 0.
func (Addr) MustRoundUp ¶
MustRoundUp is equivalent to RoundUp, but panics if rounding up wraps around.
func (Addr) PageOffset ¶
PageOffset returns the offset of v into the current page.
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.