X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=src%2Funexcw.c;h=81a38b19868222aad82fc00396e6e96b991a8e1d;hb=818f224de6694aa92bf9ba77b52c8c8d0dd24999;hp=774c0faa3d52150a9fe63dc103afe5c7dbd79f47;hpb=82f6d62ee211b1d36e8f45fed3ee3edde82b6916;p=chise%2Fxemacs-chise.git.1 diff --git a/src/unexcw.c b/src/unexcw.c index 774c0fa..81a38b1 100644 --- a/src/unexcw.c +++ b/src/unexcw.c @@ -23,11 +23,13 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA /* This is a complete rewrite, some code snarfed from unexnt.c and unexec.c, Andy Piper (andy@xemacs.org) 13-1-98 */ +#include +#include "lisp.h" + #include #include #include #include -#include #include #define DONT_ENCAPSULATE /* filenames are external in unex*.c */ @@ -35,7 +37,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #define PERROR(arg) perror(arg);exit(-1) -#ifndef HAVE_A_OUT_H +#if !defined(HAVE_A_OUT_H) && !defined(WIN32_NATIVE) unexec (char *, char *, void *, void *, void *) { PERROR("cannot unexec() a.out.h not installed"); @@ -45,15 +47,21 @@ unexec (char *, char *, void *, void *, void *) #ifndef MAX_PATH #define MAX_PATH 260 #endif + +#ifdef MINGW +#include <../../include/a.out.h> +#else #include +#endif +#define STACK_SIZE 0x800000 #define ALLOC_UNIT 0xFFFF #define ALLOC_MASK ~((unsigned long)(ALLOC_UNIT)) #define ALIGN_ALLOC(addr) \ ((((unsigned long)addr) + ALLOC_UNIT) & ALLOC_MASK) /* Note that all sections must be aligned on a 0x1000 boundary so this is the minimum size that our dummy bss can be. */ -#ifdef BROKEN_GDB +#ifndef NO_DEBUG #define BSS_PAD_SIZE 0x1000 #else #define BSS_PAD_SIZE 0 @@ -92,12 +100,10 @@ if (lseek(a_out, 0, SEEK_CUR) != a) \ exit(-1); \ } -void -unexec (char *out_name, char *in_name, void *start_data, - void * d1, void * d2); /* Dump out .data and .bss sections into a new executable. */ -void unexec (char *out_name, char *in_name, void *start_data, - void * d1, void * d2) +int +unexec (char *out_name, char *in_name, uintptr_t start_data, + uintptr_t d1, uintptr_t d2) { /* ugly nt hack - should be in lisp */ int a_new, a_out = -1; @@ -137,12 +143,13 @@ void unexec (char *out_name, char *in_name, void *start_data, close(a_out); close(a_new); + return 0; } /* Flip through the executable and cache the info necessary for dumping. */ static void get_section_info (int a_out, char* a_name) { - extern int my_ebss; + extern char my_ebss[]; /* From lastfile.c */ extern char my_edata[]; @@ -291,6 +298,11 @@ copy_executable_and_dump_data_section (int a_out, int a_new) data_padding = (f_bss.s_vaddr - f_data.s_vaddr) - f_data.s_size; } + if ((new_bss_size - bss_size) < BSS_PAD_SIZE) + { + PERROR (".bss free space too small"); + } + file_sz_change=(new_bss_size + data_padding) - BSS_PAD_SIZE; new_data_size=f_ohdr.dsize + file_sz_change; @@ -310,7 +322,7 @@ copy_executable_and_dump_data_section (int a_out, int a_new) lseek (a_new, 0, SEEK_SET); /* write file header */ f_hdr.f_symptr += file_sz_change; -#ifndef BROKEN_GDB +#ifdef NO_DEBUG f_hdr.f_nscns--; #endif @@ -325,10 +337,13 @@ copy_executable_and_dump_data_section (int a_out, int a_new) f_ohdr.dsize + f_ohdr.bsize); if (new_data_size < f_ohdr.dsize + f_ohdr.bsize ) { - PERROR("new data size is < approx"); + printf("warning: new data size is < approx\n"); } f_ohdr.dsize=new_data_size; f_ohdr.bsize=BSS_PAD_SIZE; + /* Prevent stack overflow with regexp usage. */ + f_ohdr.SizeOfStackReserve = STACK_SIZE; + if (write(a_new, &f_ohdr, sizeof(f_ohdr)) != sizeof(f_ohdr)) { PERROR("failed to write optional header"); @@ -340,7 +355,7 @@ copy_executable_and_dump_data_section (int a_out, int a_new) { PERROR("failed to write text header"); } -#ifdef BROKEN_GDB +#ifndef NO_DEBUG /* Write small bss section. */ if (!sections_reversed) { @@ -360,7 +375,7 @@ copy_executable_and_dump_data_section (int a_out, int a_new) { PERROR("failed to write data header"); } -#ifdef BROKEN_GDB +#ifndef NO_DEBUG /* Write small bss section. */ if (sections_reversed) { @@ -399,7 +414,7 @@ copy_executable_and_dump_data_section (int a_out, int a_new) PERROR("failed to write data header"); } } -#ifndef BROKEN_GDB +#ifdef NO_DEBUG /* dump bss to maintain offsets */ memset(&f_bss, 0, sizeof(f_bss)); if (write(a_new, &f_bss, sizeof(f_bss)) != sizeof(f_bss))