Commit Graph

63 Commits

Author SHA1 Message Date
Guillaume Souchere
2867f6883a Merge branch 'fix/pointer-compatibility-64bit-target' into 'idf'
fix(tlsf): Use "uintptr_t" for 64-bit targets

Closes IDFGH-15045

See merge request espressif/tlsf!16
2025-04-08 15:12:18 +08:00
Guillaume Souchere
ee35b71f5c Merge branch 'feat/add-block-finding-function' into 'idf'
feat(tlsf): Add function to find a block from a pointer

See merge request espressif/tlsf!15
2025-04-04 15:11:08 +08:00
Guillaume Souchere
791878ead2 feat(tlsf): Add function to find a block from a pointer 2025-04-03 08:29:46 +02:00
Jeff Epler
6ecac2d0bc Use "uintptr_t" for 64-bit targets
On 64-bit targets, casting from pointer to unsigned can lose data.
Instead, cast to uintptr_t. This causes no code change on 32-bit
platforms, since the types have the same width, but preserves all bits
on systems where pointers are 64 bits.
2025-02-10 08:26:09 -06:00
Guillaume Souchere
ba64d198a8 Merge branch 'fix/rename-include-folder-to-private' into 'idf'
feat(tlsf): Update the architecture to keep only public headers in the include folder

See merge request espressif/tlsf!14
2024-09-16 15:01:12 +08:00
Guillaume Souchere
bc61bdf94f fix(tlsf): Place only public header in include folder
The tlsf_control_functions.h and tlsf_block_functions.h
are moved to the root dir.

The tlsf.h header (the only public header has it contains
the public API) is kept in include folder.

The tlsf_common.h header is  deleted and its content is
split accross all header files since this file was originally
containain the definition of structures such as block_header_t
and control_t that can now be moved to tlsf_block_functions.h
(respectively tlsf_control_functions.h).
2024-09-04 13:32:00 +02:00
Guillaume Souchere
64170ec611 Merge branch 'feat/move-inline-in-header' into 'idf'
feat(tlsf): Create header for remaining static inline functions

See merge request espressif/tlsf!13
2024-08-29 16:38:30 +08:00
Guillaume Souchere
e45fc9bfbb feat(tlsf): Create header for static inline functions
Place all the remaining static inline function in a separate header
Move all headers in an include folder
2024-08-29 09:34:14 +02:00
Guillaume Souchere
ea82911f4c Merge branch 'fix/block_allocation_size' into 'idf'
Fix block allocation size

See merge request espressif/tlsf!12
2024-08-09 15:56:53 +08:00
Scott Shawcroft
c499512eed Fix adding pool with non-zeroed memory 2024-08-08 13:13:31 +02:00
Scott Shawcroft
0c8ce8f470 Fix assertion error due to zero length allocation
The original code missed a * to check the value of size for
non-zero. This corrects that error and adds an additional check
after the first alignment.
2024-08-08 13:13:08 +02:00
Guillaume Souchere
36e304a5d4 Merge branch 'feature/add-repository-integrations' into 'idf'
Add repository integrations (by Create-project-tools)

See merge request espressif/tlsf!11
2024-07-31 18:08:01 +08:00
Guillaume Souchere
3862836df0 ci(repo-integrations): Update component name to heap 2024-07-31 12:06:35 +02:00
Espressif BOT
be2197443c ci(repo-integrations): Add repository integrations (by Create-project-tools) 2024-07-31 15:16:27 +08:00
Guillaume Souchere
8fc595fe22 Merge branch 'fix/tlsf_walk_pool' into 'idf'
fix(tlsf): Fix while loop in walker

See merge request espressif/tlsf!10
2024-03-20 13:17:05 +08:00
Guillaume Souchere
817349ad39 fix(tlsf): Fix while loop in walker
Exit the loop before getting the next block if the
pool_walker returns false.
2024-03-19 13:51:43 +01:00
Guillaume Souchere
e282f0be5a Merge branch 'feat/add-return-value-to-walker' into 'idf'
change(tlsf): Add return value to tlsf_walker

See merge request espressif/tlsf!9
2024-03-19 15:35:55 +08:00
Guillaume Souchere
53a42a2c1a Merge branch 'feat/add-malloc-with-address' into 'idf'
feat(tlsf): Add a function to malloc at a given address

See merge request espressif/tlsf!8
2024-03-06 16:52:33 +08:00
Guillaume Souchere
b2f44c4bf3 feat(tlsf): Add a function to malloc at a given address
The function will find a suitable free block that can contain
the malloc size at the given address in the memory pool, split
the free block to create the block that will contain the allocated
memory, update the status of the newly created blocks (free / used)
and return the pointer to the memory allocated at the given address.

If no block is found (the status of the heap doesn't allow for an
allocation at the given address) the function will return NULL.
2024-03-06 07:33:08 +01:00
Scott Shawcroft
81d3779545 Fix block allocation size
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.
2024-03-04 16:13:26 -08:00
Guillaume Souchere
84048e02ba change(tlsf): Add return value to tlsf_walker
This commit adds a return boolean value to the tlsf_walker
function allowing users to interrupt the traversal of the
pool when returning from any call to the tlsf_walker.
2024-02-27 12:27:38 +01:00
Guillaume Souchere
ddfa052fbf Merge branch 'fix/tlsf_fit_size_for_small_size' into 'idf'
fix(tlsf): tlsf_fit_size GoodFit should not be applied for small block size

See merge request espressif/tlsf!7
2024-01-16 17:11:06 +08:00
Guillaume Souchere
32701a163d fix(tlsf): tlsf_fit_size GoodFit
The good fit mechanism should not be applied for small blocks.
If the size in parameter is inferior to control->small_block_size.
then the function tlsf_fit_size should return size directly.
2024-01-16 07:42:58 +01:00
Guillaume Souchere
d2e28f8724 Merge branch 'fix/call_check_hook_for_all_blocks' into 'idf'
tlsf: call the tlsf_check_hook from intergrity_walker to check all blocks

See merge request espressif/tlsf!6
2023-10-16 16:18:01 +08:00
Guillaume Souchere
262d11fcfa tlsf: move the call the tlsf_check_hook from tlsf_check to the intergrity_walker function
Previously the hook was called from tlsf_check function leading to only check the free blocks
and leaving the used blocks unchecked by the hook. By moving the function hook call to the
integrity_walker function, free and used blocks are now passed to the function hook.
2023-09-27 13:22:02 +02:00
Guillaume Souchere
8c9cd0517a Merge branch 'feature/inline-ffs-and-fls-functions' into 'idf'
tlsf: inline the tlsf_ffs and tlsf_fls functions for C compilation

See merge request espressif/tlsf!5
2022-11-14 14:03:41 +08:00
Guillaume Souchere
ab830e0595 tlsf: inline the tlsf_ffs and tlsf_fls functions for C compilation 2022-11-11 08:31:07 +01:00
Guillaume Souchere
13da0fff7f Merge branch 'feature/dynamic-control-size' into 'idf'
tlsf: allow each heap to have different control block

See merge request espressif/tlsf!4
2022-10-25 13:19:48 +08:00
Guillaume Souchere
1ca1da2407 tlsf: move control_t to tlsf.c
- 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
2022-10-21 11:14:44 +02:00
Guillaume Souchere
eaa11bbf5d tlsf: fix input validation of tlsf_t parameter and comment tlsf_fit_size() 2022-10-19 07:53:06 +02:00
Guillaume Souchere
049f54327a tlsf: update calculation of fl index max
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.
2022-10-18 07:39:44 +02:00
X-Ryl669
b13ce2f6bc Fix for long lines in asserts from Guillaume Souchere
Signed-off-by: X-Ryl669 <boite.pour.spam@gmail.com>
2022-10-12 16:08:12 +02:00
X-Ryl669
4d43b0df1c Multiple heap TLSF 2022-09-20 10:22:27 +02:00
Guillaume Souchere
ab17d6798d Merge branch 'feature/add-missing-comment-tlsf-check-hook' into 'idf'
Add missing doxygen comments on the tlsf_check_hook() declaration

See merge request espressif/tlsf!3
2022-08-25 18:03:08 +08:00
Guillaume Souchere
83dac36eda Add missing doxygen comments on the tlsf_check_hook() declaration 2022-08-25 11:57:43 +02:00
Guillaume Souchere
f71c4077d4 Merge branch 'feature/add-hook-in-tlsf-check' into 'idf'
Provide a function hook in tlsf_check()

See merge request espressif/tlsf!2
2022-08-25 00:04:28 +08:00
Guillaume Souchere
0fcb10c71a Remove the call to tlsf_assert in the tlsf_insist maccro
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.
2022-08-10 08:26:12 +02:00
Guillaume Souchere
9393b12cac Add a function hook called in tlsf_check() on every free block of memory
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).
2022-08-10 08:26:10 +02:00
Guillaume Souchere
ff11688f24 Incorporate wrong chunk size bugfix
See 9516fd09c2
for more details.
2022-07-29 09:39:58 +02:00
Ivan Grokhotkov
1968e04261 introduce tlsf_memalign_offs
Initial commit: d902b4e7db
2022-07-29 09:39:32 +02:00
Ivan Grokhotkov
b76f0fefd1 Add heap poisoning mechanism to fill absorbed block header with the right pattern.
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.
2022-07-26 14:40:25 +02:00
Ivan Grokhotkov
1322e839d2 add some comments to block_split and block_trim_free_leading 2022-07-26 14:40:25 +02:00
Guillaume Souchere
7d2c0f2264 Inline functions in tlsf.c and tlsf_block_functions.h
Use the attribute __attribute__((always_inline)).
2022-07-26 14:40:23 +02:00
Guillaume Souchere
81cecf2e0d move block_header_t, control_t, tlsfptr_t to tlsf_common.h and block function to tlsf_block_functions.h 2022-07-26 14:39:07 +02:00
Ivan Grokhotkov
bfd855894d move tlsf_min, tlsf_max, tlsf_cast to the tlsf_common.h header file 2022-07-26 14:38:30 +02:00
Ivan Grokhotkov
6723d4fc98 tlsf_public and tlsf_private moved to tlsf_config enum in tlsf_common.h header 2022-07-26 14:38:30 +02:00
Ivan Grokhotkov
1f77a1d2a1 add tlsf_block_functions.h and tlsf_common.h files 2022-07-26 14:38:30 +02:00
Ivan Grokhotkov
61bbda7f4a move includes to tlsf.c, add license 2022-07-25 12:45:58 +02:00
Matt Conte
deff9ab509 Update tlsf.c
Unsigned fix from Chris McEvoy @ Velan Studios.
2020-03-29 09:55:11 -07:00
matt conte
a1f743ffac Merge pull request #3 from velvitonator/large-alloc-corruption
Protect against large sizes resulting in off-the-end free blocks
2018-02-21 22:07:31 -08:00