From df4b503a8c138edc0fdcfe920c7d6b6629cd2971 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sun, 11 Jun 2006 01:48:29 +0000 Subject: [PATCH] Added null trap code for debugging. (Must be included by adding --nulltrap to the make target at the moment.) --- src/arch/i386/core/nulltrap.c | 48 ++++++++++++++++++++++++++++++++++ src/arch/i386/scripts/i386.lds | 1 + 2 files changed, 49 insertions(+) create mode 100644 src/arch/i386/core/nulltrap.c diff --git a/src/arch/i386/core/nulltrap.c b/src/arch/i386/core/nulltrap.c new file mode 100644 index 00000000..bd4b7577 --- /dev/null +++ b/src/arch/i386/core/nulltrap.c @@ -0,0 +1,48 @@ +#include +#include + +__attribute__ (( noreturn, section ( ".text.null_trap" ) )) +void null_function_trap ( void ) { + + /* 128 bytes of NOPs; the idea of this is that if something + * dereferences a NULL pointer and overwrites us, we at least + * have some chance of still getting to execute the printf() + * statement. + */ + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + __asm__ __volatile__ ( "nop ; nop ; nop ; nop" ); + + printf ( "NULL method called from %p\n", + __builtin_return_address ( 0 ) ); + while ( 1 ) {} +} diff --git a/src/arch/i386/scripts/i386.lds b/src/arch/i386/scripts/i386.lds index 4a984a95..48dd777c 100644 --- a/src/arch/i386/scripts/i386.lds +++ b/src/arch/i386/scripts/i386.lds @@ -117,6 +117,7 @@ SECTIONS { .text : AT ( _textdata_load_offset + __text ) { __text = .; + *(.text.null_trap) *(.text) *(.text.*) } = 0x9090