mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 20:28:11 +00:00
Kernel: Don't allocate memory for names of processes and threads
Instead, use the FixedCharBuffer class to ensure we always use a static buffer storage for these names. This ensures that if a Process or a Thread were created, there's a guarantee that setting a new name will never fail, as only copying of strings should be done to that static storage. The limits which are set are 32 characters for processes' names and 64 characters for thread names - this is because threads' names could be more verbose than processes' names.
This commit is contained in:
parent
0d30f558f4
commit
3fd4997fc2
22 changed files with 102 additions and 110 deletions
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Concepts.h>
|
||||
#include <AK/FixedStringBuffer.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/IntrusiveList.h>
|
||||
#include <AK/IntrusiveListRelaxedConst.h>
|
||||
|
@ -193,13 +194,13 @@ public:
|
|||
};
|
||||
|
||||
template<typename EntryFunction>
|
||||
static ErrorOr<ProcessAndFirstThread> create_kernel_process(NonnullOwnPtr<KString> name, EntryFunction entry, u32 affinity = THREAD_AFFINITY_DEFAULT, RegisterProcess do_register = RegisterProcess::Yes)
|
||||
static ErrorOr<ProcessAndFirstThread> create_kernel_process(StringView name, EntryFunction entry, u32 affinity = THREAD_AFFINITY_DEFAULT, RegisterProcess do_register = RegisterProcess::Yes)
|
||||
{
|
||||
auto* entry_func = new EntryFunction(move(entry));
|
||||
return create_kernel_process(move(name), &Process::kernel_process_trampoline<EntryFunction>, entry_func, affinity, do_register);
|
||||
return create_kernel_process(name, &Process::kernel_process_trampoline<EntryFunction>, entry_func, affinity, do_register);
|
||||
}
|
||||
|
||||
static ErrorOr<ProcessAndFirstThread> create_kernel_process(NonnullOwnPtr<KString> name, void (*entry)(void*), void* entry_data = nullptr, u32 affinity = THREAD_AFFINITY_DEFAULT, RegisterProcess do_register = RegisterProcess::Yes);
|
||||
static ErrorOr<ProcessAndFirstThread> create_kernel_process(StringView name, void (*entry)(void*), void* entry_data = nullptr, u32 affinity = THREAD_AFFINITY_DEFAULT, RegisterProcess do_register = RegisterProcess::Yes);
|
||||
static ErrorOr<ProcessAndFirstThread> create_user_process(StringView path, UserID, GroupID, Vector<NonnullOwnPtr<KString>> arguments, Vector<NonnullOwnPtr<KString>> environment, RefPtr<TTY>);
|
||||
static void register_new(Process&);
|
||||
|
||||
|
@ -207,7 +208,7 @@ public:
|
|||
|
||||
virtual void remove_from_secondary_lists();
|
||||
|
||||
ErrorOr<NonnullRefPtr<Thread>> create_kernel_thread(void (*entry)(void*), void* entry_data, u32 priority, NonnullOwnPtr<KString> name, u32 affinity = THREAD_AFFINITY_DEFAULT, bool joinable = true);
|
||||
ErrorOr<NonnullRefPtr<Thread>> create_kernel_thread(void (*entry)(void*), void* entry_data, u32 priority, StringView name, u32 affinity = THREAD_AFFINITY_DEFAULT, bool joinable = true);
|
||||
|
||||
bool is_profiling() const { return m_profiling; }
|
||||
void set_profiling(bool profiling) { m_profiling = profiling; }
|
||||
|
@ -228,8 +229,9 @@ public:
|
|||
static RefPtr<Process> from_pid_ignoring_jails(ProcessID);
|
||||
static SessionID get_sid_from_pgid(ProcessGroupID pgid);
|
||||
|
||||
SpinlockProtected<NonnullOwnPtr<KString>, LockRank::None> const& name() const;
|
||||
void set_name(NonnullOwnPtr<KString>);
|
||||
using Name = FixedStringBuffer<32>;
|
||||
SpinlockProtected<Name, LockRank::None> const& name() const;
|
||||
void set_name(StringView);
|
||||
|
||||
ProcessID pid() const
|
||||
{
|
||||
|
@ -612,8 +614,9 @@ private:
|
|||
bool add_thread(Thread&);
|
||||
bool remove_thread(Thread&);
|
||||
|
||||
Process(NonnullOwnPtr<KString> name, NonnullRefPtr<Credentials>, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> current_directory, RefPtr<Custody> executable, RefPtr<TTY> tty, UnveilNode unveil_tree, UnveilNode exec_unveil_tree, UnixDateTime creation_time);
|
||||
static ErrorOr<ProcessAndFirstThread> create(NonnullOwnPtr<KString> name, UserID, GroupID, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> current_directory = nullptr, RefPtr<Custody> executable = nullptr, RefPtr<TTY> = nullptr, Process* fork_parent = nullptr);
|
||||
Process(StringView name, NonnullRefPtr<Credentials>, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> current_directory, RefPtr<Custody> executable, RefPtr<TTY> tty, UnveilNode unveil_tree, UnveilNode exec_unveil_tree, UnixDateTime creation_time);
|
||||
static ErrorOr<ProcessAndFirstThread> create_with_forked_name(UserID, GroupID, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> current_directory = nullptr, RefPtr<Custody> executable = nullptr, RefPtr<TTY> = nullptr, Process* fork_parent = nullptr);
|
||||
static ErrorOr<ProcessAndFirstThread> create(StringView name, UserID, GroupID, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> current_directory = nullptr, RefPtr<Custody> executable = nullptr, RefPtr<TTY> = nullptr, Process* fork_parent = nullptr);
|
||||
ErrorOr<NonnullRefPtr<Thread>> attach_resources(NonnullOwnPtr<Memory::AddressSpace>&&, Process* fork_parent);
|
||||
static ProcessID allocate_pid();
|
||||
|
||||
|
@ -684,7 +687,7 @@ private:
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
SpinlockProtected<NonnullOwnPtr<KString>, LockRank::None> m_name;
|
||||
SpinlockProtected<Name, LockRank::None> m_name;
|
||||
|
||||
SpinlockProtected<OwnPtr<Memory::AddressSpace>, LockRank::None> m_space;
|
||||
|
||||
|
@ -1046,7 +1049,7 @@ struct AK::Formatter<Kernel::Process> : AK::Formatter<FormatString> {
|
|||
ErrorOr<void> format(FormatBuilder& builder, Kernel::Process const& value)
|
||||
{
|
||||
return value.name().with([&](auto& process_name) {
|
||||
return AK::Formatter<FormatString>::format(builder, "{}({})"sv, process_name->view(), value.pid().value());
|
||||
return AK::Formatter<FormatString>::format(builder, "{}({})"sv, process_name.representable_view(), value.pid().value());
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue