Rizin
unix-like reverse engineering framework and cli tools
alloc.c File Reference
#include <rz_util.h>
#include <rz_util/rz_alloc.h>

Go to the source code of this file.

Functions

RZ_API void rz_alloc_init (void)
 
RZ_API void * rz_malloc_aligned (size_t size, size_t alignment)
 
RZ_API void rz_free_aligned (void *p)
 

Function Documentation

◆ rz_alloc_init()

RZ_API void rz_alloc_init ( void  )

Definition at line 7 of file alloc.c.

7  {
8 #if RZ_MALLOC_WRAPPER
9  rz_alloc_hooks(malloc, calloc, realloc, free);
10 #endif
11 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
void * realloc(void *ptr, size_t size)
Definition: malloc.c:144
void * malloc(size_t size)
Definition: malloc.c:123
void * calloc(size_t number, size_t size)
Definition: malloc.c:102

References calloc(), free(), malloc(), and realloc().

◆ rz_free_aligned()

RZ_API void rz_free_aligned ( void *  p)

Definition at line 73 of file alloc.c.

73  {
74  _r_free(((void **)p)[-1]);
75 }
void * p
Definition: libc.cpp:67
#define _r_free
Definition: rz_alloc.h:48

References _r_free, and p.

◆ rz_malloc_aligned()

RZ_API void* rz_malloc_aligned ( size_t  size,
size_t  alignment 
)

Definition at line 62 of file alloc.c.

62  {
63  int offset = alignment - 1 + sizeof(void *);
64  void *p1 = _r_malloc(size + offset);
65  if (!p1) {
66  return NULL;
67  }
68  void **p2 = (void **)(((size_t)(p1) + offset) & ~(alignment - 1));
69  p2[-1] = p1;
70  return p2;
71 }
#define NULL
Definition: cris-opc.c:27
voidpf void uLong size
Definition: ioapi.h:138
voidpf uLong offset
Definition: ioapi.h:144
#define _r_malloc
Definition: rz_alloc.h:46

References _r_malloc, and NULL.