Skip to content

Commit 8faedb1

Browse files
Merge pull request #921 from LedgerHQ/dynamic-memory-alloc
Add dynamic memory allocator
2 parents ac71a24 + 844b6c2 commit 8faedb1

File tree

11 files changed

+899
-0
lines changed

11 files changed

+899
-0
lines changed

.github/workflows/unit_tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
STAX=1 cmake -Bbuild -H. && make -C build && CTEST_OUTPUT_ON_FAILURE=1 make -C build test
3030
cd ../app_storage/
3131
cmake -Bbuild -H. && make -C build && make -C build test
32+
cd ../lib_alloc/
33+
cmake -Bbuild -H. && make -C build && make -C build test
3234
3335
- name: Generate code coverage
3436
run: |
@@ -38,6 +40,8 @@ jobs:
3840
../gen_coverage.sh
3941
cd ../app_storage/
4042
../gen_coverage.sh
43+
cd ../lib_alloc/
44+
../gen_coverage.sh
4145
4246
- uses: actions/upload-artifact@v4
4347
with:

Makefile.rules

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ else
2727
NBGL_INCLUDE_PATH := lib_nbgl
2828
endif
2929

30+
# include dynamic memory allocator, if asked (temporary flag)
31+
ifeq ($(ENABLE_DYNAMIC_ALLOC), 1)
32+
SDK_SOURCE_PATH += lib_alloc
33+
endif
34+
3035
define uniq =
3136
$(eval seen :=)
3237
$(foreach _,$1,$(if $(filter $_,${seen}),,$(eval seen += $_)))

doc/Doxyfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,8 @@ WARN_LOGFILE =
825825

826826
INPUT = \
827827
doc \
828+
lib_alloc \
829+
lib_alloc/doc \
828830
lib_cxng/doc \
829831
lib_cxng/include \
830832
lib_cxng/src \

doc/mainpage.dox

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ The @subpage ble_mainpage page contains all information necessary to interact wi
1313

1414
The @subpage cxng_mainpage page contains all information necessary to understand Cryptographic Library
1515

16+
@section mem_presentation Dynamic Memory Allocator Interface
17+
18+
The @subpage mem_alloc_mainpage page contains all information necessary to interact with Dynamic Memory Allocator.
19+
1620
@section nbgl_presentation Screen drawing API
1721

1822
The @subpage nbgl_mainpage page contains all information necessary to understand the Graphical Library for

include/errors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,6 @@ enum sdk_generic_identifiers {
150150
#define EXCEPTION_IO_STATE 0x11 // keep original value // SWO_MUI_UNK_15
151151
#define EXCEPTION_CXPORT 0x12 // keep original value // SWO_MUI_UNK_16
152152
#define EXCEPTION_SYSTEM 0x13 // keep original value // SWO_MUI_UNK_17
153+
#define EXCEPTION_CORRUPT 0x14
153154

154155
#endif // ERRORS_H

lib_alloc/doc/mainpage.dox

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/** @page mem_alloc_mainpage Dynamic memory allocator
2+
3+
@section mem_alloc_mainpage_intro Introduction
4+
5+
This page describes the Dynamic Memory Allocator available for Applications.
6+
7+
Basically, this allocator behaves like any memory allocator in usual OS. The main difference is that it can be instantiated, thanks to
8+
its initialization function: @ref mem_init()
9+
10+
This function takes as parameters
11+
12+
- a pointer to a buffer that will be used both as context for the Allocator and for dynamic chunks,
13+
- and the size of this buffer
14+
15+
It returns a memory context (@ref mem_ctx_t) that will be used by other functions
16+
17+
Then, chunks can be allocated with @ref mem_alloc() and released with @ref mem_free()
18+
19+
Both of these function take the memory context as first parameter.
20+
21+
*/

0 commit comments

Comments
 (0)