Compare commits

...

7 Commits

Author SHA1 Message Date
Bananymous 1941885cfd Kernel: Disable USB Mass Storage writing until I get it fixed
This prevented real hw from running for over 10-20 seconds. When first
disk sync happens after 10 secods, USB storage would enter faulty state
and not allow any io operations.

I have no idea what the problem is. If I don't send Reset command to the
USB device writing seems to work fine. I also don't think its part of
the Reset process either as reading works just fine.
2024-11-26 01:01:25 +02:00
Bananymous 88a86a9927 Kernel: Fix Thread destruction after sys_exit
This had undefined behaviour as Thread's (Processes's) PageTable was
destroyed before Thread had the change to destroy its own stacks that
lived on the PageTable.
2024-11-26 00:59:34 +02:00
Bananymous 48e030bca3 Kernel: Make PageTable non-copyable and non-movable
Also PageTable destructor now verifies that is has allocated something
instead of assuming paddr of 0.
2024-11-26 00:58:35 +02:00
Bananymous 6f118c1be1 BAN: Make HashMap key move constructible
This allows using non-copyable types as keys
2024-11-26 00:57:11 +02:00
Bananymous 7316eb87b8 BAN: Add requires expression for BAN::Formatter
This allows seeing syntax errors before compilation :)
2024-11-26 00:55:58 +02:00
Bananymous 5376236ab6 BAN: Make ErrorOr non-copyable
This makes avoiding accidentals copies easier :)
2024-11-26 00:55:12 +02:00
Bananymous 0af80d48ee BAN: Mark ByteSpan::slice as [[nodiscard]] 2024-11-26 00:54:35 +02:00
11 changed files with 39 additions and 13 deletions

View File

@ -84,7 +84,7 @@ namespace BAN
return Span<S>(reinterpret_cast<S*>(m_data), m_size / sizeof(S));
}
ByteSpanGeneral slice(size_type offset, size_type length = size_type(-1)) const
[[nodiscard]] ByteSpanGeneral slice(size_type offset, size_type length = size_type(-1)) const
{
ASSERT(m_data);
ASSERT(m_size >= offset);

View File

@ -1,6 +1,7 @@
#pragma once
#include <BAN/Formatter.h>
#include <BAN/NoCopyMove.h>
#include <BAN/Variant.h>
#include <errno.h>
@ -97,6 +98,7 @@ namespace BAN
template<typename T>
class [[nodiscard]] ErrorOr
{
BAN_NON_COPYABLE(ErrorOr);
public:
ErrorOr(const T& value)
: m_data(value)
@ -110,6 +112,14 @@ namespace BAN
ErrorOr(Error&& error)
: m_data(move(error))
{}
ErrorOr(ErrorOr&& other)
: m_data(move(other.m_data))
{}
ErrorOr& operator=(ErrorOr&& other)
{
m_data = move(other.m_data);
return *this;
}
bool is_error() const { return m_data.template has<Error>(); }
const Error& error() const { return m_data.template get<Error>(); }

View File

@ -10,14 +10,11 @@ namespace BAN::Formatter
struct ValueFormat;
template<typename F>
inline void print(F putc, const char* format);
template<typename F, typename Arg, typename... Args>
inline void print(F putc, const char* format, Arg&& arg, Args&&... args);
template<typename F, typename... Args>
inline void println(F putc, const char* format, Args&&... args);
concept PrintableArguments = requires(F putc, Args&&... args, const ValueFormat& format)
{
(print_argument(putc, BAN::forward<Args>(args), format), ...);
};
template<typename F, typename T>
inline void print_argument(F putc, T value, const ValueFormat& format);
@ -53,7 +50,7 @@ namespace BAN::Formatter
}
}
template<typename F, typename Arg, typename... Args>
template<typename F, typename Arg, typename... Args> requires PrintableArguments<F, Arg, Args...>
inline void print(F putc, const char* format, Arg&& arg, Args&&... args)
{
while (*format && *format != '{')

View File

@ -19,6 +19,12 @@ namespace BAN
, value(forward<Args>(args)...)
{}
template<typename... Args>
Entry(Key&& key, Args&&... args) requires is_constructible_v<T, Args...>
: key(BAN::move(key))
, value(forward<Args>(args)...)
{}
Key key;
T value;
};

View File

@ -272,6 +272,9 @@ namespace Kernel
PageTable::~PageTable()
{
if (m_highest_paging_struct == 0)
return;
uint64_t* pdpt = reinterpret_cast<uint64_t*>(P2V(m_highest_paging_struct));
for (uint32_t pdpte = 0; pdpte < 3; pdpte++)

View File

@ -576,6 +576,9 @@ namespace Kernel
PageTable::~PageTable()
{
if (m_highest_paging_struct == 0)
return;
// NOTE: we only loop until 256 since after that is hhdm
const uint64_t* pml4 = P2V(m_highest_paging_struct);
for (uint64_t pml4e = 0; pml4e < 256; pml4e++)

View File

@ -22,6 +22,9 @@ namespace Kernel
class PageTable
{
BAN_NON_COPYABLE(PageTable);
BAN_NON_MOVABLE(PageTable);
public:
using flags_t = uint16_t;
enum Flags : flags_t

View File

@ -47,7 +47,7 @@ namespace Kernel
static Process* create_kernel(entry_t, void*);
static BAN::ErrorOr<Process*> create_userspace(const Credentials&, BAN::StringView path, BAN::Span<BAN::StringView> arguments);
~Process();
void cleanup_function();
void cleanup_function(Thread*);
void register_to_scheduler();
void exit(int status, int signal);

View File

@ -208,7 +208,7 @@ namespace Kernel
{
ASSERT(m_threads.empty());
ASSERT(m_mapped_regions.empty());
ASSERT(&PageTable::current() != m_page_table.ptr());
ASSERT(!m_page_table);
}
void Process::add_thread(Thread* thread)
@ -217,7 +217,7 @@ namespace Kernel
MUST(m_threads.push_back(thread));
}
void Process::cleanup_function()
void Process::cleanup_function(Thread* thread)
{
{
SpinLockGuard _(s_process_lock);
@ -238,6 +238,8 @@ namespace Kernel
// NOTE: We must unmap ranges while the page table is still alive
m_mapped_regions.clear();
thread->give_keep_alive_page_table(BAN::move(m_page_table));
}
bool Process::on_thread_exit(Thread& thread)

View File

@ -242,7 +242,7 @@ namespace Kernel
ASSERT(thread->m_process == process);
process->cleanup_function();
process->cleanup_function(thread);
thread->m_delete_process = true;

View File

@ -174,6 +174,8 @@ namespace Kernel
BAN::ErrorOr<void> USBSCSIDevice::write_sectors_impl(uint64_t first_lba, uint64_t sector_count, BAN::ConstByteSpan buffer)
{
return BAN::Error::from_errno(ENOTSUP);
dprintln_if(DEBUG_USB_MASS_STORAGE, "write_blocks({}, {})", first_lba, sector_count);
const size_t max_blocks_per_write = m_max_packet_size / m_block_size;