Last active
April 25, 2019 16:34
-
-
Save jedisct1/8220833d3ec09020389447a93ac905ba to your computer and use it in GitHub Desktop.
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
#define _GNU_SOURCE | |
#include <signal.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
static void | |
handler(int sig) | |
{ | |
stack_t another_stack; | |
(void) sig; | |
another_stack.ss_sp = malloc(SIGSTKSZ); | |
another_stack.ss_size = SIGSTKSZ; | |
another_stack.ss_flags = 0; | |
if (sigaltstack(&another_stack, NULL) != 0) { | |
perror("sigaltstack in handler"); /* fails with EPERM as expected */ | |
_exit(1); | |
} | |
} | |
int | |
main(void) | |
{ | |
struct sigaction sa; | |
stack_t signal_stack; | |
signal_stack.ss_sp = malloc(SIGSTKSZ); | |
signal_stack.ss_size = SIGSTKSZ; | |
signal_stack.ss_flags = 0; | |
if (sigaltstack(&signal_stack, NULL) != 0) { | |
perror("sigaltstack"); | |
} | |
sa.sa_handler = handler; | |
sigemptyset(&sa.sa_mask); | |
sa.sa_flags = SA_ONSTACK; | |
sigaction(SIGALRM, &sa, NULL); | |
alarm(1); | |
sleep(2); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment