Mercurial > hg > xemacs-beta
comparison src/unexnt.c @ 169:15872534500d r20-3b11
Import from CVS: tag r20-3b11
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:46:53 +0200 |
parents | 4be1180a9e89 |
children | 41ff10fd062f |
comparison
equal
deleted
inserted
replaced
168:9851d5c6556e | 169:15872534500d |
---|---|
40 HANDLE file; | 40 HANDLE file; |
41 HANDLE file_mapping; | 41 HANDLE file_mapping; |
42 unsigned char *file_base; | 42 unsigned char *file_base; |
43 } file_data; | 43 } file_data; |
44 | 44 |
45 enum { | |
46 HEAP_UNINITIALIZED = 1, | |
47 HEAP_UNLOADED, | |
48 HEAP_LOADED | |
49 }; | |
50 | |
45 /* Basically, our "initialized" flag. */ | 51 /* Basically, our "initialized" flag. */ |
46 BOOL need_to_recreate_heap = FALSE; | 52 int heap_state = HEAP_UNINITIALIZED; |
47 | 53 |
48 /* So we can find our heap in the file to recreate it. */ | 54 /* So we can find our heap in the file to recreate it. */ |
49 unsigned long heap_index_in_executable = 0; | 55 unsigned long heap_index_in_executable = UNINIT_LONG; |
50 | 56 |
51 void open_input_file (file_data *p_file, char *name); | 57 void open_input_file (file_data *p_file, char *name); |
52 void open_output_file (file_data *p_file, char *name, unsigned long size); | 58 void open_output_file (file_data *p_file, char *name, unsigned long size); |
53 void close_file_data (file_data *p_file); | 59 void close_file_data (file_data *p_file); |
54 | 60 |
55 void get_section_info (file_data *p_file); | 61 void get_section_info (file_data *p_file); |
56 void copy_executable_and_dump_data_section (file_data *, file_data *); | 62 void copy_executable_and_dump_data_section (file_data *, file_data *); |
57 void dump_bss_and_heap (file_data *p_infile, file_data *p_outfile); | 63 void dump_bss_and_heap (file_data *p_infile, file_data *p_outfile); |
58 | 64 |
59 /* Cached info about the .data section in the executable. */ | 65 /* Cached info about the .data section in the executable. */ |
60 PUCHAR data_start_va = 0; | 66 PUCHAR data_start_va = UNINIT_PTR; |
61 DWORD data_start_file = 0; | 67 DWORD data_start_file = UNINIT_LONG; |
62 DWORD data_size = 0; | 68 DWORD data_size = UNINIT_LONG; |
63 | 69 |
64 /* Cached info about the .bss section in the executable. */ | 70 /* Cached info about the .bss section in the executable. */ |
65 PUCHAR bss_start = 0; | 71 PUCHAR bss_start = UNINIT_PTR; |
66 DWORD bss_size = 0; | 72 DWORD bss_size = UNINIT_LONG; |
67 | 73 |
68 #ifdef HAVE_NTGUI | 74 #ifdef HAVE_NTGUI |
69 HINSTANCE hinst = NULL; | 75 HINSTANCE hinst = NULL; |
70 HINSTANCE hprevinst = NULL; | 76 HINSTANCE hprevinst = NULL; |
71 LPSTR lpCmdLine = ""; | 77 LPSTR lpCmdLine = ""; |
87 /* If we're a dumped version of emacs then we need to recreate | 93 /* If we're a dumped version of emacs then we need to recreate |
88 our heap and play tricks with our .bss section. Do this before | 94 our heap and play tricks with our .bss section. Do this before |
89 start up. (WARNING: Do not put any code before this section | 95 start up. (WARNING: Do not put any code before this section |
90 that relies upon malloc () and runs in the dumped version. It | 96 that relies upon malloc () and runs in the dumped version. It |
91 won't work.) */ | 97 won't work.) */ |
92 if (need_to_recreate_heap) | 98 if (heap_state == HEAP_UNLOADED) |
93 { | 99 { |
94 char executable_path[MAX_PATH]; | 100 char executable_path[MAX_PATH]; |
95 | 101 |
96 if (GetModuleFileName (NULL, executable_path, MAX_PATH) == 0) | 102 if (GetModuleFileName (NULL, executable_path, MAX_PATH) == 0) |
97 { | 103 { |
98 exit (1); | 104 exit (1); |
99 } | 105 } |
100 recreate_heap (executable_path); | 106 recreate_heap (executable_path); |
101 need_to_recreate_heap = FALSE; | 107 heap_state = HEAP_LOADED; |
102 } | 108 } |
103 | 109 |
104 /* The default behavior is to treat files as binary and patch up | 110 /* The default behavior is to treat files as binary and patch up |
105 text files appropriately, in accordance with the MSDOS code. */ | 111 text files appropriately, in accordance with the MSDOS code. */ |
106 _fmode = O_BINARY; | 112 _fmode = O_BINARY; |
162 round_to_next ((unsigned char *) in_file.size, get_allocation_unit ()); | 168 round_to_next ((unsigned char *) in_file.size, get_allocation_unit ()); |
163 size = heap_index_in_executable + get_committed_heap_size () + bss_size; | 169 size = heap_index_in_executable + get_committed_heap_size () + bss_size; |
164 open_output_file (&out_file, out_filename, size); | 170 open_output_file (&out_file, out_filename, size); |
165 | 171 |
166 /* Set the flag (before dumping). */ | 172 /* Set the flag (before dumping). */ |
167 need_to_recreate_heap = TRUE; | 173 heap_state = HEAP_UNLOADED; |
168 | 174 |
169 copy_executable_and_dump_data_section (&in_file, &out_file); | 175 copy_executable_and_dump_data_section (&in_file, &out_file); |
170 dump_bss_and_heap (&in_file, &out_file); | 176 dump_bss_and_heap (&in_file, &out_file); |
171 | 177 |
172 close_file_data (&in_file); | 178 close_file_data (&in_file); |
390 data_size = my_edata - data_start_va; | 396 data_size = my_edata - data_start_va; |
391 } | 397 } |
392 section++; | 398 section++; |
393 } | 399 } |
394 | 400 |
395 if (!bss_start && !bss_size) | 401 if (bss_start == UNINIT_PTR && bss_size == UNINIT_LONG) |
396 { | 402 { |
397 /* Starting with MSVC 4.0, the .bss section has been eliminated | 403 /* Starting with MSVC 4.0, the .bss section has been eliminated |
398 and appended virtually to the end of the .data section. Our | 404 and appended virtually to the end of the .data section. Our |
399 only hint about where the .bss section starts in the address | 405 only hint about where the .bss section starts in the address |
400 comes from the SizeOfRawData field in the .data section | 406 comes from the SizeOfRawData field in the .data section |