github.com/primecitizens/pcz/std@v0.2.1/core/stack/stack.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 // Package stack provides low-level access to current stack space 5 package stack 6 7 import ( 8 stdgo "github.com/primecitizens/pcz/std/builtin/go" 9 "github.com/primecitizens/pcz/std/core/abi" 10 "github.com/primecitizens/pcz/std/core/arch" 11 "github.com/primecitizens/pcz/std/core/os" 12 "github.com/primecitizens/pcz/std/core/race" 13 ) 14 15 type Stack = stdgo.Stack 16 17 const ( 18 // AIX requires a larger stack for syscalls. 19 // The race build also needs more stack. See issue 54291. 20 // 21 // This arithmetic must match that in 22 // $GOROOT/cmd/internal/objabi/stack.go:stackGuardMultiplier. 23 StackGuardMultiplier = 1 + os.IsAix + race.IsRace 24 25 // StackSystem is a number of additional bytes to add 26 // to each stack below the usual guard area for OS-specific 27 // purposes like signal handling. Used on Windows, Plan 9, 28 // and iOS because they do not use a separate stack. 29 StackSystem = os.IsWindows*512*arch.PtrSize + 30 os.IsPlan9*512 + 31 os.IsIos*arch.IsArm64*1024 32 33 // The minimum size of stack used by Go code 34 stackMin = 2048 35 36 // The minimum stack size to allocate. 37 // The hackery here rounds fixedStack0 up to a power of 2. 38 fixedStack0 = stackMin + StackSystem 39 fixedStack1 = fixedStack0 - 1 40 fixedStack2 = fixedStack1 | (fixedStack1 >> 1) 41 fixedStack3 = fixedStack2 | (fixedStack2 >> 2) 42 fixedStack4 = fixedStack3 | (fixedStack3 >> 4) 43 fixedStack5 = fixedStack4 | (fixedStack4 >> 8) 44 fixedStack6 = fixedStack5 | (fixedStack5 >> 16) 45 fixedStack = fixedStack6 + 1 46 47 // StackNosplit is the maximum number of bytes that a chain of NOSPLIT 48 // functions can use. 49 // 50 // This arithmetic must match that in cmd/internal/objabi/stack.go:StackNosplit. 51 StackNosplit = abi.StackNosplitBase * StackGuardMultiplier 52 53 // The stack guard is a pointer this many bytes above the 54 // bottom of the stack. 55 // 56 // The guard leaves enough room for a stackNosplit chain of NOSPLIT calls 57 // plus one stackSmall frame plus stackSystem bytes for the OS. 58 // 59 // This arithmetic must match that in cmd/internal/objabi/stack.go:StackLimit. 60 StackGuard = StackNosplit + StackSystem + abi.StackSmall 61 ) 62 63 // GetSP returns the value of the stack pointer register on calling. 64 func GetSP() uintptr 65 66 //go:noescape 67 func SetSP(sp uintptr)