Mercurial > hg > xemacs-beta
comparison src/unexnt.c @ 398:74fd4e045ea6 r21-2-29
Import from CVS: tag r21-2-29
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:13:30 +0200 |
parents | aabb7f5b1c81 |
children | a86b2b5e0111 |
comparison
equal
deleted
inserted
replaced
397:f4aeb21a5bad | 398:74fd4e045ea6 |
---|---|
109 | 109 |
110 /* Startup code for running on NT. When we are running as the dumped | 110 /* Startup code for running on NT. When we are running as the dumped |
111 version, we need to bootstrap our heap and .bss section into our | 111 version, we need to bootstrap our heap and .bss section into our |
112 address space before we can actually hand off control to the startup | 112 address space before we can actually hand off control to the startup |
113 code supplied by NT (primarily because that code relies upon malloc ()). */ | 113 code supplied by NT (primarily because that code relies upon malloc ()). */ |
114 | |
115 /* ********************** | |
116 Hackers please remember, this _start() thingy is *not* called neither | |
117 when dumping portably, nor when running from temacs! Do not put | |
118 significant XEmacs initialization here! | |
119 ********************** */ | |
120 | |
114 void | 121 void |
115 _start (void) | 122 _start (void) |
116 { | 123 { |
117 char * p; | |
118 extern void mainCRTStartup (void); | 124 extern void mainCRTStartup (void); |
119 | 125 |
120 /* Cache system info, e.g., the NT page size. */ | 126 /* Cache system info, e.g., the NT page size. */ |
121 cache_system_info (); | 127 cache_system_info (); |
122 | 128 |
132 if (GetModuleFileName (NULL, executable_path, MAX_PATH) == 0) | 138 if (GetModuleFileName (NULL, executable_path, MAX_PATH) == 0) |
133 { | 139 { |
134 exit (1); | 140 exit (1); |
135 } | 141 } |
136 | 142 |
137 /* To allow profiling, make sure executable_path names the .exe | 143 /* #### This is super-bogus. When I rename xemacs.exe, |
138 file, not the file created by the profiler */ | 144 the renamed file still loads its heap from xemacs.exe --kkm */ |
139 p = strrchr (executable_path, '\\'); | 145 #if 0 |
140 strcpy (p+1, PATH_PROGNAME ".exe"); | 146 { |
147 /* To allow profiling, make sure executable_path names the .exe | |
148 file, not the file created by the profiler */ | |
149 char *p = strrchr (executable_path, '\\'); | |
150 strcpy (p+1, PATH_PROGNAME ".exe"); | |
151 } | |
152 #endif | |
141 | 153 |
142 recreate_heap (executable_path); | 154 recreate_heap (executable_path); |
143 heap_state = HEAP_LOADED; | 155 heap_state = HEAP_LOADED; |
144 } | 156 } |
145 | 157 |
158 /* #### This is bogus, too. _fmode is set to different values | |
159 when we run `xemacs' and `temacs run-emacs'. The sooner we | |
160 hit and fix all the weirdities this causes us, the better --kkm */ | |
161 #if 0 | |
146 /* The default behavior is to treat files as binary and patch up | 162 /* The default behavior is to treat files as binary and patch up |
147 text files appropriately, in accordance with the MSDOS code. */ | 163 text files appropriately, in accordance with the MSDOS code. */ |
148 _fmode = O_BINARY; | 164 _fmode = O_BINARY; |
165 #endif | |
149 | 166 |
150 #if 0 | 167 #if 0 |
151 /* This prevents ctrl-c's in shells running while we're suspended from | 168 /* This prevents ctrl-c's in shells running while we're suspended from |
152 having us exit. */ | 169 having us exit. */ |
153 SetConsoleCtrlHandler ((PHANDLER_ROUTINE) ctrl_c_handler, TRUE); | 170 SetConsoleCtrlHandler ((PHANDLER_ROUTINE) ctrl_c_handler, TRUE); |
259 | 276 |
260 /* File handling. */ | 277 /* File handling. */ |
261 | 278 |
262 | 279 |
263 int | 280 int |
264 open_input_file (file_data *p_file, char *filename) | 281 open_output_file (file_data *p_file, const char *filename, unsigned long size) |
265 { | |
266 HANDLE file; | |
267 HANDLE file_mapping; | |
268 void *file_base; | |
269 unsigned long size, upper_size; | |
270 | |
271 file = CreateFile (filename, GENERIC_READ, FILE_SHARE_READ, NULL, | |
272 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); | |
273 if (file == INVALID_HANDLE_VALUE) | |
274 return FALSE; | |
275 | |
276 size = GetFileSize (file, &upper_size); | |
277 file_mapping = CreateFileMapping (file, NULL, PAGE_READONLY, | |
278 0, size, NULL); | |
279 if (!file_mapping) | |
280 return FALSE; | |
281 | |
282 file_base = MapViewOfFile (file_mapping, FILE_MAP_READ, 0, 0, size); | |
283 if (file_base == 0) | |
284 return FALSE; | |
285 | |
286 p_file->name = filename; | |
287 p_file->size = size; | |
288 p_file->file = file; | |
289 p_file->file_mapping = file_mapping; | |
290 p_file->file_base = file_base; | |
291 | |
292 return TRUE; | |
293 } | |
294 | |
295 int | |
296 open_output_file (file_data *p_file, char *filename, unsigned long size) | |
297 { | 282 { |
298 HANDLE file; | 283 HANDLE file; |
299 HANDLE file_mapping; | 284 HANDLE file_mapping; |
300 void *file_base; | 285 void *file_base; |
301 | 286 |
320 p_file->file_base = file_base; | 305 p_file->file_base = file_base; |
321 | 306 |
322 return TRUE; | 307 return TRUE; |
323 } | 308 } |
324 | 309 |
325 /* Close the system structures associated with the given file. */ | |
326 void | |
327 close_file_data (file_data *p_file) | |
328 { | |
329 UnmapViewOfFile (p_file->file_base); | |
330 CloseHandle (p_file->file_mapping); | |
331 CloseHandle (p_file->file); | |
332 } | |
333 | |
334 | |
335 /* Routines to manipulate NT executable file sections. */ | 310 /* Routines to manipulate NT executable file sections. */ |
336 | 311 |
337 #ifndef DUMP_SEPARATE_SECTION | 312 #ifndef DUMP_SEPARATE_SECTION |
338 static void | 313 static void |
339 get_bss_info_from_map_file (file_data *p_infile, PUCHAR *p_bss_start, | 314 get_bss_info_from_map_file (file_data *p_infile, PUCHAR *p_bss_start, |
373 *p_bss_start = (PUCHAR) start; | 348 *p_bss_start = (PUCHAR) start; |
374 *p_bss_size = (DWORD) len; | 349 *p_bss_size = (DWORD) len; |
375 } | 350 } |
376 #endif | 351 #endif |
377 | 352 |
378 /* Return pointer to section header for section containing the given | |
379 relative virtual address. */ | |
380 IMAGE_SECTION_HEADER * | |
381 rva_to_section (DWORD rva, IMAGE_NT_HEADERS * nt_header) | |
382 { | |
383 PIMAGE_SECTION_HEADER section; | |
384 int i; | |
385 | |
386 section = IMAGE_FIRST_SECTION (nt_header); | |
387 | |
388 for (i = 0; i < nt_header->FileHeader.NumberOfSections; i++) | |
389 { | |
390 if (rva >= section->VirtualAddress | |
391 && rva < section->VirtualAddress + section->SizeOfRawData) | |
392 return section; | |
393 section++; | |
394 } | |
395 return NULL; | |
396 } | |
397 | |
398 | |
399 /* Flip through the executable and cache the info necessary for dumping. */ | 353 /* Flip through the executable and cache the info necessary for dumping. */ |
400 static void | 354 static void |
401 get_section_info (file_data *p_infile) | 355 get_section_info (file_data *p_infile) |
402 { | 356 { |
403 PIMAGE_DOS_HEADER dos_header; | 357 PIMAGE_DOS_HEADER dos_header; |