Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit 1fdc27d

Browse files
committed
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 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/branches/release_40@295218 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 84c9f24 commit 1fdc27d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

test/builtins/Unit/clear_cache_test.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,20 @@ void __clear_cache(void* start, void* end)
1818
if (!FlushInstructionCache(GetCurrentProcess(), start, end-start))
1919
exit(1);
2020
}
21+
22+
static uintptr_t get_page_size() {
23+
SYSTEM_INFO si;
24+
GetSystemInfo(&si);
25+
return si.dwPageSize;
26+
}
2127
#else
28+
#include <unistd.h>
2229
#include <sys/mman.h>
2330
extern void __clear_cache(void* start, void* end);
31+
32+
static uintptr_t get_page_size() {
33+
return sysconf(_SC_PAGE_SIZE);
34+
}
2435
#endif
2536

2637

@@ -56,8 +67,9 @@ unsigned char execution_buffer[128];
5667
int main()
5768
{
5869
// make executable the page containing execution_buffer
59-
char* start = (char*)((uintptr_t)execution_buffer & (-4095));
60-
char* end = (char*)((uintptr_t)(&execution_buffer[128+4096]) & (-4095));
70+
uintptr_t page_size = get_page_size();
71+
char* start = (char*)((uintptr_t)execution_buffer & (-page_size));
72+
char* end = (char*)((uintptr_t)(&execution_buffer[128+page_size]) & (-page_size));
6173
#if defined(_WIN32)
6274
DWORD dummy_oldProt;
6375
MEMORY_BASIC_INFORMATION b;

0 commit comments

Comments
 (0)