diff --git a/src/memory/kern/page.c b/src/memory/kern/page.c index 719afb1..f9d2dcd 100644 --- a/src/memory/kern/page.c +++ b/src/memory/kern/page.c @@ -14,13 +14,13 @@ static uint32_t *find_next_block(size_t nb_pages) uint32_t count = 0; for (uint32_t *pte = PTE2VA(1023, KERNEL_PT_START); pte < PTE2VA(1023, KERNEL_PT_END); pte++) { - if (!*pte) { + if (*pte) { count = 0; continue; } count++; if (count == nb_pages) - return pte - count; + return pte - (count - 1); } return NULL; } diff --git a/src/memory/memory.c b/src/memory/memory.c index 4963c9e..138827e 100644 --- a/src/memory/memory.c +++ b/src/memory/memory.c @@ -124,6 +124,7 @@ void init_memory() if (!frame) kpanic("Couldn't initialize kernel PTs\n"); PD[i] = frame | INIT_FLAGS; + bzero(PTE2VA(1023, i), PAGE_SIZE); } // kalash kalash kalash sur la mélodie chez nous pas de félonie ça vient // de Sevran les R diff --git a/src/memory/virt/page.c b/src/memory/virt/page.c index c4679a3..747148c 100644 --- a/src/memory/virt/page.c +++ b/src/memory/virt/page.c @@ -15,6 +15,7 @@ static int8_t alloc_pagetable(uint16_t pd_index) if (!pt) return -1; PD[pd_index] = (uint32_t)pt | INIT_FLAGS; + bzero(PTE2VA(1023, pd_index), PAGE_SIZE); return 0; } @@ -26,13 +27,13 @@ static uint32_t *find_next_block(size_t nb_pages) if (alloc_pagetable(i) < 0) return NULL; for (size_t j = 0; j < 1024; j++) { - if (!*GET_PTE(i, j)) { + if (*GET_PTE(i, j)) { count = 0; continue; } count++; if (count == nb_pages) { - return GET_PTE(i, j) - count; + return GET_PTE(i, j) - (count - 1); } } }