# HG changeset patch # User olivierg # Date 1082062583 0 # Node ID 2364237fbc0f5c243cf0800eb21e557b870630ce # Parent 92f7301e4a233d38f2dd5aa6b454186ace520893 [xemacs-hg @ 2004-04-15 20:56:17 by olivierg] Moving the dump file inside the executable diff -r 92f7301e4a23 -r 2364237fbc0f lib-src/ChangeLog --- a/lib-src/ChangeLog Thu Apr 15 15:27:38 2004 +0000 +++ b/lib-src/ChangeLog Thu Apr 15 20:56:23 2004 +0000 @@ -1,3 +1,9 @@ +2003-12-07 Olivier Galibert + + * Makefile.in.in (insert-data-in-exec): Added target. + + * insert-data-in-exec.c: Added. + 2004-03-22 Stephen J. Turnbull * XEmacs 21.5.17 "chayote" is released. @@ -359,7 +365,6 @@ * XEmacs 21.5.0 "alfalfa" is released. ->>>>>>> 1.136 2000-08-01 Jon Schewe * gnuclient.c (filename_expand): Let Cygwin convert Windows path diff -r 92f7301e4a23 -r 2364237fbc0f lib-src/Makefile.in.in --- a/lib-src/Makefile.in.in Thu Apr 15 15:27:38 2004 +0000 +++ b/lib-src/Makefile.in.in Thu Apr 15 20:56:23 2004 +0000 @@ -129,7 +129,7 @@ ## Things that XEmacs uses during the build process itself. ## Not installed. -BUILD_UTILITIES = make-path make-dump-id +BUILD_UTILITIES = make-path make-dump-id insert-data-in-exec EXES = ${PUBLIC_INSTALLABLE_EXES} ${PRIVATE_INSTALLABLE_EXES} ${BUILD_UTILITIES} SCRIPTS = ${PUBLIC_INSTALLABLE_SCRIPTS} ${PRIVATE_INSTALLABLE_SCRIPTS} @@ -375,6 +375,9 @@ make-dump-id: ${srcdir}/make-dump-id.c $(CC) $(cflags) ${srcdir}/make-dump-id.c $(ldflags) -o $@ +insert-data-in-exec: ${srcdir}/insert-data-in-exec.c + $(CC) $(cflags) ${srcdir}/insert-data-in-exec.c $(ldflags) -o $@ + cflags_gnuserv = $(CFLAGS) $(cppflags) $(c_switch_all) ldflags_gnuserv = $(LDFLAGS) $(ld_switch_all) @libs_xauth@ $(ld_libs_general) gnuslib.o: ${srcdir}/gnuslib.c ${srcdir}/gnuserv.h ../src/config.h diff -r 92f7301e4a23 -r 2364237fbc0f lib-src/insert-data-in-exec.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib-src/insert-data-in-exec.c Thu Apr 15 20:56:23 2004 +0000 @@ -0,0 +1,199 @@ +/* Copies the dump file inside the xemacs executable */ + +#include +#include +#include + +static const unsigned char key[] = { + 255, + 6, + 1, + 2, + 3, + 4, + 255, + 3, + 9, + 62, + 255, + 10, + 4, + 61, + 255 +}; + +int main(int argc, char **argv) +{ + FILE *te, *xe, *dump; + unsigned char *xed, *p; + long size, size_dump, size1, i; + long max_size, offset; + + char msg[65536]; + + if(argc != 6 && (argc != 3 || strcmp(argv[1], "-s"))) { + fprintf(stderr, "Usage:\n%s temacs xemacs.dmp xemacs size offset\n%s -s xemacs.dmp\n", argv[0], argv[0]); + exit(1); + } + + if(argc == 3) { + sprintf(msg, "Opening %s failed", argv[2]); + dump = fopen(argv[2], "rb+"); + if(!dump) { + perror(msg); + exit(1); + } + + if(fseek(dump, 0, SEEK_END)) { + perror("fseek end dump"); + exit(1); + } + + size = ftell(dump); + if(size == -1) { + perror("ftell dump"); + exit(1); + } + + printf("%ld\n", size); + exit(0); + } + + + max_size = strtol(argv[4], 0, 10); + offset = strtol(argv[5], 0, 10); + + sprintf(msg, "Opening %s failed", argv[1]); + te = fopen(argv[1], "rb"); + if(!te) { + perror(msg); + exit(1); + } + + if(fseek(te, 0, SEEK_END)) { + perror("fseek end"); + exit(1); + } + + size = ftell(te); + if(size == -1) { + perror("ftell"); + exit(1); + } + + if(fseek(te, 0, SEEK_SET)) { + perror("fseek beginning"); + exit(1); + } + + xed = malloc(size); + if(!xed) { + perror("malloc"); + exit(1); + } + + size1 = fread(xed, 1, size, te); + if(size1 != size) { + if(ferror(te)) { + perror("fread temacs"); + exit(1); + } + fprintf(stderr, "Fread returned %ld, expected %ld ?\n", size1, size); + exit(1); + } + + if(fclose(te)) { + perror("fclose temacs"); + exit(1); + } + + p = xed; + for(i=0; i max_size) { + fprintf(stderr, "Dump file too big for available space (max=%ld, dump=%ld)\n", max_size, size); + exit(2); + } + + if(fseek(dump, 0, SEEK_SET)) { + perror("fseek beginning dump"); + exit(1); + } + + size1 = fread(xed+i+offset, 1, size_dump, dump); + if(size1 != size_dump) { + if(ferror(dump)) { + perror("fread dump"); + exit(1); + } + fprintf(stderr, "Fread dump returned %ld, expected %ld ?\n", size1, size_dump); + exit(1); + } + + if(fclose(dump)) { + perror("fclose dump"); + exit(1); + } + + memset(xed+i, 0, offset); + + xed[i ] = size_dump; + xed[i+1] = size_dump >> 8; + xed[i+2] = size_dump >> 16; + xed[i+3] = size_dump >> 24; + + fprintf(stderr, "dumped_data found at offset 0x%lx, patching.\n", i); + + sprintf(msg, "Opening %s failed", argv[3]); + xe = fopen(argv[3], "wb"); + if(!xe) { + perror(msg); + exit(1); + } + + size1 = fwrite(xed, 1, size, xe); + if(size1 != size) { + if(ferror(xe)) { + perror("fwrite xemacs"); + exit(1); + } + fprintf(stderr, "Fwrite xemacs returned %ld, expected %ld ?\n", size1, size); + exit(1); + } + + if(fclose(xe)) { + perror("fclose xemacs"); + exit(1); + } + + exit(0); +} + diff -r 92f7301e4a23 -r 2364237fbc0f src/ChangeLog --- a/src/ChangeLog Thu Apr 15 15:27:38 2004 +0000 +++ b/src/ChangeLog Thu Apr 15 20:56:23 2004 +0000 @@ -1,3 +1,17 @@ +2003-12-07 Olivier Galibert + + * Makefile.in.in: Add in-executable dump file support. + + * dump-data.h (dumped_data_get): Added. + + * dump-data.c: Added. + + * emacs.c (main_1): Add support for -si. + + * dumper.c (pdump_ram_try): Added. Tries getting the dump file + from within the executable itself. + (pdump_load): Call pdump_ram_try. + 2004-04-15 Jerry James * data.c (Fstring_to_number): Skip leading '-' when finding the diff -r 92f7301e4a23 -r 2364237fbc0f src/Makefile.in.in --- a/src/Makefile.in.in Thu Apr 15 15:27:38 2004 +0000 +++ b/src/Makefile.in.in Thu Apr 15 20:56:23 2004 +0000 @@ -417,6 +417,10 @@ DUMP_TARGET = $(PROGNAME).dmp RAW_EXE = $(PROGNAME) DUMP_ID = dump-id.o +#ifndef WIN32_NATIVE +DUMP_TARGET = $(PROGNAME) +RAW_EXE = temacs +#endif #else DUMP_TARGET = $(PROGNAME) RAW_EXE = temacs @@ -536,14 +540,18 @@ ## (2) Link the XEmacs executable -temacs_deps = $(link_deps) $(DUMP_ID) - -temacs_link_args = \ - $(start_flags) $(ldflags) \ - -o $@ $(start_files) $(objs) $(otherobjs) $(DUMP_ID) $(LIBES) - -$(RAW_EXE): $(temacs_deps) - $(LD) $(temacs_link_args) +#if !defined(PDUMP) || defined(WIN32_NATIVE) +$(RAW_EXE): $(link_deps) $(DUMP_ID) + $(LD) $(start_flags) $(ldflags) -o $@ $(start_files) $(objs) $(otherobjs) $(DUMP_ID) $(LIBES) +#else +$(RAW_EXE): $(link_deps) $(DUMP_ID) + if test -f dump-size ; then \ + $(CC) -c $(cflags) -DMAX_SIZE=`cat dump-size` $(SRC)/dump-data.c ;\ + else \ + $(CC) -c $(cflags) -DMAX_SIZE=0 $(SRC)/dump-data.c ;\ + fi + $(LD) $(start_flags) $(ldflags) -o $@ $(start_files) $(objs) $(otherobjs) $(DUMP_ID) dump-data.o $(LIBES) +#endif ## (3) Update the .elc's needed for dumping @@ -586,6 +594,26 @@ @$(RM) $@ $(dump_temacs) #endif +#if defined(PDUMP) && !defined(WIN32_NATIVE) + if test -f dump-size; then \ + $(LIB_SRC)/insert-data-in-exec $(RAW_EXE) $(DUMP_TARGET).dmp $(DUMP_TARGET) `$(DO_TEMACS) -si`; \ + ret=$$? ; \ + if test $${ret} -eq 2; then \ + $(RM) dump-size ; \ + else \ + if test $${ret} -eq 1; then \ + exit 1; \ + else \ + chmod +x $(DUMP_TARGET) ; \ + fi ; \ + fi ; \ + fi + if ! test -f dump-size; then \ + $(LIB_SRC)/insert-data-in-exec -s $(DUMP_TARGET).dmp > dump-size ; \ + $(RM) dump-data.o $(DUMP_TARGET) $(DUMP_TARGET).dmp $(RAW_EXE);\ + $(RECURSIVE_MAKE) $@; \ + fi +#endif ## (6) Update the remaining .elc's, post-dumping diff -r 92f7301e4a23 -r 2364237fbc0f src/dump-data.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dump-data.c Thu Apr 15 20:56:23 2004 +0000 @@ -0,0 +1,83 @@ +/* Static array to put the dumped data in and its management + Copyright (C) 2003 Olivier Galibert + +This file is part of XEmacs. + +XEmacs is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +XEmacs is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with XEmacs; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* Synched up with: Not in FSF. */ + +/* Mule-ized? Mwahahahahahaha */ + +/* Magic values by Larry McVoy to prevent every known compiler, including + an especially perverse HP-UX one, from putting the array in BSS. +*/ + + +#include +#include "lisp.h" +#include "dump-data.h" + +/* 4 bytes for the data size, 4096 for alignment */ + +static unsigned char dumped_data[MAX_SIZE+4096+4] = { + 255, + 6, + 1, + 2, + 3, + 4, + 255, + 3, + 9, + 62, + 255, + 10, + 4, + 61, + 255 +}; + +size_t +dumped_data_size(void) +{ + return dumped_data[0] | (dumped_data[1] << 8) | (dumped_data[2] << 16) | (dumped_data[3] << 24); +} + +size_t +dumped_data_max_size(void) +{ + return MAX_SIZE; +} + +size_t +dumped_data_align_offset(void) +{ + EMACS_INT iptr = (EMACS_INT)dumped_data; + EMACS_INT iptr2; + iptr2 = (iptr+4+4095) & ~(EMACS_INT)4095; + + return iptr2-iptr; +} + +unsigned char * +dumped_data_get(void) +{ + EMACS_INT iptr = (EMACS_INT)dumped_data; + iptr = (iptr+4+4095) & ~(EMACS_INT)4095; + return (unsigned char *)iptr; +} + diff -r 92f7301e4a23 -r 2364237fbc0f src/dump-data.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dump-data.h Thu Apr 15 20:56:23 2004 +0000 @@ -0,0 +1,38 @@ +/* Static array to put the dumped data in and its management + Copyright (C) 2003 Olivier Galibert + +This file is part of XEmacs. + +XEmacs is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +XEmacs is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with XEmacs; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* Synched up with: Not in FSF. */ + +#ifndef INCLUDED_dump_data_h_ +#define INCLUDED_dump_data_h_ + +/* inline dumped data size */ +size_t dumped_data_size(void); + +/* maximum space available for inline data */ +size_t dumped_data_max_size(void); + +/* alignment offset for data inclusion */ +size_t dumped_data_align_offset(void); + +/* inline data */ +unsigned char *dumped_data_get(void); + +#endif diff -r 92f7301e4a23 -r 2364237fbc0f src/dumper.c --- a/src/dumper.c Thu Apr 15 15:27:38 2004 +0000 +++ b/src/dumper.c Thu Apr 15 20:56:23 2004 +0000 @@ -40,6 +40,7 @@ #ifdef HAVE_MMAP #include #endif +#include "dump-data.h" #endif typedef struct @@ -1507,6 +1508,16 @@ retry_close (fd); return 1; } + +static int +pdump_ram_try (void) +{ + pdump_start = dumped_data_get(); + pdump_length = dumped_data_size(); + + return pdump_load_check(); +} + #endif /* !WIN32_NATIVE */ @@ -1553,12 +1564,19 @@ pdump_load (const Extbyte *argv0) { Extbyte exe_path[PATH_MAX]; + #ifdef WIN32_NATIVE GetModuleFileNameA (NULL, exe_path, PATH_MAX); #else /* !WIN32_NATIVE */ Extbyte *w; const Extbyte *dir, *p; + if(pdump_ram_try()) { + pdump_load_finish(); + in_pdump = 0; + return 1; + } + in_pdump = 1; dir = argv0; if (dir[0] == '-') diff -r 92f7301e4a23 -r 2364237fbc0f src/emacs.c --- a/src/emacs.c Thu Apr 15 15:27:38 2004 +0000 +++ b/src/emacs.c Thu Apr 15 20:56:23 2004 +0000 @@ -272,6 +272,10 @@ #include "console-msw.h" #endif +#ifndef WIN32_NATIVE +#include "dump-data.h" +#endif + /* For PATH_EXEC */ #include @@ -820,6 +824,18 @@ exit (0); } + /* Handle the -si/--show-inline-info switch, which means show the + alignment and max size of the inline data and quit */ + if (argmatch (argv, argc, "-si", "--show-inline-info", 0, NULL, &skip_args)) + { +#if defined(PDUMP) || !defined(WIN32_NATIVE) + printf ("%d %d\n", dumped_data_max_size(), dumped_data_align_offset()); +#else + printf ("Portable dumper not configured or windows native; -si just forces exit.\n"); +#endif + exit (0); + } + /* Handle the --no-dump-file/-nd switch, which means don't load the dump file (ignored when not using pdump) */ if (argmatch (argv, argc, "-nd", "--no-dump-file", 0, NULL, &skip_args))