From 886f912f36d9f7910ebc94994b09ff52eb165aa7 Mon Sep 17 00:00:00 2001 From: starnakin Date: Tue, 15 Oct 2024 01:10:37 +0200 Subject: [PATCH] fix: find_next_block --- src/memory/page.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/memory/page.c b/src/memory/page.c index 38a5dec..f0c3d35 100644 --- a/src/memory/page.c +++ b/src/memory/page.c @@ -6,23 +6,22 @@ #include "memory.h" #include "utils.h" -#define PT_SIZE 1024 +#define PT_SIZE 0x300 #define MAX_TLB_ENTRIES 32 extern uint32_t page_table_entries[PT_SIZE] __attribute__((aligned(4096))); static int16_t find_next_block(size_t nb_pages) { - for (size_t i = 0; i < PT_SIZE; i++) { - if (page_table_entries[i] >> 12 == i) { - size_t j = i + 1; - for (; j - i < nb_pages && j < PT_SIZE; j++) - if (page_table_entries[j] >> 12 != j) - break; - if (j - i == nb_pages) - return i; - i = j - 1; - } + for (uint16_t i = 0; i < PT_SIZE; i++) { + uint16_t j; + for (j = 0; + page_table_entries[i + j] >> 12 == i + j && j < nb_pages; + j++) + ; + if (j == nb_pages) + return i; + i += j; } return -1; }