added support for MALLOC_PERTURB_ environment variable

This commit is contained in:
Thomas Rieg 2025-12-08 15:48:24 +01:00
parent 0fd85cf568
commit 6d84b2f72a
17 changed files with 453 additions and 404 deletions

View file

@ -6,14 +6,27 @@
/* By: thrieg < thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/18 16:44:13 by thrieg #+# #+# */
/* Updated: 2025/11/28 16:41:55 by thrieg ### ########.fr */
/* Updated: 2025/12/08 15:32:55 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/ft_malloc.h"
pthread_mutex_t g_mut = PTHREAD_MUTEX_INITIALIZER;
t_state g_state = {.tiny_zone = NULL, .small_zone = NULL, .large_zone = NULL};
t_state g_state = {.tiny_zone = NULL, .small_zone = NULL, .large_zone = NULL, .patern = 0, .is_init = false};
void init_env_variables()
{
char *env = getenv("MALLOC_PERTURB_"); // this doesn't call malloc, returns a pointer from **environ
if (env)
{
int overflow = 0;
int v = ft_atoi(env, &overflow);
if (!overflow && v > 0 && v <= 255)
g_state.patern = (unsigned char)v;
}
g_state.is_init = true;
}
// only call this for TINY or SMALL
void *add_page(t_type type)