#include "assert.h"
#include "malloc.h"

struct arena {
  uint8_t * mem;
  uint32_t size;
  uint32_t ix;
};

static uint8_t arena_mem[0x100000];

static struct arena arena = {
  .mem = arena_mem,
  .size = (sizeof (arena_mem)),
  .ix = 0,
};

void malloc_arena_reset()
{
  arena.ix = 0;
}

void * malloc_arena(uint32_t size)
{
  if (size == 0)
    return nullptr;

  assert((arena.ix & (~3)) == arena.ix);
  void * ptr = &arena.mem[arena.ix];
  size = (size + 3) & (~3);
  arena.ix += size;
  return ptr;
}
