fix(libc): only call what() on std::exception types in DefaultTerminate #19

Closed
franpeza wants to merge 1 commit from upstream-pr/19 into main
franpeza commented 2026-09-26 20:28:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by franpeza on 2026-09-26T20:28:07Z.


DefaultTerminate assumed every uncaught exception object has a std::exception vtable and called its what() slot. When the thrown type does not derive from std::exception (for example throw 42, a plain class, or a foreign exception), it read an arbitrary word as a vtable pointer and crashed before printing the terminate message.

The thrown type is now matched against std::exception with the existing Match helper, and what() is called on the adjusted base pointer the match returns. The Windows guest-ABI path is unchanged.

Testing: found and verified in my fork's macOS port, where an uncaught non-std::exception crashed inside the terminate handler; it now prints the type name and aborts. I have not built this branch on Linux or Windows.

Note: #5 also edits these lines (it replaces fprintf with RawLog), so whichever lands second needs a trivial rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4649477619 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19). Originally posted by [franpeza](https://github.com/franpeza) on 2026-09-26T20:28:07Z. --- `DefaultTerminate` assumed every uncaught exception object has a `std::exception` vtable and called its `what()` slot. When the thrown type does not derive from `std::exception` (for example `throw 42`, a plain class, or a foreign exception), it read an arbitrary word as a vtable pointer and crashed before printing the terminate message. The thrown type is now matched against `std::exception` with the existing `Match` helper, and `what()` is called on the adjusted base pointer the match returns. The Windows guest-ABI path is unchanged. Testing: found and verified in my fork's macOS port, where an uncaught non-`std::exception` crashed inside the terminate handler; it now prints the type name and aborts. I have not built this branch on Linux or Windows. Note: #5 also edits these lines (it replaces `fprintf` with `RawLog`), so whichever lands second needs a trivial rebase.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!19
No description provided.