fix: bzero page tables before use it, alloc return the right index

This commit is contained in:
2025-11-28 19:24:40 +01:00
parent 2308ef509c
commit 1992d7f79b
3 changed files with 6 additions and 4 deletions

View File

@ -14,13 +14,13 @@ static uint32_t *find_next_block(size_t nb_pages)
uint32_t count = 0; uint32_t count = 0;
for (uint32_t *pte = PTE2VA(1023, KERNEL_PT_START); for (uint32_t *pte = PTE2VA(1023, KERNEL_PT_START);
pte < PTE2VA(1023, KERNEL_PT_END); pte++) { pte < PTE2VA(1023, KERNEL_PT_END); pte++) {
if (!*pte) { if (*pte) {
count = 0; count = 0;
continue; continue;
} }
count++; count++;
if (count == nb_pages) if (count == nb_pages)
return pte - count; return pte - (count - 1);
} }
return NULL; return NULL;
} }

View File

@ -124,6 +124,7 @@ void init_memory()
if (!frame) if (!frame)
kpanic("Couldn't initialize kernel PTs\n"); kpanic("Couldn't initialize kernel PTs\n");
PD[i] = frame | INIT_FLAGS; 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 // kalash kalash kalash sur la mélodie chez nous pas de félonie ça vient
// de Sevran les R // de Sevran les R

View File

@ -15,6 +15,7 @@ static int8_t alloc_pagetable(uint16_t pd_index)
if (!pt) if (!pt)
return -1; return -1;
PD[pd_index] = (uint32_t)pt | INIT_FLAGS; PD[pd_index] = (uint32_t)pt | INIT_FLAGS;
bzero(PTE2VA(1023, pd_index), PAGE_SIZE);
return 0; return 0;
} }
@ -26,13 +27,13 @@ static uint32_t *find_next_block(size_t nb_pages)
if (alloc_pagetable(i) < 0) if (alloc_pagetable(i) < 0)
return NULL; return NULL;
for (size_t j = 0; j < 1024; j++) { for (size_t j = 0; j < 1024; j++) {
if (!*GET_PTE(i, j)) { if (*GET_PTE(i, j)) {
count = 0; count = 0;
continue; continue;
} }
count++; count++;
if (count == nb_pages) { if (count == nb_pages) {
return GET_PTE(i, j) - count; return GET_PTE(i, j) - (count - 1);
} }
} }
} }