X-Git-Url: https://git.hcoop.net/bpt/emacs.git/blobdiff_plain/8ee818927b65c6efa665e5ba13d25f985721de04..4e0f64791b6f38bfaa8d84addf7a472a15aac111:/src/unexcoff.c diff --git a/src/unexcoff.c b/src/unexcoff.c index 3e9786348c..e83042a379 100644 --- a/src/unexcoff.c +++ b/src/unexcoff.c @@ -1,5 +1,4 @@ -/* Copyright (C) 1985, 1986, 1987, 1988, 1992, 1993, 1994, 2001, 2002, 2003, - 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. +/* Copyright (C) 1985-1988, 1992-1994, 2001-2012 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -34,37 +33,13 @@ along with GNU Emacs. If not, see . */ * Modified heavily since then. * * Synopsis: - * unexec (new_name, a_name, data_start, bss_start, entry_address) - * char *new_name, *a_name; - * unsigned data_start, bss_start, entry_address; + * unexec (const char *new_name, const char *old_name); * * Takes a snapshot of the program and makes an a.out format file in the * file named by the string argument new_name. * If a_name is non-NULL, the symbol table will be taken from the given file. * On some machines, an existing a_name file is required. * - * The boundaries within the a.out file may be adjusted with the data_start - * and bss_start arguments. Either or both may be given as 0 for defaults. - * - * Data_start gives the boundary between the text segment and the data - * segment of the program. The text segment can contain shared, read-only - * program code and literal data, while the data segment is always unshared - * and unprotected. Data_start gives the lowest unprotected address. - * The value you specify may be rounded down to a suitable boundary - * as required by the machine you are using. - * - * Specifying zero for data_start means the boundary between text and data - * should not be the same as when the program was loaded. - * - * Bss_start indicates how much of the data segment is to be saved in the - * a.out file and restored when the program is executed. It gives the lowest - * unsaved address, and is rounded up to a page boundary. The default when 0 - * is given assumes that the entire data segment is to be stored, including - * the previous data and bss as well as any additional storage allocated with - * break (2). - * - * The new file is set up to start at entry_address. - * * If you make improvements I'd like to get them too. * harpo!utah-cs!thomas, thomas@Utah-20 * @@ -75,6 +50,8 @@ along with GNU Emacs. If not, see . */ */ #include +#include "unexec.h" + #define PERROR(file) report_error (file, new) #ifndef CANNOT_DUMP /* all rest of file! */ @@ -84,6 +61,7 @@ along with GNU Emacs. If not, see . */ #ifdef MSDOS #include /* for O_RDONLY, O_RDWR */ #include /* for _crt0_startup_flags and its bits */ +#include static int save_djgpp_startup_flags; #define filehdr external_filehdr #define scnhdr external_scnhdr @@ -120,15 +98,7 @@ struct aouthdr #include -#ifndef O_RDONLY -#define O_RDONLY 0 -#endif -#ifndef O_RDWR -#define O_RDWR 2 -#endif - - -extern char *start_of_data (); /* Start of initialized data */ +#include "mem-limits.h" static long block_copy_start; /* Old executable start point */ static struct filehdr f_hdr; /* File header */ @@ -153,10 +123,8 @@ static int pagemask; #include #include "lisp.h" -static -report_error (file, fd) - char *file; - int fd; +static void +report_error (const char *file, int fd) { if (fd) close (fd); @@ -167,20 +135,17 @@ report_error (file, fd) #define ERROR1(msg,x) report_error_1 (new, msg, x, 0); return -1 #define ERROR2(msg,x,y) report_error_1 (new, msg, x, y); return -1 -static -report_error_1 (fd, msg, a1, a2) - int fd; - char *msg; - int a1, a2; +static void +report_error_1 (int fd, const char *msg, int a1, int a2) { close (fd); error (msg, a1, a2); } -static int make_hdr (); -static int copy_text_and_data (); -static int copy_sym (); -static void mark_x (); +static int make_hdr (int, int, const char *, const char *); +static int copy_text_and_data (int, int); +static int copy_sym (int, int, const char *, const char *); +static void mark_x (const char *); /* **************************************************************** * make_hdr @@ -189,19 +154,16 @@ static void mark_x (); * Modify the text and data sizes. */ static int -make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name) - int new, a_out; - unsigned data_start, bss_start, entry_address; - char *a_name; - char *new_name; +make_hdr (int new, int a_out, + const char *a_name, const char *new_name) { - int tem; auto struct scnhdr f_thdr; /* Text section header */ auto struct scnhdr f_dhdr; /* Data section header */ auto struct scnhdr f_bhdr; /* Bss section header */ auto struct scnhdr scntemp; /* Temporary section header */ register int scns; - unsigned int bss_end; + unsigned int bss_start; + unsigned int data_start; pagemask = getpagesize () - 1; @@ -210,23 +172,8 @@ make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name) data_start = ADDR_CORRECT (data_start); data_start = data_start & ~pagemask; /* (Down) to page boundary. */ - bss_end = ADDR_CORRECT (sbrk (0)) + pagemask; - bss_end &= ~ pagemask; - - /* Adjust data/bss boundary. */ - if (bss_start != 0) - { - bss_start = (ADDR_CORRECT (bss_start) + pagemask); - /* (Up) to page bdry. */ - bss_start &= ~ pagemask; - if (bss_start > bss_end) - { - ERROR1 ("unexec: Specified bss_start (%u) is past end of program", - bss_start); - } - } - else - bss_start = bss_end; + bss_start = ADDR_CORRECT (sbrk (0)) + pagemask; + bss_start &= ~ pagemask; if (data_start > bss_start) /* Can't have negative data size. */ { @@ -307,7 +254,7 @@ make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name) f_hdr.f_flags |= (F_RELFLG | F_EXEC); f_ohdr.dsize = bss_start - f_ohdr.data_start; - f_ohdr.bsize = bss_end - bss_start; + f_ohdr.bsize = 0; f_thdr.s_size = f_ohdr.tsize; f_thdr.s_scnptr = sizeof (f_hdr) + sizeof (f_ohdr); f_thdr.s_scnptr += (f_hdr.f_nscns) * (sizeof (f_thdr)); @@ -363,12 +310,10 @@ make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name) } -write_segment (new, ptr, end) - int new; - register char *ptr, *end; +void +write_segment (int new, const char *ptr, const char *end) { register int i, nwrite, ret; - char buf[80]; /* This is the normal amount to write at once. It is the size of block that NFS uses. */ int writesize = 1 << 13; @@ -411,8 +356,7 @@ write_segment (new, ptr, end) * Copy the text and data segments from memory to the new a.out */ static int -copy_text_and_data (new, a_out) - int new, a_out; +copy_text_and_data (int new, int a_out) { register char *end; register char *ptr; @@ -456,9 +400,7 @@ copy_text_and_data (new, a_out) * Copy the relocation information and symbol table from the a.out to the new */ static int -copy_sym (new, a_out, a_name, new_name) - int new, a_out; - char *a_name, *new_name; +copy_sym (int new, int a_out, const char *a_name, const char *new_name) { char page[1024]; int n; @@ -494,8 +436,7 @@ copy_sym (new, a_out, a_name, new_name) * After successfully building the new a.out, mark it executable */ static void -mark_x (name) - char *name; +mark_x (const char *name) { struct stat sbuf; int um; @@ -535,10 +476,8 @@ mark_x (name) a reasonable size buffer. But I don't have time to work on such things, so I am installing it as submitted to me. -- RMS. */ -adjust_lnnoptrs (writedesc, readdesc, new_name) - int writedesc; - int readdesc; - char *new_name; +int +adjust_lnnoptrs (int writedesc, int readdesc, const char *new_name) { register int nsyms; register int new; @@ -585,11 +524,10 @@ adjust_lnnoptrs (writedesc, readdesc, new_name) * * driving logic. */ -unexec (new_name, a_name, data_start, bss_start, entry_address) - char *new_name, *a_name; - unsigned data_start, bss_start, entry_address; +void +unexec (const char *new_name, const char *a_name) { - int new, a_out = -1; + int new = -1, a_out = -1; if (a_name && (a_out = open (a_name, O_RDONLY)) < 0) { @@ -600,25 +538,20 @@ unexec (new_name, a_name, data_start, bss_start, entry_address) PERROR (new_name); } - if (make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name) < 0 + if (make_hdr (new, a_out, a_name, new_name) < 0 || copy_text_and_data (new, a_out) < 0 || copy_sym (new, a_out, a_name, new_name) < 0 || adjust_lnnoptrs (new, a_out, new_name) < 0 ) { close (new); - /* unlink (new_name); /* Failed, unlink new a.out */ - return -1; + return; } close (new); if (a_out >= 0) close (a_out); mark_x (new_name); - return 0; } #endif /* not CANNOT_DUMP */ - -/* arch-tag: 62409b69-e27a-4a7c-9413-0210d6b54e7f - (do not change this comment) */