Rizin
unix-like reverse engineering framework and cli tools
|
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <stdint.h>
#include <errno.h>
#include <sys/mman.h>
#include "libc.h"
#include "atomic.h"
#include "pthread_impl.h"
Go to the source code of this file.
Classes | |
struct | chunk |
struct | bin |
Macros | |
#define | _GNU_SOURCE |
#define | SIZE_ALIGN (4*sizeof(size_t)) |
#define | SIZE_MASK (-SIZE_ALIGN) |
#define | OVERHEAD (2*sizeof(size_t)) |
#define | MMAP_THRESHOLD (0x1c00*SIZE_ALIGN) |
#define | DONTCARE 16 |
#define | RECLAIM 163840 |
#define | CHUNK_SIZE(c) ((c)->csize & -2) |
#define | CHUNK_PSIZE(c) ((c)->psize & -2) |
#define | PREV_CHUNK(c) ((struct chunk *)((char *)(c) - CHUNK_PSIZE(c))) |
#define | NEXT_CHUNK(c) ((struct chunk *)((char *)(c) + CHUNK_SIZE(c))) |
#define | MEM_TO_CHUNK(p) (struct chunk *)((char *)(p) - OVERHEAD) |
#define | CHUNK_TO_MEM(c) (void *)((char *)(c) + OVERHEAD) |
#define | BIN_TO_CHUNK(i) (MEM_TO_CHUNK(&mal.bins[i].head)) |
#define | C_INUSE ((size_t)1) |
#define | IS_MMAPPED(c) !((c)->csize & (C_INUSE)) |
Functions | |
void * | __mmap (void *, size_t, int, int, int, off_t) |
int | __munmap (void *, size_t) |
void * | __mremap (void *, size_t, size_t, int,...) |
int | __madvise (void *, size_t, int) |
static void | lock (volatile int *lk) |
static void | unlock (volatile int *lk) |
static void | lock_bin (int i) |
static void | unlock_bin (int i) |
static int | first_set (uint64_t x) |
static int | bin_index (size_t x) |
static int | bin_index_up (size_t x) |
void * | __expand_heap (size_t *) |
static struct chunk * | expand_heap (size_t n) |
static int | adjust_size (size_t *n) |
static void | unbin (struct chunk *c, int i) |
static int | alloc_fwd (struct chunk *c) |
static int | alloc_rev (struct chunk *c) |
static int | pretrim (struct chunk *self, size_t n, int i, int j) |
static void | trim (struct chunk *self, size_t n) |
void * | malloc (size_t n) |
void * | __malloc0 (size_t n) |
void * | realloc (void *p, size_t n) |
void | free (void *p) |
Variables | |
struct { | |
volatile uint64_t binmap | |
struct bin bins [64] | |
volatile int free_lock [2] | |
} | mal |
static const unsigned char | bin_tab [60] |
#define MMAP_THRESHOLD (0x1c00*SIZE_ALIGN) |
#define NEXT_CHUNK | ( | c | ) | ((struct chunk *)((char *)(c) + CHUNK_SIZE(c))) |
#define PREV_CHUNK | ( | c | ) | ((struct chunk *)((char *)(c) - CHUNK_PSIZE(c))) |
#define SIZE_MASK (-SIZE_ALIGN) |
void* __expand_heap | ( | size_t * | ) |
Referenced by expand_heap().
void* __malloc0 | ( | size_t | n | ) |
Definition at line 208 of file malloc.c.
References ENOMEM, n, OVERHEAD, PTRDIFF_MAX, SIZE_ALIGN, and SIZE_MASK.
Definition at line 234 of file malloc.c.
References bin_index(), c, C_INUSE, i, k, lock_bin(), unbin(), and unlock_bin().
Definition at line 251 of file malloc.c.
References bin_index(), c, C_INUSE, i, k, lock_bin(), PREV_CHUNK, unbin(), and unlock_bin().
Definition at line 121 of file malloc.c.
References bin_tab, SIZE_ALIGN, and x.
Referenced by alloc_fwd(), alloc_rev(), free(), and pretrim().
Definition at line 162 of file malloc.c.
References __expand_heap(), C_INUSE, test_evm::end, lock(), MEM_TO_CHUNK, n, p, SIZE_ALIGN, unlock(), and w.
Referenced by malloc().
void free | ( | void * | p | ) |
Definition at line 451 of file malloc.c.
References __madvise(), __mmap(), __munmap(), a, alloc_fwd(), alloc_rev(), b, bin_index(), BIN_TO_CHUNK, C_INUSE, CHUNK_SIZE, chunk::csize, i, IS_MMAPPED, len, lock(), lock_bin(), mal, MAP_ANONYMOUS, MAP_FIXED, MAP_PRIVATE, MEM_TO_CHUNK, chunk::next, NEXT_CHUNK, p, PREV_CHUNK, PROT_READ, PROT_WRITE, chunk::psize, RECLAIM, SIZE_ALIGN, unlock(), and unlock_bin().
Definition at line 61 of file malloc.c.
Referenced by backtrace_windows(), expand_heap(), free(), iob_read(), iob_write(), jemalloc_print_narenas(), lock_bin(), rz_basefind(), rz_bin_file_strings(), rz_core_autocomplete_add(), rz_th_cond_wait(), sdb_new(), sdb_ns_lock(), uv__fs_write(), and uv_pipe_zero_readfile_thread_proc().
|
inlinestatic |
void* malloc | ( | size_t | n | ) |
Definition at line 320 of file malloc.c.
References __mmap(), adjust_size(), alloc_rev(), bin_index_up(), BIN_TO_CHUNK, c, CHUNK_SIZE, CHUNK_TO_MEM, expand_heap(), first_set(), i, len, lock_bin(), mal, MAP_ANONYMOUS, MAP_PRIVATE, mask, MMAP_THRESHOLD, n, NEXT_CHUNK, OVERHEAD, pretrim(), PREV_CHUNK, PROT_READ, PROT_WRITE, SIZE_ALIGN, trim(), unbin(), unlock_bin(), and x.
Definition at line 272 of file malloc.c.
References bin_index(), C_INUSE, CHUNK_SIZE, chunk::csize, i, MMAP_THRESHOLD, n, chunk::next, NEXT_CHUNK, chunk::prev, and chunk::psize.
Referenced by malloc().
void* realloc | ( | void * | p, |
size_t | n | ||
) |
Definition at line 380 of file malloc.c.
References __mremap(), adjust_size(), alloc_fwd(), alloc_rev(), C_INUSE, CHUNK_SIZE, CHUNK_TO_MEM, free(), IS_MMAPPED, malloc(), MEM_TO_CHUNK, memcpy(), n, chunk::next, NEXT_CHUNK, OVERHEAD, p, PREV_CHUNK, chunk::psize, and trim().
Definition at line 302 of file malloc.c.
References C_INUSE, CHUNK_SIZE, CHUNK_TO_MEM, chunk::csize, DONTCARE, free(), n, chunk::next, NEXT_CHUNK, and chunk::psize.
Definition at line 224 of file malloc.c.
References c, C_INUSE, i, mal, and NEXT_CHUNK.
Referenced by alloc_fwd(), alloc_rev(), and malloc().
Definition at line 67 of file malloc.c.
Referenced by expand_heap(), free(), and unlock_bin().
|
inlinestatic |
Definition at line 114 of file malloc.c.
Referenced by bin_index(), and bin_index_up().
struct bin bins[64] |
Definition at line 33 of file malloc.c.
Referenced by create_cache_bins(), jemalloc_print_narenas(), and print_tcache_content().
struct { ... } mal |
Referenced by __open(), _io_malloc_buf(), _io_malloc_off(), _io_malloc_set_buf(), _io_malloc_set_off(), _io_malloc_set_sz(), _io_malloc_sz(), free(), getmalfd(), lock_bin(), malloc(), unbin(), and unlock_bin().