History log of /seL4-refos-master/libs/libmuslc/src/malloc/memalign.c
Revision Date Author Comments
# 4a30ba5c 23-Jul-2013 Rich Felker <dalias@aerifal.cx>

remove redundant check in memalign

the case where mem was already aligned is handled earlier in the
function now.


# 70a92bc9 23-Jul-2013 Rich Felker <dalias@aerifal.cx>

fix heap corruption bug in memalign

this bug was caught by the new footer-corruption check in realloc and
free.

if the block returned by malloc was already aligned to the desired
alignment, memalign's logic to split off the misaligned head was
incorrect; rather than writing to a point inside the allocated block,
it was overwriting the footer of the previous block on the heap with
the value 1 (length 0 plus an in-use flag).

fortunately, the impact of this bug was fairly low. (this is probably
why it was not caught sooner.) due to the way the heap works, malloc
will never return a block whose previous block is free. (doing so would
be harmful because it would increase fragmentation with no benefit.)
the footer is actually not needed for in-use blocks, except that its
in-use bit needs to remain set so that it does not get merged with
free blocks, so there was no harm in it being set to 1 instead of the
correct value.

however, there is one case where this bug could have had an impact: in
multi-threaded programs, if another thread freed the previous block
after memalign's call to malloc returned, but before memalign
overwrote the previous block's footer, the resulting block in the free
list could be left in a corrupt state. I have not analyzed the impact
of this bad state and whether it could lead to more serious
malfunction.


# 6d861ac8 04-Jul-2013 Rich Felker <dalias@aerifal.cx>

move core memalign code from aligned_alloc to __memalign

there are two motivations for this change. one is to avoid
gratuitously depending on a C11 symbol for implementing a POSIX
function. the other pertains to the documented semantics. C11 does not
define any behavior for aligned_alloc when the length argument is not
a multiple of the alignment argument. posix_memalign on the other hand
places no requirements on the length argument. using __memalign as the
implementation of both, rather than trying to implement one in terms
of the other when their documented contracts differ, eliminates this
confusion.


# 9bff7c13 25-Aug-2012 Rich Felker <dalias@aerifal.cx>

implement "low hanging fruit" from C11

based on Gregor's patch sent to the list. includes:
- stdalign.h
- removing gets in C11 mode
- adding aligned_alloc and adjusting other functions to use it
- adding 'x' flag to fopen for exclusive mode


# 0b44a031 11-Feb-2011 Rich Felker <dalias@aerifal.cx>

initial check-in, version 0.5.0