Commit a0667be8 authored by Shenghou Ma's avatar Shenghou Ma Committed by Minux Ma

runtime: use mincore to detect physical page size as last resort on Android

Fixes #18041.

Change-Id: Iad1439b2dd56b113c8829699eda467d1367b0e15
Reviewed-on: https://go-review.googlesource.com/34610Reviewed-by: default avatarAustin Clements <austin@google.com>
parent ddd558e7
......@@ -208,6 +208,26 @@ func sysargs(argc int32, argv **byte) {
// Fall back to /proc/self/auxv.
fd := open(&procAuxv[0], 0 /* O_RDONLY */, 0)
if fd < 0 {
// On Android, /proc/self/auxv might be unreadable (issue 9229), so we fallback to
// try using mincore to detect the physical page size.
// mincore should return EINVAL when address is not a multiple of system page size.
const size = 256 << 10 // size of memory region to allocate
p := mmap(nil, size, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_PRIVATE, -1, 0)
if uintptr(p) < 4096 {
return
}
var n uintptr
for n = 4 << 10; n < size; n <<= 1 {
err := mincore(unsafe.Pointer(uintptr(p)+n), 1, &addrspace_vec[0])
if err == 0 {
physPageSize = n
break
}
}
if physPageSize == 0 {
physPageSize = size
}
munmap(p, size)
return
}
var buf [128]uintptr
......
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