OSDN Git Service

Use arc4random_buf instead of getauxval(AT_RANDOM).
authorJosh Gao <jmgao@google.com>
Wed, 16 Sep 2015 23:27:00 +0000 (16:27 -0700)
committerJosh Gao <jmgao@google.com>
Thu, 17 Sep 2015 01:35:41 +0000 (18:35 -0700)
Reclaim the AT_RANDOM bytes used by ART for bionic.

Bug: http://b/23942752
Change-Id: Iceddce7f08fa887a7bb6828d75ef21426c413863

runtime/mem_map.cc

index d9ad7dc..2a019c5 100644 (file)
 #include "base/memory_tool.h"
 #include <backtrace/BacktraceMap.h>
 #include <inttypes.h>
+#include <stdlib.h>
 
 #include <memory>
 #include <sstream>
 
-// See CreateStartPos below.
-#ifdef __BIONIC__
-#include <sys/auxv.h>
-#endif
-
 #include "base/stringprintf.h"
 
 #pragma GCC diagnostic push
@@ -103,7 +99,7 @@ static constexpr uintptr_t LOW_MEM_START = 64 * KB;
 // --------------------------------------
 // start
 //
-// getauxval as an entropy source is exposed in Bionic, but not in glibc before 2.16. When we
+// arc4random as an entropy source is exposed in Bionic, but not in glibc. When we
 // do not have Bionic, simply start with LOW_MEM_START.
 
 // Function is standalone so it can be tested somewhat in mem_map_test.cc.
@@ -125,11 +121,11 @@ uintptr_t CreateStartPos(uint64_t input) {
 
 static uintptr_t GenerateNextMemPos() {
 #ifdef __BIONIC__
-  uint8_t* random_data = reinterpret_cast<uint8_t*>(getauxval(AT_RANDOM));
-  // The lower 8B are taken for the stack guard. Use the upper 8B (with mask).
-  return CreateStartPos(*reinterpret_cast<uintptr_t*>(random_data + 8));
+  uint64_t random_data;
+  arc4random_buf(&random_data, sizeof(random_data));
+  return CreateStartPos(random_data);
 #else
-  // No auxv on host, see above.
+  // No arc4random on host, see above.
   return LOW_MEM_START;
 #endif
 }