haze: use alignment, invalidate cached use values in console

This commit is contained in:
Liam 2023-04-15 20:48:20 -04:00
parent 48a05273be
commit d7b3676939
3 changed files with 13 additions and 9 deletions

View File

@ -64,6 +64,10 @@ namespace haze {
m_reactor = reactor;
m_object_heap = object_heap;
/* Set cached use amounts to invalid values. */
m_last_heap_used = 0xffffffffu;
m_last_heap_total = 0xffffffffu;
/* Get whether we are launched in applet mode. */
AppletType applet_type = appletGetAppletType();
m_is_applet_mode = applet_type != AppletType_Application && applet_type != AppletType_SystemApplication;

View File

@ -87,13 +87,13 @@ namespace haze {
public:
template <typename T = void>
constexpr T *Allocate(size_t n) {
/* Check for overflow. */
if (!util::CanAddWithoutOverflow(n, 7ul)) {
/* Check for overflow in alignment. */
if (!util::CanAddWithoutOverflow(n, alignof(u64) - 1)) {
return nullptr;
}
/* Round up the amount to a multiple of 8. */
n = util::AlignUp(n, 8);
/* Align the amount to satisfy allocation for u64. */
n = util::AlignUp(n, alignof(u64));
/* Check if the allocation is possible. */
if (!this->AllocationIsPossible(n)) {

View File

@ -44,7 +44,7 @@ namespace haze {
const size_t alloc_len = parent_name_len + 1 + name_len;
/* Allocate memory for the node. */
ObjectNode * const node = reinterpret_cast<ObjectNode *>(m_object_heap->Allocate(sizeof(ObjectNode) + alloc_len));
ObjectNode * const node = m_object_heap->Allocate<ObjectNode>(sizeof(ObjectNode) + alloc_len);
R_UNLESS(node != nullptr, haze::ResultOutOfMemory());
{