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();
+return si.dwPageSize;
+}
#else
+#include
#include
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)(_buffer[128+4096]) & (-4095));
+char* start = (char*)((uintptr_t)execution_buffer & (-get_page_size()));
+char* end = (char*)((uintptr_t)(_buffer[128+4096]) &
(-get_page_size()));
#if defined(_WIN32)
DWORD dummy_oldProt;
MEMORY_BASIC_INFORMATION b;
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();
+return si.dwPageSize;
+}
#else
+#include
#include
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)(_buffer[128+4096]) & (-4095));
+char* start = (char*)((uintptr_t)execution_buffer & (-get_page_size()));
+char* end = (char*)((uintptr_t)(_buffer[128+4096]) & (-get_page_size()));
#if defined(_WIN32)
DWORD dummy_oldProt;
MEMORY_BASIC_INFORMATION b;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits