Commit f61353f2 authored by Clément Chigot's avatar Clément Chigot Committed by Brad Fitzpatrick

runtime: enable runtime_mmap_test.go on AIX

AIX doesn't allow to mmap an address range which is already mmap.
Therefore, once the region has been allocated, it must munmap before
being able to play with it.

Change-Id: I1547782f0379024f57869f1dda8c1c9bb12d831f
Reviewed-on: https://go-review.googlesource.com/c/go/+/174059Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 8feeada5
...@@ -65,7 +65,7 @@ const ( ...@@ -65,7 +65,7 @@ const (
_PROT_WRITE = C.PROT_WRITE _PROT_WRITE = C.PROT_WRITE
_PROT_EXEC = C.PROT_EXEC _PROT_EXEC = C.PROT_EXEC
_MAP_ANONYMOUS = C.MAP_ANONYMOUS _MAP_ANON = C.MAP_ANONYMOUS
_MAP_PRIVATE = C.MAP_PRIVATE _MAP_PRIVATE = C.MAP_PRIVATE
_MAP_FIXED = C.MAP_FIXED _MAP_FIXED = C.MAP_FIXED
_MADV_DONTNEED = C.MADV_DONTNEED _MADV_DONTNEED = C.MADV_DONTNEED
......
...@@ -22,7 +22,7 @@ const ( ...@@ -22,7 +22,7 @@ const (
_PROT_WRITE = 0x2 _PROT_WRITE = 0x2
_PROT_EXEC = 0x4 _PROT_EXEC = 0x4
_MAP_ANONYMOUS = 0x10 _MAP_ANON = 0x10
_MAP_PRIVATE = 0x2 _MAP_PRIVATE = 0x2
_MAP_FIXED = 0x100 _MAP_FIXED = 0x100
_MADV_DONTNEED = 0x4 _MADV_DONTNEED = 0x4
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris // +build aix darwin dragonfly freebsd linux nacl netbsd openbsd solaris
// Export guts for testing. // Export guts for testing.
......
...@@ -12,7 +12,7 @@ import ( ...@@ -12,7 +12,7 @@ import (
// prevents us from allocating more stack. // prevents us from allocating more stack.
//go:nosplit //go:nosplit
func sysAlloc(n uintptr, sysStat *uint64) unsafe.Pointer { func sysAlloc(n uintptr, sysStat *uint64) unsafe.Pointer {
p, err := mmap(nil, n, _PROT_READ|_PROT_WRITE, _MAP_ANONYMOUS|_MAP_PRIVATE, -1, 0) p, err := mmap(nil, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_PRIVATE, -1, 0)
if err != 0 { if err != 0 {
if err == _EACCES { if err == _EACCES {
print("runtime: mmap: access denied\n") print("runtime: mmap: access denied\n")
...@@ -46,11 +46,11 @@ func sysFree(v unsafe.Pointer, n uintptr, sysStat *uint64) { ...@@ -46,11 +46,11 @@ func sysFree(v unsafe.Pointer, n uintptr, sysStat *uint64) {
} }
func sysFault(v unsafe.Pointer, n uintptr) { func sysFault(v unsafe.Pointer, n uintptr) {
mmap(v, n, _PROT_NONE, _MAP_ANONYMOUS|_MAP_PRIVATE|_MAP_FIXED, -1, 0) mmap(v, n, _PROT_NONE, _MAP_ANON|_MAP_PRIVATE|_MAP_FIXED, -1, 0)
} }
func sysReserve(v unsafe.Pointer, n uintptr) unsafe.Pointer { func sysReserve(v unsafe.Pointer, n uintptr) unsafe.Pointer {
p, err := mmap(v, n, _PROT_NONE, _MAP_ANONYMOUS|_MAP_PRIVATE, -1, 0) p, err := mmap(v, n, _PROT_NONE, _MAP_ANON|_MAP_PRIVATE, -1, 0)
if err != 0 { if err != 0 {
return nil return nil
} }
...@@ -63,7 +63,7 @@ func sysMap(v unsafe.Pointer, n uintptr, sysStat *uint64) { ...@@ -63,7 +63,7 @@ func sysMap(v unsafe.Pointer, n uintptr, sysStat *uint64) {
// AIX does not allow mapping a range that is already mapped. // AIX does not allow mapping a range that is already mapped.
// So always unmap first even if it is already unmapped. // So always unmap first even if it is already unmapped.
munmap(v, n) munmap(v, n)
p, err := mmap(v, n, _PROT_READ|_PROT_WRITE, _MAP_ANONYMOUS|_MAP_FIXED|_MAP_PRIVATE, -1, 0) p, err := mmap(v, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_FIXED|_MAP_PRIVATE, -1, 0)
if err == _ENOMEM { if err == _ENOMEM {
throw("runtime: out of memory") throw("runtime: out of memory")
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris // +build aix darwin dragonfly freebsd linux nacl netbsd openbsd solaris
package runtime_test package runtime_test
...@@ -34,6 +34,11 @@ func TestPhysPageSize(t *testing.T) { ...@@ -34,6 +34,11 @@ func TestPhysPageSize(t *testing.T) {
t.Fatalf("Mmap: %v", err) t.Fatalf("Mmap: %v", err)
} }
if runtime.GOOS == "aix" {
// AIX does not allow mapping a range that is already mapped.
runtime.Munmap(unsafe.Pointer(uintptr(b)), 2*ps)
}
// Mmap should fail at a half page into the buffer. // Mmap should fail at a half page into the buffer.
_, err = runtime.Mmap(unsafe.Pointer(uintptr(b)+ps/2), ps, 0, runtime.MAP_ANON|runtime.MAP_PRIVATE|runtime.MAP_FIXED, -1, 0) _, err = runtime.Mmap(unsafe.Pointer(uintptr(b)+ps/2), ps, 0, runtime.MAP_ANON|runtime.MAP_PRIVATE|runtime.MAP_FIXED, -1, 0)
if err == 0 { if err == 0 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment