You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nulltrap.c 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <stdint.h>
  2. #include <stdio.h>
  3. __attribute__ (( noreturn, section ( ".text.null_trap" ) ))
  4. void null_function_trap ( void ) {
  5. void *stack;
  6. /* 128 bytes of NOPs; the idea of this is that if something
  7. * dereferences a NULL pointer and overwrites us, we at least
  8. * have some chance of still getting to execute the printf()
  9. * statement.
  10. */
  11. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  12. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  13. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  14. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  15. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  16. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  17. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  18. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  19. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  20. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  21. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  22. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  23. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  24. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  25. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  26. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  27. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  28. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  29. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  30. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  31. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  32. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  33. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  34. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  35. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  36. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  37. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  38. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  39. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  40. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  41. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  42. __asm__ __volatile__ ( "nop ; nop ; nop ; nop" );
  43. __asm__ __volatile__ ( "movl %%esp, %0" : "=r" ( stack ) );
  44. printf ( "NULL method called from %p (stack %p)\n",
  45. __builtin_return_address ( 0 ), stack );
  46. DBG_HD ( stack, 256 );
  47. while ( 1 ) {}
  48. }