Kernel: Make TID's be unique PID's

This is a little strange, but it's how I understand things should work.

The first thread in a new process now has TID == PID.
Additional threads subsequently spawned in that process all have unique
TID's generated by the PID allocator. TIDs are now globally unique.
This commit is contained in:
Andreas Kling 2019-12-22 11:51:24 +01:00
parent 16812f0f98
commit 4b8851bd01
Notes: sideshowbarker 2024-07-19 10:46:25 +09:00
3 changed files with 14 additions and 2 deletions

View File

@ -64,6 +64,12 @@ VirtualAddress g_return_to_ring3_from_signal_trampoline;
VirtualAddress g_return_to_ring0_from_signal_trampoline;
HashMap<String, OwnPtr<Module>>* g_modules;
pid_t Process::allocate_pid()
{
InterruptDisabler disabler;
return next_pid++;
}
void Process::initialize()
{
g_modules = new HashMap<String, OwnPtr<Module>>;
@ -854,7 +860,7 @@ Process* Process::create_kernel_process(Thread*& first_thread, String&& name, vo
Process::Process(Thread*& first_thread, const String& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring, RefPtr<Custody> cwd, RefPtr<Custody> executable, TTY* tty, Process* fork_parent)
: m_name(move(name))
, m_pid(next_pid++) // FIXME: RACE: This variable looks racy!
, m_pid(allocate_pid())
, m_uid(uid)
, m_gid(gid)
, m_euid(uid)

View File

@ -310,6 +310,7 @@ private:
friend class Region;
Process(Thread*& first_thread, const String& name, uid_t, gid_t, pid_t ppid, RingLevel, RefPtr<Custody> cwd = nullptr, RefPtr<Custody> executable = nullptr, TTY* = nullptr, Process* fork_parent = nullptr);
static pid_t allocate_pid();
Range allocate_range(VirtualAddress, size_t);

View File

@ -43,9 +43,14 @@ HashTable<Thread*>& thread_table()
Thread::Thread(Process& process)
: m_process(process)
, m_tid(process.m_next_tid++)
, m_name(process.name())
{
if (m_process.m_thread_count == 0) {
// First thread gets TID == PID
m_tid = process.pid();
} else {
m_tid = Process::allocate_pid();
}
process.m_thread_count++;
dbgprintf("Thread{%p}: New thread TID=%u in %s(%u)\n", this, m_tid, process.name().characters(), process.pid());
set_default_signal_dispositions();