Russ Cox | c81a0ed | 2014-09-08 14:05:23 -0400 | [diff] [blame] | 1 | // 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 | |
| 7 | package runtime |
| 8 | |
Russ Cox | c81a0ed | 2014-09-08 14:05:23 -0400 | [diff] [blame] | 9 | func sigpanic() { |
| 10 | g := getg() |
| 11 | if !canpanic(g) { |
Keith Randall | b2a950b | 2014-12-27 20:58:00 -0800 | [diff] [blame] | 12 | throw("unexpected signal during runtime execution") |
Russ Cox | c81a0ed | 2014-09-08 14:05:23 -0400 | [diff] [blame] | 13 | } |
| 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 Randall | b2a950b | 2014-12-27 20:58:00 -0800 | [diff] [blame] | 21 | throw("fault") |
Russ Cox | c81a0ed | 2014-09-08 14:05:23 -0400 | [diff] [blame] | 22 | 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 Randall | b2a950b | 2014-12-27 20:58:00 -0800 | [diff] [blame] | 27 | throw("fault") |
Russ Cox | c81a0ed | 2014-09-08 14:05:23 -0400 | [diff] [blame] | 28 | case _SIGFPE: |
| 29 | switch g.sigcode0 { |
| 30 | case _FPE_INTDIV: |
| 31 | panicdivide() |
| 32 | case _FPE_INTOVF: |
| 33 | panicoverflow() |
| 34 | } |
| 35 | panicfloat() |
| 36 | } |
Russ Cox | 2d917c0 | 2014-11-11 17:05:55 -0500 | [diff] [blame] | 37 | |
| 38 | if g.sig >= uint32(len(sigtable)) { |
| 39 | // can't happen: we looked up g.sig in sigtable to decide to call sigpanic |
Keith Randall | b2a950b | 2014-12-27 20:58:00 -0800 | [diff] [blame] | 40 | throw("unexpected signal value") |
Russ Cox | 2d917c0 | 2014-11-11 17:05:55 -0500 | [diff] [blame] | 41 | } |
| 42 | panic(errorString(sigtable[g.sig].name)) |
Russ Cox | c81a0ed | 2014-09-08 14:05:23 -0400 | [diff] [blame] | 43 | } |