[OpenACC] Implement 'collapse' for combined constructs.
[llvm-project.git] / lldb / test / API / functionalities / signal / handle-segv / main.c
blob27d9b8e500abcb3d0424444989ee96cdaaed0c61
1 #include <sys/mman.h>
2 #include <signal.h>
3 #include <stdio.h>
4 #include <unistd.h>
6 enum {
7 kMmapSize = 0x1000,
8 kMagicValue = 47,
9 };
11 void *address;
12 volatile sig_atomic_t signaled = 0;
14 void handler(int sig)
16 signaled = 1;
17 if (munmap(address, kMmapSize) != 0)
19 perror("munmap");
20 _exit(5);
23 void* newaddr = mmap(address, kMmapSize, PROT_READ | PROT_WRITE,
24 MAP_ANON | MAP_FIXED | MAP_PRIVATE, -1, 0);
25 if (newaddr != address)
27 fprintf(stderr, "Newly mmaped address (%p) does not equal old address (%p).\n",
28 newaddr, address);
29 _exit(6);
31 *(int*)newaddr = kMagicValue;
34 int main()
36 if (signal(SIGSEGV, handler) == SIG_ERR)
38 perror("signal");
39 return 1;
42 address = mmap(NULL, kMmapSize, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
43 if (address == MAP_FAILED)
45 perror("mmap");
46 return 2;
49 // This should first trigger a segfault. Our handler will make the memory readable and write
50 // the magic value into memory.
51 if (*(int*)address != kMagicValue)
52 return 3;
54 if (! signaled)
55 return 4;
57 return 0;