ptos: mm: Protect PFDs with lock
Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
#include <mm/pm.h>
|
#include <mm/pm.h>
|
||||||
#include <mm/vm.h>
|
#include <mm/vm.h>
|
||||||
#include <ke/bpal.h>
|
#include <ke/bpal.h>
|
||||||
|
#include <ke/spinlock.h>
|
||||||
#include <ex/trace.h>
|
#include <ex/trace.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <units.h>
|
#include <units.h>
|
||||||
@@ -56,12 +57,14 @@ typedef struct _MM_PFD {
|
|||||||
*
|
*
|
||||||
* @First: First entry in freelist
|
* @First: First entry in freelist
|
||||||
* @Last: Last entry in freelist
|
* @Last: Last entry in freelist
|
||||||
|
* @Lock: Protects this list
|
||||||
*
|
*
|
||||||
* TODO: Add a lock to this structure
|
* TODO: Add a lock to this structure
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
MM_PFD *First;
|
MM_PFD *First;
|
||||||
MM_PFD *Last;
|
MM_PFD *Last;
|
||||||
|
SPINLOCK Lock;
|
||||||
} MM_PFD_LIST;
|
} MM_PFD_LIST;
|
||||||
|
|
||||||
/* Standard usable memory list */
|
/* Standard usable memory list */
|
||||||
@@ -222,7 +225,10 @@ MmRequestFrame(VOID)
|
|||||||
MM_PFD *Pfd;
|
MM_PFD *Pfd;
|
||||||
UPTR PhysicalBase;
|
UPTR PhysicalBase;
|
||||||
|
|
||||||
|
KeSpinLockAcquire(&AvlList.Lock, true);
|
||||||
Pfd = PmPfdListPop(&AvlList);
|
Pfd = PmPfdListPop(&AvlList);
|
||||||
|
KeSpinLockRelease(&AvlList.Lock);
|
||||||
|
|
||||||
if (Pfd == NULL) {
|
if (Pfd == NULL) {
|
||||||
return PFN_ERROR;
|
return PFN_ERROR;
|
||||||
}
|
}
|
||||||
@@ -242,14 +248,17 @@ MmReclaimFrame(MM_PFN Pfn)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KeSpinLockAcquire(&AvlList.Lock, true);
|
||||||
PhysicalBase = PFN_TO_ADDRESS(Pfn);
|
PhysicalBase = PFN_TO_ADDRESS(Pfn);
|
||||||
Pfd = (VOID *)PMA_TO_VMA(PhysicalBase);
|
Pfd = (VOID *)PMA_TO_VMA(PhysicalBase);
|
||||||
PmPfdListAppend(&AvlList, Pfd);
|
PmPfdListAppend(&AvlList, Pfd);
|
||||||
|
KeSpinLockRelease(&AvlList.Lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
MmPmInit(VOID)
|
MmPmInit(VOID)
|
||||||
{
|
{
|
||||||
|
KeSpinLockInit(&AvlList.Lock, "pmm.avllock");
|
||||||
DTRACE("probing physical memory...\n");
|
DTRACE("probing physical memory...\n");
|
||||||
PmProbe();
|
PmProbe();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user