/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_malloc.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: thrieg < thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/11/17 15:06:51 by thrieg #+# #+# */ /* Updated: 2025/12/08 15:32:10 by thrieg ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_MALLOC_H #define FT_MALLOC_H #include #include #include #include #include #include #include #include "../libft/ft_hashmap.h" #include "../libft/ft_vector.h" #include "ft_malloc_public.h" #define TINY_SIZE_MAX 64 #define SMALL_SIZE_MAX 4096 #define ALLIGN_BYTES _Alignof(max_align_t) typedef enum e_type { E_TINY, E_SMALL, E_LARGE } t_type; typedef struct s_zone { t_type type; size_t size; struct s_zone *next; // lock g_mut struct s_zone *prev; // lock g_mut } t_zone; typedef struct s_header { size_t size; // lock bool occupied; // lock t_zone *zone; char padding[8]; } t_header; typedef struct s_state { t_zone *tiny_zone; // lock g_mut t_zone *small_zone; // lock g_mut t_zone *large_zone; // lock g_mut, 1 zone per alloc for large unsigned char patern; // patern set in MALLOC_PERTURB_ environment variable (lock g_mut) bool is_init; } t_state; extern t_state g_state; extern pthread_mutex_t g_mut; // never lock this inside a zone mut, only the opposite void *add_large(size_t size); void *add_small(size_t size); void *add_tiny(size_t size); void *add_page(t_type type); void init_env_variables(); #endif