[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
Thu Jan 19 00:14:49 PST 2017


mgorny updated this revision to Diff 84947.
mgorny retitled this revision from "[compiler-rt] [test] Fix page address logic in clear_cache_test to use binary negation" to "[compiler-rt] [test] Fix page address logic in clear_cache_test".
mgorny edited the summary of this revision.
mgorny added a comment.

Updated to use page size logic on POSIX and Windows systems. I haven't tested the latter, though.


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,8 @@
 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));
+    char* start = (char*)((uintptr_t)execution_buffer & (-get_page_size()));
+    char* end = (char*)((uintptr_t)(&execution_buffer[128+4096]) & (-get_page_size()));
 #if defined(_WIN32)
     DWORD dummy_oldProt;
     MEMORY_BASIC_INFORMATION b;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28849.84947.patch
Type: text/x-patch
Size: 1102 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170119/28f11313/attachment.bin>


More information about the cfe-commits mailing list