1#include <stdio.h> 2#include <stdlib.h> 3#include <signal.h> 4 5static void handler(int sig, siginfo_t *info, void *v) 6{ 7 printf("info: sig=%d code=%d addr=0x%lx\n", 8 info->si_signo, info->si_code, (unsigned long)info->si_addr); 9 exit(0); 10} 11 12int main() 13{ 14 struct sigaction sa; 15 int val; 16 17 sa.sa_sigaction = handler; 18 sigfillset(&sa.sa_mask); 19 sa.sa_flags = SA_SIGINFO; 20 21 sigaction(SIGSEGV, &sa, NULL); 22 23 asm volatile("mov %1, %%fs; mov %%fs:0, %0" : "=r" (val) : "r"(4)); 24 25 printf("val=%d\n", val); 26 27 return 0; 28} 29