Skip to content

Commit a0ef40a

Browse files
ncrucesgopherbot
authored andcommitted
unix: fix MremapPtr test failing on NetBSD
NetBSD apparently doesn't allow remapping into used address space. This means that the test that uses mremap to move a mmapped page into a new address should first mmap (to reserve) then munmap (to free) the destination. Fixes golang/go#68180 Change-Id: If66b67e7166ca4dc4331a8cfc3e3a285416e9849 GitHub-Last-Rev: 92058c2 GitHub-Pull-Request: #198 Cq-Include-Trybots: luci.golang.try:x_sys-gotip-netbsd-amd64 Reviewed-on: https://go-review.googlesource.com/c/sys/+/594756 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Joedian Reid <joedian@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent daa2394 commit a0ef40a

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

unix/mremap_test.go

+14-13
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,31 @@ func TestMremap(t *testing.T) {
4747
}
4848

4949
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)
5352
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 {
5853
t.Fatalf("MmapPtr: %v", err)
5954
}
6055

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
6262

6363
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()),
6666
unix.MremapFixed|unix.MremapMaymove); err != nil {
6767
t.Fatalf("MremapPtr: %v", err)
6868
}
69-
if got := b[unix.Getpagesize()]; got != 42 {
69+
70+
if got := *(*byte)(p2); got != 42 {
7071
t.Errorf("got %d, want 42", got)
7172
}
7273

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)
7576
}
7677
}

0 commit comments

Comments
 (0)