annotate src/w32heap.c @ 24103:4adfa5300fd8

(RVA_TO_PTR): Redefine to convert RVA to address in current process. (round_to_next): Obsolete function removed. (preload_heap_section): New variable. (data_region_size): Obsolete variable removed. (allocate_heap): Modified to determine end of static heap section used during preload, and use that as initial base address for dynamic heap instead of hard-coded value. (sbrk): Remove call to allocate_heap; handled by init_heap. Skip calls to commit or decommit pages when allocating from static heap section during preload. (recreate_heap): Obsolete function removed. (init_heap): New function to initialize internal sbrk heap variables. Uses static heap section during preload, otherwise calls allocate_heap to reserve a heap region dynamically. (round_heap): Use ROUND_UP macro instead of round_to_next.
author Andrew Innes <andrewi@gnu.org>
date Sun, 17 Jan 1999 19:22:55 +0000
parents 79e077f57e7c
children fb9574318fa0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16884
36babc489b0c Change all uses of win95, winnt, and win32
Geoff Voelker <voelker@cs.washington.edu>
parents: 16593
diff changeset
1 /* Heap management routines for GNU Emacs on the Microsoft W32 API.
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 Copyright (C) 1994 Free Software Foundation, Inc.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 12452
diff changeset
4 This file is part of GNU Emacs.
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 12452
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 12452
diff changeset
7 it under the terms of the GNU General Public License as published by
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 12452
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 12452
diff changeset
9 any later version.
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 12452
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 12452
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 12452
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 12452
diff changeset
14 GNU General Public License for more details.
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 12452
diff changeset
16 You should have received a copy of the GNU General Public License
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 12452
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 12452
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 12452
diff changeset
19 Boston, MA 02111-1307, USA.
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 Geoff Voelker (voelker@cs.washington.edu) 7-29-94
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23
12452
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
24 #include "config.h"
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
25
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 #include <stdlib.h>
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 #include <stdio.h>
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28
16593
4ed80eda6fac Use new names for w32 files
Geoff Voelker <voelker@cs.washington.edu>
parents: 16588
diff changeset
29 #include "w32heap.h"
15143
d7d0413e95e2 Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
30 #include "lisp.h" /* for VALMASK */
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
24103
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
32 #undef RVA_TO_PTR
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
33 #define RVA_TO_PTR(rva) ((DWORD)(rva) + (DWORD)GetModuleHandle (NULL))
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
34
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 /* This gives us the page size and the size of the allocation unit on NT. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 SYSTEM_INFO sysinfo_cache;
12452
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
37 unsigned long syspage_mask = 0;
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 /* These are defined to get Emacs to compile, but are not used. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 int edata;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 int etext;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 /* The major and minor versions of NT. */
16588
481b7874a1e9 Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents: 15228
diff changeset
44 int w32_major_version;
481b7874a1e9 Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents: 15228
diff changeset
45 int w32_minor_version;
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46
19708
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
47 /* Distinguish between Windows NT and Windows 95. */
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
48 int os_subtype;
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
49
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 /* Cache information describing the NT system for later use. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 void
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 cache_system_info (void)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 union
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 struct info
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 char major;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 char minor;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 short platform;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 } info;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 DWORD data;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 } version;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 /* Cache the version of the operating system. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 version.data = GetVersion ();
16588
481b7874a1e9 Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents: 15228
diff changeset
67 w32_major_version = version.info.major;
481b7874a1e9 Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents: 15228
diff changeset
68 w32_minor_version = version.info.minor;
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69
19708
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
70 if (version.info.platform & 0x8000)
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
71 os_subtype = OS_WIN95;
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
72 else
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
73 os_subtype = OS_NT;
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
74
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 /* Cache page size, allocation unit, processor type, etc. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 GetSystemInfo (&sysinfo_cache);
12452
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
77 syspage_mask = sysinfo_cache.dwPageSize - 1;
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79
18506
bcc706aedcea Add pragma to force zero initialized
Geoff Voelker <voelker@cs.washington.edu>
parents: 16884
diff changeset
80 /* Emulate getpagesize. */
bcc706aedcea Add pragma to force zero initialized
Geoff Voelker <voelker@cs.washington.edu>
parents: 16884
diff changeset
81 int
bcc706aedcea Add pragma to force zero initialized
Geoff Voelker <voelker@cs.washington.edu>
parents: 16884
diff changeset
82 getpagesize (void)
bcc706aedcea Add pragma to force zero initialized
Geoff Voelker <voelker@cs.washington.edu>
parents: 16884
diff changeset
83 {
bcc706aedcea Add pragma to force zero initialized
Geoff Voelker <voelker@cs.washington.edu>
parents: 16884
diff changeset
84 return sysinfo_cache.dwPageSize;
bcc706aedcea Add pragma to force zero initialized
Geoff Voelker <voelker@cs.washington.edu>
parents: 16884
diff changeset
85 }
bcc706aedcea Add pragma to force zero initialized
Geoff Voelker <voelker@cs.washington.edu>
parents: 16884
diff changeset
86
24103
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
87 /* Info for managing our preload heap, which is essentially a fixed size
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
88 data area in the executable. */
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
89 PIMAGE_SECTION_HEADER preload_heap_section;
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 /* Info for keeping track of our heap. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 unsigned char *data_region_base = NULL;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 unsigned char *data_region_end = NULL;
12452
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
94 unsigned char *real_data_region_end = NULL;
11943
ea533622fb8b (reserved_heap_size,allocate_heap): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11385
diff changeset
95 unsigned long reserved_heap_size = 0;
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 /* The start of the data segment. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 unsigned char *
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 get_data_start (void)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 return data_region_base;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 /* The end of the data segment. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 unsigned char *
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 get_data_end (void)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 return data_region_end;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110
11943
ea533622fb8b (reserved_heap_size,allocate_heap): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11385
diff changeset
111 static char *
ea533622fb8b (reserved_heap_size,allocate_heap): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11385
diff changeset
112 allocate_heap (void)
ea533622fb8b (reserved_heap_size,allocate_heap): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11385
diff changeset
113 {
24103
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
114 /* Try to get as much as possible of the address range from the end of
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
115 the preload heap section up to the usable address limit. Since GNU
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
116 malloc can handle gaps in the memory it gets from sbrk, we can
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
117 simply set the sbrk pointer to the base of the new heap region. */
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
118 unsigned long base =
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
119 ROUND_UP ((RVA_TO_PTR (preload_heap_section->VirtualAddress)
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
120 + preload_heap_section->Misc.VirtualSize),
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
121 get_allocation_unit ());
15143
d7d0413e95e2 Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
122 unsigned long end = 1 << VALBITS; /* 256MB */
15208
01588278fceb (allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents: 15143
diff changeset
123 void *ptr = NULL;
11943
ea533622fb8b (reserved_heap_size,allocate_heap): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11385
diff changeset
124
15208
01588278fceb (allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents: 15143
diff changeset
125 while (!ptr && (base < end))
01588278fceb (allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents: 15143
diff changeset
126 {
01588278fceb (allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents: 15143
diff changeset
127 reserved_heap_size = end - base;
01588278fceb (allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents: 15143
diff changeset
128 ptr = VirtualAlloc ((void *) base,
01588278fceb (allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents: 15143
diff changeset
129 get_reserved_heap_size (),
01588278fceb (allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents: 15143
diff changeset
130 MEM_RESERVE,
01588278fceb (allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents: 15143
diff changeset
131 PAGE_NOACCESS);
01588278fceb (allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents: 15143
diff changeset
132 base += 0x00100000; /* 1MB increment */
01588278fceb (allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents: 15143
diff changeset
133 }
15228
ae9888a75348 (allocate_heap): Clean up conditional.
Richard M. Stallman <rms@gnu.org>
parents: 15208
diff changeset
134
15208
01588278fceb (allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents: 15143
diff changeset
135 return ptr;
11943
ea533622fb8b (reserved_heap_size,allocate_heap): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11385
diff changeset
136 }
ea533622fb8b (reserved_heap_size,allocate_heap): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11385
diff changeset
137
ea533622fb8b (reserved_heap_size,allocate_heap): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11385
diff changeset
138
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 /* Emulate Unix sbrk. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 void *
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 sbrk (unsigned long increment)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 void *result;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 long size = (long) increment;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 result = data_region_end;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 /* If size is negative, shrink the heap by decommitting pages. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 if (size < 0)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 {
12452
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
151 int new_size;
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
152 unsigned char *new_data_region_end;
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
153
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 size = -size;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 /* Sanity checks. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 if ((data_region_end - size) < data_region_base)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 return NULL;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159
12452
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
160 /* We can only decommit full pages, so allow for
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
161 partial deallocation [cga]. */
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
162 new_data_region_end = (data_region_end - size);
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
163 new_data_region_end = (unsigned char *)
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
164 ((long) (new_data_region_end + syspage_mask) & ~syspage_mask);
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
165 new_size = real_data_region_end - new_data_region_end;
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
166 real_data_region_end = new_data_region_end;
24103
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
167 if (new_size > 0)
12452
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
168 {
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
169 /* Decommit size bytes from the end of the heap. */
24103
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
170 if (using_dynamic_heap
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
171 && !VirtualFree (real_data_region_end, new_size, MEM_DECOMMIT))
12452
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
172 return NULL;
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
173 }
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 data_region_end -= size;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 /* If size is positive, grow the heap by committing reserved pages. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 else if (size > 0)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 /* Sanity checks. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 if ((data_region_end + size) >
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (data_region_base + get_reserved_heap_size ()))
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 return NULL;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 /* Commit more of our heap. */
24103
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
186 if (using_dynamic_heap
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
187 && VirtualAlloc (data_region_end, size, MEM_COMMIT,
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
188 PAGE_READWRITE) == NULL)
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 return NULL;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 data_region_end += size;
12452
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
191
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
192 /* We really only commit full pages, so record where
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
193 the real end of committed memory is [cga]. */
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
194 real_data_region_end = (unsigned char *)
bd304be0b491 Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11943
diff changeset
195 ((long) (data_region_end + syspage_mask) & ~syspage_mask);
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 return result;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200
24103
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
201 /* Initialize the internal heap variables used by sbrk. When running in
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
202 preload phase (ie. in the undumped executable), we rely entirely on a
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
203 fixed size heap section included in the .exe itself; this is
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
204 preserved during dumping, and truncated to the size actually used.
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
205
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
206 When running in the dumped executable, we reserve as much as possible
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
207 of the address range that is addressable by Lisp object pointers, to
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
208 supplement what is left of the preload heap. Although we cannot rely
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
209 on the dynamically allocated arena being contiguous with the static
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
210 heap area, it is not a problem because sbrk can pretend that the gap
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
211 was allocated by something else; GNU malloc detects when there is a
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
212 jump in the sbrk values, and starts a new heap block. */
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 void
24103
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
214 init_heap ()
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 {
24103
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
216 PIMAGE_DOS_HEADER dos_header;
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
217 PIMAGE_NT_HEADERS nt_header;
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
218
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
219 dos_header = (PIMAGE_DOS_HEADER) RVA_TO_PTR (0);
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
220 nt_header = (PIMAGE_NT_HEADERS) (((unsigned long) dos_header) +
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
221 dos_header->e_lfanew);
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
222 preload_heap_section = find_section ("EMHEAP", nt_header);
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223
24103
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
224 if (using_dynamic_heap)
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
225 {
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
226 data_region_base = allocate_heap ();
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
227 if (!data_region_base)
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
228 {
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
229 printf ("Error: Could not reserve dynamic heap area.\n");
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
230 exit (1);
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
231 }
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232
24103
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
233 /* Ensure that the addresses don't use the upper tag bits since
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
234 the Lisp type goes there. */
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
235 if (((unsigned long) data_region_base & ~VALMASK) != 0)
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
236 {
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
237 printf ("Error: The heap was allocated in upper memory.\n");
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
238 exit (1);
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
239 }
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
240
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
241 data_region_end = data_region_base;
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
242 real_data_region_end = data_region_end;
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
243 }
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
244 else
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
245 {
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
246 data_region_base = RVA_TO_PTR (preload_heap_section->VirtualAddress);
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
247 data_region_end = data_region_base;
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
248 real_data_region_end = data_region_end;
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
249 reserved_heap_size = preload_heap_section->Misc.VirtualSize;
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
250 }
19708
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
251
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
252 /* Update system version information to match current system. */
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
253 cache_system_info ();
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 /* Round the heap up to the given alignment. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 void
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 round_heap (unsigned long align)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 unsigned long needs_to_be;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 unsigned long need_to_alloc;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262
24103
4adfa5300fd8 (RVA_TO_PTR): Redefine to convert RVA to address in
Andrew Innes <andrewi@gnu.org>
parents: 23171
diff changeset
263 needs_to_be = (unsigned long) ROUND_UP (get_heap_end (), align);
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 need_to_alloc = needs_to_be - (unsigned long) get_heap_end ();
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 if (need_to_alloc)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 sbrk (need_to_alloc);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 }
19708
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
269
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
270 #if (_MSC_VER >= 1000)
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
271
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
272 /* MSVC 4.2 invokes these functions from mainCRTStartup to initialize
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
273 a heap via HeapCreate. They are normally defined by the runtime,
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
274 but we override them here so that the unnecessary HeapCreate call
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
275 is not performed. */
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
276
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
277 int __cdecl
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
278 _heap_init (void)
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
279 {
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
280 /* Stepping through the assembly indicates that mainCRTStartup is
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
281 expecting a nonzero success return value. */
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
282 return 1;
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
283 }
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
284
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
285 void __cdecl
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
286 _heap_term (void)
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
287 {
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
288 return;
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
289 }
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
290
16e69fbdbf0f (os_subtype): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
291 #endif