aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeoff Voelker1995-06-30 21:15:19 +0000
committerGeoff Voelker1995-06-30 21:15:19 +0000
commit198fdd15e517c81d36a6c504d445682bcbb3363e (patch)
treec5a74cdc849c8dc664d25f011ed4772343ac7ef8
parent783d52920c8f225a2d1974f4a50b6ddc519587a4 (diff)
downloademacs-198fdd15e517c81d36a6c504d445682bcbb3363e.tar.gz
emacs-198fdd15e517c81d36a6c504d445682bcbb3363e.zip
(get_section_info): Set the end of the data region
to be just before the start of the shared library data. (read_in_bss): Read directly into memory. (map_in_heap): Read directly into memory if unable to map.
-rw-r--r--src/unexw32.c65
1 files changed, 48 insertions, 17 deletions
diff --git a/src/unexw32.c b/src/unexw32.c
index a29393aef74..cf89f031bb9 100644
--- a/src/unexw32.c
+++ b/src/unexw32.c
@@ -142,8 +142,8 @@ unexec (char *new_name, char *old_name, void *start_data, void *start_bss,
142 142
143 /* The size of the dumped executable is the size of the original 143 /* The size of the dumped executable is the size of the original
144 executable plus the size of the heap and the size of the .bss section. */ 144 executable plus the size of the heap and the size of the .bss section. */
145 heap_index_in_executable = round_to_next (in_file.size, 145 heap_index_in_executable = (unsigned long)
146 get_allocation_unit ()); 146 round_to_next ((unsigned char *) in_file.size, get_allocation_unit ());
147 size = heap_index_in_executable + get_committed_heap_size () + bss_size; 147 size = heap_index_in_executable + get_committed_heap_size () + bss_size;
148 open_output_file (&out_file, out_filename, size); 148 open_output_file (&out_file, out_filename, size);
149 149
@@ -315,12 +315,20 @@ get_section_info (file_data *p_infile)
315 } 315 }
316 if (!strcmp (section->Name, ".data")) 316 if (!strcmp (section->Name, ".data"))
317 { 317 {
318 /* From lastfile.c */
319 extern char my_edata[];
320
318 /* The .data section. */ 321 /* The .data section. */
319 ptr = (char *) nt_header->OptionalHeader.ImageBase + 322 ptr = (char *) nt_header->OptionalHeader.ImageBase +
320 section->VirtualAddress; 323 section->VirtualAddress;
321 data_start_va = ptr; 324 data_start_va = ptr;
322 data_start_file = section->PointerToRawData; 325 data_start_file = section->PointerToRawData;
323 data_size = get_section_size (section); 326
327 /* We want to only write Emacs data back to the executable,
328 not any of the library data (if library data is included,
329 then a dumped Emacs won't run on system versions other
330 than the one Emacs was dumped on). */
331 data_size = my_edata - data_start_va;
324 } 332 }
325 section++; 333 section++;
326 } 334 }
@@ -429,18 +437,12 @@ read_in_bss (char *filename)
429 437
430 /* Ok, read in the saved .bss section and initialize all 438 /* Ok, read in the saved .bss section and initialize all
431 uninitialized variables. */ 439 uninitialized variables. */
432 total_read = 0; 440 if (!ReadFile (file, bss_start, bss_size, &n_read, NULL))
433 size = bss_size;
434 bss = bss_start;
435 while (ReadFile (file, buffer, 512, &n_read, NULL))
436 { 441 {
437 if (n_read == 0) 442 i = GetLastError ();
438 break; 443 exit (1);
439 memcpy (bss, buffer, n_read);
440 bss += n_read;
441 total_read += n_read;
442 } 444 }
443 445
444 CloseHandle (file); 446 CloseHandle (file);
445} 447}
446 448
@@ -451,7 +453,7 @@ map_in_heap (char *filename)
451 HANDLE file; 453 HANDLE file;
452 HANDLE file_mapping; 454 HANDLE file_mapping;
453 void *file_base; 455 void *file_base;
454 unsigned long size, upper_size; 456 unsigned long size, upper_size, n_read;
455 int i; 457 int i;
456 458
457 file = CreateFile (filename, GENERIC_READ, FILE_SHARE_READ, NULL, 459 file = CreateFile (filename, GENERIC_READ, FILE_SHARE_READ, NULL,
@@ -467,17 +469,46 @@ map_in_heap (char *filename)
467 0, size, NULL); 469 0, size, NULL);
468 if (!file_mapping) 470 if (!file_mapping)
469 { 471 {
470 i = GetLastError (); 472 i = GetLastError ();
471 exit (1); 473 exit (1);
472 } 474 }
473 475
474 size = get_committed_heap_size (); 476 size = get_committed_heap_size ();
475 file_base = MapViewOfFileEx (file_mapping, FILE_MAP_COPY, 0, 477 file_base = MapViewOfFileEx (file_mapping, FILE_MAP_COPY, 0,
476 heap_index_in_executable, size, 478 heap_index_in_executable, size,
477 get_heap_start ()); 479 get_heap_start ());
478 if (file_base == 0) 480 if (file_base != 0)
481 {
482 return;
483 }
484
485 /* If we don't succeed with the mapping, then copy from the
486 data into the heap. */
487
488 CloseHandle (file_mapping);
489
490 if (VirtualAlloc (get_heap_start (), get_committed_heap_size (),
491 MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE) == NULL)
492 {
493 i = GetLastError ();
494 exit (1);
495 }
496
497 /* Seek to the location of the heap data in the executable. */
498 i = heap_index_in_executable;
499 if (SetFilePointer (file, i, NULL, FILE_BEGIN) == 0xFFFFFFFF)
479 { 500 {
480 i = GetLastError (); 501 i = GetLastError ();
481 exit (1); 502 exit (1);
482 } 503 }
504
505 /* Read in the data. */
506 if (!ReadFile (file, get_heap_start (),
507 get_committed_heap_size (), &n_read, NULL))
508 {
509 i = GetLastError ();
510 exit (1);
511 }
512
513 CloseHandle (file);
483} 514}