diff options
author | Jason Evans <je@fb.com> | 2012-02-29 05:37:38 (GMT) |
---|---|---|
committer | Jason Evans <je@fb.com> | 2012-02-29 05:37:38 (GMT) |
commit | 5965631636c620fba2eb33698accee75fd207aab (patch) | |
tree | 04204ad7fd997905dae1483331fc093963161aab | |
parent | 93c023d181269fd47ca3f8e773509bb5bd779684 (diff) | |
download | jemalloc-5965631636c620fba2eb33698accee75fd207aab.zip jemalloc-5965631636c620fba2eb33698accee75fd207aab.tar.gz jemalloc-5965631636c620fba2eb33698accee75fd207aab.tar.bz2 |
Do not enforce minimum alignment in memalign().
Do not enforce minimum alignment in memalign(). This is a non-standard
function, and there is disagreement over whether to enforce minimum
alignment. Solaris documentation (whence memalign() originated) says
that minimum alignment is required:
The value of alignment must be a power of two and must be greater than
or equal to the size of a word.
However, Linux's manual page says in its NOTES section:
memalign() may not check that the boundary parameter is correct.
This is descriptive rather than prescriptive, but applications with
bad assumptions about memalign() exist, so be as forgiving as possible.
Reported by Mike Hommey.
-rw-r--r-- | src/jemalloc.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/jemalloc.c b/src/jemalloc.c index a3a9a70..535efaa 100644 --- a/src/jemalloc.c +++ b/src/jemalloc.c @@ -68,7 +68,8 @@ static void malloc_conf_error(const char *msg, const char *k, size_t klen, const char *v, size_t vlen); static void malloc_conf_init(void); static bool malloc_init_hard(void); -static int imemalign(void **memptr, size_t alignment, size_t size); +static int imemalign(void **memptr, size_t alignment, size_t size, + bool enforce_min_alignment); /******************************************************************************/ /* malloc_message() setup. */ @@ -900,7 +901,8 @@ JEMALLOC_ATTR(nonnull(1)) JEMALLOC_ATTR(noinline) #endif static int -imemalign(void **memptr, size_t alignment, size_t size) +imemalign(void **memptr, size_t alignment, size_t size, + bool enforce_min_alignment) { int ret; size_t usize; @@ -919,7 +921,7 @@ imemalign(void **memptr, size_t alignment, size_t size) /* Make sure that alignment is a large enough power of 2. */ if (((alignment - 1) & alignment) != 0 - || alignment < sizeof(void *)) { + || (enforce_min_alignment && alignment < sizeof(void *))) { if (config_xmalloc && opt_xmalloc) { malloc_write("<jemalloc>: Error in " "posix_memalign(): invalid alignment\n"); @@ -991,7 +993,7 @@ int JEMALLOC_P(posix_memalign)(void **memptr, size_t alignment, size_t size) { - return imemalign(memptr, alignment, size); + return imemalign(memptr, alignment, size, true); } JEMALLOC_ATTR(malloc) @@ -1249,7 +1251,7 @@ JEMALLOC_P(memalign)(size_t alignment, size_t size) = NULL #endif ; - imemalign(&ret, alignment, size); + imemalign(&ret, alignment, size, false); return (ret); } #endif @@ -1265,7 +1267,7 @@ JEMALLOC_P(valloc)(size_t size) = NULL #endif ; - imemalign(&ret, PAGE_SIZE, size); + imemalign(&ret, PAGE_SIZE, size, false); return (ret); } #endif |