1 /* simulate `sbrk' with an array in .bss, for `unexec' support for Cygwin;
2 complete rewrite of xemacs Cygwin `unexec' code
4 Copyright (C) 2004-2017 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or (at
11 your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
28 #include <stdlib.h> /* for exit */
30 static int debug_sheap
;
32 char bss_sbrk_buffer
[STATIC_HEAP_SIZE
];
33 char *max_bss_sbrk_ptr
;
34 bool bss_sbrk_did_unexec
;
37 bss_sbrk (ptrdiff_t request_size
)
39 static char *bss_sbrk_ptr
;
43 max_bss_sbrk_ptr
= bss_sbrk_ptr
= bss_sbrk_buffer
;
45 /* Force space for fork to work. */
50 int used
= bss_sbrk_ptr
- bss_sbrk_buffer
;
52 if (request_size
< -used
)
54 printf (("attempt to free too much: "
55 "avail %d used %d failed request %"pD
"d\n"),
56 STATIC_HEAP_SIZE
, used
, request_size
);
60 else if (STATIC_HEAP_SIZE
- used
< request_size
)
62 printf ("static heap exhausted: avail %d used %d failed request %"pD
"d\n",
63 STATIC_HEAP_SIZE
, used
, request_size
);
68 void *ret
= bss_sbrk_ptr
;
69 bss_sbrk_ptr
+= request_size
;
70 if (max_bss_sbrk_ptr
< bss_sbrk_ptr
)
71 max_bss_sbrk_ptr
= bss_sbrk_ptr
;
75 printf ("freed size %"pD
"d\n", request_size
);
77 printf ("allocated %p size %"pD
"d\n", ret
, request_size
);