| 1 | #include <linux/mman.h> |
| 2 | #include <sys/mman.h> |
| 3 | #include <unistd.h> |
| 4 | |
| 5 | int main(int argc, char const *argv[]) { |
| 6 | size_t page_size = sysconf(_SC_PAGESIZE); |
| 7 | // Note that we allocate memory here because if we used |
| 8 | // stack or globals lldb might read it in the course of |
| 9 | // running to the breakpoint. Before the test can look |
| 10 | // for those reads. |
| 11 | char *buf = mmap(addr: 0, len: page_size, PROT_READ | PROT_WRITE, |
| 12 | MAP_ANONYMOUS | MAP_SHARED, fd: -1, offset: 0); |
| 13 | if (buf == MAP_FAILED) |
| 14 | return 1; |
| 15 | |
| 16 | // Some known values to go in the corefile, since we cannot |
| 17 | // write to corefile memory. |
| 18 | buf[0] = 'L'; |
| 19 | buf[1] = 'L'; |
| 20 | buf[2] = 'D'; |
| 21 | buf[3] = 'B'; |
| 22 | |
| 23 | #define sign_ptr(ptr) __asm__ __volatile__("pacdza %0" : "=r"(ptr) : "r"(ptr)) |
| 24 | |
| 25 | // Set top byte to something. |
| 26 | char *buf_with_non_address = (char *)((size_t)buf | (size_t)0xff << 56); |
| 27 | sign_ptr(buf_with_non_address); |
| 28 | // Address is now: |
| 29 | // <8 bit top byte tag><pointer signature><virtual address> |
| 30 | |
| 31 | // Uncomment this line to crash and generate a corefile. |
| 32 | // Prints so we know what fixed address to look for in testing. |
| 33 | // printf("buf: %p\n", buf); |
| 34 | // printf("buf_with_non_address: %p\n", buf_with_non_address); |
| 35 | // *(char*)0 = 0; |
| 36 | |
| 37 | return 0; // Set break point at this line. |
| 38 | } |
| 39 | |