sys
packagestandard libraryThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
package sys contains system- and configuration- and architecture-specificconstants used by the runtime.
Index¶
- Constants
- Variables
- func Bswap32(x uint32) uint32
- func Bswap64(x uint64) uint64
- func DITEnabled() bool
- func DisableDIT()
- func EnableDIT() bool
- func GetCallerPC() uintptr
- func GetCallerSP() uintptr
- func GetClosurePtr() uintptr
- func LeadingZeros64(x uint64) int
- func LeadingZeros8(x uint8) int
- func Len64(x uint64) (n int)
- func Len8(x uint8) int
- func OnesCount64(x uint64) int
- func Prefetch(addr uintptr)
- func PrefetchStreamed(addr uintptr)
- func TrailingZeros32(x uint32) int
- func TrailingZeros64(x uint64) int
- func TrailingZeros8(x uint8) int
- type NotInHeap
Constants¶
const DefaultPhysPageSize =goarch.DefaultPhysPageSize
DefaultPhysPageSize is the default physical page size.
const Int64Align =goarch.PtrSize
Int64Align is the required alignment for a 64-bit integer (4 on 32-bit systems, 8 on 64-bit).
const MinFrameSize =goarch.MinFrameSize
MinFrameSize is the size of the system-reserved words at the bottomof a frame (just above the architectural stack pointer).It is zero on x86 and PtrSize on most non-x86 (LR-based) systems.On PowerPC it is larger, to cover three more reserved words:the compiler word, the link editor word, and the TOC save word.
const PCQuantum =goarch.PCQuantum
PCQuantum is the minimal unit for a program counter (1 on x86, 4 on most other systems).The various PC tables record PC deltas pre-divided by PCQuantum.
const StackAlign =goarch.StackAlign
StackAlign is the required alignment of the SP register.The stack must be at least word aligned, but some architectures require more.
const StackGuardMultiplier = 1 +goos.IsAix +goos.IsOpenbsd + isRace
AIX and OpenBSD require a larger stack for syscalls.The race build also needs more stack. See issue 54291.This arithmetic must match that in cmd/internal/objabi/stack.go:stackGuardMultiplier.
Variables¶
var DITSupported =false
Functions¶
funcBswap64¶
Bswap64 returns its input with byte order reversed0x0102030405060708 -> 0x0807060504030201
funcDITEnabled¶
func DITEnabled()bool
funcDisableDIT¶
func DisableDIT()
funcGetCallerPC¶
func GetCallerPC()uintptr
funcGetCallerSP¶
func GetCallerSP()uintptr
funcGetClosurePtr¶
func GetClosurePtr()uintptr
GetClosurePtr returns the pointer to the current closure.GetClosurePtr can only be used in an assignment statementat the entry of a function. Moreover, go:nosplit directivemust be specified at the declaration of caller function,so that the function prolog does not clobber the closure register.for example:
//go:nosplitfunc f(arg1, arg2, arg3 int) {dx := GetClosurePtr()}
The compiler rewrites calls to this function into instructions that fetch thepointer from a well-known register (DX on x86 architecture, etc.) directly.
WARNING: PGO-based devirtualization cannot detect that caller ofGetClosurePtr requires closure context, and thus must maintain a list ofthese functions, which is incmd/compile/internal/devirtualize/pgo.maybeDevirtualizeFunctionCall.
funcLeadingZeros64¶
LeadingZeros64 returns the number of leading zero bits in x; the result is 64 for x == 0.
funcLeadingZeros8¶
LeadingZeros8 returns the number of leading zero bits in x; the result is 8 for x == 0.
funcLen64¶
Len64 returns the minimum number of bits required to represent x; the result is 0 for x == 0.
nosplit because this is used in src/runtime/histogram.go, which make run in sensitive contexts.
funcLen8¶
Len8 returns the minimum number of bits required to represent x; the result is 0 for x == 0.
funcOnesCount64¶
OnesCount64 returns the number of one bits ("population count") in x.
funcPrefetch¶
func Prefetch(addruintptr)
Prefetch prefetches data from memory addr to cache
AMD64: Produce PREFETCHT0 instruction
ARM64: Produce PRFM instruction with PLDL1KEEP option
funcPrefetchStreamed¶
func PrefetchStreamed(addruintptr)
PrefetchStreamed prefetches data from memory addr, with a hint that this data is being streamed.That is, it is likely to be accessed very soon, but only once. If possible, this will avoid polluting the cache.
AMD64: Produce PREFETCHNTA instruction
ARM64: Produce PRFM instruction with PLDL1STRM option
funcTrailingZeros32¶
TrailingZeros32 returns the number of trailing zero bits in x; the result is 32 for x == 0.
funcTrailingZeros64¶
TrailingZeros64 returns the number of trailing zero bits in x; the result is 64 for x == 0.
funcTrailingZeros8¶
TrailingZeros8 returns the number of trailing zero bits in x; the result is 8 for x == 0.
Types¶
typeNotInHeap¶
type NotInHeap struct {// contains filtered or unexported fields}
NotInHeap is a type must never be allocated from the GC'd heap or on the stack,and is called not-in-heap.
Other types can embed NotInHeap to make it not-in-heap. Specifically, pointersto these types must always fail the `runtime.inheap` check. The type may be usedfor global variables, or for objects in unmanaged memory (e.g., allocated with`sysAlloc`, `persistentalloc`, `fixalloc`, or from a manually-managed span).
Specifically:
1. `new(T)`, `make([]T)`, `append([]T, ...)` and implicit heapallocation of T are disallowed. (Though implicit allocations aredisallowed in the runtime anyway.)
2. A pointer to a regular type (other than `unsafe.Pointer`) cannot beconverted to a pointer to a not-in-heap type, even if they have thesame underlying type.
3. Any type that containing a not-in-heap type is itself considered as not-in-heap.
- Structs and arrays are not-in-heap if their elements are not-in-heap.- Maps and channels contains no-in-heap types are disallowed.
4. Write barriers on pointers to not-in-heap types can be omitted.
The last point is the real benefit of NotInHeap. The runtime usesit for low-level internal structures to avoid memory barriers in thescheduler and the memory allocator where they are illegal or simplyinefficient. This mechanism is reasonably safe and does not compromisethe readability of the runtime.