Compare commits
No commits in common. "41b3c8adb2ae10847eb7b1d5013e6283b413a7e9" and "e729c38200febe904100557a49d5e842fcd0da5c" have entirely different histories.
41b3c8adb2
...
e729c38200
@ -4,7 +4,6 @@
|
||||
#include "arch/Timer.h"
|
||||
#include "boot/Init.h"
|
||||
#include "config.h"
|
||||
#include "memory/Heap.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "thread/Scheduler.h"
|
||||
#include <luna/Result.h>
|
||||
@ -24,13 +23,6 @@ void async_thread()
|
||||
}
|
||||
}
|
||||
|
||||
void heap_thread()
|
||||
{
|
||||
CPU::disable_interrupts();
|
||||
dump_heap_usage();
|
||||
while (true) kernel_sleep(UINT64_MAX);
|
||||
}
|
||||
|
||||
Result<void> init()
|
||||
{
|
||||
kinfoln("Starting Moon %s", MOON_VERSION);
|
||||
@ -41,15 +33,19 @@ Result<void> init()
|
||||
|
||||
Timer::init();
|
||||
|
||||
kinfoln("Total memory: %s", to_dynamic_unit(MemoryManager::total()).release_value().chars());
|
||||
kinfoln("Free memory: %s", to_dynamic_unit(MemoryManager::free()).release_value().chars());
|
||||
kinfoln("Used memory: %s", to_dynamic_unit(MemoryManager::used()).release_value().chars());
|
||||
kinfoln("Reserved memory: %s", to_dynamic_unit(MemoryManager::reserved()).release_value().chars());
|
||||
char buffer[64];
|
||||
to_dynamic_unit(MemoryManager::total(), buffer, sizeof(buffer));
|
||||
kinfoln("Total memory: %s", buffer);
|
||||
to_dynamic_unit(MemoryManager::free(), buffer, sizeof(buffer));
|
||||
kinfoln("Free memory: %s", buffer);
|
||||
to_dynamic_unit(MemoryManager::used(), buffer, sizeof(buffer));
|
||||
kinfoln("Used memory: %s", buffer);
|
||||
to_dynamic_unit(MemoryManager::reserved(), buffer, sizeof(buffer));
|
||||
kinfoln("Reserved memory: %s", buffer);
|
||||
|
||||
Scheduler::init();
|
||||
|
||||
TRY(Scheduler::new_kernel_thread(async_thread));
|
||||
TRY(Scheduler::new_kernel_thread(heap_thread));
|
||||
|
||||
CPU::platform_finish_init();
|
||||
|
||||
|
@ -5,18 +5,12 @@
|
||||
#include "memory/KernelVM.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include <luna/Alignment.h>
|
||||
#include <luna/Alloc.h>
|
||||
#include <luna/LinkedList.h>
|
||||
#include <luna/SafeArithmetic.h>
|
||||
#include <luna/ScopeGuard.h>
|
||||
#include <luna/String.h>
|
||||
#include <luna/SystemError.h>
|
||||
|
||||
namespace std
|
||||
{
|
||||
const std::nothrow_t nothrow;
|
||||
}
|
||||
|
||||
static constexpr int BLOCK_USED = 1 << 0;
|
||||
static constexpr int BLOCK_START_MEM = 1 << 1;
|
||||
static constexpr int BLOCK_END_MEM = 1 << 2;
|
||||
@ -360,12 +354,12 @@ void dump_heap_usage()
|
||||
kdbgln("-- Heap memory in use by the kernel: %zu bytes", alloc_used);
|
||||
}
|
||||
|
||||
void* operator new(usize size, const std::nothrow_t&) noexcept
|
||||
void* operator new(usize size) noexcept
|
||||
{
|
||||
return kmalloc(size).value_or(nullptr);
|
||||
}
|
||||
|
||||
void* operator new[](usize size, const std::nothrow_t&) noexcept
|
||||
void* operator new[](usize size) noexcept
|
||||
{
|
||||
return kmalloc(size).value_or(nullptr);
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ set(FREESTANDING_SOURCES
|
||||
src/Bitmap.cpp
|
||||
src/Stack.cpp
|
||||
src/Alloc.cpp
|
||||
src/OwnedStringView.cpp
|
||||
)
|
||||
|
||||
set(SOURCES
|
||||
|
@ -1,36 +1,19 @@
|
||||
#pragma once
|
||||
#include <luna/Result.h>
|
||||
|
||||
namespace std
|
||||
{
|
||||
struct nothrow_t
|
||||
{
|
||||
explicit nothrow_t() = default;
|
||||
};
|
||||
|
||||
extern const nothrow_t nothrow;
|
||||
|
||||
enum class align_val_t : usize
|
||||
{
|
||||
};
|
||||
};
|
||||
|
||||
[[nodiscard]] void* raw_malloc(usize);
|
||||
void raw_free(void*);
|
||||
|
||||
void* operator new(usize size, const std::nothrow_t&) noexcept;
|
||||
void* operator new[](usize size, const std::nothrow_t&) noexcept;
|
||||
|
||||
template <typename T, class... Args> [[nodiscard]] Result<T*> make(Args... args)
|
||||
{
|
||||
T* const result = new (std::nothrow) T(args...);
|
||||
T* const result = new T(args...);
|
||||
if (!result) return err(ENOMEM);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T> [[nodiscard]] Result<T*> make_array(usize count)
|
||||
{
|
||||
T* const result = new (std::nothrow) T[count];
|
||||
T* const result = new T[count];
|
||||
if (!result) return err(ENOMEM);
|
||||
return result;
|
||||
}
|
||||
|
@ -50,8 +50,10 @@ template <typename T> class Option
|
||||
T release_value()
|
||||
{
|
||||
expect(has_value(), "Option::release_value called on an empty Option");
|
||||
T item = m_storage.fetch_reference();
|
||||
m_has_value = false;
|
||||
return move(m_storage.fetch_reference());
|
||||
m_storage.destroy();
|
||||
return move(item);
|
||||
}
|
||||
|
||||
T value_or(const T& other) const
|
||||
@ -124,7 +126,7 @@ template <typename T> class Option
|
||||
|
||||
void store_moved_reference(T&& ref)
|
||||
{
|
||||
new (buffer) T(move(ref));
|
||||
new (buffer) T(ref);
|
||||
}
|
||||
|
||||
void destroy()
|
||||
|
@ -1,27 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class OwnedStringView
|
||||
{
|
||||
public:
|
||||
OwnedStringView(char* c_str);
|
||||
OwnedStringView();
|
||||
OwnedStringView(OwnedStringView&&);
|
||||
OwnedStringView(const OwnedStringView&) = delete;
|
||||
~OwnedStringView();
|
||||
|
||||
Result<OwnedStringView> clone();
|
||||
|
||||
const char* chars()
|
||||
{
|
||||
return m_string;
|
||||
}
|
||||
|
||||
usize length()
|
||||
{
|
||||
return m_length;
|
||||
}
|
||||
|
||||
private:
|
||||
char* m_string{nullptr};
|
||||
usize m_length{0};
|
||||
};
|
@ -25,7 +25,7 @@ template <typename T> class Result
|
||||
m_has_error = false;
|
||||
}
|
||||
|
||||
Result(T&& value) : m_value(move(value))
|
||||
Result(T&& value) : m_value(value)
|
||||
{
|
||||
m_has_value = true;
|
||||
m_has_error = false;
|
||||
@ -46,7 +46,7 @@ template <typename T> class Result
|
||||
}
|
||||
}
|
||||
|
||||
Result(Result<T>&& other) : m_value(move(other.m_value))
|
||||
Result(Result<T>&& other) : m_value(other.m_value)
|
||||
{
|
||||
if (!other.m_has_error)
|
||||
{
|
||||
|
@ -1,6 +1,4 @@
|
||||
#pragma once
|
||||
#include <luna/OwnedStringView.h>
|
||||
#include <luna/Result.h>
|
||||
|
||||
Result<usize> to_dynamic_unit_cstr(usize value, char* buffer, usize max);
|
||||
Result<OwnedStringView> to_dynamic_unit(usize value);
|
||||
Result<usize> to_dynamic_unit(usize value, char* buffer, usize max);
|
@ -1,36 +0,0 @@
|
||||
#include <luna/Alloc.h>
|
||||
#include <luna/OwnedStringView.h>
|
||||
#include <luna/String.h>
|
||||
|
||||
OwnedStringView::OwnedStringView()
|
||||
{
|
||||
}
|
||||
|
||||
OwnedStringView::OwnedStringView(OwnedStringView&& other)
|
||||
{
|
||||
m_string = other.m_string;
|
||||
m_length = other.m_length;
|
||||
|
||||
other.m_string = nullptr;
|
||||
}
|
||||
|
||||
OwnedStringView::OwnedStringView(char* c_str)
|
||||
{
|
||||
m_string = c_str;
|
||||
|
||||
if (m_string) { m_length = strlen(m_string); }
|
||||
}
|
||||
|
||||
OwnedStringView::~OwnedStringView()
|
||||
{
|
||||
if (m_string) destroy_array(m_string);
|
||||
}
|
||||
|
||||
Result<OwnedStringView> OwnedStringView::clone()
|
||||
{
|
||||
char* buf = TRY(make_array<char>(m_length + 1));
|
||||
|
||||
memcpy(buf, m_string, m_length + 1);
|
||||
|
||||
return OwnedStringView{buf};
|
||||
}
|
@ -1,10 +1,8 @@
|
||||
#include <luna/Alloc.h>
|
||||
#include <luna/Format.h>
|
||||
#include <luna/Result.h>
|
||||
#include <luna/ScopeGuard.h>
|
||||
#include <luna/Units.h>
|
||||
|
||||
Result<usize> to_dynamic_unit_cstr(usize value, char* buffer, usize max)
|
||||
Result<usize> to_dynamic_unit(usize value, char* buffer, usize max)
|
||||
{
|
||||
if (value < 1024) { return string_format(buffer, max, "%u bytes", value); }
|
||||
|
||||
@ -16,17 +14,4 @@ Result<usize> to_dynamic_unit_cstr(usize value, char* buffer, usize max)
|
||||
}
|
||||
|
||||
return string_format(buffer, max, "%u.%u %ciB", value / 1024, (value % 1024) / 103, *unit_prefixes);
|
||||
}
|
||||
|
||||
Result<OwnedStringView> to_dynamic_unit(usize value)
|
||||
{
|
||||
char* buf = TRY(make_array<char>(64));
|
||||
|
||||
auto guard = make_scope_guard([&] { destroy_array(buf); });
|
||||
|
||||
TRY(to_dynamic_unit_cstr(value, buf, 64));
|
||||
|
||||
guard.deactivate();
|
||||
|
||||
return OwnedStringView{buf};
|
||||
}
|
Loading…
Reference in New Issue
Block a user