Browsing the internet, I found the only solution: throw an exception from a signal handler and use -fnon-call-exceptions. At the same time, this is considered illegal. Some people advise to patch the stack frame to throw an exception on the return from a signal handler, but this is not cross-platform.
Is there any alternative to POSIX signals and related API for that in Linux that does work on all Linux platforms and is legal?