Mercurial > emacs
changeset 12454:3f4da17a7cd8
(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.
author | Geoff Voelker <voelker@cs.washington.edu> |
---|---|
date | Fri, 30 Jun 1995 21:15:19 +0000 |
parents | 8e4f8107dcd0 |
children | 2c74dc6e82ab |
files | src/unexw32.c |
diffstat | 1 files changed, 48 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/unexw32.c Fri Jun 30 21:14:56 1995 +0000 +++ b/src/unexw32.c Fri Jun 30 21:15:19 1995 +0000 @@ -142,8 +142,8 @@ /* The size of the dumped executable is the size of the original executable plus the size of the heap and the size of the .bss section. */ - heap_index_in_executable = round_to_next (in_file.size, - get_allocation_unit ()); + heap_index_in_executable = (unsigned long) + round_to_next ((unsigned char *) in_file.size, get_allocation_unit ()); size = heap_index_in_executable + get_committed_heap_size () + bss_size; open_output_file (&out_file, out_filename, size); @@ -315,12 +315,20 @@ } if (!strcmp (section->Name, ".data")) { + /* From lastfile.c */ + extern char my_edata[]; + /* The .data section. */ ptr = (char *) nt_header->OptionalHeader.ImageBase + section->VirtualAddress; data_start_va = ptr; data_start_file = section->PointerToRawData; - data_size = get_section_size (section); + + /* We want to only write Emacs data back to the executable, + not any of the library data (if library data is included, + then a dumped Emacs won't run on system versions other + than the one Emacs was dumped on). */ + data_size = my_edata - data_start_va; } section++; } @@ -429,18 +437,12 @@ /* Ok, read in the saved .bss section and initialize all uninitialized variables. */ - total_read = 0; - size = bss_size; - bss = bss_start; - while (ReadFile (file, buffer, 512, &n_read, NULL)) + if (!ReadFile (file, bss_start, bss_size, &n_read, NULL)) { - if (n_read == 0) - break; - memcpy (bss, buffer, n_read); - bss += n_read; - total_read += n_read; + i = GetLastError (); + exit (1); } - + CloseHandle (file); } @@ -451,7 +453,7 @@ HANDLE file; HANDLE file_mapping; void *file_base; - unsigned long size, upper_size; + unsigned long size, upper_size, n_read; int i; file = CreateFile (filename, GENERIC_READ, FILE_SHARE_READ, NULL, @@ -467,17 +469,46 @@ 0, size, NULL); if (!file_mapping) { - i = GetLastError (); - exit (1); + i = GetLastError (); + exit (1); } size = get_committed_heap_size (); file_base = MapViewOfFileEx (file_mapping, FILE_MAP_COPY, 0, heap_index_in_executable, size, get_heap_start ()); - if (file_base == 0) + if (file_base != 0) + { + return; + } + + /* If we don't succeed with the mapping, then copy from the + data into the heap. */ + + CloseHandle (file_mapping); + + if (VirtualAlloc (get_heap_start (), get_committed_heap_size (), + MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE) == NULL) { i = GetLastError (); exit (1); } + + /* Seek to the location of the heap data in the executable. */ + i = heap_index_in_executable; + if (SetFilePointer (file, i, NULL, FILE_BEGIN) == 0xFFFFFFFF) + { + i = GetLastError (); + exit (1); + } + + /* Read in the data. */ + if (!ReadFile (file, get_heap_start (), + get_committed_heap_size (), &n_read, NULL)) + { + i = GetLastError (); + exit (1); + } + + CloseHandle (file); }