Files
Upsilon/apps/main.cpp
Hugo Saint-Vignes 70a628f2c8 [apps] Fix Python assert crash on malloc free
Change-Id: I48f86422f7d6af5227e2556e6ef531dfad696da4
2020-11-04 15:30:53 +01:00

90 lines
2.7 KiB
C++

#include "apps_container.h"
#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
void ion_main(int argc, const char * const argv[]) {
// Initialize the backlight
Ion::Backlight::init();
while (1) {
Ion::Display::pushRectUniform(KDRect(0,0,10,10), KDColorRed);
Ion::Timing::msleep(100);
Ion::Display::pushRectUniform(KDRect(0,0,10,10), KDColorBlue);
Ion::Timing::msleep(100);
}
}
#else
void ion_main(int argc, const char * const argv[]) {
// Initialize Poincare::TreePool::sharedPool
Poincare::Init();
#if EPSILON_GETOPT
for (int i=1; i<argc; i++) {
if (argv[i][0] != '-' || argv[i][1] != '-') {
continue;
}
/* Option should be given at run-time:
* $ ./epsilon.elf --language fr
*/
if (strcmp(argv[i], "--language") == 0 && argc > i+1) {
const char * requestedLanguageId = argv[i+1];
if (strcmp(requestedLanguageId, "none") == 0) {
continue;
}
for (int j = 0; j < I18n::NumberOfLanguages; j++) {
if (strcmp(requestedLanguageId, I18n::translate(I18n::LanguageISO6391Names[j])) == 0) {
GlobalPreferences::sharedGlobalPreferences()->setLanguage((I18n::Language)j);
break;
}
}
continue;
}
/* Option should be given at run-time:
* $ ./epsilon.elf --[app_name]-[option] [arguments]
* For example:
* $ make -j8 PLATFORM=emscripten EPSILON_APPS=code
* $ ./epsilon.elf --code-script hello_world.py:print("hello") --code-lock-on-console
*/
const char * appNames[] = {"home", EPSILON_APPS_NAMES};
for (int j = 0; j < AppsContainer::sharedAppsContainer()->numberOfApps(); j++) {
App::Snapshot * snapshot = AppsContainer::sharedAppsContainer()->appSnapshotAtIndex(j);
int cmp = strcmp(argv[i]+2, appNames[j]);
if (cmp == '-') {
snapshot->setOpt(argv[i]+2+strlen(appNames[j])+1, argv[i+1]);
break;
}
}
}
#endif
#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;
s_stackStart = (void *)(&stackTop);
#endif
AppsContainer::sharedAppsContainer()->run();
}
#endif