From 3fdb336988a789df3c9a8d8165d35b4c260dbfee Mon Sep 17 00:00:00 2001 From: valentinbreiz Date: Wed, 9 Feb 2022 16:19:38 +0000 Subject: [PATCH] Disable interrupts in Heap.Collect, not free --- source/Cosmos.Core/Memory/Heap.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/source/Cosmos.Core/Memory/Heap.cs b/source/Cosmos.Core/Memory/Heap.cs index 9c3d3fd403..69fee9c49a 100644 --- a/source/Cosmos.Core/Memory/Heap.cs +++ b/source/Cosmos.Core/Memory/Heap.cs @@ -85,8 +85,6 @@ public static uint SafeAlloc(uint aSize) /// public static void Free(void* aPtr) { - CPU.DisableInterrupts(); - //TODO find a better way to remove the double look up here for GetPageType and then again in the // .Free methods which actually free the entries in the RAT. //Debugger.DoSendNumber(0x77); @@ -105,8 +103,6 @@ public static void Free(void* aPtr) default: throw new Exception("Heap item not found in RAT."); } - - CPU.EnableInterrupts(); } /// @@ -115,6 +111,9 @@ public static void Free(void* aPtr) /// Number of objects freed public static int Collect() { + //Disable interrupts: Prevent CPU exception when allocation is called from interrupt code + CPU.DisableInterrupts(); + // Mark and sweep objects from roots // 1. Check if a page is in use if medium/large mark and sweep object // 2. Go throught the SMT table for small objects and go through pages by size @@ -234,6 +233,9 @@ public static int Collect() rootSMTPtr = rootSMTPtr->LargerSize; } + + //Enable interrupts back + CPU.EnableInterrupts(); return freed; }