AnyPS5/core/libs/tests/ExceptionCCleanup.c
Dean Galvin 6670c52571 fix(libc): run the cleanups of frames that use the C personality
GCC gives C code built with -fexceptions, and cleanup-only functions
after link-time optimization, the C personality __gcc_personality_v0.
The unwinder accepted only its own C++ personality, so an exception
thrown through such a frame was never caught.

libc now provides the C personality, which never catches and installs
the frame's cleanup landing pad in the cleanup phase, and the unwinder
calls it for those frames.
2026-10-04 05:32:55 +13:00

14 lines
457 B
C

struct CleanupCounter { int* count; };
static void Leave(struct CleanupCounter* counter) { ++*counter->count; }
void CallWithCleanup(void (*function)(void), int* count) {
struct CleanupCounter counter __attribute__((cleanup(Leave))) = {count};
function();
}
void CallAroundCleanup(void (*before)(void), void (*within)(void), int* count) {
before();
struct CleanupCounter counter __attribute__((cleanup(Leave))) = {count};
within();
}