hostarch

package
v0.0.0-...-957f62e Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: Apache-2.0, MIT Imports: 7 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

	// 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
)
View Source
const (
	PageMask      = PageSize - 1
	HugePageMask  = HugePageSize - 1
	CacheLineMask = CacheLineSize - 1
)

Masks often used when working with alignment in constant expressions.

Variables

View Source
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.

View Source
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(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

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 is equivalent to function HugePageRoundDown.

func (Addr) HugeRoundUp

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

HugeRoundUp is equivalent to function HugePageRoundUp.

func (Addr) IsPageAligned

func (v Addr) IsPageAligned() bool

IsPageAligned is equivalent to function IsPageAligned.

func (Addr) MustRoundUp

func (v Addr) MustRoundUp() Addr

MustRoundUp is equivalent to function MustPageRoundUp.

func (Addr) PageOffset

func (v Addr) PageOffset() uint64

PageOffset is equivalent to function PageOffset, except that it casts the result to uint64.

func (Addr) RoundDown

func (v Addr) RoundDown() Addr

RoundDown is equivalent to function PageRoundDown.

func (Addr) RoundUp

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

RoundUp is equivalent to function PageRoundUp.

func (*Addr) StateFields

func (v *Addr) StateFields() []string

func (*Addr) StateTypeName

func (v *Addr) StateTypeName() string

func (Addr) ToRange

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

ToRange returns [v, v+length).

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

func (r AddrRange) CanSplitAt(x Addr) bool

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) Contains

func (r AddrRange) Contains(x Addr) bool

Contains returns true if r contains x.

func (AddrRange) Intersect

func (r AddrRange) Intersect(r2 AddrRange) AddrRange

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) IsPageAligned

func (ar AddrRange) IsPageAligned() bool

IsPageAligned returns true if ar.Start.IsPageAligned() and ar.End.IsPageAligned().

func (AddrRange) IsSupersetOf

func (r AddrRange) IsSupersetOf(r2 AddrRange) bool

IsSupersetOf returns true if r is a superset of r2; that is, the range r2 is contained within r.

func (AddrRange) Length

func (r AddrRange) Length() Addr

Length returns the length of the range.

func (AddrRange) Overlaps

func (r AddrRange) Overlaps(r2 AddrRange) bool

Overlaps returns true if r and r2 overlap.

func (*AddrRange) StateFields

func (r *AddrRange) StateFields() []string

func (*AddrRange) StateLoad

func (r *AddrRange) StateLoad(stateSourceObject state.Source)

+checklocksignore

func (*AddrRange) StateSave

func (r *AddrRange) StateSave(stateSinkObject state.Sink)

+checklocksignore

func (*AddrRange) StateTypeName

func (r *AddrRange) StateTypeName() string

func (AddrRange) String

func (ar AddrRange) String() string

String implements fmt.Stringer.String.

func (AddrRange) WellFormed

func (r AddrRange) WellFormed() bool

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.

Jump to

Keyboard shortcuts

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