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>
This commit is contained in:
@@ -909,6 +909,11 @@ typedef double mp_float_t;
|
||||
#define MICROPY_INTERNAL_PRINTF_PRINTER (&mp_plat_print)
|
||||
#endif
|
||||
|
||||
// Whether to support mp_sched_vm_abort to asynchronously abort to the top level.
|
||||
#ifndef MICROPY_ENABLE_VM_ABORT
|
||||
#define MICROPY_ENABLE_VM_ABORT (0)
|
||||
#endif
|
||||
|
||||
// Support for internal scheduler
|
||||
#ifndef MICROPY_ENABLE_SCHEDULER
|
||||
#define MICROPY_ENABLE_SCHEDULER (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
|
||||
@@ -1740,6 +1745,10 @@ typedef double mp_float_t;
|
||||
#define MICROPY_WRAP_MP_SCHED_SCHEDULE(f) f
|
||||
#endif
|
||||
|
||||
#ifndef MICROPY_WRAP_MP_SCHED_VM_ABORT
|
||||
#define MICROPY_WRAP_MP_SCHED_VM_ABORT(f) f
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Miscellaneous settings */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user