2
0
mirror of https://github.com/xcat2/xNBA.git synced 2024-12-16 00:01:34 +00:00
xNBA/src/arch/i386/core/nulltrap.c
Michael Brown df4b503a8c Added null trap code for debugging. (Must be included by adding
--nulltrap to the make target at the moment.)
2006-06-11 01:48:29 +00:00

49 lines
2.0 KiB
C

#include <stdint.h>
#include <vsprintf.h>
__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 ) {}
}