summaryrefslogtreecommitdiff
path: root/gui/targets/segments.c
blob: c52ad3bd1415540c4fa1986ab9c40dae3184742f (plain) (blame)
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
#define _GNU_SOURCE
#include <assert.h>
#include <stdint.h>
#include <sys/mman.h>
#include <unistd.h>

struct node { struct node *next; uint64_t value; };
struct node head, middle, tail;
volatile uint64_t counter;
uint64_t *stack_pointer;
__attribute__((noinline)) void checkpoint(void) { __asm__ volatile("" ::: "memory"); }

int main(void) {
    uint64_t stack_value = 42;
    stack_pointer = &stack_value;
    const size_t size = (size_t)1 << 32;
    int fd = memfd_create("ztrace-test-segment", 0);
    assert(fd >= 0 && ftruncate(fd, size) == 0);
    unsigned char *bytes = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    assert(bytes != MAP_FAILED);
    close(fd);
    bytes[0] = 'A';
    bytes[size - 1] = 'Z';
    head = (struct node){&middle, 1};
    middle = (struct node){&tail, 2};
    tail = (struct node){&head, 3};
    for (;;) { ++counter; checkpoint(); }
}