aboutsummaryrefslogtreecommitdiff
path: root/test/recover4.go
diff options
context:
space:
mode:
authorDave Cheney <dave@cheney.net>2015-03-17 14:56:04 +1100
committerDave Cheney <dave@cheney.net>2015-03-17 05:25:01 +0000
commit1f3fe910664069a94acdbd27d2ba3e6f5b256dbe (patch)
tree262078284ba6719f8bf283d68935393d6decfe19 /test/recover4.go
parent4eb93029725f3adbd9632a1b58644920f077f100 (diff)
downloadgo-1f3fe910664069a94acdbd27d2ba3e6f5b256dbe.tar.gz
go-1f3fe910664069a94acdbd27d2ba3e6f5b256dbe.zip
test: fix recover4 test on 64kb systems
Fix recover4.go to work on 64kb systems. Change-Id: I211cb048de1268a8bbac77c6f3a1e0b8c8277594 Reviewed-on: https://go-review.googlesource.com/7673 Reviewed-by: Minux Ma <minux@golang.org>
Diffstat (limited to 'test/recover4.go')
-rw-r--r--test/recover4.go16
1 files changed, 9 insertions, 7 deletions
diff --git a/test/recover4.go b/test/recover4.go
index 115d5a0eed..cda08138f9 100644
--- a/test/recover4.go
+++ b/test/recover4.go
@@ -44,8 +44,10 @@ func main() {
// so that memcopy can recover.
debug.SetPanicOnFault(true)
- // Map 64 kB block of data with 16 kB hole in middle.
- data, err := syscall.Mmap(-1, 0, 64*1024, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANON|syscall.MAP_PRIVATE)
+ size := syscall.Getpagesize()
+
+ // Map 16 pages of data with a 4-page hole in the middle.
+ data, err := syscall.Mmap(-1, 0, 16*size, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANON|syscall.MAP_PRIVATE)
if err != nil {
log.Fatalf("mmap: %v", err)
}
@@ -53,19 +55,19 @@ func main() {
// Note: Cannot call syscall.Munmap, because Munmap checks
// that you are unmapping a whole region returned by Mmap.
// We are trying to unmap just a hole in the middle.
- if _, _, err := syscall.Syscall(syscall.SYS_MUNMAP, uintptr(unsafe.Pointer(&data[32*1024])), 16*1024, 0); err != 0 {
+ if _, _, err := syscall.Syscall(syscall.SYS_MUNMAP, uintptr(unsafe.Pointer(&data[8*size])), uintptr(4*size), 0); err != 0 {
log.Fatalf("munmap: %v", err)
}
- other := make([]byte, 64*1024)
+ other := make([]byte, 16*size)
// Check that memcopy returns the actual amount copied
- // before the fault (32kB - 5, the offset we skip in the argument).
+ // before the fault (8*size - 5, the offset we skip in the argument).
n, err := memcopy(data[5:], other)
if err == nil {
log.Fatal("no error from memcopy across memory hole")
}
- if n != 32*1024-5 {
- log.Fatal("memcopy returned %d, want %d", n, 32*1024-5)
+ if n != 8*size-5 {
+ log.Fatal("memcopy returned %d, want %d", n, 8*size-5)
}
}