| @@ -75,3 +75,125 @@ t1: · 74 unmodified lines |
| 75 | 75 | /* ---------------------------------------------- */ |
| 76 | 76 | #endif |
| 77 | 77 | /* ---------------------------------------------- */ |
| 78 | + |
| 79 | + |
| 80 | +/* ---------------------------------------------- */ |
| 81 | +#ifndef TCC_TARGET_X86_64 |
| 82 | +/* ---------------------------------------------- */ |
| 83 | + |
| 84 | +/* |
| 85 | + int _except_handler3( |
| 86 | + PEXCEPTION_RECORD exception_record, |
| 87 | + PEXCEPTION_REGISTRATION registration, |
| 88 | + PCONTEXT context, |
| 89 | + PEXCEPTION_REGISTRATION dispatcher |
| 90 | + ); |
| 91 | + |
| 92 | + int __cdecl _XcptFilter( |
| 93 | + unsigned long xcptnum, |
| 94 | + PEXCEPTION_POINTERS pxcptinfoptrs |
| 95 | + ); |
| 96 | + |
| 97 | + struct _sehrec { |
| 98 | + void *esp; // 0 |
| 99 | + void *exception_pointers; // 1 |
| 100 | + void *prev; // 2 |
| 101 | + void *handler; // 3 |
| 102 | + void *scopetable; // 4 |
| 103 | + int trylevel; // 5 |
| 104 | + void *ebp // 6 |
| 105 | + }; |
| 106 | + |
| 107 | + // this is what the assembler code below means: |
| 108 | + __try |
| 109 | + { |
| 110 | + // ... |
| 111 | + } |
| 112 | + __except (_XcptFilter(GetExceptionCode(), GetExceptionInformation())) |
| 113 | + { |
| 114 | + exit(GetExceptionCode()); |
| 115 | + } |
| 116 | +*/ |
| 117 | + |
| 118 | +.globl _exception_info |
| 119 | +_exception_info: |
| 120 | + mov 1*4-24(%ebp),%eax |
| 121 | + ret |
| 122 | + |
| 123 | +.globl _exception_code |
| 124 | +_exception_code: |
| 125 | + call _exception_info |
| 126 | + mov (%eax),%eax |
| 127 | + mov (%eax),%eax |
| 128 | + ret |
| 129 | + |
| 130 | +seh_filter: |
| 131 | + call _exception_info |
| 132 | + push %eax |
| 133 | + call _exception_code |
| 134 | + push %eax |
| 135 | + call _XcptFilter |
| 136 | + add $ 8,%esp |
| 137 | + ret |
| 138 | + |
| 139 | +seh_except: |
| 140 | + mov 0*4-24(%ebp),%esp |
| 141 | + call _exception_code |
| 142 | + push %eax |
| 143 | + call _exit |
| 144 | + |
| 145 | +// msvcrt wants scopetables aligned and in read-only segment (using .text) |
| 146 | +.align 4 |
| 147 | +seh_scopetable: |
| 148 | + .long -1 |
| 149 | + .long seh_filter |
| 150 | + .long seh_except |
| 151 | + |
| 152 | +seh_handler: |
| 153 | + jmp _except_handler3 |
| 154 | + |
| 155 | +.globl __try__ |
| 156 | +__try__: |
| 157 | + push %ebp |
| 158 | + mov 8(%esp),%ebp |
| 159 | + |
| 160 | +// void *esp; |
| 161 | + lea 12(%esp),%eax |
| 162 | + mov %eax,0*4(%ebp) |
| 163 | + |
| 164 | +// void *exception_pointers; |
| 165 | + xor %eax,%eax |
| 166 | + mov %eax,1*4(%ebp) |
| 167 | + |
| 168 | +// void *prev; |
| 169 | + mov %fs:0,%eax |
| 170 | + mov %eax,2*4(%ebp) |
| 171 | + |
| 172 | +// void *handler; |
| 173 | + mov $ seh_handler,%eax |
| 174 | + mov %eax,3*4(%ebp) |
| 175 | + |
| 176 | +// void *scopetable; |
| 177 | + mov $ seh_scopetable,%eax |
| 178 | + mov %eax,4*4(%ebp) |
| 179 | + |
| 180 | +// int trylevel; |
| 181 | + xor %eax,%eax |
| 182 | + mov %eax,5*4(%ebp) |
| 183 | + |
| 184 | +// register new SEH |
| 185 | + lea 2*4(%ebp),%eax |
| 186 | + mov %eax,%fs:0 |
| 187 | + |
| 188 | + pop %ebp |
| 189 | + ret |
| 190 | + |
| 191 | +/* ---------------------------------------------- */ |
| 192 | +#else |
| 193 | +/* ---------------------------------------------- */ |
| 194 | + |
| 195 | +/* SEH on x86-64 not implemented */ |
| 196 | + |
| 197 | +/* ---------------------------------------------- */ |
| 198 | +#endif |
| 199 | +/* ---------------------------------------------- */ |