summaryrefslogtreecommitdiffstatshomepage
path: root/py/nlr.c
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2022-12-16 17:31:21 +1100
committerDamien George <damien@micropython.org>2023-03-21 18:08:57 +1100
commitd54208a2ff2ff8c2104597f715a586541ac6e663 (patch)
treec5f98cfef91106a097c9843c93aa0c4d7bb0d3cc /py/nlr.c
parent5d4bfce034ace816d67081d6286185d2e35b7125 (diff)
downloadmicropython-d54208a2ff2ff8c2104597f715a586541ac6e663.tar.gz
micropython-d54208a2ff2ff8c2104597f715a586541ac6e663.zip
py/scheduler: Implement VM abort flag and mp_sched_vm_abort().
This is intended to be used by the very outer caller of the VM/runtime. It allows setting a top-level NLR handler that can be jumped to directly, in order to forcefully abort the VM/runtime. Enable using: #define MICROPY_ENABLE_VM_ABORT (1) Set up the handler at the top level using: nlr_buf_t nlr; nlr.ret_val = NULL; if (nlr_push(&nlr) == 0) { nlr_set_abort(&nlr); // call into the VM/runtime ... nlr_pop(); } else { if (nlr.ret_val == NULL) { // handle abort ... } else { // handle other exception that propagated to the top level ... } } nlr_set_abort(NULL); Schedule an abort, eg from an interrupt handler, using: mp_sched_vm_abort(); Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'py/nlr.c')
-rw-r--r--py/nlr.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/py/nlr.c b/py/nlr.c
index a35e7d229c..92db8ffb19 100644
--- a/py/nlr.c
+++ b/py/nlr.c
@@ -49,3 +49,10 @@ void nlr_pop(void) {
nlr_buf_t **top = &MP_STATE_THREAD(nlr_top);
*top = (*top)->prev;
}
+
+#if MICROPY_ENABLE_VM_ABORT
+NORETURN void nlr_jump_abort(void) {
+ MP_STATE_THREAD(nlr_top) = MP_STATE_VM(nlr_abort);
+ nlr_jump(NULL);
+}
+#endif