mirror of
https://github.com/espressif/tlsf.git
synced 2025-11-16 12:34:46 +00:00
feat(tlsf): Add function to find a block from a pointer
This commit is contained in:
@@ -63,6 +63,15 @@ void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user);
|
|||||||
int tlsf_check(tlsf_t tlsf);
|
int tlsf_check(tlsf_t tlsf);
|
||||||
int tlsf_check_pool(pool_t pool);
|
int tlsf_check_pool(pool_t pool);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Find the block containing the pointer passed as parameter
|
||||||
|
*
|
||||||
|
* @param pool The pool into which to look for the block
|
||||||
|
* @param ptr The pointer we want to find the containing block of
|
||||||
|
* @return void* The pointer to the containing block if found, NULL if not.
|
||||||
|
*/
|
||||||
|
void* tlsf_find_containing_block(pool_t pool, void *ptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Weak function called on every free block of memory allowing the user to implement
|
* @brief Weak function called on every free block of memory allowing the user to implement
|
||||||
* application specific checks on the memory.
|
* application specific checks on the memory.
|
||||||
|
|||||||
20
tlsf.c
20
tlsf.c
@@ -710,3 +710,23 @@ void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size)
|
|||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* tlsf_find_containing_block(pool_t pool, void *ptr)
|
||||||
|
{
|
||||||
|
block_header_t* block = offset_to_block(pool, -(int)block_header_overhead);
|
||||||
|
|
||||||
|
while (block && !block_is_last(block))
|
||||||
|
{
|
||||||
|
if (!block_is_free(block)) {
|
||||||
|
void *block_end = block_to_ptr(block) + block_size(block);
|
||||||
|
if (block_to_ptr(block) <= ptr && block_end > ptr) {
|
||||||
|
// we found the containing block, return
|
||||||
|
return block_to_ptr(block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
block = block_next(block);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user