os

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package os contains GOOS-specific constants.

Index

Constants

View Source
const (
	// HeapAddrBits is the number of bits in a heap address. On
	// amd64, addresses are sign-extended beyond HeapAddrBits. On
	// other arches, they are zero-extended.
	//
	// On most 64-bit platforms, we limit this to 48 bits based on a
	// combination of hardware and OS limitations.
	//
	// amd64 hardware limits addresses to 48 bits, sign-extended
	// to 64 bits. Addresses where the top 16 bits are not either
	// all 0 or all 1 are "non-canonical" and invalid. Because of
	// these "negative" addresses, we offset addresses by 1<<47
	// (arenaBaseOffset) on amd64 before computing indexes into
	// the heap arenas index. In 2017, amd64 hardware added
	// support for 57 bit addresses; however, currently only Linux
	// supports this extension and the kernel will never choose an
	// address above 1<<47 unless mmap is called with a hint
	// address above 1<<47 (which we never do).
	//
	// arm64 hardware (as of ARMv8) limits user addresses to 48
	// bits, in the range [0, 1<<48).
	//
	// ppc64, mips64, and s390x support arbitrary 64 bit addresses
	// in hardware. On Linux, Go leans on stricter OS limits. Based
	// on Linux's processor.h, the user address space is limited as
	// follows on 64-bit architectures:
	//
	// Architecture  Name              Maximum Value (exclusive)
	// ---------------------------------------------------------------------
	// amd64         TASK_SIZE_MAX     0x007ffffffff000 (47 bit addresses)
	// arm64         TASK_SIZE_64      0x01000000000000 (48 bit addresses)
	// ppc64{,le}    TASK_SIZE_USER64  0x00400000000000 (46 bit addresses)
	// mips64{,le}   TASK_SIZE64       0x00010000000000 (40 bit addresses)
	// s390x         TASK_SIZE         1<<64 (64 bit addresses)
	//
	// These limits may increase over time, but are currently at
	// most 48 bits except on s390x. On all architectures, Linux
	// starts placing mmap'd regions at addresses that are
	// significantly below 48 bits, so even if it's possible to
	// exceed Go's 48 bit limit, it's extremely unlikely in
	// practice.
	//
	// On 32-bit platforms, we accept the full 32-bit address
	// space because doing so is cheap.
	// mips32 only has access to the low 2GB of virtual memory, so
	// we further limit it to 31 bits.
	//
	// On ios/arm64, although 64-bit pointers are presumably
	// available, pointers are truncated to 33 bits in iOS <14.
	// Furthermore, only the top 4 GiB of the address space are
	// actually available to the application. In iOS >=14, more
	// of the address space is available, and the OS can now
	// provide addresses outside of those 33 bits. Pick 40 bits
	// as a reasonable balance between address space usage by the
	// page allocator, and flexibility for what mmap'd regions
	// we'll accept for the heap. We can't just move to the full
	// 48 bits because this uses too much address space for older
	// iOS versions.
	// TODO(mknyszek): Once iOS <14 is deprecated, promote ios/arm64
	// to a 48-bit address space like every other arm64 platform.
	//
	// WebAssembly currently has a limit of 4GB linear memory.
	HeapAddrBits = (arch.Is64bit*(1-arch.IsWasm)*(1-IsIos*arch.IsArm64))*48 +
		(1-arch.Is64bit+arch.IsWasm)*(32-(arch.IsMips+arch.IsMipsle)) +
		40*IsIos*arch.IsArm64

	// MaxAlloc is the maximum size of an allocation. On 64-bit,
	// it's theoretically possible to allocate 1<<heapAddrBits bytes. On
	// 32-bit, however, this is one less than 1<<32 because the
	// number of bytes in the address space doesn't actually fit
	// in a uintptr.
	MaxAlloc = (1 << HeapAddrBits) - (1-arch.Is64bit)*1

	// HeapArenaBytes is the size of a heap arena. The heap
	// consists of mappings of size HeapArenaBytes, aligned to
	// HeapArenaBytes. The initial heap mapping is one arena.
	//
	// This is currently 64MB on 64-bit non-Windows and 4MB on
	// 32-bit and on Windows. We use smaller arenas on Windows
	// because all committed memory is charged to the process,
	// even if it's not touched. Hence, for processes with small
	// heaps, the mapped arena space needs to be commensurate.
	// This is particularly important with the race detector,
	// since it significantly amplifies the cost of committed
	// memory.
	HeapArenaBytes = 1 << LogHeapArenaBytes

	HeapArenaWords = HeapArenaBytes / arch.PtrSize

	// LogHeapArenaBytes is log_2 of heapArenaBytes. For clarity,
	// prefer using heapArenaBytes where possible (we need the
	// constant to compute some other constants).
	LogHeapArenaBytes = (6+20)*(arch.Is64bit*(1-IsWindows)*(1-arch.IsWasm)*(1-IsIos*arch.IsArm64)) +
		(2+20)*(arch.Is64bit*IsWindows) +
		(2+20)*(1-arch.Is64bit) +
		(2+20)*arch.IsWasm +
		(2+20)*IsIos*arch.IsArm64

	// HeapArenaBitmapWords is the size of each heap arena's bitmap in uintptrs.
	HeapArenaBitmapWords = HeapArenaWords / (8 * arch.PtrSize)
)

constants found from $GOROOT/src/runtime/malloc.go

View Source
const GOOS = `linux`
View Source
const IsAix = 0
View Source
const IsAndroid = 0
View Source
const IsDarwin = 0
View Source
const IsDragonfly = 0
View Source
const IsFreebsd = 0
View Source
const IsHurd = 0
View Source
const IsIllumos = 0
View Source
const IsIos = 0
View Source
const IsJs = 0
View Source
const IsLinux = 1
View Source
const IsNacl = 0
View Source
const IsNetbsd = 0
View Source
const IsOpenbsd = 0
View Source
const IsPlan9 = 0
View Source
const IsSolaris = 0
View Source
const IsUnix = true
View Source
const IsWasip1 = 0
View Source
const IsWindows = 0
View Source
const IsZos = 0

Variables

This section is empty.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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