mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime/debug: add SetPanicOnFault
SetPanicOnFault allows recovery from unexpected memory faults. This can be useful if you are using a memory-mapped file or probing the address space of the current program. LGTM=r R=r CC=golang-codereviews https://golang.org/cl/66590044
This commit is contained in:
parent
67c83db60d
commit
e56c6e7535
14 changed files with 52 additions and 15 deletions
|
|
@ -10,9 +10,11 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
. "runtime"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var errf error
|
||||
|
|
@ -131,3 +133,19 @@ func TestRuntimeGogoBytes(t *testing.T) {
|
|||
func TestStopCPUProfilingWithProfilerOff(t *testing.T) {
|
||||
SetCPUProfileRate(0)
|
||||
}
|
||||
|
||||
func TestSetPanicOnFault(t *testing.T) {
|
||||
old := debug.SetPanicOnFault(true)
|
||||
defer debug.SetPanicOnFault(old)
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err == nil {
|
||||
t.Fatalf("did not find error in recover")
|
||||
}
|
||||
}()
|
||||
|
||||
var p *int
|
||||
p = (*int)(unsafe.Pointer(^uintptr(0)))
|
||||
println(*p)
|
||||
t.Fatalf("still here - should have faulted")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue