Kernel: Make sure MSB is not set on SMO keys

This commit is contained in:
Bananymous 2024-05-29 20:01:12 +03:00
parent a1b3490764
commit 6840a8983c
2 changed files with 6 additions and 3 deletions

View File

@ -14,7 +14,7 @@ namespace Kernel
class SharedMemoryObjectManager
{
public:
using Key = uint32_t;
using Key = size_t;
public:
static BAN::ErrorOr<void> initialize();

View File

@ -32,9 +32,12 @@ namespace Kernel
LockGuard _(m_mutex);
Key key = Random::get<Key>();
// NOTE: don't set the top bit so cast to signed is not negative
auto generate_key = []() { return Random::get<Key>() & (~(Key)0 >> 1); };
Key key = generate_key();
while (m_objects.contains(key))
key = Random::get<Key>();
key = generate_key();
TRY(m_objects.insert(key, object));
return key;