diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2019-03-08 15:29:14 -0800 |
|---|---|---|
| committer | Scott Shawcroft <scott@tannewt.org> | 2019-03-12 11:18:26 -0700 |
| commit | 03be42ab847f04a89d207d98fdb28048cfedf72d (patch) | |
| tree | 918df321648fc6715eee60ddf926d5dc7ee58bfe /py/gc.c | |
| parent | ef4a74e201e852a32e2e1be73ed9ba85c88fb3f4 (diff) | |
Enter safe mode when an allocation is attempted on an uninitialized heap.
Diffstat (limited to 'py/gc.c')
| -rwxr-xr-x | py/gc.c | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -31,6 +31,8 @@ #include "py/gc.h" #include "py/runtime.h" +#include "supervisor/shared/safe_mode.h" + #if MICROPY_ENABLE_GC #if MICROPY_DEBUG_VERBOSE // print debugging info @@ -182,6 +184,13 @@ void gc_init(void *start, void *end) { DEBUG_printf(" pool at %p, length " UINT_FMT " bytes, " UINT_FMT " blocks\n", MP_STATE_MEM(gc_pool_start), gc_pool_block_len * BYTES_PER_BLOCK, gc_pool_block_len); } +void gc_deinit() { + // Run any finalizers before we stop using the heap. + gc_sweep_all(); + + MP_STATE_MEM(gc_pool_start) = 0; +} + void gc_lock(void) { GC_ENTER(); MP_STATE_MEM(gc_lock_depth)++; @@ -463,6 +472,10 @@ void *gc_alloc(size_t n_bytes, bool has_finaliser, bool long_lived) { return NULL; } + if (MP_STATE_MEM(gc_pool_start) == 0) { + reset_into_safe_mode(GC_ALLOC_OUTSIDE_VM); + } + GC_ENTER(); // check if GC is locked |
