mem-limits.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /* Includes for memory limit warnings.
  2. Copyright (C) 1990, 1993, 1994 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library. Its master source is NOT part of
  4. the C library, however. The master source lives in /gd/gnu/lib.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public License as
  7. published by the Free Software Foundation; either version 2 of the
  8. License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public
  14. License along with the GNU C Library; see the file COPYING.LIB. If
  15. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16. Cambridge, MA 02139, USA. */
  17. #ifdef MSDOS
  18. #include <dpmi.h>
  19. #endif
  20. /* Some systems need this before <sys/resource.h>. */
  21. #include <sys/types.h>
  22. #ifdef _LIBC
  23. #include <sys/resource.h>
  24. #define BSD4_2 /* Tell code below to use getrlimit. */
  25. #else
  26. #if defined (__osf__) && (defined (__mips) || defined (mips) || defined(__alpha))
  27. #include <sys/time.h>
  28. #include <sys/resource.h>
  29. #endif
  30. #ifdef __bsdi__
  31. #define BSD4_2
  32. #endif
  33. #ifndef BSD4_2
  34. #ifndef USG
  35. #ifndef MSDOS
  36. #ifndef WINDOWSNT
  37. #include <sys/vlimit.h>
  38. #endif /* not WINDOWSNT */
  39. #endif /* not MSDOS */
  40. #endif /* not USG */
  41. #else /* if BSD4_2 */
  42. #include <sys/time.h>
  43. #include <sys/resource.h>
  44. #endif /* BSD4_2 */
  45. #endif /* _LIBC */
  46. #ifdef emacs
  47. /* The important properties of this type are that 1) it's a pointer, and
  48. 2) arithmetic on it should work as if the size of the object pointed
  49. to has a size of 1. */
  50. #ifdef __STDC__
  51. typedef void *POINTER;
  52. #else
  53. typedef char *POINTER;
  54. #endif
  55. typedef unsigned long SIZE;
  56. #ifdef NULL
  57. #undef NULL
  58. #endif
  59. #define NULL ((POINTER) 0)
  60. extern POINTER start_of_data ();
  61. #ifdef DATA_SEG_BITS
  62. #define EXCEEDS_LISP_PTR(ptr) \
  63. (((EMACS_UINT) (ptr) & ~DATA_SEG_BITS) >> VALBITS)
  64. #else
  65. #define EXCEEDS_LISP_PTR(ptr) ((EMACS_UINT) (ptr) >> VALBITS)
  66. #endif
  67. #ifdef BSD
  68. #ifndef DATA_SEG_BITS
  69. extern char etext;
  70. #define start_of_data() &etext
  71. #endif
  72. #endif
  73. #else /* Not emacs */
  74. extern char etext;
  75. #define start_of_data() &etext
  76. #endif /* Not emacs */
  77. /* start of data space; can be changed by calling malloc_init */
  78. static POINTER data_space_start;
  79. /* Number of bytes of writable memory we can expect to be able to get */
  80. static unsigned int lim_data;
  81. #ifdef NO_LIM_DATA
  82. static void
  83. get_lim_data ()
  84. {
  85. lim_data = -1;
  86. }
  87. #else /* not NO_LIM_DATA */
  88. #ifdef USG
  89. static void
  90. get_lim_data ()
  91. {
  92. extern long ulimit ();
  93. lim_data = -1;
  94. /* Use the ulimit call, if we seem to have it. */
  95. #if !defined (ULIMIT_BREAK_VALUE) || defined (LINUX)
  96. lim_data = ulimit (3, 0);
  97. #endif
  98. /* If that didn't work, just use the macro's value. */
  99. #ifdef ULIMIT_BREAK_VALUE
  100. if (lim_data == -1)
  101. lim_data = ULIMIT_BREAK_VALUE;
  102. #endif
  103. lim_data -= (long) data_space_start;
  104. }
  105. #else /* not USG */
  106. #ifdef WINDOWSNT
  107. static void
  108. get_lim_data ()
  109. {
  110. extern unsigned long data_region_size;
  111. lim_data = data_region_size;
  112. }
  113. #else
  114. #if !defined (BSD4_2) && !defined (__osf__)
  115. #ifdef MSDOS
  116. void
  117. get_lim_data ()
  118. {
  119. _go32_dpmi_meminfo info;
  120. _go32_dpmi_get_free_memory_information (&info);
  121. lim_data = info.available_memory;
  122. }
  123. #else /* not MSDOS */
  124. static void
  125. get_lim_data ()
  126. {
  127. lim_data = vlimit (LIM_DATA, -1);
  128. }
  129. #endif /* not MSDOS */
  130. #else /* BSD4_2 */
  131. static void
  132. get_lim_data ()
  133. {
  134. struct rlimit XXrlimit;
  135. getrlimit (RLIMIT_DATA, &XXrlimit);
  136. #ifdef RLIM_INFINITY
  137. lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
  138. #else
  139. lim_data = XXrlimit.rlim_cur; /* soft limit */
  140. #endif
  141. }
  142. #endif /* BSD4_2 */
  143. #endif /* not WINDOWSNT */
  144. #endif /* not USG */
  145. #endif /* not NO_LIM_DATA */