Commit graph

42 commits

Author SHA1 Message Date
Scott Shawcroft
5481d1cafe
Stop setting next_free because it doesn't exist in used blocks and may be out of bounds 2024-08-12 13:12:27 -07:00
Scott Shawcroft
108a2a7dfc
Fix adding pool with non-zeroed memory 2024-04-12 13:22:04 -07:00
Scott Shawcroft
875a162884
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-03-11 12:25:38 -07: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
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
matt conte
16b6a9657d
Merge pull request #2 from ralphyon/master
Fix block_size_max handling in adjust_request_size
2018-02-21 22:06:57 -08:00
Vitor Menezes
72601dd683 Protect against large sizes resulting in off-the-end free blocks 2017-05-11 00:04:48 -07:00
Martin Dufour
2b73b8a482 Fix block_size_max handling in adjust_request_size
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.
2016-08-01 07:51:11 -04:00
matthew conte
7d6c9a78da Fix broken link, placeholder text in copyright. 2016-04-11 17:08:29 -07:00
matthew conte
bd50675b3c Fix it so it really compiles this time. 2016-04-11 16:59:11 -07:00
matthew conte
9620facc84 Fix tlsf.c so it compiles. 2016-04-11 16:57:49 -07:00
matthew conte
a7e1d103d1 Fix broken link. 2016-04-11 16:54:46 -07:00
matthew conte
a9c9020812 Merge pull request #1 from salkinium/master
Fix [-Wstrict-prototypes] warnings.
2016-04-11 15:07:47 -07:00
Niklas Hauser
757298305a Fix [-Wstrict-prototypes] warnings. 2016-04-11 21:13:44 +01:00
matthew conte
8b7c441ecf Added files via upload
Add tlsf.h, tlsf.c, version 3.1.
2016-04-10 15:02:17 -07:00
matthew conte
265a6c3798 Update README.md 2016-04-10 15:01:34 -07:00
matthew conte
150d9f97aa Update README.md 2016-04-10 15:01:07 -07:00
mattconte
cee96d6b9c Initial commit 2015-05-26 11:31:33 -07:00