diff options
| author | Christopher Ferris <cferris@google.com> | 2014-06-13 13:57:51 -0700 |
|---|---|---|
| committer | Christopher Ferris <cferris@google.com> | 2014-06-18 14:23:46 -0700 |
| commit | 03eebcb6e8762e668a0d3af6bb303cccb88c5b81 (patch) | |
| tree | 3c5053d90eb3d1fac8c21fa390367a911e188191 /libc/bionic/jemalloc_wrapper.cpp | |
| parent | 64dfbd242cddc3ef95576e27e3940d68b89b5fce (diff) | |
Move common macros into bionic_macros.h.
Bug: 15590152
Change-Id: I730636613ef3653f68c5ab1d43b53beaf8e0dc25
Diffstat (limited to 'libc/bionic/jemalloc_wrapper.cpp')
| -rw-r--r-- | libc/bionic/jemalloc_wrapper.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/libc/bionic/jemalloc_wrapper.cpp b/libc/bionic/jemalloc_wrapper.cpp index 625d789e7..d1fe96056 100644 --- a/libc/bionic/jemalloc_wrapper.cpp +++ b/libc/bionic/jemalloc_wrapper.cpp @@ -14,13 +14,19 @@ * limitations under the License. */ +#include <sys/param.h> #include <unistd.h> #include "jemalloc.h" +#include "private/bionic_macros.h" void* je_pvalloc(size_t bytes) { size_t pagesize = sysconf(_SC_PAGESIZE); - return je_memalign(pagesize, (bytes + pagesize - 1) & ~(pagesize - 1)); + size_t size = BIONIC_ALIGN(bytes, pagesize); + if (size < bytes) { + return NULL; + } + return je_memalign(pagesize, size); } #ifdef je_memalign @@ -31,11 +37,9 @@ void* je_pvalloc(size_t bytes) { // but this is not true. Both glibc and dlmalloc round up to the next power // of 2, so we'll do the same. void* je_memalign_round_up_boundary(size_t boundary, size_t size) { - unsigned int power_of_2 = static_cast<unsigned int>(boundary); - if (power_of_2 != 0) { - power_of_2 = 1UL << (sizeof(unsigned int)*8 - 1 - __builtin_clz(power_of_2)); - if (power_of_2 != boundary) { - boundary = power_of_2 << 1; + if (boundary != 0) { + if (!powerof2(boundary)) { + boundary = BIONIC_ROUND_UP_POWER_OF_2(boundary); } } else { boundary = 1; |
