Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sbrk.c « sysnecv850 « sys « libc « newlib - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2893c322fdce68392a0d9da1aafcebe7b9ee81f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <_ansi.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "sys/syscall.h"

caddr_t
_sbrk (int incr)
{
  extern char   heap_start[];	/* Defined by the linker script.  */
  static char * heap_end = NULL;
  char *        prev_heap_end;
  char *        sp = (char *) & sp;

  if (heap_end == NULL)
    heap_end = heap_start;

  prev_heap_end = heap_end;

  if (heap_end + incr > sp)
    {
#define MESSAGE "Heap and stack collision\n"
      _write (1, MESSAGE, sizeof MESSAGE);
      abort ();
    }

  heap_end += incr;

  return (caddr_t) prev_heap_end;
}