haze: use alignment, invalidate cached use values in console

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

View file

@ -64,6 +64,10 @@ namespace haze {
m_reactor = reactor; m_reactor = reactor;
m_object_heap = object_heap; 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. */ /* Get whether we are launched in applet mode. */
AppletType applet_type = appletGetAppletType(); AppletType applet_type = appletGetAppletType();
m_is_applet_mode = applet_type != AppletType_Application && applet_type != AppletType_SystemApplication; m_is_applet_mode = applet_type != AppletType_Application && applet_type != AppletType_SystemApplication;

View file

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

View file

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