1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:28:12 +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:
Liav A 2023-07-17 18:34:19 +03:00 committed by Andrew Kaster
parent 0d30f558f4
commit 3fd4997fc2
22 changed files with 102 additions and 110 deletions

View file

@ -9,6 +9,7 @@
#include <AK/Concepts.h>
#include <AK/EnumBits.h>
#include <AK/Error.h>
#include <AK/FixedStringBuffer.h>
#include <AK/IntrusiveList.h>
#include <AK/Optional.h>
#include <AK/OwnPtr.h>
@ -94,11 +95,13 @@ public:
Process& process() { return m_process; }
Process const& process() const { return m_process; }
SpinlockProtected<NonnullOwnPtr<KString>, LockRank::None> const& name() const
using Name = FixedStringBuffer<64>;
SpinlockProtected<Name, LockRank::None> const& name() const
{
return m_name;
}
void set_name(NonnullOwnPtr<KString> name);
void set_name(StringView);
void finalize();
@ -1083,7 +1086,7 @@ public:
#endif
private:
Thread(NonnullRefPtr<Process>, NonnullOwnPtr<Memory::Region>, NonnullRefPtr<Timer>, NonnullOwnPtr<KString>);
Thread(NonnullRefPtr<Process>, NonnullOwnPtr<Memory::Region>, NonnullRefPtr<Timer>);
BlockResult block_impl(BlockTimeout const&, Blocker&);
@ -1221,7 +1224,7 @@ private:
FPUState m_fpu_state {};
State m_state { Thread::State::Invalid };
SpinlockProtected<NonnullOwnPtr<KString>, LockRank::None> m_name;
SpinlockProtected<Name, LockRank::None> m_name;
u32 m_priority { THREAD_PRIORITY_NORMAL };
State m_stop_state { Thread::State::Invalid };