Introduce STACK_GUARD_MARGIN in all variants

Create a gap between the BSS and the stack guard.
Set this gap (STACK_GUARD_MARGIN) to 32 bytes in all variants.

The gap serves two purposes:

- Detect a stack overflow earlier (falsely triggering in overtight
  situations is OK!), so that we can hopefully avoid smashing
  the heap and have a clean view during the dump.

- Reserve spack space itself for the stack dumping machinery,
  which is going to grow the stack even further.

Remove get_stack_guard_test_value() which was unused.
This commit is contained in:
Yuri D'Elia 2021-06-12 12:08:53 +02:00
parent 9663653671
commit f18d4757c6
10 changed files with 11 additions and 12 deletions

View File

@ -48,24 +48,16 @@ void SdFatUtil::set_stack_guard()
{
uint32_t *stack_guard;
stack_guard = (uint32_t*)&__bss_end;
stack_guard = (uint32_t*)(&__bss_end + STACK_GUARD_MARGIN);
*stack_guard = STACK_GUARD_TEST_VALUE;
}
bool SdFatUtil::test_stack_integrity()
{
uint32_t* stack_guard = (uint32_t*)&__bss_end;
uint32_t* stack_guard = (uint32_t*)(&__bss_end + STACK_GUARD_MARGIN);
return (*stack_guard == STACK_GUARD_TEST_VALUE);
}
uint32_t SdFatUtil::get_stack_guard_test_value()
{
uint32_t* stack_guard;
uint32_t output;
stack_guard = (uint32_t*)&__bss_end;
output = *stack_guard;
return(output);
}
//------------------------------------------------------------------------------
/** %Print a string in flash memory.
*

View File

@ -41,11 +41,10 @@ namespace SdFatUtil {
void SerialPrintln_P(PGM_P str);
void set_stack_guard();
bool test_stack_integrity();
uint32_t get_stack_guard_test_value();
}
using namespace SdFatUtil; // NOLINT
#endif // #define SdFatUtil_h
#endif
#endif

View File

@ -418,6 +418,7 @@ THERMISTORS SETTINGS
#endif
#define STACK_GUARD_TEST_VALUE 0xA2A2
#define STACK_GUARD_MARGIN 32
#define MAX_BED_TEMP_CALIBRATION 50
#define MAX_HOTEND_TEMP_CALIBRATION 50

View File

@ -407,6 +407,7 @@ THERMISTORS SETTINGS
#endif
#define STACK_GUARD_TEST_VALUE 0xA2A2
#define STACK_GUARD_MARGIN 32
#define MAX_BED_TEMP_CALIBRATION 50
#define MAX_HOTEND_TEMP_CALIBRATION 50

View File

@ -469,6 +469,7 @@
#define TEMP_SENSOR_PINDA 1
#define STACK_GUARD_TEST_VALUE 0xA2A2
#define STACK_GUARD_MARGIN 32
#define MAX_BED_TEMP_CALIBRATION 50
#define MAX_HOTEND_TEMP_CALIBRATION 50

View File

@ -470,6 +470,7 @@
#define TEMP_SENSOR_PINDA 1
#define STACK_GUARD_TEST_VALUE 0xA2A2
#define STACK_GUARD_MARGIN 32
#define MAX_BED_TEMP_CALIBRATION 50
#define MAX_HOTEND_TEMP_CALIBRATION 50

View File

@ -469,6 +469,7 @@
#define TEMP_SENSOR_PINDA 1
#define STACK_GUARD_TEST_VALUE 0xA2A2
#define STACK_GUARD_MARGIN 32
#define MAX_BED_TEMP_CALIBRATION 50
#define MAX_HOTEND_TEMP_CALIBRATION 50

View File

@ -470,6 +470,7 @@
#define TEMP_SENSOR_PINDA 1
#define STACK_GUARD_TEST_VALUE 0xA2A2
#define STACK_GUARD_MARGIN 32
#define MAX_BED_TEMP_CALIBRATION 50
#define MAX_HOTEND_TEMP_CALIBRATION 50

View File

@ -598,6 +598,7 @@
#define TEMP_SENSOR_AMBIENT 2000
#define STACK_GUARD_TEST_VALUE 0xA2A2
#define STACK_GUARD_MARGIN 32
#define MAX_BED_TEMP_CALIBRATION 50
#define MAX_HOTEND_TEMP_CALIBRATION 50

View File

@ -602,6 +602,7 @@
#define TEMP_SENSOR_AMBIENT 2000
#define STACK_GUARD_TEST_VALUE 0xA2A2
#define STACK_GUARD_MARGIN 32
#define MAX_BED_TEMP_CALIBRATION 50
#define MAX_HOTEND_TEMP_CALIBRATION 50