Blender
V3.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.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 |
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 133 of file mallocn_guarded_impl.c.
Definition at line 141 of file mallocn_guarded_impl.c.
typedef struct localListBase localListBase |
typedef MemHead MemHeadAligned |
Definition at line 101 of file mallocn_guarded_impl.c.
typedef struct MemPrintBlock MemPrintBlock |
|
static |
Definition at line 924 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 1019 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().
Definition at line 590 of file mallocn_guarded_impl.c.
References MemPrintBlock::len.
Referenced by MEM_guarded_printmemlist_stats().
Definition at line 582 of file mallocn_guarded_impl.c.
References MemPrintBlock::name.
Referenced by MEM_guarded_printmemlist_stats().
Definition at line 397 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 229 of file mallocn_guarded_impl.c.
References MemHead::len.
Referenced by MEM_use_guarded_allocator().
Definition at line 786 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 557 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 533 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().
Definition at line 206 of file mallocn_guarded_impl.c.
References check_memlist(), localListBase::last, membase, and NULL.
Referenced by MEM_use_guarded_allocator().
Definition at line 241 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().
Definition at line 849 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 1180 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 1169 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 1151 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 460 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 432 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 478 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 1192 of file mallocn_guarded_impl.c.
References MemHead::name.
Referenced by MEM_use_guarded_allocator().
Definition at line 840 of file mallocn_guarded_impl.c.
References MEM_guarded_printmemlist_internal().
Referenced by MEM_use_guarded_allocator().
|
static |
Definition at line 729 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().
Definition at line 844 of file mallocn_guarded_impl.c.
References MEM_guarded_printmemlist_internal().
Referenced by MEM_use_guarded_allocator().
Definition at line 605 of file mallocn_guarded_impl.c.
References Freestyle::a, MemHead::alignment, usdtokens::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, NULL, peak_mem, print_error(), totblock, and UNLIKELY.
Referenced by MEM_use_guarded_allocator().
Definition at line 290 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().
Definition at line 325 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().
Definition at line 1162 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().
Definition at line 219 of file mallocn_guarded_impl.c.
References error_callback.
Referenced by MEM_use_guarded_allocator().
Definition at line 224 of file mallocn_guarded_impl.c.
References malloc_debug_memset.
Referenced by MEM_use_guarded_allocator().
Definition at line 196 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().
Definition at line 201 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 1010 of file mallocn_guarded_impl.c.
References error(), and print_error().
Referenced by check_memlist(), and MEM_guarded_freeN().
|
static |
Definition at line 176 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().
Definition at line 977 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 949 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 148 of file mallocn_guarded_impl.c.
Definition at line 152 of file mallocn_guarded_impl.c.
Referenced by MEM_guarded_set_error_callback(), and print_error().
|
static |
Definition at line 154 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 148 of file mallocn_guarded_impl.c.
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_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 708 of file mallocn_guarded_impl.c.
Referenced by MEM_guarded_printmemlist_internal().
|
static |
Definition at line 151 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 148 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 194 of file mallocn_guarded_impl.c.
Referenced by mem_lock_thread(), and mem_unlock_thread().
|
static |
Definition at line 147 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().