/*
  Functions to get suitably aligned core memory from the
  environment and return it (if possible).
  OS9 memory is 256-bytes page aligned. And allocations will always
  request full pages.
*/

#include <stdlib.h>
#include <os9.h>

static char *top;

void *__getcore(size_t s)
{
  char *p = sbrk(s);

  if (p == (char *)-1)
    return NULL;

  top = p + s;  /* remember top of allocations */
  return p;
}

void __freecore(void *p,size_t s)
{
  /* we can only free from the top of allocations */
  if ((char *)p+s >= top)
    (void)sbrk((char *)p-top);
}
