wiki:Tools/MemoryChecker

Version 2 (modified by becoulet, 15 years ago) (diff)

--

Memory access checker for Soclib

The Memory checker tool is a software memory access debugger for SoClib.

Overview

The Memory checker is able to perform several analysis on memory accesses performed by the running software to track software bugs. Access to uninitialized or freed data and stack overflow are examples of reported behaviors. It acts as the valgrind memory checker tool found on some unix.

Implementation

Like the Gdb Server, the Memory checker contains no processor specific code and can be used to manage any Soclib processor model using the generic Iss interface. It is implemented as an Iss wrapper class. When the Memory checker is in use, it intercepts all events between the processor Iss model and the Soclib platform. The running operating system must be instrumented slightly to let the Memory checker be aware of valid stack ranges and allocation ranges. The MutekH operating system is working with the Memory checker.

What is being checked

All memory accesses are monitored and checked for read to non previously initialized (written) words.

Context and stacks related checks:

  • The stack pointer register must stay in range given by the operating system for each software context in use.
  • The frame pointer register (if any) must stay in range given by the operating system for each software context in use.
  • Contexts stack ranges can not overlap (checked on context creation).
  • Stack range must be in allocated memory at context creation (as soon as allocation checks are enabled).
  • The stack memory is marked as non-initialized when a new execution context is created.
  • The stack memory is always considered as non-initialized below the stack pointer.
  • Memory r/w accesses can not occur below the stack pointer.

Memory allocation and region checks:

  • Write accesses can not occur in read only preloaded sections.
  • Preloaded sections are marked as uninitialized when appropriate.
  • Memory is marked as uninitialized on malloc() invocation.
  • Memory is marked as uninitialized on free() invocation.
  • Memory r/w accesses can not occur in freed memory.
  • Allocation are only allowed in free memory.

Suspicious memory access reporting

Suspicious memory accesses produce a message on simulator stdout stream. This simulation is not stopped anyway.

An exception can be reported to an optional Gdb Server module to stop processors execution when a suspicious memory access happend. This enables further analisys of buggy software. When using the Memory checker with the Gdb Server, the Memory checker must wrap the processor directly and must be wrapped in the Gdb Server.

Usage

Adding Memory checker support to your platform

Adding the GdbServer to your topcell is easy. First include the header:

#include "iss_memchecker.h"

Then call the init function with mapping table and loader parameters and replace processor instantiation:

   // Without Memory checker
// soclib::caba::VciXcacheWrapper<soclib::common::Mips32ElIss> cpu0("cpu0", 0, maptab, IntTab(0), 1,8,4, 1,8,4);

   // With Memory checker
   soclib::common::Memchecker<soclib::common::Mips32ElIss>::init(maptab, loader);
   soclib::caba::VciXcacheWrapper<soclib::common::Memchecker<soclib::common::Mips32ElIss> > cpu0("cpu0", 0, maptab, IntTab(0), 1,8,4, 1,8,4);

Finally do not forget to update the platform description file:

Uses('iss_wrapper', iss_t = 'common:memchecker_iss', memchecker_iss_t = 'common:mips32el'),

Using an instrumented operating system

The running operating system must communicate with the Memory checker to report information about context creation, stack range and allocator operations. This is done through read/write access to specifc memory locations which are intercepted by the Memory checker and not forwarded to the rest of the platform.

Currently the only known supported operating system is MutekH with Mips processor. Other processors are partially supported, only memory allocation checks are performed. To use the memory checker with MutekH, simply add the CONFIG_SOCLIB_MEMCHECK configuration token to your configuration file.

Note:

  • An instrumented operating system can not be used without the ISS Memory checker module as memory access won't be intercepted and may cause bus error or side effects.
  • The default base address for the register bank of the memory checker is 0x00004200. This address can be changed but must stay close to 0 to fit on some processor instruction immediate field. You should consider this if you already have components at these addresses.
  • The Memory checker registers bank is protected by a magic value and has almost no chance being modified by an other running software.

Attachments (1)

Download all attachments as: .zip