summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
authorChristian Walther <cwalther@gmx.ch>2020-10-11 14:59:33 +0200
committerChristian Walther <cwalther@gmx.ch>2020-11-28 17:50:23 +0100
commitc7404a3ff89c738c002ec63448a58d56330dfcc3 (patch)
treeb7eabbfe9dd8cdd9f6029252dc9c341e1b3d1ac1 /shared-module
parentbd87201c4f5a326e0328648700e1929d876b8c36 (diff)
Add movable allocation system.
This allows calls to `allocate_memory()` while the VM is running, it will then allocate from the GC heap (unless there is a suitable hole among the supervisor allocations), and when the VM exits and the GC heap is freed, the allocation will be moved to the bottom of the former GC heap and transformed into a proper supervisor allocation. Existing movable allocations will also be moved to defragment the supervisor heap and ensure that the next VM run gets as much memory as possible for the GC heap. By itself this breaks terminalio because it violates the assumption that supervisor_display_move_memory() still has access to an undisturbed heap to copy the tilegrid from. It will work in many cases, but if you're unlucky you will get garbled terminal contents after exiting from the vm run that created the display. This will be fixed in the following commit, which is separate to simplify review.
Diffstat (limited to 'shared-module')
-rw-r--r--shared-module/rgbmatrix/RGBMatrix.c2
-rw-r--r--shared-module/sharpdisplay/SharpMemoryFramebuffer.c2
-rw-r--r--shared-module/usb_midi/__init__.c2
3 files changed, 3 insertions, 3 deletions
diff --git a/shared-module/rgbmatrix/RGBMatrix.c b/shared-module/rgbmatrix/RGBMatrix.c
index 94c3eda27..1f144aedb 100644
--- a/shared-module/rgbmatrix/RGBMatrix.c
+++ b/shared-module/rgbmatrix/RGBMatrix.c
@@ -220,7 +220,7 @@ void *common_hal_rgbmatrix_allocator_impl(size_t sz) {
if (gc_alloc_possible()) {
return m_malloc_maybe(sz + sizeof(void*), true);
} else {
- supervisor_allocation *allocation = allocate_memory(align32_size(sz), false);
+ supervisor_allocation *allocation = allocate_memory(align32_size(sz), false, false);
return allocation ? allocation->ptr : NULL;
}
}
diff --git a/shared-module/sharpdisplay/SharpMemoryFramebuffer.c b/shared-module/sharpdisplay/SharpMemoryFramebuffer.c
index b199e98d6..aefb6b18d 100644
--- a/shared-module/sharpdisplay/SharpMemoryFramebuffer.c
+++ b/shared-module/sharpdisplay/SharpMemoryFramebuffer.c
@@ -40,7 +40,7 @@
#define SHARPMEM_BIT_VCOM_LSB (0x40)
static void *hybrid_alloc(size_t sz) {
- supervisor_allocation *allocation = allocate_memory(align32_size(sz), false);
+ supervisor_allocation *allocation = allocate_memory(align32_size(sz), false, false);
if (allocation) {
memset(allocation->ptr, 0, sz);
return allocation->ptr;
diff --git a/shared-module/usb_midi/__init__.c b/shared-module/usb_midi/__init__.c
index 73a314b99..5afdd1821 100644
--- a/shared-module/usb_midi/__init__.c
+++ b/shared-module/usb_midi/__init__.c
@@ -45,7 +45,7 @@ void usb_midi_init(void) {
uint16_t portout_size = align32_size(sizeof(usb_midi_portout_obj_t));
// For each embedded MIDI Jack in the descriptor we create a Port
- usb_midi_allocation = allocate_memory(tuple_size + portin_size + portout_size, false);
+ usb_midi_allocation = allocate_memory(tuple_size + portin_size + portout_size, false, false);
mp_obj_tuple_t *ports = (mp_obj_tuple_t *) usb_midi_allocation->ptr;
ports->base.type = &mp_type_tuple;