Skip to content
This repository has been archived by the owner on May 9, 2023. It is now read-only.

Commit

Permalink
Add simple workaround of mmap overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Hary309 authored Jan 31, 2021
1 parent deafddc commit 51b3249
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion code/kernel/memory/kernel_heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ static allocator* allocator;

void kheap::init()
{
const uint64_t max_address = 4ull * 1024 * 1024 * 1024;

auto entries = mmap::get_entries();

mmap::entry largest{};
Expand All @@ -23,7 +25,7 @@ void kheap::init()
{
if (entry.type == mmap::entry::type::available)
{
if (entry.length > largest.length)
if (entry.addr < max_address && entry.length > largest.length)
{
largest = entry;
}
Expand All @@ -36,6 +38,12 @@ void kheap::init()
const uint32_t kernel_start = reinterpret_cast<uint32_t>(&_kernel_start);
const uint32_t kernel_end = reinterpret_cast<uint32_t>(&_kernel_end);

// limit memory to 1 GB (avoid overflow :x)
if (largest.length > 1024 * 1024 * 1024)
{
largest.length = 1024 * 1024 * 1024;
}

uint32_t heap_start = largest.addr;
uint32_t heap_end = largest.addr = largest.length;

Expand Down

0 comments on commit 51b3249

Please sign in to comment.