Last change
on this file since 678 was
444,
checked in by satin@…, 7 years ago
|
add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc
|
File size:
1.1 KB
|
Line | |
---|
1 | #include <_ansi.h> |
---|
2 | #include <sys/types.h> |
---|
3 | #include <sys/stat.h> |
---|
4 | |
---|
5 | #include "regs.S" |
---|
6 | |
---|
7 | extern char _end[]; |
---|
8 | |
---|
9 | /* FIXME: This is not ideal, since we do a get_mem_info() call for |
---|
10 | every sbrk() call. */ |
---|
11 | char * |
---|
12 | sbrk (nbytes) |
---|
13 | int nbytes; |
---|
14 | { |
---|
15 | static char *heap_ptr = _end; |
---|
16 | static char *heap_start = _end; |
---|
17 | char *base; |
---|
18 | struct s_mem { |
---|
19 | unsigned int size; |
---|
20 | unsigned int icsize; |
---|
21 | unsigned int dcsize; |
---|
22 | } mem; |
---|
23 | unsigned int avail = 0; |
---|
24 | |
---|
25 | /* The sizeof (s_mem.size) must be 4 bytes. The compiler should be |
---|
26 | able to eliminate this check */ |
---|
27 | if (sizeof (unsigned int) != 4) |
---|
28 | return (char *)-1; |
---|
29 | |
---|
30 | get_mem_info(&mem); |
---|
31 | /* NOTE: The value returned from the get_mem_info call is the amount |
---|
32 | of memory, and not the address of the (last byte + 1) */ |
---|
33 | |
---|
34 | if (((size_t)heap_ptr >= heap_start) && ((size_t)heap_ptr < (heap_start + mem.size))) { |
---|
35 | avail = (heap_start + mem.size) - (size_t)heap_ptr; |
---|
36 | base = heap_ptr; |
---|
37 | } /* else will fail since "nbytes" will be greater than zeroed "avail" value */ |
---|
38 | |
---|
39 | if ((nbytes > avail) || (heap_ptr + nbytes < _end)) |
---|
40 | base = (char *)-1; |
---|
41 | else |
---|
42 | heap_ptr += nbytes; |
---|
43 | |
---|
44 | return base; |
---|
45 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.