mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:28:12 +00:00
Kernel: Use Process::require_promise() instead of REQUIRE_PROMISE()
This change lays the foundation for making the require_promise return an error hand handling the process abort outside of the syscall implementations, to avoid cases where we would leak resources. It also has the advantage that it makes removes a gs pointer read to look up the current thread, then process for every syscall. We can instead go through the Process this pointer in most cases.
This commit is contained in:
parent
c4f60844c5
commit
bad6d50b86
61 changed files with 133 additions and 132 deletions
|
@ -14,7 +14,7 @@ namespace Kernel {
|
|||
ErrorOr<FlatPtr> Process::sys$create_thread(void* (*entry)(void*), Userspace<const Syscall::SC_create_thread_params*> user_params)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(thread);
|
||||
require_promise(Pledge::thread);
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
unsigned detach_state = params.detach_state;
|
||||
|
@ -74,7 +74,7 @@ ErrorOr<FlatPtr> Process::sys$create_thread(void* (*entry)(void*), Userspace<con
|
|||
void Process::sys$exit_thread(Userspace<void*> exit_value, Userspace<void*> stack_location, size_t stack_size)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(thread);
|
||||
require_promise(Pledge::thread);
|
||||
|
||||
if (this->thread_count() == 1) {
|
||||
// If this is the last thread, instead kill the process.
|
||||
|
@ -98,7 +98,7 @@ void Process::sys$exit_thread(Userspace<void*> exit_value, Userspace<void*> stac
|
|||
ErrorOr<FlatPtr> Process::sys$detach_thread(pid_t tid)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(thread);
|
||||
require_promise(Pledge::thread);
|
||||
auto thread = Thread::from_tid(tid);
|
||||
if (!thread || thread->pid() != pid())
|
||||
return ESRCH;
|
||||
|
@ -113,7 +113,7 @@ ErrorOr<FlatPtr> Process::sys$detach_thread(pid_t tid)
|
|||
ErrorOr<FlatPtr> Process::sys$join_thread(pid_t tid, Userspace<void**> exit_value)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(thread);
|
||||
require_promise(Pledge::thread);
|
||||
|
||||
auto thread = Thread::from_tid(tid);
|
||||
if (!thread || thread->pid() != pid())
|
||||
|
@ -148,7 +148,7 @@ ErrorOr<FlatPtr> Process::sys$join_thread(pid_t tid, Userspace<void**> exit_valu
|
|||
ErrorOr<FlatPtr> Process::sys$kill_thread(pid_t tid, int signal)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(thread);
|
||||
require_promise(Pledge::thread);
|
||||
|
||||
if (signal < 0 || signal >= 32)
|
||||
return EINVAL;
|
||||
|
@ -166,7 +166,7 @@ ErrorOr<FlatPtr> Process::sys$kill_thread(pid_t tid, int signal)
|
|||
ErrorOr<FlatPtr> Process::sys$set_thread_name(pid_t tid, Userspace<const char*> user_name, size_t user_name_length)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(stdio);
|
||||
require_promise(Pledge::stdio);
|
||||
|
||||
auto name = TRY(try_copy_kstring_from_user(user_name, user_name_length));
|
||||
|
||||
|
@ -185,7 +185,7 @@ ErrorOr<FlatPtr> Process::sys$set_thread_name(pid_t tid, Userspace<const char*>
|
|||
ErrorOr<FlatPtr> Process::sys$get_thread_name(pid_t tid, Userspace<char*> buffer, size_t buffer_size)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(thread);
|
||||
require_promise(Pledge::thread);
|
||||
if (buffer_size == 0)
|
||||
return EINVAL;
|
||||
|
||||
|
@ -212,7 +212,7 @@ ErrorOr<FlatPtr> Process::sys$get_thread_name(pid_t tid, Userspace<char*> buffer
|
|||
ErrorOr<FlatPtr> Process::sys$gettid()
|
||||
{
|
||||
VERIFY_NO_PROCESS_BIG_LOCK(this)
|
||||
REQUIRE_PROMISE(stdio);
|
||||
require_promise(Pledge::stdio);
|
||||
return Thread::current()->tid().value();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue