diff options
author | Bruno Haible <bruno@clisp.org> | 2018-02-02 19:32:02 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2018-02-02 19:32:02 +0100 |
commit | 8a4aa2ec86c0e94c6ed548519b1660c6b1bac0c1 (patch) | |
tree | 82db5e78ebd3a58a720ca0759b31d0a3edbf2c55 /lib/xmalloca.h | |
parent | cf56f8f618c48cfadd2499ced58574633d12f129 (diff) | |
download | gnulib-8a4aa2ec86c0e94c6ed548519b1660c6b1bac0c1.tar.gz |
malloca, xmalloca: Make multithread-safe.
Reported by Florian Weimer <fweimer@redhat.com>.
Implements an idea by Ondřej Bílka <neleai@seznam.cz>.
* lib/malloca.h (malloca): In the stack allocation case, return a
pointer that is a multiple of 2 * sa_alignment_max.
(sa_increment): Remove enum item.
* lib/xmalloca.h (xmalloca): In the stack allocation case, return
a pointer that is a multiple of 2 * sa_alignment_max.
* lib/malloca.c (NO_SANITIZE_MEMORY): Remove macro.
(MAGIC_NUMBER, MAGIC_SIZE, preliminary_header, HEADER_SIZE, header,
HASH_TABLE_SIZE, mmalloca_results): Remove.
(small_t): New type.
(mmalloca, free): Rewritten.
* lib/malloca.valgrind: Remove file.
* modules/malloca (Files): Remove it.
(Depends-on): Remove verify.
Diffstat (limited to 'lib/xmalloca.h')
-rw-r--r-- | lib/xmalloca.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/xmalloca.h b/lib/xmalloca.h index 456f25b5f1..14fc1b9dcc 100644 --- a/lib/xmalloca.h +++ b/lib/xmalloca.h @@ -32,8 +32,10 @@ extern "C" { the function returns. Upon failure, it exits with an error message. */ #if HAVE_ALLOCA # define xmalloca(N) \ - ((N) < 4032 - sa_increment \ - ? (void *) ((char *) alloca ((N) + sa_increment) + sa_increment) \ + ((N) < 4032 - (2 * sa_alignment_max - 1) \ + ? (void *) (((uintptr_t) alloca ((N) + 2 * sa_alignment_max - 1) \ + + (2 * sa_alignment_max - 1)) \ + & ~(uintptr_t)(2 * sa_alignment_max - 1)) \ : xmmalloca (N)) extern void * xmmalloca (size_t n); #else |