hostarch

package
v0.0.0-...-c88ffa3 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: Apache-2.0, MIT Imports: 6 Imported by: 175

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

func (v Addr) HugePageOffset() uint64

HugePageOffset is equivalent to function HugePageOffset.

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

func (v Addr) IsHugePageAligned() bool

IsHugePageAligned is equivalent to function IsHugePageAligned.

func (Addr) IsPageAligned

func (v Addr) IsPageAligned() bool

IsPageAligned is equivalent to function IsPageAligned.

func (Addr) MustHugeRoundUp

func (v Addr) MustHugeRoundUp() Addr

MustHugeRoundUp is equivalent to function MustHugePageRoundUp.

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