github.com/4ad/go@v0.0.0-20161219182952-69a12818b605/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 type puintptr uintptr 209 210 //go:nosplit 211 func (pp puintptr) ptr() *p { return (*p)(unsafe.Pointer(pp)) } 212 213 //go:nosplit 214 func (pp *puintptr) set(p *p) { *pp = puintptr(unsafe.Pointer(p)) } 215 216 type muintptr uintptr 217 218 //go:nosplit 219 func (mp muintptr) ptr() *m { return (*m)(unsafe.Pointer(mp)) } 220 221 //go:nosplit 222 func (mp *muintptr) set(m *m) { *mp = muintptr(unsafe.Pointer(m)) } 223 224 type gobuf struct { 225 // The offsets of sp, pc, and g are known to (hard-coded in) libmach. 226 sp uintptr 227 pc uintptr 228 g guintptr 229 ctxt unsafe.Pointer // this has to be a pointer so that gc scans it 230 ret sys.Uintreg 231 lr uintptr 232 bp uintptr // for GOEXPERIMENT=framepointer 233 } 234 235 // sudog represents a g in a wait list, such as for sending/receiving 236 // on a channel. 237 // 238 // sudog is necessary because the g ↔ synchronization object relation 239 // is many-to-many. A g can be on many wait lists, so there may be 240 // many sudogs for one g; and many gs may be waiting on the same 241 // synchronization object, so there may be many sudogs for one object. 242 // 243 // sudogs are allocated from a special pool. Use acquireSudog and 244 // releaseSudog to allocate and free them. 245 type sudog struct { 246 // The following fields are protected by the hchan.lock of the 247 // channel this sudog is blocking on. shrinkstack depends on 248 // this. 249 250 g *g 251 selectdone *uint32 // CAS to 1 to win select race (may point to stack) 252 next *sudog 253 prev *sudog 254 elem unsafe.Pointer // data element (may point to stack) 255 256 // The following fields are never accessed concurrently. 257 // waitlink is only accessed by g. 258 259 releasetime int64 260 ticket uint32 261 waitlink *sudog // g.waiting list 262 c *hchan // channel 263 } 264 265 type gcstats struct { 266 // the struct must consist of only uint64's, 267 // because it is casted to uint64[]. 268 nhandoff uint64 269 nhandoffcnt uint64 270 nprocyield uint64 271 nosyield uint64 272 nsleep uint64 273 } 274 275 type libcall struct { 276 fn uintptr 277 n uintptr // number of parameters 278 args uintptr // parameters 279 r1 uintptr // return values 280 r2 uintptr 281 err uintptr // error number 282 } 283 284 // describes how to handle callback 285 type wincallbackcontext struct { 286 gobody unsafe.Pointer // go function to call 287 argsize uintptr // callback arguments size (in bytes) 288 restorestack uintptr // adjust stack on return by (in bytes) (386 only) 289 cleanstack bool 290 } 291 292 // Stack describes a Go execution stack. 293 // The bounds of the stack are exactly [lo, hi), 294 // with no implicit data structures on either side. 295 type stack struct { 296 lo uintptr 297 hi uintptr 298 } 299 300 // stkbar records the state of a G's stack barrier. 301 type stkbar struct { 302 savedLRPtr uintptr // location overwritten by stack barrier PC 303 savedLRVal uintptr // value overwritten at savedLRPtr 304 } 305 306 type g struct { 307 // Stack parameters. 308 // stack describes the actual stack memory: [stack.lo, stack.hi). 309 // stackguard0 is the stack pointer compared in the Go stack growth prologue. 310 // It is stack.lo+StackGuard normally, but can be StackPreempt to trigger a preemption. 311 // stackguard1 is the stack pointer compared in the C stack growth prologue. 312 // It is stack.lo+StackGuard on g0 and gsignal stacks. 313 // It is ~0 on other goroutine stacks, to trigger a call to morestackc (and crash). 314 stack stack // offset known to runtime/cgo 315 stackguard0 uintptr // offset known to liblink 316 stackguard1 uintptr // offset known to liblink 317 318 _panic *_panic // innermost panic - offset known to liblink 319 _defer *_defer // innermost defer 320 m *m // current m; offset known to arm liblink 321 stackAlloc uintptr // stack allocation is [stack.lo,stack.lo+stackAlloc) 322 sched gobuf 323 syscallsp uintptr // if status==Gsyscall, syscallsp = sched.sp to use during gc 324 syscallpc uintptr // if status==Gsyscall, syscallpc = sched.pc to use during gc 325 stkbar []stkbar // stack barriers, from low to high (see top of mstkbar.go) 326 stkbarPos uintptr // index of lowest stack barrier not hit 327 stktopsp uintptr // expected sp at top of stack, to check in traceback 328 param unsafe.Pointer // passed parameter on wakeup 329 atomicstatus uint32 330 stackLock uint32 // sigprof/scang lock; TODO: fold in to atomicstatus 331 goid int64 332 waitsince int64 // approx time when the g become blocked 333 waitreason string // if status==Gwaiting 334 schedlink guintptr 335 preempt bool // preemption signal, duplicates stackguard0 = stackpreempt 336 paniconfault bool // panic (instead of crash) on unexpected fault address 337 preemptscan bool // preempted g does scan for gc 338 gcscandone bool // g has scanned stack; protected by _Gscan bit in status 339 gcscanvalid bool // false at start of gc cycle, true if G has not run since last scan; transition from true to false by calling queueRescan and false to true by calling dequeueRescan 340 throwsplit bool // must not split stack 341 raceignore int8 // ignore race detection events 342 sysblocktraced bool // StartTrace has emitted EvGoInSyscall about this goroutine 343 sysexitticks int64 // cputicks when syscall has returned (for tracing) 344 traceseq uint64 // trace event sequencer 345 tracelastp puintptr // last P emitted an event for this goroutine 346 lockedm *m 347 sig uint32 348 writebuf []byte 349 sigcode0 uintptr 350 sigcode1 uintptr 351 sigpc uintptr 352 gopc uintptr // pc of go statement that created this goroutine 353 startpc uintptr // pc of goroutine function 354 racectx uintptr 355 waiting *sudog // sudog structures this g is waiting on (that have a valid elem ptr); in lock order 356 cgoCtxt []uintptr // cgo traceback context 357 358 // Per-G GC state 359 360 // gcRescan is this G's index in work.rescan.list. If this is 361 // -1, this G is not on the rescan list. 362 // 363 // If gcphase != _GCoff and this G is visible to the garbage 364 // collector, writes to this are protected by work.rescan.lock. 365 gcRescan int32 366 367 // gcAssistBytes is this G's GC assist credit in terms of 368 // bytes allocated. If this is positive, then the G has credit 369 // to allocate gcAssistBytes bytes without assisting. If this 370 // is negative, then the G must correct this by performing 371 // scan work. We track this in bytes to make it fast to update 372 // and check for debt in the malloc hot path. The assist ratio 373 // determines how this corresponds to scan work debt. 374 gcAssistBytes int64 375 } 376 377 type m struct { 378 g0 *g // goroutine with scheduling stack 379 morebuf gobuf // gobuf arg to morestack 380 divmod uint32 // div/mod denominator for arm - known to liblink 381 382 // Fields not known to debuggers. 383 procid uint64 // for debuggers, but offset not hard-coded 384 gsignal *g // signal-handling g 385 sigmask sigset // storage for saved signal mask 386 tls [6]uintptr // thread-local storage (for x86 extern register) 387 mstartfn func() 388 curg *g // current running goroutine 389 caughtsig guintptr // goroutine running during fatal signal 390 p puintptr // attached p for executing go code (nil if not executing go code) 391 nextp puintptr 392 id int32 393 mallocing int32 394 throwing int32 395 preemptoff string // if != "", keep curg running on this m 396 locks int32 397 softfloat int32 398 dying int32 399 profilehz int32 400 helpgc int32 401 spinning bool // m is out of work and is actively looking for work 402 blocked bool // m is blocked on a note 403 inwb bool // m is executing a write barrier 404 newSigstack bool // minit on C thread called sigaltstack 405 printlock int8 406 fastrand uint32 407 ncgocall uint64 // number of cgo calls in total 408 ncgo int32 // number of cgo calls currently in progress 409 cgoCallersUse uint32 // if non-zero, cgoCallers in use temporarily 410 cgoCallers *cgoCallers // cgo traceback if crashing in cgo call 411 park note 412 alllink *m // on allm 413 schedlink muintptr 414 mcache *mcache 415 lockedg *g 416 createstack [32]uintptr // stack that created this thread. 417 freglo [16]uint32 // d[i] lsb and f[i] 418 freghi [16]uint32 // d[i] msb and f[i+16] 419 fflag uint32 // floating point compare flags 420 locked uint32 // tracking for lockosthread 421 nextwaitm uintptr // next m waiting for lock 422 gcstats gcstats 423 needextram bool 424 traceback uint8 425 waitunlockf unsafe.Pointer // todo go func(*g, unsafe.pointer) bool 426 waitlock unsafe.Pointer 427 waittraceev byte 428 waittraceskip int 429 startingtrace bool 430 syscalltick uint32 431 thread uintptr // thread handle 432 433 // these are here because they are too large to be on the stack 434 // of low-level NOSPLIT functions. 435 libcall libcall 436 libcallpc uintptr // for cpu profiler 437 libcallsp uintptr 438 libcallg guintptr 439 syscall libcall // stores syscall parameters on windows 440 441 mOS 442 } 443 444 type p struct { 445 lock mutex 446 447 id int32 448 status uint32 // one of pidle/prunning/... 449 link puintptr 450 schedtick uint32 // incremented on every scheduler call 451 syscalltick uint32 // incremented on every system call 452 m muintptr // back-link to associated m (nil if idle) 453 mcache *mcache 454 racectx uintptr 455 456 deferpool [5][]*_defer // pool of available defer structs of different sizes (see panic.go) 457 deferpoolbuf [5][32]*_defer 458 459 // Cache of goroutine ids, amortizes accesses to runtime·sched.goidgen. 460 goidcache uint64 461 goidcacheend uint64 462 463 // Queue of runnable goroutines. Accessed without lock. 464 runqhead uint32 465 runqtail uint32 466 runq [256]guintptr 467 // runnext, if non-nil, is a runnable G that was ready'd by 468 // the current G and should be run next instead of what's in 469 // runq if there's time remaining in the running G's time 470 // slice. It will inherit the time left in the current time 471 // slice. If a set of goroutines is locked in a 472 // communicate-and-wait pattern, this schedules that set as a 473 // unit and eliminates the (potentially large) scheduling 474 // latency that otherwise arises from adding the ready'd 475 // goroutines to the end of the run queue. 476 runnext guintptr 477 478 // Available G's (status == Gdead) 479 gfree *g 480 gfreecnt int32 481 482 sudogcache []*sudog 483 sudogbuf [128]*sudog 484 485 tracebuf traceBufPtr 486 487 palloc persistentAlloc // per-P to avoid mutex 488 489 // Per-P GC state 490 gcAssistTime int64 // Nanoseconds in assistAlloc 491 gcBgMarkWorker guintptr 492 gcMarkWorkerMode gcMarkWorkerMode 493 494 // gcw is this P's GC work buffer cache. The work buffer is 495 // filled by write barriers, drained by mutator assists, and 496 // disposed on certain GC state transitions. 497 gcw gcWork 498 499 runSafePointFn uint32 // if 1, run sched.safePointFn at next safe point 500 501 pad [64]byte 502 } 503 504 const ( 505 // The max value of GOMAXPROCS. 506 // There are no fundamental restrictions on the value. 507 _MaxGomaxprocs = 1 << 8 508 ) 509 510 type schedt struct { 511 // accessed atomically. keep at top to ensure alignment on 32-bit systems. 512 goidgen uint64 513 lastpoll uint64 514 515 lock mutex 516 517 midle muintptr // idle m's waiting for work 518 nmidle int32 // number of idle m's waiting for work 519 nmidlelocked int32 // number of locked m's waiting for work 520 mcount int32 // number of m's that have been created 521 maxmcount int32 // maximum number of m's allowed (or die) 522 523 ngsys uint32 // number of system goroutines; updated atomically 524 525 pidle puintptr // idle p's 526 npidle uint32 527 nmspinning uint32 // See "Worker thread parking/unparking" comment in proc.go. 528 529 // Global runnable queue. 530 runqhead guintptr 531 runqtail guintptr 532 runqsize int32 533 534 // Global cache of dead G's. 535 gflock mutex 536 gfreeStack *g 537 gfreeNoStack *g 538 ngfree int32 539 540 // Central cache of sudog structs. 541 sudoglock mutex 542 sudogcache *sudog 543 544 // Central pool of available defer structs of different sizes. 545 deferlock mutex 546 deferpool [5]*_defer 547 548 gcwaiting uint32 // gc is waiting to run 549 stopwait int32 550 stopnote note 551 sysmonwait uint32 552 sysmonnote note 553 554 // safepointFn should be called on each P at the next GC 555 // safepoint if p.runSafePointFn is set. 556 safePointFn func(*p) 557 safePointWait int32 558 safePointNote note 559 560 profilehz int32 // cpu profiling rate 561 562 procresizetime int64 // nanotime() of last change to gomaxprocs 563 totaltime int64 // ∫gomaxprocs dt up to procresizetime 564 } 565 566 // The m.locked word holds two pieces of state counting active calls to LockOSThread/lockOSThread. 567 // The low bit (LockExternal) is a boolean reporting whether any LockOSThread call is active. 568 // External locks are not recursive; a second lock is silently ignored. 569 // The upper bits of m.locked record the nesting depth of calls to lockOSThread 570 // (counting up by LockInternal), popped by unlockOSThread (counting down by LockInternal). 571 // Internal locks can be recursive. For instance, a lock for cgo can occur while the main 572 // goroutine is holding the lock during the initialization phase. 573 const ( 574 _LockExternal = 1 575 _LockInternal = 2 576 ) 577 578 type sigtabtt struct { 579 flags int32 580 name *int8 581 } 582 583 const ( 584 _SigNotify = 1 << iota // let signal.Notify have signal, even if from kernel 585 _SigKill // if signal.Notify doesn't take it, exit quietly 586 _SigThrow // if signal.Notify doesn't take it, exit loudly 587 _SigPanic // if the signal is from the kernel, panic 588 _SigDefault // if the signal isn't explicitly requested, don't monitor it 589 _SigHandling // our signal handler is registered 590 _SigGoExit // cause all runtime procs to exit (only used on Plan 9). 591 _SigSetStack // add SA_ONSTACK to libc handler 592 _SigUnblock // unblocked in minit 593 ) 594 595 // Layout of in-memory per-function information prepared by linker 596 // See https://golang.org/s/go12symtab. 597 // Keep in sync with linker 598 // and with package debug/gosym and with symtab.go in package runtime. 599 type _func struct { 600 entry uintptr // start pc 601 nameoff int32 // function name 602 603 args int32 // in/out args size 604 _ int32 // previously legacy frame size; kept for layout compatibility 605 606 pcsp int32 607 pcfile int32 608 pcln int32 609 npcdata int32 610 nfuncdata int32 611 } 612 613 // layout of Itab known to compilers 614 // allocated in non-garbage-collected memory 615 // Needs to be in sync with 616 // ../cmd/compile/internal/gc/reflect.go:/^func.dumptypestructs. 617 type itab struct { 618 inter *interfacetype 619 _type *_type 620 link *itab 621 bad int32 622 unused int32 623 fun [1]uintptr // variable sized 624 } 625 626 // Lock-free stack node. 627 // // Also known to export_test.go. 628 type lfnode struct { 629 next uint64 630 pushcnt uintptr 631 } 632 633 type forcegcstate struct { 634 lock mutex 635 g *g 636 idle uint32 637 } 638 639 // startup_random_data holds random bytes initialized at startup. These come from 640 // the ELF AT_RANDOM auxiliary vector (vdso_linux_amd64.go or os_linux_386.go). 641 var startupRandomData []byte 642 643 // extendRandom extends the random numbers in r[:n] to the whole slice r. 644 // Treats n<0 as n==0. 645 func extendRandom(r []byte, n int) { 646 if n < 0 { 647 n = 0 648 } 649 for n < len(r) { 650 // Extend random bits using hash function & time seed 651 w := n 652 if w > 16 { 653 w = 16 654 } 655 h := memhash(unsafe.Pointer(&r[n-w]), uintptr(nanotime()), uintptr(w)) 656 for i := 0; i < sys.PtrSize && n < len(r); i++ { 657 r[n] = byte(h) 658 n++ 659 h >>= 8 660 } 661 } 662 } 663 664 // deferred subroutine calls 665 type _defer struct { 666 siz int32 667 started bool 668 sp uintptr // sp at time of defer 669 pc uintptr 670 fn *funcval 671 _panic *_panic // panic that is running defer 672 link *_defer 673 } 674 675 // panics 676 type _panic struct { 677 argp unsafe.Pointer // pointer to arguments of deferred call run during panic; cannot move - known to liblink 678 arg interface{} // argument to panic 679 link *_panic // link to earlier panic 680 recovered bool // whether this panic is over 681 aborted bool // the panic was aborted 682 } 683 684 // stack traces 685 type stkframe struct { 686 fn *_func // function being run 687 pc uintptr // program counter within fn 688 continpc uintptr // program counter where execution can continue, or 0 if not 689 lr uintptr // program counter at caller aka link register 690 sp uintptr // stack pointer at pc 691 fp uintptr // stack pointer at caller aka frame pointer 692 varp uintptr // top of local variables 693 argp uintptr // pointer to function arguments 694 arglen uintptr // number of bytes at argp 695 argmap *bitvector // force use of this argmap 696 } 697 698 const ( 699 _TraceRuntimeFrames = 1 << iota // include frames for internal runtime functions. 700 _TraceTrap // the initial PC, SP are from a trap, not a return PC from a call 701 _TraceJumpStack // if traceback is on a systemstack, resume trace at g that called into it 702 ) 703 704 // The maximum number of frames we print for a traceback 705 const _TracebackMaxFrames = 100 706 707 var ( 708 emptystring string 709 allglen uintptr 710 allm *m 711 allp [_MaxGomaxprocs + 1]*p 712 gomaxprocs int32 713 panicking uint32 714 ncpu int32 715 forcegc forcegcstate 716 sched schedt 717 newprocs int32 718 719 // Information about what cpu features are available. 720 // Set on startup in asm_{x86,amd64}.s. 721 cpuid_ecx uint32 722 cpuid_edx uint32 723 cpuid_ebx7 uint32 724 lfenceBeforeRdtsc bool 725 support_avx bool 726 support_avx2 bool 727 728 goarm uint8 // set by cmd/link on arm systems 729 framepointer_enabled bool // set by cmd/link 730 ) 731 732 // Set by the linker so the runtime can determine the buildmode. 733 var ( 734 islibrary bool // -buildmode=c-shared 735 isarchive bool // -buildmode=c-archive 736 )