1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:38:12 +00:00

Kernel: Make sure we can allocate kernel stack before creating thread

Wrap thread creation in a Thread::try_create() helper that first
allocates a kernel stack region. If that allocation fails, we propagate
an ENOMEM error to the caller.

This avoids the situation where a thread is half-constructed, without a
valid kernel stack, and avoids having to do messy cleanup in that case.
This commit is contained in:
Andreas Kling 2021-02-07 18:13:51 +01:00
parent 5c45b0d32d
commit b466ede1ea
4 changed files with 32 additions and 29 deletions

View file

@ -99,7 +99,7 @@ public:
static void initialize();
explicit Thread(NonnullRefPtr<Process>);
static KResultOr<NonnullRefPtr<Thread>> try_create(NonnullRefPtr<Process>);
~Thread();
static RefPtr<Thread> from_tid(ThreadID);
@ -1157,15 +1157,15 @@ public:
}
#endif
bool was_created() const
bool is_handling_page_fault() const
{
return m_kernel_stack_region;
return m_handling_page_fault;
}
bool is_handling_page_fault() const { return m_handling_page_fault; }
void set_handling_page_fault(bool b) { m_handling_page_fault = b; }
private:
Thread(NonnullRefPtr<Process>, NonnullOwnPtr<Region> kernel_stack_region);
IntrusiveListNode m_process_thread_list_node;
int m_runnable_priority { -1 };