Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #define _GNU_SOURCE
  2. #include <execinfo.h>
  3. #include <signal.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <ucontext.h>
  8. #include <unistd.h>
  9. #include <sys/mman.h>
  10.  
  11. int err=0;
  12.  
  13. void handler(int sig, siginfo_t *info, void *uncontext ){
  14. //  char buff[104];
  15. //  snprintf(buff,100,"%d signal number: %d, An errno value: %d, Signal value: %d.\n",sig, (*info).si_signo, (*info).si_errno, (*info).si_code);
  16. //  write(2,buff,100);
  17.     err++;
  18.     printf("Error %d\n",err);
  19. }
  20.  
  21. int main(void) {
  22.     struct sigaction mysig_act;
  23.     mysig_act.sa_flags = SA_SIGINFO;
  24.     mysig_act.sa_sigaction = &handler;
  25.     sigaction(SIGSEGV,&mysig_act,NULL);
  26.  
  27.     long *addr = mmap(NULL,44,PROT_NONE,MAP_PRIVATE,0,0);
  28.  
  29.     munmap(addr,44);
  30.     (*addr) = 4;
  31.     return EXIT_SUCCESS;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement