Recover from out-of-memory, thrown exceptions, and aborts in plugins and firmware#601
Open
danngreen wants to merge 39 commits into
Open
Recover from out-of-memory, thrown exceptions, and aborts in plugins and firmware#601danngreen wants to merge 39 commits into
danngreen wants to merge 39 commits into
Conversation
- newlib wrapper functions for free/free_r/realloc/realloc_r that check ptr and route
…a instead TLSF cannot easily be forced to align to > sizeof(void*), so instead we just force alignment in plugin arena
…(do not demangle)
Catches OOM in plugin's init() and also in loading the metadata. OOM in allocating space for the assets and/or the .so code are caught elsewhere
They are just printed to console, so a fatal error could cause a crash.
…llModule standin)
Because the preview buffer is shared between pages
-AbortRescue holds the jmp_buf, activates it when a context calls "arm()" -One AbortRescue can be active per context (previous one is swapped back in when one is destructed) -Disabled if malloc or tslf arena lock is held (hard crash if exception throws inside malloc/tslf alloc) -
If the module crashes/oom in its constructor, then we'll catch the abort()
Member
Author
|
This bumps the firmware size over 9.5MB, so it requires #602 before it can be run from NOR flash (running from SD card or JTAG debugger is fine). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a large refactor to the dynamic memory system that prevents the MM from crashing if a plugin tries to allocate more memory than is available, or otherwise hits abort(). If a MM does not have enough memory available to load a module, a notification will be shown to the user and the module will not be added. For modules in plugins with SDK 2.2 or earlier, memory may be leaked. For plugins SDK v2.3 or later, exception handling is enabled, so the plugin's stack can be unwound and the destructors will be called (hopefully cleaning up any memory used).
Also, if a plugin calls abort() (due to an uncaught exception or a terminate from some other error, the MM will intercept this and try to recover gracefully.
It also catches internal OOM and other exceptions thrown, and handles them reasonably.
Changes:
Exceptions:
Heap
--wraped with our own version that checks which arena/heap the address is in. If it's in the plugin arena, then it calls the plugin arena free(). Otherwise it calls the main newlib free()Error/exception handling
If an exception is thrown:
...then we report it to the user via a Notification and unwind the stack (hopefully if the module uses RAII or std containers then memory will get cleaned up)
If a module calls abort() because
...then we use the C-style setjmp/longjmp to try to clean up (unload what we can, abort the process).
If an exception is thrown in the audio thread, we still will crash (no recovery)