summaryrefslogtreecommitdiff
path: root/src/runtime/panic.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-09-18 14:49:24 -0400
committerRuss Cox <rsc@golang.org>2014-09-18 14:49:24 -0400
commit154be0397299f982c1c0e7c182a2deeb77ac4ec4 (patch)
tree6778e45ac7891fc52d1268e549091112e0362bf3 /src/runtime/panic.go
parent433566655a72738d3f2f700c4134226a88e6293d (diff)
downloadgo-154be0397299f982c1c0e7c182a2deeb77ac4ec4.tar.gz
runtime: delete panicstring; move its checks into gopanic
In Go 1.3 the runtime called panicstring to report errors like divide by zero or memory faults. Now we call panic (gopanic) with pre-allocated error values. That new path is missing the checking that panicstring did, so add it there. The only call to panicstring left is in cnew, which is problematic because if it fails, probably the heap is corrupt. In that case, calling panicstring creates a new errorCString (no allocation there), but then panic tries to print it, invoking errorCString.Error, which does a string concatenation (allocating), which then dies. Replace that one panicstring with a throw: cnew is for allocating runtime data structures and should never ask for an inappropriate amount of memory. With panicstring gone, delete newErrorCString, errorCString. While we're here, delete newErrorString, not called by anyone. (It can't be: that would be C code calling Go code that might block or grow the stack.) Found while debugging a malloc corruption. This resulted in 'panic during panic' instead of a more useful message. LGTM=khr R=khr CC=golang-codereviews https://codereview.appspot.com/138290045
Diffstat (limited to 'src/runtime/panic.go')
-rw-r--r--src/runtime/panic.go59
1 files changed, 29 insertions, 30 deletions
diff --git a/src/runtime/panic.go b/src/runtime/panic.go
index 927b6db44..3cc31053e 100644
--- a/src/runtime/panic.go
+++ b/src/runtime/panic.go
@@ -281,6 +281,35 @@ func gopanic(e interface{}) {
if gp.m.curg != gp {
gothrow("panic on m stack")
}
+
+ // m.softfloat is set during software floating point.
+ // It increments m.locks to avoid preemption.
+ // We moved the memory loads out, so there shouldn't be
+ // any reason for it to panic anymore.
+ if gp.m.softfloat != 0 {
+ gp.m.locks--
+ gp.m.softfloat = 0
+ gothrow("panic during softfloat")
+ }
+ if gp.m.mallocing != 0 {
+ print("panic: ")
+ printany(e)
+ print("\n")
+ gothrow("panic during malloc")
+ }
+ if gp.m.gcing != 0 {
+ print("panic: ")
+ printany(e)
+ print("\n")
+ gothrow("panic during gc")
+ }
+ if gp.m.locks != 0 {
+ print("panic: ")
+ printany(e)
+ print("\n")
+ gothrow("panic holding locks")
+ }
+
var p _panic
p.arg = e
p.link = gp._panic
@@ -431,33 +460,3 @@ func gothrow(s string) {
dopanic(0)
*(*int)(nil) = 0 // not reached
}
-
-func panicstring(s *int8) {
- // m.softfloat is set during software floating point,
- // which might cause a fault during a memory load.
- // It increments m.locks to avoid preemption.
- // If we're panicking, the software floating point frames
- // will be unwound, so decrement m.locks as they would.
- gp := getg()
- if gp.m.softfloat != 0 {
- gp.m.locks--
- gp.m.softfloat = 0
- }
-
- if gp.m.mallocing != 0 {
- print("panic: ", s, "\n")
- gothrow("panic during malloc")
- }
- if gp.m.gcing != 0 {
- print("panic: ", s, "\n")
- gothrow("panic during gc")
- }
- if gp.m.locks != 0 {
- print("panic: ", s, "\n")
- gothrow("panic holding locks")
- }
-
- var err interface{}
- newErrorCString(unsafe.Pointer(s), &err)
- gopanic(err)
-}