[llvm-branch-commits] [compiler-rt-branch] r295218 - Merging r292729:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Feb 15 11:06:24 PST 2017


Author: hans
Date: Wed Feb 15 13:06:24 2017
New Revision: 295218

URL: http://llvm.org/viewvc/llvm-project?rev=295218&view=rev
Log:
Merging r292729:
------------------------------------------------------------------------
r292729 | mgorny | 2017-01-21 13:55:00 -0800 (Sat, 21 Jan 2017) | 17 lines

[test] Fix page address logic in clear_cache_test

Fix the logic used to calculate page boundaries in clear_cache_test to
use correct masks -- e.g. -4096 rather than -4095. The latter gives
incorrect result since:

  -4095 -> 0xfffff001
  -4096 -> 0xfffff000 (== ~4095)

The issue went unnoticed so far because the array alignment caused
the last bit not to be set. However, on 32-bit x86 no such alignment is
enforced and the wrong page address caused the test to fail.

Furthermore, obtain the page size from the system instead of hardcoding
4096.

Differential Revision: https://reviews.llvm.org/D28849
------------------------------------------------------------------------

Modified:
    compiler-rt/branches/release_40/   (props changed)
    compiler-rt/branches/release_40/test/builtins/Unit/clear_cache_test.c

Propchange: compiler-rt/branches/release_40/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Feb 15 13:06:24 2017
@@ -1 +1 @@
-/compiler-rt/trunk:292257,292517,293120,293536,294425,294806,294886
+/compiler-rt/trunk:292257,292517,292729,293120,293536,294425,294806,294886

Modified: compiler-rt/branches/release_40/test/builtins/Unit/clear_cache_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/branches/release_40/test/builtins/Unit/clear_cache_test.c?rev=295218&r1=295217&r2=295218&view=diff
==============================================================================
--- compiler-rt/branches/release_40/test/builtins/Unit/clear_cache_test.c (original)
+++ compiler-rt/branches/release_40/test/builtins/Unit/clear_cache_test.c Wed Feb 15 13:06:24 2017
@@ -18,9 +18,20 @@ void __clear_cache(void* start, void* en
     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 @@ unsigned char execution_buffer[128];
 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;




More information about the llvm-branch-commits mailing list