[compiler-rt] [scudo] Add hooks to mark the range of realloc (PR #73883)
Christopher Ferris via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 29 18:15:21 PST 2023
================
@@ -27,6 +27,51 @@ static void reportDeallocation(void *ptr) {
if (__scudo_deallocate_hook)
__scudo_deallocate_hook(ptr);
}
+static void reportReallocBegin(void *old_ptr) {
+ if (SCUDO_ENABLE_HOOKS)
+ if (__scudo_realloc_begin_hook)
+ __scudo_realloc_begin_hook(old_ptr);
+}
+static void reportReallocEnd(void *old_ptr) {
+ if (SCUDO_ENABLE_HOOKS)
+ if (__scudo_realloc_end_hook)
+ __scudo_realloc_end_hook(old_ptr);
+}
+
+static void *reallocImpl(void *ptr, size_t size) {
+ if (!ptr) {
+ void *Ptr = SCUDO_ALLOCATOR.allocate(size, scudo::Chunk::Origin::Malloc,
+ SCUDO_MALLOC_ALIGNMENT);
+ reportAllocation(Ptr, size);
+ return Ptr;
+ }
+ if (size == 0) {
+ reportDeallocation(ptr);
+ SCUDO_ALLOCATOR.deallocate(ptr, scudo::Chunk::Origin::Malloc);
+ return nullptr;
+ }
+
+ // Given that the reporting of deallocation and allocation are not atomic, we
+ // always pretend the old pointer will be released so that the user don't need
+ // to worry about the false double-use case from the view of hooks.
+ // For example, before the reporting all the events in the `realloc` has
----------------
cferris1000 wrote:
before the reporting -> before reporting
https://github.com/llvm/llvm-project/pull/73883
More information about the llvm-commits
mailing list