[PATCH] D28849: [compiler-rt] [test] Fix page address logic in clear_cache_test to use binary negation
Michał Górny via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 18 00:56:29 PST 2017
mgorny created this revision.
Herald added a subscriber: dberris.
Fix the logic used to calculate page address in clear_cache_test to use
the binary negation of 4095 rather than arithmetic. The latter gives
incorrect result since:
-4095 -> 0xfffff001
~4095 -> 0xfffff000
Alternatively, -4096 could be used to obtain the correct result.
However, considering the confusion caused by this so far I think it's
better to use binary negation explicitly.
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.
@@ -56,8 +56,8 @@
// 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 & (~4095));
+ char* end = (char*)((uintptr_t)(&execution_buffer[128+4096]) & (~4095));
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 662 bytes
Desc: not available
More information about the cfe-commits