mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 02:28:12 +00:00
Kernel: Make MemoryManager API type-safe for Region::Access enum
Increase type-safety moving the MemoryManager APIs which take a Region::Access to actually use that type instead of a `u8`. Eventually the actually m_access can be moved there as well, but I hit some weird bug where it wasn't using the correct operators in `set_access_bit(..)` even though it's declared (and tested). Something to fix-up later.
This commit is contained in:
parent
c825159f01
commit
eaef57443c
6 changed files with 39 additions and 35 deletions
|
@ -48,7 +48,7 @@ namespace Kernel {
|
|||
|
||||
class KBufferImpl : public RefCounted<KBufferImpl> {
|
||||
public:
|
||||
static RefPtr<KBufferImpl> try_create_with_size(size_t size, u8 access, const char* name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve)
|
||||
static RefPtr<KBufferImpl> try_create_with_size(size_t size, Region::Access access, const char* name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve)
|
||||
{
|
||||
auto region = MM.allocate_kernel_region(page_round_up(size), name, access, strategy);
|
||||
if (!region)
|
||||
|
@ -56,7 +56,7 @@ public:
|
|||
return adopt(*new KBufferImpl(region.release_nonnull(), size, strategy));
|
||||
}
|
||||
|
||||
static RefPtr<KBufferImpl> try_create_with_bytes(ReadonlyBytes bytes, u8 access, const char* name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve)
|
||||
static RefPtr<KBufferImpl> try_create_with_bytes(ReadonlyBytes bytes, Region::Access access, const char* name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve)
|
||||
{
|
||||
auto region = MM.allocate_kernel_region(page_round_up(bytes.size()), name, access, strategy);
|
||||
if (!region)
|
||||
|
@ -65,12 +65,12 @@ public:
|
|||
return adopt(*new KBufferImpl(region.release_nonnull(), bytes.size(), strategy));
|
||||
}
|
||||
|
||||
static RefPtr<KBufferImpl> create_with_size(size_t size, u8 access, const char* name, AllocationStrategy strategy = AllocationStrategy::Reserve)
|
||||
static RefPtr<KBufferImpl> create_with_size(size_t size, Region::Access access, const char* name, AllocationStrategy strategy = AllocationStrategy::Reserve)
|
||||
{
|
||||
return try_create_with_size(size, access, name, strategy);
|
||||
}
|
||||
|
||||
static RefPtr<KBufferImpl> copy(const void* data, size_t size, u8 access, const char* name)
|
||||
static RefPtr<KBufferImpl> copy(const void* data, size_t size, Region::Access access, const char* name)
|
||||
{
|
||||
auto buffer = create_with_size(size, access, name, AllocationStrategy::AllocateNow);
|
||||
if (!buffer)
|
||||
|
@ -124,7 +124,7 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] static OwnPtr<KBuffer> try_create_with_size(size_t size, u8 access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve)
|
||||
[[nodiscard]] static OwnPtr<KBuffer> try_create_with_size(size_t size, Region::Access access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve)
|
||||
{
|
||||
auto impl = KBufferImpl::try_create_with_size(size, access, name, strategy);
|
||||
if (!impl)
|
||||
|
@ -132,7 +132,7 @@ public:
|
|||
return adopt_own(*new KBuffer(impl.release_nonnull()));
|
||||
}
|
||||
|
||||
[[nodiscard]] static OwnPtr<KBuffer> try_create_with_bytes(ReadonlyBytes bytes, u8 access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve)
|
||||
[[nodiscard]] static OwnPtr<KBuffer> try_create_with_bytes(ReadonlyBytes bytes, Region::Access access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve)
|
||||
{
|
||||
auto impl = KBufferImpl::try_create_with_bytes(bytes, access, name, strategy);
|
||||
if (!impl)
|
||||
|
@ -140,12 +140,12 @@ public:
|
|||
return adopt_own(*new KBuffer(impl.release_nonnull()));
|
||||
}
|
||||
|
||||
[[nodiscard]] static KBuffer create_with_size(size_t size, u8 access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve)
|
||||
[[nodiscard]] static KBuffer create_with_size(size_t size, Region::Access access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve)
|
||||
{
|
||||
return KBuffer(KBufferImpl::create_with_size(size, access, name, strategy));
|
||||
}
|
||||
|
||||
[[nodiscard]] static KBuffer copy(const void* data, size_t size, u8 access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer")
|
||||
[[nodiscard]] static KBuffer copy(const void* data, size_t size, Region::Access access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer")
|
||||
{
|
||||
return KBuffer(KBufferImpl::copy(data, size, access, name));
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ public:
|
|||
[[nodiscard]] const KBufferImpl& impl() const { return *m_impl; }
|
||||
[[nodiscard]] RefPtr<KBufferImpl> take_impl() { return move(m_impl); }
|
||||
|
||||
KBuffer(const ByteBuffer& buffer, u8 access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer")
|
||||
KBuffer(const ByteBuffer& buffer, Region::Access access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer")
|
||||
: m_impl(KBufferImpl::copy(buffer.data(), buffer.size(), access, name))
|
||||
{
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue