瀏覽代碼

Fix malloc corrupting the stack. Added new function reserve_stack() to adjust the amount of memory reserved for the stack.

teensy4-core
Tilo Nitzsche 7 年之前
父節點
當前提交
c5bdda910b
共有 2 個檔案被更改,包括 18 行新增0 行删除
  1. +5
    -0
      teensy3/kinetis.h
  2. +13
    -0
      teensy3/mk20dx128.c

+ 5
- 0
teensy3/kinetis.h 查看文件

@@ -5794,6 +5794,11 @@ extern void software_isr(void);
extern void (* _VectorsRam[NVIC_NUM_INTERRUPTS+16])(void);
extern void (* const _VectorsFlash[NVIC_NUM_INTERRUPTS+16])(void);

// Reserve stack memory. This is the amount of memory malloc will leave alone
// for the stack. The stack can grow larger than this limit (growing towards /
// into the heap). 512 bytes are reserved by default.
extern void reserve_stack(int size);

#ifdef __cplusplus
}
#endif

+ 13
- 0
teensy3/mk20dx128.c 查看文件

@@ -32,6 +32,7 @@
#include "core_pins.h" // testing only
#include "ser_print.h" // testing only

#include <errno.h>

// Flash Security Setting. On Teensy 3.2, you can lock the MK20 chip to prevent
// anyone from reading your code. You CAN still reprogram your Teensy while
@@ -1137,8 +1138,20 @@ void ResetHandler(void)

char *__brkval = (char *)&_ebss;

int reserved_stack_size = 512;

void reserve_stack(int size)
{
reserved_stack_size = size;
}

void * _sbrk(int incr)
{
if(__brkval + incr >= (char*) &_estack - reserved_stack_size)
{
errno = ENOMEM;
return (void*) -1;
}
char *prev = __brkval;
__brkval += incr;
return prev;

Loading…
取消
儲存