From: John Hodge Date: Sun, 18 May 2014 06:26:38 +0000 (+0800) Subject: Kernel/x86_64 - Fix MM_AllocDMA to handle NULL PAddr pointer X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=200fecd6756067c8bf806fd11eaeb3b65090c68b;p=tpg%2Facess2.git Kernel/x86_64 - Fix MM_AllocDMA to handle NULL PAddr pointer --- diff --git a/KernelLand/Kernel/arch/x86_64/desctab.asm b/KernelLand/Kernel/arch/x86_64/desctab.asm index e8331735..e5e3f247 100644 --- a/KernelLand/Kernel/arch/x86_64/desctab.asm +++ b/KernelLand/Kernel/arch/x86_64/desctab.asm @@ -404,7 +404,7 @@ SyscallStub: mov [rsp+0x10], rdi ; Arg1 mov [rsp+0x18], rsi ; Arg2 mov [rsp+0x20], rdx ; Arg3 - mov [rsp+0x28], r10 ; Arg4 + mov [rsp+0x28], r10 ; Arg4 (r10 used in place of rcx) mov [rsp+0x30], r8 ; Arg5 mov [rsp+0x38], r9 ; Arg6 diff --git a/KernelLand/Kernel/arch/x86_64/mm_virt.c b/KernelLand/Kernel/arch/x86_64/mm_virt.c index 3d89ea6e..57308d7a 100644 --- a/KernelLand/Kernel/arch/x86_64/mm_virt.c +++ b/KernelLand/Kernel/arch/x86_64/mm_virt.c @@ -861,15 +861,16 @@ void *MM_AllocDMA(int Pages, int MaxBits, tPAddr *PhysAddr) void *ret; // Sanity Check - if(MaxBits < 12 || !PhysAddr) return 0; + ASSERTCR(MaxBits, >=, 12, NULL); // Fast Allocate if(Pages == 1 && MaxBits >= PHYS_BITS) { phys = MM_AllocPhys(); - *PhysAddr = phys; ret = MM_MapHWPages(phys, 1); MM_DerefPhys(phys); + if(PhysAddr) + *PhysAddr = phys; return ret; } @@ -880,7 +881,8 @@ void *MM_AllocDMA(int Pages, int MaxBits, tPAddr *PhysAddr) // Allocated successfully, now map ret = MM_MapHWPages(phys, Pages); - *PhysAddr = phys; + if(PhysAddr) + *PhysAddr = phys; // MapHWPages references the pages, so deref them back down to 1 for(;Pages--;phys+=0x1000) MM_DerefPhys(phys); @@ -897,9 +899,8 @@ void *MM_MapTemp(tPAddr PAddr) { const int max_slots = (MM_TMPMAP_END - MM_TMPMAP_BASE) / PAGE_SIZE; tVAddr ret = MM_TMPMAP_BASE; - int i; - for( i = 0; i < max_slots; i ++, ret += PAGE_SIZE ) + for( int i = 0; i < max_slots; i ++, ret += PAGE_SIZE ) { tPAddr *ent; if( MM_GetPageEntryPtr( ret, 0, 1, 0, &ent) < 0 ) {