github.com/zhiqiangxu/util@v0.0.0-20230112053021-0a7aee056cd5/hack_amd64.go (about) 1 //go:build amd64 2 // +build amd64 3 4 package util 5 6 func getg() *g 7 8 type stack struct { 9 lo uintptr 10 hi uintptr 11 } 12 type g struct { 13 // Stack parameters. 14 // stack describes the actual stack memory: [stack.lo, stack.hi). 15 // stackguard0 is the stack pointer compared in the Go stack growth prologue. 16 // It is stack.lo+StackGuard normally, but can be StackPreempt to trigger a preemption. 17 // stackguard1 is the stack pointer compared in the C stack growth prologue. 18 // It is stack.lo+StackGuard on g0 and gsignal stacks. 19 // It is ~0 on other goroutine stacks, to trigger a call to morestackc (and crash). 20 stack stack // offset known to runtime/cgo 21 } 22 23 // StackSize calculates current stack size 24 func StackSize() uintptr { 25 g := getg() 26 return g.stack.hi - g.stack.lo 27 }