Browse Source

Make JIT paging tests' mmap calls more robust (no SEGFAULT and better physical map)

1. SEGFAULTs may be caused by using MAP_FIXED - it may override an existing
mapping, which may exist for internal implementation helpers.

2. The Linux3 profile seems to allocate physical frames in the order in which
writes to memory mapped virtual addresses happen.

For this commit, for eg:

page0;     virtual=0xB7766000 physical=0x12C9000
throwaway; virtual=0xB7765000 physical=0x12C8000
page1;     virtual=0xB7767000 physical=0x12CC000

This way we can write from page0 -> page1's virtual addresses and make sure our
paging support works as it should, and that the tests aren't simply passing
because even the underlying physical frames are contiguous.
Amaan Cheval 6 years ago
parent
commit
d505d7b936
1 changed files with 13 additions and 2 deletions
  1. 13 2
      tests/jit-paging/test-jit.c

+ 13 - 2
tests/jit-paging/test-jit.c

@@ -89,7 +89,7 @@ void test_shared()
 void test_consecutive()
 {
     uint8_t *const page0 = mmap(NULL,
-            PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+            2 * PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 
     // throwaway mmap to reduce likelhood of page0 and page1 mapping to consecutive physical frames
     uint8_t *const throwaway = mmap(NULL,
@@ -103,6 +103,11 @@ void test_consecutive()
         fatal("mmap");
     }
 
+    // Attempt to influence virtual to physical mapping - we want page0->page1 to not be contiguous
+    // physically
+    page0[0] = 0;
+    throwaway[0] = 0;
+    page1[0] = 0;
 
     for(int32_t i = 0; i < 100; i++)
     {
@@ -125,7 +130,7 @@ void test_consecutive()
 void test_consecutive_written()
 {
     uint8_t *const page0 = mmap(NULL,
-            PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+            2 * PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 
     // throwaway mmap to reduce likelhood of page0 and page1 mapping to consecutive physical frames
     uint8_t *const throwaway = mmap(NULL,
@@ -139,6 +144,12 @@ void test_consecutive_written()
         fatal("mmap");
     }
 
+    // Attempt to influence virtual to physical mapping - we want page0->page1 to not be contiguous
+    // physically
+    page0[0] = 0;
+    throwaway[0] = 0;
+    page1[0] = 0;
+
     uint8_t* start = page1 - 8;
     uint8_t* ptr = start;
     const int32_t INC_COUNT = 16;