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

syscalls.c « mips « libgloss - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3ab543674086bedb400d485c9e83d9962a89ff21 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <_ansi.h>
#include <sys/types.h>
#include <sys/stat.h>

#include "regs.S"

extern char _end[];

/* FIXME: This is not ideal, since we do a get_mem_info() call for
   every sbrk() call. */
char *
sbrk (nbytes)
     int nbytes;
{
  static char *heap_ptr = _end;
  static char *heap_start = _end;
  char        *base;
  struct s_mem {
    unsigned int size;
    unsigned int icsize;
    unsigned int dcsize;
  } mem;
  unsigned int avail = 0;

  /* The sizeof (s_mem.size) must be 4 bytes.  The compiler should be
     able to eliminate this check */
  if (sizeof (unsigned int) != 4)
    return (char *)-1;

  get_mem_info(&mem);
  /* NOTE: The value returned from the get_mem_info call is the amount
     of memory, and not the address of the (last byte + 1) */

  if (((size_t)heap_ptr >= heap_start) && ((size_t)heap_ptr < (heap_start + mem.size))) {
    avail = (heap_start + mem.size) - (size_t)heap_ptr;
    base = heap_ptr;
  } /* else will fail since "nbytes" will be greater than zeroed "avail" value */

  if ((nbytes > avail) || (heap_ptr + nbytes < _end))
   base = (char *)-1;
  else
   heap_ptr += nbytes;

  return base;
}