CCTLib
Calling-context and data-object attribution library for Intel Pin
deadspy_cross_page_qword_tp.c
Go to the documentation of this file.
1 // Deadspy ISA edge case: cross-page qword write.
2 // The qword store starts 4 bytes before a page boundary, so the 8-byte
3 // store straddles two 4KB pages. Deadspy's per-byte shadow (organized
4 // as a 2-level page table with 64KB shadow pages) must correctly handle
5 // a store that spans two shadow-page slots.
6 //
7 // Pattern: write qword at addr X, then write qword at same addr X.
8 // Both stores straddle a page boundary. Second store's 8B are dead.
9 #include <stdint.h>
10 #include <stdlib.h>
11 #include <sys/mman.h>
12 #define WORK_COUNT 10000
13 static volatile uint64_t sink;
14 int main(int argc, char** argv) {
15  (void)argc; (void)argv;
16  // mmap two contiguous 4KB pages so we can address across the boundary.
17  const size_t pagesz = 4096;
18  void* region = mmap(NULL, 2 * pagesz, PROT_READ | PROT_WRITE,
19  MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
20  if (region == MAP_FAILED) return 1;
21  // Straddle offset: last 4B of page 0 + first 4B of page 1.
22  uint64_t* straddle = (uint64_t*)((char*)region + pagesz - 4);
23  uint64_t v1 = 0xDEADBEEF, v2 = 0xC0FFEE;
24  for (int i = 0; i < WORK_COUNT; ++i) {
25  __asm__ __volatile__(
26  "movq %[v1], (%[p])\n\t"
27  "movq %[v2], (%[p])\n\t" // dead: 8B write over 8B write, straddles page
28  :
29  : [p] "r"(straddle), [v1] "r"(v1), [v2] "r"(v2)
30  : "memory");
31  }
32  sink = *straddle;
33  munmap(region, 2 * pagesz);
34  return 0;
35 }
#define WORK_COUNT
int main(int argc, char **argv)
static volatile uint64_t sink