Rizin
unix-like reverse engineering framework and cli tools
rz_alloc.h File Reference
#include <rz_types.h>
#include <stdlib.h>
#include <stddef.h>

Go to the source code of this file.

Macros

#define RZ_MALLOC_WRAPPER   0
 
#define RZ_MALLOC_GLOBAL   0
 
#define rz_malloc(x)   malloc((x))
 
#define rz_calloc(x, y)   calloc((x), (y))
 
#define rz_realloc(x, y)   realloc((x), (y))
 
#define rz_free(x)   free((x))
 
#define _r_malloc   rz_malloc
 
#define _r_calloc   rz_calloc
 
#define _r_free   rz_free
 
#define _r_realloc   rz_realloc
 

Typedefs

typedef void *() RMalloc(size_t)
 
typedef void *() RCalloc(size_t, size_t)
 
typedef void *() RRealloc(void *, size_t)
 
typedef void() RFree(void *)
 

Functions

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

Macro Definition Documentation

◆ _r_calloc

#define _r_calloc   rz_calloc

Definition at line 47 of file rz_alloc.h.

◆ _r_free

#define _r_free   rz_free

Definition at line 48 of file rz_alloc.h.

◆ _r_malloc

#define _r_malloc   rz_malloc

Definition at line 46 of file rz_alloc.h.

◆ _r_realloc

#define _r_realloc   rz_realloc

Definition at line 49 of file rz_alloc.h.

◆ rz_calloc

#define rz_calloc (   x,
 
)    calloc((x), (y))

Definition at line 42 of file rz_alloc.h.

◆ rz_free

#define rz_free (   x)    free((x))

Definition at line 44 of file rz_alloc.h.

◆ rz_malloc

#define rz_malloc (   x)    malloc((x))

Definition at line 41 of file rz_alloc.h.

◆ RZ_MALLOC_GLOBAL

#define RZ_MALLOC_GLOBAL   0

Definition at line 9 of file rz_alloc.h.

◆ RZ_MALLOC_WRAPPER

#define RZ_MALLOC_WRAPPER   0

Definition at line 8 of file rz_alloc.h.

◆ rz_realloc

#define rz_realloc (   x,
 
)    realloc((x), (y))

Definition at line 43 of file rz_alloc.h.

Typedef Documentation

◆ RCalloc

typedef void*() RCalloc(size_t, size_t)

Definition at line 12 of file rz_alloc.h.

◆ RFree

typedef void() RFree(void *)

Definition at line 14 of file rz_alloc.h.

◆ RMalloc

typedef void*() RMalloc(size_t)

Definition at line 11 of file rz_alloc.h.

◆ RRealloc

typedef void*() RRealloc(void *, size_t)

Definition at line 13 of file rz_alloc.h.

Function Documentation

◆ 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.