[ion] Set stack pointer when testing as well

Change-Id: Ibeae7961535208c224f9ac51f4cf33e3978665b3
This commit is contained in:
Hugo Saint-Vignes
2020-09-10 18:12:40 +02:00
committed by Émilie Feral
parent e199143412
commit 688394abce
5 changed files with 35 additions and 18 deletions

View File

@@ -2,19 +2,6 @@
#include "global_preferences.h" #include "global_preferences.h"
#include <poincare/init.h> #include <poincare/init.h>
#if PLATFORM_DEVICE
// On device, stack start address is always known. TODO : Factorize address
static void * s_stackStart = reinterpret_cast<void *>(0x20000000 + 256*1024);
#else
// Stack start will be defined in ion_main.
static void * s_stackStart = nullptr;
#endif
void * Ion::stackStart() {
assert(s_stackStart != nullptr);
return s_stackStart;
}
#define DUMMY_MAIN 0 #define DUMMY_MAIN 0
#if DUMMY_MAIN #if DUMMY_MAIN
@@ -80,7 +67,7 @@ void ion_main(int argc, const char * const argv[]) {
* example, stack pointer could go backward after initialization and allocated * example, stack pointer could go backward after initialization and allocated
* memory pointers could be overlooked during mark procedure. */ * memory pointers could be overlooked during mark procedure. */
volatile int stackTop; volatile int stackTop;
s_stackStart = (void *)(&stackTop); Ion::setStackStart((void *)(&stackTop));
#endif #endif
AppsContainer::sharedAppsContainer()->run(); AppsContainer::sharedAppsContainer()->run();

View File

@@ -31,6 +31,7 @@ ion_src += $(addprefix ion/src/shared/, \
events_keyboard.cpp \ events_keyboard.cpp \
events_modifier.cpp \ events_modifier.cpp \
platform_info.cpp \ platform_info.cpp \
stack_position.cpp \
storage.cpp \ storage.cpp \
unicode/utf8_decoder.cpp\ unicode/utf8_decoder.cpp\
unicode/utf8_helper.cpp\ unicode/utf8_helper.cpp\

View File

@@ -46,8 +46,9 @@ uint32_t random();
// Decompress data // Decompress data
void decompress(const uint8_t * src, uint8_t * dst, int srcSize, int dstSize); void decompress(const uint8_t * src, uint8_t * dst, int srcSize, int dstSize);
// Returns address to the first object that can be allocated on stack // Sets and returns address to the first object that can be allocated on stack
void * stackStart(); void * stackStart();
void setStackStart(void *);
// Tells whether the stack pointer is within acceptable bounds // Tells whether the stack pointer is within acceptable bounds
bool stackSafe(); bool stackSafe();

View File

@@ -0,0 +1,22 @@
#include <ion.h>
namespace Ion {
#if PLATFORM_DEVICE
// On device, stack start address is always known. TODO : Factorize address
static void * s_stackStart = reinterpret_cast<void *>(0x20000000 + 256*1024);
#else
// Stack start will be defined in ion_main.
static void * s_stackStart = nullptr;
#endif
void * stackStart() {
assert(s_stackStart != nullptr);
return s_stackStart;
}
void setStackStart(void * pointer) {
assert(pointer != nullptr);
s_stackStart = pointer;
}
}

View File

@@ -31,10 +31,16 @@ static inline void ion_main_inner() {
void ion_main(int argc, const char * const argv[]) { void ion_main(int argc, const char * const argv[]) {
// Initialize the backlight
Ion::Backlight::init(); Ion::Backlight::init();
// Initialize Poincare::TreePool::sharedPool Poincare::Init(); // Initialize Poincare::TreePool::sharedPool
Poincare::Init(); #if !PLATFORM_DEVICE
/* s_stackStart must be defined as early as possible to ensure that there
* cannot be allocated memory pointers before. Otherwise, with MicroPython for
* example, stack pointer could go backward after initialization and allocated
* memory pointers could be overlooked during mark procedure. */
volatile int stackTop;
Ion::setStackStart((void *)(&stackTop));
#endif
Poincare::ExceptionCheckpoint ecp; Poincare::ExceptionCheckpoint ecp;
if (ExceptionRun(ecp)) { if (ExceptionRun(ecp)) {