cesanta / mongoose-os

Mongoose OS - an IoT Firmware Development Framework. Supported microcontrollers: ESP32, ESP8266, CC3220, CC3200, STM32F4, STM32L4, STM32F7. Amazon AWS IoT, Microsoft Azure, Google IoT Core integrated. Code in C or JavaScript.
https://mongoose-os.com
Other
2.48k stars 430 forks source link

Self re-trigger crashes with stack canary or double exception (ESP32) #581

Closed scaprile closed 2 years ago

scaprile commented 2 years ago

A callback for an event triggering the very same event in order to simulate a main loop causes canary watchpoint resets or core panics (Double exception); minimum app attached: crash.zip

static void rundemo(int ev, void *ev_data, void *userdata) {
  mgos_event_trigger(MY_EVENT, NULL);
}
enum mgos_app_init_result mgos_app_init(void) {
  if(!mgos_event_register_base(MY_EVENT, "Ping-pong demo")) return false;
  if(!mgos_event_add_handler(MY_EVENT, rundemo, NULL))  return false;
  mgos_event_trigger(MY_EVENT, NULL);
  return MGOS_APP_INIT_SUCCESS;
}
scaprile commented 2 years ago

Observing the source code for the mgos_event_trigger() function I see it just calls the handler, no event queuing, so it is clear to me why this is not proper usage of the function and that mOS does not support an event handler re-triggering itself other than for recursive-function-like purposes (and given enough stack space available)

rojer commented 2 years ago

indeed, event handlers are executed in-line so you can't re-trigger event from its handler.