@@ -44,28 +44,30 @@ func main() {
44
44
// so that memcopy can recover.
45
45
debug .SetPanicOnFault (true )
46
46
47
- // Map 64 kB block of data with 16 kB hole in middle.
48
- data , err := syscall .Mmap (- 1 , 0 , 64 * 1024 , syscall .PROT_READ | syscall .PROT_WRITE , syscall .MAP_ANON | syscall .MAP_PRIVATE )
47
+ size := syscall .Getpagesize ()
48
+
49
+ // Map 16 pages of data with a 4-page hole in the middle.
50
+ data , err := syscall .Mmap (- 1 , 0 , 16 * size , syscall .PROT_READ | syscall .PROT_WRITE , syscall .MAP_ANON | syscall .MAP_PRIVATE )
49
51
if err != nil {
50
52
log .Fatalf ("mmap: %v" , err )
51
53
}
52
54
53
55
// Note: Cannot call syscall.Munmap, because Munmap checks
54
56
// that you are unmapping a whole region returned by Mmap.
55
57
// We are trying to unmap just a hole in the middle.
56
- if _ , _ , err := syscall .Syscall (syscall .SYS_MUNMAP , uintptr (unsafe .Pointer (& data [32 * 1024 ])), 16 * 1024 , 0 ); err != 0 {
58
+ if _ , _ , err := syscall .Syscall (syscall .SYS_MUNMAP , uintptr (unsafe .Pointer (& data [8 * size ])), uintptr ( 4 * size ) , 0 ); err != 0 {
57
59
log .Fatalf ("munmap: %v" , err )
58
60
}
59
61
60
- other := make ([]byte , 64 * 1024 )
62
+ other := make ([]byte , 16 * size )
61
63
62
64
// Check that memcopy returns the actual amount copied
63
- // before the fault (32kB - 5, the offset we skip in the argument).
65
+ // before the fault (8*size - 5, the offset we skip in the argument).
64
66
n , err := memcopy (data [5 :], other )
65
67
if err == nil {
66
68
log .Fatal ("no error from memcopy across memory hole" )
67
69
}
68
- if n != 32 * 1024 - 5 {
69
- log .Fatal ("memcopy returned %d, want %d" , n , 32 * 1024 - 5 )
70
+ if n != 8 * size - 5 {
71
+ log .Fatal ("memcopy returned %d, want %d" , n , 8 * size - 5 )
70
72
}
71
73
}
0 commit comments