diff --git a/compiler-rt/include/sanitizer/allocator_interface.h b/compiler-rt/include/sanitizer/allocator_interface.h --- a/compiler-rt/include/sanitizer/allocator_interface.h +++ b/compiler-rt/include/sanitizer/allocator_interface.h @@ -28,7 +28,7 @@ /* If a pointer lies within an allocation, it will return the start address of the allocation. Otherwise, it returns nullptr. */ - void *__sanitizer_get_allocated_begin(const void *p); + const void *__sanitizer_get_allocated_begin(const void *p); /* Returns the number of bytes reserved for the pointer p. Requires (get_ownership(p) == true) or (p == 0). */ diff --git a/compiler-rt/lib/asan/asan_allocator.cpp b/compiler-rt/lib/asan/asan_allocator.cpp --- a/compiler-rt/lib/asan/asan_allocator.cpp +++ b/compiler-rt/lib/asan/asan_allocator.cpp @@ -1164,7 +1164,7 @@ // ---------------------- Interface ---------------- {{{1 using namespace __asan; -void *AllocationBegin(const void *p) { +const void *AllocationBegin(const void *p) { AsanChunk *m = __asan::instance.GetAsanChunkByAddr((uptr)p); if (!m) return nullptr; @@ -1172,7 +1172,7 @@ return nullptr; if (m->UsedSize() == 0) return nullptr; - return (void *)(m->Beg()); + return (const void *)(m->Beg()); } // ASan allocator doesn't reserve extra bytes, so normally we would @@ -1198,7 +1198,7 @@ return allocated_size; } -void *__sanitizer_get_allocated_begin(const void *p) { +const void *__sanitizer_get_allocated_begin(const void *p) { return AllocationBegin(p); } diff --git a/compiler-rt/lib/dfsan/dfsan_allocator.cpp b/compiler-rt/lib/dfsan/dfsan_allocator.cpp --- a/compiler-rt/lib/dfsan/dfsan_allocator.cpp +++ b/compiler-rt/lib/dfsan/dfsan_allocator.cpp @@ -174,7 +174,7 @@ return DFsanAllocate(nmemb * size, sizeof(u64), true /*zeroise*/); } -void *AllocationBegin(const void *p) { +const void *AllocationBegin(const void *p) { if (!p) return nullptr; void *beg = allocator.GetBlockBegin(p); @@ -185,7 +185,7 @@ return nullptr; if (b->requested_size == 0) return nullptr; - return (void *)beg; + return (const void *)beg; } static uptr AllocationSize(const void *p) { @@ -308,7 +308,7 @@ int __sanitizer_get_ownership(const void *p) { return AllocationSize(p) != 0; } -void *__sanitizer_get_allocated_begin(const void *p) { +const void *__sanitizer_get_allocated_begin(const void *p) { return AllocationBegin(p); } diff --git a/compiler-rt/lib/hwasan/hwasan_allocator.cpp b/compiler-rt/lib/hwasan/hwasan_allocator.cpp --- a/compiler-rt/lib/hwasan/hwasan_allocator.cpp +++ b/compiler-rt/lib/hwasan/hwasan_allocator.cpp @@ -397,7 +397,7 @@ return HwasanChunkView(reinterpret_cast(block), metadata); } -void *AllocationBegin(const void *p) { +const void *AllocationBegin(const void *p) { const void *untagged_ptr = UntagPtr(p); if (!untagged_ptr) return nullptr; @@ -411,7 +411,7 @@ return nullptr; tag_t tag = GetTagFromPointer((uptr)p); - return (void *)AddTagToPointer((uptr)beg, tag); + return (const void *)AddTagToPointer((uptr)beg, tag); } static uptr AllocationSize(const void *tagged_ptr) { @@ -658,7 +658,7 @@ int __sanitizer_get_ownership(const void *p) { return AllocationSize(p) != 0; } -void *__sanitizer_get_allocated_begin(const void *p) { +const void *__sanitizer_get_allocated_begin(const void *p) { return AllocationBegin(p); } diff --git a/compiler-rt/lib/lsan/lsan_allocator.cpp b/compiler-rt/lib/lsan/lsan_allocator.cpp --- a/compiler-rt/lib/lsan/lsan_allocator.cpp +++ b/compiler-rt/lib/lsan/lsan_allocator.cpp @@ -145,7 +145,7 @@ *end = *begin + sizeof(AllocatorCache); } -void *GetMallocBegin(const void *p) { +const void *GetMallocBegin(const void *p) { if (!p) return nullptr; void *beg = allocator.GetBlockBegin(p); @@ -158,7 +158,7 @@ return nullptr; if (m->requested_size == 0) return nullptr; - return (void *)beg; + return (const void *)beg; } uptr GetMallocUsableSize(const void *p) { @@ -380,7 +380,7 @@ int __sanitizer_get_ownership(const void *p) { return Metadata(p) != nullptr; } SANITIZER_INTERFACE_ATTRIBUTE -void * __sanitizer_get_allocated_begin(const void *p) { +const void * __sanitizer_get_allocated_begin(const void *p) { return GetMallocBegin(p); } diff --git a/compiler-rt/lib/memprof/memprof_allocator.cpp b/compiler-rt/lib/memprof/memprof_allocator.cpp --- a/compiler-rt/lib/memprof/memprof_allocator.cpp +++ b/compiler-rt/lib/memprof/memprof_allocator.cpp @@ -681,7 +681,7 @@ return 0; } -void *memprof_malloc_begin(const void *p) { +const void *memprof_malloc_begin(const void *p) { u64 user_requested_size; MemprofChunk *m = instance.GetMemprofChunkByAddr((uptr)p, user_requested_size); @@ -690,7 +690,7 @@ if (user_requested_size == 0) return nullptr; - return (void *)m->Beg(); + return (const void *)m->Beg(); } uptr memprof_malloc_usable_size(const void *ptr, uptr pc, uptr bp) { @@ -711,7 +711,7 @@ return memprof_malloc_usable_size(p, 0, 0) != 0; } -void *__sanitizer_get_allocated_begin(const void *p) { +const void *__sanitizer_get_allocated_begin(const void *p) { return memprof_malloc_begin(p); } diff --git a/compiler-rt/lib/msan/msan_allocator.cpp b/compiler-rt/lib/msan/msan_allocator.cpp --- a/compiler-rt/lib/msan/msan_allocator.cpp +++ b/compiler-rt/lib/msan/msan_allocator.cpp @@ -260,7 +260,7 @@ return MsanAllocate(stack, nmemb * size, sizeof(u64), true); } -void *AllocationBegin(const void *p) { +const void *AllocationBegin(const void *p) { if (!p) return nullptr; void *beg = allocator.GetBlockBegin(p); @@ -272,7 +272,7 @@ if (b->requested_size == 0) return nullptr; - return (void *)beg; + return (const void *)beg; } static uptr AllocationSize(const void *p) { @@ -388,7 +388,7 @@ int __sanitizer_get_ownership(const void *p) { return AllocationSize(p) != 0; } -void *__sanitizer_get_allocated_begin(const void *p) { +const void *__sanitizer_get_allocated_begin(const void *p) { return AllocationBegin(p); } diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_interface.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_interface.h --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_interface.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_interface.h @@ -21,7 +21,7 @@ SANITIZER_INTERFACE_ATTRIBUTE uptr __sanitizer_get_estimated_allocated_size(uptr size); SANITIZER_INTERFACE_ATTRIBUTE int __sanitizer_get_ownership(const void *p); -SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void * +SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE const void * __sanitizer_get_allocated_begin(const void *p); SANITIZER_INTERFACE_ATTRIBUTE uptr __sanitizer_get_allocated_size(const void *p); diff --git a/compiler-rt/lib/tsan/rtl/tsan_mman.cpp b/compiler-rt/lib/tsan/rtl/tsan_mman.cpp --- a/compiler-rt/lib/tsan/rtl/tsan_mman.cpp +++ b/compiler-rt/lib/tsan/rtl/tsan_mman.cpp @@ -352,7 +352,7 @@ return SetErrnoOnNull(user_alloc_internal(thr, pc, sz, PageSize)); } -void *user_alloc_begin(const void *p) { +const void *user_alloc_begin(const void *p) { if (p == nullptr || !IsAppMem((uptr)p)) return nullptr; void *beg = allocator()->GetBlockBegin(p); @@ -363,7 +363,7 @@ if (!b) return nullptr; // Not a valid pointer. - return (void *)beg; + return (const void *)beg; } uptr user_alloc_usable_size(const void *p) { @@ -444,7 +444,7 @@ return allocator()->GetBlockBegin(p) != 0; } -void *__sanitizer_get_allocated_begin(const void *p) { +const void *__sanitizer_get_allocated_begin(const void *p) { return user_alloc_begin(p); } diff --git a/compiler-rt/test/sanitizer_common/TestCases/get_allocated_begin.cpp b/compiler-rt/test/sanitizer_common/TestCases/get_allocated_begin.cpp --- a/compiler-rt/test/sanitizer_common/TestCases/get_allocated_begin.cpp +++ b/compiler-rt/test/sanitizer_common/TestCases/get_allocated_begin.cpp @@ -23,7 +23,7 @@ // Bogus value to unpoison start. Calling __sanitizer_get_allocated_begin // does not unpoison it. - void *start = NULL; + const void *start = NULL; for (int j = 0; j < sizes[i]; j++) { printf("j: %d\n", j);