#define _GNU_SOURCE #include #include #include #include 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"); } __attribute__((naked, noinline)) void address_probe(uint64_t *stack, struct node *data, size_t index) { __asm__ volatile( ".globl operand_stack\noperand_stack: lea 8(%rdi), %rax\n" ".globl operand_indexed\noperand_indexed: lea (%rsi,%rdx,8), %rax\n" ".globl operand_relative\noperand_relative: mov head(%rip), %rax\n" "ret\n"); } 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(); address_probe(&stack_value, &head, 2); } }