Make new and delete noexcept and return nullptr on failure
This commit is contained in:
parent
891320f7d3
commit
a63a8b32b5
@ -368,44 +368,32 @@ void dump_heap_usage()
|
|||||||
kdbgln("-- Heap memory in use by the kernel: %zu bytes", alloc_used);
|
kdbgln("-- Heap memory in use by the kernel: %zu bytes", alloc_used);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* operator new(usize size)
|
void* operator new(usize size) noexcept
|
||||||
{
|
{
|
||||||
auto rc = kmalloc(size);
|
return kmalloc(size).value_or(nullptr);
|
||||||
if (rc.has_error()) { expect(false, rc.error_string()); }
|
|
||||||
return rc.release_value();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void* operator new[](usize size)
|
void* operator new[](usize size) noexcept
|
||||||
{
|
{
|
||||||
auto rc = kmalloc(size);
|
return kmalloc(size).value_or(nullptr);
|
||||||
if (rc.has_error()) { expect(false, rc.error_string()); }
|
|
||||||
return rc.release_value();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator delete(void* p)
|
void operator delete(void* p) noexcept
|
||||||
{
|
{
|
||||||
auto rc = kfree(p);
|
kfree(p);
|
||||||
if (rc.has_error()) { expect(false, rc.error_string()); }
|
|
||||||
return rc.release_value();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator delete[](void* p)
|
void operator delete[](void* p) noexcept
|
||||||
{
|
{
|
||||||
auto rc = kfree(p);
|
kfree(p);
|
||||||
if (rc.has_error()) { expect(false, rc.error_string()); }
|
|
||||||
return rc.release_value();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator delete(void* p, usize)
|
void operator delete(void* p, usize) noexcept
|
||||||
{
|
{
|
||||||
auto rc = kfree(p);
|
kfree(p);
|
||||||
if (rc.has_error()) { expect(false, rc.error_string()); }
|
|
||||||
return rc.release_value();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator delete[](void* p, usize)
|
void operator delete[](void* p, usize) noexcept
|
||||||
{
|
{
|
||||||
auto rc = kfree(p);
|
kfree(p);
|
||||||
if (rc.has_error()) { expect(false, rc.error_string()); }
|
|
||||||
return rc.release_value();
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user