| 1742 | #ifdef _WIN32 |
| 1743 | |
| 1744 | static LONG exception_handler(PEXCEPTION_POINTERS pExp) noexcept |
| 1745 | { |
| 1746 | if (pExp->ExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT) |
| 1747 | { |
| 1748 | return EXCEPTION_CONTINUE_SEARCH; |
| 1749 | } |
| 1750 | |
| 1751 | const auto ptr = reinterpret_cast<u8*>(pExp->ExceptionRecord->ExceptionInformation[1]); |
| 1752 | const bool is_writing = pExp->ExceptionRecord->ExceptionInformation[0] == 1; |
| 1753 | const bool is_executing = pExp->ExceptionRecord->ExceptionInformation[0] == 8; |
| 1754 | |
| 1755 | if (pExp->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION && !is_executing) |
| 1756 | { |
| 1757 | u32 addr = 0; |
| 1758 | |
| 1759 | if (auto [addr0, ok] = vm::try_get_addr(ptr); ok) |
| 1760 | { |
| 1761 | addr = addr0; |
| 1762 | } |
| 1763 | else if (const usz exec64 = (ptr - vm::g_exec_addr) / 2; exec64 <= u32{umax}) |
| 1764 | { |
| 1765 | addr = static_cast<u32>(exec64); |
| 1766 | } |
| 1767 | else |
| 1768 | { |
| 1769 | return EXCEPTION_CONTINUE_SEARCH; |
| 1770 | } |
| 1771 | |
| 1772 | if (thread_ctrl::get_current() && handle_access_violation(addr, is_writing, pExp->ContextRecord)) |
| 1773 | { |
| 1774 | return EXCEPTION_CONTINUE_EXECUTION; |
| 1775 | } |
| 1776 | } |
| 1777 | |
| 1778 | switch (pExp->ExceptionRecord->ExceptionCode) |
| 1779 | { |
| 1780 | case EXCEPTION_ACCESS_VIOLATION: |
| 1781 | case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: |
| 1782 | case EXCEPTION_DATATYPE_MISALIGNMENT: |
| 1783 | case EXCEPTION_ILLEGAL_INSTRUCTION: |
| 1784 | case EXCEPTION_IN_PAGE_ERROR: |
| 1785 | case EXCEPTION_INT_DIVIDE_BY_ZERO: |
| 1786 | case EXCEPTION_NONCONTINUABLE_EXCEPTION: |
| 1787 | case EXCEPTION_PRIV_INSTRUCTION: |
| 1788 | // case EXCEPTION_STACK_OVERFLOW: |
| 1789 | { |
| 1790 | sys_log.notice("\n%s", dump_useful_thread_info()); |
| 1791 | logs::listener::sync_all(); |
| 1792 | break; |
| 1793 | } |
| 1794 | default: |
| 1795 | { |
| 1796 | break; |
| 1797 | } |
| 1798 | } |
| 1799 | |
| 1800 | return EXCEPTION_CONTINUE_SEARCH; |
| 1801 | } |
nothing calls this directly
no test coverage detected