Skip to content

Commit c892bb7

Browse files
ncrucesgopherbot
authored andcommitted
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. Fixes golang/go#68181 Change-Id: I588255f5e10ec015dbb7188eac79cee6be570680 GitHub-Last-Rev: 2535abd GitHub-Pull-Request: #199 Cq-Include-Trybots: luci.golang.try:go1.22-openbsd-amd64 Reviewed-on: https://go-review.googlesource.com/c/sys/+/595095 TryBot-Bypass: Ian Lance Taylor <iant@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org>
1 parent a0ef40a commit c892bb7

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)