Last active
July 18, 2024 07:43
-
-
Save Cyberax/5bd53bff3308d6e026d414f93de4a62d to your computer and use it in GitHub Desktop.
SIGSEGV benchmark
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 <signal.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <setjmp.h> | |
sigjmp_buf target; | |
static void handler(int sig, siginfo_t *si, void *unused) | |
{ | |
siglongjmp(target, 1); | |
} | |
int main(int argc, char *argv[]) | |
{ | |
char *p; | |
long long int count = 0; | |
struct sigaction sa; | |
sa.sa_flags = SA_SIGINFO; | |
sigemptyset(&sa.sa_mask); | |
sa.sa_sigaction = handler; | |
if (sigaction(SIGSEGV, &sa, NULL) == -1) { | |
perror("sigaction"); | |
return 1; | |
} | |
p = NULL; | |
sigsetjmp(target, 1); | |
count++; | |
if (count == 1000000) { | |
printf("Done\n"); | |
exit(0); | |
} | |
*p = 11; // SIGSEGV | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment