Browse Source

Added null trap code for debugging. (Must be included by adding

--nulltrap to the make target at the moment.)
tags/v0.9.3
Michael Brown 18 years ago
parent
commit
df4b503a8c
2 changed files with 49 additions and 0 deletions
  1. 48
    0
      src/arch/i386/core/nulltrap.c
  2. 1
    0
      src/arch/i386/scripts/i386.lds

+ 48
- 0
src/arch/i386/core/nulltrap.c View File

@@ -0,0 +1,48 @@
1
+#include <stdint.h>
2
+#include <vsprintf.h>
3
+
4
+__attribute__ (( noreturn, section ( ".text.null_trap" ) ))
5
+void null_function_trap ( void ) {
6
+
7
+	/* 128 bytes of NOPs; the idea of this is that if something
8
+	 * dereferences a NULL pointer and overwrites us, we at least
9
+	 * have some chance of still getting to execute the printf()
10
+	 * statement.
11
+	 */
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__ ( "nop ; nop ; nop ; nop" );
44
+
45
+	printf ( "NULL method called from %p\n", 
46
+		 __builtin_return_address ( 0 ) );
47
+	while ( 1 ) {}
48
+}

+ 1
- 0
src/arch/i386/scripts/i386.lds View File

@@ -117,6 +117,7 @@ SECTIONS {
117 117
 
118 118
     .text : AT ( _textdata_load_offset + __text ) {
119 119
 	__text = .;
120
+	*(.text.null_trap)
120 121
 	*(.text)
121 122
 	*(.text.*)
122 123
     } = 0x9090

Loading…
Cancel
Save