Signed-off-by: Mark Cave-Ayland <mark.cave-ayland(a)ilande.co.uk>
---
openbios-devel/arch/ppc/qemu/ofmem.c | 7 ++++---
openbios-devel/arch/sparc32/lib.c | 6 +++---
openbios-devel/arch/sparc64/ofmem_sparc64.c | 4 ++--
3 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/openbios-devel/arch/ppc/qemu/ofmem.c b/openbios-devel/arch/ppc/qemu/ofmem.c
index 0161a17..429f43b 100644
--- a/openbios-devel/arch/ppc/qemu/ofmem.c
+++ b/openbios-devel/arch/ppc/qemu/ofmem.c
@@ -549,9 +549,10 @@ ofmem_init(void)
{
ofmem_t *ofmem = ofmem_arch_get_private();
- ofmem_claim_phys(0, get_ram_bottom(), 0);
- ofmem_claim_virt(0, get_ram_bottom(), 0);
- ofmem_map(0, 0, get_ram_bottom(), 0);
+ /* Map the memory (don't map page 0 to allow catching of NULL dereferences) */
+ ofmem_claim_phys(PAGE_SIZE, get_ram_bottom() - PAGE_SIZE, 0);
+ ofmem_claim_virt(PAGE_SIZE, get_ram_bottom() - PAGE_SIZE, 0);
+ ofmem_map(PAGE_SIZE, PAGE_SIZE, get_ram_bottom() - PAGE_SIZE, 0);
/* Map everything at the top of physical RAM 1:1, minus the OpenBIOS ROM in RAM copy */
ofmem_claim_phys(get_ram_top(), get_hash_base() + HASH_SIZE - get_ram_top(), 0);
diff --git a/openbios-devel/arch/sparc32/lib.c b/openbios-devel/arch/sparc32/lib.c
index c0df654..4ff3619 100644
--- a/openbios-devel/arch/sparc32/lib.c
+++ b/openbios-devel/arch/sparc32/lib.c
@@ -403,9 +403,9 @@ init_mmu_swift(void)
ofmem_arch_map_pages(pa, va, size, ofmem_arch_default_translation_mode(pa));
ofmem_map_page_range(pa, va, size, ofmem_arch_default_translation_mode(pa));
- // 1:1 mapping for RAM
- ofmem_arch_map_pages(0, 0, LOWMEMSZ, ofmem_arch_default_translation_mode(0));
- ofmem_map_page_range(0, 0, LOWMEMSZ, ofmem_arch_default_translation_mode(0));
+ // 1:1 mapping for RAM (don't map page 0 to allow catching of NULL dereferences)
+ ofmem_arch_map_pages(PAGE_SIZE, PAGE_SIZE, LOWMEMSZ - PAGE_SIZE, ofmem_arch_default_translation_mode(0));
+ ofmem_map_page_range(PAGE_SIZE, PAGE_SIZE, LOWMEMSZ - PAGE_SIZE, ofmem_arch_default_translation_mode(0));
/*
* Flush cache
diff --git a/openbios-devel/arch/sparc64/ofmem_sparc64.c b/openbios-devel/arch/sparc64/ofmem_sparc64.c
index 50224e6..ece51f9 100644
--- a/openbios-devel/arch/sparc64/ofmem_sparc64.c
+++ b/openbios-devel/arch/sparc64/ofmem_sparc64.c
@@ -365,8 +365,8 @@ void ofmem_init( void )
/* inherit translations set up by entry.S */
ofmem_walk_boot_map(remap_page_range);
- /* Map the memory */
- ofmem_map_page_range(0, 0, qemu_mem_size, 0x36);
+ /* Map the memory (don't map page 0 to allow catching of NULL dereferences) */
+ ofmem_map_page_range(PAGE_SIZE, PAGE_SIZE, qemu_mem_size - PAGE_SIZE, 0x36);
if (!(retained->magic == RETAIN_MAGIC)) {
OFMEM_TRACE("ofmem_init: no retained magic found, creating\n");
--
1.7.10.4