Movatterモバイル変換


[0]ホーム

URL:


sys

packagestandard library
go1.25.2Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2025 License:BSD-3-ClauseImports:2Imported by:0

Details

Repository

cs.opensource.google/go/go

Links

Documentation

Overview

package sys contains system- and configuration- and architecture-specificconstants used by the runtime.

Index

Constants

View Source
const DefaultPhysPageSize =goarch.DefaultPhysPageSize

DefaultPhysPageSize is the default physical page size.

View Source
const Int64Align =goarch.PtrSize

Int64Align is the required alignment for a 64-bit integer (4 on 32-bit systems, 8 on 64-bit).

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

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

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

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

View Source
var DITSupported =false

Functions

funcBswap32

func Bswap32(xuint32)uint32

Bswap32 returns its input with byte order reversed0x01020304 -> 0x04030201

funcBswap64

func Bswap64(xuint64)uint64

Bswap64 returns its input with byte order reversed0x0102030405060708 -> 0x0807060504030201

funcDITEnabled

func DITEnabled()bool

funcDisableDIT

func DisableDIT()

funcEnableDIT

func EnableDIT()bool

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

func LeadingZeros64(xuint64)int

LeadingZeros64 returns the number of leading zero bits in x; the result is 64 for x == 0.

funcLeadingZeros8

func LeadingZeros8(xuint8)int

LeadingZeros8 returns the number of leading zero bits in x; the result is 8 for x == 0.

funcLen64

func Len64(xuint64) (nint)

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

func Len8(xuint8)int

Len8 returns the minimum number of bits required to represent x; the result is 0 for x == 0.

funcOnesCount64

func OnesCount64(xuint64)int

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

func TrailingZeros32(xuint32)int

TrailingZeros32 returns the number of trailing zero bits in x; the result is 32 for x == 0.

funcTrailingZeros64

func TrailingZeros64(xuint64)int

TrailingZeros64 returns the number of trailing zero bits in x; the result is 64 for x == 0.

funcTrailingZeros8

func TrailingZeros8(xuint8)int

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.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp