Allocator V1.0
* Allocator Version 1.0
This commit is contained in:
parent
04691819f7
commit
5d2202a0c9
20 changed files with 609 additions and 74 deletions
|
|
@ -6,7 +6,7 @@
|
|||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
||||
# Updated: 2024/05/14 18:44:53 by maiboyer ### ########.fr #
|
||||
# Updated: 2024/05/16 16:06:36 by maiboyer ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ NAME = libaq.a
|
|||
LIB_NAME ?=
|
||||
TARGET = $(BUILD_DIR)/$(NAME)
|
||||
CC ?= clang
|
||||
CFLAGS = -Wno-unused-command-line-argument -Wall -Werror -Wextra -g3 -L$(BUILD_DIR) -MMD -rdynamic -DBASE_PATH='"$(BASE_PATH)/"'
|
||||
CFLAGS = -Wno-unused-command-line-argument -Wall -Werror -Wextra -g3 -L$(BUILD_DIR) -MMD -rdynamic -DBASE_PATH='"$(BASE_PATH)/"' -O0
|
||||
# CFLAGS += -fsanitize=address -fno-omit-frame-pointer -fsanitize-address-use-after-return=runtime -fno-common -fsanitize-address-use-after-scope
|
||||
BONUS_FILES =
|
||||
LIBS_NAME =
|
||||
|
|
@ -55,7 +55,6 @@ $(NAME): $(TARGET)
|
|||
|
||||
$(TARGET): $(OBJ)
|
||||
@echo -e '$(COL_GRAY) Linking\t$(COL_GREEN)$(TARGET)$(COL_RESET)'
|
||||
@#$(CC) $(INCLUDES) $(OBJ) $(CFLAGS) -o $(NAME)
|
||||
@ar rcs $(BUILD_DIR)/$(NAME) $(OBJ)
|
||||
|
||||
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
|
||||
|
|
|
|||
|
|
@ -6,15 +6,13 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/12 22:20:30 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/14 16:17:25 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/17 15:34:26 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef INTERNAL_VG_FUNCS_H
|
||||
#define INTERNAL_VG_FUNCS_H
|
||||
|
||||
#include "aq/alloc_internal.h"
|
||||
|
||||
#include "me/types.h"
|
||||
#if !defined(NVALGRIND) || defined(VGHEADER)
|
||||
# ifdef NVALGRIND
|
||||
|
|
@ -30,7 +28,7 @@
|
|||
|
||||
static inline t_usize redzone_size(void)
|
||||
{
|
||||
return (sizeof(t_mblock));
|
||||
return (8);
|
||||
}
|
||||
|
||||
#ifdef VGFUNCS
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/14 17:54:03 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/14 18:08:16 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/16 15:43:00 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -23,4 +23,6 @@ void *m_realloc_array(t_allocator *self, void *ptr, t_usize size,
|
|||
void m_free(t_allocator *self, void *ptr);
|
||||
void m_uninit(t_allocator *self);
|
||||
|
||||
t_allocator m_init(void);
|
||||
|
||||
#endif /* MELLOC_H */
|
||||
|
|
|
|||
64
allocator/include/aq/melloc_interal.h
Normal file
64
allocator/include/aq/melloc_interal.h
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* melloc_interal.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/15 15:27:46 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/16 14:58:27 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MELLOC_INTERAL_H
|
||||
#define MELLOC_INTERAL_H
|
||||
|
||||
#include "aq/allocator.h"
|
||||
#include "me/types.h"
|
||||
|
||||
#define PAGE_LIST_MAX 255
|
||||
#define PAGE_POW_2 12
|
||||
#define PAGE_ALIGN 3
|
||||
|
||||
typedef struct s_chunk
|
||||
{
|
||||
bool used : 1;
|
||||
t_u64 size : 63;
|
||||
} t_chunk;
|
||||
|
||||
typedef struct s_page
|
||||
{
|
||||
t_usize size;
|
||||
void *data;
|
||||
} t_page;
|
||||
|
||||
typedef struct s_page_list
|
||||
{
|
||||
t_usize len;
|
||||
t_page pages[PAGE_LIST_MAX];
|
||||
struct s_page_list *next;
|
||||
} t_page_list;
|
||||
|
||||
struct s_allocator_melloc
|
||||
{
|
||||
t_allocator_alloc alloc;
|
||||
t_allocator_alloc_array alloc_array;
|
||||
t_allocator_realloc realloc;
|
||||
t_allocator_realloc_array realloc_array;
|
||||
t_allocator_free free;
|
||||
t_allocator_uninit uninit;
|
||||
t_page_list *list;
|
||||
};
|
||||
|
||||
t_error alloc_page_list(t_page_list **out);
|
||||
|
||||
void *m_malloc(struct s_allocator_melloc *self, t_usize size);
|
||||
void *m_alloc_array(struct s_allocator_melloc *self, t_usize size,
|
||||
t_usize count);
|
||||
void *m_realloc(struct s_allocator_melloc *self, void *ptr, t_usize min_size);
|
||||
void *m_realloc_array(struct s_allocator_melloc *self, void *ptr, t_usize size,
|
||||
t_usize count);
|
||||
void m_free(struct s_allocator_melloc *self, void *ptr);
|
||||
void m_uninit(struct s_allocator_melloc *self);
|
||||
|
||||
#endif /* MELLOC_INTERAL_H */
|
||||
|
|
@ -4,6 +4,9 @@ lc_alloc/functions1
|
|||
lc_alloc/functions2
|
||||
me_alloc/functions1
|
||||
me_alloc/functions2
|
||||
vg/dummy_block
|
||||
vg/dummy_mempool
|
||||
vg/dummy_mem_status
|
||||
vg/valgrind_block
|
||||
vg/valgrind_mempool
|
||||
vg/valgrind_mem_status
|
||||
|
|
|
|||
|
|
@ -6,47 +6,375 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/14 18:02:12 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/14 18:21:16 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/17 15:21:57 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "aq/allocator.h"
|
||||
#include "aq/libc_wrapper.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/types.h"
|
||||
|
||||
// void *__libc_malloc(t_usize size);
|
||||
// void *__libc_calloc(t_usize size, t_usize elem);
|
||||
// void *__libc_realloc(void *ptr, t_usize size);
|
||||
// void *__libc_realloc_array(void *ptr, t_usize size, t_usize elem);
|
||||
// void __libc_free(void *ptr);
|
||||
//
|
||||
// void *lc_malloc(t_allocator *self, t_usize size)
|
||||
// {
|
||||
// (void)(self);
|
||||
// return (__libc_malloc(size));
|
||||
// }
|
||||
//
|
||||
// void *lc_calloc(t_allocator *self, t_usize size, t_usize elem)
|
||||
// {
|
||||
// (void)(self);
|
||||
// return (__libc_calloc(size, elem));
|
||||
// }
|
||||
//
|
||||
// void *lc_realloc(t_allocator *self, void *ptr, t_usize size)
|
||||
// {
|
||||
// (void)(self);
|
||||
// return (__libc_realloc(ptr, size));
|
||||
// }
|
||||
//
|
||||
// void *lc_realloc_array(t_allocator *self, void *ptr, t_usize size, t_usize elem)
|
||||
// {
|
||||
// (void)(self);
|
||||
// return (__libc_realloc_array(ptr, size, elem));
|
||||
// }
|
||||
//
|
||||
// void lc_free(t_allocator *self, void *ptr)
|
||||
// {
|
||||
// (void)(self);
|
||||
// return (__libc_free(ptr));
|
||||
// }
|
||||
#include "aq/allocator.h"
|
||||
#include "aq/internal_vg_funcs.h"
|
||||
#include "aq/melloc_interal.h"
|
||||
#include "valgrind/valgrind.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
|
||||
|
||||
void *__libc_malloc(t_usize size);
|
||||
void *__libc_calloc(t_usize size, t_usize elem);
|
||||
void *__libc_realloc(void *ptr, t_usize size);
|
||||
void *__libc_realloc_array(void *ptr, t_usize size, t_usize elem);
|
||||
void __libc_free(void *ptr);
|
||||
|
||||
t_chunk *get_first_block(t_page *page)
|
||||
{
|
||||
t_chunk *chunk;
|
||||
if (page == NULL)
|
||||
return (NULL);
|
||||
vg_mem_defined(page, sizeof(*page));
|
||||
chunk = page->data;
|
||||
vg_mem_no_access(page, sizeof(*page));
|
||||
return (chunk);
|
||||
}
|
||||
|
||||
t_chunk *get_next_block(t_chunk *chunk, bool find_zero)
|
||||
{
|
||||
t_chunk *next;
|
||||
|
||||
if (chunk == NULL)
|
||||
return (NULL);
|
||||
vg_mem_defined(chunk, sizeof(*chunk));
|
||||
next = (void *)(chunk) + sizeof(*chunk) + chunk->size;
|
||||
vg_mem_no_access(chunk, sizeof(*chunk));
|
||||
vg_mem_defined(next, sizeof(*next));
|
||||
if (!find_zero && next->size == 0)
|
||||
{
|
||||
vg_mem_no_access(next, sizeof(*next));
|
||||
return (NULL);
|
||||
}
|
||||
vg_mem_no_access(next, sizeof(*next));
|
||||
return (next);
|
||||
}
|
||||
|
||||
t_usize round_to_pow2(t_usize val, t_usize pow)
|
||||
{
|
||||
pow = (1 << pow) - 1;
|
||||
|
||||
return ((val + pow) & (~pow));
|
||||
}
|
||||
|
||||
t_error alloc_page_list(t_page_list **out)
|
||||
{
|
||||
t_page_list *val;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
val = __libc_calloc(sizeof(*val), 1);
|
||||
if (val == NULL)
|
||||
return (ERROR);
|
||||
*out = val;
|
||||
vg_mem_no_access(val, sizeof(*val));
|
||||
vg_mempool_create_ext(val, MEMPOOL_FLAG_MALLOCLIKE);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
void merge_blocks(t_page *page)
|
||||
{
|
||||
t_chunk *cur;
|
||||
t_chunk *next;
|
||||
bool did_merge;
|
||||
|
||||
did_merge = true;
|
||||
while (did_merge)
|
||||
{
|
||||
cur = get_first_block(page);
|
||||
next = get_next_block(cur, false);
|
||||
did_merge = false;
|
||||
while (cur != NULL && next != NULL)
|
||||
{
|
||||
(vg_mem_defined(cur, sizeof(*cur)),
|
||||
vg_mem_defined(next, sizeof(*next)));
|
||||
if (!cur->used && !next->used)
|
||||
{
|
||||
did_merge = true;
|
||||
cur->size += sizeof(*cur);
|
||||
cur->size += next->size;
|
||||
(vg_mem_no_access(cur, sizeof(*cur)),
|
||||
vg_mem_no_access(next, sizeof(*next)));
|
||||
next = get_next_block(cur, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
(vg_mem_no_access(cur, sizeof(*cur)),
|
||||
vg_mem_no_access(next, sizeof(*next)));
|
||||
cur = next;
|
||||
next = get_next_block(cur, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
t_chunk *split_block(t_chunk *chunk, t_usize size)
|
||||
{
|
||||
t_usize remaining;
|
||||
t_chunk *next;
|
||||
t_chunk *ac_next;
|
||||
|
||||
if (chunk == NULL)
|
||||
return (NULL);
|
||||
vg_mem_defined(chunk, sizeof(*chunk));
|
||||
if (chunk->size > size + sizeof(*chunk) + (2 << PAGE_ALIGN))
|
||||
{
|
||||
remaining = chunk->size - size - sizeof(*chunk);
|
||||
next = get_next_block(chunk, true);
|
||||
vg_mem_defined(chunk, sizeof(*chunk));
|
||||
// eprintf("before size = %zu\n", (t_usize)chunk->size);
|
||||
chunk->size = size;
|
||||
// eprintf("after size = %zu\n", (t_usize)chunk->size);
|
||||
ac_next = get_next_block(chunk, true);
|
||||
// eprintf("chunk = %p\n", chunk);
|
||||
// eprintf("next = %p\n", next);
|
||||
// eprintf("ac_next = %p\n", ac_next);
|
||||
// eprintf("get_next_block(ac_next, true) = %p\n",
|
||||
// get_next_block(ac_next, true));
|
||||
vg_mem_defined(ac_next, sizeof(*ac_next));
|
||||
ac_next->used = false;
|
||||
ac_next->size = remaining;
|
||||
assert(next == get_next_block(ac_next, true));
|
||||
vg_mem_no_access(ac_next, sizeof(*ac_next));
|
||||
}
|
||||
vg_mem_no_access(chunk, sizeof(*chunk));
|
||||
return (chunk);
|
||||
}
|
||||
|
||||
t_chunk *find_chunk_of_size(struct s_allocator_melloc *alloc, t_usize size)
|
||||
{
|
||||
t_page_list *list;
|
||||
t_page_list *list_next;
|
||||
t_usize idx;
|
||||
t_chunk *chunk;
|
||||
|
||||
list = alloc->list;
|
||||
while (list != NULL)
|
||||
{
|
||||
vg_mem_defined(list, sizeof(*list));
|
||||
idx = 0;
|
||||
while (idx < list->len)
|
||||
{
|
||||
// printf("[%zu]list\n", idx);
|
||||
chunk = get_first_block(&list->pages[idx++]);
|
||||
while (chunk)
|
||||
{
|
||||
vg_mem_defined(chunk, sizeof(*chunk));
|
||||
if (!chunk->used && chunk->size >= size)
|
||||
{
|
||||
vg_mem_no_access(chunk, sizeof(*chunk));
|
||||
vg_mem_no_access(list, sizeof(*list));
|
||||
return (split_block(chunk, size));
|
||||
}
|
||||
vg_mem_no_access(chunk, sizeof(*chunk));
|
||||
chunk = get_next_block(chunk, false);
|
||||
}
|
||||
}
|
||||
list_next = list->next;
|
||||
vg_mem_no_access(list, sizeof(*list));
|
||||
list = list_next;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
t_error alloc_new_page(struct s_allocator_melloc *alloc, t_usize page_size)
|
||||
{
|
||||
t_page_list *list;
|
||||
t_page_list *list_bis;
|
||||
t_chunk *chunk;
|
||||
|
||||
page_size = round_to_pow2(page_size, PAGE_POW_2);
|
||||
if (alloc->list == NULL && alloc_page_list(&alloc->list))
|
||||
return (eprintf("Oups\n"), ERROR);
|
||||
list = alloc->list;
|
||||
while (list)
|
||||
{
|
||||
vg_mem_defined(list, sizeof(*list));
|
||||
if (list->len != PAGE_LIST_MAX)
|
||||
break;
|
||||
if (list->next == NULL && alloc_page_list(&list->next))
|
||||
return (vg_mem_no_access(list, sizeof(*list)), ERROR);
|
||||
list_bis = list;
|
||||
list = list->next;
|
||||
vg_mem_no_access(list_bis, sizeof(*list_bis));
|
||||
}
|
||||
if (list == NULL)
|
||||
return (ERROR);
|
||||
vg_mem_defined(list, sizeof(*list));
|
||||
list->pages[list->len].data = __libc_calloc(page_size, 1);
|
||||
if (list->pages[list->len].data == NULL)
|
||||
return (ERROR);
|
||||
list->pages[list->len].size = page_size;
|
||||
|
||||
// eprintf("thingy!\n");
|
||||
// eprintf("(%p)pool_exist = %s\n", list,
|
||||
// VALGRIND_MEMPOOL_EXISTS(list) ? "true" : "false");
|
||||
vg_mempool_alloc(list, list->pages[list->len].data, page_size);
|
||||
chunk = get_first_block(&list->pages[list->len]);
|
||||
chunk->used = false;
|
||||
chunk->size = page_size - sizeof(*chunk) * 2;
|
||||
vg_mem_no_access(chunk, sizeof(*chunk));
|
||||
list->len++;
|
||||
vg_mem_no_access(list, sizeof(*list));
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
void *m_alloc_error(struct s_allocator_melloc *self, t_str msg)
|
||||
{
|
||||
(void)(self);
|
||||
me_abort(msg);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
void *m_malloc(struct s_allocator_melloc *self, t_usize size)
|
||||
{
|
||||
return (m_realloc(self, NULL, size));
|
||||
}
|
||||
|
||||
void *m_alloc_array(struct s_allocator_melloc *self, t_usize size,
|
||||
t_usize count)
|
||||
{
|
||||
if (size != 0 && count > SIZE_MAX / size)
|
||||
return (m_alloc_error(self, "Alloc array overflow"));
|
||||
return (m_realloc(self, NULL, size * count));
|
||||
}
|
||||
|
||||
void *m_realloc(struct s_allocator_melloc *self, void *ptr, t_usize size)
|
||||
{
|
||||
t_chunk *chunk;
|
||||
t_chunk *next;
|
||||
t_usize old_size;
|
||||
|
||||
// eprintf("M_REALLOC\n");
|
||||
// if (self->list == NULL && alloc_page_list(&self->list))
|
||||
// return (m_alloc_error(self, "Unable to alloc page list"));
|
||||
size = round_to_pow2(size, PAGE_ALIGN);
|
||||
if (ptr == NULL)
|
||||
{
|
||||
chunk = find_chunk_of_size(self, size);
|
||||
if (chunk == NULL)
|
||||
{
|
||||
if (alloc_new_page(self, size + sizeof(t_chunk) * 2))
|
||||
return (m_alloc_error(self, "Unable to alloc page"));
|
||||
chunk = find_chunk_of_size(self, size);
|
||||
if (chunk == NULL)
|
||||
return (m_alloc_error(self, "Unable to find block"));
|
||||
}
|
||||
vg_mem_defined((void *)chunk, sizeof(*chunk));
|
||||
chunk->used = true;
|
||||
vg_mem_defined((void *)chunk + sizeof(*chunk), chunk->size);
|
||||
mem_set_zero((void *)chunk + sizeof(*chunk), chunk->size);
|
||||
vg_block_malloc((void *)chunk + sizeof(*chunk), chunk->size);
|
||||
vg_mem_no_access((void *)chunk, sizeof(*chunk));
|
||||
return ((void *)chunk + sizeof(*chunk));
|
||||
}
|
||||
else
|
||||
{
|
||||
chunk = ptr - sizeof(*chunk);
|
||||
vg_mem_defined(chunk, sizeof(*chunk));
|
||||
if (chunk->size >= size)
|
||||
return (vg_mem_no_access(chunk, sizeof(*chunk)), ptr);
|
||||
next = get_next_block(chunk, false);
|
||||
vg_mem_defined(next, sizeof(*next));
|
||||
vg_mem_defined(chunk, sizeof(*chunk));
|
||||
if (next != NULL && !next->used &&
|
||||
chunk->size + next->size + sizeof(*next) >= size)
|
||||
{
|
||||
old_size = chunk->size;
|
||||
chunk->size += next->size + sizeof(*next);
|
||||
vg_mem_defined(next, next->size + sizeof(*next));
|
||||
mem_set_zero(next, next->size + sizeof(*next));
|
||||
vg_block_resize((void *)chunk + sizeof(*chunk), old_size,
|
||||
chunk->size);
|
||||
vg_mem_no_access(chunk, sizeof(*chunk));
|
||||
return (ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
vg_mem_no_access(next, sizeof(*next));
|
||||
next = m_realloc(self, NULL, size);
|
||||
vg_mem_defined(chunk, sizeof(*chunk));
|
||||
mem_copy(ptr, next, chunk->size);
|
||||
vg_mem_no_access(chunk, sizeof(*chunk));
|
||||
m_free(self, ptr);
|
||||
return (next);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void *m_realloc_array(struct s_allocator_melloc *self, void *ptr, t_usize size,
|
||||
t_usize count)
|
||||
{
|
||||
if (size != 0 && count > SIZE_MAX / size)
|
||||
return (m_alloc_error(self, "Realloc array overflow"));
|
||||
return (m_realloc(self, ptr, size * count));
|
||||
}
|
||||
|
||||
void m_free(struct s_allocator_melloc *self, void *ptr)
|
||||
{
|
||||
t_chunk *chunk;
|
||||
|
||||
(void)(self);
|
||||
if (ptr == NULL)
|
||||
return;
|
||||
vg_block_free(ptr);
|
||||
chunk = ptr - sizeof(*chunk);
|
||||
vg_mem_defined(chunk, sizeof(*chunk));
|
||||
chunk->used = false;
|
||||
vg_mem_no_access(chunk, sizeof(*chunk));
|
||||
}
|
||||
|
||||
void m_uninit(struct s_allocator_melloc *self)
|
||||
{
|
||||
t_page_list *list;
|
||||
t_page_list *list_next;
|
||||
t_usize idx;
|
||||
|
||||
list = self->list;
|
||||
while (list)
|
||||
{
|
||||
vg_mem_defined(list, sizeof(*list));
|
||||
idx = 0;
|
||||
while (idx < list->len)
|
||||
{
|
||||
if (list->pages[idx].data != NULL)
|
||||
{
|
||||
vg_mempool_free(list, list->pages[idx].data);
|
||||
__libc_free(list->pages[idx].data);
|
||||
list->pages[idx].size = 0;
|
||||
list->pages[idx].data = NULL;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
list_next = list->next;
|
||||
__libc_free(list);
|
||||
vg_mempool_destroy(list);
|
||||
vg_mem_no_access(list, sizeof(*list));
|
||||
list = list_next;
|
||||
}
|
||||
}
|
||||
|
||||
t_allocator m_init(void)
|
||||
{
|
||||
t_allocator out;
|
||||
|
||||
out.free = (t_allocator_free)m_free;
|
||||
out.alloc = (t_allocator_alloc)m_malloc;
|
||||
out.alloc_array = (t_allocator_alloc_array)m_alloc_array;
|
||||
out.realloc = (t_allocator_realloc)m_realloc;
|
||||
out.realloc_array = (t_allocator_realloc_array)m_realloc_array;
|
||||
out.uninit = (t_allocator_uninit)m_uninit;
|
||||
out.alloc_data = NULL;
|
||||
return (out);
|
||||
}
|
||||
|
|
|
|||
35
allocator/src/vg/dummy_block.c
Normal file
35
allocator/src/vg/dummy_block.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* dummy_block.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/12 22:51:55 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/17 15:28:09 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "aq/internal_vg_funcs.h"
|
||||
|
||||
#ifndef VGFUNCS
|
||||
|
||||
void vg_block_malloc(void *ptr, t_usize size)
|
||||
{
|
||||
(void)(ptr);
|
||||
(void)(size);
|
||||
}
|
||||
|
||||
void vg_block_resize(void *ptr, t_usize oldsize, t_usize newsize)
|
||||
{
|
||||
(void)(ptr);
|
||||
(void)(oldsize);
|
||||
(void)(newsize);
|
||||
}
|
||||
|
||||
void vg_block_free(void *ptr)
|
||||
{
|
||||
(void)(ptr);
|
||||
}
|
||||
|
||||
#endif
|
||||
35
allocator/src/vg/dummy_mem_status.c
Normal file
35
allocator/src/vg/dummy_mem_status.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* dummy_mem_status.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/12 23:08:47 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/17 15:28:52 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "aq/internal_vg_funcs.h"
|
||||
|
||||
#ifndef VGFUNCS
|
||||
|
||||
void vg_mem_no_access(void *ptr, t_usize size)
|
||||
{
|
||||
(void)(ptr);
|
||||
(void)(size);
|
||||
}
|
||||
|
||||
void vg_mem_undefined(void *ptr, t_usize size)
|
||||
{
|
||||
(void)(ptr);
|
||||
(void)(size);
|
||||
}
|
||||
|
||||
void vg_mem_defined(void *ptr, t_usize size)
|
||||
{
|
||||
(void)(ptr);
|
||||
(void)(size);
|
||||
}
|
||||
|
||||
#endif
|
||||
53
allocator/src/vg/dummy_mempool.c
Normal file
53
allocator/src/vg/dummy_mempool.c
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* dummy_mempool.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/12 22:33:30 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/17 15:29:59 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "aq/internal_vg_funcs.h"
|
||||
|
||||
#ifndef VGFUNCS
|
||||
|
||||
void vg_mempool_create_ext(void *pool, t_usize flags)
|
||||
{
|
||||
(void)(pool);
|
||||
(void)(flags);
|
||||
}
|
||||
|
||||
void vg_mempool_resize(void *pool, void *ptr, t_usize size)
|
||||
{
|
||||
(void)(pool);
|
||||
(void)(ptr);
|
||||
(void)(size);
|
||||
}
|
||||
|
||||
void vg_mempool_create(void *pool)
|
||||
{
|
||||
(void)(pool);
|
||||
}
|
||||
|
||||
void vg_mempool_destroy(void *pool)
|
||||
{
|
||||
(void)(pool);
|
||||
}
|
||||
|
||||
void vg_mempool_alloc(void *pool, void *addr, t_usize size)
|
||||
{
|
||||
(void)(pool);
|
||||
(void)(addr);
|
||||
(void)(size);
|
||||
}
|
||||
|
||||
void vg_mempool_free(void *pool, void *addr)
|
||||
{
|
||||
(void)(pool);
|
||||
(void)(addr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* 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 */
|
||||
/* Updated: 2024/05/17 15:30:09 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -25,8 +25,7 @@ void vg_mempool_create_ext(void *pool, t_usize flags)
|
|||
if (flags & MEMPOOL_FLAG_AUTOFREE)
|
||||
actual_flags |= VALGRIND_MEMPOOL_AUTO_FREE;
|
||||
|
||||
VALGRIND_CREATE_MEMPOOL_EXT(pool, redzone_size(), ZEROED_POOL,
|
||||
actual_flags);
|
||||
VALGRIND_CREATE_MEMPOOL_EXT(pool, 0, ZEROED_POOL, actual_flags);
|
||||
}
|
||||
|
||||
void vg_mempool_resize(void *pool, void *ptr, t_usize size)
|
||||
|
|
@ -36,7 +35,8 @@ void vg_mempool_resize(void *pool, void *ptr, t_usize size)
|
|||
|
||||
void vg_mempool_create(void *pool)
|
||||
{
|
||||
VALGRIND_CREATE_MEMPOOL(pool, redzone_size(), ZEROED_POOL);
|
||||
VALGRIND_CREATE_MEMPOOL(pool, 0, ZEROED_POOL);
|
||||
|
||||
}
|
||||
|
||||
void vg_mempool_destroy(void *pool)
|
||||
|
|
@ -46,7 +46,6 @@ void vg_mempool_destroy(void *pool)
|
|||
|
||||
void vg_mempool_alloc(void *pool, void *addr, t_usize size)
|
||||
{
|
||||
VALGRIND_CREATE_BLOCK(addr, size, "mempool");
|
||||
VALGRIND_MEMPOOL_ALLOC(pool, addr, size);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue