Compare commits
No commits in common. "944d32de36d1116a3cdebd1fe9e68ca234ad918c" and "a6974b605ec05b4faa8e44d54a625c2a29020568" have entirely different histories.
944d32de36
...
a6974b605e
@ -33,15 +33,18 @@ Result<bool> UserVM::try_expand(usize size)
|
|||||||
{
|
{
|
||||||
if (m_bitmap.size_in_bytes() == MAX_VM_SIZE) { return false; }
|
if (m_bitmap.size_in_bytes() == MAX_VM_SIZE) { return false; }
|
||||||
|
|
||||||
const usize old_size = m_bitmap.size_in_bytes();
|
usize new_size = m_bitmap.size_in_bytes() + size;
|
||||||
usize new_size = old_size + size;
|
|
||||||
|
|
||||||
if (new_size > MAX_VM_SIZE) new_size = MAX_VM_SIZE;
|
if (new_size > MAX_VM_SIZE) new_size = MAX_VM_SIZE;
|
||||||
|
|
||||||
m_bitmap.resize(new_size);
|
usize old_size = m_bitmap.size_in_bytes();
|
||||||
|
|
||||||
|
void* const base = TRY(krealloc(m_bitmap.location(), new_size));
|
||||||
|
|
||||||
|
m_bitmap.initialize(base, new_size);
|
||||||
m_bitmap.clear_region(old_size * 8, (new_size - old_size) * 8, false);
|
m_bitmap.clear_region(old_size * 8, (new_size - old_size) * 8, false);
|
||||||
|
|
||||||
kdbgln("user vm expanded to base=%p, size=%zu", m_bitmap.location(), new_size);
|
kdbgln("user vm expanded to base=%p, size=%zu", base, new_size);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -107,5 +110,5 @@ Result<void> UserVM::free_several_pages(u64 address, usize count)
|
|||||||
UserVM::~UserVM()
|
UserVM::~UserVM()
|
||||||
{
|
{
|
||||||
kdbgln("user vm destroyed: base=%p, size=%zu", m_bitmap.location(), m_bitmap.size_in_bytes());
|
kdbgln("user vm destroyed: base=%p, size=%zu", m_bitmap.location(), m_bitmap.size_in_bytes());
|
||||||
m_bitmap.deallocate();
|
kfree(m_bitmap.location());
|
||||||
}
|
}
|
||||||
|
@ -8,15 +8,9 @@ class Bitmap
|
|||||||
Bitmap();
|
Bitmap();
|
||||||
Bitmap(void* location, usize size_in_bytes);
|
Bitmap(void* location, usize size_in_bytes);
|
||||||
|
|
||||||
// Naive initialization functions.
|
|
||||||
void initialize(void* location, usize size_in_bytes);
|
void initialize(void* location, usize size_in_bytes);
|
||||||
void* move(void* new_location, usize new_location_size_in_bytes);
|
void* move(void* new_location, usize new_location_size_in_bytes);
|
||||||
|
|
||||||
// Dynamic memory initialization functions.
|
|
||||||
Result<void> allocate(usize size_in_bytes);
|
|
||||||
Result<void*> resize(usize new_size_in_bytes);
|
|
||||||
Result<void> deallocate();
|
|
||||||
|
|
||||||
void set(usize index, bool value);
|
void set(usize index, bool value);
|
||||||
bool get(usize index) const;
|
bool get(usize index) const;
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#include <luna/Bitmap.h>
|
#include <luna/Bitmap.h>
|
||||||
#include <luna/CString.h>
|
#include <luna/CString.h>
|
||||||
#include <luna/Check.h>
|
#include <luna/Check.h>
|
||||||
#include <luna/Heap.h>
|
|
||||||
|
|
||||||
Bitmap::Bitmap()
|
Bitmap::Bitmap()
|
||||||
{
|
{
|
||||||
@ -17,24 +16,6 @@ void Bitmap::initialize(void* location, usize size_in_bytes)
|
|||||||
m_size_in_bytes = size_in_bytes;
|
m_size_in_bytes = size_in_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<void> Bitmap::allocate(usize size_in_bytes)
|
|
||||||
{
|
|
||||||
initialize(TRY(malloc_impl(size_in_bytes)), size_in_bytes);
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
Result<void*> Bitmap::resize(usize new_size_in_bytes)
|
|
||||||
{
|
|
||||||
m_location = (u8*)TRY(realloc_impl(m_location, new_size_in_bytes));
|
|
||||||
m_size_in_bytes = new_size_in_bytes;
|
|
||||||
return (void*)m_location;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result<void> Bitmap::deallocate()
|
|
||||||
{
|
|
||||||
return free_impl(m_location);
|
|
||||||
}
|
|
||||||
|
|
||||||
void* Bitmap::move(void* new_location, usize new_location_size_in_bytes)
|
void* Bitmap::move(void* new_location, usize new_location_size_in_bytes)
|
||||||
{
|
{
|
||||||
expect(initialized(), "Bitmap was never initialized");
|
expect(initialized(), "Bitmap was never initialized");
|
||||||
@ -43,7 +24,7 @@ void* Bitmap::move(void* new_location, usize new_location_size_in_bytes)
|
|||||||
else
|
else
|
||||||
memcpy(new_location, m_location, new_location_size_in_bytes);
|
memcpy(new_location, m_location, new_location_size_in_bytes);
|
||||||
|
|
||||||
void* const old_location = (void*)m_location;
|
void* old_location = (void*)m_location;
|
||||||
|
|
||||||
m_location = (u8*)new_location;
|
m_location = (u8*)new_location;
|
||||||
m_size_in_bytes = new_location_size_in_bytes;
|
m_size_in_bytes = new_location_size_in_bytes;
|
||||||
@ -55,8 +36,8 @@ void Bitmap::set(usize index, bool value)
|
|||||||
{
|
{
|
||||||
expect(initialized(), "Bitmap was never initialized");
|
expect(initialized(), "Bitmap was never initialized");
|
||||||
expect(index < size(), "Bitmap access out of range");
|
expect(index < size(), "Bitmap access out of range");
|
||||||
const u64 byte_index = index / 8;
|
u64 byte_index = index / 8;
|
||||||
const u8 bit_mask = (u8)(0b10000000 >> (index % 8));
|
u8 bit_mask = (u8)(0b10000000 >> (index % 8));
|
||||||
m_location[byte_index] &= (u8)(~bit_mask);
|
m_location[byte_index] &= (u8)(~bit_mask);
|
||||||
if (value) { m_location[byte_index] |= bit_mask; }
|
if (value) { m_location[byte_index] |= bit_mask; }
|
||||||
}
|
}
|
||||||
@ -65,8 +46,8 @@ bool Bitmap::get(usize index) const
|
|||||||
{
|
{
|
||||||
expect(initialized(), "Bitmap was never initialized");
|
expect(initialized(), "Bitmap was never initialized");
|
||||||
expect(index < size(), "Bitmap access out of range");
|
expect(index < size(), "Bitmap access out of range");
|
||||||
const usize byte_index = index / 8;
|
usize byte_index = index / 8;
|
||||||
const u8 bit_mask = (u8)(0b10000000 >> (index % 8));
|
u8 bit_mask = (u8)(0b10000000 >> (index % 8));
|
||||||
return (m_location[byte_index] & bit_mask) > 0;
|
return (m_location[byte_index] & bit_mask) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +73,7 @@ void Bitmap::clear_region(usize start, usize bits, bool value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clear out the rest in bytes.
|
// Clear out the rest in bytes.
|
||||||
const usize bytes = bits / 8;
|
usize bytes = bits / 8;
|
||||||
|
|
||||||
memset(&m_location[start / 8], value_byte(value), bytes);
|
memset(&m_location[start / 8], value_byte(value), bytes);
|
||||||
start += bytes * 8;
|
start += bytes * 8;
|
||||||
@ -182,7 +163,7 @@ Option<usize> Bitmap::find_region(bool value, usize count, usize begin) const
|
|||||||
|
|
||||||
Option<usize> Bitmap::find_and_toggle_region(bool value, usize count, usize begin)
|
Option<usize> Bitmap::find_and_toggle_region(bool value, usize count, usize begin)
|
||||||
{
|
{
|
||||||
const usize index = TRY(find_region(value, count, begin));
|
usize index = TRY(find_region(value, count, begin));
|
||||||
clear_region(index, count, !value);
|
clear_region(index, count, !value);
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
@ -203,7 +184,7 @@ bool Bitmap::match_region(usize start, usize bits, bool value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Match the rest in bytes.
|
// Match the rest in bytes.
|
||||||
const usize bytes = bits / 8;
|
usize bytes = bits / 8;
|
||||||
const u8 byte_that_contains_only_value = value_byte(value);
|
const u8 byte_that_contains_only_value = value_byte(value);
|
||||||
|
|
||||||
for (usize i = start; i < start + bytes; i += 8)
|
for (usize i = start; i < start + bytes; i += 8)
|
||||||
|
Loading…
Reference in New Issue
Block a user