Kernel: SYS_FORK can now fail instead of panicing on error

This commit is contained in:
Bananymous
2023-07-19 17:47:12 +03:00
parent 8b34880064
commit 5d2bfc858e
8 changed files with 79 additions and 67 deletions

View File

@@ -1,7 +1,8 @@
#pragma once
#include <BAN/Vector.h>
#include <BAN/NoCopyMove.h>
#include <BAN/UniqPtr.h>
#include <BAN/Vector.h>
#include <kernel/Memory/PageTable.h>
namespace Kernel
@@ -13,11 +14,11 @@ namespace Kernel
BAN_NON_MOVABLE(VirtualRange);
public:
static VirtualRange* create(PageTable&, vaddr_t, size_t, uint8_t flags);
static VirtualRange* create_kmalloc(size_t);
static BAN::ErrorOr<BAN::UniqPtr<VirtualRange>> create(PageTable&, vaddr_t, size_t, uint8_t flags);
static BAN::ErrorOr<BAN::UniqPtr<VirtualRange>> create_kmalloc(size_t);
~VirtualRange();
VirtualRange* clone(PageTable&);
BAN::ErrorOr<BAN::UniqPtr<VirtualRange>> clone(PageTable&);
vaddr_t vaddr() const { return m_vaddr; }
size_t size() const { return m_size; }

View File

@@ -17,6 +17,8 @@ namespace Kernel
OpenFileDescriptorSet(const Credentials&);
~OpenFileDescriptorSet();
OpenFileDescriptorSet& operator=(OpenFileDescriptorSet&&);
BAN::ErrorOr<void> clone_from(const OpenFileDescriptorSet&);
BAN::ErrorOr<int> open(BAN::StringView absolute_path, int flags);

View File

@@ -140,7 +140,7 @@ namespace Kernel
OpenFileDescriptorSet m_open_file_descriptors;
BAN::Vector<VirtualRange*> m_mapped_ranges;
BAN::Vector<BAN::UniqPtr<VirtualRange>> m_mapped_ranges;
mutable RecursiveSpinLock m_lock;

View File

@@ -2,6 +2,7 @@
#include <BAN/NoCopyMove.h>
#include <BAN/RefPtr.h>
#include <BAN/UniqPtr.h>
#include <kernel/Memory/VirtualRange.h>
#include <sys/types.h>
@@ -69,18 +70,18 @@ namespace Kernel
void validate_stack() const;
private:
static constexpr size_t m_kernel_stack_size = PAGE_SIZE * 1;
static constexpr size_t m_userspace_stack_size = PAGE_SIZE * 2;
static constexpr size_t m_interrupt_stack_size = PAGE_SIZE * 2;
VirtualRange* m_interrupt_stack { nullptr };
VirtualRange* m_stack { nullptr };
uintptr_t m_rip { 0 };
uintptr_t m_rsp { 0 };
const pid_t m_tid { 0 };
State m_state { State::NotStarted };
Process* m_process { nullptr };
bool m_in_syscall { false };
bool m_is_userspace { false };
static constexpr size_t m_kernel_stack_size = PAGE_SIZE * 1;
static constexpr size_t m_userspace_stack_size = PAGE_SIZE * 2;
static constexpr size_t m_interrupt_stack_size = PAGE_SIZE * 2;
BAN::UniqPtr<VirtualRange> m_interrupt_stack;
BAN::UniqPtr<VirtualRange> m_stack;
uintptr_t m_rip { 0 };
uintptr_t m_rsp { 0 };
const pid_t m_tid { 0 };
State m_state { State::NotStarted };
Process* m_process { nullptr };
bool m_in_syscall { false };
bool m_is_userspace { false };
friend class Scheduler;
};