Created
November 25, 2021 02:03
-
-
Save kostikbel/b886401fcc92dc37b49316eaf0e871ca to your computer and use it in GitHub Desktop.
throw from signal handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <err.h> | |
#include <signal.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <machine/sigframe.h> | |
static void | |
handler(int sig __unused, siginfo_t *, void *x) | |
{ | |
ucontext_t *xx; | |
xx = static_cast<ucontext_t *>(x); | |
xx->uc_mcontext.mc_onstack += 1; | |
// abort(); | |
throw 12; | |
} | |
int | |
main(int ac __unused, char **av __unused) | |
{ | |
struct sigaction sa; | |
struct sigframe xxx; | |
memset(&xxx, 0, sizeof(xxx)); | |
memset(&sa, 0, sizeof(sa)); | |
sa.sa_sigaction = handler; | |
sa.sa_flags = SA_SIGINFO; | |
if (sigaction(SIGUSR1, &sa, NULL) == -1) | |
err(1, "signal"); | |
try { | |
if (kill(getpid(), SIGUSR1) == -1) | |
err(1, "kill"); | |
} catch (int yy) { | |
printf("yy %d\n", yy); | |
} | |
printf("survived\n"); | |
return (0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment