It needs to include the rounding done by `mapping_search()`
otherwise we'll trim the block too much and not be able to
re-allocate the same amount of space after the block is freed.
In the paper's version of mapping_search, this is subtle because
r is marked as "in out". http://www.gii.upv.es/tlsf/files/papers/jrts2008.pdf
To reproduce:
* Allocate an amount that is rounded up.
* Allocate a second block that takes up the remaining space. This
prevents the second allocation from occurring in a new spot.
* Free the first block.
* Allocate the first amount a second time. It will fail without this
change even though the requested space is actually available because the
free block was added to the non-rounded segmented list.
- the control_t structure should not be available to the user so it
was moved to tlsf.c. In addition bitfields are now used in control_t
when possible which reduces the size of the structure from 56 bytes
to 36 bytes.
- fix an assert message to place it in the tlsf_assert
- add comment about the index count log2 field in control_t
The calculation of fl index max is changed to always be the smallest
number that includes the size of the registered memory.
The control_construct() function now checks for minimum size as the control structure
parameters are calculated.
There is no longer a minimum configuration for fl index max so the tlsf_config
enum is striped down to remove unecessary compile time values.
the tlsf_size() function will fail if no tlsf pointer is passed as parameter since there
is no way to calculate a default tlsf size anymore.
In this commit:
The call to tlsf_asssert is removed from tlsf_insist to allow the tlsf_check()
function to return when one or more of the tlsf_insist() calls fails. In the previous
implementation any failing tlsf_assist() was causing the tlsf_assert to terminate the
execution of the application which doesn't allow the user to handle failures in tlsf_check()
eventhough tlsf_check() returns a value.
In this commit:
- We add a weak delcaration of tlsf_check_hook() in tlsf.h.
- We call tlsf_check_hook() in tlsf_check() if the function has a defintion
This hook function allows the user to implement application specific checks on
the memory of every free blocks (e.g. check for memory corruption).
Note: block_absorb() is called in tlsf_free(), which is eventually called in multi_heap_free()
after the memory fill is done. As the block_absorb merges 2 blocks together, the previous block
header of the merged block is now in the middle of the memory block but not filled with 0xfe.
- Remove dependencies with the heap component of the IDF.
- The tlsf_poison_fill_region_hook() function is defined as weak in IDF and checked for NULL
in block_absorb() function in order to minimize the dependencies between IDF and the TLSF.
- The the implementation of tlsf_poison_fill_region_hook() must be provided at the discretion
of the user.
In the 64-bit build, an allocation of request in the range
]block_size_max-ALIGN_SIZE,block_size_max[ could cause an out-of-bounds
access to sl_bitmap.