@@ -47,30 +47,31 @@ func TestMremap(t *testing.T) {
47
47
}
48
48
49
49
func TestMremapPtr (t * testing.T ) {
50
- mmapProt := unix .PROT_NONE
51
- mmapPtrProt := unix .PROT_READ | unix .PROT_WRITE
52
- b , err := unix .Mmap (- 1 , 0 , 2 * unix .Getpagesize (), mmapProt , unix .MAP_ANON | unix .MAP_PRIVATE )
50
+ p1 , err := unix .MmapPtr (- 1 , 0 , nil , uintptr (2 * unix .Getpagesize ()),
51
+ unix .PROT_READ | unix .PROT_WRITE , unix .MAP_ANON | unix .MAP_PRIVATE )
53
52
if err != nil {
54
- t .Fatalf ("Mmap: %v" , err )
55
- }
56
- if _ , err := unix .MmapPtr (- 1 , 0 , unsafe .Pointer (& b [0 ]), uintptr (unix .Getpagesize ()),
57
- mmapPtrProt , unix .MAP_ANON | unix .MAP_PRIVATE | unix .MAP_FIXED ); err != nil {
58
53
t .Fatalf ("MmapPtr: %v" , err )
59
54
}
60
55
61
- b [0 ] = 42
56
+ p2 := unsafe .Add (p1 , unix .Getpagesize ())
57
+ if err := unix .MunmapPtr (p2 , uintptr (unix .Getpagesize ())); err != nil {
58
+ t .Fatalf ("MunmapPtr: %v" , err )
59
+ }
60
+
61
+ * (* byte )(p1 ) = 42
62
62
63
63
if _ , err := unix .MremapPtr (
64
- unsafe . Pointer ( & b [ 0 ]) , uintptr (unix .Getpagesize ()),
65
- unsafe . Pointer ( & b [ unix . Getpagesize ()]) , uintptr (unix .Getpagesize ()),
64
+ p1 , uintptr (unix .Getpagesize ()),
65
+ p2 , uintptr (unix .Getpagesize ()),
66
66
unix .MremapFixed | unix .MremapMaymove ); err != nil {
67
67
t .Fatalf ("MremapPtr: %v" , err )
68
68
}
69
- if got := b [unix .Getpagesize ()]; got != 42 {
69
+
70
+ if got := * (* byte )(p2 ); got != 42 {
70
71
t .Errorf ("got %d, want 42" , got )
71
72
}
72
73
73
- if err := unix .Munmap ( b ); err != nil {
74
- t .Fatalf ("Munmap : %v" , err )
74
+ if err := unix .MunmapPtr ( p2 , uintptr ( unix . Getpagesize ()) ); err != nil {
75
+ t .Fatalf ("MunmapPtr : %v" , err )
75
76
}
76
77
}
0 commit comments