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

Kernel: PID/TID typing

This compiles, and contains exactly the same bugs as before.
The regex 'FIXME: PID/' should reveal all markers that I left behind, including:
- Incomplete conversion
- Issues or things that look fishy
- Actual bugs that will go wrong during runtime
This commit is contained in:
Ben Wiederhake 2020-08-08 17:32:34 +02:00 committed by Andreas Kling
parent f225321184
commit f5744a6f2f
26 changed files with 136 additions and 111 deletions

View file

@ -28,7 +28,7 @@
namespace Kernel {
int Process::sys$disown(pid_t pid)
int Process::sys$disown(ProcessID pid)
{
REQUIRE_PROMISE(proc);
auto process = Process::from_pid(pid);

View file

@ -282,7 +282,8 @@ int Process::do_exec(NonnullRefPtr<FileDescription> main_program_description, Ve
m_master_tls_size = master_tls_size;
m_master_tls_alignment = master_tls_alignment;
m_pid = new_main_thread->tid();
// FIXME: PID/TID BUG
m_pid = new_main_thread->tid().value();
new_main_thread->make_thread_specific_region({});
new_main_thread->reset_fpu_state();
@ -296,7 +297,7 @@ int Process::do_exec(NonnullRefPtr<FileDescription> main_program_description, Ve
tss.eip = m_entry_eip;
tss.esp = new_userspace_esp;
tss.cr3 = m_page_directory->cr3();
tss.ss2 = m_pid;
tss.ss2 = m_pid.value();
if (was_profiling)
Profiling::did_exec(path);

View file

@ -95,7 +95,7 @@ pid_t Process::sys$fork(RegisterState& regs)
}
child_first_thread->set_state(Thread::State::Skip1SchedulerPass);
return child->pid();
return child->pid().value();
}
}

View file

@ -35,7 +35,7 @@ KResult Process::do_kill(Process& process, int signal)
if (!is_superuser() && m_euid != process.m_uid && m_uid != process.m_uid)
return KResult(-EPERM);
if (process.is_ring0() && signal == SIGKILL) {
klog() << "attempted to send SIGKILL to ring 0 process " << process.name().characters() << "(" << process.pid() << ")";
klog() << "attempted to send SIGKILL to ring 0 process " << process.name().characters() << "(" << process.pid().value() << ")";
return KResult(-EPERM);
}
if (signal != 0)
@ -119,33 +119,34 @@ KResult Process::do_killself(int signal)
return KSuccess;
}
int Process::sys$kill(pid_t pid, int signal)
int Process::sys$kill(pid_t pid_or_pgid, int signal)
{
if (pid == m_pid)
if (pid_or_pgid == m_pid.value())
REQUIRE_PROMISE(stdio);
else
REQUIRE_PROMISE(proc);
if (signal < 0 || signal >= 32)
return -EINVAL;
if (pid < -1) {
if (pid == NumericLimits<i32>::min())
if (pid_or_pgid < -1) {
if (pid_or_pgid == NumericLimits<i32>::min())
return -EINVAL;
return do_killpg(-pid, signal);
return do_killpg(-pid_or_pgid, signal);
}
if (pid == -1)
if (pid_or_pgid == -1)
return do_killall(signal);
if (pid == m_pid) {
if (pid_or_pgid == m_pid.value()) {
return do_killself(signal);
}
ASSERT(pid_or_pgid >= 0);
ScopedSpinLock lock(g_processes_lock);
auto peer = Process::from_pid(pid);
auto peer = Process::from_pid(pid_or_pgid);
if (!peer)
return -ESRCH;
return do_kill(*peer, signal);
}
int Process::sys$killpg(int pgrp, int signum)
int Process::sys$killpg(pid_t pgrp, int signum)
{
REQUIRE_PROMISE(proc);
if (signum < 1 || signum >= 32)

View file

@ -32,13 +32,13 @@ namespace Kernel {
pid_t Process::sys$getpid()
{
REQUIRE_PROMISE(stdio);
return m_pid;
return m_pid.value();
}
pid_t Process::sys$getppid()
{
REQUIRE_PROMISE(stdio);
return m_ppid;
return m_ppid.value();
}
int Process::sys$set_process_icon(int icon_id)

View file

@ -44,7 +44,10 @@ int Process::sys$ptrace(Userspace<const Syscall::SC_ptrace_params*> user_params)
return result.is_error() ? result.error() : result.value();
}
bool Process::has_tracee_thread(int tracer_pid) const
/**
* "Does this process have a thread that is currently being traced by the provided process?"
*/
bool Process::has_tracee_thread(ProcessID tracer_pid) const
{
bool has_tracee = false;

View file

@ -48,14 +48,15 @@ pid_t Process::sys$setsid()
REQUIRE_PROMISE(proc);
InterruptDisabler disabler;
bool found_process_with_same_pgid_as_my_pid = false;
Process::for_each_in_pgrp(pid(), [&](auto&) {
// FIXME: PID/PGID ISSUE?
Process::for_each_in_pgrp(pid().value(), [&](auto&) {
found_process_with_same_pgid_as_my_pid = true;
return IterationDecision::Break;
});
if (found_process_with_same_pgid_as_my_pid)
return -EPERM;
m_sid = m_pid;
m_pgid = m_pid;
m_sid = m_pid.value();
m_pgid = m_pid.value();
m_tty = nullptr;
return m_sid;
}
@ -91,7 +92,7 @@ int Process::sys$setpgid(pid_t specified_pid, pid_t specified_pgid)
{
REQUIRE_PROMISE(proc);
ScopedSpinLock lock(g_processes_lock); // FIXME: Use a ProcessHandle
pid_t pid = specified_pid ? specified_pid : m_pid;
ProcessID pid = specified_pid ? ProcessID(specified_pid) : m_pid;
if (specified_pgid < 0) {
// The value of the pgid argument is less than 0, or is not a value supported by the implementation.
return -EINVAL;
@ -115,7 +116,8 @@ int Process::sys$setpgid(pid_t specified_pid, pid_t specified_pgid)
return -EPERM;
}
pid_t new_pgid = specified_pgid ? specified_pgid : process->m_pid;
// FIXME: PID/PGID INCOMPLETE
pid_t new_pgid = specified_pgid ? specified_pgid : process->m_pid.value();
pid_t current_sid = get_sid_from_pgid(process->m_pgid);
pid_t new_sid = get_sid_from_pgid(new_pgid);
if (current_sid != new_sid) {

View file

@ -70,7 +70,7 @@ int Process::sys$shbuf_create(int size, void** buffer)
int Process::sys$shbuf_allow_pid(int shbuf_id, pid_t peer_pid)
{
REQUIRE_PROMISE(shared_buffer);
if (!peer_pid || peer_pid < 0 || peer_pid == m_pid)
if (!peer_pid || peer_pid < 0 || ProcessID(peer_pid) == m_pid)
return -EINVAL;
LOCKER(shared_buffers().lock());
auto it = shared_buffers().resource().find(shbuf_id);

View file

@ -87,7 +87,7 @@ int Process::sys$create_thread(void* (*entry)(void*), Userspace<const Syscall::S
thread->make_thread_specific_region({});
thread->set_state(Thread::State::Runnable);
return thread->tid();
return thread->tid().value();
}
void Process::sys$exit_thread(void* exit_value)
@ -212,7 +212,7 @@ int Process::sys$get_thread_name(int tid, char* buffer, size_t buffer_size)
int Process::sys$gettid()
{
REQUIRE_PROMISE(stdio);
return Thread::current()->tid();
return Thread::current()->tid().value();
}
}

View file

@ -34,9 +34,12 @@ KResultOr<siginfo_t> Process::do_waitid(idtype_t idtype, int id, int options)
ScopedSpinLock lock(g_processes_lock);
if (idtype == P_PID && !Process::from_pid(id))
return KResult(-ECHILD);
// FIXME: Race: After 'lock' releases, the 'id' process might vanish.
// If that is not a problem, why check for it?
// If it is a problem, let's fix it! (Eventually.)
}
pid_t waitee_pid;
ProcessID waitee_pid { 0 };
// FIXME: WaitBlocker should support idtype/id specs directly.
if (idtype == P_ALL) {
@ -62,14 +65,15 @@ KResultOr<siginfo_t> Process::do_waitid(idtype_t idtype, int id, int options)
if (waitee_process->is_dead()) {
return reap(*waitee_process);
} else {
auto* waitee_thread = Thread::from_tid(waitee_pid);
// FIXME: PID/TID BUG
auto* waitee_thread = Thread::from_tid(waitee_pid.value());
if (!waitee_thread)
return KResult(-ECHILD);
ASSERT((options & WNOHANG) || waitee_thread->state() == Thread::State::Stopped);
siginfo_t siginfo;
memset(&siginfo, 0, sizeof(siginfo));
siginfo.si_signo = SIGCHLD;
siginfo.si_pid = waitee_process->pid();
siginfo.si_pid = waitee_process->pid().value();
siginfo.si_uid = waitee_process->uid();
switch (waitee_thread->state()) {