mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:08:10 +00:00
Kernel: Protect Process::m_name with a spinlock
This also lets us remove the `get_process_name` and `set_process_name` syscalls from the big lock. :^)
This commit is contained in:
parent
b26ecca970
commit
fe7b08dad7
13 changed files with 102 additions and 42 deletions
|
@ -334,7 +334,11 @@ Process::Process(NonnullOwnPtr<KString> name, NonnullRefPtr<Credentials> credent
|
|||
protected_data.credentials = move(credentials);
|
||||
});
|
||||
|
||||
dbgln_if(PROCESS_DEBUG, "Created new process {}({})", m_name, this->pid().value());
|
||||
if constexpr (PROCESS_DEBUG) {
|
||||
this->name().with([&](auto& process_name) {
|
||||
dbgln("Created new process {}({})", process_name->view(), this->pid().value());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ErrorOr<void> Process::attach_resources(NonnullOwnPtr<Memory::AddressSpace>&& preallocated_space, LockRefPtr<Thread>& first_thread, Process* fork_parent)
|
||||
|
@ -671,7 +675,9 @@ ErrorOr<void> Process::dump_core()
|
|||
dbgln("Generating coredump for pid {} failed because coredump directory was not set.", pid().value());
|
||||
return {};
|
||||
}
|
||||
auto coredump_path = TRY(KString::formatted("{}/{}_{}_{}", coredump_directory_path->view(), name(), pid().value(), kgettimeofday().to_truncated_seconds()));
|
||||
auto coredump_path = TRY(name().with([&](auto& process_name) {
|
||||
return KString::formatted("{}/{}_{}_{}", coredump_directory_path->view(), process_name->view(), pid().value(), kgettimeofday().to_truncated_seconds());
|
||||
}));
|
||||
auto coredump = TRY(Coredump::try_create(*this, coredump_path->view()));
|
||||
return coredump->write();
|
||||
}
|
||||
|
@ -683,7 +689,9 @@ ErrorOr<void> Process::dump_perfcore()
|
|||
dbgln("Generating perfcore for pid: {}", pid().value());
|
||||
|
||||
// Try to generate a filename which isn't already used.
|
||||
auto base_filename = TRY(KString::formatted("{}_{}", name(), pid().value()));
|
||||
auto base_filename = TRY(name().with([&](auto& process_name) {
|
||||
return KString::formatted("{}_{}", process_name->view(), pid().value());
|
||||
}));
|
||||
auto perfcore_filename = TRY(KString::formatted("{}.profile", base_filename));
|
||||
LockRefPtr<OpenFileDescription> description;
|
||||
auto credentials = this->credentials();
|
||||
|
@ -721,8 +729,11 @@ void Process::finalize()
|
|||
|
||||
dbgln_if(PROCESS_DEBUG, "Finalizing process {}", *this);
|
||||
|
||||
if (veil_state() == VeilState::Dropped)
|
||||
dbgln("\x1b[01;31mProcess '{}' exited with the veil left open\x1b[0m", name());
|
||||
if (veil_state() == VeilState::Dropped) {
|
||||
name().with([&](auto& process_name) {
|
||||
dbgln("\x1b[01;31mProcess '{}' exited with the veil left open\x1b[0m", process_name->view());
|
||||
});
|
||||
}
|
||||
|
||||
if (g_init_pid != 0 && pid() == g_init_pid)
|
||||
PANIC("Init process quit unexpectedly. Exit code: {}", termination_status());
|
||||
|
@ -831,11 +842,20 @@ void Process::die()
|
|||
auto& process = *it;
|
||||
++it;
|
||||
if (process.has_tracee_thread(pid())) {
|
||||
dbgln_if(PROCESS_DEBUG, "Process {} ({}) is attached by {} ({}) which will exit", process.name(), process.pid(), name(), pid());
|
||||
if constexpr (PROCESS_DEBUG) {
|
||||
process.name().with([&](auto& process_name) {
|
||||
name().with([&](auto& name) {
|
||||
dbgln("Process {} ({}) is attached by {} ({}) which will exit", process_name->view(), process.pid(), name->view(), pid());
|
||||
});
|
||||
});
|
||||
}
|
||||
process.stop_tracing();
|
||||
auto err = process.send_signal(SIGSTOP, this);
|
||||
if (err.is_error())
|
||||
dbgln("Failed to send the SIGSTOP signal to {} ({})", process.name(), process.pid());
|
||||
if (err.is_error()) {
|
||||
process.name().with([&](auto& process_name) {
|
||||
dbgln("Failed to send the SIGSTOP signal to {} ({})", process_name->view(), process.pid());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -1077,4 +1097,16 @@ ErrorOr<NonnullRefPtr<Custody>> Process::custody_for_dirfd(int dirfd)
|
|||
return *base_description->custody();
|
||||
}
|
||||
|
||||
SpinlockProtected<NonnullOwnPtr<KString>, LockRank::None> const& Process::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void Process::set_name(NonnullOwnPtr<KString> name)
|
||||
{
|
||||
m_name.with([&](auto& this_name) {
|
||||
this_name = move(name);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue