1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:17:35 +00:00

Kernel: Allow process with multiple threads to call exec and exit

This allows a process wich has more than 1 thread to call exec, even
from a thread. This kills all the other threads, but it won't wait for
them to finish, just makes sure that they are not in a running/runable
state.

In the case where a thread does exec, the new program PID will be the
thread TID, to keep the PID == TID in the new process.

This introduces a new function inside the Process class,
kill_threads_except_self which is called on exit() too (exit with
multiple threads wasn't properly working either).

Inside the Lock class, there is the need for a new function,
clear_waiters, which removes all the waiters from the
Process::big_lock. This is needed since after a exit/exec, there should
be no other threads waiting for this lock, the threads should be simply
killed. Only queued threads should wait for this lock at this point,
since blocked threads are handled in set_should_die.
This commit is contained in:
Cristian-Bogdan SIRB 2020-02-18 14:28:28 +02:00 committed by Andreas Kling
parent 9fcb37ad30
commit 717cd5015e
8 changed files with 78 additions and 22 deletions

View file

@ -141,6 +141,8 @@ public:
gid_t egid() const { return m_egid; }
pid_t ppid() const { return m_ppid; }
pid_t exec_tid() const { return m_exec_tid; }
mode_t umask() const { return m_umask; }
bool in_group(gid_t) const;
@ -417,6 +419,9 @@ private:
Region& add_region(NonnullOwnPtr<Region>);
void kill_threads_except_self();
void kill_all_threads();
int do_exec(NonnullRefPtr<FileDescription> main_program_description, Vector<String> arguments, Vector<String> environment, RefPtr<FileDescription> interpreter_description);
ssize_t do_write(FileDescription&, const u8*, int data_size);
@ -448,6 +453,8 @@ private:
pid_t m_sid { 0 };
pid_t m_pgid { 0 };
pid_t m_exec_tid { 0 };
static const int m_max_open_file_descriptors { FD_SETSIZE };
struct FileDescriptionAndFlags {