1 // Copyright 2012 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.
10 // Code related to defer, panic and recover.
12 uint32 runtime_panicking
;
15 // Run all deferred functions for the current goroutine.
23 while((d
= g
->defer
) != nil
) {
36 runtime_startpanic(void)
41 if(runtime_mheap
== 0 || runtime_mheap
->cachealloc
.size
== 0) { // very early
42 runtime_printf("runtime: panic before malloc heap initialized\n");
43 m
->mallocing
= 1; // tell rest of panic not to try to malloc
44 } else if(m
->mcache
== nil
) // can happen if called from signal handler or throw
45 m
->mcache
= runtime_allocmcache();
47 runtime_printf("panic during panic\n");
51 runtime_xadd(&runtime_panicking
, 1);
52 runtime_lock(&paniclk
);
56 runtime_dopanic(int32 unused
__attribute__ ((unused
)))
59 static bool didothers
;
64 runtime_printf("[signal %x code=%p addr=%p]\n",
65 g
->sig
, (void*)g
->sigcode0
, (void*)g
->sigcode1
);
67 if(runtime_gotraceback(&crash
)){
68 if(g
!= runtime_m()->g0
) {
70 runtime_goroutineheader(g
);
72 runtime_goroutinetrailer(g
);
76 runtime_tracebackothers(g
);
79 runtime_unlock(&paniclk
);
80 if(runtime_xadd(&runtime_panicking
, -1) != 0) {
81 // Some other m is panicking too.
82 // Let it print what it needs to print.
83 // Wait forever without chewing up cpu.
84 // It will exit when it's done.
86 runtime_lock(&deadlock
);
87 runtime_lock(&deadlock
);
97 runtime_throw(const char *s
)
102 if(mp
->throwing
== 0)
104 runtime_startpanic();
105 runtime_printf("fatal error: %s\n", s
);
107 *(int32
*)0 = 0; // not reached
108 runtime_exit(1); // even more not reached
112 runtime_panicstring(const char *s
)
116 if(runtime_m()->gcing
) {
117 runtime_printf("panic: %s\n", s
);
118 runtime_throw("panic during gc");
120 runtime_newErrorString(runtime_gostringnocopy((const byte
*)s
), &err
);
124 void runtime_Goexit (void) __asm__ (GOSYM_PREFIX
"runtime.Goexit");