From 58fa4c59cc5d2ae7de8cd9bb09786790486816d4 Mon Sep 17 00:00:00 2001 From: Horst Schirmeier Date: Thu, 13 Feb 2014 18:27:32 +0100 Subject: [PATCH] sal/bochs: fix handling of unmapped memory Up to now, BochsMemory::isMapped() always returned true in 32-bit protected mode with a 4GB linear address space (as used by, e.g., eCos), even for addresses greater than the configured memory size. This led to lots of bogus memory dereferences in the (extended) tracing plugin. This change (a follow-up to commit 5171645) additionally checks the return value of getHostMemAddr(), and announces BX_RW (read/write access) instead of BX_READ as the intended type of memory access. In the aforementioned scenario, memory addresses greater than the memory size are now correctly detected as "not mapped". Change-Id: Ic2fa7554c869cb90191164535a601bae4dbb49b6 --- src/core/sal/bochs/BochsMemory.hpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/core/sal/bochs/BochsMemory.hpp b/src/core/sal/bochs/BochsMemory.hpp index 98d2455b..a6d7e4b6 100644 --- a/src/core/sal/bochs/BochsMemory.hpp +++ b/src/core/sal/bochs/BochsMemory.hpp @@ -95,13 +95,16 @@ public: // Map the linear address to the physical address: bx_phy_address physicalAddr; bx_bool fValid = BX_CPU(0)->dbg_xlate_linear2phy(linearAddr, (bx_phy_address*)&physicalAddr); + if (!fValid) { + return (host_address_t) ADDR_INV; // error + } // Determine the *host* address of the physical address: - Bit8u* hostAddr = BX_MEM(0)->getHostMemAddr(BX_CPU(0), physicalAddr, BX_READ); - // Now, hostAddr contains the "final" address - if (!fValid) - return ((host_address_t)ADDR_INV); // error - else - return (reinterpret_cast(hostAddr)); // okay + Bit8u* hostAddr = BX_MEM(0)->getHostMemAddr(BX_CPU(0), physicalAddr, BX_RW); + if (!hostAddr) { + return (host_address_t) ADDR_INV; // error + } + + return reinterpret_cast(hostAddr); } /**