]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use mincore to detect physical page size as last resort on Android
authorShenghou Ma <minux@golang.org>
Mon, 19 Dec 2016 14:48:07 +0000 (09:48 -0500)
committerMinux Ma <minux@golang.org>
Mon, 19 Dec 2016 22:00:50 +0000 (22:00 +0000)
Fixes #18041.

Change-Id: Iad1439b2dd56b113c8829699eda467d1367b0e15
Reviewed-on: https://go-review.googlesource.com/34610
Reviewed-by: Austin Clements <austin@google.com>
src/runtime/os_linux.go

index 320c1281c28c24be771d6cb3e5c7efc2fbaaae57..213b951a6b5239a6e12ac4cea3b0631b7254f634 100644 (file)
@@ -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