diff options
| author | 2015-11-20 01:17:20 +0000 | |
|---|---|---|
| committer | 2015-11-20 01:17:20 +0000 | |
| commit | 7dd1260c564c1504a37bfa41e1372868c605ffdd (patch) | |
| tree | 3009f75ca01b671f9c54e2643e0f9082839724ee /runtime/utils.cc | |
| parent | d042c4514abe104c9591e9336321e11102347105 (diff) | |
| parent | 7ecbd49c6c78e6c633883aa6766675df8abaa7dd (diff) | |
Merge "Use arc4random when available to select delta for image relocation."
Diffstat (limited to 'runtime/utils.cc')
| -rw-r--r-- | runtime/utils.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/runtime/utils.cc b/runtime/utils.cc index 68db7e3a73..7da56403e5 100644 --- a/runtime/utils.cc +++ b/runtime/utils.cc @@ -18,12 +18,14 @@ #include <inttypes.h> #include <pthread.h> +#include <stdlib.h> #include <sys/stat.h> #include <sys/syscall.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> #include <memory> +#include <random> #include "art_field-inl.h" #include "art_method-inl.h" @@ -60,6 +62,26 @@ namespace art { static constexpr bool kUseAddr2line = !kIsTargetBuild; #endif +#if defined(__BIONIC__) +struct Arc4RandomGenerator { + typedef uint32_t result_type; + uint32_t min() { return std::numeric_limits<uint32_t>::min(); } + uint32_t max() { return std::numeric_limits<uint32_t>::max(); } + uint32_t operator() { return arc4random(); } +}; +using RNG = Arc4RandomGenerator; +#else +using RNG = std::random_device; +#endif + +template <typename T> +T GetRandomNumber(T min, T max) { + CHECK_LT(min, max); + std::uniform_int_distribution<T> dist(min, max); + RNG rng; + return dist(rng); +} + pid_t GetTid() { #if defined(__APPLE__) uint64_t owner; |