github.com/primecitizens/pcz/std@v0.2.1/builtin/go/defer.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 // 4 // Copyright 2009 The Go Authors. All rights reserved. 5 // Use of this source code is governed by a BSD-style 6 // license that can be found in the LICENSE file. 7 8 package stdgo 9 10 import ( 11 "unsafe" 12 ) 13 14 // A Defer holds an entry on the list of deferred calls. 15 // If you add a field here, add code to clear it in deferProcStack. 16 // This struct must match the code in cmd/compile/internal/ssagen/ssa.go:deferstruct 17 // and cmd/compile/internal/ssagen/ssa.go:(*state).call. 18 // Some defers will be allocated on the stack and some on the heap. 19 // All defers are logically part of the stack, so write barriers to 20 // initialize them are not required. All defers must be manually scanned, 21 // and for heap defers, marked. 22 // 23 // See $GOROOT/src/runtime/runtime2.go#type:_defer 24 type Defer struct { 25 Started bool 26 Heap bool 27 // OpenDefer indicates that this _defer is for a frame with open-coded 28 // defers. We have only one defer record for the entire frame (which may 29 // currently have 0, 1, or more defers active). 30 OpenDefer bool 31 SP uintptr // sp at time of defer 32 PC uintptr // pc at time of defer 33 Fn func() // can be nil for open-coded defers 34 Panic *Panic // panic that is running defer 35 Link *Defer // next defer on G; can point to either heap or stack! 36 37 // If openDefer is true, the fields below record values about the stack 38 // frame and associated function that has the open-coded defer(s). sp 39 // above will be the sp for the frame, and pc will be address of the 40 // deferreturn call in the function. 41 FuncData unsafe.Pointer // funcdata for the function associated with the frame 42 Varp uintptr // value of varp for the stack frame 43 // FramePC is the current pc associated with the stack frame. Together, 44 // with sp above (which is the sp associated with the stack frame), 45 // FramePC/sp can be used as pc/sp pair to continue a stack trace via 46 // gentraceback(). 47 FramePC uintptr 48 }