MP-Gadget
5.0.1.dev1-76bc7d4726-dirty
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include "memory.h"
#include "endrun.h"
Go to the source code of this file.
Classes | |
struct | BlockHeader |
Macros | |
#define | MAGIC "DEADBEEF" |
#define | ALIGNMENT 4096 |
Functions | |
int | allocator_init (Allocator *alloc, const char *name, const size_t request_size, const int zero, Allocator *parent) |
int | allocator_malloc_init (Allocator *alloc, const char *name, const size_t request_size, const int zero, Allocator *parent) |
int | allocator_reset (Allocator *alloc, int zero) |
static void * | allocator_alloc_va (Allocator *alloc, const char *name, const size_t request_size, const int dir, const char *fmt, va_list va) |
void * | allocator_alloc (Allocator *alloc, const char *name, const size_t request_size, const int dir, const char *fmt,...) |
int | allocator_destroy (Allocator *alloc) |
int | allocator_iter_start (AllocatorIter *iter, Allocator *alloc) |
static int | is_header (struct BlockHeader *header) |
int | allocator_iter_next (AllocatorIter *iter) |
int | allocator_iter_ended (AllocatorIter *iter) |
size_t | allocator_get_free_size (Allocator *alloc) |
size_t | allocator_get_used_size (Allocator *alloc, int dir) |
void | allocator_print (Allocator *alloc) |
void * | allocator_realloc_int (Allocator *alloc, void *ptr, const size_t new_size, const char *fmt,...) |
void | allocator_free (void *ptr) |
int | allocator_dealloc (Allocator *alloc, void *ptr) |
void* allocator_alloc | ( | Allocator * | alloc, |
const char * | name, | ||
const size_t | request_size, | ||
const int | dir, | ||
const char * | fmt, | ||
... | |||
) |
Definition at line 166 of file memory.c.
References BlockHeader::alloc, allocator_alloc_va(), BlockHeader::dir, name, and BlockHeader::request_size.
Referenced by allocator_init(), and allocator_malloc_init().
|
static |
Definition at line 106 of file memory.c.
References ALIGNMENT, BlockHeader::alloc, ALLOC_DIR_BOT, ALLOC_DIR_TOP, allocator_print(), BlockHeader::annotation, Allocator::base, Allocator::bottom, BlockHeader::dir, endrun(), MAGIC, BlockHeader::magic, name, BlockHeader::name, BlockHeader::ptr, Allocator::refcount, BlockHeader::request_size, BlockHeader::self, BlockHeader::size, Allocator::top, and Allocator::use_malloc.
Referenced by allocator_alloc(), and allocator_realloc_int().
int allocator_dealloc | ( | Allocator * | alloc, |
void * | ptr | ||
) |
Definition at line 376 of file memory.c.
References ALIGNMENT, BlockHeader::alloc, ALLOC_DIR_BOT, ALLOC_DIR_TOP, ALLOC_EMISMATCH, ALLOC_ENOTALLOC, Allocator::base, Allocator::bottom, BlockHeader::dir, is_header(), BlockHeader::ptr, Allocator::refcount, BlockHeader::self, BlockHeader::size, Allocator::top, and Allocator::use_malloc.
Referenced by allocator_destroy(), allocator_free(), allocator_realloc_int(), test_allocator(), and test_allocator_malloc().
int allocator_destroy | ( | Allocator * | alloc | ) |
Definition at line 176 of file memory.c.
References BlockHeader::alloc, allocator_dealloc(), allocator_print(), endrun(), Allocator::parent, Allocator::rawbase, and Allocator::refcount.
Referenced by test_allocator(), test_allocator_malloc(), and test_sub_allocator().
void allocator_free | ( | void * | ptr | ) |
Definition at line 358 of file memory.c.
References ALIGNMENT, BlockHeader::alloc, allocator_dealloc(), allocator_print(), BlockHeader::annotation, endrun(), is_header(), BlockHeader::name, and BlockHeader::ptr.
Referenced by test_allocator(), test_allocator_malloc(), and test_sub_allocator().
size_t allocator_get_free_size | ( | Allocator * | alloc | ) |
Definition at line 246 of file memory.c.
References BlockHeader::alloc, Allocator::bottom, Allocator::top, and Allocator::use_malloc.
Referenced by allocator_print().
size_t allocator_get_used_size | ( | Allocator * | alloc, |
int | dir | ||
) |
Definition at line 256 of file memory.c.
References BlockHeader::alloc, ALLOC_DIR_BOT, ALLOC_DIR_BOTH, ALLOC_DIR_TOP, allocator_iter_ended(), allocator_iter_next(), allocator_iter_start(), Allocator::bottom, BlockHeader::dir, AllocatorIter::request_size, Allocator::size, Allocator::top, and Allocator::use_malloc.
Referenced by allocator_print(), and report_detailed_memory_usage().
int allocator_init | ( | Allocator * | alloc, |
const char * | name, | ||
const size_t | request_size, | ||
const int | zero, | ||
Allocator * | parent | ||
) |
Definition at line 24 of file memory.c.
References ALIGNMENT, ALLOC_DIR_BOT, ALLOC_ENOMEMORY, allocator_alloc(), allocator_reset(), Allocator::base, Allocator::bottom, name, Allocator::name, Allocator::parent, Allocator::rawbase, Allocator::refcount, Allocator::size, Allocator::top, and Allocator::use_malloc.
Referenced by mymalloc_init(), tamalloc_init(), test_allocator(), and test_sub_allocator().
int allocator_iter_ended | ( | AllocatorIter * | iter | ) |
Definition at line 240 of file memory.c.
References AllocatorIter::_ended.
Referenced by allocator_get_used_size(), allocator_print(), and allocator_reset().
int allocator_iter_next | ( | AllocatorIter * | iter | ) |
Definition at line 209 of file memory.c.
References AllocatorIter::_bottom, AllocatorIter::_ended, AllocatorIter::_top, BlockHeader::alloc, AllocatorIter::alloc, BlockHeader::annotation, AllocatorIter::annotation, Allocator::base, Allocator::bottom, BlockHeader::dir, AllocatorIter::dir, endrun(), is_header(), BlockHeader::name, AllocatorIter::name, BlockHeader::ptr, AllocatorIter::ptr, BlockHeader::request_size, AllocatorIter::request_size, BlockHeader::size, Allocator::size, and AllocatorIter::size.
Referenced by allocator_get_used_size(), allocator_iter_start(), allocator_print(), and allocator_reset().
int allocator_iter_start | ( | AllocatorIter * | iter, |
Allocator * | alloc | ||
) |
Definition at line 190 of file memory.c.
References AllocatorIter::_bottom, AllocatorIter::_ended, AllocatorIter::_top, BlockHeader::alloc, AllocatorIter::alloc, allocator_iter_next(), and Allocator::top.
Referenced by allocator_get_used_size(), allocator_print(), and allocator_reset().
int allocator_malloc_init | ( | Allocator * | alloc, |
const char * | name, | ||
const size_t | request_size, | ||
const int | zero, | ||
Allocator * | parent | ||
) |
Definition at line 54 of file memory.c.
References ALIGNMENT, ALLOC_DIR_BOT, ALLOC_ENOMEMORY, allocator_alloc(), allocator_reset(), Allocator::base, Allocator::bottom, name, Allocator::name, Allocator::parent, Allocator::rawbase, Allocator::refcount, Allocator::size, Allocator::top, and Allocator::use_malloc.
Referenced by test_allocator_malloc().
void allocator_print | ( | Allocator * | alloc | ) |
Definition at line 284 of file memory.c.
References BlockHeader::alloc, ALLOC_DIR_BOT, ALLOC_DIR_BOTH, ALLOC_DIR_TOP, allocator_get_free_size(), allocator_get_used_size(), allocator_iter_ended(), allocator_iter_next(), allocator_iter_start(), AllocatorIter::annotation, AllocatorIter::dir, message(), Allocator::name, AllocatorIter::name, AllocatorIter::request_size, Allocator::size, AllocatorIter::size, and Allocator::use_malloc.
Referenced by allocator_alloc_va(), allocator_destroy(), allocator_free(), allocator_realloc_int(), report_detailed_memory_usage(), test_allocator(), test_allocator_malloc(), and test_sub_allocator().
void* allocator_realloc_int | ( | Allocator * | alloc, |
void * | ptr, | ||
const size_t | new_size, | ||
const char * | fmt, | ||
... | |||
) |
Definition at line 312 of file memory.c.
References ALIGNMENT, BlockHeader::alloc, ALLOC_DIR_TOP, allocator_alloc_va(), allocator_dealloc(), allocator_print(), BlockHeader::annotation, Allocator::base, BlockHeader::dir, endrun(), is_header(), BlockHeader::name, BlockHeader::ptr, BlockHeader::request_size, BlockHeader::self, BlockHeader::size, Allocator::top, and Allocator::use_malloc.
int allocator_reset | ( | Allocator * | alloc, |
int | zero | ||
) |
Definition at line 85 of file memory.c.
References ALIGNMENT, allocator_iter_ended(), allocator_iter_next(), allocator_iter_start(), Allocator::base, Allocator::bottom, AllocatorIter::ptr, Allocator::refcount, Allocator::size, Allocator::top, and Allocator::use_malloc.
Referenced by allocator_init(), and allocator_malloc_init().
|
static |
Definition at line 203 of file memory.c.
References MAGIC, and BlockHeader::magic.
Referenced by allocator_dealloc(), allocator_free(), allocator_iter_next(), and allocator_realloc_int().