wip fuck it
This commit is contained in:
parent
746a1ad2ad
commit
3937b70957
7 changed files with 120 additions and 177 deletions
|
|
@ -39,7 +39,7 @@
|
||||||
#define STACK_VERSION_NONE ((t_stack_version)-1)
|
#define STACK_VERSION_NONE ((t_stack_version)-1)
|
||||||
#define TS_DECODE_ERROR (-1)
|
#define TS_DECODE_ERROR (-1)
|
||||||
|
|
||||||
#if 1 == 1
|
#if false
|
||||||
# undef malloc
|
# undef malloc
|
||||||
# undef calloc
|
# undef calloc
|
||||||
# undef realloc
|
# undef realloc
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/07 09:48:17 by maiboyer #+# #+# */
|
/* Created: 2024/05/07 09:48:17 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/05/08 19:15:05 by maiboyer ### ########.fr */
|
/* Updated: 2024/05/09 13:30:12 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,31 +17,33 @@
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
#include <stdalign.h>
|
#include <stdalign.h>
|
||||||
|
|
||||||
#define ARENA_SIZE_DEFAULT 4096 * 2 * 2
|
#define PAGE_SIZE_DEFAULT 4096 * 4
|
||||||
|
#define BLOCK_PADDING "\xFE\xDC\xAB\xC0\xFE\xEE"
|
||||||
|
|
||||||
typedef struct s_arena_block
|
typedef struct s_mblock
|
||||||
{
|
{
|
||||||
|
struct s_mblock *next;
|
||||||
|
struct s_mpage *page;
|
||||||
t_usize size;
|
t_usize size;
|
||||||
bool end;
|
|
||||||
bool used;
|
bool used;
|
||||||
t_u8 padding[6];
|
t_u8 padding[7];
|
||||||
} t_arena_block;
|
} t_mblock;
|
||||||
|
|
||||||
typedef struct s_arena_page
|
typedef struct s_mpage
|
||||||
{
|
{
|
||||||
t_usize page_size;
|
t_usize page_size;
|
||||||
struct s_arena_page *next;
|
t_mblock *first;
|
||||||
} t_arena_page;
|
struct s_mpage *next;
|
||||||
|
} t_mpage;
|
||||||
|
|
||||||
// Will never be null, as it will allocate a new arena if it needs to do so
|
// Will never be null, as it will allocate a new arena if it needs to do so
|
||||||
t_arena_page *get_head_arena(void);
|
t_mpage *get_head_arena(void);
|
||||||
|
|
||||||
// Will return ERROR if it couldn't malloc the page
|
// Will return ERROR if it couldn't malloc the page
|
||||||
t_error alloc_arena_page(t_usize min_size, t_arena_page **out);
|
t_error alloc_arena_page(t_usize min_size, t_mpage **out);
|
||||||
|
|
||||||
t_error get_block_for_page(t_usize size, t_arena_page *page,
|
t_mblock *get_block_for_size(t_usize size);
|
||||||
t_arena_block **out);
|
|
||||||
void print_pages_info(void);
|
void print_pages_info(void);
|
||||||
t_arena_page *get_page_from_ptr(void *ptr);
|
t_mpage *get_page_from_ptr(void *ptr);
|
||||||
|
|
||||||
#endif /* ALLOC_INTERNAL_H */
|
#endif /* ALLOC_INTERNAL_H */
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/07 10:13:06 by maiboyer #+# #+# */
|
/* Created: 2024/05/07 10:13:06 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/05/08 19:37:39 by maiboyer ### ########.fr */
|
/* Updated: 2024/05/09 17:57:54 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -22,60 +22,16 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
t_arena_page *find_page_for(t_usize data_size, t_arena_page *page)
|
|
||||||
{
|
|
||||||
t_arena_block *block;
|
|
||||||
t_arena_page *last_page;
|
|
||||||
|
|
||||||
last_page = NULL;
|
|
||||||
while (page != NULL)
|
|
||||||
{
|
|
||||||
if (page->page_size <= data_size + sizeof(t_arena_block))
|
|
||||||
{
|
|
||||||
if (page->next == NULL &&
|
|
||||||
alloc_arena_page(usize_round_up_to(data_size + sizeof(*block),
|
|
||||||
ARENA_SIZE_DEFAULT),
|
|
||||||
&page->next))
|
|
||||||
return (me_abort("Failed Malloc"), NULL);
|
|
||||||
last_page = page;
|
|
||||||
page = page->next;
|
|
||||||
}
|
|
||||||
block = (t_arena_block *)(&page[1]);
|
|
||||||
while (block)
|
|
||||||
{
|
|
||||||
if ((t_u8 *)block >= (t_u8 *)page + sizeof(*page) + page->page_size)
|
|
||||||
break;
|
|
||||||
if (!block->used && block->size >= data_size)
|
|
||||||
return (page);
|
|
||||||
block = (void *)((t_u8 *)block + block->size + sizeof(*block));
|
|
||||||
}
|
|
||||||
last_page = page;
|
|
||||||
page = page->next;
|
|
||||||
}
|
|
||||||
if (last_page != NULL)
|
|
||||||
{
|
|
||||||
if (alloc_arena_page(usize_round_up_to(data_size + sizeof(*block),
|
|
||||||
ARENA_SIZE_DEFAULT),
|
|
||||||
&last_page->next))
|
|
||||||
return (me_abort("Failed Malloc"), NULL);
|
|
||||||
return (last_page->next);
|
|
||||||
}
|
|
||||||
return ((me_abort("Found no pages for memory"), NULL));
|
|
||||||
}
|
|
||||||
|
|
||||||
// the is twice the size of size_t, only to stay aligned on a 16 byte
|
|
||||||
// alignement
|
|
||||||
void *me_malloc(t_usize size)
|
void *me_malloc(t_usize size)
|
||||||
{
|
{
|
||||||
t_arena_page *arena;
|
t_mblock *block;
|
||||||
t_arena_block *block;
|
|
||||||
|
|
||||||
size = usize_round_up_to(size, 16);
|
size = usize_round_up_to(size, 16);
|
||||||
arena = find_page_for(size, get_head_arena());
|
block = get_block_for_size(size);
|
||||||
if (get_block_for_page(size, arena, &block))
|
if (block == NULL)
|
||||||
return (me_abort("Found no page for me_malloc"), NULL);
|
return (me_abort("Found no page for me_malloc"), NULL);
|
||||||
block->used = true;
|
block->used = true;
|
||||||
return ((t_u8 *)block + sizeof(*block));
|
return ((void *)(((t_usize)block) + sizeof(t_mblock)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void *me_calloc(t_usize elem_size, t_usize elem_count)
|
void *me_calloc(t_usize elem_size, t_usize elem_count)
|
||||||
|
|
@ -87,16 +43,15 @@ void *me_calloc(t_usize elem_size, t_usize elem_count)
|
||||||
|
|
||||||
void *me_realloc(void *ptr, t_usize new_size)
|
void *me_realloc(void *ptr, t_usize new_size)
|
||||||
{
|
{
|
||||||
t_arena_block *block;
|
t_mblock *block;
|
||||||
void *ret;
|
void *ret;
|
||||||
|
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
return (me_malloc(new_size));
|
return (me_malloc(new_size));
|
||||||
block = (void *)((t_u8 *)(ptr) - sizeof(t_arena_block));
|
block = (void *)((t_u8 *)(ptr) - sizeof(t_mblock));
|
||||||
if (block->size <= new_size)
|
if (block->size <= new_size)
|
||||||
return (ptr);
|
return (ptr);
|
||||||
ret = me_malloc(new_size);
|
ret = me_malloc(new_size);
|
||||||
|
|
||||||
mem_copy(ret, ptr, block->size);
|
mem_copy(ret, ptr, block->size);
|
||||||
me_free(ptr);
|
me_free(ptr);
|
||||||
return (ret);
|
return (ret);
|
||||||
|
|
@ -104,22 +59,14 @@ void *me_realloc(void *ptr, t_usize new_size)
|
||||||
|
|
||||||
void me_free(void *ptr)
|
void me_free(void *ptr)
|
||||||
{
|
{
|
||||||
t_arena_page *page;
|
t_mblock *cur;
|
||||||
t_arena_block *cur;
|
|
||||||
t_arena_block *next;
|
|
||||||
|
|
||||||
print_trace();
|
cur = (void *)(((t_usize)ptr) - sizeof(t_mblock));
|
||||||
page = get_page_from_ptr(ptr);
|
|
||||||
if (page == NULL)
|
|
||||||
me_abort("Tried to me_free with me_free something that isn't allocated "
|
|
||||||
"with me_alloc");
|
|
||||||
cur = (void *)(((t_usize)ptr) - sizeof(*cur));
|
|
||||||
cur->used = false;
|
cur->used = false;
|
||||||
next = (void *)(((t_usize)cur) + sizeof(*cur) + cur->size);
|
if (cur->next != NULL && cur->page == cur->next->page && !cur->next->used)
|
||||||
if (((t_usize)page) <= ((t_usize)next) &&
|
|
||||||
((t_usize)next) <= ((t_usize)page) + page->page_size + sizeof(*page))
|
|
||||||
{
|
{
|
||||||
if (!next->used)
|
cur->size += sizeof(t_mblock) + cur->next->size;
|
||||||
cur->size += next->size + sizeof(*cur);
|
mem_set_zero(cur->next->padding, 7);
|
||||||
|
cur->next = cur->next->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,24 +6,6 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/08 19:11:20 by maiboyer #+# #+# */
|
/* Created: 2024/05/08 19:11:20 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/05/08 19:14:57 by maiboyer ### ########.fr */
|
/* Updated: 2024/05/09 08:04:37 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "me/alloc/alloc.h"
|
|
||||||
#include "me/alloc/alloc_internal.h"
|
|
||||||
|
|
||||||
t_arena_page *get_page_from_ptr(void *ptr)
|
|
||||||
{
|
|
||||||
t_arena_page *page;
|
|
||||||
|
|
||||||
page = get_head_arena();
|
|
||||||
while (page)
|
|
||||||
{
|
|
||||||
if (((t_usize)page) <= ((t_usize)ptr) &&
|
|
||||||
((t_usize)ptr) <= ((t_usize)page) + page->page_size + sizeof(*page))
|
|
||||||
return (page);
|
|
||||||
page = page->next;
|
|
||||||
}
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/07 09:47:50 by maiboyer #+# #+# */
|
/* Created: 2024/05/07 09:47:50 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/05/08 22:05:36 by maiboyer ### ########.fr */
|
/* Updated: 2024/05/09 18:21:33 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
#include "me/fs/putendl_fd.h"
|
#include "me/fs/putendl_fd.h"
|
||||||
#include "me/fs/putnbr_fd.h"
|
#include "me/fs/putnbr_fd.h"
|
||||||
#include "me/fs/putstr_fd.h"
|
#include "me/fs/putstr_fd.h"
|
||||||
|
#include "me/mem/mem_compare.h"
|
||||||
|
#include "me/mem/mem_copy.h"
|
||||||
#include "me/mem/mem_set_zero.h"
|
#include "me/mem/mem_set_zero.h"
|
||||||
#include "me/num/usize.h"
|
#include "me/num/usize.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
@ -22,80 +24,89 @@
|
||||||
|
|
||||||
void *__libc_malloc(size_t size);
|
void *__libc_malloc(size_t size);
|
||||||
|
|
||||||
t_arena_page *get_head_arena(void)
|
t_mpage *alloc_page(t_usize size)
|
||||||
{
|
{
|
||||||
static t_arena_page *val = NULL;
|
t_mpage *val;
|
||||||
|
|
||||||
if (val == NULL)
|
size = usize_round_up_to(size, PAGE_SIZE_DEFAULT);
|
||||||
{
|
val = __libc_malloc(PAGE_SIZE_DEFAULT);
|
||||||
if (alloc_arena_page(ARENA_SIZE_DEFAULT, &val))
|
if (val == NULL || sizeof(t_mpage) >= PAGE_SIZE_DEFAULT)
|
||||||
{
|
return (NULL);
|
||||||
me_putstr_fd("Error: malloc failed\n", 2);
|
val->next = NULL;
|
||||||
exit(1);
|
val->page_size = PAGE_SIZE_DEFAULT;
|
||||||
}
|
val->first = (t_mblock *)(((t_usize)val) + sizeof(t_mpage));
|
||||||
}
|
val->first->page = val;
|
||||||
|
val->first->next = NULL;
|
||||||
|
mem_copy(val->first->padding, BLOCK_PADDING, 7);
|
||||||
|
val->first->used = false;
|
||||||
|
val->first->size = PAGE_SIZE_DEFAULT - sizeof(t_mpage);
|
||||||
|
me_putstr_fd("Allocating a page of size ", 2);
|
||||||
|
me_putnbr_fd(size, 2);
|
||||||
|
me_putendl_fd("", 2);
|
||||||
return (val);
|
return (val);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_error alloc_arena_page(t_usize min_size, t_arena_page **out)
|
t_mpage *get_head_arena(void)
|
||||||
{
|
{
|
||||||
t_arena_block *block;
|
static t_mpage *val = NULL;
|
||||||
|
|
||||||
printf("Allocating page with size %zu\n", min_size);
|
if (val == NULL)
|
||||||
min_size = usize_round_up_to(min_size, ARENA_SIZE_DEFAULT);
|
val = alloc_page(PAGE_SIZE_DEFAULT);
|
||||||
if (out == NULL)
|
if (val == NULL)
|
||||||
return (ERROR);
|
(me_putstr_fd("Failed to alloc first page", 2), exit(1));
|
||||||
*out = __libc_malloc(sizeof(t_arena_page) + min_size);
|
return (val);
|
||||||
if (*out == NULL)
|
|
||||||
return (ERROR);
|
|
||||||
mem_set_zero((t_u8 *)*out + sizeof(**out), min_size);
|
|
||||||
(*out)->page_size = min_size;
|
|
||||||
(*out)->next = NULL;
|
|
||||||
block = (t_arena_block *)((t_u8 *)*out + sizeof(**out));
|
|
||||||
block->end = true;
|
|
||||||
block->used = false;
|
|
||||||
block->size = min_size - sizeof(*block);
|
|
||||||
return (NO_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t_error get_block_for_page(t_usize size, t_arena_page *page,
|
t_mblock *split_block(t_mblock *self, t_usize min_size)
|
||||||
t_arena_block **out)
|
|
||||||
{
|
{
|
||||||
t_arena_block *cur;
|
t_usize remaining;
|
||||||
t_arena_block *next;
|
t_mblock *old_next;
|
||||||
t_usize leftover;
|
|
||||||
|
|
||||||
if (page == NULL || out == NULL)
|
min_size = usize_round_up_to(min_size, 16);
|
||||||
return (ERROR);
|
if (self->size > (min_size + sizeof(t_mpage) + 16))
|
||||||
if (page->page_size - sizeof(t_arena_block) <= size)
|
{
|
||||||
return (ERROR);
|
remaining = self->size - min_size - sizeof(t_mpage);
|
||||||
cur = (void *)((t_u8 *)page + sizeof(*page));
|
printf("Splitting %zu into %zu and %zu\n", self->size, min_size,
|
||||||
while ((t_usize)((t_u8 *)cur - (t_u8 *)page) <
|
remaining);
|
||||||
page->page_size - sizeof(*page))
|
self->size = min_size;
|
||||||
|
old_next = self->next;
|
||||||
|
self->next =
|
||||||
|
(t_mblock *)(((t_usize)self) + self->size + sizeof(t_mpage));
|
||||||
|
self->next->page = self->page;
|
||||||
|
self->next->next = old_next;
|
||||||
|
self->next->used = false;
|
||||||
|
self->next->size = remaining;
|
||||||
|
mem_copy(self->next->padding, BLOCK_PADDING, 7);
|
||||||
|
}
|
||||||
|
return (self);
|
||||||
|
}
|
||||||
|
|
||||||
|
t_mblock *get_block_for_size(t_usize size)
|
||||||
|
{
|
||||||
|
t_mblock *last;
|
||||||
|
t_mblock *cur;
|
||||||
|
|
||||||
|
last = NULL;
|
||||||
|
cur = get_head_arena()->first;
|
||||||
|
while (cur)
|
||||||
{
|
{
|
||||||
if (!cur->used && cur->size >= size)
|
if (!cur->used && cur->size >= size)
|
||||||
{
|
return (split_block(cur, size));
|
||||||
if (cur->size > size + sizeof(*cur) * 2)
|
last = cur;
|
||||||
{
|
cur = cur->next;
|
||||||
leftover = cur->size - size - sizeof(*cur);
|
|
||||||
cur->size = size;
|
|
||||||
next = (void *)(((t_usize)cur) + size);
|
|
||||||
next->size = leftover;
|
|
||||||
next->end = cur->end;
|
|
||||||
next->used = false;
|
|
||||||
cur->end = false;
|
|
||||||
}
|
}
|
||||||
*out = cur;
|
if (last == NULL)
|
||||||
return (NO_ERROR);
|
return (NULL);
|
||||||
}
|
last->page->next = alloc_page(size);
|
||||||
cur = (void *)((t_u8 *)cur + cur->size + sizeof(*cur));
|
if (last->page->next == NULL)
|
||||||
}
|
me_abort("Failed to alloc page!");
|
||||||
return (ERROR);
|
last->next = last->page->next->first;
|
||||||
|
return (split_block(last->page->next->first, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pages_info(void)
|
void print_pages_info(void)
|
||||||
{
|
{
|
||||||
t_arena_page *page;
|
t_mpage *page;
|
||||||
t_i32 page_nb;
|
t_i32 page_nb;
|
||||||
|
|
||||||
page = get_head_arena();
|
page = get_head_arena();
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/07 11:08:03 by maiboyer #+# #+# */
|
/* Created: 2024/05/07 11:08:03 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/05/08 23:26:22 by maiboyer ### ########.fr */
|
/* Updated: 2024/05/09 07:43:10 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -54,7 +54,7 @@ static void print_trace_inner(void **trace, t_str *messages, t_usize i)
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
snprintf(
|
snprintf(
|
||||||
syscom, sizeof(syscom) / sizeof(syscom[0]),
|
syscom, sizeof(syscom) / sizeof(syscom[0]),
|
||||||
"addr2line %#x -e %.*s -ipfa"
|
"addr2line %#x -e %.*s -ipf"
|
||||||
"| 1>&2 rg \"^(.*) at %s(.*)\"'$' --replace '$1 at $2' --color never",
|
"| 1>&2 rg \"^(.*) at %s(.*)\"'$' --replace '$1 at $2' --color never",
|
||||||
(t_u32)(convert_to_vma((t_usize)trace[i])), p, messages[i], BASE_PATH);
|
(t_u32)(convert_to_vma((t_usize)trace[i])), p, messages[i], BASE_PATH);
|
||||||
if (system(syscom))
|
if (system(syscom))
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/07 13:08:52 by maiboyer #+# #+# */
|
/* Created: 2024/05/07 13:08:52 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/05/08 19:33:27 by maiboyer ### ########.fr */
|
/* Updated: 2024/05/09 17:55:46 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -16,27 +16,28 @@
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
void __libc_free(void *ptr);
|
||||||
|
|
||||||
void me_exit(t_i32 exit_code)
|
void me_exit(t_i32 exit_code)
|
||||||
{
|
{
|
||||||
t_arena_page *page;
|
t_mpage *page;
|
||||||
t_arena_page *tmp;
|
t_mpage *tmp;
|
||||||
t_arena_block *block;
|
t_mblock *block;
|
||||||
t_usize count_block;
|
t_usize count_block;
|
||||||
|
|
||||||
page = get_head_arena();
|
page = get_head_arena();
|
||||||
count_block = 0;
|
count_block = 0;
|
||||||
while (page)
|
while (page)
|
||||||
{
|
{
|
||||||
block = (void *)(((t_usize)page) + sizeof(*page));
|
block = page->first;
|
||||||
while (((t_usize)page) <= ((t_usize)block) &&
|
while (block)
|
||||||
((t_usize)block) <=
|
|
||||||
((t_usize)page) + page->page_size + sizeof(*page))
|
|
||||||
{
|
{
|
||||||
count_block += block->used;
|
if (block->used)
|
||||||
block = (void *)(((t_usize)block) + sizeof(*block) + block);
|
count_block += 1;
|
||||||
|
block = block->next;
|
||||||
}
|
}
|
||||||
tmp = page->next;
|
tmp = page->next;
|
||||||
me_free(page);
|
__libc_free(page);
|
||||||
page = tmp;
|
page = tmp;
|
||||||
}
|
}
|
||||||
if (count_block != 0)
|
if (count_block != 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue