Commit 9d9d3fc6 authored by Hugo's avatar Hugo
Browse files

partie 1 semble verifiee

parent e5d1b1f3
......@@ -16,38 +16,42 @@ unsigned long knuth_mmix_one_round(unsigned long in)
return in * 6364136223846793005UL % 1442695040888963407UL;
}
//FONCTION MARCHE
void *mark_memarea_and_get_user_ptr(void *ptr, unsigned long size, MemKind k)
{
//calcul magic
uint64_t magic;
magic = (uint64_t)knuth_mmix_one_round(size);
magic &= 0xFFFFFFFFFFFFFFFC;
magic |= k;
uint64_t magic;
magic = knuth_mmix_one_round((unsigned long)ptr) & ~(0b11UL);
//marquage du bloc
*(uint64_t*)(ptr+8) = magic;
*(uint64_t*)(ptr+size+16) = magic;
*(uint64_t*)ptr = (uint64_t)size;
*(uint64_t*)(ptr+size+24) = (uint64_t)size;
return ptr+16;
char* pointeur = NULL;
pointeur = (char*)ptr;
*(unsigned long*)(pointeur) = (unsigned long)size;
*(unsigned long*)(pointeur+8) = magic;
*(unsigned long*)(pointeur+size-16) = magic;
*(unsigned long*)(pointeur+size-8) = (unsigned long)size;
return (void*)ptr+16;
}
Alloc
mark_check_and_get_alloc(void *ptr)
{
Alloc a = {};
a.ptr = ptr-16;
a.size = *(uint64_t*)a.ptr;
uint64_t magique = *(uint64_t*)(ptr-8);
magique &= 0x0000000000000003;
char* pointeur = (char*)ptr -16;
a.ptr = (void*)pointeur;
a.size = *(unsigned long*)a.ptr;
/*
a.size = *(unsigned long*)(pointeur);
uint64_t magique = knuth_mmix_one_round((unsigned long)pointeur) & ~(0b11UL);
a.kind = *(MemKind*)magique;
uint64_t magic;
magic = (uint64_t)knuth_mmix_one_round(a.size);
magic &= 0xFFFFFFFFFFFFFFFC;
magic |= a.kind;
assert(magic == *((uint64_t*)(ptr+a.size))) ;
assert(*((uint64_t*)(ptr-16))==*((uint64_t*)(ptr+a.size+8)));
assert(*((uint64_t*)(ptr-8))==*((uint64_t*)(ptr+a.size)));
magic = knuth_mmix_one_round((unsigned long)a.size) & ~(0b11UL);*/
// assert(magic == *((uint64_t*)(ptr+a.size))) ;
// assert(*((uint64_t*)(ptr-16))==*((uint64_t*)(ptr+a.size+8)));
// assert(*((uint64_t*)(ptr-8))==*((uint64_t*)(ptr+a.size)));
return a;
}
......
......@@ -27,12 +27,10 @@
void *
emalloc_small(unsigned long size)
{
void *head=arena.chunkpool+96;
free((u_int32_t*)(arena.chunkpool+64));//libère la premiere cellule de 96 cases
free((u_int64_t*)arena.chunkpool);
arena.chunkpool=head;
if(size<=0){return NULL;}
arena.chunkpool=arena.chunkpool+96;
void *ptr = NULL;
ptr = mark_memarea_and_get_user_ptr(head,size,SMALL_KIND);//appelle la fonction de marquage
ptr = mark_memarea_and_get_user_ptr(arena.chunkpool,size,SMALL_KIND);//appelle la fonction de marquage
if(arena.chunkpool==NULL){
unsigned int taille = mem_realloc_small();
unsigned int compteur = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment