Documentation ¶
Overview ¶
Package hostarch contains host arch address operations for user memory.
Index ¶
- Constants
- Variables
- func CacheLineRoundDown[T bytecount](x T) T
- func CacheLineRoundUp[T bytecount](x T) (val T, ok bool)
- func HugePageOffset[T hugebytecount](x T) T
- func HugePageRoundDown[T hugebytecount](x T) T
- func HugePageRoundUp[T hugebytecount](x T) (val T, ok bool)
- func IsHugePageAligned[T hugebytecount](x T) bool
- func IsPageAligned[T bytecount](x T) bool
- func MustHugePageRoundUp[T hugebytecount](x T) T
- func MustPageRoundUp[T bytecount](x T) T
- func PageOffset[T bytecount](x T) T
- func PageRoundDown[T bytecount](x T) T
- func PageRoundUp[T bytecount](x T) (val T, ok bool)
- func ToPagesRoundUp[T bytecount](x T) (T, 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) StateFields() []string
- func (a *AccessType) StateLoad(ctx context.Context, stateSourceObject state.Source)
- func (a *AccessType) StateSave(stateSinkObject state.Sink)
- func (a *AccessType) StateTypeName() string
- 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) HugePageOffset() uint64
- func (v Addr) HugeRoundDown() Addr
- func (v Addr) HugeRoundUp() (Addr, bool)
- func (v Addr) IsHugePageAligned() bool
- func (v Addr) IsPageAligned() bool
- func (v Addr) MustHugeRoundUp() Addr
- func (v Addr) MustRoundUp() Addr
- func (v Addr) PageOffset() uint64
- func (v Addr) RoundDown() Addr
- func (v Addr) RoundUp() (Addr, bool)
- func (v *Addr) StateFields() []string
- func (v *Addr) StateTypeName() string
- func (v Addr) ToRange(length uint64) (AddrRange, bool)
- type AddrRange
- func (r AddrRange) CanSplitAt(x Addr) bool
- func (r AddrRange) Contains(x Addr) bool
- func (r AddrRange) Intersect(r2 AddrRange) AddrRange
- func (ar AddrRange) IsHugePageAligned() bool
- func (ar AddrRange) IsPageAligned() bool
- func (r AddrRange) IsSupersetOf(r2 AddrRange) bool
- func (r AddrRange) Length() Addr
- func (r AddrRange) Overlaps(r2 AddrRange) bool
- func (r *AddrRange) StateFields() []string
- func (r *AddrRange) StateLoad(ctx context.Context, stateSourceObject state.Source)
- func (r *AddrRange) StateSave(stateSinkObject state.Sink)
- func (r *AddrRange) StateTypeName() string
- func (ar AddrRange) String() string
- func (r AddrRange) WellFormed() 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 // CacheLineSize is the size of the cache line. CacheLineSize = 1 << CacheLineShift // 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 // CacheLineShift is the binary log of the cache line size. CacheLineShift = 6 )
const ( PageMask = PageSize - 1 HugePageMask = HugePageSize - 1 CacheLineMask = CacheLineSize - 1 )
Masks often used when working with alignment in constant expressions.
Variables ¶
var ( NoAccess = AccessType{} Read = AccessType{Read: true} Write = AccessType{Write: true} Execute = AccessType{Execute: true} ReadWrite = AccessType{Read: true, Write: true} ReadExecute = AccessType{Read: true, Execute: 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 CacheLineRoundDown ¶
func CacheLineRoundDown[T bytecount](x T) T
CacheLineRoundDown returns the offset rounded down to the nearest multiple of CacheLineSize.
func CacheLineRoundUp ¶
func CacheLineRoundUp[T bytecount](x T) (val T, ok bool)
CacheLineRoundUp returns the offset rounded up to the nearest multiple of CacheLineSize. ok is true iff rounding up does not overflow the range of T.
func HugePageOffset ¶
func HugePageOffset[T hugebytecount](x T) T
HugePageOffset returns the offset of x into its containing page.
func HugePageRoundDown ¶
func HugePageRoundDown[T hugebytecount](x T) T
HugePageRoundDown returns x rounded down to the nearest multiple of HugePageSize.
func HugePageRoundUp ¶
func HugePageRoundUp[T hugebytecount](x T) (val T, ok bool)
HugePageRoundUp returns x rounded up to the nearest multiple of HugePageSize. ok is true iff rounding up does not overflow the range of T.
func IsHugePageAligned ¶
func IsHugePageAligned[T hugebytecount](x T) bool
IsHugePageAligned returns true if x is a multiple of HugePageSize.
func IsPageAligned ¶
func IsPageAligned[T bytecount](x T) bool
IsPageAligned returns true if x is a multiple of PageSize.
func MustHugePageRoundUp ¶
func MustHugePageRoundUp[T hugebytecount](x T) T
MustHugePageRoundUp is equivalent to HugePageRoundUp, but panics if rounding up overflows.
func MustPageRoundUp ¶
func MustPageRoundUp[T bytecount](x T) T
MustPageRoundUp is equivalent to PageRoundUp, but panics if rounding up overflows.
func PageOffset ¶
func PageOffset[T bytecount](x T) T
PageOffset returns the offset of x into its containing page.
func PageRoundDown ¶
func PageRoundDown[T bytecount](x T) T
PageRoundDown returns x rounded down to the nearest multiple of PageSize.
func PageRoundUp ¶
func PageRoundUp[T bytecount](x T) (val T, ok bool)
PageRoundUp returns x rounded up to the nearest multiple of PageSize. ok is true iff rounding up does not overflow the range of T.
func ToPagesRoundUp ¶
func ToPagesRoundUp[T bytecount](x T) (T, bool)
ToPagesRoundUp returns (the number of pages equal to x bytes rounded up, true). If rounding x up to a multiple of PageSize overflows the range of T, ToPagesRoundUp returns (unspecified, false).
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) StateFields ¶
func (a *AccessType) StateFields() []string
func (*AccessType) StateLoad ¶
func (a *AccessType) StateLoad(ctx context.Context, stateSourceObject state.Source)
+checklocksignore
func (*AccessType) StateSave ¶
func (a *AccessType) StateSave(stateSinkObject state.Sink)
+checklocksignore
func (*AccessType) StateTypeName ¶
func (a *AccessType) StateTypeName() string
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 an address in an unspecified address space.
+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) HugePageOffset ¶
HugePageOffset is equivalent to function HugePageOffset.
func (Addr) HugeRoundDown ¶
HugeRoundDown is equivalent to function HugePageRoundDown.
func (Addr) HugeRoundUp ¶
HugeRoundUp is equivalent to function HugePageRoundUp.
func (Addr) IsHugePageAligned ¶
IsHugePageAligned is equivalent to function IsHugePageAligned.
func (Addr) IsPageAligned ¶
IsPageAligned is equivalent to function IsPageAligned.
func (Addr) MustHugeRoundUp ¶
MustHugeRoundUp is equivalent to function MustHugePageRoundUp.
func (Addr) MustRoundUp ¶
MustRoundUp is equivalent to function MustPageRoundUp.
func (Addr) PageOffset ¶
PageOffset is equivalent to function PageOffset, except that it casts the result to uint64.
func (*Addr) StateFields ¶
func (*Addr) StateTypeName ¶
type AddrRange ¶
type AddrRange struct { // Start is the inclusive start of the range. Start Addr // End is the exclusive end of the range. End Addr }
A Range represents a contiguous range of T.
+stateify savable
func (AddrRange) CanSplitAt ¶
CanSplitAt returns true if it is legal to split a segment spanning the range r at x; that is, splitting at x would produce two ranges, both of which have non-zero length.
func (AddrRange) Intersect ¶
Intersect returns a range consisting of the intersection between r and r2. If r and r2 do not overlap, Intersect returns a range with unspecified bounds, but for which Length() == 0.
func (AddrRange) IsHugePageAligned ¶
IsHugePageAligned returns true if ar.Start.IsHugePageAligned() and ar.End.IsHugePageAligned().
func (AddrRange) IsPageAligned ¶
IsPageAligned returns true if ar.Start.IsPageAligned() and ar.End.IsPageAligned().
func (AddrRange) IsSupersetOf ¶
IsSupersetOf returns true if r is a superset of r2; that is, the range r2 is contained within r.
func (*AddrRange) StateFields ¶
func (*AddrRange) StateTypeName ¶
func (AddrRange) WellFormed ¶
WellFormed returns true if r.Start <= r.End. All other methods on a Range require that the Range is well-formed.
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.