From: Josh Gao Date: Wed, 16 Sep 2015 23:27:00 +0000 (-0700) Subject: Use arc4random_buf instead of getauxval(AT_RANDOM). X-Git-Tag: android-x86-7.1-r1~889^2~359^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=0389cd57de8faedb85b749656b8e1735a7bce002;p=android-x86%2Fart.git Use arc4random_buf instead of getauxval(AT_RANDOM). Reclaim the AT_RANDOM bytes used by ART for bionic. Bug: http://b/23942752 Change-Id: Iceddce7f08fa887a7bb6828d75ef21426c413863 --- diff --git a/runtime/mem_map.cc b/runtime/mem_map.cc index d9ad7dc0c..2a019c5ba 100644 --- a/runtime/mem_map.cc +++ b/runtime/mem_map.cc @@ -19,15 +19,11 @@ #include "base/memory_tool.h" #include #include +#include #include #include -// See CreateStartPos below. -#ifdef __BIONIC__ -#include -#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(getauxval(AT_RANDOM)); - // The lower 8B are taken for the stack guard. Use the upper 8B (with mask). - return CreateStartPos(*reinterpret_cast(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 }