Compare commits
4 commits
circuitpyt
...
idf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ddfa052fbf | ||
|
|
32701a163d | ||
|
|
d2e28f8724 | ||
|
|
262d11fcfa |
1 changed files with 31 additions and 27 deletions
58
tlsf.c
58
tlsf.c
|
|
@ -668,14 +668,32 @@ static void integrity_walker(void* ptr, size_t size, int used, void* user)
|
|||
const size_t this_block_size = block_size(block);
|
||||
|
||||
int status = 0;
|
||||
(void)used;
|
||||
tlsf_insist(integ->prev_status == this_prev_status && "prev status incorrect");
|
||||
tlsf_insist(size == this_block_size && "block size incorrect");
|
||||
|
||||
if (tlsf_check_hook != NULL)
|
||||
{
|
||||
/* block_size(block) returns the size of the usable memory when the block is allocated.
|
||||
* As the block under test is free, we need to subtract to the block size the next_free
|
||||
* and prev_free fields of the block header as they are not a part of the usable memory
|
||||
* when the block is free. In addition, we also need to subtract the size of prev_phys_block
|
||||
* as this field is in fact part of the current free block and not part of the next (allocated)
|
||||
* block. Check the comments in block_split function for more details.
|
||||
*/
|
||||
const size_t actual_free_block_size = used ? this_block_size :
|
||||
this_block_size - offsetof(block_header_t, next_free)- block_header_overhead;
|
||||
|
||||
void* ptr_block = used ? (void*)block + block_start_offset :
|
||||
(void*)block + sizeof(block_header_t);
|
||||
|
||||
tlsf_insist(tlsf_check_hook(ptr_block, actual_free_block_size, !used));
|
||||
}
|
||||
|
||||
integ->prev_status = this_status;
|
||||
integ->status += status;
|
||||
}
|
||||
|
||||
|
||||
int tlsf_check(tlsf_t tlsf)
|
||||
{
|
||||
int i, j;
|
||||
|
|
@ -722,23 +740,6 @@ int tlsf_check(tlsf_t tlsf)
|
|||
mapping_insert(control, block_size(block), &fli, &sli);
|
||||
tlsf_insist(fli == i && sli == j && "block size indexed in wrong list");
|
||||
|
||||
if (tlsf_check_hook != NULL)
|
||||
{
|
||||
/* block_size(block) returns the size of the usable memory when the block is allocated.
|
||||
* As the block under test is free, we need to subtract to the block size the next_free
|
||||
* and prev_free fields of the block header as they are not a part of the usable memory
|
||||
* when the block is free. In addition, we also need to subtract the size of prev_phys_block
|
||||
* as this field is in fact part of the current free block and not part of the next (allocated)
|
||||
* block. Check the comments in block_split function for more details.
|
||||
*/
|
||||
const size_t actual_free_block_size = block_size(block)
|
||||
- offsetof(block_header_t, next_free)
|
||||
- block_header_overhead;
|
||||
|
||||
tlsf_insist(tlsf_check_hook((void*)block + sizeof(block_header_t),
|
||||
actual_free_block_size, is_block_free));
|
||||
}
|
||||
|
||||
block = block->next_free;
|
||||
}
|
||||
}
|
||||
|
|
@ -794,17 +795,20 @@ int tlsf_check_pool(pool_t pool)
|
|||
|
||||
size_t tlsf_fit_size(tlsf_t tlsf, size_t size)
|
||||
{
|
||||
/* because it's GoodFit, allocable size is one range lower */
|
||||
if (size && tlsf != NULL)
|
||||
{
|
||||
size_t sl_interval;
|
||||
control_t* control = tlsf_cast(control_t*, tlsf);
|
||||
sl_interval = (1 << (32 - __builtin_clz(size) - 1)) / control->sl_index_count;
|
||||
return size & ~(sl_interval - 1);
|
||||
if (size == 0 || tlsf == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
control_t* control = tlsf_cast(control_t*, tlsf);
|
||||
if (size < control->small_block_size) {
|
||||
return adjust_request_size(tlsf, size, ALIGN_SIZE);
|
||||
}
|
||||
|
||||
/* because it's GoodFit, allocable size is one range lower */
|
||||
size_t sl_interval;
|
||||
sl_interval = (1 << (32 - __builtin_clz(size) - 1)) / control->sl_index_count;
|
||||
return size & ~(sl_interval - 1);
|
||||
}
|
||||
|
||||
/*
|
||||
** Size of the TLSF structures in a given memory block passed to
|
||||
|
|
|
|||
Loading…
Reference in a new issue