mirror of
https://github.com/rwinkhart/sys.git
synced 2026-08-27 20:36:31 -04:00
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: 2535abd892d9063b9bdda69101a45f71c4174124 GitHub-Pull-Request: golang/sys#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>
This commit is contained in:
committed by
Gopher Robot
parent
a0ef40af1f
commit
c892bb7ec2
+9
-13
@@ -9,7 +9,6 @@ package unix_test
|
||||
import (
|
||||
"runtime"
|
||||
"testing"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
@@ -52,23 +51,20 @@ func TestMmap(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMmapPtr(t *testing.T) {
|
||||
mmapProt := unix.PROT_NONE
|
||||
mmapPtrProt := unix.PROT_READ | unix.PROT_WRITE
|
||||
b, err := unix.Mmap(-1, 0, 2*unix.Getpagesize(), mmapProt, unix.MAP_ANON|unix.MAP_PRIVATE)
|
||||
p, err := unix.MmapPtr(-1, 0, nil, uintptr(2*unix.Getpagesize()),
|
||||
unix.PROT_NONE, unix.MAP_ANON|unix.MAP_PRIVATE)
|
||||
if err != nil {
|
||||
t.Fatalf("Mmap: %v", err)
|
||||
}
|
||||
if _, err := unix.MmapPtr(-1, 0, unsafe.Pointer(&b[0]), uintptr(unix.Getpagesize()),
|
||||
mmapPtrProt, unix.MAP_ANON|unix.MAP_PRIVATE|unix.MAP_FIXED); err != nil {
|
||||
t.Fatalf("MmapPtr: %v", err)
|
||||
}
|
||||
|
||||
b[0] = 42
|
||||
if _, err := unix.MmapPtr(-1, 0, p, uintptr(unix.Getpagesize()),
|
||||
unix.PROT_READ|unix.PROT_WRITE, unix.MAP_ANON|unix.MAP_PRIVATE|unix.MAP_FIXED); err != nil {
|
||||
t.Fatalf("MmapPtr: %v", err)
|
||||
}
|
||||
|
||||
if err := unix.MunmapPtr(unsafe.Pointer(&b[0]), uintptr(unix.Getpagesize())); err != nil {
|
||||
*(*byte)(p) = 42
|
||||
|
||||
if err := unix.MunmapPtr(p, uintptr(2*unix.Getpagesize())); err != nil {
|
||||
t.Fatalf("MunmapPtr: %v", err)
|
||||
}
|
||||
if err := unix.Munmap(b); err != nil {
|
||||
t.Fatalf("Munmap: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user