blob: d09d5e2d84ac6e15914883f49983ca52a1adc0d2 [file] [log] [blame]
James Kuszmaul82f6c042021-01-17 11:30:16 -08001/**
2 * @file re_mem.h Interface to Memory management with reference counting
3 *
4 * Copyright (C) 2010 Creytiv.com
5 */
6
7
8/**
9 * Defines the memory destructor handler, which is called when the reference
10 * of a memory object goes down to zero
11 *
12 * @param data Pointer to memory object
13 */
14typedef void (mem_destroy_h)(void *data);
15
16/** Memory Statistics */
17struct memstat {
18 size_t bytes_cur; /**< Current bytes allocated */
19 size_t bytes_peak; /**< Peak bytes allocated */
20 size_t blocks_cur; /**< Current blocks allocated */
21 size_t blocks_peak; /**< Peak blocks allocated */
22 size_t size_min; /**< Lowest block size allocated */
23 size_t size_max; /**< Largest block size allocated */
24};
25
26void *mem_alloc(size_t size, mem_destroy_h *dh);
27void *mem_zalloc(size_t size, mem_destroy_h *dh);
28void *mem_realloc(void *data, size_t size);
29void *mem_reallocarray(void *ptr, size_t nmemb,
30 size_t membsize, mem_destroy_h *dh);
31void *mem_ref(void *data);
32void *mem_deref(void *data);
33uint32_t mem_nrefs(const void *data);
34
35void mem_debug(void);
36void mem_threshold_set(ssize_t n);
37struct re_printf;
38int mem_status(struct re_printf *pf, void *unused);
39int mem_get_stat(struct memstat *mstat);
40
41
42/* Secure memory functions */
43int mem_seccmp(const volatile uint8_t *volatile s1,
44 const volatile uint8_t *volatile s2,
45 size_t n);