Compare commits
4 Commits
60520dff4c
...
5b72144fac
Author | SHA1 | Date | |
---|---|---|---|
5b72144fac | |||
92a7004c2f | |||
31ee901e01 | |||
9eb829f3a2 |
@ -1,7 +1,6 @@
|
|||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "arch/CPU.h"
|
#include "arch/CPU.h"
|
||||||
#include "arch/MMU.h"
|
#include "arch/MMU.h"
|
||||||
#include "arch/Serial.h"
|
|
||||||
#include "arch/Timer.h"
|
#include "arch/Timer.h"
|
||||||
#include "boot/Init.h"
|
#include "boot/Init.h"
|
||||||
#include "boot/bootboot.h"
|
#include "boot/bootboot.h"
|
||||||
@ -10,6 +9,7 @@
|
|||||||
#include "memory/KernelVM.h"
|
#include "memory/KernelVM.h"
|
||||||
#include "memory/MemoryManager.h"
|
#include "memory/MemoryManager.h"
|
||||||
#include "thread/Scheduler.h"
|
#include "thread/Scheduler.h"
|
||||||
|
#include <luna/CString.h>
|
||||||
#include <luna/Result.h>
|
#include <luna/Result.h>
|
||||||
#include <luna/TarStream.h>
|
#include <luna/TarStream.h>
|
||||||
#include <luna/Units.h>
|
#include <luna/Units.h>
|
||||||
@ -46,22 +46,7 @@ void reap_thread()
|
|||||||
auto dying_threads = Scheduler::check_for_dying_threads();
|
auto dying_threads = Scheduler::check_for_dying_threads();
|
||||||
CPU::enable_interrupts();
|
CPU::enable_interrupts();
|
||||||
|
|
||||||
if (dying_threads.count())
|
dying_threads.consume([](Thread* thread) { Scheduler::reap_thread(thread); });
|
||||||
{
|
|
||||||
Thread* thread_to_reap = dying_threads.expect_first();
|
|
||||||
Thread* next_thread = thread_to_reap;
|
|
||||||
|
|
||||||
while (thread_to_reap)
|
|
||||||
{
|
|
||||||
next_thread = dying_threads.next(thread_to_reap).value_or(nullptr);
|
|
||||||
kinfoln("reap: reaping thread with id %zu", thread_to_reap->id);
|
|
||||||
auto stack = thread_to_reap->stack;
|
|
||||||
kinfoln("deleting thread stack @ %#lx, has %zu bytes of stack", stack.bottom(), stack.bytes());
|
|
||||||
MemoryManager::unmap_owned_and_free_vm(stack.bottom(), stack.bytes() / ARCH_PAGE_SIZE).release_value();
|
|
||||||
delete thread_to_reap;
|
|
||||||
thread_to_reap = next_thread;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
kernel_sleep(250);
|
kernel_sleep(250);
|
||||||
}
|
}
|
||||||
@ -87,8 +72,17 @@ Result<void> init()
|
|||||||
while (TRY(stream.read_next_entry().try_set_value_with_specific_error(entry, 0)))
|
while (TRY(stream.read_next_entry().try_set_value_with_specific_error(entry, 0)))
|
||||||
{
|
{
|
||||||
if (entry.type == TarStream::EntryType::RegularFile)
|
if (entry.type == TarStream::EntryType::RegularFile)
|
||||||
|
{
|
||||||
kinfoln("Found file %s in initial ramdisk, of size %s", entry.name,
|
kinfoln("Found file %s in initial ramdisk, of size %s", entry.name,
|
||||||
to_dynamic_unit(entry.size).release_value().chars());
|
to_dynamic_unit(entry.size).release_value().chars());
|
||||||
|
|
||||||
|
if (!strcmp(entry.name, "sys/config"))
|
||||||
|
{
|
||||||
|
auto contents = TRY(stream.read_contents_as_string(entry, 0, entry.size));
|
||||||
|
|
||||||
|
kinfoln("%s", contents.chars());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread::init();
|
Thread::init();
|
||||||
|
@ -95,6 +95,16 @@ namespace Scheduler
|
|||||||
return new_kernel_thread_impl(thread);
|
return new_kernel_thread_impl(thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void reap_thread(Thread* thread)
|
||||||
|
{
|
||||||
|
kinfoln("reap: reaping thread with id %zu", thread->id);
|
||||||
|
auto stack = thread->stack;
|
||||||
|
kinfoln("deleting thread stack @ %#lx, has %zu bytes of stack", stack.bottom(), stack.bytes());
|
||||||
|
// FIXME: Propagate errors I guess?
|
||||||
|
MemoryManager::unmap_owned_and_free_vm(stack.bottom(), stack.bytes() / ARCH_PAGE_SIZE).release_value();
|
||||||
|
delete thread;
|
||||||
|
}
|
||||||
|
|
||||||
Thread* pick_task()
|
Thread* pick_task()
|
||||||
{
|
{
|
||||||
Thread* old = g_current;
|
Thread* old = g_current;
|
||||||
|
@ -14,6 +14,8 @@ namespace Scheduler
|
|||||||
|
|
||||||
Thread* pick_task();
|
Thread* pick_task();
|
||||||
|
|
||||||
|
void reap_thread(Thread* thread);
|
||||||
|
|
||||||
void switch_task(Registers* regs);
|
void switch_task(Registers* regs);
|
||||||
|
|
||||||
void invoke(Registers* regs);
|
void invoke(Registers* regs);
|
||||||
|
@ -8,6 +8,7 @@ extern "C"
|
|||||||
int memcmp(const void* a, const void* b, usize n);
|
int memcmp(const void* a, const void* b, usize n);
|
||||||
void* memmove(void* dest, const void* src, usize n);
|
void* memmove(void* dest, const void* src, usize n);
|
||||||
usize strlen(const char* str);
|
usize strlen(const char* str);
|
||||||
|
int strcmp(const char* a, const char* b);
|
||||||
|
|
||||||
usize wcslen(const wchar_t* str);
|
usize wcslen(const wchar_t* str);
|
||||||
|
|
||||||
|
@ -155,26 +155,45 @@ template <typename T> class DoublyLinkedList
|
|||||||
return nonnull_or_error((T*)extract_node(item)->get_last());
|
return nonnull_or_error((T*)extract_node(item)->get_last());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Iterates over the elements of the DoublyLinkedList from start to end, calling callback for every element.
|
||||||
template <typename Callback> void for_each(Callback callback)
|
template <typename Callback> void for_each(Callback callback)
|
||||||
{
|
{
|
||||||
for (Node* node = m_start_node; node; node = node->get_next()) { callback((T*)node); }
|
for (Node* node = m_start_node; node; node = node->get_next()) { callback((T*)node); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Iterates over the elements of the DoublyLinkedList from end to start, calling callback for every element.
|
||||||
template <typename Callback> void for_each_reversed(Callback callback)
|
template <typename Callback> void for_each_reversed(Callback callback)
|
||||||
{
|
{
|
||||||
for (Node* node = m_end_node; node; node = node->get_last()) { callback((T*)node); }
|
for (Node* node = m_end_node; node; node = node->get_last()) { callback((T*)node); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Iterates over the elements of the DoublyLinkedList from the element after 'start' to end, calling callback for
|
||||||
|
// every element.
|
||||||
template <typename Callback> void for_each_after(T* start, Callback callback)
|
template <typename Callback> void for_each_after(T* start, Callback callback)
|
||||||
{
|
{
|
||||||
for (Node* node = extract_node(start)->m_next_node; node; node = node->get_next()) { callback((T*)node); }
|
for (Node* node = extract_node(start)->m_next_node; node; node = node->get_next()) { callback((T*)node); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Iterates over the elements of the DoublyLinkedList from the element before 'end' to start, calling callback for
|
||||||
|
// every element.
|
||||||
template <typename Callback> void for_each_before(T* end, Callback callback)
|
template <typename Callback> void for_each_before(T* end, Callback callback)
|
||||||
{
|
{
|
||||||
for (Node* node = extract_node(end)->m_last_node; node; node = node->get_last()) { callback((T*)node); }
|
for (Node* node = extract_node(end)->m_last_node; node; node = node->get_last()) { callback((T*)node); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Iterates over the elements of the DoublyLinkedList from start to end, removing each element before passing it to
|
||||||
|
// the callback.
|
||||||
|
template <typename Callback> void consume(Callback callback)
|
||||||
|
{
|
||||||
|
for (Node* node = m_start_node; node;)
|
||||||
|
{
|
||||||
|
T* current = (T*)node;
|
||||||
|
node = node->get_next();
|
||||||
|
remove(current);
|
||||||
|
callback(current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
usize count()
|
usize count()
|
||||||
{
|
{
|
||||||
return m_count;
|
return m_count;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <luna/OwnedStringView.h>
|
||||||
#include <luna/Result.h>
|
#include <luna/Result.h>
|
||||||
#include <luna/Types.h>
|
#include <luna/Types.h>
|
||||||
|
|
||||||
@ -33,6 +34,8 @@ class TarStream
|
|||||||
|
|
||||||
usize read_contents(const Entry& entry, char* buf, usize offset, usize length);
|
usize read_contents(const Entry& entry, char* buf, usize offset, usize length);
|
||||||
|
|
||||||
|
Result<OwnedStringView> read_contents_as_string(const Entry& entry, usize offset, usize max);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct [[gnu::packed]] TarHeader
|
struct [[gnu::packed]] TarHeader
|
||||||
{
|
{
|
||||||
|
@ -46,6 +46,16 @@ extern "C"
|
|||||||
return (usize)(i - str);
|
return (usize)(i - str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int strcmp(const char* a, const char* b)
|
||||||
|
{
|
||||||
|
while (*a && (*a == *b))
|
||||||
|
{
|
||||||
|
a++;
|
||||||
|
b++;
|
||||||
|
}
|
||||||
|
return *(const u8*)a - *(const u8*)b;
|
||||||
|
}
|
||||||
|
|
||||||
usize wcslen(const wchar_t* str)
|
usize wcslen(const wchar_t* str)
|
||||||
{
|
{
|
||||||
const wchar_t* i = str;
|
const wchar_t* i = str;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#define _LUNA_SYSTEM_ERROR_EXTENSIONS
|
#define _LUNA_SYSTEM_ERROR_EXTENSIONS
|
||||||
#include <luna/Alignment.h>
|
#include <luna/Alignment.h>
|
||||||
|
#include <luna/Alloc.h>
|
||||||
#include <luna/CString.h>
|
#include <luna/CString.h>
|
||||||
#include <luna/NumberParsing.h>
|
#include <luna/NumberParsing.h>
|
||||||
#include <luna/TarStream.h>
|
#include <luna/TarStream.h>
|
||||||
@ -95,3 +96,14 @@ usize TarStream::read_contents(const Entry& entry, char* buf, usize offset, usiz
|
|||||||
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result<OwnedStringView> TarStream::read_contents_as_string(const Entry& entry, usize offset, usize max)
|
||||||
|
{
|
||||||
|
char* buf = TRY(make_array<char>(max + 1));
|
||||||
|
|
||||||
|
usize nread = read_contents(entry, buf, offset, max);
|
||||||
|
|
||||||
|
buf[nread] = 0;
|
||||||
|
|
||||||
|
return OwnedStringView{buf};
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user