Put the custom allocator in its own lib, as to lessen the difficulty to switch between libc's allocator and a custom one (#7)

This commit is contained in:
Maix0 2024-05-14 18:56:53 +02:00 committed by GitHub
parent 713f0f0302
commit cb7f3c3fdf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
85 changed files with 1121 additions and 877 deletions

View file

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* valgrind_block.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/12 22:51:55 by maiboyer #+# #+# */
/* Updated: 2024/05/12 22:55:45 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "aq/internal_vg_funcs.h"
#include "valgrind/valgrind.h"
#ifdef VGFUNCS
void vg_block_malloc(void *ptr, t_usize size)
{
VALGRIND_MALLOCLIKE_BLOCK(ptr, size, redzone_size(), ZEROED_ALLOC);
}
void vg_block_resize(void *ptr, t_usize oldsize, t_usize newsize)
{
VALGRIND_RESIZEINPLACE_BLOCK(ptr, oldsize, newsize, redzone_size());
}
void vg_block_free(void *ptr)
{
VALGRIND_FREELIKE_BLOCK(ptr, redzone_size());
}
#endif

View file

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* valgrind_mem_status.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/12 23:08:47 by maiboyer #+# #+# */
/* Updated: 2024/05/12 23:22:08 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "aq/internal_vg_funcs.h"
#ifdef VGFUNCS
void vg_mem_no_access(void *ptr, t_usize size)
{
VALGRIND_MAKE_MEM_NOACCESS(ptr, size);
}
void vg_mem_undefined(void *ptr, t_usize size)
{
VALGRIND_MAKE_MEM_UNDEFINED(ptr, size);
}
void vg_mem_defined(void *ptr, t_usize size)
{
VALGRIND_MAKE_MEM_DEFINED(ptr, size);
}
#endif

View file

@ -0,0 +1,58 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* valgrind_mempool.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/12 22:33:30 by maiboyer #+# #+# */
/* Updated: 2024/05/14 16:17:37 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "aq/internal_vg_funcs.h"
#include "valgrind/valgrind.h"
#ifdef VGFUNCS
void vg_mempool_create_ext(void *pool, t_usize flags)
{
t_usize actual_flags;
actual_flags = 0;
if (flags & MEMPOOL_FLAG_MALLOCLIKE)
actual_flags |= VALGRIND_MEMPOOL_METAPOOL;
if (flags & MEMPOOL_FLAG_AUTOFREE)
actual_flags |= VALGRIND_MEMPOOL_AUTO_FREE;
VALGRIND_CREATE_MEMPOOL_EXT(pool, redzone_size(), ZEROED_POOL,
actual_flags);
}
void vg_mempool_resize(void *pool, void *ptr, t_usize size)
{
VALGRIND_MEMPOOL_CHANGE(pool, ptr, ptr, size);
}
void vg_mempool_create(void *pool)
{
VALGRIND_CREATE_MEMPOOL(pool, redzone_size(), ZEROED_POOL);
}
void vg_mempool_destroy(void *pool)
{
VALGRIND_DESTROY_MEMPOOL(pool);
}
void vg_mempool_alloc(void *pool, void *addr, t_usize size)
{
VALGRIND_CREATE_BLOCK(addr, size, "mempool");
VALGRIND_MEMPOOL_ALLOC(pool, addr, size);
}
void vg_mempool_free(void *pool, void *addr)
{
VALGRIND_MEMPOOL_FREE(pool, addr);
}
#endif