github.com/mattn/go@v0.0.0-20171011075504-07f7db3ea99f/src/runtime/runtime2.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package runtime 6 7 import ( 8 "runtime/internal/atomic" 9 "runtime/internal/sys" 10 "unsafe" 11 ) 12 13 // defined constants 14 const ( 15 // G status 16 // 17 // Beyond indicating the general state of a G, the G status 18 // acts like a lock on the goroutine's stack (and hence its 19 // ability to execute user code). 20 // 21 // If you add to this list, add to the list 22 // of "okay during garbage collection" status 23 // in mgcmark.go too. 24 25 // _Gidle means this goroutine was just allocated and has not 26 // yet been initialized. 27 _Gidle = iota // 0 28 29 // _Grunnable means this goroutine is on a run queue. It is 30 // not currently executing user code. The stack is not owned. 31 _Grunnable // 1 32 33 // _Grunning means this goroutine may execute user code. The 34 // stack is owned by this goroutine. It is not on a run queue. 35 // It is assigned an M and a P. 36 _Grunning // 2 37 38 // _Gsyscall means this goroutine is executing a system call. 39 // It is not executing user code. The stack is owned by this 40 // goroutine. It is not on a run queue. It is assigned an M. 41 _Gsyscall // 3 42 43 // _Gwaiting means this goroutine is blocked in the runtime. 44 // It is not executing user code. It is not on a run queue, 45 // but should be recorded somewhere (e.g., a channel wait 46 // queue) so it can be ready()d when necessary. The stack is 47 // not owned *except* that a channel operation may read or 48 // write parts of the stack under the appropriate channel 49 // lock. Otherwise, it is not safe to access the stack after a 50 // goroutine enters _Gwaiting (e.g., it may get moved). 51 _Gwaiting // 4 52 53 // _Gmoribund_unused is currently unused, but hardcoded in gdb 54 // scripts. 55 _Gmoribund_unused // 5 56 57 // _Gdead means this goroutine is currently unused. It may be 58 // just exited, on a free list, or just being initialized. It 59 // is not executing user code. It may or may not have a stack 60 // allocated. The G and its stack (if any) are owned by the M 61 // that is exiting the G or that obtained the G from the free 62 // list. 63 _Gdead // 6 64 65 // _Genqueue_unused is currently unused. 66 _Genqueue_unused // 7 67 68 // _Gcopystack means this goroutine's stack is being moved. It 69 // is not executing user code and is not on a run queue. The 70 // stack is owned by the goroutine that put it in _Gcopystack. 71 _Gcopystack // 8 72 73 // _Gscan combined with one of the above states other than 74 // _Grunning indicates that GC is scanning the stack. The 75 // goroutine is not executing user code and the stack is owned 76 // by the goroutine that set the _Gscan bit. 77 // 78 // _Gscanrunning is different: it is used to briefly block 79 // state transitions while GC signals the G to scan its own 80 // stack. This is otherwise like _Grunning. 81 // 82 // atomicstatus&~Gscan gives the state the goroutine will 83 // return to when the scan completes. 84 _Gscan = 0x1000 85 _Gscanrunnable = _Gscan + _Grunnable // 0x1001 86 _Gscanrunning = _Gscan + _Grunning // 0x1002 87 _Gscansyscall = _Gscan + _Gsyscall // 0x1003 88 _Gscanwaiting = _Gscan + _Gwaiting // 0x1004 89 ) 90 91 const ( 92 // P status 93 _Pidle = iota 94 _Prunning // Only this P is allowed to change from _Prunning. 95 _Psyscall 96 _Pgcstop 97 _Pdead 98 ) 99 100 // Mutual exclusion locks. In the uncontended case, 101 // as fast as spin locks (just a few user-level instructions), 102 // but on the contention path they sleep in the kernel. 103 // A zeroed Mutex is unlocked (no need to initialize each lock). 104 type mutex struct { 105 // Futex-based impl treats it as uint32 key, 106 // while sema-based impl as M* waitm. 107 // Used to be a union, but unions break precise GC. 108 key uintptr 109 } 110 111 // sleep and wakeup on one-time events. 112 // before any calls to notesleep or notewakeup, 113 // must call noteclear to initialize the Note. 114 // then, exactly one thread can call notesleep 115 // and exactly one thread can call notewakeup (once). 116 // once notewakeup has been called, the notesleep 117 // will return. future notesleep will return immediately. 118 // subsequent noteclear must be called only after 119 // previous notesleep has returned, e.g. it's disallowed 120 // to call noteclear straight after notewakeup. 121 // 122 // notetsleep is like notesleep but wakes up after 123 // a given number of nanoseconds even if the event 124 // has not yet happened. if a goroutine uses notetsleep to 125 // wake up early, it must wait to call noteclear until it 126 // can be sure that no other goroutine is calling 127 // notewakeup. 128 // 129 // notesleep/notetsleep are generally called on g0, 130 // notetsleepg is similar to notetsleep but is called on user g. 131 type note struct { 132 // Futex-based impl treats it as uint32 key, 133 // while sema-based impl as M* waitm. 134 // Used to be a union, but unions break precise GC. 135 key uintptr 136 } 137 138 type funcval struct { 139 fn uintptr 140 // variable-size, fn-specific data here 141 } 142 143 type iface struct { 144 tab *itab 145 data unsafe.Pointer 146 } 147 148 type eface struct { 149 _type *_type 150 data unsafe.Pointer 151 } 152 153 func efaceOf(ep *interface{}) *eface { 154 return (*eface)(unsafe.Pointer(ep)) 155 } 156 157 // The guintptr, muintptr, and puintptr are all used to bypass write barriers. 158 // It is particularly important to avoid write barriers when the current P has 159 // been released, because the GC thinks the world is stopped, and an 160 // unexpected write barrier would not be synchronized with the GC, 161 // which can lead to a half-executed write barrier that has marked the object 162 // but not queued it. If the GC skips the object and completes before the 163 // queuing can occur, it will incorrectly free the object. 164 // 165 // We tried using special assignment functions invoked only when not 166 // holding a running P, but then some updates to a particular memory 167 // word went through write barriers and some did not. This breaks the 168 // write barrier shadow checking mode, and it is also scary: better to have 169 // a word that is completely ignored by the GC than to have one for which 170 // only a few updates are ignored. 171 // 172 // Gs, Ms, and Ps are always reachable via true pointers in the 173 // allgs, allm, and allp lists or (during allocation before they reach those lists) 174 // from stack variables. 175 176 // A guintptr holds a goroutine pointer, but typed as a uintptr 177 // to bypass write barriers. It is used in the Gobuf goroutine state 178 // and in scheduling lists that are manipulated without a P. 179 // 180 // The Gobuf.g goroutine pointer is almost always updated by assembly code. 181 // In one of the few places it is updated by Go code - func save - it must be 182 // treated as a uintptr to avoid a write barrier being emitted at a bad time. 183 // Instead of figuring out how to emit the write barriers missing in the 184 // assembly manipulation, we change the type of the field to uintptr, 185 // so that it does not require write barriers at all. 186 // 187 // Goroutine structs are published in the allg list and never freed. 188 // That will keep the goroutine structs from being collected. 189 // There is never a time that Gobuf.g's contain the only references 190 // to a goroutine: the publishing of the goroutine in allg comes first. 191 // Goroutine pointers are also kept in non-GC-visible places like TLS, 192 // so I can't see them ever moving. If we did want to start moving data 193 // in the GC, we'd need to allocate the goroutine structs from an 194 // alternate arena. Using guintptr doesn't make that problem any worse. 195 type guintptr uintptr 196 197 //go:nosplit 198 func (gp guintptr) ptr() *g { return (*g)(unsafe.Pointer(gp)) } 199 200 //go:nosplit 201 func (gp *guintptr) set(g *g) { *gp = guintptr(unsafe.Pointer(g)) } 202 203 //go:nosplit 204 func (gp *guintptr) cas(old, new guintptr) bool { 205 return atomic.Casuintptr((*uintptr)(unsafe.Pointer(gp)), uintptr(old), uintptr(new)) 206 } 207 208 // setGNoWB performs *gp = new without a write barrier. 209 // For times when it's impractical to use a guintptr. 210 //go:nosplit 211 //go:nowritebarrier 212 func setGNoWB(gp **g, new *g) { 213 (*guintptr)(unsafe.Pointer(gp)).set(new) 214 } 215 216 type puintptr uintptr 217 218 //go:nosplit 219 func (pp puintptr) ptr() *p { return (*p)(unsafe.Pointer(pp)) } 220 221 //go:nosplit 222 func (pp *puintptr) set(p *p) { *pp = puintptr(unsafe.Pointer(p)) } 223 224 type muintptr uintptr 225 226 //go:nosplit 227 func (mp muintptr) ptr() *m { return (*m)(unsafe.Pointer(mp)) } 228 229 //go:nosplit 230 func (mp *muintptr) set(m *m) { *mp = muintptr(unsafe.Pointer(m)) } 231 232 // setMNoWB performs *mp = new without a write barrier. 233 // For times when it's impractical to use an muintptr. 234 //go:nosplit 235 //go:nowritebarrier 236 func setMNoWB(mp **m, new *m) { 237 (*muintptr)(unsafe.Pointer(mp)).set(new) 238 } 239 240 type gobuf struct { 241 // The offsets of sp, pc, and g are known to (hard-coded in) libmach. 242 // 243 // ctxt is unusual with respect to GC: it may be a 244 // heap-allocated funcval so write require a write barrier, 245 // but gobuf needs to be cleared from assembly. We take 246 // advantage of the fact that the only path that uses a 247 // non-nil ctxt is morestack. As a result, gogo is the only 248 // place where it may not already be nil, so gogo uses an 249 // explicit write barrier. Everywhere else that resets the 250 // gobuf asserts that ctxt is already nil. 251 sp uintptr 252 pc uintptr 253 g guintptr 254 ctxt unsafe.Pointer // this has to be a pointer so that gc scans it 255 ret sys.Uintreg 256 lr uintptr 257 bp uintptr // for GOEXPERIMENT=framepointer 258 } 259 260 // sudog represents a g in a wait list, such as for sending/receiving 261 // on a channel. 262 // 263 // sudog is necessary because the g ↔ synchronization object relation 264 // is many-to-many. A g can be on many wait lists, so there may be 265 // many sudogs for one g; and many gs may be waiting on the same 266 // synchronization object, so there may be many sudogs for one object. 267 // 268 // sudogs are allocated from a special pool. Use acquireSudog and 269 // releaseSudog to allocate and free them. 270 type sudog struct { 271 // The following fields are protected by the hchan.lock of the 272 // channel this sudog is blocking on. shrinkstack depends on 273 // this for sudogs involved in channel ops. 274 275 g *g 276 277 // isSelect indicates g is participating in a select, so 278 // g.selectDone must be CAS'd to win the wake-up race. 279 isSelect bool 280 next *sudog 281 prev *sudog 282 elem unsafe.Pointer // data element (may point to stack) 283 284 // The following fields are never accessed concurrently. 285 // For channels, waitlink is only accessed by g. 286 // For semaphores, all fields (including the ones above) 287 // are only accessed when holding a semaRoot lock. 288 289 acquiretime int64 290 releasetime int64 291 ticket uint32 292 parent *sudog // semaRoot binary tree 293 waitlink *sudog // g.waiting list or semaRoot 294 waittail *sudog // semaRoot 295 c *hchan // channel 296 } 297 298 type libcall struct { 299 fn uintptr 300 n uintptr // number of parameters 301 args uintptr // parameters 302 r1 uintptr // return values 303 r2 uintptr 304 err uintptr // error number 305 } 306 307 // describes how to handle callback 308 type wincallbackcontext struct { 309 gobody unsafe.Pointer // go function to call 310 argsize uintptr // callback arguments size (in bytes) 311 restorestack uintptr // adjust stack on return by (in bytes) (386 only) 312 cleanstack bool 313 } 314 315 // Stack describes a Go execution stack. 316 // The bounds of the stack are exactly [lo, hi), 317 // with no implicit data structures on either side. 318 type stack struct { 319 lo uintptr 320 hi uintptr 321 } 322 323 type g struct { 324 // Stack parameters. 325 // stack describes the actual stack memory: [stack.lo, stack.hi). 326 // stackguard0 is the stack pointer compared in the Go stack growth prologue. 327 // It is stack.lo+StackGuard normally, but can be StackPreempt to trigger a preemption. 328 // stackguard1 is the stack pointer compared in the C stack growth prologue. 329 // It is stack.lo+StackGuard on g0 and gsignal stacks. 330 // It is ~0 on other goroutine stacks, to trigger a call to morestackc (and crash). 331 stack stack // offset known to runtime/cgo 332 stackguard0 uintptr // offset known to liblink 333 stackguard1 uintptr // offset known to liblink 334 335 _panic *_panic // innermost panic - offset known to liblink 336 _defer *_defer // innermost defer 337 m *m // current m; offset known to arm liblink 338 sched gobuf 339 syscallsp uintptr // if status==Gsyscall, syscallsp = sched.sp to use during gc 340 syscallpc uintptr // if status==Gsyscall, syscallpc = sched.pc to use during gc 341 stktopsp uintptr // expected sp at top of stack, to check in traceback 342 param unsafe.Pointer // passed parameter on wakeup 343 atomicstatus uint32 344 stackLock uint32 // sigprof/scang lock; TODO: fold in to atomicstatus 345 goid int64 346 waitsince int64 // approx time when the g become blocked 347 waitreason string // if status==Gwaiting 348 schedlink guintptr 349 preempt bool // preemption signal, duplicates stackguard0 = stackpreempt 350 paniconfault bool // panic (instead of crash) on unexpected fault address 351 preemptscan bool // preempted g does scan for gc 352 gcscandone bool // g has scanned stack; protected by _Gscan bit in status 353 gcscanvalid bool // false at start of gc cycle, true if G has not run since last scan; TODO: remove? 354 throwsplit bool // must not split stack 355 raceignore int8 // ignore race detection events 356 sysblocktraced bool // StartTrace has emitted EvGoInSyscall about this goroutine 357 sysexitticks int64 // cputicks when syscall has returned (for tracing) 358 traceseq uint64 // trace event sequencer 359 tracelastp puintptr // last P emitted an event for this goroutine 360 lockedm muintptr 361 sig uint32 362 writebuf []byte 363 sigcode0 uintptr 364 sigcode1 uintptr 365 sigpc uintptr 366 gopc uintptr // pc of go statement that created this goroutine 367 startpc uintptr // pc of goroutine function 368 racectx uintptr 369 waiting *sudog // sudog structures this g is waiting on (that have a valid elem ptr); in lock order 370 cgoCtxt []uintptr // cgo traceback context 371 labels unsafe.Pointer // profiler labels 372 timer *timer // cached timer for time.Sleep 373 selectDone uint32 // are we participating in a select and did someone win the race? 374 375 // Per-G GC state 376 377 // gcAssistBytes is this G's GC assist credit in terms of 378 // bytes allocated. If this is positive, then the G has credit 379 // to allocate gcAssistBytes bytes without assisting. If this 380 // is negative, then the G must correct this by performing 381 // scan work. We track this in bytes to make it fast to update 382 // and check for debt in the malloc hot path. The assist ratio 383 // determines how this corresponds to scan work debt. 384 gcAssistBytes int64 385 } 386 387 type m struct { 388 g0 *g // goroutine with scheduling stack 389 morebuf gobuf // gobuf arg to morestack 390 divmod uint32 // div/mod denominator for arm - known to liblink 391 392 // Fields not known to debuggers. 393 procid uint64 // for debuggers, but offset not hard-coded 394 gsignal *g // signal-handling g 395 sigmask sigset // storage for saved signal mask 396 tls [6]uintptr // thread-local storage (for x86 extern register) 397 mstartfn func() 398 curg *g // current running goroutine 399 caughtsig guintptr // goroutine running during fatal signal 400 p puintptr // attached p for executing go code (nil if not executing go code) 401 nextp puintptr 402 id int32 403 mallocing int32 404 throwing int32 405 preemptoff string // if != "", keep curg running on this m 406 locks int32 407 softfloat int32 408 dying int32 409 profilehz int32 410 helpgc int32 411 spinning bool // m is out of work and is actively looking for work 412 blocked bool // m is blocked on a note 413 inwb bool // m is executing a write barrier 414 newSigstack bool // minit on C thread called sigaltstack 415 printlock int8 416 incgo bool // m is executing a cgo call 417 fastrand [2]uint32 418 needextram bool 419 traceback uint8 420 ncgocall uint64 // number of cgo calls in total 421 ncgo int32 // number of cgo calls currently in progress 422 cgoCallersUse uint32 // if non-zero, cgoCallers in use temporarily 423 cgoCallers *cgoCallers // cgo traceback if crashing in cgo call 424 park note 425 alllink *m // on allm 426 schedlink muintptr 427 mcache *mcache 428 lockedg guintptr 429 createstack [32]uintptr // stack that created this thread. 430 freglo [16]uint32 // d[i] lsb and f[i] 431 freghi [16]uint32 // d[i] msb and f[i+16] 432 fflag uint32 // floating point compare flags 433 lockedExt uint32 // tracking for external LockOSThread 434 lockedInt uint32 // tracking for internal lockOSThread 435 nextwaitm uintptr // next m waiting for lock 436 waitunlockf unsafe.Pointer // todo go func(*g, unsafe.pointer) bool 437 waitlock unsafe.Pointer 438 waittraceev byte 439 waittraceskip int 440 startingtrace bool 441 syscalltick uint32 442 thread uintptr // thread handle 443 444 // these are here because they are too large to be on the stack 445 // of low-level NOSPLIT functions. 446 libcall libcall 447 libcallpc uintptr // for cpu profiler 448 libcallsp uintptr 449 libcallg guintptr 450 syscall libcall // stores syscall parameters on windows 451 452 mOS 453 } 454 455 type p struct { 456 lock mutex 457 458 id int32 459 status uint32 // one of pidle/prunning/... 460 link puintptr 461 schedtick uint32 // incremented on every scheduler call 462 syscalltick uint32 // incremented on every system call 463 sysmontick sysmontick // last tick observed by sysmon 464 m muintptr // back-link to associated m (nil if idle) 465 mcache *mcache 466 racectx uintptr 467 468 deferpool [5][]*_defer // pool of available defer structs of different sizes (see panic.go) 469 deferpoolbuf [5][32]*_defer 470 471 // Cache of goroutine ids, amortizes accesses to runtime·sched.goidgen. 472 goidcache uint64 473 goidcacheend uint64 474 475 // Queue of runnable goroutines. Accessed without lock. 476 runqhead uint32 477 runqtail uint32 478 runq [256]guintptr 479 // runnext, if non-nil, is a runnable G that was ready'd by 480 // the current G and should be run next instead of what's in 481 // runq if there's time remaining in the running G's time 482 // slice. It will inherit the time left in the current time 483 // slice. If a set of goroutines is locked in a 484 // communicate-and-wait pattern, this schedules that set as a 485 // unit and eliminates the (potentially large) scheduling 486 // latency that otherwise arises from adding the ready'd 487 // goroutines to the end of the run queue. 488 runnext guintptr 489 490 // Available G's (status == Gdead) 491 gfree *g 492 gfreecnt int32 493 494 sudogcache []*sudog 495 sudogbuf [128]*sudog 496 497 tracebuf traceBufPtr 498 499 // traceSweep indicates the sweep events should be traced. 500 // This is used to defer the sweep start event until a span 501 // has actually been swept. 502 traceSweep bool 503 // traceSwept and traceReclaimed track the number of bytes 504 // swept and reclaimed by sweeping in the current sweep loop. 505 traceSwept, traceReclaimed uintptr 506 507 palloc persistentAlloc // per-P to avoid mutex 508 509 // Per-P GC state 510 gcAssistTime int64 // Nanoseconds in assistAlloc 511 gcBgMarkWorker guintptr 512 gcMarkWorkerMode gcMarkWorkerMode 513 514 // gcw is this P's GC work buffer cache. The work buffer is 515 // filled by write barriers, drained by mutator assists, and 516 // disposed on certain GC state transitions. 517 gcw gcWork 518 519 runSafePointFn uint32 // if 1, run sched.safePointFn at next safe point 520 521 pad [sys.CacheLineSize]byte 522 } 523 524 type schedt struct { 525 // accessed atomically. keep at top to ensure alignment on 32-bit systems. 526 goidgen uint64 527 lastpoll uint64 528 529 lock mutex 530 531 midle muintptr // idle m's waiting for work 532 nmidle int32 // number of idle m's waiting for work 533 nmidlelocked int32 // number of locked m's waiting for work 534 mcount int32 // number of m's that have been created 535 maxmcount int32 // maximum number of m's allowed (or die) 536 537 ngsys uint32 // number of system goroutines; updated atomically 538 539 pidle puintptr // idle p's 540 npidle uint32 541 nmspinning uint32 // See "Worker thread parking/unparking" comment in proc.go. 542 543 // Global runnable queue. 544 runqhead guintptr 545 runqtail guintptr 546 runqsize int32 547 548 // Global cache of dead G's. 549 gflock mutex 550 gfreeStack *g 551 gfreeNoStack *g 552 ngfree int32 553 554 // Central cache of sudog structs. 555 sudoglock mutex 556 sudogcache *sudog 557 558 // Central pool of available defer structs of different sizes. 559 deferlock mutex 560 deferpool [5]*_defer 561 562 gcwaiting uint32 // gc is waiting to run 563 stopwait int32 564 stopnote note 565 sysmonwait uint32 566 sysmonnote note 567 568 // safepointFn should be called on each P at the next GC 569 // safepoint if p.runSafePointFn is set. 570 safePointFn func(*p) 571 safePointWait int32 572 safePointNote note 573 574 profilehz int32 // cpu profiling rate 575 576 procresizetime int64 // nanotime() of last change to gomaxprocs 577 totaltime int64 // ∫gomaxprocs dt up to procresizetime 578 } 579 580 // Values for the flags field of a sigTabT. 581 const ( 582 _SigNotify = 1 << iota // let signal.Notify have signal, even if from kernel 583 _SigKill // if signal.Notify doesn't take it, exit quietly 584 _SigThrow // if signal.Notify doesn't take it, exit loudly 585 _SigPanic // if the signal is from the kernel, panic 586 _SigDefault // if the signal isn't explicitly requested, don't monitor it 587 _SigGoExit // cause all runtime procs to exit (only used on Plan 9). 588 _SigSetStack // add SA_ONSTACK to libc handler 589 _SigUnblock // unblocked in minit 590 _SigIgn // _SIG_DFL action is to ignore the signal 591 ) 592 593 // Layout of in-memory per-function information prepared by linker 594 // See https://golang.org/s/go12symtab. 595 // Keep in sync with linker (../cmd/link/internal/ld/pcln.go:/pclntab) 596 // and with package debug/gosym and with symtab.go in package runtime. 597 type _func struct { 598 entry uintptr // start pc 599 nameoff int32 // function name 600 601 args int32 // in/out args size 602 _ int32 // previously legacy frame size; kept for layout compatibility 603 604 pcsp int32 605 pcfile int32 606 pcln int32 607 npcdata int32 608 nfuncdata int32 609 } 610 611 // layout of Itab known to compilers 612 // allocated in non-garbage-collected memory 613 // Needs to be in sync with 614 // ../cmd/compile/internal/gc/reflect.go:/^func.dumptypestructs. 615 type itab struct { 616 inter *interfacetype 617 _type *_type 618 hash uint32 // copy of _type.hash. Used for type switches. 619 _ [4]byte 620 fun [1]uintptr // variable sized. fun[0]==0 means _type does not implement inter. 621 } 622 623 // Lock-free stack node. 624 // // Also known to export_test.go. 625 type lfnode struct { 626 next uint64 627 pushcnt uintptr 628 } 629 630 type forcegcstate struct { 631 lock mutex 632 g *g 633 idle uint32 634 } 635 636 // startup_random_data holds random bytes initialized at startup. These come from 637 // the ELF AT_RANDOM auxiliary vector (vdso_linux_amd64.go or os_linux_386.go). 638 var startupRandomData []byte 639 640 // extendRandom extends the random numbers in r[:n] to the whole slice r. 641 // Treats n<0 as n==0. 642 func extendRandom(r []byte, n int) { 643 if n < 0 { 644 n = 0 645 } 646 for n < len(r) { 647 // Extend random bits using hash function & time seed 648 w := n 649 if w > 16 { 650 w = 16 651 } 652 h := memhash(unsafe.Pointer(&r[n-w]), uintptr(nanotime()), uintptr(w)) 653 for i := 0; i < sys.PtrSize && n < len(r); i++ { 654 r[n] = byte(h) 655 n++ 656 h >>= 8 657 } 658 } 659 } 660 661 // A _defer holds an entry on the list of deferred calls. 662 // If you add a field here, add code to clear it in freedefer. 663 type _defer struct { 664 siz int32 665 started bool 666 sp uintptr // sp at time of defer 667 pc uintptr 668 fn *funcval 669 _panic *_panic // panic that is running defer 670 link *_defer 671 } 672 673 // panics 674 type _panic struct { 675 argp unsafe.Pointer // pointer to arguments of deferred call run during panic; cannot move - known to liblink 676 arg interface{} // argument to panic 677 link *_panic // link to earlier panic 678 recovered bool // whether this panic is over 679 aborted bool // the panic was aborted 680 } 681 682 // stack traces 683 type stkframe struct { 684 fn funcInfo // function being run 685 pc uintptr // program counter within fn 686 continpc uintptr // program counter where execution can continue, or 0 if not 687 lr uintptr // program counter at caller aka link register 688 sp uintptr // stack pointer at pc 689 fp uintptr // stack pointer at caller aka frame pointer 690 varp uintptr // top of local variables 691 argp uintptr // pointer to function arguments 692 arglen uintptr // number of bytes at argp 693 argmap *bitvector // force use of this argmap 694 } 695 696 const ( 697 _TraceRuntimeFrames = 1 << iota // include frames for internal runtime functions. 698 _TraceTrap // the initial PC, SP are from a trap, not a return PC from a call 699 _TraceJumpStack // if traceback is on a systemstack, resume trace at g that called into it 700 ) 701 702 // The maximum number of frames we print for a traceback 703 const _TracebackMaxFrames = 100 704 705 var ( 706 allglen uintptr 707 allm *m 708 allp []*p // len(allp) == gomaxprocs; may change at safe points, otherwise immutable 709 allpLock mutex // Protects P-less reads of allp and all writes 710 gomaxprocs int32 711 ncpu int32 712 forcegc forcegcstate 713 sched schedt 714 newprocs int32 715 716 // Information about what cpu features are available. 717 // Set on startup in asm_{386,amd64,amd64p32}.s. 718 // Packages outside the runtime should not use these 719 // as they are not an external api. 720 processorVersionInfo uint32 721 isIntel bool 722 lfenceBeforeRdtsc bool 723 support_aes bool 724 support_avx bool 725 support_avx2 bool 726 support_bmi1 bool 727 support_bmi2 bool 728 support_erms bool 729 support_osxsave bool 730 support_popcnt bool 731 support_sse2 bool 732 support_sse41 bool 733 support_sse42 bool 734 support_ssse3 bool 735 736 goarm uint8 // set by cmd/link on arm systems 737 framepointer_enabled bool // set by cmd/link 738 ) 739 740 // Set by the linker so the runtime can determine the buildmode. 741 var ( 742 islibrary bool // -buildmode=c-shared 743 isarchive bool // -buildmode=c-archive 744 )