xref: /openbmc/qemu/tests/tcg/aarch64/lse2-fault.c (revision 784155cd)
1 #include <sys/mman.h>
2 #include <sys/shm.h>
3 #include <unistd.h>
4 #include <stdio.h>
5 
6 int main()
7 {
8     int psize = getpagesize();
9     int id;
10     void *p;
11 
12     /*
13      * We need a shared mapping to enter CF_PARALLEL mode.
14      * The easiest way to get that is shmat.
15      */
16     id = shmget(IPC_PRIVATE, 2 * psize, IPC_CREAT | 0600);
17     if (id < 0) {
18         perror("shmget");
19         return 2;
20     }
21     p = shmat(id, NULL, 0);
22     if (p == MAP_FAILED) {
23         perror("shmat");
24         return 2;
25     }
26 
27     /* Protect the second page. */
28     if (mprotect(p + psize, psize, PROT_NONE) < 0) {
29         perror("mprotect");
30         return 2;
31     }
32 
33     /*
34      * Load 4 bytes, 6 bytes from the end of the page.
35      * On success this will load 0 from the newly allocated shm.
36      */
37     return *(int *)(p + psize - 6);
38 }
39