|
Blender V5.0
|
#include <stdarg.h>#include <stddef.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/types.h>#include <pthread.h>#include "MEM_guardedalloc.h"#include "../../source/blender/blenlib/BLI_strict_flags.h"#include "atomic_ops.h"#include "mallocn_intern.hh"#include "mallocn_intern_function_pointers.hh"Go to the source code of this file.
Classes | |
| struct | localLink |
| struct | localListBase |
| struct | MemTail |
| struct | MemPrintBlock |
Macros | |
| #define | MAKE_ID(a, b, c, d) |
| #define | MEMTAG1 MAKE_ID('M', 'E', 'M', 'O') |
| #define | MEMTAG2 MAKE_ID('R', 'Y', 'B', 'L') |
| #define | MEMTAG3 MAKE_ID('O', 'C', 'K', '!') |
| #define | MEMFREE MAKE_ID('F', 'R', 'E', 'E') |
| #define | MEMNEXT(x) |
Typedefs | |
| typedef struct localLink | localLink |
| typedef struct localListBase | localListBase |
| typedef struct MemTail | MemTail |
| typedef struct MemPrintBlock | MemPrintBlock |
Enumerations | |
| enum | MemHeadFlag { MEMHEAD_FLAG_FROM_CPP_NEW = 1 << 1 } |
Functions | |
| static void | addtail (volatile localListBase *listbase, void *vlink) |
| static void | remlink (volatile localListBase *listbase, void *vlink) |
| static void | rem_memblock (MemHead *memh) |
| static void | MemorY_ErroR (const char *block, const char *error) |
| static const char * | check_memlist (const MemHead *memh) |
| static void | print_error (const char *message, va_list str_format_args) |
| static void | print_error (const char *message,...) |
| static void | report_error_on_address (const void *vmemh, const char *message,...) |
| static void | mem_lock_thread () |
| static void | mem_unlock_thread () |
| bool | MEM_guarded_consistency_check () |
| void | MEM_guarded_set_error_callback (void(*func)(const char *)) |
| void | MEM_guarded_set_memory_debug () |
| size_t | MEM_guarded_allocN_len (const void *vmemh) |
| void * | MEM_guarded_dupallocN (const void *vmemh) |
| void * | MEM_guarded_reallocN_id (void *vmemh, size_t len, const char *str) |
| void * | MEM_guarded_recallocN_id (void *vmemh, size_t len, const char *str) |
| static void | make_memhead_header (MemHead *memh, size_t len, const char *str, const AllocationType allocation_type) |
| void * | MEM_guarded_mallocN (size_t len, const char *str) |
| void * | MEM_guarded_malloc_arrayN (size_t len, size_t size, const char *str) |
| void * | MEM_guarded_mallocN_aligned (size_t len, size_t alignment, const char *str, const AllocationType allocation_type) |
| void * | MEM_guarded_callocN (size_t len, const char *str) |
| void * | MEM_guarded_calloc_arrayN (size_t len, size_t size, const char *str) |
| static void * | mem_guarded_malloc_arrayN_aligned (const size_t len, const size_t size, const size_t alignment, const char *str, size_t &r_bytes_num) |
| void * | MEM_guarded_malloc_arrayN_aligned (const size_t len, const size_t size, const size_t alignment, const char *str) |
| void * | MEM_guarded_calloc_arrayN_aligned (const size_t len, const size_t size, const size_t alignment, const char *str) |
| static int | compare_name (const void *p1, const void *p2) |
| static int | compare_len (const void *p1, const void *p2) |
| void | MEM_guarded_printmemlist_stats () |
| static void | MEM_guarded_printmemlist_internal (int pydict) |
| void | MEM_guarded_callbackmemlist (void(*func)(void *)) |
| void | MEM_guarded_printmemlist () |
| void | MEM_guarded_printmemlist_pydict () |
| void | mem_guarded_clearmemlist () |
| void | MEM_guarded_freeN (void *vmemh, const AllocationType allocation_type) |
| size_t | MEM_guarded_get_peak_memory () |
| void | MEM_guarded_reset_peak_memory () |
| size_t | MEM_guarded_get_memory_in_use () |
| uint | MEM_guarded_get_memory_blocks_in_use () |
| const char * | MEM_guarded_name_ptr (void *vmemh) |
| void | MEM_guarded_name_ptr_set (void *vmemh, const char *str) |
Variables | |
| static uint | totblock = 0 |
| static size_t | mem_in_use = 0 |
| static size_t | peak_mem = 0 |
| static volatile localListBase | _membase |
| static volatile localListBase * | membase = &_membase |
| static void(* | error_callback )(const char *) = nullptr |
| static bool | malloc_debug_memset = false |
| static pthread_mutex_t | thread_lock = PTHREAD_MUTEX_INITIALIZER |
| static const char | mem_printmemlist_pydict_script [] |
Guarded memory allocation, and boundary-write detection.
Definition in file mallocn_guarded_impl.cc.
| #define MAKE_ID | ( | a, | |
| b, | |||
| c, | |||
| d ) |
Definition at line 178 of file mallocn_guarded_impl.cc.
Definition at line 183 of file mallocn_guarded_impl.cc.
Referenced by MEM_guarded_freeN().
| #define MEMNEXT | ( | x | ) |
Definition at line 185 of file mallocn_guarded_impl.cc.
Referenced by check_memlist(), make_memhead_header(), MEM_guarded_callbackmemlist(), MEM_guarded_name_ptr_set(), MEM_guarded_printmemlist_internal(), MEM_guarded_printmemlist_stats(), and rem_memblock().
Definition at line 180 of file mallocn_guarded_impl.cc.
Referenced by check_memlist(), make_memhead_header(), and MEM_guarded_freeN().
Definition at line 181 of file mallocn_guarded_impl.cc.
Referenced by check_memlist(), make_memhead_header(), and MEM_guarded_freeN().
Definition at line 182 of file mallocn_guarded_impl.cc.
Referenced by make_memhead_header(), and MEM_guarded_freeN().
| typedef struct localLink localLink |
| typedef struct localListBase localListBase |
| typedef struct MemPrintBlock MemPrintBlock |
| typedef struct MemTail MemTail |
| enum MemHeadFlag |
| Enumerator | |
|---|---|
| MEMHEAD_FLAG_FROM_CPP_NEW | This block of memory has been allocated from CPP new (e.g. #MEM_new, or some guardedalloc-overloaded new operator). It mainly checks that MEM_freeN is not directly called on it (#MEM_delete or some guardedalloc-overloaded delete operator should always be used instead). |
Definition at line 145 of file mallocn_guarded_impl.cc.
|
static |
Definition at line 1123 of file mallocn_guarded_impl.cc.
References localListBase::first, localListBase::last, localLink::next, and localLink::prev.
Referenced by make_memhead_header().
|
static |
Definition at line 1223 of file mallocn_guarded_impl.cc.
References membase, MEMNEXT, MemorY_ErroR(), MEMTAG1, MEMTAG2, and name.
Referenced by MEM_guarded_consistency_check(), and MEM_guarded_freeN().
|
static |
Definition at line 772 of file mallocn_guarded_impl.cc.
References MemPrintBlock::len.
Referenced by MEM_guarded_printmemlist_stats().
|
static |
Definition at line 764 of file mallocn_guarded_impl.cc.
References MemPrintBlock::name.
|
static |
Definition at line 494 of file mallocn_guarded_impl.cc.
References addtail(), atomic_add_and_fetch_u(), atomic_add_and_fetch_z(), len, mem_in_use, mem_lock_thread(), mem_unlock_thread(), membase, MEMHEAD_FLAG_FROM_CPP_NEW, MEMNEXT, MEMTAG1, MEMTAG2, MEMTAG3, mem_guarded::internal::NEW_DELETE, peak_mem, str, MemTail::tag3, and totblock.
Referenced by MEM_guarded_callocN(), MEM_guarded_mallocN(), and MEM_guarded_mallocN_aligned().
| size_t MEM_guarded_allocN_len | ( | const void * | vmemh | ) |
Definition at line 313 of file mallocn_guarded_impl.cc.
Referenced by MEM_use_guarded_allocator().
| void MEM_guarded_callbackmemlist | ( | void(* | func )(void *) | ) |
Definition at line 971 of file mallocn_guarded_impl.cc.
References mem_lock_thread(), mem_unlock_thread(), membase, and MEMNEXT.
Referenced by MEM_guarded_calloc_arrayN_aligned(), and MEM_use_guarded_allocator().
| void * MEM_guarded_calloc_arrayN | ( | size_t | len, |
| size_t | size, | ||
| const char * | str ) |
Definition at line 691 of file mallocn_guarded_impl.cc.
References len, MEM_guarded_callocN(), mem_in_use, MEM_size_safe_multiply(), print_error(), size(), SIZET_ARG, SIZET_FORMAT, str, and UNLIKELY.
Referenced by MEM_guarded_calloc_arrayN(), and MEM_use_guarded_allocator().
| void * MEM_guarded_calloc_arrayN_aligned | ( | const size_t | len, |
| const size_t | size, | ||
| const size_t | alignment, | ||
| const char * | str ) |
Definition at line 741 of file mallocn_guarded_impl.cc.
References len, mem_guarded_malloc_arrayN_aligned(), ptr, size(), and str.
Referenced by MEM_guarded_calloc_arrayN_aligned(), and MEM_use_guarded_allocator().
| void * MEM_guarded_callocN | ( | size_t | len, |
| const char * | str ) |
Definition at line 666 of file mallocn_guarded_impl.cc.
References mem_guarded::internal::ALLOC_FREE, len, make_memhead_header(), mem_in_use, print_error(), SIZET_ALIGN_4, SIZET_ARG, SIZET_FORMAT, and str.
Referenced by MEM_guarded_calloc_arrayN(), MEM_guarded_recallocN_id(), and MEM_use_guarded_allocator().
| void mem_guarded_clearmemlist | ( | void | ) |
Definition at line 1034 of file mallocn_guarded_impl.cc.
References membase.
Referenced by MEM_guarded_calloc_arrayN_aligned(), and MEM_use_guarded_allocator().
| bool MEM_guarded_consistency_check | ( | void | ) |
Definition at line 290 of file mallocn_guarded_impl.cc.
References check_memlist(), and membase.
Referenced by MEM_guarded_calloc_arrayN_aligned(), and MEM_use_guarded_allocator().
| void * MEM_guarded_dupallocN | ( | const void * | vmemh | ) |
Definition at line 325 of file mallocn_guarded_impl.cc.
References mem_guarded::internal::ALLOC_FREE, LIKELY, MEM_guarded_mallocN(), MEM_guarded_mallocN_aligned(), MEMHEAD_FLAG_FROM_CPP_NEW, name, and report_error_on_address().
Referenced by MEM_use_guarded_allocator().
| void MEM_guarded_freeN | ( | void * | vmemh, |
| const AllocationType | allocation_type ) |
Definition at line 1039 of file mallocn_guarded_impl.cc.
References check_memlist(), free_after_leak_detection_message, leak_detector_has_run, mem_lock_thread(), mem_unlock_thread(), MEMFREE, MEMHEAD_FLAG_FROM_CPP_NEW, MemorY_ErroR(), MEMTAG1, MEMTAG2, MEMTAG3, name, mem_guarded::internal::NEW_DELETE, rem_memblock(), report_error_on_address(), MemTail::tag3, and totblock.
Referenced by MEM_guarded_reallocN_id(), MEM_guarded_recallocN_id(), and MEM_use_guarded_allocator().
| uint MEM_guarded_get_memory_blocks_in_use | ( | void | ) |
Definition at line 1384 of file mallocn_guarded_impl.cc.
References mem_lock_thread(), mem_unlock_thread(), and totblock.
Referenced by MEM_guarded_calloc_arrayN_aligned(), and MEM_use_guarded_allocator().
| size_t MEM_guarded_get_memory_in_use | ( | void | ) |
Definition at line 1373 of file mallocn_guarded_impl.cc.
References mem_in_use, mem_lock_thread(), and mem_unlock_thread().
Referenced by MEM_guarded_calloc_arrayN_aligned(), and MEM_use_guarded_allocator().
| size_t MEM_guarded_get_peak_memory | ( | void | ) |
Definition at line 1355 of file mallocn_guarded_impl.cc.
References mem_lock_thread(), mem_unlock_thread(), and peak_mem.
Referenced by MEM_guarded_calloc_arrayN_aligned(), and MEM_use_guarded_allocator().
| void * MEM_guarded_malloc_arrayN | ( | size_t | len, |
| size_t | size, | ||
| const char * | str ) |
Definition at line 575 of file mallocn_guarded_impl.cc.
References len, MEM_guarded_mallocN(), mem_in_use, MEM_size_safe_multiply(), print_error(), size(), SIZET_ARG, SIZET_FORMAT, str, and UNLIKELY.
Referenced by MEM_guarded_malloc_arrayN(), and MEM_use_guarded_allocator().
| void * MEM_guarded_malloc_arrayN_aligned | ( | const size_t | len, |
| const size_t | size, | ||
| const size_t | alignment, | ||
| const char * | str ) |
Definition at line 732 of file mallocn_guarded_impl.cc.
References len, mem_guarded_malloc_arrayN_aligned(), size(), and str.
Referenced by MEM_guarded_malloc_arrayN_aligned(), and MEM_use_guarded_allocator().
|
static |
Definition at line 709 of file mallocn_guarded_impl.cc.
References len, mem_in_use, mem_guarded::internal::mem_mallocN, MEM_mallocN_aligned(), MEM_size_safe_multiply(), print_error(), size(), SIZET_ARG, SIZET_FORMAT, str, and UNLIKELY.
Referenced by MEM_guarded_calloc_arrayN_aligned(), and MEM_guarded_malloc_arrayN_aligned().
| void * MEM_guarded_mallocN | ( | size_t | len, |
| const char * | str ) |
Definition at line 532 of file mallocn_guarded_impl.cc.
References mem_guarded::internal::ALLOC_FREE, len, LIKELY, make_memhead_header(), malloc_debug_memset, mem_in_use, print_error(), SIZET_ALIGN_4, SIZET_ARG, SIZET_FORMAT, str, and UNLIKELY.
Referenced by MEM_guarded_calloc_arrayN(), MEM_guarded_dupallocN(), MEM_guarded_malloc_arrayN(), MEM_guarded_reallocN_id(), MEM_guarded_recallocN_id(), and MEM_use_guarded_allocator().
| void * MEM_guarded_mallocN_aligned | ( | size_t | len, |
| size_t | alignment, | ||
| const char * | str, | ||
| const AllocationType | allocation_type ) |
Definition at line 593 of file mallocn_guarded_impl.cc.
References aligned_malloc(), ALIGNED_MALLOC_MINIMUM_ALIGNMENT, assert, IS_POW2, len, LIKELY, make_memhead_header(), malloc_debug_memset, mem_in_use, MEMHEAD_ALIGN_PADDING, print_error(), SIZET_ALIGN_4, SIZET_ARG, SIZET_FORMAT, str, and UNLIKELY.
Referenced by MEM_guarded_dupallocN(), MEM_guarded_malloc_arrayN(), MEM_guarded_reallocN_id(), MEM_guarded_recallocN_id(), and MEM_use_guarded_allocator().
| const char * MEM_guarded_name_ptr | ( | void * | vmemh | ) |
Definition at line 1396 of file mallocn_guarded_impl.cc.
Referenced by MEM_use_guarded_allocator().
| void MEM_guarded_name_ptr_set | ( | void * | vmemh, |
| const char * | str ) |
Definition at line 1407 of file mallocn_guarded_impl.cc.
Referenced by MEM_use_guarded_allocator().
| void MEM_guarded_printmemlist | ( | void | ) |
Definition at line 1026 of file mallocn_guarded_impl.cc.
References MEM_guarded_printmemlist_internal().
Referenced by MEM_guarded_calloc_arrayN_aligned(), and MEM_use_guarded_allocator().
|
static |
Definition at line 911 of file mallocn_guarded_impl.cc.
References mem_lock_thread(), mem_printmemlist_pydict_script, mem_unlock_thread(), membase, MEMNEXT, print_error(), SIZET_ARG, and SIZET_FORMAT.
Referenced by MEM_guarded_printmemlist(), and MEM_guarded_printmemlist_pydict().
| void MEM_guarded_printmemlist_pydict | ( | void | ) |
Definition at line 1030 of file mallocn_guarded_impl.cc.
References MEM_guarded_printmemlist_internal().
Referenced by MEM_guarded_calloc_arrayN_aligned(), and MEM_use_guarded_allocator().
| void MEM_guarded_printmemlist_stats | ( | void | ) |
Definition at line 787 of file mallocn_guarded_impl.cc.
References b, compare_len(), compare_name(), free(), MemPrintBlock::items, MemPrintBlock::len, mem_in_use, mem_lock_thread(), mem_unlock_thread(), membase, MEMNEXT, MemPrintBlock::name, name, peak_mem, print_error(), printf, totblock, and UNLIKELY.
Referenced by MEM_guarded_calloc_arrayN_aligned(), and MEM_use_guarded_allocator().
| void * MEM_guarded_reallocN_id | ( | void * | vmemh, |
| size_t | len, | ||
| const char * | str ) |
Definition at line 385 of file mallocn_guarded_impl.cc.
References mem_guarded::internal::ALLOC_FREE, len, LIKELY, MEM_guarded_freeN(), MEM_guarded_mallocN(), MEM_guarded_mallocN_aligned(), MEMHEAD_FLAG_FROM_CPP_NEW, report_error_on_address(), and str.
Referenced by MEM_use_guarded_allocator().
| void * MEM_guarded_recallocN_id | ( | void * | vmemh, |
| size_t | len, | ||
| const char * | str ) |
Definition at line 427 of file mallocn_guarded_impl.cc.
References mem_guarded::internal::ALLOC_FREE, len, LIKELY, MEM_guarded_callocN(), MEM_guarded_freeN(), MEM_guarded_mallocN(), MEM_guarded_mallocN_aligned(), MEMHEAD_FLAG_FROM_CPP_NEW, report_error_on_address(), and str.
Referenced by MEM_use_guarded_allocator().
| void MEM_guarded_reset_peak_memory | ( | void | ) |
Definition at line 1366 of file mallocn_guarded_impl.cc.
References mem_in_use, mem_lock_thread(), mem_unlock_thread(), and peak_mem.
Referenced by MEM_guarded_calloc_arrayN_aligned(), and MEM_use_guarded_allocator().
| void MEM_guarded_set_error_callback | ( | void(* | func )(const char *) | ) |
Definition at line 303 of file mallocn_guarded_impl.cc.
References error_callback.
Referenced by MEM_guarded_calloc_arrayN_aligned(), and MEM_use_guarded_allocator().
| void MEM_guarded_set_memory_debug | ( | void | ) |
Definition at line 308 of file mallocn_guarded_impl.cc.
References malloc_debug_memset.
Referenced by MEM_guarded_calloc_arrayN_aligned(), and MEM_use_guarded_allocator().
|
static |
Definition at line 280 of file mallocn_guarded_impl.cc.
References thread_lock.
Referenced by make_memhead_header(), MEM_guarded_callbackmemlist(), MEM_guarded_freeN(), MEM_guarded_get_memory_blocks_in_use(), MEM_guarded_get_memory_in_use(), MEM_guarded_get_peak_memory(), MEM_guarded_printmemlist_internal(), MEM_guarded_printmemlist_stats(), MEM_guarded_reset_peak_memory(), and rem_memblock().
|
static |
Definition at line 285 of file mallocn_guarded_impl.cc.
References thread_lock.
Referenced by make_memhead_header(), MEM_guarded_callbackmemlist(), MEM_guarded_freeN(), MEM_guarded_get_memory_blocks_in_use(), MEM_guarded_get_memory_in_use(), MEM_guarded_get_peak_memory(), MEM_guarded_printmemlist_internal(), MEM_guarded_printmemlist_stats(), MEM_guarded_reset_peak_memory(), and rem_memblock().
|
static |
Definition at line 1214 of file mallocn_guarded_impl.cc.
References error(), and print_error().
Referenced by check_memlist(), and MEM_guarded_freeN().
|
static |
Definition at line 220 of file mallocn_guarded_impl.cc.
References error_callback.
Referenced by MEM_guarded_calloc_arrayN(), MEM_guarded_callocN(), MEM_guarded_malloc_arrayN(), mem_guarded_malloc_arrayN_aligned(), MEM_guarded_mallocN(), MEM_guarded_mallocN_aligned(), MEM_guarded_printmemlist_internal(), MEM_guarded_printmemlist_stats(), MemorY_ErroR(), print_error(), and report_error_on_address().
|
static |
Definition at line 238 of file mallocn_guarded_impl.cc.
References print_error().
|
static |
Definition at line 1180 of file mallocn_guarded_impl.cc.
References aligned_free(), atomic_sub_and_fetch_u(), atomic_sub_and_fetch_z(), free(), LIKELY, malloc_debug_memset, mem_in_use, mem_lock_thread(), mem_unlock_thread(), membase, MEMHEAD_REAL_PTR, MEMNEXT, remlink(), totblock, and UNLIKELY.
Referenced by MEM_guarded_freeN().
|
static |
Definition at line 1150 of file mallocn_guarded_impl.cc.
References localListBase::first, localListBase::last, localLink::next, and localLink::prev.
Referenced by rem_memblock().
|
static |
Definition at line 250 of file mallocn_guarded_impl.cc.
References len, MEM_trigger_error_on_memory_block(), MEMHEAD_ALIGN_PADDING, MEMHEAD_REAL_PTR, print_error(), size(), and UNLIKELY.
Referenced by MEM_guarded_dupallocN(), MEM_guarded_freeN(), MEM_guarded_reallocN_id(), and MEM_guarded_recallocN_id().
|
static |
Definition at line 194 of file mallocn_guarded_impl.cc.
|
static |
Definition at line 196 of file mallocn_guarded_impl.cc.
Referenced by imb_load_jp2_stream(), imb_save_jp2_stream(), MEM_guarded_set_error_callback(), MEM_lockfree_set_error_callback(), print_error(), and print_error().
|
static |
Definition at line 198 of file mallocn_guarded_impl.cc.
Referenced by MEM_guarded_mallocN(), MEM_guarded_mallocN_aligned(), MEM_guarded_set_memory_debug(), MEM_lockfree_freeN(), MEM_lockfree_mallocN(), MEM_lockfree_mallocN_aligned(), MEM_lockfree_set_memory_debug(), and rem_memblock().
|
static |
Definition at line 192 of file mallocn_guarded_impl.cc.
Referenced by ED_info_statusbar_string_ex(), MEM_CacheLimiter< MEM_CacheLimiterHandleCClass >::enforce_limits(), IMB_moviecache_put_if_possible(), make_memhead_header(), make_renderinfo_string(), MEM_guarded_calloc_arrayN(), MEM_guarded_callocN(), MEM_guarded_get_memory_in_use(), MEM_guarded_malloc_arrayN(), mem_guarded_malloc_arrayN_aligned(), MEM_guarded_mallocN(), MEM_guarded_mallocN_aligned(), MEM_guarded_printmemlist_stats(), MEM_guarded_reset_peak_memory(), memory_usage_current(), rem_memblock(), Freestyle::Controller::RenderStrokes(), and write_memory().
|
static |
Definition at line 890 of file mallocn_guarded_impl.cc.
Referenced by MEM_guarded_printmemlist_internal().
|
static |
Definition at line 195 of file mallocn_guarded_impl.cc.
Referenced by check_memlist(), make_memhead_header(), MEM_guarded_callbackmemlist(), mem_guarded_clearmemlist(), MEM_guarded_consistency_check(), MEM_guarded_printmemlist_internal(), MEM_guarded_printmemlist_stats(), and rem_memblock().
|
static |
Definition at line 192 of file mallocn_guarded_impl.cc.
Referenced by make_memhead_header(), MEM_guarded_get_peak_memory(), MEM_guarded_printmemlist_stats(), and MEM_guarded_reset_peak_memory().
|
static |
Definition at line 278 of file mallocn_guarded_impl.cc.
Referenced by mem_lock_thread(), and mem_unlock_thread().
|
static |
Definition at line 191 of file mallocn_guarded_impl.cc.
Referenced by make_memhead_header(), MEM_guarded_freeN(), MEM_guarded_get_memory_blocks_in_use(), MEM_guarded_printmemlist_stats(), and rem_memblock().