• Paul Eggert's avatar
    Memory allocator alignment fixes · 7fcce24e
    Paul Eggert authored
    These changes remove some assumptions about heap allocator
    alignment that may not be true on unusual platforms.
    * src/alloc.c (POWER_OF_2): New macro.
    (ROUNDUP): Use it.
    (BLOCK_ALIGN): Verify that it is a power of 2.
    (aligned_alloc): Check that alignment passed to posix_memalign
    satisfies POSIX restrictions.
    (lisp_align_malloc): Check that size passed to aligned_alloc
    satisfies C11 restrictions.
    (MALLOC_IS_GC_ALIGNED): Check that GCALIGNMENT is 8, since the
    code has not been verified to work with other GCALIGNMENT values
    and the ice is thin here.  On GNU/Linux, malloc can return a value
    that is a multiple of 8 but not 16, even though __alignof__
    (max_align_t) is 16.  See:
    https://gcc.gnu.org/ml/gcc-patches/2016-08/msg01902.html
    (lmalloc) [USE_ALIGNED_ALLOC]: Use aligned_alloc only if size
    is a multiple of alignment, since C11 says the behavior is
    undefined otherwise.
    (lmalloc, lrealloc): Don't use INT_ADD_WRAPV on size_t, as in
    general this macro is restricted to signed types.  Remove
    assertion that the result is a multiple of GCALIGNMENT, as that
    need not be true.
    7fcce24e
alloc.c 200 KB