Commit b4f30b77 authored by Jules Sang's avatar Jules Sang
Browse files

TEMP

parent cbed2d7e
......@@ -18,32 +18,30 @@ unsigned long knuth_mmix_one_round(unsigned long in)
void *mark_memarea_and_get_user_ptr(void *ptr, unsigned long size, MemKind k)
{
unsigned long magic_number = (knuth_mmix_one_round((unsigned long) ptr) & ~(0b11UL)) | k;
((unsigned long*) ptr)[0] = size;
((unsigned long*) ptr)[1] = magic_number;
((unsigned long*) ptr)[size/8 + 2] = magic_number;
((unsigned long*) ptr)[size/8 + 3] = size;
*((unsigned long*) ptr) = size;
*((unsigned long*) ptr+1) = magic_number;
*((unsigned long*) ptr + size/8 - 2)= magic_number;
*((unsigned long*) ptr + size/8 - 1) = size;
return ((char*) ptr) + 16;
}
Alloc
mark_check_and_get_alloc(void *ptr)
{
void* data_beginning = ((unsigned long *) ptr) - 2;
// unsigned long size = *((unsigned long*) (ptr - 2 * sizeof(unsigned long)));
void* data_beginning = ((char*) ptr) - 16;
unsigned long size = *((unsigned long *) data_beginning);
// unsigned long magic_number = *((unsigned long*) (ptr - sizeof(unsigned long)));
unsigned long magic_number = *(((unsigned long *) data_beginning) + 1);
unsigned long magic_number = *(unsigned long*)((char*) data_beginning + 8);
MemKind k = magic_number & 0b11UL;
// unsigned long expected_magic_number = (knuth_mmix_one_round((unsigned long) (ptr - 2 * sizeof(unsigned long))) & ~(0b11UL)) | k;
unsigned long expected_magic_number = (knuth_mmix_one_round((unsigned long) data_beginning) & ~(0b11UL)) | k;
assert(magic_number == expected_magic_number);
// assertion of marquage coherence for magic_number & size
unsigned long size_at_end = ((unsigned long*) data_beginning)[size/8 + 3];
unsigned long size_at_end = *((unsigned long*) data_beginning + size/8 - 1);
assert(size == size_at_end);
Alloc a = { ptr - 2 * sizeof(unsigned long), k, size };
Alloc a = { data_beginning, k, size };
return a;
}
......
......@@ -38,7 +38,7 @@ emalloc_small(unsigned long size) {
void* head = arena.chunkpool;
// move arena.chunkpool's head
arena.chunkpool = *(void**)arena.chunkpool;
void* res = mark_memarea_and_get_user_ptr(head, SMALLALLOC, SMALL_KIND);
void* res = mark_memarea_and_get_user_ptr(head, CHUNKSIZE, SMALL_KIND);
return res;
}
......
......@@ -35,7 +35,7 @@ void allocat::doAlloc()
if ( adr == (char *)0 )
{
/* l'allocation a echoue */
printf ("Une allocation de %d a echoue !\n", size );
// printf ("Une allocation de %d a echoue !\n", size );
adr = nullptr;
}
......
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