From dadb05e022a85af8903a265fde657ee1f22542b5 Mon Sep 17 00:00:00 2001 From: "Sergio R. Caprile" Date: Thu, 16 Feb 2023 15:01:10 -0300 Subject: [PATCH] Add heap limit --- examples/stm32/nucleo-f429zi-baremetal/syscalls.c | 3 +++ examples/stm32/nucleo-f429zi-rndis/syscalls.c | 3 +++ examples/stm32/nucleo-f746zg-baremetal/syscalls.c | 3 +++ examples/stm32/nucleo-f746zg-rndis/syscalls.c | 3 +++ examples/stm32/nucleo-h743zi-baremetal/syscalls.c | 3 +++ 5 files changed, 15 insertions(+) diff --git a/examples/stm32/nucleo-f429zi-baremetal/syscalls.c b/examples/stm32/nucleo-f429zi-baremetal/syscalls.c index be3210aa..ac27f093 100644 --- a/examples/stm32/nucleo-f429zi-baremetal/syscalls.c +++ b/examples/stm32/nucleo-f429zi-baremetal/syscalls.c @@ -12,8 +12,11 @@ void *_sbrk(int incr) { extern char _end; static unsigned char *heap = NULL; unsigned char *prev_heap; + unsigned char x = 0, *heap_end = (unsigned char *)((size_t) &x - 512); + (void) x; if (heap == NULL) heap = (unsigned char *) &_end; prev_heap = heap; + if (heap + incr > heap_end) return (void *) -1; heap += incr; return prev_heap; } diff --git a/examples/stm32/nucleo-f429zi-rndis/syscalls.c b/examples/stm32/nucleo-f429zi-rndis/syscalls.c index be3210aa..ac27f093 100644 --- a/examples/stm32/nucleo-f429zi-rndis/syscalls.c +++ b/examples/stm32/nucleo-f429zi-rndis/syscalls.c @@ -12,8 +12,11 @@ void *_sbrk(int incr) { extern char _end; static unsigned char *heap = NULL; unsigned char *prev_heap; + unsigned char x = 0, *heap_end = (unsigned char *)((size_t) &x - 512); + (void) x; if (heap == NULL) heap = (unsigned char *) &_end; prev_heap = heap; + if (heap + incr > heap_end) return (void *) -1; heap += incr; return prev_heap; } diff --git a/examples/stm32/nucleo-f746zg-baremetal/syscalls.c b/examples/stm32/nucleo-f746zg-baremetal/syscalls.c index be3210aa..ac27f093 100644 --- a/examples/stm32/nucleo-f746zg-baremetal/syscalls.c +++ b/examples/stm32/nucleo-f746zg-baremetal/syscalls.c @@ -12,8 +12,11 @@ void *_sbrk(int incr) { extern char _end; static unsigned char *heap = NULL; unsigned char *prev_heap; + unsigned char x = 0, *heap_end = (unsigned char *)((size_t) &x - 512); + (void) x; if (heap == NULL) heap = (unsigned char *) &_end; prev_heap = heap; + if (heap + incr > heap_end) return (void *) -1; heap += incr; return prev_heap; } diff --git a/examples/stm32/nucleo-f746zg-rndis/syscalls.c b/examples/stm32/nucleo-f746zg-rndis/syscalls.c index be3210aa..ac27f093 100644 --- a/examples/stm32/nucleo-f746zg-rndis/syscalls.c +++ b/examples/stm32/nucleo-f746zg-rndis/syscalls.c @@ -12,8 +12,11 @@ void *_sbrk(int incr) { extern char _end; static unsigned char *heap = NULL; unsigned char *prev_heap; + unsigned char x = 0, *heap_end = (unsigned char *)((size_t) &x - 512); + (void) x; if (heap == NULL) heap = (unsigned char *) &_end; prev_heap = heap; + if (heap + incr > heap_end) return (void *) -1; heap += incr; return prev_heap; } diff --git a/examples/stm32/nucleo-h743zi-baremetal/syscalls.c b/examples/stm32/nucleo-h743zi-baremetal/syscalls.c index be3210aa..ac27f093 100644 --- a/examples/stm32/nucleo-h743zi-baremetal/syscalls.c +++ b/examples/stm32/nucleo-h743zi-baremetal/syscalls.c @@ -12,8 +12,11 @@ void *_sbrk(int incr) { extern char _end; static unsigned char *heap = NULL; unsigned char *prev_heap; + unsigned char x = 0, *heap_end = (unsigned char *)((size_t) &x - 512); + (void) x; if (heap == NULL) heap = (unsigned char *) &_end; prev_heap = heap; + if (heap + incr > heap_end) return (void *) -1; heap += incr; return prev_heap; }