|
Blender V4.3
|
#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 | MemHead |
| struct | MemTail |
| struct | MemPrintBlock |
Macros | |
| #define | MAKE_ID(a, b, c, d) (int(d) << 24 | int(c) << 16 | (b) << 8 | (a)) |
| #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) ((MemHead *)(((char *)x) - offsetof(MemHead, next))) |
Typedefs | |
| typedef struct localLink | localLink |
| typedef struct localListBase | localListBase |
| typedef struct MemHead | MemHead |
| typedef MemHead | MemHeadAligned |
| 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) |
| 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.
Definition at line 176 of file mallocn_guarded_impl.cc.
Definition at line 182 of file mallocn_guarded_impl.cc.
Referenced by MEM_guarded_freeN().
Definition at line 184 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 179 of file mallocn_guarded_impl.cc.
Referenced by check_memlist(), make_memhead_header(), and MEM_guarded_freeN().
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 make_memhead_header(), and MEM_guarded_freeN().
| typedef struct localLink localLink |
| typedef struct localListBase localListBase |
| typedef struct MemHead MemHead |
| typedef MemHead MemHeadAligned |
Definition at line 138 of file mallocn_guarded_impl.cc.
| 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 |
Definition at line 141 of file mallocn_guarded_impl.cc.
|
static |
Definition at line 1100 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 1195 of file mallocn_guarded_impl.cc.
References localListBase::first, localListBase::last, membase, MEMNEXT, MemorY_ErroR(), MEMTAG1, MEMTAG2, MemHead::name, MemHead::next, MemHead::nextname, MemHead::prev, MemHead::tag1, and MemHead::tag2.
Referenced by MEM_guarded_consistency_check(), and MEM_guarded_freeN().
|
static |
Definition at line 750 of file mallocn_guarded_impl.cc.
References MemPrintBlock::len.
Referenced by MEM_guarded_printmemlist_stats().
|
static |
Definition at line 742 of file mallocn_guarded_impl.cc.
References MemPrintBlock::name.
Referenced by MEM_guarded_printmemlist_stats().
|
static |
Definition at line 493 of file mallocn_guarded_impl.cc.
References addtail(), MemHead::alignment, atomic_add_and_fetch_u(), atomic_add_and_fetch_z(), MemHead::flag, len, MemHead::len, mem_in_use, mem_lock_thread(), mem_unlock_thread(), membase, MEMHEAD_FLAG_FROM_CPP_NEW, MEMNEXT, MEMTAG1, MEMTAG2, MEMTAG3, MemHead::name, MemHead::next, MemHead::nextname, peak_mem, str, MemHead::tag1, MemHead::tag2, 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 312 of file mallocn_guarded_impl.cc.
References MemHead::len.
Referenced by MEM_use_guarded_allocator().
| void MEM_guarded_callbackmemlist | ( | void(* | func )(void *) | ) |
Definition at line 949 of file mallocn_guarded_impl.cc.
References localListBase::first, mem_lock_thread(), mem_unlock_thread(), membase, MEMNEXT, and MemHead::next.
Referenced by MEM_use_guarded_allocator().
| void * MEM_guarded_calloc_arrayN | ( | size_t | len, |
| size_t | size, | ||
| const char * | str ) |
Definition at line 687 of file mallocn_guarded_impl.cc.
References len, MEM_guarded_callocN(), mem_in_use, MEM_size_safe_multiply(), print_error(), SIZET_ARG, SIZET_FORMAT, str, and UNLIKELY.
Referenced by 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 705 of file mallocn_guarded_impl.cc.
References len, MEM_callocN, mem_in_use, MEM_mallocN_aligned(), MEM_size_safe_multiply(), print_error(), ptr, SIZET_ARG, SIZET_FORMAT, str, and UNLIKELY.
Referenced by MEM_use_guarded_allocator().
| void * MEM_guarded_callocN | ( | size_t | len, |
| const char * | str ) |
Definition at line 663 of file mallocn_guarded_impl.cc.
References 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 1011 of file mallocn_guarded_impl.cc.
References localListBase::first, localListBase::last, and membase.
Referenced by MEM_use_guarded_allocator().
| bool MEM_guarded_consistency_check | ( | void | ) |
Definition at line 289 of file mallocn_guarded_impl.cc.
References check_memlist(), localListBase::last, and membase.
Referenced by MEM_use_guarded_allocator().
| void * MEM_guarded_dupallocN | ( | const void * | vmemh | ) |
Definition at line 324 of file mallocn_guarded_impl.cc.
References MemHead::alignment, MemHead::flag, MemHead::len, LIKELY, MEM_guarded_mallocN(), MEM_guarded_mallocN_aligned(), MEMHEAD_FLAG_FROM_CPP_NEW, MemHead::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 1016 of file mallocn_guarded_impl.cc.
References check_memlist(), MemHead::flag, free_after_leak_detection_message, leak_detector_has_run, MemHead::len, mem_lock_thread(), mem_unlock_thread(), MEMFREE, MEMHEAD_FLAG_FROM_CPP_NEW, MemorY_ErroR(), MEMTAG1, MEMTAG2, MEMTAG3, MemHead::name, rem_memblock(), report_error_on_address(), MemHead::tag1, MemHead::tag2, 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 1356 of file mallocn_guarded_impl.cc.
References mem_lock_thread(), mem_unlock_thread(), and totblock.
Referenced by MEM_use_guarded_allocator().
| size_t MEM_guarded_get_memory_in_use | ( | void | ) |
Definition at line 1345 of file mallocn_guarded_impl.cc.
References mem_in_use, mem_lock_thread(), and mem_unlock_thread().
Referenced by MEM_use_guarded_allocator().
| size_t MEM_guarded_get_peak_memory | ( | void | ) |
Definition at line 1327 of file mallocn_guarded_impl.cc.
References mem_lock_thread(), mem_unlock_thread(), and peak_mem.
Referenced by MEM_use_guarded_allocator().
| void * MEM_guarded_malloc_arrayN | ( | size_t | len, |
| size_t | size, | ||
| const char * | str ) |
Definition at line 573 of file mallocn_guarded_impl.cc.
References len, MEM_guarded_mallocN(), mem_in_use, MEM_size_safe_multiply(), print_error(), SIZET_ARG, SIZET_FORMAT, str, and UNLIKELY.
Referenced by MEM_use_guarded_allocator().
| void * MEM_guarded_mallocN | ( | size_t | len, |
| const char * | str ) |
Definition at line 531 of file mallocn_guarded_impl.cc.
References 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_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 591 of file mallocn_guarded_impl.cc.
References aligned_malloc(), ALIGNED_MALLOC_MINIMUM_ALIGNMENT, MemHead::alignment, 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_reallocN_id(), MEM_guarded_recallocN_id(), and MEM_use_guarded_allocator().
| const char * MEM_guarded_name_ptr | ( | void * | vmemh | ) |
Definition at line 1368 of file mallocn_guarded_impl.cc.
References MemHead::name.
Referenced by MEM_use_guarded_allocator().
| void MEM_guarded_name_ptr_set | ( | void * | vmemh, |
| const char * | str ) |
Definition at line 1379 of file mallocn_guarded_impl.cc.
References MEMNEXT, MemHead::name, MemHead::prev, and str.
Referenced by MEM_use_guarded_allocator().
| void MEM_guarded_printmemlist | ( | void | ) |
Definition at line 1003 of file mallocn_guarded_impl.cc.
References MEM_guarded_printmemlist_internal().
Referenced by MEM_use_guarded_allocator().
|
static |
Definition at line 889 of file mallocn_guarded_impl.cc.
References localListBase::first, MemHead::len, mem_lock_thread(), mem_printmemlist_pydict_script, mem_unlock_thread(), membase, MEMNEXT, MemHead::name, MemHead::next, 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 1007 of file mallocn_guarded_impl.cc.
References MEM_guarded_printmemlist_internal().
Referenced by MEM_use_guarded_allocator().
| void MEM_guarded_printmemlist_stats | ( | void | ) |
Definition at line 765 of file mallocn_guarded_impl.cc.
References MemHead::alignment, b, compare_len(), compare_name(), localListBase::first, free(), MemPrintBlock::items, MemHead::len, MemPrintBlock::len, mem_in_use, mem_lock_thread(), mem_unlock_thread(), membase, MEMNEXT, MemHead::name, MemPrintBlock::name, MemHead::next, peak_mem, print_error(), printf, totblock, and UNLIKELY.
Referenced by MEM_use_guarded_allocator().
| void * MEM_guarded_reallocN_id | ( | void * | vmemh, |
| size_t | len, | ||
| const char * | str ) |
Definition at line 384 of file mallocn_guarded_impl.cc.
References MemHead::alignment, MemHead::flag, len, MemHead::len, LIKELY, MEM_guarded_freeN(), MEM_guarded_mallocN(), MEM_guarded_mallocN_aligned(), MEMHEAD_FLAG_FROM_CPP_NEW, MemHead::name, 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 426 of file mallocn_guarded_impl.cc.
References MemHead::alignment, MemHead::flag, len, MemHead::len, LIKELY, MEM_guarded_callocN(), MEM_guarded_freeN(), MEM_guarded_mallocN(), MEM_guarded_mallocN_aligned(), MEMHEAD_FLAG_FROM_CPP_NEW, MemHead::name, report_error_on_address(), and str.
Referenced by MEM_use_guarded_allocator().
| void MEM_guarded_reset_peak_memory | ( | void | ) |
Definition at line 1338 of file mallocn_guarded_impl.cc.
References mem_in_use, mem_lock_thread(), mem_unlock_thread(), and peak_mem.
Referenced by MEM_use_guarded_allocator().
| void MEM_guarded_set_error_callback | ( | void(* | func )(const char *) | ) |
Definition at line 302 of file mallocn_guarded_impl.cc.
References error_callback.
Referenced by MEM_use_guarded_allocator().
| void MEM_guarded_set_memory_debug | ( | void | ) |
Definition at line 307 of file mallocn_guarded_impl.cc.
References malloc_debug_memset.
Referenced by MEM_use_guarded_allocator().
|
static |
Definition at line 279 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 284 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 1186 of file mallocn_guarded_impl.cc.
References error(), and print_error().
Referenced by check_memlist(), and MEM_guarded_freeN().
|
static |
Definition at line 219 of file mallocn_guarded_impl.cc.
References error_callback.
Referenced by MEM_guarded_calloc_arrayN(), MEM_guarded_calloc_arrayN_aligned(), MEM_guarded_callocN(), MEM_guarded_malloc_arrayN(), 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 237 of file mallocn_guarded_impl.cc.
References print_error().
|
static |
Definition at line 1153 of file mallocn_guarded_impl.cc.
References aligned_free(), MemHead::alignment, atomic_sub_and_fetch_u(), atomic_sub_and_fetch_z(), free(), MemHead::len, LIKELY, malloc_debug_memset, mem_in_use, mem_lock_thread(), mem_unlock_thread(), membase, MEMHEAD_REAL_PTR, MEMNEXT, MemHead::name, MemHead::next, MemHead::prev, remlink(), totblock, and UNLIKELY.
Referenced by MEM_guarded_freeN().
|
static |
Definition at line 1125 of file mallocn_guarded_impl.cc.
References localListBase::first, localListBase::last, localLink::next, and localLink::prev.
Referenced by rem_memblock().
|
static |
Definition at line 249 of file mallocn_guarded_impl.cc.
References MemHead::alignment, MemHeadAligned::alignment, len, MemHead::len, MEM_trigger_error_on_memory_block(), MEMHEAD_ALIGN_PADDING, MEMHEAD_REAL_PTR, print_error(), and UNLIKELY.
Referenced by MEM_guarded_dupallocN(), MEM_guarded_freeN(), MEM_guarded_reallocN_id(), and MEM_guarded_recallocN_id().
|
static |
Definition at line 193 of file mallocn_guarded_impl.cc.
|
static |
Definition at line 195 of file mallocn_guarded_impl.cc.
Referenced by imb_load_jp2_stream(), imb_save_jp2_stream(), MEM_guarded_set_error_callback(), and print_error().
|
static |
Definition at line 197 of file mallocn_guarded_impl.cc.
Referenced by MEM_guarded_mallocN(), MEM_guarded_mallocN_aligned(), MEM_guarded_set_memory_debug(), and rem_memblock().
|
static |
Definition at line 191 of file mallocn_guarded_impl.cc.
Referenced by ED_info_statusbar_string_ex(), MEM_CacheLimiter< T >::enforce_limits(), IMB_moviecache_put_if_possible(), make_memhead_header(), make_renderinfo_string(), MEM_guarded_calloc_arrayN(), MEM_guarded_calloc_arrayN_aligned(), MEM_guarded_callocN(), MEM_guarded_get_memory_in_use(), MEM_guarded_malloc_arrayN(), 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 stats_background().
|
static |
Definition at line 868 of file mallocn_guarded_impl.cc.
Referenced by MEM_guarded_printmemlist_internal().
|
static |
Definition at line 194 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 191 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 277 of file mallocn_guarded_impl.cc.
Referenced by mem_lock_thread(), and mem_unlock_thread().
|
static |
Definition at line 190 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(), rem_memblock(), and wm_main_playanim_intern().