| 278 | #endif |
| 279 | |
| 280 | LONG WINAPI seh_filter(struct _EXCEPTION_POINTERS* ep) { |
| 281 | #ifndef _M_ARM64 |
| 282 | if (ep->ContextRecord->EFlags & AC) { |
| 283 | // the comment on the next line was for the x64 binary translator, I'm not sure if it still applies to the JIT |
| 284 | // :TODO: not sure what causes this, seen it in winroids |
| 285 | ep->ContextRecord->EFlags &= ~AC; |
| 286 | return EXCEPTION_CONTINUE_EXECUTION; |
| 287 | } |
| 288 | #endif |
| 289 | KThread* currentThread = KThread::currentThread(); |
| 290 | if (!currentThread) { |
| 291 | return EXCEPTION_CONTINUE_SEARCH; |
| 292 | } |
| 293 | CPU* cpu = currentThread->cpu; |
| 294 | if (cpu != (CPU*)ep->ContextRecord->CPU_REG) { |
| 295 | return EXCEPTION_CONTINUE_SEARCH; |
| 296 | } |
| 297 | |
| 298 | bool inBinaryTranslator = cpu->memory->isCode((U8*)ep->ContextRecord->REG_IP); |
| 299 | if (!inBinaryTranslator) { |
| 300 | return EXCEPTION_CONTINUE_SEARCH; |
| 301 | } |
| 302 | |
| 303 | syncFromException(ep); |
| 304 | //klog_fmt("exception at %llx(%d)", ep->ExceptionRecord->ExceptionInformation[1], (U32)ep->ExceptionRecord->ExceptionInformation[0]); |
| 305 | bool readException = ep->ExceptionRecord->ExceptionInformation[0] == 0; |
| 306 | void* result = cpu->startException((U32)ep->ExceptionRecord->ExceptionInformation[1], readException); |
| 307 | if (result) { |
| 308 | syncToException(ep); |
| 309 | ep->ContextRecord->SET_REG_IP(result); |
| 310 | return EXCEPTION_CONTINUE_EXECUTION; |
| 311 | } |
| 312 | |
| 313 | InException inException(cpu); |
| 314 | |
| 315 | if (ep->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION || ep->ExceptionRecord->ExceptionCode == EXCEPTION_DATATYPE_MISALIGNMENT || ep->ExceptionRecord->ExceptionCode == STATUS_ILLEGAL_INSTRUCTION) { |
| 316 | BOXEDWINE_CRITICAL_SECTION_WITH_MUTEX(cpu->memory->mutex); // jitCache needs this |
| 317 | U32 eip = 0; |
| 318 | if (!getMemData(cpu->memory)->findOpFromJitAddress((U8*)ep->ContextRecord->REG_IP, eip)) { |
| 319 | return EXCEPTION_CONTINUE_SEARCH; |
| 320 | } |
| 321 | #ifdef _DEBUG |
| 322 | if (ep->ExceptionRecord->ExceptionCode != STATUS_ILLEGAL_INSTRUCTION && eip != cpu->eip.u32) { |
| 323 | klog_fmt("%x/%x", cpu->eip.u32, eip); |
| 324 | } |
| 325 | #endif |
| 326 | cpu->eip.u32 = eip; |
| 327 | DecodedOp* op = cpu->getNextOp(); |
| 328 | #ifndef BOXEDWINE_64 |
| 329 | if (op->inst == Movsd || op->inst == Movsw || op->inst == Movsb) { |
| 330 | cpu->reg[6].u32 = ep->ContextRecord->Esi; |
| 331 | if (!readException && (op->flags2 & OP_FLAG2_WRITE_SAVED_ADDRESS)) { |
| 332 | cpu->reg[7].u32 = cpu->tmpReg; |
| 333 | } else { |
| 334 | cpu->reg[7].u32 = ep->ContextRecord->Edx; |
| 335 | } |
| 336 | if (op->repNotZero || op->repZero) { |
| 337 | cpu->reg[1].u32 = ep->ContextRecord->Ecx; |
nothing calls this directly
no test coverage detected