kernel: Store a thread's parent directly instead of its parent's PID
This commit is contained in:
parent
58eb2d7703
commit
4616997f5b
@ -125,12 +125,12 @@ Result<u64> sys_fork(Registers* regs, SyscallArgs)
|
||||
|
||||
thread->state = ThreadState::Runnable;
|
||||
thread->is_kernel = false;
|
||||
thread->parent_id = current->id;
|
||||
thread->fp_data.save();
|
||||
thread->name = current->name;
|
||||
thread->auth = current->auth;
|
||||
thread->current_directory = current->current_directory;
|
||||
thread->current_directory_path = move(current_directory_path);
|
||||
thread->parent = current;
|
||||
|
||||
for (int i = 0; i < FD_MAX; i++) { thread->fd_table[i] = current->fd_table[i]; }
|
||||
|
||||
|
@ -8,7 +8,7 @@ Result<u64> sys_exit(Registers*, SyscallArgs args)
|
||||
Thread* current = Scheduler::current();
|
||||
|
||||
Scheduler::for_each_child(current, [](Thread* child) {
|
||||
child->parent_id = 1;
|
||||
child->parent = Scheduler::init_thread();
|
||||
return true;
|
||||
});
|
||||
|
||||
|
@ -9,7 +9,9 @@ Result<u64> sys_getpid(Registers*, SyscallArgs)
|
||||
|
||||
Result<u64> sys_getppid(Registers*, SyscallArgs)
|
||||
{
|
||||
return Scheduler::current()->parent_id;
|
||||
auto* parent = Scheduler::current()->parent;
|
||||
|
||||
return parent ? parent->id : 0;
|
||||
}
|
||||
|
||||
Result<u64> sys_getuid(Registers*, SyscallArgs)
|
||||
|
@ -17,7 +17,7 @@ Result<u64> sys_waitpid(Registers*, SyscallArgs args)
|
||||
{
|
||||
thread = TRY(Result<Thread*>::from_option(Scheduler::find_by_pid(pid), ESRCH));
|
||||
|
||||
if (thread->parent_id != current->id) return err(ECHILD);
|
||||
if (thread->parent && thread->parent != current) return err(ECHILD);
|
||||
|
||||
while (thread->state != ThreadState::Exited)
|
||||
{
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
static Thread g_idle;
|
||||
static Thread* g_current = nullptr;
|
||||
static Thread* g_init = nullptr;
|
||||
|
||||
static const usize TICKS_PER_TIMESLICE = 20;
|
||||
|
||||
@ -23,7 +24,7 @@ namespace Scheduler
|
||||
g_idle.set_ip((u64)CPU::idle_loop);
|
||||
g_idle.state = ThreadState::Idle;
|
||||
g_idle.is_kernel = true;
|
||||
g_idle.parent_id = 0;
|
||||
g_idle.parent = nullptr;
|
||||
g_idle.name = "[idle]";
|
||||
|
||||
g_idle.ticks_left = 1;
|
||||
@ -52,6 +53,11 @@ namespace Scheduler
|
||||
return &g_idle;
|
||||
}
|
||||
|
||||
Thread* init_thread()
|
||||
{
|
||||
return g_init;
|
||||
}
|
||||
|
||||
Result<void> new_kernel_thread_impl(Thread* thread, const char* name)
|
||||
{
|
||||
// If anything fails, make sure to clean up.
|
||||
@ -66,8 +72,6 @@ namespace Scheduler
|
||||
|
||||
thread->stack = thread_stack;
|
||||
|
||||
thread->parent_id = 0;
|
||||
|
||||
thread->name = name;
|
||||
|
||||
thread->is_kernel = true;
|
||||
@ -119,7 +123,6 @@ namespace Scheduler
|
||||
thread->is_kernel = false;
|
||||
thread->id = 1;
|
||||
thread->name = name;
|
||||
thread->parent_id = 0;
|
||||
thread->auth = Credentials { .uid = 0, .euid = 0, .suid = 0, .gid = 0, .egid = 0, .sgid = 0 };
|
||||
|
||||
Vector<String> args;
|
||||
@ -143,6 +146,7 @@ namespace Scheduler
|
||||
thread->sp(), thread->kernel_stack.top());
|
||||
|
||||
g_threads.append(thread);
|
||||
g_init = thread;
|
||||
|
||||
return thread;
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ namespace Scheduler
|
||||
|
||||
Thread* current();
|
||||
Thread* idle();
|
||||
Thread* init_thread();
|
||||
|
||||
Result<void> new_kernel_thread(u64 address, const char* name);
|
||||
Result<void> new_kernel_thread(void (*func)(void), const char* name);
|
||||
@ -33,7 +34,7 @@ namespace Scheduler
|
||||
{
|
||||
for (Thread* current = thread; current; current = g_threads.next(current).value_or(nullptr))
|
||||
{
|
||||
if (current->parent_id == thread->id)
|
||||
if (current->parent == thread)
|
||||
{
|
||||
bool should_continue = callback(current);
|
||||
if (!should_continue) return;
|
||||
|
@ -55,7 +55,6 @@ struct Thread : public LinkedListNode<Thread>
|
||||
Registers regs;
|
||||
|
||||
u64 id;
|
||||
u64 parent_id;
|
||||
|
||||
Credentials auth;
|
||||
|
||||
@ -90,6 +89,8 @@ struct Thread : public LinkedListNode<Thread>
|
||||
String current_directory_path = {};
|
||||
SharedPtr<VFS::Inode> current_directory = {};
|
||||
|
||||
Thread* parent { nullptr };
|
||||
|
||||
PageDirectory* directory;
|
||||
|
||||
bool is_idle()
|
||||
|
Loading…
Reference in New Issue
Block a user