comparison src/emacs.c @ 57623:1293d7f90911

* 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.
author Jan Djärv <jan.h.d@swipnet.se>
date Wed, 20 Oct 2004 16:23:30 +0000
parents 69f225b794b1
children eb20070961bb ae7fab96922c f3ec05478165
comparison
equal deleted inserted replaced
57622:a17f324d7b7f 57623:1293d7f90911
63 #endif 63 #endif
64 64
65 #ifdef HAVE_SETRLIMIT 65 #ifdef HAVE_SETRLIMIT
66 #include <sys/time.h> 66 #include <sys/time.h>
67 #include <sys/resource.h> 67 #include <sys/resource.h>
68 #endif
69
70 #ifdef HAVE_PERSONALITY_LINUX32
71 #include <sys/personality.h>
68 #endif 72 #endif
69 73
70 #ifndef O_RDWR 74 #ifndef O_RDWR
71 #define O_RDWR 2 75 #define O_RDWR 2
72 #endif 76 #endif
189 #endif 193 #endif
190 194
191 /* An address near the bottom of the stack. 195 /* An address near the bottom of the stack.
192 Tells GC how to save a copy of the stack. */ 196 Tells GC how to save a copy of the stack. */
193 char *stack_bottom; 197 char *stack_bottom;
198
199 /* The address where the heap starts (from the first sbrk (0) call). */
200 static void *my_heap_start;
201
202 /* The gap between BSS end and heap start as far as we can tell. */
203 static 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
194 209
195 #ifdef HAVE_WINDOW_SYSTEM 210 #ifdef HAVE_WINDOW_SYSTEM
196 extern Lisp_Object Vwindow_system; 211 extern Lisp_Object Vwindow_system;
197 #endif /* HAVE_WINDOW_SYSTEM */ 212 #endif /* HAVE_WINDOW_SYSTEM */
198 213
731 746
732 malloc_set_state (malloc_state_ptr); 747 malloc_set_state (malloc_state_ptr);
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
739 void (*__malloc_initialize_hook) () = malloc_initialize_hook; 758 void (*__malloc_initialize_hook) () = malloc_initialize_hook;
740 759
741 #endif /* DOUG_LEA_MALLOC */ 760 #endif /* DOUG_LEA_MALLOC */
806 825
807 #if GC_MARK_STACK 826 #if GC_MARK_STACK
808 extern Lisp_Object *stack_base; 827 extern Lisp_Object *stack_base;
809 stack_base = &dummy; 828 stack_base = &dummy;
810 #endif 829 #endif
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 }
811 841
812 #ifdef LINUX_SBRK_BUG 842 #ifdef LINUX_SBRK_BUG
813 __sbrk (1); 843 __sbrk (1);
814 #endif 844 #endif
815 845
849 printf ("For more information about these matters, "); 879 printf ("For more information about these matters, ");
850 printf ("see the file named COPYING.\n"); 880 printf ("see the file named COPYING.\n");
851 exit (0); 881 exit (0);
852 } 882 }
853 } 883 }
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
854 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))
858 { 910 {
2128 check_pure_size (); 2180 check_pure_size ();
2129 2181
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. */
2136 symbol = intern ("command-line-processed"); 2199 symbol = intern ("command-line-processed");
2137 specbind (symbol, Qnil); 2200 specbind (symbol, Qnil);