Skip to content

Commit 2535abd

Browse files
committed
unix: fix MmapPtr test failing on OpenBSD
OpenBSD apparently doesn't allow unmapping address space if part of the region is already unmapped. This tweaks the test so that munmapping twice no longer happens. Cq-Include-Trybots: luci.golang.try:gotip-openbsd-amd64
1 parent daa2394 commit 2535abd

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

unix/mmap_unix_test.go

+8-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ package unix_test
99
import (
1010
"runtime"
1111
"testing"
12-
"unsafe"
1312

1413
"golang.org/x/sys/unix"
1514
)
@@ -52,23 +51,20 @@ func TestMmap(t *testing.T) {
5251
}
5352

5453
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)
5856
if err != nil {
59-
t.Fatalf("Mmap: %v", err)
57+
t.Fatalf("MmapPtr: %v", err)
6058
}
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 {
6362
t.Fatalf("MmapPtr: %v", err)
6463
}
6564

66-
b[0] = 42
65+
*(*byte)(p) = 42
6766

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 {
6968
t.Fatalf("MunmapPtr: %v", err)
7069
}
71-
if err := unix.Munmap(b); err != nil {
72-
t.Fatalf("Munmap: %v", err)
73-
}
7470
}

0 commit comments

Comments
 (0)