|
Blender
V2.93
|
#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.h"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 |
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 (MemHead *memh) |
| static void | print_error (const char *str,...) |
| static void | mem_lock_thread (void) |
| static void | mem_unlock_thread (void) |
| bool | MEM_guarded_consistency_check (void) |
| void | MEM_guarded_set_error_callback (void(*func)(const char *)) |
| void | MEM_guarded_set_memory_debug (void) |
| 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) |
| 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) |
| 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 int | compare_name (const void *p1, const void *p2) |
| static int | compare_len (const void *p1, const void *p2) |
| void | MEM_guarded_printmemlist_stats (void) |
| static void | MEM_guarded_printmemlist_internal (int pydict) |
| void | MEM_guarded_callbackmemlist (void(*func)(void *)) |
| void | MEM_guarded_printmemlist (void) |
| void | MEM_guarded_printmemlist_pydict (void) |
| void | MEM_guarded_freeN (void *vmemh) |
| size_t | MEM_guarded_get_peak_memory (void) |
| void | MEM_guarded_reset_peak_memory (void) |
| size_t | MEM_guarded_get_memory_in_use (void) |
| unsigned int | MEM_guarded_get_memory_blocks_in_use (void) |
| const char * | MEM_guarded_name_ptr (void *vmemh) |
Variables | |
| static unsigned int | totblock = 0 |
| static size_t | mem_in_use = 0 |
| static size_t | peak_mem = 0 |
| static volatile struct localListBase | _membase |
| static volatile struct localListBase * | membase = &_membase |
| static void(* | error_callback )(const char *) = NULL |
| 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.c.
| #define MAKE_ID | ( | a, | |
| b, | |||
| c, | |||
| d | |||
| ) | ((int)(d) << 24 | (int)(c) << 16 | (b) << 8 | (a)) |
Definition at line 150 of file mallocn_guarded_impl.c.
Definition at line 156 of file mallocn_guarded_impl.c.
Definition at line 158 of file mallocn_guarded_impl.c.
Definition at line 153 of file mallocn_guarded_impl.c.
Definition at line 155 of file mallocn_guarded_impl.c.
| typedef struct localListBase localListBase |
| typedef MemHead MemHeadAligned |
Definition at line 118 of file mallocn_guarded_impl.c.
| typedef struct MemPrintBlock MemPrintBlock |
|
static |
Definition at line 941 of file mallocn_guarded_impl.c.
References localListBase::first, localListBase::last, localLink::next, NULL, and localLink::prev.
Referenced by make_memhead_header().
|
static |
Definition at line 1036 of file mallocn_guarded_impl.c.
References localListBase::first, if(), localListBase::last, membase, MEMNEXT, MemorY_ErroR(), MEMTAG1, MEMTAG2, MemHead::name, MemHead::next, MemHead::nextname, NULL, MemHead::prev, MemHead::tag1, and MemHead::tag2.
Referenced by MEM_guarded_consistency_check(), and MEM_guarded_freeN().
|
static |
Definition at line 607 of file mallocn_guarded_impl.c.
References MemPrintBlock::len.
Referenced by MEM_guarded_printmemlist_stats().
|
static |
Definition at line 599 of file mallocn_guarded_impl.c.
References MemPrintBlock::name.
Referenced by MEM_guarded_printmemlist_stats().
|
static |
Definition at line 414 of file mallocn_guarded_impl.c.
References addtail(), MemHead::alignment, atomic_add_and_fetch_u(), atomic_add_and_fetch_z(), MemHead::len, len, mem_in_use, mem_lock_thread(), mem_unlock_thread(), membase, MEMNEXT, MEMTAG1, MEMTAG2, MEMTAG3, MemHead::name, MemHead::next, MemHead::nextname, NULL, MemHead::pad1, 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 246 of file mallocn_guarded_impl.c.
References MemHead::len.
Referenced by MEM_use_guarded_allocator().
| void MEM_guarded_callbackmemlist | ( | void(*)(void *) | func | ) |
Definition at line 803 of file mallocn_guarded_impl.c.
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 574 of file mallocn_guarded_impl.c.
References len, MEM_guarded_callocN(), mem_in_use, MEM_size_safe_multiply(), NULL, print_error(), size(), 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 550 of file mallocn_guarded_impl.c.
References len, make_memhead_header(), mem_in_use, NULL, 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().
| bool MEM_guarded_consistency_check | ( | void | ) |
Definition at line 223 of file mallocn_guarded_impl.c.
References check_memlist(), localListBase::last, membase, and NULL.
Referenced by MEM_use_guarded_allocator().
| void* MEM_guarded_dupallocN | ( | const void * | vmemh | ) |
Definition at line 258 of file mallocn_guarded_impl.c.
References MemHead::alignment, MemHead::len, LIKELY, MEM_guarded_mallocN(), MEM_guarded_mallocN_aligned(), MemHead::name, and NULL.
Referenced by MEM_use_guarded_allocator().
| void MEM_guarded_freeN | ( | void * | vmemh | ) |
Definition at line 866 of file mallocn_guarded_impl.c.
References check_memlist(), free_after_leak_detection_message, leak_detector_has_run, MemHead::len, mem_lock_thread(), mem_unlock_thread(), MEMFREE, MemorY_ErroR(), MEMTAG1, MEMTAG2, MEMTAG3, MemHead::name, NULL, rem_memblock(), MemHead::tag1, MemHead::tag2, MemTail::tag3, and totblock.
Referenced by MEM_guarded_reallocN_id(), MEM_guarded_recallocN_id(), and MEM_use_guarded_allocator().
| unsigned int MEM_guarded_get_memory_blocks_in_use | ( | void | ) |
Definition at line 1197 of file mallocn_guarded_impl.c.
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 1186 of file mallocn_guarded_impl.c.
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 1168 of file mallocn_guarded_impl.c.
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 477 of file mallocn_guarded_impl.c.
References len, MEM_guarded_mallocN(), mem_in_use, MEM_size_safe_multiply(), NULL, print_error(), size(), 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 449 of file mallocn_guarded_impl.c.
References len, LIKELY, make_memhead_header(), malloc_debug_memset, mem_in_use, NULL, 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 | ||
| ) |
Definition at line 495 of file mallocn_guarded_impl.c.
References aligned_malloc(), MemHead::alignment, IS_POW2, len, LIKELY, make_memhead_header(), malloc_debug_memset, mem_in_use, MEMHEAD_ALIGN_PADDING, NULL, 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 1209 of file mallocn_guarded_impl.c.
References MemHead::name.
Referenced by MEM_use_guarded_allocator().
| void MEM_guarded_printmemlist | ( | void | ) |
Definition at line 857 of file mallocn_guarded_impl.c.
References MEM_guarded_printmemlist_internal().
Referenced by MEM_use_guarded_allocator().
|
static |
Definition at line 746 of file mallocn_guarded_impl.c.
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 861 of file mallocn_guarded_impl.c.
References MEM_guarded_printmemlist_internal().
Referenced by MEM_use_guarded_allocator().
| void MEM_guarded_printmemlist_stats | ( | void | ) |
Definition at line 622 of file mallocn_guarded_impl.c.
References Freestyle::a, MemHead::alignment, 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, NULL, peak_mem, print_error(), 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 307 of file mallocn_guarded_impl.c.
References MemHead::alignment, MemHead::len, len, LIKELY, MEM_guarded_freeN(), MEM_guarded_mallocN(), MEM_guarded_mallocN_aligned(), MemHead::name, NULL, and str.
Referenced by MEM_use_guarded_allocator().
| void* MEM_guarded_recallocN_id | ( | void * | vmemh, |
| size_t | len, | ||
| const char * | str | ||
| ) |
Definition at line 342 of file mallocn_guarded_impl.c.
References MemHead::alignment, MemHead::len, len, LIKELY, MEM_guarded_callocN(), MEM_guarded_freeN(), MEM_guarded_mallocN(), MEM_guarded_mallocN_aligned(), MemHead::name, NULL, and str.
Referenced by MEM_use_guarded_allocator().
| void MEM_guarded_reset_peak_memory | ( | void | ) |
Definition at line 1179 of file mallocn_guarded_impl.c.
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(*)(const char *) | func | ) |
Definition at line 236 of file mallocn_guarded_impl.c.
References error_callback.
Referenced by MEM_use_guarded_allocator().
| void MEM_guarded_set_memory_debug | ( | void | ) |
Definition at line 241 of file mallocn_guarded_impl.c.
References malloc_debug_memset.
Referenced by MEM_use_guarded_allocator().
|
static |
Definition at line 213 of file mallocn_guarded_impl.c.
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 218 of file mallocn_guarded_impl.c.
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 1027 of file mallocn_guarded_impl.c.
References error(), and print_error().
Referenced by check_memlist(), and MEM_guarded_freeN().
|
static |
Definition at line 193 of file mallocn_guarded_impl.c.
References error_callback, and str.
Referenced by MEM_guarded_calloc_arrayN(), MEM_guarded_callocN(), MEM_guarded_malloc_arrayN(), MEM_guarded_mallocN(), MEM_guarded_mallocN_aligned(), MEM_guarded_printmemlist_internal(), MEM_guarded_printmemlist_stats(), and MemorY_ErroR().
|
static |
Definition at line 994 of file mallocn_guarded_impl.c.
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, NULL, MemHead::prev, remlink(), totblock, and UNLIKELY.
Referenced by MEM_guarded_freeN().
|
static |
Definition at line 966 of file mallocn_guarded_impl.c.
References localListBase::first, localListBase::last, localLink::next, NULL, and localLink::prev.
Referenced by rem_memblock().
|
static |
Definition at line 165 of file mallocn_guarded_impl.c.
|
static |
Definition at line 169 of file mallocn_guarded_impl.c.
Referenced by MEM_guarded_set_error_callback(), and print_error().
|
static |
Definition at line 171 of file mallocn_guarded_impl.c.
Referenced by MEM_guarded_mallocN(), MEM_guarded_mallocN_aligned(), MEM_guarded_set_memory_debug(), and rem_memblock().
|
static |
Definition at line 165 of file mallocn_guarded_impl.c.
Referenced by MEM_CacheLimiter< T >::enforce_limits(), IMB_moviecache_put_if_possible(), info_statusbar_string(), 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_mallocN(), MEM_guarded_mallocN_aligned(), MEM_guarded_printmemlist_stats(), MEM_guarded_reset_peak_memory(), rem_memblock(), Freestyle::Controller::RenderStrokes(), and stats_background().
|
static |
Definition at line 725 of file mallocn_guarded_impl.c.
Referenced by MEM_guarded_printmemlist_internal().
|
static |
Definition at line 168 of file mallocn_guarded_impl.c.
Referenced by check_memlist(), make_memhead_header(), MEM_guarded_callbackmemlist(), MEM_guarded_consistency_check(), MEM_guarded_printmemlist_internal(), MEM_guarded_printmemlist_stats(), and rem_memblock().
|
static |
Definition at line 165 of file mallocn_guarded_impl.c.
Referenced by make_memhead_header(), MEM_guarded_get_peak_memory(), MEM_guarded_printmemlist_stats(), and MEM_guarded_reset_peak_memory().
|
static |
Definition at line 211 of file mallocn_guarded_impl.c.
Referenced by mem_lock_thread(), and mem_unlock_thread().
|
static |
Definition at line 164 of file mallocn_guarded_impl.c.
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().