Add necessary sections for stack protection area and implement fill function

This commit is contained in:
Mario Hüttel 2020-09-07 21:03:37 +02:00
parent cbbd97e1bd
commit ba41c0911d
3 changed files with 52 additions and 2 deletions

View File

@ -50,4 +50,8 @@ static inline uint32_t read_stack_pointer()
return stack_pointer;
}
int stack_check_init_corruption_detect_area(void);
int stack_check_corruption_detect_area(void);
#endif /* __STACK_CHECK_H__ */

View File

@ -20,9 +20,10 @@
#include <reflow-controller/stack-check.h>
#include <stdint.h>
#include <stm-periph/rng.h>
extern char __ld_top_of_stack;
extern char __ld_eheap;
extern char __ld_end_stack;
int32_t stack_check_get_usage()
{
@ -41,7 +42,45 @@ int32_t stack_check_get_free()
uint32_t stack_ptr;
stack_ptr = read_stack_pointer();
upper_heap_boundary = (uint32_t)&__ld_eheap;
upper_heap_boundary = (uint32_t)&__ld_end_stack;
return stack_ptr - upper_heap_boundary;
}
extern uint32_t __ld_start_stack_corruption_detect_area;
extern uint32_t __ld_end_stack_corruption_detect_area;
int stack_check_init_corruption_detect_area(void)
{
volatile uint32_t *ptr = &__ld_start_stack_corruption_detect_area;
volatile uint32_t *end_ptr = &__ld_end_stack_corruption_detect_area;
enum random_number_error rng_stat;
uint32_t rng_number;
int ret = 0;
end_ptr--;
random_number_gen_init(false);
while (ptr < end_ptr) {
rng_stat = random_number_gen_get_number(&rng_number, true);
if (rng_stat != RNG_ERROR_OK) {
ret = -1;
goto exit_deinit_rng;
}
*ptr = rng_number;
ptr++;
}
exit_deinit_rng:
random_number_gen_deinit();
return ret;
}
int stack_check_corruption_detect_area(void)
{
}

View File

@ -25,6 +25,7 @@
/* USER PARAMETERS */
__ld_stack_size = 0x3000;
__ld_heap_size = 0x2100;
__stack_corruption_area_size = 64;
/* END OF USER PARAMETERS */
ENTRY(Reset_Handler)
@ -150,6 +151,12 @@ SECTIONS
__ld_sheap = .;
. = . + __ld_heap_size;
__ld_eheap = .;
. = ALIGN(4)
__ld_start_stack_corruption_detect_area = .;
. = . + __stack_corruption_area_size;
. = ALIGN(4);
__ld_end_stack_corruption_detect_area = .;
__ld_end_stack = .
. = . + __ld_stack_size;
. = ALIGN(4);
} >RAM