kernel: Use pid_t internally for process IDs
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This removes a bunch of casts between pid_t and u64, and makes more sense since pid_t is literally the data type for process IDs.
This commit is contained in:
parent
5aad7d3154
commit
11df5a2ec3
@ -106,7 +106,7 @@ bool Thread::deliver_signal(int signo, Registers* current_regs)
|
||||
|
||||
memcpy(®s, current_regs, sizeof(regs));
|
||||
|
||||
kinfoln("signal: delivering signal %d for thread %ld, ip=%p, sp=%p, handler=%p, sigreturn=%p", signo, id,
|
||||
kinfoln("signal: delivering signal %d for thread %d, ip=%p, sp=%p, handler=%p, sigreturn=%p", signo, id,
|
||||
(void*)regs.rip, (void*)regs.rsp, (void*)handler.sa_handler, (void*)handler.__sa_sigreturn);
|
||||
|
||||
regs.rsp -= 128; // Skip the red zone
|
||||
|
@ -31,7 +31,7 @@ Result<void> ConsoleDevice::handle_background_process_group(bool can_succeed, in
|
||||
auto foreground_pgrp = m_foreground_process_group.value();
|
||||
|
||||
auto* current = Scheduler::current();
|
||||
if ((pid_t)current->pgid == foreground_pgrp) return {};
|
||||
if (current->pgid == foreground_pgrp) return {};
|
||||
|
||||
if ((current->signal_mask & (1 << (signo - 1))) || (current->signal_handlers[signo - 1].sa_handler == SIG_IGN))
|
||||
{
|
||||
|
@ -119,7 +119,7 @@ Result<u64> sys_execve(Registers* regs, SyscallArgs args)
|
||||
|
||||
current->has_called_exec = true;
|
||||
|
||||
kinfoln("exec: thread %lu was replaced with %s", current->id, path.chars());
|
||||
kinfoln("exec: thread %d was replaced with %s", current->id, path.chars());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -101,8 +101,8 @@ Result<u64> sys_setpgid(Registers*, SyscallArgs args)
|
||||
pid_t pgid = (pid_t)args[1];
|
||||
|
||||
auto* current = Scheduler::current();
|
||||
if (pid == 0) pid = (pid_t)current->id;
|
||||
if (pgid == 0) pgid = (pid_t)current->id;
|
||||
if (pid == 0) pid = current->id;
|
||||
if (pgid == 0) pgid = current->id;
|
||||
|
||||
if (pgid < 0) return err(EINVAL);
|
||||
|
||||
@ -113,7 +113,7 @@ Result<u64> sys_setpgid(Registers*, SyscallArgs args)
|
||||
|
||||
if (thread->has_called_exec) return err(EPERM);
|
||||
|
||||
if (pgid != (pid_t)current->id)
|
||||
if (pgid != current->id)
|
||||
{
|
||||
bool pgid_exists = false;
|
||||
Scheduler::for_each_in_process_group(pgid, [&pgid_exists](Thread*) {
|
||||
@ -133,7 +133,7 @@ Result<u64> sys_getpgid(Registers*, SyscallArgs args)
|
||||
pid_t pid = (pid_t)args[0];
|
||||
|
||||
auto* current = Scheduler::current();
|
||||
if (pid == 0) pid = (pid_t)current->id;
|
||||
if (pid == 0) pid = current->id;
|
||||
|
||||
if (pid < 0) return err(EINVAL);
|
||||
|
||||
|
@ -20,8 +20,8 @@ Result<u64> sys_pstat(Registers*, SyscallArgs args)
|
||||
auto* thread = TRY(Result<Thread*>::from_option(Scheduler::find_by_pid(pid), ESRCH));
|
||||
|
||||
struct process proc;
|
||||
proc.ps_pid = (pid_t)thread->id;
|
||||
proc.ps_ppid = thread->parent ? (pid_t)thread->parent->id : 0;
|
||||
proc.ps_pid = thread->id;
|
||||
proc.ps_ppid = thread->parent ? thread->parent->id : 0;
|
||||
proc.ps_uid = thread->auth.uid;
|
||||
proc.ps_gid = thread->auth.gid;
|
||||
proc.ps_euid = thread->auth.euid;
|
||||
|
@ -40,7 +40,7 @@ namespace Scheduler
|
||||
|
||||
g_idle.stack = idle_stack;
|
||||
|
||||
kinfoln("Created idle thread: id %lu with ip %#lx and sp %#lx", g_idle.id, g_idle.ip(), g_idle.sp());
|
||||
kinfoln("Created idle thread: id %d with ip %#lx and sp %#lx", g_idle.id, g_idle.ip(), g_idle.sp());
|
||||
|
||||
g_current = &g_idle;
|
||||
}
|
||||
@ -95,7 +95,7 @@ namespace Scheduler
|
||||
|
||||
thread->state = ThreadState::Runnable;
|
||||
|
||||
kinfoln("Created kernel thread: id %lu with ip %#lx and sp %#lx", thread->id, thread->ip(), thread->sp());
|
||||
kinfoln("Created kernel thread: id %d with ip %#lx and sp %#lx", thread->id, thread->ip(), thread->sp());
|
||||
|
||||
return thread;
|
||||
}
|
||||
@ -161,7 +161,7 @@ namespace Scheduler
|
||||
thread->signal_handlers[i] = { .sa_handler = SIG_DFL, .sa_mask = 0, .sa_flags = 0 };
|
||||
}
|
||||
|
||||
kinfoln("Created userspace thread: id %lu with ip %#.16lx and sp %#.16lx (ksp %#lx)", thread->id, thread->ip(),
|
||||
kinfoln("Created userspace thread: id %d with ip %#.16lx and sp %#.16lx (ksp %#lx)", thread->id, thread->ip(),
|
||||
thread->sp(), thread->kernel_stack.top());
|
||||
|
||||
g_threads.append(thread);
|
||||
@ -308,7 +308,7 @@ namespace Scheduler
|
||||
{
|
||||
for (auto* const thread : g_threads)
|
||||
{
|
||||
if (thread->id == (u64)pid && thread->state != ThreadState::Dying) return thread;
|
||||
if (thread->id == pid && thread->state != ThreadState::Dying) return thread;
|
||||
}
|
||||
|
||||
return {};
|
||||
@ -347,11 +347,11 @@ namespace Scheduler
|
||||
CPU::disable_interrupts();
|
||||
|
||||
kdbgln("--- BEGIN SCHEDULER DUMP ---");
|
||||
kdbgln("current at %p, id = %zu", g_current, g_current->id);
|
||||
kdbgln("current at %p, id = %d", g_current, g_current->id);
|
||||
|
||||
for (const auto* thread : g_threads)
|
||||
{
|
||||
kdbgln("%p %c [%-20s] %4zu, parent = (%-18p,%zu), state = %d, ticks: (k:%04zu,u:%04zu), status = "
|
||||
kdbgln("%p %c [%-20s] %4d, parent = (%-18p,%d), state = %d, ticks: (k:%04zu,u:%04zu), status = "
|
||||
"%d, cwd = %s",
|
||||
thread, thread->is_kernel ? 'k' : 'u', thread->name.chars(), thread->id, thread->parent,
|
||||
thread->parent ? thread->parent->id : 0, (int)thread->state, thread->kernel_ticks_self,
|
||||
|
@ -50,7 +50,7 @@ namespace Scheduler
|
||||
for (Thread* current = g_threads.first().value_or(nullptr); current;
|
||||
current = g_threads.next(current).value_or(nullptr))
|
||||
{
|
||||
if (current->pgid == (u64)group)
|
||||
if (current->pgid == group)
|
||||
{
|
||||
bool should_continue = callback(current);
|
||||
if (!should_continue) return;
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <luna/Atomic.h>
|
||||
#include <luna/PathParser.h>
|
||||
|
||||
static Atomic<u64> g_next_id;
|
||||
static Atomic<pid_t> g_next_id;
|
||||
|
||||
LinkedList<Thread> g_threads;
|
||||
|
||||
@ -29,7 +29,7 @@ Result<Thread*> new_thread()
|
||||
return thread;
|
||||
}
|
||||
|
||||
u64 next_thread_id()
|
||||
pid_t next_thread_id()
|
||||
{
|
||||
return g_next_id.load();
|
||||
}
|
||||
@ -98,9 +98,9 @@ Result<SharedPtr<VFS::Inode>> Thread::resolve_atfile(int dirfd, const String& pa
|
||||
if (parent->state == ThreadState::Waiting)
|
||||
{
|
||||
auto child = *parent->child_being_waited_for;
|
||||
if (child == -1 || child == (pid_t)id)
|
||||
if (child == -1 || child == id)
|
||||
{
|
||||
parent->child_being_waited_for = (pid_t)id;
|
||||
parent->child_being_waited_for = id;
|
||||
parent->wake_up();
|
||||
}
|
||||
}
|
||||
@ -151,7 +151,7 @@ void Thread::process_pending_signals(Registers* current_regs)
|
||||
if (pending_signals & (1 << i))
|
||||
{
|
||||
pending_signals &= ~(1 << i);
|
||||
kinfoln("signal: executing signal %d for thread %ld", signo, id);
|
||||
kinfoln("signal: executing signal %d for thread %d", signo, id);
|
||||
auto handler = signal_handlers[i];
|
||||
if (signo != SIGKILL && signo != SIGSTOP && handler.sa_handler == SIG_IGN)
|
||||
{
|
||||
|
@ -56,8 +56,8 @@ struct Thread : public LinkedListNode<Thread>
|
||||
{
|
||||
Registers regs;
|
||||
|
||||
u64 id;
|
||||
u64 pgid { 0 };
|
||||
pid_t id;
|
||||
pid_t pgid { 0 };
|
||||
|
||||
Credentials auth;
|
||||
|
||||
@ -159,6 +159,6 @@ bool is_in_kernel(Registers* regs);
|
||||
|
||||
Result<Thread*> new_thread();
|
||||
|
||||
u64 next_thread_id();
|
||||
pid_t next_thread_id();
|
||||
|
||||
extern LinkedList<Thread> g_threads;
|
||||
|
Loading…
Reference in New Issue
Block a user