From b3025a8642645f026efef25e5302e5183113aa59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Sat, 26 Oct 2013 20:49:48 +0200 Subject: [PATCH] bootloader: M68K: Fix mmu_free() Same bug as in ARM code... --- src/system/boot/arch/m68k/mmu.cpp | 10 +++++----- src/system/boot/platform/amiga_m68k/mmu.cpp | 10 +++++----- src/system/boot/platform/atari_m68k/mmu.cpp | 9 +++++---- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/system/boot/arch/m68k/mmu.cpp b/src/system/boot/arch/m68k/mmu.cpp index 79ea943e55..8f7495c824 100644 --- a/src/system/boot/arch/m68k/mmu.cpp +++ b/src/system/boot/arch/m68k/mmu.cpp @@ -373,18 +373,18 @@ mmu_free(void *virtualAddress, size_t size) TRACE(("mmu_free(virtualAddress = %p, size: %ld)\n", virtualAddress, size)); addr_t address = (addr_t)virtualAddress; - size = (size + B_PAGE_SIZE - 1) / B_PAGE_SIZE; - // get number of pages to map + addr_t pageOffset = address % B_PAGE_SIZE; + address -= pageOffset; + size = (size + pageOffset + B_PAGE_SIZE - 1) / B_PAGE_SIZE * B_PAGE_SIZE; // is the address within the valid range? - if (address < KERNEL_LOAD_BASE - || address + size >= KERNEL_LOAD_BASE + kMaxKernelSize) { + if (address < KERNEL_LOAD_BASE || address + size > sNextVirtualAddress) { panic("mmu_free: asked to unmap out of range region (%p, size %lx)\n", (void *)address, size); } // unmap all pages within the range - for (uint32 i = 0; i < size; i++) { + for (size_t i = 0; i < size; i += B_PAGE_SIZE) { unmap_page(address); address += B_PAGE_SIZE; } diff --git a/src/system/boot/platform/amiga_m68k/mmu.cpp b/src/system/boot/platform/amiga_m68k/mmu.cpp index eb5d17ba03..bbc02c672b 100644 --- a/src/system/boot/platform/amiga_m68k/mmu.cpp +++ b/src/system/boot/platform/amiga_m68k/mmu.cpp @@ -373,18 +373,18 @@ mmu_free(void *virtualAddress, size_t size) TRACE(("mmu_free(virtualAddress = %p, size: %ld)\n", virtualAddress, size)); addr_t address = (addr_t)virtualAddress; - size = (size + B_PAGE_SIZE - 1) / B_PAGE_SIZE; - // get number of pages to map + addr_t pageOffset = address % B_PAGE_SIZE; + address -= pageOffset; + size = (size + pageOffset + B_PAGE_SIZE - 1) / B_PAGE_SIZE * B_PAGE_SIZE; // is the address within the valid range? - if (address < KERNEL_LOAD_BASE - || address + size >= KERNEL_LOAD_BASE + kMaxKernelSize) { + if (address < KERNEL_LOAD_BASE || address + size > sNextVirtualAddress) { panic("mmu_free: asked to unmap out of range region (%p, size %lx)\n", (void *)address, size); } // unmap all pages within the range - for (uint32 i = 0; i < size; i++) { + for (size_t i = 0; i < size; i += B_PAGE_SIZE) { unmap_page(address); address += B_PAGE_SIZE; } diff --git a/src/system/boot/platform/atari_m68k/mmu.cpp b/src/system/boot/platform/atari_m68k/mmu.cpp index 300e160d80..4a858ec44a 100644 --- a/src/system/boot/platform/atari_m68k/mmu.cpp +++ b/src/system/boot/platform/atari_m68k/mmu.cpp @@ -374,17 +374,18 @@ mmu_free(void *virtualAddress, size_t size) TRACE(("mmu_free(virtualAddress = %p, size: %ld)\n", virtualAddress, size)); addr_t address = (addr_t)virtualAddress; - size = (size + B_PAGE_SIZE - 1) / B_PAGE_SIZE; - // get number of pages to map + addr_t pageOffset = address % B_PAGE_SIZE; + address -= pageOffset; + size = (size + pageOffset + B_PAGE_SIZE - 1) / B_PAGE_SIZE * B_PAGE_SIZE; // is the address within the valid range? - if (address < KERNEL_LOAD_BASE) { + if (address < KERNEL_LOAD_BASE || address + size > sNextVirtualAddress) { panic("mmu_free: asked to unmap out of range region (%p, size %lx)\n", (void *)address, size); } // unmap all pages within the range - for (uint32 i = 0; i < size; i++) { + for (size_t i = 0; i < size; i += B_PAGE_SIZE) { unmap_page(address); address += B_PAGE_SIZE; }