]> code.delx.au - gnu-emacs/blobdiff - src/w32heap.c
(nnmail-extra-headers): Add defvar.
[gnu-emacs] / src / w32heap.c
index 38f7ffe05346902014fc3d4691324dfaef1bf7dd..a0c50da550693156a28dcba58be56685932122e5 100644 (file)
@@ -1,5 +1,5 @@
 /* Heap management routines for GNU Emacs on the Microsoft W32 API.
-   Copyright (C) 1994 Free Software Foundation, Inc.
+   Copyright (C) 1994, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -15,13 +15,15 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.
 
    Geoff Voelker (voelker@cs.washington.edu)                        7-29-94
 */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -29,11 +31,14 @@ Boston, MA 02111-1307, USA.
 #include "w32heap.h"
 #include "lisp.h"  /* for VALMASK */
 
-#undef RVA_TO_PTR
-#define RVA_TO_PTR(rva) ((DWORD)(rva) + (DWORD)GetModuleHandle (NULL))
+#define RVA_TO_PTR(rva) ((unsigned char *)((DWORD)(rva) + (DWORD)GetModuleHandle (NULL)))
 
 /* This gives us the page size and the size of the allocation unit on NT.  */
 SYSTEM_INFO sysinfo_cache;
+
+/* This gives us version, build, and platform identification.  */
+OSVERSIONINFO osinfo_cache;
+
 unsigned long syspage_mask = 0;
 
 /* These are defined to get Emacs to compile, but are not used.  */
@@ -43,6 +48,7 @@ int etext;
 /* The major and minor versions of NT.  */
 int w32_major_version;
 int w32_minor_version;
+int w32_build_number;
 
 /* Distinguish between Windows NT and Windows 95.  */
 int os_subtype;
@@ -51,9 +57,9 @@ int os_subtype;
 void
 cache_system_info (void)
 {
-  union 
+  union
     {
-      struct info 
+      struct info
        {
          char  major;
          char  minor;
@@ -75,6 +81,14 @@ cache_system_info (void)
   /* Cache page size, allocation unit, processor type, etc.  */
   GetSystemInfo (&sysinfo_cache);
   syspage_mask = sysinfo_cache.dwPageSize - 1;
+
+  /* Cache os info.  */
+  osinfo_cache.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
+  GetVersionEx (&osinfo_cache);
+
+  w32_build_number = osinfo_cache.dwBuildNumber;
+  if (os_subtype == OS_WIN95)
+    w32_build_number &= 0xffff;
 }
 
 /* Emulate getpagesize.  */
@@ -142,11 +156,11 @@ sbrk (unsigned long increment)
 {
   void *result;
   long size = (long) increment;
-  
+
   result = data_region_end;
-  
+
   /* If size is negative, shrink the heap by decommitting pages.  */
-  if (size < 0) 
+  if (size < 0)
     {
       int new_size;
       unsigned char *new_data_region_end;
@@ -157,7 +171,7 @@ sbrk (unsigned long increment)
       if ((data_region_end - size) < data_region_base)
        return NULL;
 
-      /* We can only decommit full pages, so allow for 
+      /* We can only decommit full pages, so allow for
         partial deallocation [cga].  */
       new_data_region_end = (data_region_end - size);
       new_data_region_end = (unsigned char *)
@@ -173,9 +187,9 @@ sbrk (unsigned long increment)
        }
 
       data_region_end -= size;
-    } 
+    }
   /* If size is positive, grow the heap by committing reserved pages.  */
-  else if (size > 0) 
+  else if (size > 0)
     {
       /* Sanity checks.  */
       if ((data_region_end + size) >
@@ -194,7 +208,7 @@ sbrk (unsigned long increment)
       real_data_region_end = (unsigned char *)
          ((long) (data_region_end + syspage_mask) & ~syspage_mask);
     }
-  
+
   return result;
 }
 
@@ -217,7 +231,7 @@ init_heap ()
   PIMAGE_NT_HEADERS nt_header;
 
   dos_header = (PIMAGE_DOS_HEADER) RVA_TO_PTR (0);
-  nt_header = (PIMAGE_NT_HEADERS) (((unsigned long) dos_header) + 
+  nt_header = (PIMAGE_NT_HEADERS) (((unsigned long) dos_header) +
                                   dos_header->e_lfanew);
   preload_heap_section = find_section ("EMHEAP", nt_header);
 
@@ -230,14 +244,15 @@ init_heap ()
          exit (1);
        }
 
+#if defined (NO_UNION_TYPE) && !defined (USE_LSB_TAG)
       /* Ensure that the addresses don't use the upper tag bits since
         the Lisp type goes there.  */
-      if (((unsigned long) data_region_base & ~VALMASK) != 0) 
+      if (((unsigned long) data_region_base & ~VALMASK) != 0)
        {
          printf ("Error: The heap was allocated in upper memory.\n");
          exit (1);
        }
-
+#endif
       data_region_end = data_region_base;
       real_data_region_end = data_region_end;
     }
@@ -259,15 +274,15 @@ round_heap (unsigned long align)
 {
   unsigned long needs_to_be;
   unsigned long need_to_alloc;
-  
+
   needs_to_be = (unsigned long) ROUND_UP (get_heap_end (), align);
   need_to_alloc = needs_to_be - (unsigned long) get_heap_end ();
-  
-  if (need_to_alloc) 
+
+  if (need_to_alloc)
     sbrk (need_to_alloc);
 }
 
-#if (_MSC_VER >= 1000)
+#if (_MSC_VER >= 1000 && _MSC_VER < 1300 && !defined(USE_CRT_DLL))
 
 /* MSVC 4.2 invokes these functions from mainCRTStartup to initialize
    a heap via HeapCreate.  They are normally defined by the runtime,
@@ -289,3 +304,6 @@ _heap_term (void)
 }
 
 #endif
+
+/* arch-tag: 9a6a9860-040d-422d-8905-450dd535cd9c
+   (do not change this comment) */