Move common macros into bionic_macros.h.

Bug: 15590152
Change-Id: I730636613ef3653f68c5ab1d43b53beaf8e0dc25
This commit is contained in:
Christopher Ferris
2014-06-13 13:57:51 -07:00
parent 64dfbd242c
commit 03eebcb6e8
8 changed files with 42 additions and 29 deletions

View File

@@ -37,6 +37,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/system_properties.h>
@@ -48,6 +49,7 @@
#include "debug_stacktrace.h"
#include "malloc_debug_common.h"
#include "private/bionic_macros.h"
#include "private/libc_logging.h"
#include "private/ScopedPthreadMutexLocker.h"
@@ -255,7 +257,7 @@ extern "C" struct mallinfo fill_mallinfo() {
}
extern "C" int fill_posix_memalign(void** memptr, size_t alignment, size_t size) {
if ((alignment & (alignment - 1)) != 0) {
if (!powerof2(alignment)) {
return EINVAL;
}
int saved_errno = errno;
@@ -266,7 +268,7 @@ extern "C" int fill_posix_memalign(void** memptr, size_t alignment, size_t size)
extern "C" void* fill_pvalloc(size_t bytes) {
size_t pagesize = sysconf(_SC_PAGESIZE);
size_t size = (bytes + pagesize - 1) & ~(pagesize - 1);
size_t size = BIONIC_ALIGN(bytes, pagesize);
if (size < bytes) { // Overflow
return NULL;
}
@@ -401,8 +403,8 @@ extern "C" void* leak_memalign(size_t alignment, size_t bytes) {
}
// need to make sure it's a power of two
if (alignment & (alignment-1)) {
alignment = 1L << (31 - __builtin_clz(alignment));
if (!powerof2(alignment)) {
alignment = BIONIC_ROUND_UP_POWER_OF_2(alignment);
}
// here, alignment is at least MALLOC_ALIGNMENT<<1 bytes
@@ -464,7 +466,7 @@ extern "C" struct mallinfo leak_mallinfo() {
}
extern "C" int leak_posix_memalign(void** memptr, size_t alignment, size_t size) {
if ((alignment & (alignment - 1)) != 0) {
if (!powerof2(alignment)) {
return EINVAL;
}
int saved_errno = errno;
@@ -475,7 +477,7 @@ extern "C" int leak_posix_memalign(void** memptr, size_t alignment, size_t size)
extern "C" void* leak_pvalloc(size_t bytes) {
size_t pagesize = sysconf(_SC_PAGESIZE);
size_t size = (bytes + pagesize - 1) & ~(pagesize - 1);
size_t size = BIONIC_ALIGN(bytes, pagesize);
if (size < bytes) { // Overflow
return NULL;
}