Skip to content

Commit 726b1bf

Browse files
committed
runtime: expand comments on runtime panic checks
This adds comments explaining why it's important that some panics are allowed in the runtime (even though this isn't ideal). Change-Id: I04c6fc4f792f3793f951619ccaea6bfef2f1763c Reviewed-on: https://go-review.googlesource.com/c/go/+/181737 Reviewed-by: Keith Randall <[email protected]>
1 parent 84fce98 commit 726b1bf

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/runtime/panic.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,24 @@ func panicCheck1(pc uintptr, msg string) {
2929
}
3030

3131
// Same as above, but calling from the runtime is allowed.
32+
//
33+
// Using this function is necessary for any panic that may be
34+
// generated by runtime.sigpanic, since those are always called by the
35+
// runtime.
3236
func panicCheck2(err string) {
37+
// panic allocates, so to avoid recursive malloc, turn panics
38+
// during malloc into throws.
3339
gp := getg()
3440
if gp != nil && gp.m != nil && gp.m.mallocing != 0 {
3541
throw(err)
3642
}
3743
}
3844

45+
// Many of the following panic entry-points turn into throws when they
46+
// happen in various runtime contexts. These should never happen in
47+
// the runtime, and if they do, they indicate a serious issue and
48+
// should not be caught by user code.
49+
//
3950
// The panic{Index,Slice,divide,shift} functions are called by
4051
// code generated by the compiler for out of bounds index expressions,
4152
// out of bounds slice expressions, division by zero, and shift by negative.
@@ -49,6 +60,11 @@ func panicCheck2(err string) {
4960
// runtime package we turn the panic into a throw. That will dump the
5061
// entire runtime stack for easier debugging.
5162
//
63+
// The entry points called by the signal handler will be called from
64+
// runtime.sigpanic, so we can't disallow calls from the runtime to
65+
// these (they always look like they're called from the runtime).
66+
// Hence, for these, we just check for clearly bad runtime conditions.
67+
//
5268
// The panic{Index,Slice} functions are implemented in assembly and tail call
5369
// to the goPanic{Index,Slice} functions below. This is done so we can use
5470
// a space-minimal register calling convention.

0 commit comments

Comments
 (0)