Skip to content

Commit

Permalink
runtime: use mincore to detect physical page size as last resort on A…
Browse files Browse the repository at this point in the history
…ndroid

Fixes golang#18041.

Change-Id: Iad1439b2dd56b113c8829699eda467d1367b0e15
Reviewed-on: https://go-review.googlesource.com/34610
Reviewed-by: Austin Clements <[email protected]>
  • Loading branch information
minux committed Dec 19, 2016
1 parent ddd558e commit a0667be
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/runtime/os_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a0667be

Please sign in to comment.