Compare commits

...

3 Commits

Author SHA1 Message Date
Bananymous 6840a8983c Kernel: Make sure MSB is not set on SMO keys 2024-05-29 20:01:12 +03:00
Bananymous a1b3490764 Kernel: Improve random number generation for unsigned types 2024-05-29 20:00:47 +03:00
Bananymous 076f1efecb Kernel: Fix 32 bit fast page locking
I forgot to change this when changing the lock type. 32 bit boots again
fine :D
2024-05-29 19:44:39 +03:00
4 changed files with 12 additions and 11 deletions

View File

@ -178,7 +178,7 @@ namespace Kernel
ASSERT(s_kernel);
ASSERT(paddr);
SpinLockGuard _(s_fast_page_lock);
ASSERT(s_fast_page_lock.current_processor_has_lock());
constexpr uint64_t pdpte = (fast_page() >> 30) & 0x1FF;
constexpr uint64_t pde = (fast_page() >> 21) & 0x1FF;
@ -198,7 +198,7 @@ namespace Kernel
{
ASSERT(s_kernel);
SpinLockGuard _(s_fast_page_lock);
ASSERT(s_fast_page_lock.current_processor_has_lock());
constexpr uint64_t pdpte = (fast_page() >> 30) & 0x1FF;
constexpr uint64_t pde = (fast_page() >> 21) & 0x1FF;

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

@ -11,14 +11,12 @@ namespace Kernel
static void initialize();
static uint32_t get_u32();
static uint64_t get_u64();
template<typename T>
static T get();
template<BAN::unsigned_integral T> requires (sizeof(T) == 4)
static T get() { return Random::get_u32(); }
template<BAN::unsigned_integral T> requires (sizeof(T) == 8)
static T get() { return Random::get_u64(); }
};
template<>
inline uint32_t Random::get<uint32_t>() { return Random::get_u32(); }
template<>
inline uint64_t Random::get<uint64_t>() { return Random::get_u64(); }
}

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;