4 #define ASMNAME(cname) ASMNAME2 (__USER_LABEL_PREFIX__, cname)
5 #define ASMNAME2(prefix, cname) STRING (prefix) cname
9 extern "C" void abort (void);
11 extern void abort (void);
14 extern void foo(void);
20 /* Set DI/SI/BX to wrong value
21 Use following template so that RA will save/restore callee
22 save registers in prologue/epilogue */
23 #define ALTER_REGS() \
26 __asm__ __volatile__ (\
27 "movl %1, %0" : "=D" (dummy) : "i" (-INIT_EDI)\
29 __asm__ __volatile__ (\
30 "movl %1, %0" : "=S" (dummy) : "i" (-INIT_ESI)\
32 __asm__ __volatile__ (\
33 "movl %1, %0" : "=b" (dummy) : "i" (-INIT_EBX)\
37 #if defined __PIC__ || defined __USING_SJLJ_EXCEPTIONS__
44 void __attribute__ ((noinline
))
45 copy (char *p
, int size
)
47 __builtin_strncpy (p
, "good", size
);
50 int g_edi
=INIT_EDI
, g_esi
=INIT_ESI
, g_ebx
=INIT_EBX
;
51 int g_ebp
, g_ebp_save
, g_esp
, g_esp_save
;
58 // Init registers to correct value.
59 // Use following template so that RA will save/restore callee
60 // save registers in prologue/epilogue
61 __asm__
__volatile__ (
66 __asm__
__volatile__ (
71 __asm__
__volatile__ (
76 __asm__
__volatile__ (
77 "movl %ebp," ASMNAME("g_ebp_save")"\n\t"
78 "movl %esp," ASMNAME("g_esp_save")"\n\t"
87 // Get DI/SI/BX register value after exception caught
88 __asm__
__volatile__ (
89 "movl %edi," ASMNAME("g_edi")"\n\t"
90 "movl %esi," ASMNAME("g_esi")"\n\t"
91 "movl %ebx," ASMNAME("g_ebx")"\n\t"
92 "movl %ebp," ASMNAME("g_ebp")"\n\t"
93 "movl %esp," ASMNAME("g_esp")"\n\t"
96 // Check if DI/SI/BX register value are the same as before calling
98 if (g_edi
!= INIT_EDI
)
102 printf("edi=%d, correct value:%d\n", g_edi
, INIT_EDI
);
105 if (g_esi
!= INIT_ESI
)
109 printf("esi=%d, correct value:%d\n", g_esi
, INIT_ESI
);
112 if (g_ebx
!= INIT_EBX
)
116 printf("ebx=%d, correct value:%d\n", g_ebx
, INIT_EBX
);
119 if (g_ebp
!= g_ebp_save
)
123 printf("ebp=0x%x, correct value:0x%x\n", g_ebp
, g_ebp_save
);
126 if (g_esp
!= g_esp_save
)
130 printf("esp=0x%x, correct value:0x%x\n", g_esp
, g_esp_save
);