From d91d0762c7757c12c7d5f9e2ae3f170d5bd7ba84 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Thu, 20 Aug 2020 14:22:30 -0700 Subject: runtime/debug: provide Addr method for errors from SetPanicOnFault When we're building a panic that's triggered by a memory fault when SetPanicOnFault has been called, include an Addr method. This method reports the address at which the fault occurred. Fixes #37023 RELNOTE=yes Change-Id: Idff144587d6b75070fdc861a36efec76f4ec7384 Reviewed-on: https://go-review.googlesource.com/c/go/+/249677 Run-TryBot: Keith Randall TryBot-Result: Go Bot Trust: Keith Randall Reviewed-by: Russ Cox --- src/runtime/debug/garbage.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/runtime/debug/garbage.go') diff --git a/src/runtime/debug/garbage.go b/src/runtime/debug/garbage.go index 785e9d4598..e36e54f12d 100644 --- a/src/runtime/debug/garbage.go +++ b/src/runtime/debug/garbage.go @@ -139,6 +139,11 @@ func SetMaxThreads(threads int) int { // manipulation of memory may cause faults at non-nil addresses in less // dramatic situations; SetPanicOnFault allows such programs to request // that the runtime trigger only a panic, not a crash. +// The runtime.Error that the runtime panics with may have an additional method: +// Addr() uintptr +// If that method exists, it returns the memory address which triggered the fault. +// The results of Addr are best-effort and the veracity of the result +// may depend on the platform. // SetPanicOnFault applies only to the current goroutine. // It returns the previous setting. func SetPanicOnFault(enabled bool) bool { -- cgit v1.3-5-g9baa