This source file includes following definitions.
- bss_sbrk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include <config.h>
22
23 #include "sheap.h"
24
25 #include <stdio.h>
26 #include "lisp.h"
27 #include <unistd.h>
28 #include <stdlib.h>
29
30 static int debug_sheap;
31
32 char bss_sbrk_buffer[STATIC_HEAP_SIZE];
33 char *max_bss_sbrk_ptr;
34
35 void *
36 bss_sbrk (ptrdiff_t request_size)
37 {
38 static char *bss_sbrk_ptr;
39
40 if (!bss_sbrk_ptr)
41 {
42 max_bss_sbrk_ptr = bss_sbrk_ptr = bss_sbrk_buffer;
43 #ifdef CYGWIN
44
45 sbrk (4096);
46 #endif
47 }
48
49 int used = bss_sbrk_ptr - bss_sbrk_buffer;
50
51 if (request_size < -used)
52 {
53 printf (("attempt to free too much: "
54 "avail %d used %d failed request %"pD"d\n"),
55 STATIC_HEAP_SIZE, used, request_size);
56 exit (-1);
57 return 0;
58 }
59 else if (STATIC_HEAP_SIZE - used < request_size)
60 {
61 printf ("static heap exhausted: avail %d used %d failed request %"pD"d\n",
62 STATIC_HEAP_SIZE, used, request_size);
63 exit (-1);
64 return 0;
65 }
66
67 void *ret = bss_sbrk_ptr;
68 bss_sbrk_ptr += request_size;
69 if (max_bss_sbrk_ptr < bss_sbrk_ptr)
70 max_bss_sbrk_ptr = bss_sbrk_ptr;
71 if (debug_sheap)
72 {
73 if (request_size < 0)
74 printf ("freed size %"pD"d\n", request_size);
75 else
76 printf ("allocated %p size %"pD"d\n", ret, request_size);
77 }
78 return ret;
79 }