aboutsummaryrefslogtreecommitdiff
path: root/tests/tcg/aarch64/lse2-fault.c
blob: 2187219a083e823b4dbb7f5cf8733c9e28c220ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <sys/mman.h>
#include <sys/shm.h>
#include <unistd.h>
#include <stdio.h>

int main()
{
    int psize = getpagesize();
    int id;
    void *p;

    /*
     * We need a shared mapping to enter CF_PARALLEL mode.
     * The easiest way to get that is shmat.
     */
    id = shmget(IPC_PRIVATE, 2 * psize, IPC_CREAT | 0600);
    if (id < 0) {
        perror("shmget");
        return 2;
    }
    p = shmat(id, NULL, 0);
    if (p == MAP_FAILED) {
        perror("shmat");
        return 2;
    }

    /* Protect the second page. */
    if (mprotect(p + psize, psize, PROT_NONE) < 0) {
        perror("mprotect");
        return 2;
    }

    /*
     * Load 4 bytes, 6 bytes from the end of the page.
     * On success this will load 0 from the newly allocated shm.
     */
    return *(int *)(p + psize - 6);
}