Commit Graph

277 Commits

Author SHA1 Message Date
Guillaume Souchere
cdf5414302 fix(heap): Wrong size propagated in alloc fail callback
Propagate `n * size` as the size of the failed allocation
instead of just `size` when heap_caps_calloc() fails since
`n * size` is the actual number of bytes that the heap
component tried to allocate.
2024-04-08 08:45:18 +02:00
Guillaume Souchere
d8a8149abd fix(heap): Patch tlsf_check_pool in ROM heap
The integrity_walker now calls the integrity check hook to control
free AND used blocks of memory in the TLSF pool. This integrity walker
function is called from tlsf_check_pool.

This commit creates a patch of integrity_walker function to update the
outdated implementation in the ROM.
2023-11-02 09:04:24 +01:00
Guillaume Souchere
825f99f16e fix(heap): Fixed integrity check on used blocks by the tlsf component
This commit updates the tlsf submodule to include the modification made in the component
aiming to perform integrity check on all blocks (not only the free ones).
Added test to test the fix in test_apps/heap_tests.

Fixes https://github.com/espressif/esp-idf/issues/12231
2023-11-02 08:21:06 +01:00
KonstantinKondrashov
031af815da esp_hw_support: Fix invalid system time if s_esp_rtc_time_us & s_rtc_last_ticks were moved around
The commit fixes the case:
If variables in RTC RAM have been moved around by the linker,
they will be filled with garbage data. Any reset other than OTA would work fine
because the variables would still be initialized from the initial bootup.

So now system time will be valid even after OTA.

Closes https://github.com/espressif/esp-idf/issues/9448
2023-07-13 18:30:26 +08:00
Guillaume Souchere
2ea046c091 heap: Fix erroneous value returned by heap_caps_get_allocated_size() when poisoning is enabled
When light (or comprehensive) poisoning is enabled, the size requested by the user for allocation
is extended by a few bytes to store the canary header and footer. heap_caps_get_allocated_size() should
return the original size asked by the user (without the additional canary bytes).

test_malloc.c extended with a new test assuring that  heap_caps_get_allocated_size() returns the proper size
regardless of the degree of poisoning.
2023-02-22 11:42:02 +01:00
Marius Vikhammer
18bda1be31 Merge branch 'feature/re-enable-heap-test-c2_v5.0' into 'release/v5.0'
heap: re-enable temporarily disabled test on esp32c2 (backport v5.0)

See merge request espressif/esp-idf!21873
2023-02-20 15:34:16 +08:00
Marius Vikhammer
5b718a81a0 Merge branch 'feat/verbose-alloc-failure-abort_v5.0' into 'release/v5.0'
heap: print size and caps when malloc fails before calling system abort (backport v5.0)

See merge request espressif/esp-idf!22343
2023-02-20 15:17:51 +08:00
Guillaume Souchere
6e35b1eba3 heap: Fix priority in shex() bit shift 2023-02-13 09:03:32 +01:00
Chip Weinberger
6ed2371bd1 [Logs] print size and caps when malloc fails 2023-02-13 09:02:59 +01:00
Guillaume Souchere
41fd87fd89 heap: Modify the memory type of the memory used as startup stack when memory protection is enabled
If memory protection is enabled on esp32c3 and esp32s3, we don't want to the heap component to see
the startup stack memory as D/IRAM but as DRAM only. Introduce a new type to make this possible in
the same fashion the regular D/IRAM regions are handled.
2023-01-31 07:40:20 +01:00
Guillaume Souchere
327bf0d608 heap: RE-enable ESP32C2 test in test_apps 2023-01-03 09:52:33 +01:00
Zim Kalinowski
6972b61ea5 Merge branch 'staging/esp_static_assert_v5.0' into 'release/v5.0'
C/Cxx: unify static assertions with the macro ESP_STATIC_ASSERT (backport v5.0)

See merge request espressif/esp-idf!21695
2022-12-20 20:53:02 +08:00
Jiang Jiang Jian
c173845ff3 Merge branch 'feature/tlsf-dynamic-control-size_v5.0' into 'release/v5.0'
heap: Update to the new tlsf implementation of dynamic metadata size (backport v5.0)

See merge request espressif/esp-idf!20774
2022-12-20 13:51:07 +08:00
Omar Chebib
0714847552 C/Cxx: unify static assertions with the macro ESP_STATIC_ASSERT
Closes https://github.com/espressif/esp-idf/issues/9938
2022-12-19 15:06:15 +01:00
Guillaume Souchere
72e7cbee88 heap: Remove size check in multi_heap.c when registering a new heap
The tlsf now checks for size validity when creating a new heap.

The check previously done in multi_heap_register_impl() is no longer
valid since the tlsf_size() is not known at this time (as the metadata
size is linked ot the size of the memory region passed as parameter
when calling tlsf_create_with_pool())

The tlsf_create_with_pool() will return a null pointer if the size
of the memory is not big enough to hold the metadata overhead and
at least a small block.

Update the test according to the changes in TLSF API
2022-12-14 12:37:23 +01:00
Guillaume Souchere
47dc520538 heap: Update host tests after incorporation of the new TLSF implementation 2022-12-14 12:37:23 +01:00
Guillaume Souchere
6c926ab7b0 heap: Update the component to incorporate the new TLSF implementation
- remove tlsf_platform.h from esp-idf since the fl_index is now calculated
  based on the size of the requested heap
- update CMakeLists.txt accordingly
2022-12-14 12:37:23 +01:00
Guillaume Souchere
be74fd1e8c heap: fix linker issues and remove spi flash dependencies 2022-12-14 12:37:23 +01:00
Guillaume Souchere
35260d4325 feat: remove tlsf_fls and tlsf_ffs from linker as they are inlined. 2022-12-14 12:37:23 +01:00
Guillaume Souchere
c47ea5d2bb tools: update list of references to not include symbold used by __assert_func calls
On xtensa architecture, the call to __assert_func uses a reference to __func__ that can
sometimes be placed in flash. Since the __asert_func can be called from functions in IRAM
the check_callgraph script can report an error when checking for invalid calls from IRAM
to flash sections. However, the __asert_func prevents this scenario at runtime so the
check_callgraph script reports a 'flas positive' situation. For this reasson, all references
to __func__$x found prior to a call to __assert_func are droped in the parsing of the rtl files.
2022-12-14 12:37:23 +01:00
Guillaume Souchere
e92250e6a2 heap: add check for usage of flash content from iram
this commits:
- adds build-time test to check that no call to flash regions are done from IRAM functions

- resolves problems related to IRAM function using content in flash memory

- update heap_caps_alloc_failed to use a default function name in DRAM
  when necessary instead of creating a function name variable in DRAM for
  each call of heap_caps_alloc_failed. This allows to save some extra bytes
  in RAM.
2022-12-14 12:37:16 +01:00
Zim Kalinowski
23dda413a5 Merge branch 'fix/add-region-allowed-checks_v5.0' into 'release/v5.0'
heap: Fix memory boundary condition checks when adding new region (backport v5.0)

See merge request espressif/esp-idf!20557
2022-12-09 17:27:39 +08:00
Jiang Jiang Jian
ff88f19ddd Merge branch 'feature/add_rom_tlsf_function_prototype_v5.0' into 'release/v5.0'
esp_rom: add rom tlsf function prototype instead of void * (backport to v5.0)

See merge request espressif/esp-idf!20684
2022-12-02 19:52:51 +08:00
Guillaume Souchere
755dded0f5 heap: add documentation about the function placement in IRAM and its usage in ISR
This commits adds a internal.md file in the heap directory to clarify the idea behind
which functions is placed in IRAM or in flash.

A section in mem_alloc.rst documentation is added to specify which functions from the
heap component API can be used in interrupt handlers.
2022-11-24 12:40:00 +01:00
Guillaume Souchere
47cfd0a0d8 heap: add selective placement of function in IRAM
This commit aims to place in the IRAM section only the functions that
are relevent for performance instead of placing the entire content of
multi_heap.c, mullti_heap_poisoning.c and tlsf.c in the IRAM.
2022-11-24 12:39:46 +01:00
Martin Vychodil
af81bd1b0a Storage: Partition APIs moved to the new component 'esp_partition'
All the partition handling API functions and data-types were moved from the 'spi_flash' component to the new one named 'esp_partition'. See Storage 5.x migration guide for more details
2022-11-02 21:49:08 +01:00
jiangguangming
bc3bf04af7 esp_rom: add rom tlsf function prototype instead of void * 2022-10-19 19:35:39 +08:00
Guillaume Souchere
5ec5faf02f heap: Fix memory boundary condition checks when adding new region
Previously, condition_4 was making impossible the valid scenario
start > heap_start && end == heap_end.

Now, the end == heap_end and start == heap_start case is handled
separately allowing the case start > heap_start && ned == heap_end
to be considered a valid scenario
2022-10-12 08:17:50 +02:00
Jiang Jiang Jian
aad557d70b Merge branch 'feature/mem-corruption-check-when-comprehensif-poisoning_v5.0' into 'release/v5.0'
heap: provide the tlsf_check_hook() definition to implement a check of memory corruption (v5.0)

See merge request espressif/esp-idf!19779
2022-09-19 11:04:44 +08:00
Jiang Jiang Jian
c111b94057 Merge branch 'contrib/github_pr_9517_v5.0' into 'release/v5.0'
fix malloc(0) and heap_caps_alloc_failed() (backport v5.0)

See merge request espressif/esp-idf!19795
2022-09-14 13:50:33 +08:00
Omar Chebib
2e897c2e74 TLSF: fix the patch for tlsf_check function in ROM
tlsf_check in the patch was not called because the the TLSF functions
table in ROM was still pointing to the ROM implementation.
2022-09-13 14:20:39 +02:00
Guillaume Souchere
860232bdaf heap: Add test to check that the corruption of free memory is detected
This commit extends the heap test set by adding a test to check corruption
detection in free memory block.

For each byte of the free block memory, the test changes the value of the byte,
call multi_heap_check(), make sure that the function returns 'corruption detected'
only when comprehensive poisoning is set, restore the good value of the byte, calls
multi_heap_check() again and make sure that it returns 'OK'.
2022-09-13 14:19:51 +02:00
Guillaume Souchere
b8f682a11b esp-rom: create a patch of tlsf_check() for target(s) supporting ROM implementation of TLSF
The tlsf implementation in the ROM does not provide a mechanism
to register a callback to be called in by tlsf_check().

This commit is creating a patch of the tlsf implementation to provide
a definition of the function allowing to register the callback called
in tlsf_check() and add the call of this callback in tlsf_check().

This patch is only compiled for target(s) with ESP_ROM_HAS_HEAP_TLSF
set and ESP_ROM_TLSF_CHECK_PATCH set. For all the other configurations
the environment remains unchanged by those modifications.
2022-09-13 14:19:51 +02:00
Guillaume Souchere
fc43fed8ea heap: Provide definition of the tlsf_check_hook() declared in the tlsf submodule
Add the definition of tlsf_check_hook() in multi_heap if MULTI_HEAP_POISONING
is set. This definition calls the multi_heap_internal_check_block_poisoning()
to check the memory of a free block for corruption. If the light poisoinng is
set this function returns true. If the comprehensive poisoning is set, this
function will check that all byte of memory in the memory chunk passed as parameter
are set to the right FILL pattern.
2022-09-13 14:19:51 +02:00
Omar Chebib
372ab1468b heap: add a unit test for malloc(0) and slightly optimize heap_caps_malloc_prefer 2022-09-01 08:43:18 +00:00
tgotic
8b3f916d1a fix malloc(0) and heap_caps_alloc_failed()
Don't call heap_caps_alloc_failed() for malloc(0) and calloc(0), because it is not an error.
Improve handling of malloc(0) and calloc(0).

Merges https://github.com/espressif/esp-idf/pull/9517
2022-09-01 08:43:18 +00:00
Marius Vikhammer
7caafb2542 heap: remove misleading info about malloc being equivalent to heap_caps_malloc(p, MALLOC_CAP_8BIT)
The actual memory allocated for malloc() depends on a lot of factors, see heap_caps_malloc_default()

Closes https://github.com/espressif/esp-idf/issues/7659
2022-09-01 14:32:54 +08:00
Guillaume Souchere
378c54e273 heap: Move the declaration of tlsf_poison_fill_pfunc_set() in esp_rom component
- The declaration is moved to esp_rom/include/esp32c2/rom/tlsf.h.
- multi_heap_poisoning.h now includes rom/tlsf.h instead of declaring
tlsf_poison_fill_pfunc_set().

Note: If more targets will support an implementation of the TLSF in ROM,
esp_rom will be extended with new headers in the respective target directories
but multi_heap_poisoning.h will remain unchanged.
2022-08-15 11:11:52 +02:00
Guillaume Souchere
8fb2a7a162 heap: Fix compilation error when CONFIG_SPIRAM is set on esp32s3 target
When CONFIG_SPIRAM is set, the TLSF_MAX_POOL_SIZE is set to SOC_EXTRAM_DATA_SIZE
which caused the TLSF_MAX_POOL_SIZE to be bigger than 16MB.

This commit fixes the issue by adding an extra else if case to cover this configuration.
2022-08-15 11:11:52 +02:00
Guillaume Souchere
86d1425346 heap: Fix compilation errors when CONFIG_HEAP_TLSF_USE_ROM_IMPL is set
- include headers from the tlsf submodule only when CONFIG_HEAP_TLSF_USE_ROM_IMPL is not set
- remove usage of the tlsf_t type in the multi_heap.c
- add missing declaration of tlsf_poison_fill_pfunc_set() in multi_heap_poisoning.c
- define headers from tlsf submodule as private
- update the linker file in the heap component to the new naming of the tlsf file
- update the copyright docuementation to reference the submodule in github (https://github.com/espressif/tlsf)
- remove deleted files from the check_copyright_ignore.txt
2022-08-15 11:11:52 +02:00
Guillaume Souchere
a2b60946ac heap: Remove TLSF related files and replace them with the tlsf submodule
As the tlsf implementation is a fork from https://github.com/mattconte/tlsf,
the sources are moved to a separate repository and used as a submodule in the esp-idf instead.

In this commit:
- Removing TLSF related files and using tlsf submodule instead.

- Adding components/heap/tlsf_platform.h header gathering all IDF specifics.

- The multi_heap_poisoning.c provides the declaration of the
function block_absorb_post_hook() definied weak in the TLSF repository.

- The tlsf_platform.h includes the tlsf_common.h file after the definition
of FL_INDEX_MAX_PLATFORM macro to make sure that this macro will be available
in tlsf_common.h without having to include tlaf_platform.h from IDF in the
tlsf_common.h header from the TLSF repository.

- Add missing include from tlsf_block_functions.h in the multi_heap.c file.
Change related to the changes made in TLSF repository (tlsf_block_functions.h
no longer included in tlsf.h)
2022-08-15 11:11:52 +02:00
wuzhenghui
2313663c2e bugfix: DCache data memory is dma accessible but not retention dma accessible 2022-08-09 21:10:55 +08:00
Ivan Grokhotkov
401c10ecfb build system: re-add -Wno-format as private flag for some components 2022-08-03 16:42:47 +04:00
wuzhenghui
5e8ba9cea8 use enum and designated initializers in soc_memory_type define 2022-07-29 17:07:41 +08:00
wuzhenghui
70eabb5492 ci: fix ci 2022-07-29 17:07:41 +08:00
wuzhenghui
7cb9304b65 Clean IRAM and DRAM address space conversion macros 2022-07-29 17:07:39 +08:00
wuzhenghui
65aea5d177 stack/dram is also IRAM0 accessible 2022-07-29 10:51:48 +08:00
wuzhenghui
21a4eda4d4 Use the entire sharedbuffer space as the heap of the D/IRAM attribute 2022-07-29 10:51:47 +08:00
Mahavir Jain
c0e096d5b2 Merge branch 'contrib/github_pr_9446' into 'master'
Add missing comma (GitHub PR)

Closes IDFGH-7928

See merge request espressif/esp-idf!19271
2022-07-28 12:36:30 +08:00
FanhuaCloud
a1c04ad6fd
Add missing comma
Add missing comma when CONFIG_ESP32S3_DATA_CACHE_16KB is enabled
2022-07-27 17:12:17 +08:00