Skip to content

Commit

Permalink
[ion] Set stack pointer when testing as well
Browse files Browse the repository at this point in the history
Change-Id: Ibeae7961535208c224f9ac51f4cf33e3978665b3
  • Loading branch information
HugoNumworks authored and EmilieNumworks committed Nov 4, 2020
1 parent e199143 commit 688394a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
15 changes: 1 addition & 14 deletions apps/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@
#include "global_preferences.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
#if DUMMY_MAIN

Expand Down Expand Up @@ -80,7 +67,7 @@ void ion_main(int argc, const char * const argv[]) {
* example, stack pointer could go backward after initialization and allocated
* memory pointers could be overlooked during mark procedure. */
volatile int stackTop;
s_stackStart = (void *)(&stackTop);
Ion::setStackStart((void *)(&stackTop));
#endif

AppsContainer::sharedAppsContainer()->run();
Expand Down
1 change: 1 addition & 0 deletions ion/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ion_src += $(addprefix ion/src/shared/, \
events_keyboard.cpp \
events_modifier.cpp \
platform_info.cpp \
stack_position.cpp \
storage.cpp \
unicode/utf8_decoder.cpp\
unicode/utf8_helper.cpp\
Expand Down
3 changes: 2 additions & 1 deletion ion/include/ion.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ uint32_t random();
// Decompress data
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 setStackStart(void *);
// Tells whether the stack pointer is within acceptable bounds
bool stackSafe();

Expand Down
22 changes: 22 additions & 0 deletions ion/src/shared/stack_position.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
}
12 changes: 9 additions & 3 deletions quiz/src/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ static inline void ion_main_inner() {


void ion_main(int argc, const char * const argv[]) {
// Initialize the backlight
Ion::Backlight::init();
// Initialize Poincare::TreePool::sharedPool
Poincare::Init();
Poincare::Init(); // Initialize Poincare::TreePool::sharedPool
#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;
if (ExceptionRun(ecp)) {
Expand Down

0 comments on commit 688394a

Please sign in to comment.