2018-01-25 16:24:33 +00:00
|
|
|
#include <llarp/mem.h>
|
2018-04-04 16:10:27 +00:00
|
|
|
#include <cstring>
|
2017-10-03 19:14:46 +00:00
|
|
|
|
2018-01-29 14:27:24 +00:00
|
|
|
namespace llarp {
|
2018-05-16 18:13:18 +00:00
|
|
|
void *std_malloc(struct llarp_alloc *mem, size_t sz, size_t align) {
|
|
|
|
(void)mem;
|
2018-01-29 14:27:24 +00:00
|
|
|
(void)align;
|
|
|
|
void *ptr = malloc(sz);
|
2018-04-05 14:43:16 +00:00
|
|
|
if (ptr) {
|
2018-04-04 16:10:27 +00:00
|
|
|
std::memset(ptr, 0, sz);
|
|
|
|
return ptr;
|
|
|
|
}
|
2018-01-29 14:27:24 +00:00
|
|
|
abort();
|
|
|
|
}
|
2017-10-03 19:14:46 +00:00
|
|
|
|
2018-05-16 18:13:18 +00:00
|
|
|
void std_free(struct llarp_alloc * mem, void *ptr) {
|
|
|
|
(void) mem;
|
2018-02-01 13:21:00 +00:00
|
|
|
if (ptr) free(ptr);
|
2017-10-03 19:14:46 +00:00
|
|
|
}
|
|
|
|
|
2018-02-01 13:21:00 +00:00
|
|
|
} // namespace llarp
|
2018-01-29 14:27:24 +00:00
|
|
|
|
2017-10-03 19:14:46 +00:00
|
|
|
extern "C" {
|
2018-05-16 18:13:18 +00:00
|
|
|
void llarp_mem_stdlib(struct llarp_alloc * mem) {
|
|
|
|
mem->alloc = llarp::std_malloc;
|
|
|
|
mem->free = llarp::std_free;
|
2018-01-29 14:27:24 +00:00
|
|
|
}
|
2017-10-03 19:14:46 +00:00
|
|
|
}
|