Skip to content

Commit c8644ea

Browse files
committed
[compiler-rt][lsan] Update CanBeAHeapPointer for AArch64
While attempting to get the 64-bit lsan allocator working for Fuchsia, I noticed this function would incorrectly return false for pointers returned by the 64-bit allocator. On AArch64, this function attempts to get the VMA size dynamically by counting the number of leading zeros from the function frame address. This will fail if the frame address is significantly below an allocated pointer (that is, the frame address has more leading zeros than an allocated pointer). This is possible on Fuchsia and linux (when not called from the initial thread stack). It seems the intended use of this function is to speed up pointer scanning by filtering out addresses that user code might not be able to access. Other platforms this check is done on seem to hardcode the VMA size/shift, so it seems appropriate to do this for aarch64 as well. This implies pointers on aarch64 where the VMA size is <64 will pass through, but bad pointers will still be caught by subsequent scan checks. This patch also renames the function to something more fitting of what it's trying to do. Differential Revision: https://reviews.llvm.org/D123814
1 parent 175833e commit c8644ea

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

compiler-rt/lib/lsan/lsan_common.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class Decorator : public __sanitizer::SanitizerCommonDecorator {
240240
const char *Leak() { return Blue(); }
241241
};
242242

243-
static inline bool CanBeAHeapPointer(uptr p) {
243+
static inline bool MaybeUserPointer(uptr p) {
244244
// Since our heap is located in mmap-ed memory, we can assume a sensible lower
245245
// bound on heap addresses.
246246
const uptr kMinAddress = 4 * 4096;
@@ -252,8 +252,8 @@ static inline bool CanBeAHeapPointer(uptr p) {
252252
# elif defined(__mips64)
253253
return ((p >> 40) == 0);
254254
# elif defined(__aarch64__)
255-
unsigned runtimeVMA = (MostSignificantSetBitIndex(GET_CURRENT_FRAME()) + 1);
256-
return ((p >> runtimeVMA) == 0);
255+
// Accept up to 48 bit VMA.
256+
return ((p >> 48) == 0);
257257
# else
258258
return true;
259259
# endif
@@ -276,7 +276,7 @@ void ScanRangeForPointers(uptr begin, uptr end, Frontier *frontier,
276276
pp = pp + alignment - pp % alignment;
277277
for (; pp + sizeof(void *) <= end; pp += alignment) {
278278
void *p = *reinterpret_cast<void **>(pp);
279-
if (!CanBeAHeapPointer(reinterpret_cast<uptr>(p)))
279+
if (!MaybeUserPointer(reinterpret_cast<uptr>(p)))
280280
continue;
281281
uptr chunk = PointsIntoChunk(p);
282282
if (!chunk)

0 commit comments

Comments
 (0)