From 9521538a2533451531292eaef4b1a380772831c7 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 22 Sep 2009 20:36:59 +0800 Subject: [PATCH] Added out of memory handling to MM_Allocate --- Kernel/arch/x86/mm_phys.c | 2 +- Kernel/arch/x86/mm_virt.c | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Kernel/arch/x86/mm_phys.c b/Kernel/arch/x86/mm_phys.c index 72f5dc9a..a6656e50 100644 --- a/Kernel/arch/x86/mm_phys.c +++ b/Kernel/arch/x86/mm_phys.c @@ -96,7 +96,7 @@ tPAddr MM_AllocPhys() for(a=0;gaSuperBitmap[a]==-1&&a> 22 ] == 0 ) { // Allocate directory - gaPageDir[ VAddr >> 22 ] = MM_AllocPhys() | 3; + paddr = MM_AllocPhys(); + if( paddr == 0 ) { + Warning("MM_Allocate - Out of Memory (Called by %p)", __builtin_return_address(0)); + return 0; + } + // Map + gaPageDir[ VAddr >> 22 ] = paddr | 3; // Mark as user if(VAddr < MM_USER_MAX) gaPageDir[ VAddr >> 22 ] |= PF_USER; @@ -223,13 +230,19 @@ tPAddr MM_Allocate(Uint VAddr) } // Allocate - gaPageTable[ VAddr >> 12 ] = MM_AllocPhys() | 3; + paddr = MM_AllocPhys(); + if( paddr == 0 ) { + Warning("MM_Allocate - Out of Memory (Called by %p)", __builtin_return_address(0)); + return 0; + } + // Map + gaPageTable[ VAddr >> 12 ] = paddr | 3; // Mark as user if(VAddr < MM_USER_MAX) gaPageTable[ VAddr >> 12 ] |= PF_USER; // Invalidate Cache for address INVLPG( VAddr & ~0xFFF ); - return gaPageTable[ VAddr >> 12 ] & ~0xFFF; + return paddr; } /** -- 2.20.1