Skip to content

Commit 3fdb336

Browse files
committed
Disable interrupts in Heap.Collect, not free
1 parent 64362cb commit 3fdb336

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

source/Cosmos.Core/Memory/Heap.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ public static uint SafeAlloc(uint aSize)
8585
/// </exception>
8686
public static void Free(void* aPtr)
8787
{
88-
CPU.DisableInterrupts();
89-
9088
//TODO find a better way to remove the double look up here for GetPageType and then again in the
9189
// .Free methods which actually free the entries in the RAT.
9290
//Debugger.DoSendNumber(0x77);
@@ -105,8 +103,6 @@ public static void Free(void* aPtr)
105103
default:
106104
throw new Exception("Heap item not found in RAT.");
107105
}
108-
109-
CPU.EnableInterrupts();
110106
}
111107

112108
/// <summary>
@@ -115,6 +111,9 @@ public static void Free(void* aPtr)
115111
/// <returns>Number of objects freed</returns>
116112
public static int Collect()
117113
{
114+
//Disable interrupts: Prevent CPU exception when allocation is called from interrupt code
115+
CPU.DisableInterrupts();
116+
118117
// Mark and sweep objects from roots
119118
// 1. Check if a page is in use if medium/large mark and sweep object
120119
// 2. Go throught the SMT table for small objects and go through pages by size
@@ -234,6 +233,9 @@ public static int Collect()
234233

235234
rootSMTPtr = rootSMTPtr->LargerSize;
236235
}
236+
237+
//Enable interrupts back
238+
CPU.EnableInterrupts();
237239

238240
return freed;
239241
}

0 commit comments

Comments
 (0)