github.com/golang/gofrontend@v0.0.0-20240429183944-60f985a78526/libgo/runtime/panic.c (about) 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. 4 5 #include "runtime.h" 6 7 extern void gothrow(String) __attribute__((noreturn)); 8 extern void gothrow(String) __asm__(GOSYM_PREFIX "runtime.throw"); 9 10 void 11 runtime_throw(const char *s) 12 { 13 gothrow(runtime_gostringnocopy((const byte *)s)); 14 } 15 16 void 17 runtime_panicstring(const char *s) 18 { 19 G *gp; 20 Eface err; 21 22 gp = runtime_g(); 23 if (gp == nil) { 24 runtime_printf("panic: %s\n", s); 25 runtime_throw("panic with no g"); 26 } 27 if (gp->m == nil) { 28 runtime_printf("panic: %s\n", s); 29 runtime_throw("panic with no m"); 30 } 31 if (gp->m->curg != gp) { 32 runtime_printf("panic: %s\n", s); 33 runtime_throw("panic on system stack"); 34 } 35 if (gp->m->mallocing != 0) { 36 runtime_printf("panic: %s\n", s); 37 runtime_throw("panic during malloc"); 38 } 39 if (gp->m->preemptoff.len != 0) { 40 runtime_printf("panic: %s\n", s); 41 runtime_printf("preempt off reason: %S\n", gp->m->preemptoff); 42 runtime_throw("panic during preemptoff"); 43 } 44 if (gp->m->locks != 0) { 45 runtime_printf("panic: %s\n", s); 46 runtime_throw("panic holding locks"); 47 } 48 runtime_newErrorCString((uintptr) s, &err); 49 runtime_panic(err); 50 } 51 52 extern void runtime_abort(void) __asm__(GOSYM_PREFIX "runtime.abort"); 53 54 void 55 runtime_abort() 56 { 57 abort(); 58 }