mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48: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:
parent
5c45b0d32d
commit
b466ede1ea
4 changed files with 32 additions and 29 deletions
|
@ -60,11 +60,11 @@ int Process::sys$create_thread(void* (*entry)(void*), Userspace<const Syscall::S
|
|||
|
||||
// FIXME: Do something with guard pages?
|
||||
|
||||
auto thread = adopt(*new Thread(*this));
|
||||
if (!thread->was_created()) {
|
||||
// Could not fully create a thread
|
||||
return -ENOMEM;
|
||||
}
|
||||
auto thread_or_error = Thread::try_create(*this);
|
||||
if (thread_or_error.is_error())
|
||||
return thread_or_error.error();
|
||||
|
||||
auto& thread = thread_or_error.value();
|
||||
|
||||
// We know this thread is not the main_thread,
|
||||
// So give it a unique name until the user calls $set_thread_name on it
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue