[Patch]: heap_chunk_size

Pierre A. Humblet pierre@phumblet.no-ip.org
Tue Feb 3 01:23:00 GMT 2004


Here is a no brainer patch that eliminates the use of 
"heap_chunk" in the cygwin shared. That removes a source 
of DOS attack and it's another step towards the demise
of the cygwin shared.
Actually deleting the "heap_chunk" member from the structure
will be done shortly.

Pierre

2004-02-02  Pierre Humblet <pierre.humblet@ieee.org>

	* shared.cc (shared_info::heap_chunk_size): Delete.
	* heap.cc (heap_chunk_size): Create.
	(heap_init): Call heap_chunk_size instead of
	cygwin_shared->heap_chunk_size.
-------------- next part --------------
Index: heap.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/heap.cc,v
retrieving revision 1.39
diff -u -p -r1.39 heap.cc
--- heap.cc	14 Jan 2004 15:45:36 -0000	1.39
+++ heap.cc	3 Feb 2004 01:18:58 -0000
@@ -30,6 +30,38 @@ extern "C" size_t getpagesize ();

 #define MINHEAP_SIZE (4 * 1024 * 1024)

+static unsigned
+heap_chunk_size ()
+{
+  unsigned int heap_chunk;
+
+  /* Fetch misc. registry entries.  */
+
+  reg_key reg (KEY_READ, NULL);
+
+  /* Note that reserving a huge amount of heap space does not result in
+     the use of swap since we are not committing it. */
+  /* FIXME: We should not be restricted to a fixed size heap no matter
+     what the fixed size is. */
+
+  heap_chunk = reg.get_int ("heap_chunk_in_mb", 0);
+  if (!heap_chunk) {
+    reg_key r1 (HKEY_LOCAL_MACHINE, KEY_READ, "SOFTWARE",
+		CYGWIN_INFO_CYGNUS_REGISTRY_NAME,
+		CYGWIN_INFO_CYGWIN_REGISTRY_NAME, NULL);
+    heap_chunk = r1.get_int ("heap_chunk_in_mb", 384);
+  }
+
+  if (!heap_chunk)
+    heap_chunk = MINHEAP_SIZE;
+  else if (!(heap_chunk <<= 20))
+    heap_chunk = 384 * 1024 * 1024;
+
+  debug_printf ("fixed heap size is %u", heap_chunk);
+
+  return heap_chunk;
+}
+
 /* Initialize the heap at process start up.  */
 void
 heap_init ()
@@ -40,7 +72,7 @@ heap_init ()
   page_const = system_info.dwPageSize;
   if (!cygheap->user_heap.base)
     {
-      cygheap->user_heap.chunk = cygwin_shared->heap_chunk_size ();
+      cygheap->user_heap.chunk = heap_chunk_size ();
       while (cygheap->user_heap.chunk >= MINHEAP_SIZE)
 	{
 	  /* Initialize page mask and default heap size.  Preallocate a heap
Index: shared.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/shared.cc,v
retrieving revision 1.80
diff -u -p -r1.80 shared.cc
--- shared.cc	1 Dec 2003 15:03:43 -0000	1.80
+++ shared.cc	3 Feb 2004 01:18:58 -0000
@@ -244,37 +244,3 @@ memory_init ()

   user_shared_initialize (false);
 }
-
-unsigned
-shared_info::heap_chunk_size ()
-{
-  if (!heap_chunk)
-    {
-      /* Fetch misc. registry entries.  */
-
-      reg_key reg (KEY_READ, NULL);
-
-      /* Note that reserving a huge amount of heap space does not result in
-      the use of swap since we are not committing it. */
-      /* FIXME: We should not be restricted to a fixed size heap no matter
-      what the fixed size is. */
-
-      heap_chunk = reg.get_int ("heap_chunk_in_mb", 0);
-      if (!heap_chunk) {
-	reg_key r1 (HKEY_LOCAL_MACHINE, KEY_READ, "SOFTWARE",
-		    CYGWIN_INFO_CYGNUS_REGISTRY_NAME,
-		    CYGWIN_INFO_CYGWIN_REGISTRY_NAME, NULL);
-	heap_chunk = r1.get_int ("heap_chunk_in_mb", 384);
-      }
-
-      if (heap_chunk < 4)
-	heap_chunk = 4 * 1024 * 1024;
-      else
-	heap_chunk <<= 20;
-      if (!heap_chunk)
-	heap_chunk = 384 * 1024 * 1024;
-      debug_printf ("fixed heap size is %u", heap_chunk);
-    }
-
-  return heap_chunk;
-}


More information about the Cygwin-patches mailing list