Update __sanitizer_get_allocated_begin to return const void*

D147005 introduced __sanitizer_get_allocated_begin, with a return
value of void*. This involved a few naughty casts that dropped the
const. This patch adds back the const qualifier.

Differential Revision: https://reviews.llvm.org/D147489
This commit is contained in:
Thurston Dang 2023-04-04 00:42:37 +00:00
parent 321d02cc6b
commit d644ab022a
10 changed files with 24 additions and 24 deletions

View File

@ -28,7 +28,7 @@ extern "C" {
/* 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). */

View File

@ -1164,7 +1164,7 @@ IgnoreObjectResult IgnoreObjectLocked(const void *p) {
// ---------------------- 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 @@ void *AllocationBegin(const void *p) {
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 @@ uptr __sanitizer_get_allocated_size(const void *p) {
return allocated_size;
}
void *__sanitizer_get_allocated_begin(const void *p) {
const void *__sanitizer_get_allocated_begin(const void *p) {
return AllocationBegin(p);
}

View File

@ -174,7 +174,7 @@ void *DFsanCalloc(uptr nmemb, uptr size) {
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 @@ void *AllocationBegin(const void *p) {
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 @@ uptr __sanitizer_get_estimated_allocated_size(uptr size) { return size; }
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);
}

View File

@ -397,7 +397,7 @@ HwasanChunkView FindHeapChunkByAddress(uptr address) {
return HwasanChunkView(reinterpret_cast<uptr>(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 @@ void *AllocationBegin(const void *p) {
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 @@ uptr __sanitizer_get_estimated_allocated_size(uptr size) { return size; }
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);
}

View File

@ -145,7 +145,7 @@ void GetAllocatorCacheRange(uptr *begin, uptr *end) {
*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 @@ void *GetMallocBegin(const void *p) {
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 @@ SANITIZER_INTERFACE_ATTRIBUTE
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);
}

View File

@ -681,7 +681,7 @@ int memprof_posix_memalign(void **memptr, uptr alignment, uptr size,
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 @@ void *memprof_malloc_begin(const void *p) {
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 @@ int __sanitizer_get_ownership(const void *p) {
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);
}

View File

@ -260,7 +260,7 @@ static void *MsanCalloc(StackTrace *stack, uptr nmemb, uptr size) {
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 @@ void *AllocationBegin(const void *p) {
if (b->requested_size == 0)
return nullptr;
return (void *)beg;
return (const void *)beg;
}
static uptr AllocationSize(const void *p) {
@ -388,7 +388,7 @@ uptr __sanitizer_get_estimated_allocated_size(uptr size) { return size; }
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);
}

View File

@ -21,7 +21,7 @@ extern "C" {
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);

View File

@ -352,7 +352,7 @@ void *user_pvalloc(ThreadState *thr, uptr pc, uptr sz) {
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 @@ void *user_alloc_begin(const void *p) {
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 @@ int __sanitizer_get_ownership(const void *p) {
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);
}

View File

@ -23,7 +23,7 @@ int main(void) {
// 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);