[PATCH] D28849: [compiler-rt] [test] Fix page address logic in clear_cache_test

Michał Górny via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 20 15:43:01 PST 2017


mgorny updated this revision to Diff 85208.
mgorny marked an inline comment as done.
mgorny added a comment.

Fixed the missing change. Also created a local variable to avoid calling the sysconf three times.


https://reviews.llvm.org/D28849

Files:
  test/builtins/Unit/clear_cache_test.c


Index: test/builtins/Unit/clear_cache_test.c
===================================================================
--- test/builtins/Unit/clear_cache_test.c
+++ test/builtins/Unit/clear_cache_test.c
@@ -18,9 +18,20 @@
     if (!FlushInstructionCache(GetCurrentProcess(), start, end-start))
         exit(1);
 }
+
+static uintptr_t get_page_size() {
+    SYSTEM_INFO si;
+    GetSystemInfo(&si);
+    return si.dwPageSize;
+}
 #else
+#include <unistd.h>
 #include <sys/mman.h>
 extern void __clear_cache(void* start, void* end);
+
+static uintptr_t get_page_size() {
+    return sysconf(_SC_PAGE_SIZE);
+}
 #endif
 
 
@@ -56,8 +67,9 @@
 int main()
 {
     // make executable the page containing execution_buffer 
-    char* start = (char*)((uintptr_t)execution_buffer & (-4095));
-    char* end = (char*)((uintptr_t)(&execution_buffer[128+4096]) & (-4095));
+    uintptr_t page_size = get_page_size();
+    char* start = (char*)((uintptr_t)execution_buffer & (-page_size));
+    char* end = (char*)((uintptr_t)(&execution_buffer[128+page_size]) & (-page_size));
 #if defined(_WIN32)
     DWORD dummy_oldProt;
     MEMORY_BASIC_INFORMATION b;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28849.85208.patch
Type: text/x-patch
Size: 1139 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170120/22f7cd85/attachment.bin>


More information about the cfe-commits mailing list