aboutsummaryrefslogtreecommitdiffstats
path: root/src/emacs.c
diff options
context:
space:
mode:
authorJan Djärv2004-10-20 16:23:30 +0000
committerJan Djärv2004-10-20 16:23:30 +0000
commitdede27921696e4e940c93fa7335066864c93ccfd (patch)
treece72db52bdf71d9dce653075a9565016a81f8f02 /src/emacs.c
parentf17e308a43db0a5bcc847714a79f3334201d415f (diff)
downloademacs-dede27921696e4e940c93fa7335066864c93ccfd.tar.gz
emacs-dede27921696e4e940c93fa7335066864c93ccfd.zip
* emacs.c (my_heap_start, heap_bss_diff, MAX_HEAP_BSS_DIFF):
New variables and constant. (main): Calculate heap_bss_diff. If we are dumping and the heap_bss_diff is greater than MAX_HEAP_BSS_DIFF, set PER_LINUX32 and exec ourself again. (Fdump_emacs): If heap_bss_diff is greater than MAX_HEAP_BSS_DIFF print a warning. * lastfile.c: Make my_endbss and my_endbss_static available on all platforms. * Makefile.in (RUN_TEMACS): Remove @SETARCH@. * config.in (HAVE_PERSONALITY_LINUX32): Regenerate.
Diffstat (limited to 'src/emacs.c')
-rw-r--r--src/emacs.c65
1 files changed, 64 insertions, 1 deletions
diff --git a/src/emacs.c b/src/emacs.c
index 6ecfdbd4231..bb601ea8643 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -67,6 +67,10 @@ Boston, MA 02111-1307, USA. */
67#include <sys/resource.h> 67#include <sys/resource.h>
68#endif 68#endif
69 69
70#ifdef HAVE_PERSONALITY_LINUX32
71#include <sys/personality.h>
72#endif
73
70#ifndef O_RDWR 74#ifndef O_RDWR
71#define O_RDWR 2 75#define O_RDWR 2
72#endif 76#endif
@@ -192,6 +196,17 @@ int display_arg;
192 Tells GC how to save a copy of the stack. */ 196 Tells GC how to save a copy of the stack. */
193char *stack_bottom; 197char *stack_bottom;
194 198
199/* The address where the heap starts (from the first sbrk (0) call). */
200static void *my_heap_start;
201
202/* The gap between BSS end and heap start as far as we can tell. */
203static unsigned long heap_bss_diff;
204
205/* If the gap between BSS end and heap start is larger than this we try to
206 work around it, and if that fails, output a warning in dump-emacs. */
207#define MAX_HEAP_BSS_DIFF (1024*1024)
208
209
195#ifdef HAVE_WINDOW_SYSTEM 210#ifdef HAVE_WINDOW_SYSTEM
196extern Lisp_Object Vwindow_system; 211extern Lisp_Object Vwindow_system;
197#endif /* HAVE_WINDOW_SYSTEM */ 212#endif /* HAVE_WINDOW_SYSTEM */
@@ -733,7 +748,11 @@ malloc_initialize_hook ()
733 free (malloc_state_ptr); 748 free (malloc_state_ptr);
734 } 749 }
735 else 750 else
736 malloc_using_checking = getenv ("MALLOC_CHECK_") != NULL; 751 {
752 if (my_heap_start == 0)
753 my_heap_start = sbrk (0);
754 malloc_using_checking = getenv ("MALLOC_CHECK_") != NULL;
755 }
737} 756}
738 757
739void (*__malloc_initialize_hook) () = malloc_initialize_hook; 758void (*__malloc_initialize_hook) () = malloc_initialize_hook;
@@ -809,6 +828,17 @@ main (argc, argv
809 stack_base = &dummy; 828 stack_base = &dummy;
810#endif 829#endif
811 830
831 if (!initialized)
832 {
833 extern char my_endbss[];
834 extern char *my_endbss_static;
835
836 if (my_heap_start == 0)
837 my_heap_start = sbrk (0);
838
839 heap_bss_diff = (char *)my_heap_start - max (my_endbss, my_endbss_static);
840 }
841
812#ifdef LINUX_SBRK_BUG 842#ifdef LINUX_SBRK_BUG
813 __sbrk (1); 843 __sbrk (1);
814#endif 844#endif
@@ -852,6 +882,28 @@ main (argc, argv
852 } 882 }
853 } 883 }
854 884
885#ifdef HAVE_PERSONALITY_LINUX32
886 /* See if there is a gap between the end of BSS and the heap.
887 In that case, set personality and exec ourself again. */
888 if (!initialized
889 && (strcmp (argv[argc-1], "dump") == 0
890 || strcmp (argv[argc-1], "bootstrap") == 0)
891 && heap_bss_diff > MAX_HEAP_BSS_DIFF)
892 {
893 if (! getenv ("EMACS_HEAP_EXEC"))
894 {
895 /* Set this so we only do this once. */
896 putenv("EMACS_HEAP_EXEC=true");
897 personality (PER_LINUX32);
898 execvp (argv[0], argv);
899
900 /* If the exec fails, try to dump anyway. */
901 perror ("execvp");
902 }
903 }
904#endif /* HAVE_PERSONALITY_LINUX32 */
905
906
855/* Map in shared memory, if we are using that. */ 907/* Map in shared memory, if we are using that. */
856#ifdef HAVE_SHM 908#ifdef HAVE_SHM
857 if (argmatch (argv, argc, "-nl", "--no-shared-memory", 6, NULL, &skip_args)) 909 if (argmatch (argv, argc, "-nl", "--no-shared-memory", 6, NULL, &skip_args))
@@ -2130,6 +2182,17 @@ You must run Emacs in batch mode in order to dump it. */)
2130 if (! noninteractive) 2182 if (! noninteractive)
2131 error ("Dumping Emacs works only in batch mode"); 2183 error ("Dumping Emacs works only in batch mode");
2132 2184
2185 if (heap_bss_diff > MAX_HEAP_BSS_DIFF)
2186 {
2187 fprintf (stderr, "**************************************************\n");
2188 fprintf (stderr, "Warning: Your system has a gap between BSS and the\n");
2189 fprintf (stderr, "heap. This usually means that exec-shield or\n");
2190 fprintf (stderr, "something similar is in effect. The dump may fail\n");
2191 fprintf (stderr, "because of this. See the section about exec-shield\n");
2192 fprintf (stderr, "in etc/PROBLEMS for more information.\n");
2193 fprintf (stderr, "**************************************************\n");
2194 }
2195
2133 /* Bind `command-line-processed' to nil before dumping, 2196 /* Bind `command-line-processed' to nil before dumping,
2134 so that the dumped Emacs will process its command line 2197 so that the dumped Emacs will process its command line
2135 and set up to work with X windows if appropriate. */ 2198 and set up to work with X windows if appropriate. */