Home | History | Annotate | Download | only in tests
      1 // This test-case exposes a bug that was present in the compressed V bit
      2 // handling for a while.  The problem was that when
      3 // copy_address_range_state() copied a VA_BITS2_OTHER value, it failed to
      4 // also copy the corresponding entry in the sec-V-bits table.  Then later on
      5 // when we searched for the sec-V-bits entry for the copied-to location, it
      6 // failed to find it:
      7 //
      8 //   Memcheck: mc_main.c:766 (get_sec_vbits8): Assertion 'n' failed.
      9 //   Memcheck: get_sec_vbits8: no node for address 0x4017440 (0x4017441)
     10 
     11 #include <stdlib.h>
     12 
     13 int main(void)
     14 {
     15    int i, t = 0;
     16    char* x = malloc(1000);
     17 
     18    // Write some PDBs (partially defined bytes)
     19    for (i = 0; i < 1000; i++)
     20       x[i] &= (i & 0xff);
     21 
     22    // realloc them, invoking copy_address_range_state()
     23    x = realloc(x, 10000);
     24 
     25    // Read the PDBs -- this caused a sec-V-bits lookup failure.
     26    for (i = 0; i < 1000; i++)
     27       t += x[i];
     28 
     29    __asm__ __volatile__ ("" :: "r"(t));
     30 
     31    return 0;
     32 }
     33 
     34