aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2013-02-24 21:55:37 -0800
committerPaul Eggert2013-02-24 21:55:37 -0800
commit1ddc2bd6ff0b5071454d2591f835927ea5b85a06 (patch)
treedff377164bcc7d9e8a84e0279cee6f9c28e3fcc5 /src
parent82fcf982c39d5ff821bb7d3353ca973e277e1810 (diff)
downloademacs-1ddc2bd6ff0b5071454d2591f835927ea5b85a06.tar.gz
emacs-1ddc2bd6ff0b5071454d2591f835927ea5b85a06.zip
Simplify data_start configuration.
This is a followon simplification to the fix for Bug#13650. * admin/CPP-DEFINES (DATA_START, ORDINARY_LINK): Remove. * configure.ac (CRT_DIR, LIB_STANDARD, START_FILES, DATA_START) (LD_FIRSTFLAG, ORDINARY_LINK, LIB_GCC): Remove. (AC_CHECK_HEADERS_ONCE): Remove sys/resource.h, as it's not always needed. (HAVE_DATA_START): New macro. * etc/PROBLEMS (LIBS_SYSTEM, LIBS_MACHINE, LIBS_STANDARD): Remove. Remove legacy-systems section, as this stuff is no longer applicable with current linking strategies. * src/Makefile.in (LD_FIRSTFLAG, LIB_GCC, CRT_DIR, LIB_STANDARD) (START_FILES): Remove. All uses removed. (otherobj): Remove $(VMLIMIT_OBJ), as it's now first. (ALLOBJS): Move here from autodeps.mk, and with VMLIMITS_OBJ first. (buildobj.h): Use it. ($(ALLOBJS)): Depend on globals.h. (temacs$(EXEEXT)): Use $(ALLOBJS). * src/autodeps.mk (ALLOBJS): Move to Makefile.in. * src/deps.mk (vm-limit.o): * src/makefile.w32-in ($(BLD)/vm-limit.$(O)): Do not depend on mem-limits.h. * src/emacs.c (__do_global_ctors, __do_global_ctors_aux) (__do_global_dtors, __CTOR_LIST__, __DTOR_LIST__) [__GNUC__ && !ORDINARY_LINK]: Remove. * src/mem-limits.h, src/pre-crt0.c: Remove. * src/unexaix.c, src/unexcoff.c: Don't include mem-limits.h. * src/unexcoff.c (etext): New decl. (make_hdr): Use it instead of start_of_data. * src/vm-limit.c: Move most of mem-limits.h's contents here. (data_start): New decl. It's OK if this is approximate, so simplify-away some unnecessary exactness. (POINTER): Remove; all uses removed. (data_space_start): Now char *, to avoid casts. (exceeds_lisp_ptr): New function, replacing the old EXCEEDS_LISP_PTR macro. All uses changed. (check_memory_limits): Simplify and remove casts. (start_of_data) [!CANNOT_DUMP || !SYSTEM_MALLOC]: Remove. (memory_warnings): Use data_start instead of start_of_data. Fixes: debbugs:13783
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog33
-rw-r--r--src/Makefile.in34
-rw-r--r--src/autodeps.mk1
-rw-r--r--src/deps.mk2
-rw-r--r--src/emacs.c26
-rw-r--r--src/makefile.w32-in1
-rw-r--r--src/mem-limits.h43
-rw-r--r--src/pre-crt0.c10
-rw-r--r--src/unexaix.c2
-rw-r--r--src/unexcoff.c4
-rw-r--r--src/vm-limit.c103
11 files changed, 95 insertions, 164 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 8d3fc1e56fb..00d1f30dd46 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,36 @@
12013-02-25 Paul Eggert <eggert@cs.ucla.edu>
2
3 Simplify data_start configuration (Bug#13783).
4 This is a followon simplification to the fix for Bug#13650.
5 * Makefile.in (LD_FIRSTFLAG, LIB_GCC, CRT_DIR, LIB_STANDARD)
6 (START_FILES): Remove. All uses removed.
7 (otherobj): Remove $(VMLIMIT_OBJ), as it's now first.
8 (ALLOBJS): Move here from autodeps.mk, and with VMLIMITS_OBJ first.
9 (buildobj.h): Use it.
10 ($(ALLOBJS)): Depend on globals.h.
11 (temacs$(EXEEXT)): Use $(ALLOBJS).
12 * autodeps.mk (ALLOBJS): Move to Makefile.in.
13 * deps.mk (vm-limit.o):
14 * makefile.w32-in ($(BLD)/vm-limit.$(O)):
15 Do not depend on mem-limits.h.
16 * emacs.c (__do_global_ctors, __do_global_ctors_aux)
17 (__do_global_dtors, __CTOR_LIST__, __DTOR_LIST__)
18 [__GNUC__ && !ORDINARY_LINK]: Remove.
19 * mem-limits.h, pre-crt0.c: Remove.
20 * unexaix.c, unexcoff.c: Don't include mem-limits.h.
21 * unexcoff.c (etext): New decl.
22 (make_hdr): Use DATA_START instead of start_of_data.
23 * vm-limit.c: Move most of mem-limits.h's contents here.
24 (data_start): New decl. It's OK if this is approximate,
25 so simplify-away some unnecessary exactness.
26 (POINTER): Remove; all uses removed.
27 (data_space_start): Now char *, to avoid casts.
28 (exceeds_lisp_ptr): New function, replacing the old
29 EXCEEDS_LISP_PTR macro. All uses changed.
30 (check_memory_limits): Simplify and remove casts.
31 (start_of_data) [!CANNOT_DUMP || !SYSTEM_MALLOC]: Remove.
32 (memory_warnings): Use data_start instead of start_of_data.
33
12013-02-24 Andreas Schwab <schwab@linux-m68k.org> 342013-02-24 Andreas Schwab <schwab@linux-m68k.org>
2 35
3 * xdisp.c (set_message): Only check for debug-on-message if STRING 36 * xdisp.c (set_message): Only check for debug-on-message if STRING
diff --git a/src/Makefile.in b/src/Makefile.in
index 6ee03177861..b2034a3379d 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -36,7 +36,6 @@ WINDRES = @WINDRES@
36CFLAGS = @CFLAGS@ 36CFLAGS = @CFLAGS@
37CPPFLAGS = @CPPFLAGS@ 37CPPFLAGS = @CPPFLAGS@
38LDFLAGS = @LDFLAGS@ 38LDFLAGS = @LDFLAGS@
39LD_FIRSTFLAG=@LD_FIRSTFLAG@
40EXEEXT = @EXEEXT@ 39EXEEXT = @EXEEXT@
41version = @version@ 40version = @version@
42# Substitute an assignment for the MAKE variable, because 41# Substitute an assignment for the MAKE variable, because
@@ -102,10 +101,8 @@ LD_SWITCH_X_SITE_RPATH=@LD_SWITCH_X_SITE_RPATH@
102## System-specific LDFLAGS. 101## System-specific LDFLAGS.
103LD_SWITCH_SYSTEM=@LD_SWITCH_SYSTEM@ 102LD_SWITCH_SYSTEM=@LD_SWITCH_SYSTEM@
104 103
105## This holds any special options for linking temacs only (ie, not 104## This holds any special options for linking temacs only (i.e., not
106## used by configure). Not used elsewhere because it sometimes 105## used by configure).
107## contains options that have to do with using Emacs's crt0,
108## which are only good with temacs.
109LD_SWITCH_SYSTEM_TEMACS=@LD_SWITCH_SYSTEM_TEMACS@ 106LD_SWITCH_SYSTEM_TEMACS=@LD_SWITCH_SYSTEM_TEMACS@
110 107
111## Flags to pass to ld only for temacs. 108## Flags to pass to ld only for temacs.
@@ -120,14 +117,6 @@ PAXCTL = @PAXCTL@
120## Some systems define this to request special libraries. 117## Some systems define this to request special libraries.
121LIBS_SYSTEM=@LIBS_SYSTEM@ 118LIBS_SYSTEM=@LIBS_SYSTEM@
122 119
123## Where to find libgcc.a, if using gcc and necessary.
124LIB_GCC=@LIB_GCC@
125
126CRT_DIR=@CRT_DIR@
127## May use $CRT_DIR.
128LIB_STANDARD=@LIB_STANDARD@
129START_FILES = @START_FILES@
130
131## -lm, or empty. 120## -lm, or empty.
132LIB_MATH=@LIB_MATH@ 121LIB_MATH=@LIB_MATH@
133 122
@@ -389,17 +378,16 @@ POST_ALLOC_OBJ=@POST_ALLOC_OBJ@
389 378
390## List of object files that make-docfile should not be told about. 379## List of object files that make-docfile should not be told about.
391otherobj= $(TERMCAP_OBJ) $(PRE_ALLOC_OBJ) $(GMALLOC_OBJ) $(RALLOC_OBJ) \ 380otherobj= $(TERMCAP_OBJ) $(PRE_ALLOC_OBJ) $(GMALLOC_OBJ) $(RALLOC_OBJ) \
392 $(POST_ALLOC_OBJ) $(VMLIMIT_OBJ) $(WIDGET_OBJ) $(LIBOBJS) 381 $(POST_ALLOC_OBJ) $(WIDGET_OBJ) $(LIBOBJS)
393 382
383## All object files linked into temacs. $(VMLIMIT_OBJ) should be first.
384ALLOBJS = $(VMLIMIT_OBJ) $(obj) $(otherobj)
394 385
395## Configure inserts the file lisp.mk at this point, defining $lisp. 386## Configure inserts the file lisp.mk at this point, defining $lisp.
396@lisp_frag@ 387@lisp_frag@
397 388
398 389
399## Construct full set of libraries to be linked. 390## Construct full set of libraries to be linked.
400## Note that SunOS needs -lm to come before -lc; otherwise, you get
401## duplicated symbols. If the standard libraries were compiled
402## with GCC, we might need LIB_GCC again after them.
403LIBES = $(LIBS) $(W32_LIBS) $(LIBS_GNUSTEP) $(LIBX_BASE) $(LIBIMAGE) \ 391LIBES = $(LIBS) $(W32_LIBS) $(LIBS_GNUSTEP) $(LIBX_BASE) $(LIBIMAGE) \
404 $(LIBX_OTHER) $(LIBSOUND) \ 392 $(LIBX_OTHER) $(LIBSOUND) \
405 $(RSVG_LIBS) $(IMAGEMAGICK_LIBS) $(LIB_CLOCK_GETTIME) \ 393 $(RSVG_LIBS) $(IMAGEMAGICK_LIBS) $(LIB_CLOCK_GETTIME) \
@@ -409,7 +397,7 @@ LIBES = $(LIBS) $(W32_LIBS) $(LIBS_GNUSTEP) $(LIBX_BASE) $(LIBIMAGE) \
409 $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \ 397 $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \
410 $(FREETYPE_LIBS) $(FONTCONFIG_LIBS) $(LIBOTF_LIBS) $(M17N_FLT_LIBS) \ 398 $(FREETYPE_LIBS) $(FONTCONFIG_LIBS) $(LIBOTF_LIBS) $(M17N_FLT_LIBS) \
411 $(LIBACL_LIBS) $(LIBGNUTLS_LIBS) $(LIB_PTHREAD) $(LIB_PTHREAD_SIGMASK) \ 399 $(LIBACL_LIBS) $(LIBGNUTLS_LIBS) $(LIB_PTHREAD) $(LIB_PTHREAD_SIGMASK) \
412 $(LIB_GCC) $(LIB_MATH) $(LIB_STANDARD) $(LIB_GCC) 400 $(LIB_MATH)
413 401
414all: emacs$(EXEEXT) $(OTHER_FILES) 402all: emacs$(EXEEXT) $(OTHER_FILES)
415.PHONY: all 403.PHONY: all
@@ -456,7 +444,7 @@ $(libsrc)/make-docfile$(EXEEXT):
456 cd $(libsrc); $(MAKE) $(MFLAGS) make-docfile$(EXEEXT) 444 cd $(libsrc); $(MAKE) $(MFLAGS) make-docfile$(EXEEXT)
457 445
458buildobj.h: Makefile 446buildobj.h: Makefile
459 echo "#define BUILDOBJ \"$(obj) $(otherobj) " "\"" > buildobj.h 447 echo "#define BUILDOBJ \"$(ALLOBJS) " "\"" >$@
460 448
461globals.h: gl-stamp; @true 449globals.h: gl-stamp; @true
462 450
@@ -468,15 +456,15 @@ gl-stamp: $(libsrc)/make-docfile$(EXEEXT) $(GLOBAL_SOURCES)
468 $(srcdir)/../build-aux/move-if-change gl-tmp globals.h 456 $(srcdir)/../build-aux/move-if-change gl-tmp globals.h
469 echo timestamp > $@ 457 echo timestamp > $@
470 458
471$(obj) $(otherobj): globals.h 459$(ALLOBJS): globals.h
472 460
473$(lib)/libgnu.a: $(config_h) 461$(lib)/libgnu.a: $(config_h)
474 cd $(lib) && $(MAKE) libgnu.a 462 cd $(lib) && $(MAKE) libgnu.a
475 463
476temacs$(EXEEXT): $(START_FILES) stamp-oldxmenu $(obj) $(otherobj) \ 464temacs$(EXEEXT): stamp-oldxmenu $(ALLOBJS) \
477 $(lib)/libgnu.a $(W32_RES) 465 $(lib)/libgnu.a $(W32_RES)
478 $(CC) $(LD_FIRSTFLAG) $(ALL_CFLAGS) $(TEMACS_LDFLAGS) $(LDFLAGS) \ 466 $(CC) $(ALL_CFLAGS) $(TEMACS_LDFLAGS) $(LDFLAGS) \
479 -o temacs $(START_FILES) $(obj) $(otherobj) $(lib)/libgnu.a $(LIBES) \ 467 -o temacs $(ALLOBJS) $(lib)/libgnu.a $(LIBES) \
480 $(W32_RES_LINK) 468 $(W32_RES_LINK)
481 test "$(CANNOT_DUMP)" = "yes" || \ 469 test "$(CANNOT_DUMP)" = "yes" || \
482 test "X$(PAXCTL)" = X || $(PAXCTL) -r temacs$(EXEEXT) 470 test "X$(PAXCTL)" = X || $(PAXCTL) -r temacs$(EXEEXT)
diff --git a/src/autodeps.mk b/src/autodeps.mk
index fb0e21366c7..8b014a7508c 100644
--- a/src/autodeps.mk
+++ b/src/autodeps.mk
@@ -2,5 +2,4 @@
2 2
3## This is inserted in src/Makefile if AUTO_DEPEND=yes. 3## This is inserted in src/Makefile if AUTO_DEPEND=yes.
4 4
5ALLOBJS=$(START_FILES) ${obj} ${otherobj}
6-include $(ALLOBJS:%.o=${DEPDIR}/%.d) 5-include $(ALLOBJS:%.o=${DEPDIR}/%.d)
diff --git a/src/deps.mk b/src/deps.mk
index 47185c9262c..83444474c59 100644
--- a/src/deps.mk
+++ b/src/deps.mk
@@ -144,7 +144,7 @@ macros.o: macros.c window.h buffer.h commands.h macros.h keyboard.h msdos.h \
144 dispextern.h lisp.h globals.h $(config_h) systime.h coding.h composite.h 144 dispextern.h lisp.h globals.h $(config_h) systime.h coding.h composite.h
145gmalloc.o: gmalloc.c $(config_h) 145gmalloc.o: gmalloc.c $(config_h)
146ralloc.o: ralloc.c lisp.h $(config_h) 146ralloc.o: ralloc.c lisp.h $(config_h)
147vm-limit.o: vm-limit.c mem-limits.h lisp.h globals.h $(config_h) 147vm-limit.o: vm-limit.c lisp.h globals.h $(config_h)
148marker.o: marker.c buffer.h character.h lisp.h globals.h $(config_h) 148marker.o: marker.c buffer.h character.h lisp.h globals.h $(config_h)
149minibuf.o: minibuf.c syntax.h frame.h window.h keyboard.h systime.h \ 149minibuf.o: minibuf.c syntax.h frame.h window.h keyboard.h systime.h \
150 buffer.h commands.h character.h msdos.h $(INTERVALS_H) keymap.h \ 150 buffer.h commands.h character.h msdos.h $(INTERVALS_H) keymap.h \
diff --git a/src/emacs.c b/src/emacs.c
index c494dff8cac..b96076b1340 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -521,32 +521,6 @@ DEFUN ("invocation-directory", Finvocation_directory, Sinvocation_directory,
521static char const dump_tz[] = "UtC0"; 521static char const dump_tz[] = "UtC0";
522#endif 522#endif
523 523
524#ifndef ORDINARY_LINK
525/* We don't include crtbegin.o and crtend.o in the link,
526 so these functions and variables might be missed.
527 Provide dummy definitions to avoid error.
528 (We don't have any real constructors or destructors.) */
529#ifdef __GNUC__
530
531/* Define a dummy function F. Declare F too, to pacify gcc
532 -Wmissing-prototypes. */
533#define DEFINE_DUMMY_FUNCTION(f) \
534 void f (void) ATTRIBUTE_CONST EXTERNALLY_VISIBLE; void f (void) {}
535
536#ifndef GCC_CTORS_IN_LIBC
537DEFINE_DUMMY_FUNCTION (__do_global_ctors)
538DEFINE_DUMMY_FUNCTION (__do_global_ctors_aux)
539DEFINE_DUMMY_FUNCTION (__do_global_dtors)
540/* GNU/Linux has a bug in its library; avoid an error. */
541#ifndef GNU_LINUX
542char * __CTOR_LIST__[2] EXTERNALLY_VISIBLE = { (char *) (-1), 0 };
543#endif
544char * __DTOR_LIST__[2] EXTERNALLY_VISIBLE = { (char *) (-1), 0 };
545#endif /* GCC_CTORS_IN_LIBC */
546DEFINE_DUMMY_FUNCTION (__main)
547#endif /* __GNUC__ */
548#endif /* ORDINARY_LINK */
549
550/* Test whether the next argument in ARGV matches SSTR or a prefix of 524/* Test whether the next argument in ARGV matches SSTR or a prefix of
551 LSTR (at least MINLEN characters). If so, then if VALPTR is non-null 525 LSTR (at least MINLEN characters). If so, then if VALPTR is non-null
552 (the argument is supposed to have a value) store in *VALPTR either 526 (the argument is supposed to have a value) store in *VALPTR either
diff --git a/src/makefile.w32-in b/src/makefile.w32-in
index 6e1873f8e49..d60331198db 100644
--- a/src/makefile.w32-in
+++ b/src/makefile.w32-in
@@ -1492,7 +1492,6 @@ $(BLD)/unexw32.$(O) : \
1492 1492
1493$(BLD)/vm-limit.$(O) : \ 1493$(BLD)/vm-limit.$(O) : \
1494 $(SRC)/vm-limit.c \ 1494 $(SRC)/vm-limit.c \
1495 $(SRC)/mem-limits.h \
1496 $(SRC)/w32heap.h \ 1495 $(SRC)/w32heap.h \
1497 $(NT_INC)/unistd.h \ 1496 $(NT_INC)/unistd.h \
1498 $(CONFIG_H) \ 1497 $(CONFIG_H) \
diff --git a/src/mem-limits.h b/src/mem-limits.h
deleted file mode 100644
index 941ccf5f121..00000000000
--- a/src/mem-limits.h
+++ /dev/null
@@ -1,43 +0,0 @@
1/* Includes for memory limit warnings.
2 Copyright (C) 1990, 1993-1996, 2001-2013 Free Software Foundation,
3 Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19
20#ifdef MSDOS
21#include <dpmi.h>
22extern int etext;
23#endif
24
25/* Some systems need this before <sys/resource.h>. */
26#include <sys/types.h>
27
28#ifdef HAVE_SYS_RESOURCE_H
29# include <sys/time.h>
30# include <sys/resource.h>
31#else
32# if HAVE_SYS_VLIMIT_H
33# include <sys/vlimit.h> /* Obsolete, says glibc */
34# endif
35#endif
36
37extern char *start_of_data (void) ATTRIBUTE_CONST;
38#if USE_LSB_TAG || UINTPTR_MAX <= VAL_MAX
39#define EXCEEDS_LISP_PTR(ptr) 0
40#else
41#define EXCEEDS_LISP_PTR(ptr) \
42 (((uintptr_t) (ptr) & ~DATA_SEG_BITS) >> VALBITS)
43#endif
diff --git a/src/pre-crt0.c b/src/pre-crt0.c
deleted file mode 100644
index 6b9618c8dc3..00000000000
--- a/src/pre-crt0.c
+++ /dev/null
@@ -1,10 +0,0 @@
1/* This file is loaded before crt0.o on machines where we do not
2 remap part of the data space into text space in unexec.
3 On these machines, there is no problem with standard crt0.o's
4 that make environ an initialized variable. However, we do
5 need to make sure the label data_start exists anyway. */
6
7/* Create a label to appear at the beginning of data space.
8 Its value is nonzero so that it cannot be put into bss. */
9
10int data_start = 1;
diff --git a/src/unexaix.c b/src/unexaix.c
index da44480fdca..44a824b8c12 100644
--- a/src/unexaix.c
+++ b/src/unexaix.c
@@ -59,8 +59,6 @@ what you give them. Help stamp out software-hoarding! */
59#include <unistd.h> 59#include <unistd.h>
60#include <fcntl.h> 60#include <fcntl.h>
61 61
62#include "mem-limits.h"
63
64extern char _data[]; 62extern char _data[];
65extern char _text[]; 63extern char _text[];
66 64
diff --git a/src/unexcoff.c b/src/unexcoff.c
index 466a5c0e491..2e662a34145 100644
--- a/src/unexcoff.c
+++ b/src/unexcoff.c
@@ -99,7 +99,7 @@ struct aouthdr
99 99
100#include <sys/file.h> 100#include <sys/file.h>
101 101
102#include "mem-limits.h" 102extern int etext;
103 103
104static long block_copy_start; /* Old executable start point */ 104static long block_copy_start; /* Old executable start point */
105static struct filehdr f_hdr; /* File header */ 105static struct filehdr f_hdr; /* File header */
@@ -168,7 +168,7 @@ make_hdr (int new, int a_out,
168 pagemask = getpagesize () - 1; 168 pagemask = getpagesize () - 1;
169 169
170 /* Adjust text/data boundary. */ 170 /* Adjust text/data boundary. */
171 data_start = (int) start_of_data (); 171 data_start = (int) DATA_START;
172 data_start = ADDR_CORRECT (data_start); 172 data_start = ADDR_CORRECT (data_start);
173 data_start = data_start & ~pagemask; /* (Down) to page boundary. */ 173 data_start = data_start & ~pagemask; /* (Down) to page boundary. */
174 174
diff --git a/src/vm-limit.c b/src/vm-limit.c
index fc7a253325a..3fca8bd26c1 100644
--- a/src/vm-limit.c
+++ b/src/vm-limit.c
@@ -19,7 +19,37 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19#include <config.h> 19#include <config.h>
20#include <unistd.h> /* for 'environ', on AIX */ 20#include <unistd.h> /* for 'environ', on AIX */
21#include "lisp.h" 21#include "lisp.h"
22#include "mem-limits.h" 22
23#ifdef MSDOS
24#include <dpmi.h>
25extern int etext;
26#endif
27
28/* Some systems need this before <sys/resource.h>. */
29#include <sys/types.h>
30
31#ifdef HAVE_SYS_RESOURCE_H
32# include <sys/time.h>
33# include <sys/resource.h>
34#else
35# if HAVE_SYS_VLIMIT_H
36# include <sys/vlimit.h> /* Obsolete, says glibc */
37# endif
38#endif
39
40/* Start of data. It is OK if this is approximate; it's used only as
41 a heuristic. */
42#ifdef DATA_START
43# define data_start ((char *) DATA_START)
44#else
45extern char data_start[];
46# ifndef HAVE_DATA_START
47/* Initialize to nonzero, so that it's put into data and not bss.
48 Link this file's object code first, so that this symbol is near the
49 start of data. */
50char data_start[1] = { 1 };
51# endif
52#endif
23 53
24/* 54/*
25 Level number of warnings already issued. 55 Level number of warnings already issued.
@@ -35,12 +65,20 @@ static enum warnlevel warnlevel;
35 0 means don't issue them. */ 65 0 means don't issue them. */
36static void (*warn_function) (const char *); 66static void (*warn_function) (const char *);
37 67
38/* Start of data space; can be changed by calling malloc_init. */ 68/* Start of data space; can be changed by calling memory_warnings. */
39static void *data_space_start; 69static char *data_space_start;
40 70
41/* Number of bytes of writable memory we can expect to be able to get. */ 71/* Number of bytes of writable memory we can expect to be able to get. */
42static size_t lim_data; 72static size_t lim_data;
43 73
74/* Return true if PTR cannot be represented as an Emacs Lisp object. */
75static bool
76exceeds_lisp_ptr (void *ptr)
77{
78 return (! USE_LSB_TAG
79 && VAL_MAX < UINTPTR_MAX
80 && ((uintptr_t) ptr & ~DATA_SEG_BITS) >> VALBITS != 0);
81}
44 82
45#ifdef HAVE_GETRLIMIT 83#ifdef HAVE_GETRLIMIT
46 84
@@ -122,10 +160,12 @@ check_memory_limits (void)
122{ 160{
123#ifdef REL_ALLOC 161#ifdef REL_ALLOC
124 extern void *(*real_morecore) (ptrdiff_t); 162 extern void *(*real_morecore) (ptrdiff_t);
163#else
164 void *(*real_morecore) (ptrdiff_t) = 0;
125#endif 165#endif
126 extern void *(*__morecore) (ptrdiff_t); 166 extern void *(*__morecore) (ptrdiff_t);
127 167
128 void *cp; 168 char *cp;
129 size_t five_percent; 169 size_t five_percent;
130 size_t data_size; 170 size_t data_size;
131 enum warnlevel new_warnlevel; 171 enum warnlevel new_warnlevel;
@@ -135,13 +175,8 @@ check_memory_limits (void)
135 five_percent = lim_data / 20; 175 five_percent = lim_data / 20;
136 176
137 /* Find current end of memory and issue warning if getting near max */ 177 /* Find current end of memory and issue warning if getting near max */
138#ifdef REL_ALLOC 178 cp = (real_morecore ? real_morecore : __morecore) (0);
139 if (real_morecore) 179 data_size = cp - data_space_start;
140 cp = (char *) (*real_morecore) (0);
141 else
142#endif
143 cp = (char *) (*__morecore) (0);
144 data_size = (char *) cp - (char *) data_space_start;
145 180
146 if (!warn_function) 181 if (!warn_function)
147 return; 182 return;
@@ -188,49 +223,10 @@ check_memory_limits (void)
188 warnlevel = warned_85; 223 warnlevel = warned_85;
189 } 224 }
190 225
191 if (EXCEEDS_LISP_PTR (cp)) 226 if (exceeds_lisp_ptr (cp))
192 (*warn_function) ("Warning: memory in use exceeds lisp pointer size"); 227 (*warn_function) ("Warning: memory in use exceeds lisp pointer size");
193} 228}
194 229
195#if !defined (CANNOT_DUMP) || !defined (SYSTEM_MALLOC)
196/* Some systems that cannot dump also cannot implement these. */
197
198/*
199 * Return the address of the start of the data segment prior to
200 * doing an unexec. After unexec the return value is undefined.
201 * See crt0.c for further information and definition of data_start.
202 *
203 * Apparently, on BSD systems this is etext at startup. On
204 * USG systems (swapping) this is highly mmu dependent and
205 * is also dependent on whether or not the program is running
206 * with shared text. Generally there is a (possibly large)
207 * gap between end of text and start of data with shared text.
208 *
209 */
210
211char *
212start_of_data (void)
213{
214#ifdef BSD_SYSTEM
215 extern char etext;
216 return (void *) &etext;
217#elif defined DATA_START
218 return (void *) DATA_START;
219#elif defined ORDINARY_LINK
220 /*
221 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
222 * data_start isn't defined. We take the address of environ, which
223 * is known to live at or near the start of the system crt0.c, and
224 * we don't sweat the handful of bytes that might lose.
225 */
226 return (void *) &environ;
227#else
228 extern int data_start;
229 return (void *) &data_start;
230#endif
231}
232#endif /* (not CANNOT_DUMP or not SYSTEM_MALLOC) */
233
234/* Enable memory usage warnings. 230/* Enable memory usage warnings.
235 START says where the end of pure storage is. 231 START says where the end of pure storage is.
236 WARNFUN specifies the function to call to issue a warning. */ 232 WARNFUN specifies the function to call to issue a warning. */
@@ -240,10 +236,7 @@ memory_warnings (void *start, void (*warnfun) (const char *))
240{ 236{
241 extern void (* __after_morecore_hook) (void); /* From gmalloc.c */ 237 extern void (* __after_morecore_hook) (void); /* From gmalloc.c */
242 238
243 if (start) 239 data_space_start = start ? start : data_start;
244 data_space_start = start;
245 else
246 data_space_start = start_of_data ();
247 240
248 warn_function = warnfun; 241 warn_function = warnfun;
249 __after_morecore_hook = check_memory_limits; 242 __after_morecore_hook = check_memory_limits;