@@ -9,7 +9,6 @@ package unix_test
9
9
import (
10
10
"runtime"
11
11
"testing"
12
- "unsafe"
13
12
14
13
"golang.org/x/sys/unix"
15
14
)
@@ -52,23 +51,20 @@ func TestMmap(t *testing.T) {
52
51
}
53
52
54
53
func TestMmapPtr (t * testing.T ) {
55
- mmapProt := unix .PROT_NONE
56
- mmapPtrProt := unix .PROT_READ | unix .PROT_WRITE
57
- b , err := unix .Mmap (- 1 , 0 , 2 * unix .Getpagesize (), mmapProt , unix .MAP_ANON | unix .MAP_PRIVATE )
54
+ p , err := unix .MmapPtr (- 1 , 0 , nil , uintptr (2 * unix .Getpagesize ()),
55
+ unix .PROT_NONE , unix .MAP_ANON | unix .MAP_PRIVATE )
58
56
if err != nil {
59
- t .Fatalf ("Mmap : %v" , err )
57
+ t .Fatalf ("MmapPtr : %v" , err )
60
58
}
61
- if _ , err := unix .MmapPtr (- 1 , 0 , unsafe .Pointer (& b [0 ]), uintptr (unix .Getpagesize ()),
62
- mmapPtrProt , unix .MAP_ANON | unix .MAP_PRIVATE | unix .MAP_FIXED ); err != nil {
59
+
60
+ if _ , err := unix .MmapPtr (- 1 , 0 , p , uintptr (unix .Getpagesize ()),
61
+ unix .PROT_READ | unix .PROT_WRITE , unix .MAP_ANON | unix .MAP_PRIVATE | unix .MAP_FIXED ); err != nil {
63
62
t .Fatalf ("MmapPtr: %v" , err )
64
63
}
65
64
66
- b [ 0 ] = 42
65
+ * ( * byte )( p ) = 42
67
66
68
- if err := unix .MunmapPtr (unsafe . Pointer ( & b [ 0 ]) , uintptr (unix .Getpagesize ())); err != nil {
67
+ if err := unix .MunmapPtr (p , uintptr (2 * unix .Getpagesize ())); err != nil {
69
68
t .Fatalf ("MunmapPtr: %v" , err )
70
69
}
71
- if err := unix .Munmap (b ); err != nil {
72
- t .Fatalf ("Munmap: %v" , err )
73
- }
74
70
}
0 commit comments