Index: c/src/exec/score/ChangeLog
===================================================================
--- c/src/exec/score/ChangeLog	(revision aac7fdd28cf1ffbce75e88a1174e75bf5dfa0f30)
+++ c/src/exec/score/ChangeLog	(revision 252565f24da1ca21bd681acf621201b5318d95d7)
@@ -1,2 +1,8 @@
+
+2000-10-18	Nick Simon <Nick.SIMON@syntegra.bt.co.uk>
+
+	* src/heapgetinfo.c, include/rtems/score/heap.h, src/Makefile.am:
+	Added _Heap_Get_information() and information control block.
+	* src/heapgetinfo.c: New file.
 
 2000-09-25	Joel Sherrill <joel@OARcorp.com>
Index: c/src/exec/score/include/rtems/score/heap.h
===================================================================
--- c/src/exec/score/include/rtems/score/heap.h	(revision aac7fdd28cf1ffbce75e88a1174e75bf5dfa0f30)
+++ c/src/exec/score/include/rtems/score/heap.h	(revision 252565f24da1ca21bd681acf621201b5318d95d7)
@@ -35,4 +35,25 @@
   HEAP_EXTEND_NOT_IMPLEMENTED
 }  Heap_Extend_status;
+
+/*
+ *  Status codes for _Heap_Get_information
+ */
+
+typedef enum {
+    HEAP_GET_INFORMATION_SUCCESSFUL = 0,
+    HEAP_GET_INFORMATION_SYSTEM_STATE_ERROR,
+    HEAP_GET_INFORMATION_BLOCK_ERROR
+}  Heap_Get_information_status;
+        
+/*
+ *  Information block returned by _Heap_Get_information
+ */
+
+typedef struct {
+  unsigned32   free_blocks;
+  unsigned32   free_size;
+  unsigned32   used_blocks;
+  unsigned32   used_size;
+} Heap_Information_block;
 
 /*
@@ -214,4 +235,27 @@
 );
 
+/*PAGE
+ *
+ *  _Heap_Get_information
+ *
+ *  This kernel routine walks the heap and tots up the free and allocated
+ *  sizes.  Derived from _Heap_Walk.
+ *
+ *  Input parameters:
+ *    the_heap  - pointer to heap header
+ *    the_info  - pointer to information block
+ *
+ *  Output parameters: 
+ *    *the_info - status information
+ *    return 0=success, otherwise heap is corrupt.
+ */
+
+
+Heap_Get_information_status _Heap_Get_information(
+  Heap_Control            *the_heap,
+  Heap_Information_block  *the_info
+);
+
+
 #ifndef __RTEMS_APPLICATION__
 #include <rtems/score/heap.inl>
Index: c/src/exec/score/src/Makefile.am
===================================================================
--- c/src/exec/score/src/Makefile.am	(revision aac7fdd28cf1ffbce75e88a1174e75bf5dfa0f30)
+++ c/src/exec/score/src/Makefile.am	(revision 252565f24da1ca21bd681acf621201b5318d95d7)
@@ -23,5 +23,5 @@
 
 HEAP_C_FILES = heap.c heapallocate.c heapextend.c heapfree.c \
-    heapsizeofuserarea.c heapwalk.c
+    heapsizeofuserarea.c heapwalk.c heapgetinfo.c
 
 OBJECT_C_FILES = object.c objectallocate.c objectallocatebyindex.c \
Index: c/src/exec/score/src/heapgetinfo.c
===================================================================
--- c/src/exec/score/src/heapgetinfo.c	(revision 252565f24da1ca21bd681acf621201b5318d95d7)
+++ c/src/exec/score/src/heapgetinfo.c	(revision 252565f24da1ca21bd681acf621201b5318d95d7)
@@ -0,0 +1,101 @@
+/*
+ *  Heap Handler
+ *
+ *  COPYRIGHT (c) 1989-2000.
+ *  On-Line Applications Research Corporation (OAR).
+ *
+ *  The license and distribution terms for this file may be
+ *  found in the file LICENSE in this distribution or at
+ *  http://www.OARcorp.com/rtems/license.html.
+ *
+ */
+
+
+#include <rtems/system.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/heap.h>
+
+/*PAGE
+ *
+ *  _Heap_Get_information
+ *
+ *  This kernel routine walks the heap and tots up the free and allocated
+ *  sizes.  Derived from _Heap_Walk.
+ *
+ *  Input parameters:
+ *    the_heap  - pointer to heap header
+ *
+ *  Output parameters: 
+ *    free_sz   - Pointer for free amount return
+ *    used_sz   - Pointer for used amount return
+ *    return 0=success, otherwise heap is corrupt.
+ */
+
+
+Heap_Get_information_status _Heap_Get_information(
+  Heap_Control            *the_heap,
+  Heap_Information_block  *the_info
+)
+{
+  Heap_Block *the_block  = 0;  /* avoid warnings */
+  Heap_Block *next_block = 0;  /* avoid warnings */
+  int         notdone = 1;
+
+
+  the_info->free_blocks = 0;
+  the_info->free_size   = 0;
+  the_info->used_blocks = 0;
+  the_info->used_size   = 0;
+
+  /*
+   * We don't want to allow walking the heap until we have
+   * transferred control to the user task so we watch the
+   * system state.
+   */
+
+  if ( !_System_state_Is_up( _System_state_Get() ) )
+    return HEAP_GET_INFORMATION_SYSTEM_STATE_ERROR;
+
+  the_block = the_heap->start;
+
+  /*
+   * Handle the 1st block
+   */
+
+  if ( the_block->back_flag != HEAP_DUMMY_FLAG ) {
+    return HEAP_GET_INFORMATION_BLOCK_ERROR;
+  }
+
+  while (notdone) {
+      
+      /*
+       * Accumulate size
+       */
+
+      if ( _Heap_Is_block_free(the_block) ) {
+        the_info->free_blocks++;
+        the_info->free_size += _Heap_Block_size(the_block);
+      } else {
+        the_info->used_blocks++;
+        the_info->used_size += _Heap_Block_size(the_block);
+      }
+    
+      /*
+       * Handle the last block
+       */
+
+      if ( the_block->front_flag != HEAP_DUMMY_FLAG ) {
+        next_block = _Heap_Next_block(the_block);
+        if ( the_block->front_flag != next_block->back_flag ) {
+          return HEAP_GET_INFORMATION_BLOCK_ERROR;
+        }
+      }
+
+      if ( the_block->front_flag == HEAP_DUMMY_FLAG )
+        notdone = 0;
+      else
+        the_block = next_block;
+  }  /* while(notdone) */
+
+  return HEAP_GET_INFORMATION_SUCCESSFUL;
+}
Index: cpukit/score/ChangeLog
===================================================================
--- cpukit/score/ChangeLog	(revision aac7fdd28cf1ffbce75e88a1174e75bf5dfa0f30)
+++ cpukit/score/ChangeLog	(revision 252565f24da1ca21bd681acf621201b5318d95d7)
@@ -1,2 +1,8 @@
+
+2000-10-18	Nick Simon <Nick.SIMON@syntegra.bt.co.uk>
+
+	* src/heapgetinfo.c, include/rtems/score/heap.h, src/Makefile.am:
+	Added _Heap_Get_information() and information control block.
+	* src/heapgetinfo.c: New file.
 
 2000-09-25	Joel Sherrill <joel@OARcorp.com>
Index: cpukit/score/include/rtems/score/heap.h
===================================================================
--- cpukit/score/include/rtems/score/heap.h	(revision aac7fdd28cf1ffbce75e88a1174e75bf5dfa0f30)
+++ cpukit/score/include/rtems/score/heap.h	(revision 252565f24da1ca21bd681acf621201b5318d95d7)
@@ -35,4 +35,25 @@
   HEAP_EXTEND_NOT_IMPLEMENTED
 }  Heap_Extend_status;
+
+/*
+ *  Status codes for _Heap_Get_information
+ */
+
+typedef enum {
+    HEAP_GET_INFORMATION_SUCCESSFUL = 0,
+    HEAP_GET_INFORMATION_SYSTEM_STATE_ERROR,
+    HEAP_GET_INFORMATION_BLOCK_ERROR
+}  Heap_Get_information_status;
+        
+/*
+ *  Information block returned by _Heap_Get_information
+ */
+
+typedef struct {
+  unsigned32   free_blocks;
+  unsigned32   free_size;
+  unsigned32   used_blocks;
+  unsigned32   used_size;
+} Heap_Information_block;
 
 /*
@@ -214,4 +235,27 @@
 );
 
+/*PAGE
+ *
+ *  _Heap_Get_information
+ *
+ *  This kernel routine walks the heap and tots up the free and allocated
+ *  sizes.  Derived from _Heap_Walk.
+ *
+ *  Input parameters:
+ *    the_heap  - pointer to heap header
+ *    the_info  - pointer to information block
+ *
+ *  Output parameters: 
+ *    *the_info - status information
+ *    return 0=success, otherwise heap is corrupt.
+ */
+
+
+Heap_Get_information_status _Heap_Get_information(
+  Heap_Control            *the_heap,
+  Heap_Information_block  *the_info
+);
+
+
 #ifndef __RTEMS_APPLICATION__
 #include <rtems/score/heap.inl>
Index: cpukit/score/src/Makefile.am
===================================================================
--- cpukit/score/src/Makefile.am	(revision aac7fdd28cf1ffbce75e88a1174e75bf5dfa0f30)
+++ cpukit/score/src/Makefile.am	(revision 252565f24da1ca21bd681acf621201b5318d95d7)
@@ -23,5 +23,5 @@
 
 HEAP_C_FILES = heap.c heapallocate.c heapextend.c heapfree.c \
-    heapsizeofuserarea.c heapwalk.c
+    heapsizeofuserarea.c heapwalk.c heapgetinfo.c
 
 OBJECT_C_FILES = object.c objectallocate.c objectallocatebyindex.c \
Index: cpukit/score/src/heapgetinfo.c
===================================================================
--- cpukit/score/src/heapgetinfo.c	(revision 252565f24da1ca21bd681acf621201b5318d95d7)
+++ cpukit/score/src/heapgetinfo.c	(revision 252565f24da1ca21bd681acf621201b5318d95d7)
@@ -0,0 +1,101 @@
+/*
+ *  Heap Handler
+ *
+ *  COPYRIGHT (c) 1989-2000.
+ *  On-Line Applications Research Corporation (OAR).
+ *
+ *  The license and distribution terms for this file may be
+ *  found in the file LICENSE in this distribution or at
+ *  http://www.OARcorp.com/rtems/license.html.
+ *
+ */
+
+
+#include <rtems/system.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/heap.h>
+
+/*PAGE
+ *
+ *  _Heap_Get_information
+ *
+ *  This kernel routine walks the heap and tots up the free and allocated
+ *  sizes.  Derived from _Heap_Walk.
+ *
+ *  Input parameters:
+ *    the_heap  - pointer to heap header
+ *
+ *  Output parameters: 
+ *    free_sz   - Pointer for free amount return
+ *    used_sz   - Pointer for used amount return
+ *    return 0=success, otherwise heap is corrupt.
+ */
+
+
+Heap_Get_information_status _Heap_Get_information(
+  Heap_Control            *the_heap,
+  Heap_Information_block  *the_info
+)
+{
+  Heap_Block *the_block  = 0;  /* avoid warnings */
+  Heap_Block *next_block = 0;  /* avoid warnings */
+  int         notdone = 1;
+
+
+  the_info->free_blocks = 0;
+  the_info->free_size   = 0;
+  the_info->used_blocks = 0;
+  the_info->used_size   = 0;
+
+  /*
+   * We don't want to allow walking the heap until we have
+   * transferred control to the user task so we watch the
+   * system state.
+   */
+
+  if ( !_System_state_Is_up( _System_state_Get() ) )
+    return HEAP_GET_INFORMATION_SYSTEM_STATE_ERROR;
+
+  the_block = the_heap->start;
+
+  /*
+   * Handle the 1st block
+   */
+
+  if ( the_block->back_flag != HEAP_DUMMY_FLAG ) {
+    return HEAP_GET_INFORMATION_BLOCK_ERROR;
+  }
+
+  while (notdone) {
+      
+      /*
+       * Accumulate size
+       */
+
+      if ( _Heap_Is_block_free(the_block) ) {
+        the_info->free_blocks++;
+        the_info->free_size += _Heap_Block_size(the_block);
+      } else {
+        the_info->used_blocks++;
+        the_info->used_size += _Heap_Block_size(the_block);
+      }
+    
+      /*
+       * Handle the last block
+       */
+
+      if ( the_block->front_flag != HEAP_DUMMY_FLAG ) {
+        next_block = _Heap_Next_block(the_block);
+        if ( the_block->front_flag != next_block->back_flag ) {
+          return HEAP_GET_INFORMATION_BLOCK_ERROR;
+        }
+      }
+
+      if ( the_block->front_flag == HEAP_DUMMY_FLAG )
+        notdone = 0;
+      else
+        the_block = next_block;
+  }  /* while(notdone) */
+
+  return HEAP_GET_INFORMATION_SUCCESSFUL;
+}
