2019-06-10 21:54:23 +00:00
|
|
|
#include <cpm.h>
|
2019-06-11 18:32:00 +00:00
|
|
|
#include <stdint.h>
|
2007-04-27 22:42:41 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#define OUT_OF_MEMORY (void*)(-1) /* sbrk returns this on failure */
|
|
|
|
|
2019-06-11 18:32:00 +00:00
|
|
|
extern uint8_t _end[1];
|
2007-04-27 22:42:41 +00:00
|
|
|
|
|
|
|
int brk(void* newend)
|
|
|
|
{
|
2019-06-11 18:32:00 +00:00
|
|
|
uint8_t* p = newend;
|
2007-04-27 22:42:41 +00:00
|
|
|
|
2019-06-11 18:32:00 +00:00
|
|
|
if ((p >= cpm_ramtop) ||
|
2007-04-27 22:42:41 +00:00
|
|
|
(p < _end))
|
|
|
|
return -1;
|
|
|
|
|
2019-06-11 18:32:00 +00:00
|
|
|
cpm_ram = (uint8_t*)p;
|
2007-04-27 22:42:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-23 21:06:24 +00:00
|
|
|
void* sbrk(int increment)
|
2007-04-27 22:42:41 +00:00
|
|
|
{
|
2019-06-11 18:32:00 +00:00
|
|
|
uint8_t* old;
|
|
|
|
uint8_t* new;
|
2007-04-27 22:42:41 +00:00
|
|
|
|
|
|
|
if (increment == 0)
|
2019-06-10 21:54:23 +00:00
|
|
|
return cpm_ram;
|
2007-04-27 22:42:41 +00:00
|
|
|
|
2019-06-10 21:54:23 +00:00
|
|
|
old = cpm_ram;
|
2019-02-08 20:43:52 +00:00
|
|
|
new = old + increment;
|
|
|
|
|
|
|
|
if ((increment > 0) && (new <= old))
|
|
|
|
goto out_of_memory;
|
|
|
|
else if ((increment < 0) && (new >= old))
|
|
|
|
goto out_of_memory;
|
|
|
|
|
|
|
|
if (brk(new) < 0)
|
|
|
|
goto out_of_memory;
|
|
|
|
|
2007-04-27 22:42:41 +00:00
|
|
|
return old;
|
2019-02-08 20:43:52 +00:00
|
|
|
|
|
|
|
out_of_memory:
|
|
|
|
errno = ENOMEM;
|
|
|
|
return OUT_OF_MEMORY;
|
2007-04-27 22:42:41 +00:00
|
|
|
}
|