diff options
author | Freya Murphy <freya@freyacat.org> | 2024-01-30 12:16:22 -0500 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-01-30 12:17:47 -0500 |
commit | e76cbbcb327e0966fff47a645cdbc26e27a4bc8a (patch) | |
tree | 8850bb6be51e5cedb9c7ff89e047d21deec84fdf /src/memory | |
parent | added backtraces (diff) | |
download | corn-e76cbbcb327e0966fff47a645cdbc26e27a4bc8a.tar.gz corn-e76cbbcb327e0966fff47a645cdbc26e27a4bc8a.tar.bz2 corn-e76cbbcb327e0966fff47a645cdbc26e27a4bc8a.zip |
make paging more stable
Diffstat (limited to 'src/memory')
-rw-r--r-- | src/memory/physalloc.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/memory/physalloc.c b/src/memory/physalloc.c index 5be7469..dccd980 100644 --- a/src/memory/physalloc.c +++ b/src/memory/physalloc.c @@ -26,6 +26,7 @@ static uint64_t total_memory; static uint64_t free_memory; static uint64_t page_count; static uint64_t page_free_start; +static uint64_t segment_count; static struct memory_area *page_start; static int n_pages(const struct memory_area *m) { @@ -34,7 +35,8 @@ static int n_pages(const struct memory_area *m) { static void *page_at(int i) { int cur_page = 0; - for (struct memory_area *m = page_start; m != NULL; m++) { + for (uint64_t idx = 0; idx < segment_count; idx++) { + struct memory_area *m = &page_start[idx]; int pages = n_pages(m); if (i - cur_page < pages) { return (void *) (m->addr + (PAGE_SIZE * (i - cur_page))); @@ -165,7 +167,7 @@ void memory_init(struct memory_map *map) { end += map->size; struct memory_segment *segment = &map->entries[0]; - int segment_count = 0; + segment_count = 0; for(; (uintptr_t) segment < end; segment++) { if (segment_invalid(segment)) |