Prereq: 2007-01-30 diff -ur emacs-18.59-orig/src/ChangeLog emacs-18.59/src/ChangeLog --- emacs-18.59-orig/src/ChangeLog 2007-01-30 01:00:00.000000000 +0100 +++ emacs-18.59/src/ChangeLog 2008-10-21 15:04:59.000000000 +0200 @@ -1,3 +1,13 @@ +2008-10-21 Ulrich Mueller + + * emacs.c: Handle gap between end of BSS and heap, backported + from Emacs 22. Original changes by Jan Djarv and Masatake YAMATO. + This fixes dumping on Linux 2.6.25. + (main): Unconditionally set PER_LINUX32 | ADDR_NO_RANDOMIZE + and exec ourself again if HAVE_PERSONALITY_LINUX32 is defined. + + * s-linux.h (HAVE_PERSONALITY_LINUX32): Define. + 2007-01-30 Ulrich Mueller * x11term.c (internal_socket_read): Handle XK_BackSpace key. diff -ur emacs-18.59-orig/src/emacs.c emacs-18.59/src/emacs.c --- emacs-18.59-orig/src/emacs.c 2007-01-29 21:47:56.000000000 +0100 +++ emacs-18.59/src/emacs.c 2008-10-21 15:04:59.000000000 +0200 @@ -78,6 +78,13 @@ #endif #endif +#ifdef HAVE_PERSONALITY_LINUX32 +#include +#ifndef ADDR_NO_RANDOMIZE +#define ADDR_NO_RANDOMIZE 0x0040000 +#endif +#endif + #ifndef O_RDWR #define O_RDWR 2 #endif @@ -242,6 +249,27 @@ extern int errno; extern void malloc_warning (); +#ifdef HAVE_PERSONALITY_LINUX32 + /* See if there is a gap between the end of BSS and the heap. + In that case, set personality and exec ourself again. */ + if (!initialized + && strcmp (argv[argc-1], "dump") == 0 + && !getenv ("EMACS_HEAP_EXEC")) + { + /* Set this so we only do this once. */ + putenv ("EMACS_HEAP_EXEC=true"); + + /* A flag to turn off address randomization which is introduced + in linux kernel shipped with fedora core 4 */ + personality (PER_LINUX32 | ADDR_NO_RANDOMIZE); + + execvp (argv[0], argv); + + /* If the exec fails, try to dump anyway. */ + perror ("execvp"); + } +#endif /* HAVE_PERSONALITY_LINUX32 */ + /* Map in shared memory, if we are using that. */ #ifdef HAVE_SHM if (argc > 1 && !strcmp (argv[1], "-nl")) diff -ur emacs-18.59-orig/src/s-linux.h emacs-18.59/src/s-linux.h --- emacs-18.59-orig/src/s-linux.h 2007-01-29 21:47:56.000000000 +0100 +++ emacs-18.59/src/s-linux.h 2008-05-11 01:58:40.000000000 +0200 @@ -161,6 +161,7 @@ #define HAVE_SYS_SIGLIST /* we have a (non-standard) sys_siglist */ #define SYS_SIGLIST_DECLARED #define HAVE_GETWD /* cure conflict with getcwd? */ +#define HAVE_PERSONALITY_LINUX32 /* personality LINUX32 can be set */ #define NO_SIOCTL_H /* don't have sioctl.h */ #define SYSV_SYSTEM_DIR /* use dirent.h */