blob: f1205dc9654334a284f4bd2d128abf363d211904 [file] [log] [blame]
Russ Coxc81a0ed2014-09-08 14:05:23 -04001// Copyright 2014 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// +build darwin dragonfly freebsd linux netbsd openbsd solaris
6
7package runtime
8
Russ Coxc81a0ed2014-09-08 14:05:23 -04009func sigpanic() {
10 g := getg()
11 if !canpanic(g) {
Keith Randallb2a950b2014-12-27 20:58:00 -080012 throw("unexpected signal during runtime execution")
Russ Coxc81a0ed2014-09-08 14:05:23 -040013 }
14
15 switch g.sig {
16 case _SIGBUS:
17 if g.sigcode0 == _BUS_ADRERR && g.sigcode1 < 0x1000 || g.paniconfault {
18 panicmem()
19 }
20 print("unexpected fault address ", hex(g.sigcode1), "\n")
Keith Randallb2a950b2014-12-27 20:58:00 -080021 throw("fault")
Russ Coxc81a0ed2014-09-08 14:05:23 -040022 case _SIGSEGV:
23 if (g.sigcode0 == 0 || g.sigcode0 == _SEGV_MAPERR || g.sigcode0 == _SEGV_ACCERR) && g.sigcode1 < 0x1000 || g.paniconfault {
24 panicmem()
25 }
26 print("unexpected fault address ", hex(g.sigcode1), "\n")
Keith Randallb2a950b2014-12-27 20:58:00 -080027 throw("fault")
Russ Coxc81a0ed2014-09-08 14:05:23 -040028 case _SIGFPE:
29 switch g.sigcode0 {
30 case _FPE_INTDIV:
31 panicdivide()
32 case _FPE_INTOVF:
33 panicoverflow()
34 }
35 panicfloat()
36 }
Russ Cox2d917c02014-11-11 17:05:55 -050037
38 if g.sig >= uint32(len(sigtable)) {
39 // can't happen: we looked up g.sig in sigtable to decide to call sigpanic
Keith Randallb2a950b2014-12-27 20:58:00 -080040 throw("unexpected signal value")
Russ Cox2d917c02014-11-11 17:05:55 -050041 }
42 panic(errorString(sigtable[g.sig].name))
Russ Coxc81a0ed2014-09-08 14:05:23 -040043}