1 | #include <stdio.h> |
---|---|
2 | |
3 | // For the test case, we really want the the layout of this binary |
4 | // to be: |
5 | // |
6 | // foo() |
7 | // bar() - 4096 bytes of nop's |
8 | // main() |
9 | // "HI" string |
10 | // |
11 | // in reality getting this layout from the compiler and linker |
12 | // is a crapshoot, so I have yaml's checked in of the correct |
13 | // layout. Recompiling from source may not get the needed |
14 | // binary layout. |
15 | |
16 | static int bar(); |
17 | static int foo() { return 5 + bar(); } |
18 | // A function of 4096 bytes, so when main() loads the |
19 | // address of foo() before this one, it has to subtract |
20 | // a 4096 page. |
21 | #define SIXTY_FOUR_BYTES_NOP \ |
22 | asm("nop"); \ |
23 | asm("nop"); \ |
24 | asm("nop"); \ |
25 | asm("nop"); \ |
26 | asm("nop"); \ |
27 | asm("nop"); \ |
28 | asm("nop"); \ |
29 | asm("nop"); \ |
30 | asm("nop"); \ |
31 | asm("nop"); \ |
32 | asm("nop"); \ |
33 | asm("nop"); \ |
34 | asm("nop"); \ |
35 | asm("nop"); \ |
36 | asm("nop"); \ |
37 | asm("nop"); |
38 | |
39 | static int bar() { |
40 | SIXTY_FOUR_BYTES_NOP; |
41 | SIXTY_FOUR_BYTES_NOP; |
42 | SIXTY_FOUR_BYTES_NOP; |
43 | SIXTY_FOUR_BYTES_NOP; |
44 | SIXTY_FOUR_BYTES_NOP; |
45 | SIXTY_FOUR_BYTES_NOP; |
46 | SIXTY_FOUR_BYTES_NOP; |
47 | SIXTY_FOUR_BYTES_NOP; |
48 | SIXTY_FOUR_BYTES_NOP; |
49 | SIXTY_FOUR_BYTES_NOP; |
50 | SIXTY_FOUR_BYTES_NOP; |
51 | SIXTY_FOUR_BYTES_NOP; |
52 | SIXTY_FOUR_BYTES_NOP; |
53 | SIXTY_FOUR_BYTES_NOP; |
54 | SIXTY_FOUR_BYTES_NOP; |
55 | SIXTY_FOUR_BYTES_NOP; |
56 | SIXTY_FOUR_BYTES_NOP; |
57 | SIXTY_FOUR_BYTES_NOP; |
58 | SIXTY_FOUR_BYTES_NOP; |
59 | SIXTY_FOUR_BYTES_NOP; |
60 | SIXTY_FOUR_BYTES_NOP; |
61 | SIXTY_FOUR_BYTES_NOP; |
62 | SIXTY_FOUR_BYTES_NOP; |
63 | SIXTY_FOUR_BYTES_NOP; |
64 | SIXTY_FOUR_BYTES_NOP; |
65 | SIXTY_FOUR_BYTES_NOP; |
66 | SIXTY_FOUR_BYTES_NOP; |
67 | SIXTY_FOUR_BYTES_NOP; |
68 | SIXTY_FOUR_BYTES_NOP; |
69 | SIXTY_FOUR_BYTES_NOP; |
70 | SIXTY_FOUR_BYTES_NOP; |
71 | SIXTY_FOUR_BYTES_NOP; |
72 | SIXTY_FOUR_BYTES_NOP; |
73 | SIXTY_FOUR_BYTES_NOP; |
74 | SIXTY_FOUR_BYTES_NOP; |
75 | SIXTY_FOUR_BYTES_NOP; |
76 | SIXTY_FOUR_BYTES_NOP; |
77 | SIXTY_FOUR_BYTES_NOP; |
78 | SIXTY_FOUR_BYTES_NOP; |
79 | SIXTY_FOUR_BYTES_NOP; |
80 | SIXTY_FOUR_BYTES_NOP; |
81 | SIXTY_FOUR_BYTES_NOP; |
82 | SIXTY_FOUR_BYTES_NOP; |
83 | SIXTY_FOUR_BYTES_NOP; |
84 | SIXTY_FOUR_BYTES_NOP; |
85 | SIXTY_FOUR_BYTES_NOP; |
86 | SIXTY_FOUR_BYTES_NOP; |
87 | SIXTY_FOUR_BYTES_NOP; |
88 | SIXTY_FOUR_BYTES_NOP; |
89 | SIXTY_FOUR_BYTES_NOP; |
90 | SIXTY_FOUR_BYTES_NOP; |
91 | SIXTY_FOUR_BYTES_NOP; |
92 | SIXTY_FOUR_BYTES_NOP; |
93 | SIXTY_FOUR_BYTES_NOP; |
94 | SIXTY_FOUR_BYTES_NOP; |
95 | SIXTY_FOUR_BYTES_NOP; |
96 | SIXTY_FOUR_BYTES_NOP; |
97 | SIXTY_FOUR_BYTES_NOP; |
98 | SIXTY_FOUR_BYTES_NOP; |
99 | SIXTY_FOUR_BYTES_NOP; |
100 | SIXTY_FOUR_BYTES_NOP; |
101 | SIXTY_FOUR_BYTES_NOP; |
102 | SIXTY_FOUR_BYTES_NOP; |
103 | SIXTY_FOUR_BYTES_NOP; |
104 | return 5; |
105 | } |
106 | int main() { |
107 | int (*f)(void) = foo; |
108 | puts(s: "HI"); |
109 | return f(); |
110 | } |
111 |