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.
9 // Code related to defer, panic and recover.
11 uint32 runtime_panicking
;
14 // Run all deferred functions for the current goroutine.
22 while((d
= g
->defer
) != nil
) {
35 runtime_startpanic(void)
41 runtime_printf("panic during panic\n");
45 runtime_xadd(&runtime_panicking
, 1);
46 runtime_lock(&paniclk
);
50 runtime_dopanic(int32 unused
__attribute__ ((unused
)))
53 static bool didothers
;
57 runtime_printf("[signal %x code=%p addr=%p]\n",
58 g
->sig
, (void*)g
->sigcode0
, (void*)g
->sigcode1
);
60 if(runtime_gotraceback()){
61 if(g
!= runtime_m()->g0
) {
63 runtime_goroutineheader(g
);
65 runtime_goroutinetrailer(g
);
69 runtime_tracebackothers(g
);
72 runtime_unlock(&paniclk
);
73 if(runtime_xadd(&runtime_panicking
, -1) != 0) {
74 // Some other m is panicking too.
75 // Let it print what it needs to print.
76 // Wait forever without chewing up cpu.
77 // It will exit when it's done.
79 runtime_lock(&deadlock
);
80 runtime_lock(&deadlock
);
87 runtime_throw(const char *s
)
90 runtime_printf("throw: %s\n", s
);
92 *(int32
*)0 = 0; // not reached
93 runtime_exit(1); // even more not reached
97 runtime_panicstring(const char *s
)
101 if(runtime_m()->gcing
) {
102 runtime_printf("panic: %s\n", s
);
103 runtime_throw("panic during gc");
105 runtime_newErrorString(runtime_gostringnocopy((const byte
*)s
), &err
);
109 void runtime_Goexit (void) asm ("runtime.Goexit");