| 1 | //===-- copyprof_per_object_state.h ---------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// |
| 9 | /// This file declares per-object state data structures and helper functions |
| 10 | /// for tracking dynamic memory allocations associated with object copies. |
| 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef COPYPROF_PER_OBJECT_STATE_H |
| 15 | #define COPYPROF_PER_OBJECT_STATE_H |
| 16 | |
| 17 | #include "sanitizer_common/sanitizer_internal_defs.h" |
| 18 | |
| 19 | namespace __copyprof { |
| 20 | |
| 21 | // Initializes the per-object state tracking. |
| 22 | // Must be called once at program startup, after flags are initialized. |
| 23 | void InitializePerObjectTracking(); |
| 24 | |
| 25 | // Initializes the per-object state for the object at `this_ptr` with the given |
| 26 | // static size. |
| 27 | void InitPerObjectState(const void* this_ptr, uptr static_size); |
| 28 | |
| 29 | // Records a dynamic allocation of `num_bytes` for the object at `this_ptr`. |
| 30 | void RecordPerObjectAllocation(const void* this_ptr, uptr num_bytes); |
| 31 | |
| 32 | // Returns the tracked size for the object at `this_ptr`. |
| 33 | uptr GetPerObjectTrackedSize(const void* this_ptr); |
| 34 | |
| 35 | // Returns whether the object at `this_ptr` has performed any dynamic |
| 36 | // allocations. |
| 37 | bool GetPerObjectDidAllocate(const void* this_ptr); |
| 38 | |
| 39 | // Removes the per-object state for the object at `this_ptr`. |
| 40 | void RemovePerObjectState(const void* this_ptr); |
| 41 | |
| 42 | } // namespace __copyprof |
| 43 | |
| 44 | #endif // COPYPROF_PER_OBJECT_STATE_H |
| 45 | |