changeset 2015:2364237fbc0f

[xemacs-hg @ 2004-04-15 20:56:17 by olivierg] Moving the dump file inside the executable
author olivierg
date Thu, 15 Apr 2004 20:56:23 +0000
parents 92f7301e4a23
children 6aa2e57a873e
files lib-src/ChangeLog lib-src/Makefile.in.in lib-src/insert-data-in-exec.c src/ChangeLog src/Makefile.in.in src/dump-data.c src/dump-data.h src/dumper.c src/emacs.c
diffstat 9 files changed, 414 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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  <galibert@pobox.com>
+
+	* Makefile.in.in (insert-data-in-exec): Added target.
+
+	* insert-data-in-exec.c: Added.
+
 2004-03-22  Stephen J. Turnbull  <stephen@xemacs.org>
 
 	* 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  <jpschewe@eggplant.mtu.net>
 
 	* gnuclient.c (filename_expand): Let Cygwin convert Windows path
--- 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
--- /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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+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<size-(long)sizeof(key); i++) {
+    if(!memcmp(p, key, sizeof(key)))
+      goto found;
+    p++;
+  }
+
+  fprintf(stderr, "dumped_data key not found in executable.\n");
+  exit(1);
+
+ found:
+  fprintf(stderr, "dumped_data found at offset 0x%lx, patching.\n", i);
+
+  sprintf(msg, "Opening %s failed", argv[2]);
+  dump = fopen(argv[2], "r");
+  if(!dump) {
+    perror(msg);
+    exit(1);
+  }
+
+  if(fseek(dump, 0, SEEK_END)) {
+    perror("fseek end dump");
+    exit(1);
+  }
+
+  size_dump = ftell(dump);
+  if(size_dump == -1) {
+    perror("ftell dump");
+    exit(1);
+  }
+
+  if(size_dump > 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);
+}
+
--- 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  <galibert@pobox.com>
+
+	* 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  <james@xemacs.org>
 
 	* data.c (Fstring_to_number): Skip leading '-' when finding the
--- 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
 
--- /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 <config.h>
+#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;
+}
+
--- /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
--- 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 <sys/mman.h>
 #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] == '-')
--- 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 <paths.h>
 
@@ -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))