Browse Source

Cleanup lub library

git-svn-id: https://klish.googlecode.com/svn/trunk@588 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 12 years ago
parent
commit
122e9ea8e1
100 changed files with 19 additions and 8627 deletions
  1. 19 250
      Makefile.in
  2. 0 226
      lub/blockpool.h
  3. 0 29
      lub/blockpool/blockpool__get_stats.c
  4. 0 70
      lub/blockpool/blockpool_alloc.c
  5. 0 58
      lub/blockpool/blockpool_free.c
  6. 0 73
      lub/blockpool/blockpool_init.c
  7. 0 7
      lub/blockpool/module.am
  8. 0 29
      lub/blockpool/private.h
  9. 0 140
      lub/dblockpool.h
  10. 0 48
      lub/dblockpool/dblockpool_alloc.c
  11. 0 17
      lub/dblockpool/dblockpool_fini.c
  12. 0 34
      lub/dblockpool/dblockpool_free.c
  13. 0 14
      lub/dblockpool/dblockpool_init.c
  14. 0 7
      lub/dblockpool/module.am
  15. 0 9
      lub/dblockpool/private.h
  16. 0 997
      lub/heap.h
  17. 0 402
      lub/heap/cache.c
  18. 0 53
      lub/heap/cache.h
  19. 0 77
      lub/heap/cache_bucket.c
  20. 0 754
      lub/heap/context.c
  21. 0 284
      lub/heap/context.h
  22. 0 19
      lub/heap/heap__get_max_free.c
  23. 0 54
      lub/heap/heap__get_stacktrace.c
  24. 0 8
      lub/heap/heap__get_stats.c
  25. 0 126
      lub/heap/heap_add_segment.c
  26. 0 133
      lub/heap/heap_align_block.c
  27. 0 10
      lub/heap/heap_block__get_tail.c
  28. 0 11
      lub/heap/heap_block_check.c
  29. 0 9
      lub/heap/heap_block_from_ptr.c
  30. 0 9
      lub/heap/heap_block_getfirst.c
  31. 0 17
      lub/heap/heap_block_getkey.c
  32. 0 17
      lub/heap/heap_block_getnext.c
  33. 0 24
      lub/heap/heap_block_getprevious.c
  34. 0 90
      lub/heap/heap_check.c
  35. 0 16
      lub/heap/heap_context_delete.c
  36. 0 29
      lub/heap/heap_context_find_or_create.c
  37. 0 82
      lub/heap/heap_create.c
  38. 0 55
      lub/heap/heap_destroy.c
  39. 0 34
      lub/heap/heap_extend_both_ways.c
  40. 0 81
      lub/heap/heap_extend_downwards.c
  41. 0 68
      lub/heap/heap_extend_upwards.c
  42. 0 24
      lub/heap/heap_foreach_free_block.c
  43. 0 18
      lub/heap/heap_foreach_segment.c
  44. 0 61
      lub/heap/heap_graft_to_bottom.c
  45. 0 53
      lub/heap/heap_graft_to_top.c
  46. 0 42
      lub/heap/heap_init_free_block.c
  47. 0 37
      lub/heap/heap_merge_with_next.c
  48. 0 49
      lub/heap/heap_merge_with_previous.c
  49. 0 74
      lub/heap/heap_new_alloc_block.c
  50. 0 27
      lub/heap/heap_new_free_block.c
  51. 0 41
      lub/heap/heap_post_realloc.c
  52. 0 35
      lub/heap/heap_pre_realloc.c
  53. 0 238
      lub/heap/heap_raw_realloc.c
  54. 0 57
      lub/heap/heap_realloc.c
  55. 0 66
      lub/heap/heap_scan_stack.c
  56. 0 135
      lub/heap/heap_show.c
  57. 0 75
      lub/heap/heap_slice_from_bottom.c
  58. 0 68
      lub/heap/heap_slice_from_top.c
  59. 0 98
      lub/heap/heap_static_alloc.c
  60. 0 61
      lub/heap/heap_stop_here.c
  61. 0 58
      lub/heap/heap_tainted_memory.c
  62. 0 57
      lub/heap/module.am
  63. 0 483
      lub/heap/node.c
  64. 0 100
      lub/heap/node.h
  65. 0 7
      lub/heap/posix/heap_clean_stacks.c
  66. 0 52
      lub/heap/posix/heap_leak_mutex.c
  67. 0 21
      lub/heap/posix/heap_scan_bss.c
  68. 0 24
      lub/heap/posix/heap_scan_data.c
  69. 0 291
      lub/heap/posix/heap_symShow.c
  70. 0 8
      lub/heap/posix/module.am
  71. 0 17
      lub/heap/posix/sysheap_stubs.c
  72. 0 451
      lub/heap/private.h
  73. 0 48
      lub/heap/vxworks/heap_clean_stacks.c
  74. 0 34
      lub/heap/vxworks/heap_leak_mutex.c
  75. 0 21
      lub/heap/vxworks/heap_scan_bss.c
  76. 0 24
      lub/heap/vxworks/heap_scan_data.c
  77. 0 135
      lub/heap/vxworks/heap_symShow.c
  78. 0 6
      lub/heap/vxworks/module.am
  79. 0 15
      lub/module.am
  80. 0 241
      lub/partition.h
  81. 0 24
      lub/partition/module.am
  82. 0 22
      lub/partition/partition_check_memory.c
  83. 0 19
      lub/partition/partition_destroy_local_heap.c
  84. 0 19
      lub/partition/partition_disable_leak_detection.c
  85. 0 19
      lub/partition/partition_enable_leak_detection.c
  86. 0 20
      lub/partition/partition_extend_memory.c
  87. 0 47
      lub/partition/partition_findcreate_local_heap.c
  88. 0 25
      lub/partition/partition_fini.c
  89. 0 31
      lub/partition/partition_init.c
  90. 0 137
      lub/partition/partition_realloc.c
  91. 0 17
      lub/partition/partition_segment_alloc.c
  92. 0 40
      lub/partition/partition_show.c
  93. 0 21
      lub/partition/partition_sysalloc.c
  94. 0 4
      lub/partition/posix/module.am
  95. 0 145
      lub/partition/posix/posix_partition.c
  96. 0 18
      lub/partition/posix/private.h
  97. 0 34
      lub/partition/private.h
  98. 0 3
      lub/partition/vxworks/module.am
  99. 0 18
      lub/partition/vxworks/private.h
  100. 0 142
      lub/partition/vxworks/vxworks_partition.c

File diff suppressed because it is too large
+ 19 - 250
Makefile.in


+ 0 - 226
lub/blockpool.h

@@ -1,226 +0,0 @@
-/**
-\ingroup lub
-\defgroup lub_blockpool blockpool
- @{
- 
-\brief This interface provides a facility to manage the allocation and
-deallocation of fixed sized blocks of memory.
-
-This type of memory manager is very fast and doesn't suffer from
-any memory fragmentation problems.
-
-This allocator uses block in the order in which they are freed,
-this is significant for some applications where you don't want to
-re-use a particular freed block too soon. e.g. hardware timing
-limits on re-use.
-
-The client is responsible for providing the memory to be managed.
-\author  Graeme McKerrell
-\date    Created On      : Fri Jan 23 12:50:18 2004
-\version TESTED
-*/
-/*---------------------------------------------------------------
- * HISTORY
- * 7-Dec-2004		Graeme McKerrell	
- *    Updated to use the "lub" prefix
- * 6-Feb-2004		Graeme McKerrell	
- *    removed init_fn type definition and parameter, the client had
- *    more flexiblity in defining their own initialisation operation with
- *    arguments rather than use a "one-size-fits-all" approach.
- *    Modified blockpool structure to support FIFO block allocation.
- * 23-Jan-2004		Graeme McKerrell	
- *    Initial version
- *---------------------------------------------------------------
- * Copyright (C) 2004 3Com Corporation. All Rights Reserved.
- *--------------------------------------------------------------- */
-#ifndef _lub_blockpool_h
-#define _lub_blockpool_h
-#include <stddef.h>
-
-/****************************************************************
- * TYPE DEFINITIONS
- **************************************************************** */
-typedef struct _lub_blockpool_block lub_blockpool_block_t;
-/**
- * This type represents a "blockpool" instance.
- */
-typedef struct _lub_blockpool lub_blockpool_t;
-struct _lub_blockpool {
-	/* CLIENTS MUSTN'T TOUCH THESE DETAILS */
-	lub_blockpool_block_t *m_head;
-	lub_blockpool_block_t *m_tail;
-	size_t m_block_size;
-	size_t m_num_blocks;
-	unsigned m_alloc_blocks;
-	unsigned m_alloc_total_blocks;
-	unsigned m_alloc_hightide_blocks;
-	unsigned m_alloc_failures;
-};
-/**
- * This type defines the statistics available for each blockpool.
- */
-typedef struct _lub_blockpool_stats lub_blockpool_stats_t;
-struct _lub_blockpool_stats {
-    /*----------------------------------------------------- */
-    /**
-     * NUmber of bytes in each block.
-     */
-	size_t block_size;
-    /**
-     * Total number of blocks in this pool.
-     */
-	size_t num_blocks;
-    /*----------------------------------------------------- */
-    /**
-     * Number of dynamically allocated blocks currently
-     * held by clients of a blockpool.
-     */
-	size_t alloc_blocks;
-    /**
-     * Number of dynamically allocated bytes currently
-     * held by clients of a blockpool.
-     */
-	size_t alloc_bytes;
-    /**
-     * Number of free blocks.
-     */
-	size_t free_blocks;
-    /**
-     * Number of bytes available in a blockpool.
-     */
-	size_t free_bytes;
-    /*----------------------------------------------------- */
-    /**
-     * Cumulative number of dynamically allocated blocks
-     * given to clients of a blockpool.
-     */
-	size_t alloc_total_blocks;
-    /**
-     * Cumulative number of dynamically allocated bytes
-     * given to clients of a blockpool.
-     */
-	size_t alloc_total_bytes;
-    /*----------------------------------------------------- */
-    /**
-     * Number of dynamically allocated blocks
-     * given to clients when the memory usage was at it's highest.
-     */
-	size_t alloc_hightide_blocks;
-    /**
-     * Number of dynamically allocated bytes
-     * given to clients of a blockpool when the memory usage was at it's
-     * highest
-     */
-	size_t alloc_hightide_bytes;
-    /**
-     * Number of free blocks when the memory usage was at it's
-     * highest
-     */
-	size_t free_hightide_blocks;
-    /**
-     * Number of free bytes when the memory usage was at it's highest.
-     */
-	size_t free_hightide_bytes;
-    /*----------------------------------------------------- */
-    /**
-     * Number of time an allocation has failed from this block
-     */
-	size_t alloc_failures;
-    /*----------------------------------------------------- */
-};
-/****************************************************************
- * BLOCKPOOL OPERATIONS
- **************************************************************** */
-/**
- * This operation initialises an instance of a blockpool.
- *
- *
- * \pre 'blocksize' must be an multiple of 'sizeof(void *)'.
- * (If the client declares a structure for the block this should be handled
- * automatically by the compiler)
- *
- * \post If the size constraint is not met an assert will fire.
- * \post Following initialisation the allocation of memory can be performed.
- */
-extern void lub_blockpool_init(
-	/** 
-         * the "blockpool" instance to initialise.
-         */
-				      lub_blockpool_t * blockpool,
-	/** 
-         * the memory to be managed.
-         */
-				      void *memory,
-	/**
-         * The size in bytes of each block.
-         */
-				      size_t blocksize,
-	/** The number of blocks to be managed. NB the client is
-         * responsible for ensuring that (blocksize x blockcount)
-         * bytes of memory are available for use.
-         */
-				      unsigned blockcount);
-
-/**
- * This operation allocates a "block" of memory from a "blockpool"
- *
- *
- * \pre
- * The blockpool must have been initialised.
- * 
- * \return
- * A pointer to a "block" of memory, or NULL if there is none left for
- * allocation.
- *
- * \post
- * The behaviour is undefined if the "blockpool" is uninitialised.
- */
-extern void *lub_blockpool_alloc(
-	/** 
-         * the "blockpool" instance to invoke this operation upon
-         */
-					lub_blockpool_t * blockpool);
-
-/**
- * This operation de-allocates a "block" of memory back into a "blockpool"
- *
- * \pre
- * The specified block must have been previously allocated using
- * lub_blockpool_alloc()
- * 
- * \post
- * The de-allocated block become available for subsequent
- * lub_blockpool_alloc() requests.
- */
-extern void lub_blockpool_free(
-	/** 
-         * the "blockpool" instance to invoke this operation upon
-         */
-				      lub_blockpool_t * blockpool,
-	/** 
-         * the "block" to release back to the pool
-         */
-				      void *block);
-/**
- * This operation fills out a statistics structure with the details for the 
- * specified blockpool.
- *
- * \pre
- * - none
- *
- * \post
- * - the results filled out are a snapshot of the statistics as the time
- *   of the call.
- */
-void lub_blockpool__get_stats(
-	/**
-         * The instance on which to operate
-         */
-				     lub_blockpool_t * instance,
-	/**
-         * A client provided structure to fill out with the blockpool details
-         */
-				     lub_blockpool_stats_t * stats);
-
-#endif				/* _lub_blockpool_h */
-/** @} blockpool */

+ 0 - 29
lub/blockpool/blockpool__get_stats.c

@@ -1,29 +0,0 @@
-/*
- * blockpool__get_stats->c
- */
-#include "private.h"
-
-/*--------------------------------------------------------- */
-void
-lub_blockpool__get_stats(lub_blockpool_t * this, lub_blockpool_stats_t * stats)
-{
-	stats->block_size = this->m_block_size;
-	stats->num_blocks = this->m_num_blocks;
-	stats->alloc_blocks = this->m_alloc_blocks;
-	stats->alloc_bytes = stats->alloc_blocks * stats->block_size;
-	stats->free_blocks = stats->num_blocks - stats->alloc_blocks;
-	stats->free_bytes = stats->free_blocks * stats->block_size;
-	stats->alloc_total_blocks = this->m_alloc_total_blocks;
-	stats->alloc_total_bytes =
-	    stats->alloc_total_blocks * stats->block_size;
-	stats->alloc_hightide_blocks = this->m_alloc_hightide_blocks;
-	stats->alloc_hightide_bytes =
-	    stats->alloc_hightide_blocks * stats->block_size;
-	stats->free_hightide_blocks =
-	    stats->num_blocks - stats->alloc_hightide_blocks;
-	stats->free_hightide_bytes =
-	    stats->free_hightide_blocks * stats->block_size;
-	stats->alloc_failures = this->m_alloc_failures;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 70
lub/blockpool/blockpool_alloc.c

@@ -1,70 +0,0 @@
-/*********************** -*- Mode: C -*- ***********************
- * File            : blockpool_alloc.c
- *---------------------------------------------------------------
- * Description
- * ===========
- *---------------------------------------------------------------
- * This operation allocates a "block" of memory from a "blockpool"
- *
- * blockpool - the "blockpool" instance to invoke this operation upon
- *
- * PRE-CONDITIONS
- * The blockpool must have been initialised.
- * 
- * RETURNS
- * A pointer to a "block" of memory, or NULL if there is none left for
- * allocation.
- *
- * POST-CONDITIONS
- * The behaviour is undefined if the "blockpool" is uninitialised.
- *
- * If an initialisation operation has been registered then this will
- * have been invoked with the block pointer before returning from this
- * call. 
- *---------------------------------------------------------------
- * Author          : Graeme McKerrell
- * Created On      : Thu Jan 29 14:11:00 2004
- * Status          : TESTED
- *---------------------------------------------------------------
- * HISTORY
- * 7-Dec-2004		Graeme McKerrell	
- *    updated to use the "lub_" namespace
- * 5-May-2004		Graeme McKerrell	
- *    updates following review
- * 1-Apr-2004		Peter Kennedy	
- *    updated to fix last entry removal test - use tail
- * 6-Feb-2004		Graeme McKerrell	
- *    updated to use FIFO allocation of blocks
- *    removed initialisation function call.
- * 29-Jan-2004		Graeme McKerrell	
- *    Initial version
- *---------------------------------------------------------------
- * Copyright (C) 2004 3Com Corporation. All Rights Reserved.
- **************************************************************** */
-#include "private.h"
-
-/*--------------------------------------------------------- */
-void *lub_blockpool_alloc(lub_blockpool_t * this)
-{
-	lub_blockpool_block_t *newblock = this->m_head;
-	if (newblock) {
-		if (newblock == this->m_tail) {
-			/* remove the last item from the pool */
-			this->m_head = NULL;
-			this->m_tail = NULL;
-		} else {
-			this->m_head = newblock->next;
-		}
-		/* updated the stats */
-		++this->m_alloc_blocks;
-		++this->m_alloc_total_blocks;
-		if (this->m_alloc_blocks > this->m_alloc_hightide_blocks) {
-			this->m_alloc_hightide_blocks = this->m_alloc_blocks;
-		}
-	} else {
-		++this->m_alloc_failures;
-	}
-	return newblock;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 58
lub/blockpool/blockpool_free.c

@@ -1,58 +0,0 @@
-/*********************** -*- Mode: C -*- ***********************
- * File            : blockpool_free.c
- *---------------------------------------------------------------
- * Description
- * ===========
- * This operation de-allocates a "block" of memory back into a "blockpool"
- *
- * blockpool - the "blockpool" instance to invoke this operation upon
- *
- * PRE-CONDITIONS
- * The specified block must have been previously allocated using
- * lub_blockpool_alloc.
- * 
- * POST-CONDITIONS
- * The de-allocated block become available for subsequent
- * lub_blockpool_alloc() requests.
- *---------------------------------------------------------------
- * Author          : Graeme McKerrell
- * Created On      : Thu Jan 29 14:08:41 2004
- * Status          : TESTED
- *---------------------------------------------------------------
- * HISTORY
- * 7-Dec-2004		Graeme McKerrell	
- *    updated to use the "lub_" namespace
- * 5-May-2004		Graeme McKerrell	
- *    updates following review
- * 1-Apr-2004		Peter Kennedy	
- *    updated to free the tail as well as the head
- * 6-Feb-2004		Graeme McKerrell	
- *    updated to use FIFO allocation of blocks
- * 29-Jan-2004		Graeme McKerrell	
- *   Initial version
- *---------------------------------------------------------------
- * Copyright (C) 2004 3Com Corporation. All Rights Reserved.
- **************************************************************** */
-#include "private.h"
-
-/*--------------------------------------------------------- */
-void lub_blockpool_free(lub_blockpool_t * this, void *block)
-{
-	lub_blockpool_block_t *newfree = block;
-
-	/* simply add this block to the end of the free list */
-	newfree->next = NULL;
-	if (NULL != this->m_tail) {
-		this->m_tail->next = newfree;
-	} else {
-		/* first entry in the list */
-		this->m_head = newfree;
-	}
-	/* add to end of list */
-	this->m_tail = newfree;
-
-	/* updated the stats */
-	--this->m_alloc_blocks;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 73
lub/blockpool/blockpool_init.c

@@ -1,73 +0,0 @@
-/*********************** -*- Mode: C -*- ***********************
- * File            : blockpool_init.c
- *---------------------------------------------------------------
- * Description
- * ===========
- * This operation initialises an instance of a blockpool.
- *
- * blockpool   - the "blockpool" instance to initialise.
- * memory      - the memory to be managed.
- * blocksize   - The size in bytes of each block.
- * blockcount  - The number of blocks to be managed. NB the client is
- *               responsible for ensuring that (blocksize x blockcount)
- *               bytes of memory are available for use.
- *
- * PRE-CONDITION
- * 'blocksize' must be an multiple of 'sizeof(void *)'.
- * (If the client declares a structure for the block this should be handled
- * automatically by the compiler)
- *
- * POST-CONDITION
- * If the size constraint is not met an assert will fire.
- *
- * Following initialisation the allocation of memory can be performed.
- *
- *---------------------------------------------------------------
- * Author          : Graeme McKerrell
- * Created On      : Thu Jan 29 13:57:54 2004
- * Status          : TESTED
- *---------------------------------------------------------------
- * HISTORY
- * 7-Dec-2004		Graeme McKerrell	
- *    updated to use the "lub_" namespace
- * 5-May-2004		Graeme McKerrell	
- *    updates following review
- * 6-Feb-2004		Graeme McKerrell	
- *    removed extra init_fn parameter from the initialisation call
- * 28-Jan-2004		Graeme McKerrell	
- *   Initial version
- *---------------------------------------------------------------
- * Copyright (C) 2004 3Com Corporation. All Rights Reserved.
- **************************************************************** */
-#include <assert.h>
-#include "private.h"
-
-/*--------------------------------------------------------- */
-void
-lub_blockpool_init(lub_blockpool_t * this,
-		   void *memory, size_t blocksize, unsigned blockcount)
-{
-	unsigned i;
-	char *ptr = memory;
-
-	/* check that this is a multiple of sizeof(void*) */
-	assert((blocksize & (sizeof(void *) - 1)) == 0);
-
-	/* start off with nothing in the list */
-	this->m_head = this->m_tail = NULL;
-
-	/* run through all the blocks placing them into the free list */
-	for (i = 0; i < blockcount; ++i) {
-		lub_blockpool_free(this, ptr);
-		ptr += blocksize;
-	}
-	/* intialise the stats */
-	this->m_block_size = blocksize;
-	this->m_num_blocks = blockcount;
-	this->m_alloc_blocks = 0;
-	this->m_alloc_total_blocks = 0;
-	this->m_alloc_hightide_blocks = 0;
-	this->m_alloc_failures = 0;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 7
lub/blockpool/module.am

@@ -1,7 +0,0 @@
-## Process this file with automake to produce Makefile.in
-liblub_la_SOURCES  += lub/blockpool/blockpool_alloc.c   \
-              lub/blockpool/blockpool__get_stats.c      \
-              lub/blockpool/blockpool_free.c            \
-              lub/blockpool/blockpool_init.c            \
-              lub/blockpool/private.h
-

+ 0 - 29
lub/blockpool/private.h

@@ -1,29 +0,0 @@
-/*********************** -*- Mode: C -*- ***********************
- * File            : private.h
- *---------------------------------------------------------------
- * Description
- * ===========
- * This defines the private interface used internally by this component
- *---------------------------------------------------------------
- * Author          : Graeme McKerrell
- * Created On      : Wed Jan 28 08:45:01 2004
- * Status          : TESTED
- *---------------------------------------------------------------
- * HISTORY
- * 7-Dec-2004		Graeme McKerrell	
- *    updated to "lub_" namespace
- * 5-May-2004		Graeme McKerrell	
- *    updates following review
- * 28-Jan-2004		Graeme McKerrell	
- *   Initial version
- *---------------------------------------------------------------
- * Copyright (C) 2004 3Com Corporation. All Rights Reserved.
- **************************************************************** */
-#include "lub/blockpool.h"
-
-struct _lub_blockpool_block {
-	lub_blockpool_block_t *next;
-};
-/*************************************************************
- * PRIVATE OPERATIONS
- ************************************************************* */

+ 0 - 140
lub/dblockpool.h

@@ -1,140 +0,0 @@
-/**
-\ingroup lub
-\defgroup lub_dblockpool dblockpool
- @{
- 
-\brief This interface provides a dynamic facility to manage the allocation and
-deallocation of fixed sized blocks of memory.
-
-It dynamically allocates chunks of memory each of which is used as a "blockpool".
-This dynamic memory is taken from the standard heap via "malloc()".
-
-This type of memory manager is very fast and doesn't suffer from
-any memory fragmentation problems.
-
-This allocator can reuse blocks in the order in which they are freed,
-this is significant for some applications where you don't want to
-re-use a particular freed block too soon. e.g. hardware timing
-limits on re-use.
-
-\author  Graeme McKerrell
-\date    Created On      : Fri Feb 24 14:50:18 2005
-\version TESTED
-*/
-/*---------------------------------------------------------------
- * HISTORY
- * 24-Feb-2006      Graeme McKerrell
- *    Initial version
- *---------------------------------------------------------------
- * Copyright (C) 2006 Newport Networks. All Rights Reserved.
- *--------------------------------------------------------------- */
-#ifndef _lub_dblockpool_h
-#define _lub_dblockpool_h
-#include <stddef.h>
-
-#include "c_decl.h"
-
-_BEGIN_C_DECL
-/****************************************************************
- * TYPE DEFINITIONS
- **************************************************************** */
-/**
- * This type represents a "dblockpool" instance.
- */
-typedef struct _lub_dblockpool lub_dblockpool_t;
-/**
- * CLIENTS MUST NOT USE THESE FIELDS DIRECTLY
- */
-struct _lub_dblockpool {
-	struct _lub_dblockpool_chunk *first_chunk;
-	size_t block_size;
-	unsigned chunk_size;
-	unsigned max_chunks;
-};
-
-/****************************************************************
- * DBLOCKPOOL OPERATIONS
- **************************************************************** */
-/**
- * This operation initialises an instance of a dblockpool.
- *
- * \pre 'blocksize' must be an multiple of 'sizeof(void *)'.
- * (If the client declares a structure for the block this should be handled
- * automatically by the compiler)
- *
- * \post If the size constraint is not met an assert will fire.
- * \post Following initialisation the allocation of memory can be performed.
- */
-extern void lub_dblockpool_init(
-	/** 
-         * the "dblockpool" instance to initialise.
-         */
-				       lub_dblockpool_t * instance,
-	/**
-         * The size in bytes of each block.
-         */
-				       size_t blocksize,
-	/** 
-         * The number of blocks to be managed in a chunk.
-         */
-				       unsigned chunksize,
-	/** 
-         * The maximum number of chunks to be allocated.
-         * (a value of zero means unlimited...)
-         */
-				       unsigned max_chunks);
-/**
- * This operation finalises an instance of a dblockpool.
- *
- * \pre 'instance' must have been initialised first.
- *
- * \post All the dynamic memory allocated will be released.
- */
-extern void lub_dblockpool_fini(
-	/** 
-         * the "dblockpool" instance to finalise.
-         */
-				       lub_dblockpool_t * instance);
-/**
- * This operation allocates a "block" of memory from a "dblockpool"
- *
- *
- * \pre
- * The dblockpool must have been initialised.
- * 
- * \return
- * A pointer to a "block" of memory, or NULL if there is none left for
- * allocation.
- *
- * \post
- * The behaviour is undefined if the "dblockpool" is uninitialised.
- */
-extern void *lub_dblockpool_alloc(
-	/** 
-         * the "dblockpool" instance to operate on
-         */
-					 lub_dblockpool_t * instance);
-/**
- * This operation de-allocates a "block" of memory back into a "blockpool"
- *
- * \pre
- * The specified block must have been previously allocated using
- * lub_blockpool_alloc()
- * 
- * \post
- * The de-allocated block become available for subsequent
- * lub_blockpool_alloc() requests.
- */
-extern void lub_dblockpool_free(
-	/** 
-         * the "blockpool" instance to invoke this operation upon
-         */
-				       lub_dblockpool_t * instance,
-	/** 
-         * the "block" to release back to the pool
-         */
-				       void *block);
-
-_END_C_DECL
-#endif				/* _lub_dblockpool_h */
-/** @} lub_dblockpool */

+ 0 - 48
lub/dblockpool/dblockpool_alloc.c

@@ -1,48 +0,0 @@
-#include <stdlib.h>
-
-#include "private.h"
-
-/*--------------------------------------------------------- */
-void *lub_dblockpool_alloc(lub_dblockpool_t * this)
-{
-	void *result = NULL;
-	lub_dblockpool_chunk_t *chunk;
-	unsigned chunk_count = 0;
-
-	/* first find a chunk which can service this request */
-	for (chunk = this->first_chunk; chunk; chunk = chunk->next) {
-		chunk_count++;
-		/* try and get a block from this chunk */
-		result = lub_blockpool_alloc(&chunk->pool);
-		if (NULL != result) {
-			/* got some memory */
-			break;
-		}
-	}
-	if ((NULL == result)
-	    && (!this->max_chunks || (chunk_count < this->max_chunks))) {
-		/* dynamically allocate a new chunk */
-		chunk =
-		    malloc(sizeof(lub_dblockpool_chunk_t) +
-			   (this->block_size * this->chunk_size));
-		if (NULL != chunk) {
-			/* configure the new chunk */
-			chunk->next = this->first_chunk;
-			lub_blockpool_init(&chunk->pool,
-					   &chunk[1],
-					   this->block_size, this->chunk_size);
-			this->first_chunk = chunk;
-			chunk->count = 0;
-
-			/* now allocate the memory */
-			result = lub_blockpool_alloc(&chunk->pool);
-		}
-	}
-	if ((NULL != result) && (NULL != chunk)) {
-		/* track the number of allocations */
-		chunk->count++;
-	}
-	return result;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 17
lub/dblockpool/dblockpool_fini.c

@@ -1,17 +0,0 @@
-#include <stdlib.h>
-
-#include "private.h"
-
-/*--------------------------------------------------------- */
-void lub_dblockpool_fini(lub_dblockpool_t * this)
-{
-	lub_dblockpool_chunk_t *chunk;
-
-	/* release all the memory used for contexts */
-	while ((chunk = this->first_chunk)) {
-		this->first_chunk = chunk->next;
-		free(chunk);
-	}
-}
-
-/*--------------------------------------------------------- */

+ 0 - 34
lub/dblockpool/dblockpool_free.c

@@ -1,34 +0,0 @@
-#include <stdlib.h>
-
-#include "private.h"
-
-/*--------------------------------------------------------- */
-void lub_dblockpool_free(lub_dblockpool_t * this, void *block)
-{
-	lub_dblockpool_chunk_t **chunk_ptr;
-
-	/* find the chunk from which this derived. */
-	for (chunk_ptr = &this->first_chunk;
-	     *chunk_ptr; chunk_ptr = &(*chunk_ptr)->next) {
-		const char *pool_start = (char *)&(*chunk_ptr)[1];
-		const char *pool_end =
-		    pool_start + (this->block_size * this->chunk_size);
-		const char *ptr = block;
-
-		if ((ptr >= pool_start) && (ptr < pool_end)) {
-			/* found the right pool */
-			lub_blockpool_free(&(*chunk_ptr)->pool, block);
-			(*chunk_ptr)->count--;
-			/* track the number of allocations */
-			if (0 == (*chunk_ptr)->count) {
-				lub_dblockpool_chunk_t *tmp = *chunk_ptr;
-				/* removing last block from this chunk */
-				*chunk_ptr = (*chunk_ptr)->next;
-				free(tmp);
-			}
-			break;
-		}
-	}
-}
-
-/*--------------------------------------------------------- */

+ 0 - 14
lub/dblockpool/dblockpool_init.c

@@ -1,14 +0,0 @@
-#include "private.h"
-
-/*--------------------------------------------------------- */
-void
-lub_dblockpool_init(lub_dblockpool_t * this,
-		    size_t block_size, unsigned chunk_size, unsigned max_chunks)
-{
-	this->first_chunk = NULL;
-	this->block_size = block_size;
-	this->chunk_size = chunk_size;
-	this->max_chunks = max_chunks;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 7
lub/dblockpool/module.am

@@ -1,7 +0,0 @@
-## Process this file with automake to produce Makefile.in
-liblub_la_SOURCES  +=   lub/dblockpool/dblockpool_alloc.c   \
-                        lub/dblockpool/dblockpool_fini.c    \
-                        lub/dblockpool/dblockpool_free.c    \
-                        lub/dblockpool/dblockpool_init.c    \
-                        lub/dblockpool/private.h
-

+ 0 - 9
lub/dblockpool/private.h

@@ -1,9 +0,0 @@
-#include "lub/dblockpool.h"
-#include "lub/blockpool.h"
-
-typedef struct _lub_dblockpool_chunk lub_dblockpool_chunk_t;
-struct _lub_dblockpool_chunk {
-	lub_dblockpool_chunk_t *next;
-	lub_blockpool_t pool;
-	unsigned count;
-};

+ 0 - 997
lub/heap.h

@@ -1,997 +0,0 @@
-/*
- * heap.h
- */
-/**
-\ingroup lub
-\defgroup lub_heap heap
-@{
-
-\brief This is a generic heap manager which incorporates a memory leak detection system 
-which can monitor and report the dynamic memory which is in use for each heap.
-
-A client creates an instance of heap; providing it with memory segments
-to manage. Subsequent operations can then be invoked to obtain memory
-from those registered segments.
-
-\section static_allocs Static allocation
-Static memory allocations are those which are for the lifetime of the
-heap from which they are allocated. Because they do not need to be freed
-there is zero overhead required for such blocks; they can be exactly butted 
-up against each other in memory. There is also zero fragmentation as they 
-are never freed.
-
-\section dynamic_allocs Dynamic allocation
-Dynamic memory allocations have a lifetime less than that of the heap 
-from which they are allocated. In order to manage the reuse of this blocks
-once they are released, there will be a slight "housekeeping" overhead
-associated with each block. They are also suceptible to fragmentation, which 
-can occur when the lifetimes of blocks differ from one another.
-
-\section leak_detection Leak Detection
-It monitors the dynamic allocation which are performed and maintains 
-statistics to help identify and isolation memory leaks.
-
-It detects two types of leak by scanning the BSS and DATA segments and identifying 
-any nodes referenced from there. Then each of these referenced nodes is scanned to 
-look for further references.
-
-\subsection full_leak Full Leak
-there is no reference to a block of memory or to any memory within that block in the system.
-
-\subsection partial_leak Partial Leak
-there is no reference to the start of a block of memory. NB. there
-may be circumstances where this is not a real leak, e.g. memory allocation
-systems typically hand out references just beyond a control header to their
-clients. However there may also be instances where this is a real leak 
-and someone just happens to have a reference to some contained data.
-
-\section tainting  Memory Tainting
-Memory is deliberately dirtied in the following ways:
-
--   Initial heap space - 0xBBBBBBBB
--   Allocated memory   - 0xAAAAAAAA
--   Freed memory       - 0xFFFFFFFF
--   Dead Stack memory  - 0xCCCCCCCC (done before leak scan)
-
-\section usage Utility functions
-Currently the following utility functions are available:
-
-- leakScan [0|1|2]      - provides a dump of the currently allocated blocks of 
-                          memory in the system pool.
-                          argument values have the following meanings:
-                          - 0 - display stats for just memory leaks.
-                          - 1 - display stats for memory leaks and partial leaks.
-                          - 2 - display stats for all currently allocation memory 
-                          blocks.
-
-- leakEnable [framecount] - enables leak detection and causes the current statistics to be 
-                          cleared out.
-                          Even if there are memory blocks in use, this
-                          command will cause future "leakShow" invocations
-                          to behave as if monitoring started from this new
-                          point in time.
-                          The optional 'framecount' argument can be used 
-                          to change the number of levels of backtrace
-                          recorded. By default this number is 16. The
-                          number of contexts stored will be affected by
-                          this number. If the value is small then a
-                          limited number of contexts will exist and the 
-                          memory overhead of monitoring will be reduced. 
-                          If the number is large (can support a maximum 
-                          of 16 levels) then the granularity of the
-                          contexts will be finer i.e. more of them, but 
-                          the memory overhead in monitoring will be 
-                          increased.
-                          With no specified framecount the maximum will be assumed.
-
-- leakDisable             - Disabled the leak detection.
-    
-\section implementation Implementation
-Static and dynamic blocks are allocated from opposite ends of a memory
-segment. As static blocks are allocated the end of the last 
-"free block" migrates downwards in memory. Dynamic blocks are allocated 
-from the start of the appropriately sized free block, hence leaving
-space for static allocations at the end of the heap memory.
-
-The heap implements a "best fit" model, for allocation of dynamic memory.
-This means that free blocks are maintained in size order and hence
-the most appropriate one can be used to satisfy client requests.
-This minimises fragmentation of the dynamically allocated memory.
-
-The free blocks are held in a binary tree (using \ref lub_bintree) which provide
-fast searching for the appropriate block.
-
-\author  Graeme McKerrell
-\date    Created On      : Wed Dec 14 10:20:00 2005
-\version UNTESTED
-*/
-#ifndef _lub_heap_h
-#define _lub_heap_h
-#include <stddef.h>
-
-#include "lub/types.h"
-#include "lub/c_decl.h"
-_BEGIN_C_DECL
-/**
- * This type is used to reference an instance of a heap.
- */
-typedef struct lub_heap_s lub_heap_t;
-
-/**
- * This type is used to reference an instance of a free block
- */
-typedef struct lub_heap_free_block_s lub_heap_free_block_t;
-
-/**
- * This type defines the statistics available for each heap.
- */
-typedef struct lub_heap_stats_s lub_heap_stats_t;
-struct lub_heap_stats_s {
-    /*----------------------------------------------------- */
-    /**
-     * Number of segments comprising this heap.
-     */
-	size_t segs;
-    /**
-     * Number of bytes available in all the segments.
-     */
-	size_t segs_bytes;
-    /**
-     * Number of bytes used in housekeeping overheads
-     */
-	size_t segs_overhead;
-    /*----------------------------------------------------- */
-    /**
-     * Number of free blocks. This is indication 
-     * the fragmentation state of a heap.
-     */
-	size_t free_blocks;
-    /**
-     * Number of bytes available in a heap.
-     */
-	size_t free_bytes;
-    /**
-     * Number of bytes used in housekeeping overheads
-     */
-	size_t free_overhead;
-    /*----------------------------------------------------- */
-    /**
-     * Number of dynamically allocated blocks currently
-     * held by clients of a heap.
-     */
-	size_t alloc_blocks;
-    /**
-     * Number of dynamically allocated bytes currently
-     * held by clients of a heap.
-     */
-	size_t alloc_bytes;
-    /**
-     * Number of bytes used in housekeeping overheads
-     */
-	size_t alloc_overhead;
-    /*----------------------------------------------------- */
-    /**
-     * Cumulative number of dynamically allocated blocks
-     * given to clients of a heap.
-     */
-	size_t alloc_total_blocks;
-    /**
-     * Cumulative number of dynamically allocated bytes
-     * given to clients of a heap.
-     */
-	size_t alloc_total_bytes;
-    /*----------------------------------------------------- */
-    /**
-     * Number of dynamically allocated blocks
-     * given to clients when the memory usage was at it's highest.
-     */
-	size_t alloc_hightide_blocks;
-    /**
-     * Number of dynamically allocated bytes
-     * given to clients of a heap when the memory usage was at it's
-     * highest
-     */
-	size_t alloc_hightide_bytes;
-    /**
-     * Number of bytes of overhead in use when the memory usage 
-     * was at it's highest
-     */
-	size_t alloc_hightide_overhead;
-    /**
-     * Number of free blocks when the memory usage was at it's
-     * highest
-     */
-	size_t free_hightide_blocks;
-    /**
-     * Number of free bytes when the memory usage was at it's highest.
-     */
-	size_t free_hightide_bytes;
-   /**
-     * Number of housekeeping overhead bytes when the memory 
-     * usage was at it's highest.
-     */
-	size_t free_hightide_overhead;
-    /*----------------------------------------------------- */
-    /**
-     * Number of statically allocated blocks currently
-     * held by clients of a heap.
-     */
-	size_t static_blocks;
-    /**
-     * Number of statically allocated bytes currently
-     * held by clients of a heap.
-     */
-	size_t static_bytes;
-    /**
-     * Number of dynamically allocated bytes currently
-     * held by clients of a heap.
-     */
-	size_t static_overhead;
-    /*----------------------------------------------------- */
-};
-/**
- * This type is used to indicate the result of a dynamic
- * memory allocation
- */
-typedef enum {
-    /**
-     * The allocation was successful
-     */
-	LUB_HEAP_OK,
-    /**
-     * There was insufficient resource to satisfy the request
-     */
-	LUB_HEAP_FAILED,
-    /**
-     * An attempt has been made to release an already freed block
-     * of memory.
-     */
-	LUB_HEAP_DOUBLE_FREE,
-    /**
-     * A memory corruption has been detected. e.g. someone writing
-     * beyond the bounds of an allocated block of memory.
-     */
-	LUB_HEAP_CORRUPTED,
-    /**
-     * The client has passed in an invalid pointer
-     * i.e. one which lies outside the bounds of the current heap.
-     */
-	LUB_HEAP_INVALID_POINTER
-} lub_heap_status_t;
-
-typedef struct {
-	void *ptr;
-} struct_void_ptr;
-/**
- * This type is used to indicate the alignment required 
- * for a memory allocation.
- */
-typedef enum {
-    /**
-     * This is the "native" alignment required for the current
-     * CPU architecture.
-     */
-	LUB_HEAP_ALIGN_NATIVE = sizeof(struct_void_ptr),
-    /**
-     * 4 byte alignment
-     */
-	LUB_HEAP_ALIGN_2_POWER_2 = 0x00000004,
-    /**
-     * 8 byte alignment
-     */
-	LUB_HEAP_ALIGN_2_POWER_3 = 0x00000008,
-    /**
-     * 16 byte alignment
-     */
-	LUB_HEAP_ALIGN_2_POWER_4 = 0x00000010,
-    /**
-     * 32 byte alignment
-     */
-	LUB_HEAP_ALIGN_2_POWER_5 = 0x00000020,
-    /**
-     * 64 byte alignment
-     */
-	LUB_HEAP_ALIGN_2_POWER_6 = 0x00000040,
-    /**
-     * 128 byte alignment
-     */
-	LUB_HEAP_ALIGN_2_POWER_7 = 0x00000080,
-    /**
-     * 256 byte alignment
-     */
-	LUB_HEAP_ALIGN_2_POWER_8 = 0x00000100,
-    /**
-     * 512 byte alignment
-     */
-	LUB_HEAP_ALIGN_2_POWER_9 = 0x00000200,
-    /**
-     * 1024 byte alignment (1KB)
-     */
-	LUB_HEAP_ALIGN_2_POWER_10 = 0x00000400,
-    /**
-     * 2048 byte alignment (2KB)
-     */
-	LUB_HEAP_ALIGN_2_POWER_11 = 0x00000800,
-    /**
-     * 4096 byte alignment (4KB)
-     */
-	LUB_HEAP_ALIGN_2_POWER_12 = 0x00001000,
-    /**
-     * 8192 byte alignment (8KB)
-     */
-	LUB_HEAP_ALIGN_2_POWER_13 = 0x00002000,
-    /**
-     * 16384 byte alignment (16KB)
-     */
-	LUB_HEAP_ALIGN_2_POWER_14 = 0x00004000,
-    /**
-     * 32768 byte alignment (32KB)
-     */
-	LUB_HEAP_ALIGN_2_POWER_15 = 0x00008000,
-    /**
-     * 65536 byte alignment (64KB)
-     */
-	LUB_HEAP_ALIGN_2_POWER_16 = 0x00010000,
-    /**
-     * 131072 byte alignment (128KB)
-     */
-	LUB_HEAP_ALIGN_2_POWER_17 = 0x00020000,
-    /**
-     * 262144 byte alignment (256KB)
-     */
-	LUB_HEAP_ALIGN_2_POWER_18 = 0x00040000,
-    /**
-     * 524288 byte alignment (512KB)
-     */
-	LUB_HEAP_ALIGN_2_POWER_19 = 0x00080000,
-    /**
-     * 1048576 byte alignment (1MB)
-     */
-	LUB_HEAP_ALIGN_2_POWER_20 = 0x00100000,
-    /**
-     * 2097152 byte alignment (2MB)
-     */
-	LUB_HEAP_ALIGN_2_POWER_21 = 0x00200000,
-    /**
-     * 4194304 byte alignment (4MB)
-     */
-	LUB_HEAP_ALIGN_2_POWER_22 = 0x00400000,
-    /**
-     * 8388608 byte alignment (8MB)
-     */
-	LUB_HEAP_ALIGN_2_POWER_23 = 0x00800000,
-    /**
-     *  16777216 byte alignment (16MB)
-     */
-	LUB_HEAP_ALIGN_2_POWER_24 = 0x01000000,
-    /**
-     *  33554432 byte alignment (32MB)
-     */
-	LUB_HEAP_ALIGN_2_POWER_25 = 0x02000000,
-    /**
-     * 67108864 byte alignment (64MB)
-     */
-	LUB_HEAP_ALIGN_2_POWER_26 = 0x04000000,
-    /**
-     * 134217728 byte alignment (128MB)
-     */
-	LUB_HEAP_ALIGN_2_POWER_27 = 0x08000000
-}
-lub_heap_align_t;
-
-/**
- * This type defines how leak details should be displayed
- */
-typedef enum {
-    /**
-     * Only show allocations which have no reference elsewhere
-     * in the system
-     */
-	LUB_HEAP_SHOW_LEAKS,
-    /**
-     * Only show allocations which have no direct reference elsewhere
-     * in the system, but do have their contents referenced.
-     */
-	LUB_HEAP_SHOW_PARTIALS,
-    /**
-     * Show all the current allocations in the system.
-     */
-	LUB_HEAP_SHOW_ALL
-} lub_heap_show_e;
-
-/**
- * This type defines a function prototype to be used to 
- * iterate around each of a number of things in the system.
- */
-typedef void lub_heap_foreach_fn(
-	/**
-         * The current entity
-         */
-					void *block,
-	/**
-         * A simple 1-based identifier for this entity
-         */
-					unsigned index,
-	/**
-         * The number of bytes available in this entity
-         */
-					size_t size,
-	/**
-         * Client specific argument
-         */
-					void *arg);
-
-/**
- * This operation is a diagnostic which can be used to 
- * iterate around all the segments in the specified heap.
- * For example it may be desirable to output information about 
- * each of the segments present.
- *
- * \pre
- * - The heap needs to have been create with an initial memory segment.
- *
- * \return 
- * - none
- *
- * \post
- * -The specified function will have been called once for every segment
- *  in the specified heap
- */
-void lub_heap_foreach_segment(
-	/**
-         * The heap instance on which to operate
-         */
-				     lub_heap_t * instance,
-	/**
-         * The client provided function to call for each free block
-         */
-				     lub_heap_foreach_fn * fn,
-	/**
-         * Some client specific data to pass through to the callback
-         * function.
-         */
-				     void *arg);
-/**
- * This operation is a diagnostic which can be used to 
- * iterate around all the free blocks in the specified heap.
- * For example it may be desirable to output information about 
- * each of the free blocks present.
- *
- * \pre
- * - The heap needs to have been create with an initial memory segment.
- *
- * \return 
- * - none
- *
- * \post
- * -The specified function will have been called once for every free
- *  block in the specified heap
- */
-void lub_heap_foreach_free_block(
-	/**
-         * The heap instance on which to operate
-         */
-					lub_heap_t * instance,
-	/**
-         * The client provided function to call for each free block
-         */
-					lub_heap_foreach_fn * fn,
-	/**
-         * Some client specific data to pass through to the callback
-         * function.
-         */
-					void *arg);
-
-/**
-  * This operation creates a dynamic heap from the provided
-  * memory segment.
-  *
-  * \pre
-  * - none
-  *
-  * \return
-  * - a reference to a heap object which can be used to allocate
-  *   memory from the segments associated with this heap.
-  *
-  * \post
-  * - memory allocations can be invoked on the returned intance.
-  * - further memory segements can be augmented to the heap using
-  *   the lub_heap_add_segment() operation.
-  */
-lub_heap_t *lub_heap_create(
-	/**
-         * The begining of the first memory segment to associate with 
-         * this heap
-         */
-				   void *start,
-	/**
-         * The number of bytes available for use in the first segment.
-         */
-				   size_t size);
-/**
-  * This operation creates a dynamic heap from the provided
-  * memory segment.
-  *
-  * \pre
- * - The heap needs to have been create with an initial memory segment.
-  *
-  * \return
-  * - none
-  *
-  * \post
-  * - The heap is no longer valid for use.
-  * - The memory segment(s) previously given to the heap
-  *   may now be reused.
-  * - Any extra resources used for leak detection will have been released.
-  */
-void lub_heap_destroy(
-	/**
-         * The heap instance on which to operate
-         */
-			     lub_heap_t * instance);
-/**
- * This operation augments an existing heap with 
- * some more memory to manage.
- * NB. if the memory happens to be follow on from the initial memory segment
- * then the two will merge into a single larger segment. This means that a heap
- * which is expanded with a sbrk() like mechanism will contain a single
- * expandible segment.
- *
- * \pre
- * - The heap needs to have been create with an initial memory segment.
- *
- * \return 
- * - none
- *
- * \post
- * - The new segment of memory becomes available for use by this heap.
- */
-void lub_heap_add_segment(
-	/**
-         * The heap instance on which to operate
-         */
-				 lub_heap_t * instance,
-	/** 
-         * The beginning of the memory segment to be managed
-         */
-				 void *start,
-	/**
-         * The number of bytes available for use in this segment
-         */
-				 size_t size);
-/**
- * This operation allocates some "static" memory from a heap. This is 
- * memory which will remain allocted for the lifetime of the heap instance.
- * "static" memory allocation has zero overhead and causes zero fragmentation.
- *
- * NB. static allocation are only handed out from the first memory segment 
- *
- * \pre
- * - The heap needs to have been created with an initial memory segment.
- *
- * \return 
- * - a pointer to some "static" memory which will be fixed for the
- *   remaining lifetime of this heap.
- *
- * \post
- * - The client cannot ever free this memory although if the heap is
- *   managing memory which itself has been dynamically allocated, then 
- *   the memory will be recovered when the heap is released.
- */
-void *lub_heap_static_alloc(
-	/**
-         * The heap instance on which to operate
-         */
-				   lub_heap_t * instance,
-	/**
-         * The number of bytes to allocate
-         */
-				   size_t size);
-/**
- * This operation changes the size of the object referenced by a passed in 
- * pointer to "size". The contents will be unchanged up to the minimum of the old 
- * and new sizes. If the new size is larger, the new space is uninitialised.
- *
- * \pre
- * - The heap needs to have been created with an initial memory segment.
- * - If "*ptr" contains a non-NULL value then this MUST have 
- *   been allocated using this operation, from the same heap instance.
- *
- * \return 
- * - the status of the operation.
- *
- * \post
- * - The client takes responsiblity for releasing any allocated memory when they
- *   are finished with it.
- * - If *ptr contains a non-NULL value, then after a succesfull call, the 
- *   initial memory referenced by it may have been released for reuse,
- *   and the pointer modified to reference some new memory.
- * - *ptr may contain NULL in which case no memory will be released back to the
- *   heap for reuse, and the pointer is filled out with the allocated memory.
- * - (size == 0) No new memory will be allocated, *ptr will be set to NULL,
- *   and any original memory referenced by it will have been released.
- */
-lub_heap_status_t lub_heap_realloc(
-	/**
-         * The heap instance on which to operate
-         */
-					  lub_heap_t * instance,
-	/**
-         * Reference to a pointer containing previously allocated memory 
-         * or NULL.
-         */
-					  char **ptr,
-	/**
-         * The number of bytes required for the object 
-         */
-					  size_t size,
-	/**
-         * The alignement required for a new allocations.
-         */
-					  lub_heap_align_t alignment);
-/**
- * This operation controls the tainted memory facility.
- * This means that during certain heap operations memory can
- * be filled with some well defined bit patterns. This causes
- * a slight performance overhead but can be used to shake out 
- * bugs such and free-memory-reads and uninitialised-memory-reads
- * 
- * By default tainting is switched off.
- *
- * \pre
- * - none
- *
- * \return 
- * - last tainted status
- *
- * \post
- * - (enabled) when a memory segment is given to a heap (either at creation or later)
- *   the contents will be set to 0xBB
- * - (enabled) when some dynamically allocated memory is released back to a heap
- *   the contents will be set to 0xFF
- * - (enabled) when some dynamic or static memory is allocated the contents will
- *   be set to 0xAA as the "uninitialised" value.
- * - (disabled) no memory tainting will occur.
- */
-bool_t lub_heap_taint(
-	/**
-         * BOOL_TRUE to enable tainting or BOOL_FALSE to disable
-         */
-			     bool_t enable);
-/**
- * This operation indicates the current status of the memory tainting
- * facility
- * 
- * \pre
- * none
- *
- * \return
- * - BOOL_TRUE if memory tainting is enabled.
- * - BOOL_FALSE if memory tainting is disabled.
- *
- * \post 
- * none
- */
-bool_t lub_heap_is_tainting(void);
-/**
- * This operation controls runtime heap corruption detection.
- * This means that during every heap operation a full check is 
- * done of the specified heap, before any allocations/free are 
- * performed.
- * This has a performance overhead but provides a valuable
- * aid in finding a memory corrupting client.
- * Corruption will be spotted the first time a memory operation
- * is performed AFTER it has occured.
- * 
- * By default checking is switched off.
- *
- * \pre
- * - none
- *
- * \return 
- * - last checking status
- *
- * \post
- * - (enabled) the heap will have been scanned for any corruption and if found the
- * return status of the invoking heap operation will be LUB_HEAP_CORRUPTED.
- * - (disabled) no entire heap memory checking will occur.
- */
-bool_t lub_heap_check(
-	/**
-         * BOOL_TRUE to enable checking or BOOL_FALSE to disable
-         */
-			     bool_t enable);
-
-/**
- * This operation indicates the current status of the full memory checking
- * facility.
- * 
- * \pre
- * none
- *
- * \return
- * - BOOL_TRUE if full memory checking is enabled.
- * - BOOL_FALSE if full memory checking is disabled.
- *
- * \post 
- * none
- */
-bool_t lub_heap_is_checking(void);
-
-/**
- * This operation checks the integrety of the memory in the specified
- * heap.
- * Corruption will be spotted the first time a check is performed AFTER 
- * it has occured.
- * \pre
- * - the specified heap will have been created
- *
- * \return 
- * - BOOL_TRUE if the heap is OK
- * - BOOL_FALSE if the heap is corrupted.
- *
- * \post
- * - none
- */
-extern bool_t lub_heap_check_memory(lub_heap_t * instance);
-
-/**
- * This function is invoked whenever a call to lub_heap_realloc() fails.
- * It is provided as a debugging aid; simple set a breakpoint to
- * stop execution of the program and any failures will be caught in context.
- */
-void lub_heap_stop_here(
-	/**
-         * The failure status of the the call to realloc
-         */
-			       lub_heap_status_t status,
-	/**
-         * The old value of the pointer passed in
-         */
-			       char *old_ptr,
-	/**
-         * The requested number of bytes
-         */
-			       size_t new_size);
-
-/**
- * This operation fills out a statistics structure with the details for the 
- * specified heap.
- *
- * \pre
- * - none
- *
- * \post
- * - the results filled out are a snapshot of the statistics as the time
- *   of the call.
- */
-void lub_heap__get_stats(
-	/**
-         * The instance on which to operate
-         */
-				lub_heap_t * instance,
-	/**
-         * A client provided structure to fill out with the heap details
-         */
-				lub_heap_stats_t * stats);
-
-/**
- * This operation dumps the salient details of the specified heap to stdout
- */
-void lub_heap_show(
-	/**
-         * The instance on which to operate
-         */
-			  lub_heap_t * instance,
-	/**
-         * Whether to be verbose or not
-         */
-			  bool_t verbose);
-/**
- * This method provides the size, in bytes, of the largest allocation
- * which can be performed.
- * \pre
- * - The heap needs to have been created with an initial memory segment.
- *
- * \return 
- * - size of largest possible allocation.
- *
- * \post
- * - none
- */
-size_t lub_heap__get_max_free(
-	/**
-         * The instance on which to operate
-         */
-				     lub_heap_t * instance);
-
-extern size_t
-lub_heap__get_block_overhead(lub_heap_t * instance, const void *ptr);
-
-extern size_t lub_heap__get_block_size(lub_heap_t * instance, const void *ptr);
-/**
- * This function scans memory to identify memory leaks
- * 
- * NB. if tainting is switched off then this function may miss some leaks as
- * references may remain in freed memory.
- *
- */
-extern void lub_heap_leak_scan(void);
-/**
- * This function dumps all the context details for the heap
- * to stdout.
- * 'how' is one of the following values:
- * 0 - show only leaks
- * 1 - show partial leaks (no references to the start of the block)
- * 2 - show all allocations (VERY VERBOSE)
- *
- * NB. if tainting is switched off then this function will not perform
- * any memory scanning and will simply show all the allocated blocks.
- *
- * \return 
- * - a boolean indicating whether any leaks were displayed or not.
- */
-extern bool_t lub_heap_leak_report(
-	/**
-         * how to display the details
-         */
-					  lub_heap_show_e how,
-	/**
-         * an optional substring to use to filter contexts.
-         * Only contexts which contain the substring will be displayed
-         */
-					  const char *substring);
-
-void lub_heap__set_framecount(
-	/**
-         * The new framecount to use
-         */
-				     unsigned framecount);
-
-unsigned lub_heap__get_framecount(void);
-
-extern bool_t lub_heap_validate_pointer(lub_heap_t * instance, char *ptr);
-/**
- * This 'magic' pointer is returned when a client requests zero bytes
- * The client can see that the allocation has succeeded, but cannot use 
- * the "memory" returned. This pointer may be passed transparently back
- * to lub_heap_realloc() without impact.
- */
-#define LUB_HEAP_ZERO_ALLOC ((void*)-1)
-
-/**
- * This operation is used to initialise the heap management 
- * subsystem
- * \pre
- * - none
- *
- * \post
- * - The POSIX specific subsystem will be initialised to load
- *   the debugging symbols for the current executable. This
- *   enables the backtraces used for leak detection to show
- *   the full detail in the stack traces.
- * - If the system is configured at build time without GPL
- *   support (disabled by default) then only the address of
- *   each stack frame will be shown.
- */
-extern void lub_heap_init(
-	/** 
-         * The full pathname of the current executable
-         * This is typically obtained from argv[0] in main()
-         */
-				 const char *program_name);
-
-#if defined(__CYGWIN__)
-
-/**
- * CYGWIN requires a specialised initialisation to account for 
- * argv[0] not containing the trailing ".exe" of the executable.
- */
-extern void cygwin_lub_heap_init(const char *file_name);
-
-#define lub_heap_init(arg0) cygwin_lub_heap_init(arg0)
-
-#endif				/* __CYGWIN__ */
-/**
-  * This operation adds a cache to the current heap, which speeds up
-  * the allocation and releasing of smaller block sizes.
-  *
-  * \pre
-  * - The heap must have been initialised
-  * - This call must not have been made on this heap before
-  *
-  * \return
-  * - LUB_HEAP_OK if the cache was successfully set up.
-  * - LUB_HEAP_FAILED if the cache was not set up for whatever reason
-  *
-  * \post
-  * - memory allocations for smaller block sizes may come from the
-  *   cache.
-  */
-lub_heap_status_t lub_heap_cache_init(
-	/**
-         * The instance on which to operate
-         */
-					     lub_heap_t * instance,
-	/**
-         * The maximum block size for the cache
-         */
-					     lub_heap_align_t max_block_size,
-	/**
-         * The number of maximum sized blocks to make available.
-         */
-					     size_t num_max_blocks);
-/**
-  * This operation signals the start of a section of code which 
-  * should not have any of it's heap usage monitored by the leak
-  * detection code.
-  *
-  * \pre
-  * - The heap must have been initialised
-  *
-  * \return
-  * - none
-  *
-  * \post
-  * - If leak detection is enabled then no subsequent allocations will
-  *   be monitored until the lub_heap_leak_restore_detection() is called.
-  */
-void lub_heap_leak_suppress_detection(
-	/**
-         * The instance on which to operate
-         */
-					     lub_heap_t * instance);
-/**
-  * This operation signals the end of a section of code which 
-  * should not have any of it's heap usage monitored by the leak
-  * detection code.
-  *
-  * NB. you may nest the usage of lub_heap_leak_suppress_detection() and
-  * lub_heap_leak_restore_detection() in which case only when the outermost
-  * section has been terminated will monitoring commence again.
-  *
-  * \pre
-  * - The heap must have been initialised
-  * - lub_heap_start_unmonitored_section() must have been called.
-  *
-  * \return
-  * - none
-  *
-  * \post
-  * - If leak detection is enabled then no subsequent allocations will
-  *   be monitored until the lub_heap_end_unmonitored_section() is called.
-  */
-void lub_heap_leak_restore_detection(
-	/**
-         * The instance on which to operate
-         */
-					    lub_heap_t * instance);
-
-/**
-  * This operation returns the overhead, in bytes, which is required
-  * to implement a heap instance. This provide clients the means of 
-  * calculating how much memory they need to assign for a heap instance
-  * to manage.
-  *
-  * \pre
-  * - none
-  *
-  * \return
-  * - size in bytes of the overhead required by a lub_heap instance.
-  *
-  * \post
-  * - none
-  */
-size_t lub_heap_overhead_size(
-	/**
-         * The maximum block size for the cache
-         */
-				     lub_heap_align_t max_block_size,
-	/**
-         * The number of maximum sized blocks to make available.
-         */
-				     size_t num_max_blocks);
-
-_END_C_DECL
-#endif				/* _lub_heap_h */
-/** @} */

+ 0 - 402
lub/heap/cache.c

@@ -1,402 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include "cache.h"
-
-/*--------------------------------------------------------- */
-size_t lub_heap_cache__get_max_free(lub_heap_cache_t * this)
-{
-	size_t size = 0;
-	/* get the size from the cache */
-	lub_heap_cache_bucket_t **ptr;
-
-	for (ptr = this->m_bucket_start; ptr < this->m_bucket_end; ++ptr) {
-		lub_blockpool_stats_t stats;
-		lub_blockpool__get_stats(&(*ptr)->m_blockpool, &stats);
-		if (stats.free_blocks
-		    && ((stats.block_size - sizeof(lub_heap_cache_bucket_t *)) >
-			size)) {
-			size =
-			    stats.block_size -
-			    sizeof(lub_heap_cache_bucket_t *);
-		}
-	}
-	return size;
-}
-
-/*--------------------------------------------------------- */
-static lub_heap_cache_bucket_t
-    *_lub_heap_cache_find_bucket_from_size(lub_heap_cache_t * this, size_t size)
-{
-	lub_heap_cache_bucket_t **ptr = this->m_bucket_start;
-	/* leave space to put the bucket reference into place */
-	size += sizeof(lub_heap_cache_bucket_t *);
-	/* place powers of two into the correct bucket */
-	--size;
-	/* ignore sizes of 1,2 and 4 bytes */
-	size >>= 3;
-	for (; (ptr < this->m_bucket_end) && size; ++ptr) {
-		size >>= 1;
-	}
-	return (ptr == this->m_bucket_end) ? 0 : *ptr;
-}
-
-/*--------------------------------------------------------- */
-static size_t lub_heap_cache_num_buckets(lub_heap_align_t max_block_size)
-{
-	unsigned num_buckets = 0;
-
-	/* count the number of buckets to be created */
-	max_block_size >>= 3;	/* ignore buckets of size 1,2 and 4 bytes */
-	while (max_block_size) {
-		++num_buckets;
-		max_block_size >>= 1;
-	}
-	return num_buckets;
-}
-
-/*--------------------------------------------------------- */
-size_t
-lub_heap_cache_overhead_size(lub_heap_align_t max_block_size,
-			     size_t num_max_blocks)
-{
-	size_t overhead = 0;
-	if (num_max_blocks && max_block_size) {
-		/* 
-		 * account for the cache overheads
-		 */
-		size_t num_buckets = lub_heap_cache_num_buckets(max_block_size);
-
-		/* cache control block */
-		overhead += sizeof(lub_heap_cache_t);
-
-		/* array of bucket pointers (-1 because one is contained in control block) */
-		overhead +=
-		    sizeof(lub_heap_cache_bucket_t *) * (num_buckets - 1);
-
-		/* fast size lookup array */
-		overhead += sizeof(lub_heap_cache_bucket_t *) * max_block_size;
-
-		/* buckets themselves */
-		overhead +=
-		    num_buckets * offsetof(lub_heap_cache_bucket_t,
-					   m_memory_start);
-	}
-	return overhead;
-}
-
-/*--------------------------------------------------------- */
-size_t
-lub_heap_overhead_size(lub_heap_align_t max_block_size, size_t num_max_blocks)
-{
-	/* heap control block */
-	size_t overhead = sizeof(lub_heap_t);
-
-	/* need at least one free blocks worth */
-	overhead += sizeof(lub_heap_free_block_t);
-
-	if (max_block_size && num_max_blocks) {
-		size_t num_buckets = lub_heap_cache_num_buckets(max_block_size);
-		size_t bucket_size = max_block_size * num_max_blocks;
-
-		/* now add any cache overhead contribution */
-		overhead +=
-		    lub_heap_cache_overhead_size(max_block_size,
-						 num_max_blocks);
-
-		/* add the bucket contents */
-		overhead += (num_buckets * bucket_size);
-	}
-	return overhead;
-}
-
-/*--------------------------------------------------------- */
-lub_heap_status_t
-lub_heap_cache_init(lub_heap_t * this,
-		    lub_heap_align_t max_block_size, size_t num_max_blocks)
-{
-	lub_heap_status_t status = LUB_HEAP_FAILED;
-	do {
-		size_t bucket_size = (max_block_size * num_max_blocks);
-		unsigned num_buckets =
-		    lub_heap_cache_num_buckets(max_block_size);
-		size_t block_size = 8;
-		lub_heap_cache_t *cache;
-		lub_heap_cache_bucket_t **ptr;
-		int i;
-		/* cannot call this multiple times */
-		if (this->cache)
-			break;
-
-		/* allocate a cache control block */
-		cache = this->cache = lub_heap_static_alloc(this,
-							    sizeof
-							    (lub_heap_cache_t) +
-							    sizeof
-							    (lub_heap_cache_bucket_t
-							     *) * (num_buckets -
-								   1));
-		if (!cache)
-			break;
-
-		cache->m_max_block_size = max_block_size;
-		cache->m_num_max_blocks = num_max_blocks;
-		cache->m_num_buckets = num_buckets;
-		cache->m_bucket_size = bucket_size;
-		cache->m_misses = 0;
-		cache->m_bucket_end = &cache->m_bucket_start[num_buckets];
-
-		/* allocate each bucket for the cache */
-		for (ptr = cache->m_bucket_start;
-		     ptr < cache->m_bucket_end; ++ptr) {
-			*ptr = lub_heap_static_alloc(this,
-						     bucket_size +
-						     offsetof
-						     (lub_heap_cache_bucket_t,
-						      m_memory_start));
-			if (!*ptr)
-				break;
-			/* set up each bucket */
-			lub_heap_cache_bucket_init(*ptr,
-						   cache,
-						   block_size, bucket_size);
-			block_size <<= 1;
-		}
-		if (ptr != cache->m_bucket_end)
-			break;
-
-		/* now create a fast lookup for resolving size to bucket */
-		cache->m_bucket_lookup =
-		    lub_heap_static_alloc(this,
-					  sizeof(lub_heap_cache_bucket_t *) *
-					  max_block_size);
-		if (!cache->m_bucket_lookup)
-			break;
-
-		for (i = 0; i < cache->m_max_block_size; ++i) {
-			cache->m_bucket_lookup[i] =
-			    _lub_heap_cache_find_bucket_from_size(cache, i + 1);
-		}
-		status = LUB_HEAP_OK;
-	} while (0);
-
-	return status;
-}
-
-/*--------------------------------------------------------- */
-lub_heap_cache_bucket_t
-    *lub_heap_cache_find_bucket_from_address(lub_heap_cache_t * this,
-					     const void *address)
-{
-	lub_heap_cache_bucket_t **bucket = (void *)address;
-
-	/* get the bucket reference */
-	--bucket;
-
-	if ((*bucket > this->m_bucket_start[0])
-	    || (*bucket < this->m_bucket_end[-1])) {
-		bucket = 0;
-	}
-	return bucket ? *bucket : 0;
-}
-
-/*--------------------------------------------------------- */
-lub_heap_cache_bucket_t *lub_heap_cache_find_bucket_from_size(lub_heap_cache_t *
-							      this, size_t size)
-{
-	lub_heap_cache_bucket_t *bucket = 0;
-
-	/* simply get the result from the fast lookup table */
-	if (size > 0) {
-		if (size <= this->m_max_block_size) {
-			bucket = this->m_bucket_lookup[size - 1];
-		} else {
-			++this->m_misses;
-		}
-	}
-	return bucket;
-}
-
-/*--------------------------------------------------------- */
-lub_heap_status_t
-lub_heap_cache_realloc(lub_heap_t * this, char **ptr, size_t size)
-{
-	lub_heap_status_t status = LUB_HEAP_FAILED;
-	lub_heap_cache_bucket_t *old_bucket = 0;
-	lub_heap_cache_bucket_t *new_bucket =
-	    size ? lub_heap_cache_find_bucket_from_size(this->cache, size) : 0;
-	char *new_ptr = 0;
-
-	do {
-		char *old_ptr = *ptr;
-		if (old_ptr) {
-			old_bucket =
-			    lub_heap_cache_find_bucket_from_address(this->cache,
-								    old_ptr);
-		} else if (size == 0) {
-			/* nothing to do */
-			status = LUB_HEAP_OK;
-			break;
-		}
-		if (old_bucket) {
-	    /********************************
-             * old from CACHE, new from CACHE
-             ******************************** */
-			if (new_bucket) {
-				if (old_bucket == new_bucket) {
-					/* keep the existing cache block which is big enough */
-					new_ptr = old_ptr;
-					status = LUB_HEAP_OK;
-					break;
-				}
-				/* try and get memory from the cache */
-				new_ptr =
-				    lub_heap_cache_bucket_alloc(new_bucket);
-				if (new_ptr) {
-					if (old_ptr) {
-						/* copy the old details across */
-						memcpy(new_ptr, old_ptr, size);
-
-						/* release the old cache block */
-						status =
-						    lub_heap_cache_bucket_free
-						    (old_bucket, old_ptr);
-						if (LUB_HEAP_OK != status) {
-							break;
-						}
-					}
-					/* all done */
-					status = LUB_HEAP_OK;
-					break;
-				}
-			}
-	    /********************************
-             * old from CACHE, new from HEAP
-             ******************************** */
-			if (size) {
-				/* get new memory from the dynamic heap */
-				status =
-				    lub_heap_raw_realloc(this, &new_ptr, size,
-							 LUB_HEAP_ALIGN_NATIVE);
-				if (LUB_HEAP_OK != status) {
-					break;
-				}
-				/* copy the old details across */
-				memcpy(new_ptr, old_ptr, size);
-			}
-			/* release the old cache block */
-			status =
-			    lub_heap_cache_bucket_free(old_bucket, old_ptr);
-		} else {
-	    /********************************
-             * old from HEAP, new from CACHE
-             ******************************** */
-			if (size) {
-				if (new_bucket) {
-					/* try and get memory from the cache */
-					new_ptr =
-					    lub_heap_cache_bucket_alloc
-					    (new_bucket);
-					if (new_ptr) {
-						if (old_ptr) {
-							/* copy the old details across */
-							memcpy(new_ptr, old_ptr,
-							       size);
-							size = 0;
-						} else {
-							/* all done */
-							status = LUB_HEAP_OK;
-							break;
-						}
-					}
-				}
-			} else if (!old_ptr) {
-				/* nothing to do */
-				status = LUB_HEAP_OK;
-				break;
-			}
-	    /********************************
-             * old from HEAP, new from HEAP
-             ******************************** */
-			/* release old memory and potentially get new memory */
-			status =
-			    lub_heap_raw_realloc(this, &old_ptr, size,
-						 LUB_HEAP_ALIGN_NATIVE);
-			if (LUB_HEAP_OK != status) {
-				break;
-			} else if (size) {
-				new_ptr = old_ptr;
-			}
-		}
-	} while (0);
-
-	if (LUB_HEAP_OK == status) {
-		/* set up the new pointer value */
-		*ptr = new_ptr;
-	}
-	return status;
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_cache_show(lub_heap_cache_t * this)
-{
-	lub_heap_cache_bucket_t **ptr;
-
-	printf
-	    ("       size num blocks    current  high-tide cumulative     misses\n");
-	printf
-	    (" ---------- ---------- ---------- ---------- ---------- ----------\n");
-	for (ptr = this->m_bucket_start; ptr < this->m_bucket_end; ++ptr) {
-		lub_blockpool_t *blockpool = &(*ptr)->m_blockpool;
-		lub_blockpool_stats_t stats;
-
-		lub_blockpool__get_stats(blockpool, &stats);
-
-		printf(" %10" SIZE_FMT " %10" SIZE_FMT " %10" SIZE_FMT " %10"
-		       SIZE_FMT " %10" SIZE_FMT " %10" SIZE_FMT "\n",
-		       stats.block_size, stats.num_blocks, stats.alloc_blocks,
-		       stats.alloc_hightide_blocks, stats.alloc_total_blocks,
-		       stats.alloc_failures);
-	}
-
-	printf(" %10u %10s %10s %10s %10s %10" SIZE_FMT "\n",
-	       this->m_max_block_size, "-", "-", "-", "-", this->m_misses);
-}
-
-/*--------------------------------------------------------- */
-void
-lub_heap_cache__get_stats(lub_heap_cache_t * this, lub_heap_stats_t * stats)
-{
-	lub_heap_cache_bucket_t **ptr;
-
-	memset(stats, 0, sizeof(lub_heap_stats_t));
-	stats->free_overhead =
-	    lub_heap_cache_overhead_size(this->m_max_block_size,
-					 this->m_num_max_blocks);
-
-	for (ptr = this->m_bucket_start; ptr < this->m_bucket_end; ++ptr) {
-		lub_blockpool_t *blockpool = &(*ptr)->m_blockpool;
-		lub_blockpool_stats_t bucket_stats;
-		size_t block_size;
-		size_t block_overhead = sizeof(lub_heap_cache_bucket_t *);	/* used for fast lookup from address */
-
-		lub_blockpool__get_stats(blockpool, &bucket_stats);
-		block_size = (bucket_stats.block_size - block_overhead);
-
-		stats->free_blocks += bucket_stats.free_blocks;
-		stats->free_bytes += block_size * bucket_stats.free_blocks;
-		stats->free_overhead +=
-		    block_overhead * bucket_stats.free_blocks;
-
-		stats->alloc_blocks += bucket_stats.alloc_blocks;
-		stats->alloc_bytes += block_size * bucket_stats.alloc_blocks;
-		stats->alloc_overhead +=
-		    block_overhead * bucket_stats.alloc_blocks;
-
-		stats->alloc_total_blocks += bucket_stats.alloc_total_blocks;
-		stats->alloc_total_bytes +=
-		    block_size * bucket_stats.alloc_total_blocks;
-	}
-
-}
-
-/*--------------------------------------------------------- */

+ 0 - 53
lub/heap/cache.h

@@ -1,53 +0,0 @@
-#include "lub/blockpool.h"
-#include "private.h"
-
-typedef struct _lub_heap_cache_bucket lub_heap_cache_bucket_t;
-/*-------------------------------------
- * lub_heap_cache_t class
- *------------------------------------- */
-struct _lub_heap_cache {
-	lub_heap_align_t m_max_block_size;
-	unsigned m_num_max_blocks;
-	unsigned m_num_buckets;
-	size_t m_bucket_size;
-	size_t m_misses;
-	lub_heap_cache_bucket_t **m_bucket_lookup;
-	lub_heap_cache_bucket_t **m_bucket_end;
-	lub_heap_cache_bucket_t *m_bucket_start[1];	/* must be last */
-};
-
-lub_heap_cache_bucket_t
-    *lub_heap_cache_find_bucket_from_address(lub_heap_cache_t * instance,
-					     const void *address);
-lub_heap_cache_bucket_t *lub_heap_cache_find_bucket_from_size(lub_heap_cache_t *
-							      instance,
-							      size_t size);
-void lub_heap_cache__get_stats(lub_heap_cache_t * this,
-			       lub_heap_stats_t * stats);
-
-/*-------------------------------------
- * lub_heap_cache_bucket_t class
- *------------------------------------- */
-struct _lub_heap_cache_bucket {
-	lub_blockpool_t m_blockpool;
-	lub_heap_cache_t *m_cache;
-	char *m_memory_end;
-	char m_memory_start[1];	/* must be last */
-};
-
-void
-lub_heap_cache_bucket_init(lub_heap_cache_bucket_t * instance,
-			   lub_heap_cache_t * cache,
-			   size_t block_size, size_t bucket_size);
-void *lub_heap_cache_bucket_alloc(lub_heap_cache_bucket_t * instance);
-lub_heap_status_t
-lub_heap_cache_bucket_free(lub_heap_cache_bucket_t * instance, void *ptr);
-size_t lub_heap_cache__get_max_free(lub_heap_cache_t * this);
-
-lub_heap_cache_bucket_t
-    *lub_heap_cache_find_bucket_from_address(lub_heap_cache_t * this,
-					     const void *address);
-size_t lub_heap_cache_bucket__get_block_overhead(lub_heap_cache_bucket_t * this,
-						 const char *block);
-size_t lub_heap_cache_bucket__get_block_size(lub_heap_cache_bucket_t * this,
-					     const char *block);

+ 0 - 77
lub/heap/cache_bucket.c

@@ -1,77 +0,0 @@
-#include "cache.h"
-
-/*--------------------------------------------------------- */
-size_t
-lub_heap_cache_bucket__get_block_overhead(lub_heap_cache_bucket_t * this,
-					  const char *ptr)
-{
-	return sizeof(lub_heap_cache_bucket_t *);
-}
-
-/*--------------------------------------------------------- */
-size_t
-lub_heap_cache_bucket__get_block_size(lub_heap_cache_bucket_t * this,
-				      const char *ptr)
-{
-	size_t size = 0;
-
-	/* get the size from the cache */
-	lub_blockpool_stats_t stats;
-	lub_blockpool__get_stats(&this->m_blockpool, &stats);
-	size = stats.block_size - sizeof(lub_heap_cache_bucket_t *);
-
-	return size;
-}
-
-/*--------------------------------------------------------- */
-void
-lub_heap_cache_bucket_init(lub_heap_cache_bucket_t * this,
-			   lub_heap_cache_t * cache,
-			   size_t block_size, size_t bucket_size)
-{
-	/* initialise the blockpool */
-	size_t num_blocks = bucket_size / block_size;
-
-	lub_blockpool_init(&this->m_blockpool,
-			   this->m_memory_start, block_size, num_blocks);
-	this->m_memory_end = this->m_memory_start + bucket_size;
-	this->m_cache = cache;
-}
-
-/*--------------------------------------------------------- */
-void *lub_heap_cache_bucket_alloc(lub_heap_cache_bucket_t * this)
-{
-	void *ptr = 0;
-	lub_heap_cache_bucket_t **bucket_ptr =
-	    lub_blockpool_alloc(&this->m_blockpool);
-	if (bucket_ptr) {
-		*bucket_ptr = this;
-		ptr = ++bucket_ptr;
-		/* make sure that released memory is tainted */
-		lub_heap_taint_memory(ptr,
-				      LUB_HEAP_TAINT_ALLOC,
-				      this->m_blockpool.m_block_size -
-				      sizeof(lub_heap_cache_bucket_t *));
-	}
-	return ptr;
-}
-
-/*--------------------------------------------------------- */
-lub_heap_status_t
-lub_heap_cache_bucket_free(lub_heap_cache_bucket_t * this, void *ptr)
-{
-	lub_heap_status_t status = LUB_HEAP_CORRUPTED;
-	lub_heap_cache_bucket_t **bucket_ptr = ptr;
-	--bucket_ptr;
-	if (*bucket_ptr == this) {
-		lub_blockpool_free(&this->m_blockpool, bucket_ptr);
-		/* make sure that released memory is tainted */
-		lub_heap_taint_memory((char *)bucket_ptr,
-				      LUB_HEAP_TAINT_FREE,
-				      this->m_blockpool.m_block_size);
-		status = LUB_HEAP_OK;
-	}
-	return status;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 754
lub/heap/context.c

@@ -1,754 +0,0 @@
-#include <string.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-
-#include "private.h"
-#include "context.h"
-#include "node.h"
-
-unsigned long lub_heap_frame_count;
-
-#define CONTEXT_CHUNK_SIZE 100	/* number of contexts per chunk */
-#define CONTEXT_MAX_CHUNKS 100	/* allow upto 10000 contexts */
-
-/*--------------------------------------------------------- 
- * PRIVATE META FUNCTIONS
- *--------------------------------------------------------- */
-void lub_heap_context_meta_init(void)
-{
-	static bool_t initialised = BOOL_FALSE;
-	if (BOOL_FALSE == initialised) {
-		lub_heap_leak_t *leak = lub_heap_leak_instance();
-		initialised = BOOL_TRUE;
-
-		/* initialise the context tree */
-		lub_bintree_init(&leak->m_context_tree,
-				 offsetof(lub_heap_context_t, bt_node),
-				 lub_heap_context_compare,
-				 lub_heap_context_getkey);
-		lub_heap_leak_release(leak);
-	}
-}
-
-/*--------------------------------------------------------- */
-int lub_heap_context_compare(const void *clientnode, const void *clientkey)
-{
-	int i, delta = 0;
-	const lub_heap_context_t *node = clientnode;
-	const lub_heap_context_key_t *key = clientkey;
-	function_t *const *node_fn = node->key.backtrace;
-	function_t *const *key_fn = key->backtrace;
-
-	for (i = lub_heap_frame_count; i; --i, ++node_fn, ++key_fn) {
-		delta = ((unsigned long)*node_fn - (unsigned long)*key_fn);
-		if (0 != delta) {
-			break;
-		}
-	}
-	return delta;
-}
-
-/*--------------------------------------------------------- */
-/* we simply use the embedded key as the index */
-void lub_heap_context_getkey(const void *clientnode, lub_bintree_key_t * key)
-{
-	const lub_heap_context_t *context = clientnode;
-	memcpy(key, &context->key, sizeof(lub_heap_context_key_t));
-}
-
-/*--------------------------------------------------------- */
-static bool_t
-lub_heap_foreach_context(bool_t(*fn) (lub_heap_context_t *, void *), void *arg)
-{
-	bool_t result = BOOL_FALSE;
-	lub_heap_context_t *context;
-	lub_bintree_iterator_t iter;
-
-	lub_heap_context_meta_init();
-
-	{
-		lub_heap_leak_t *leak = lub_heap_leak_instance();
-		for (context = lub_bintree_findfirst(&leak->m_context_tree),
-		     context ? lub_bintree_iterator_init(&iter,
-							 &leak->m_context_tree,
-							 context) : (void)0;
-		     context; context = lub_bintree_iterator_next(&iter)) {
-			lub_heap_leak_release(leak);
-			/* invoke the specified method on this context */
-			result = fn(context, arg);
-			leak = lub_heap_leak_instance();
-		}
-		lub_heap_leak_release(leak);
-	}
-	return result;
-}
-
-/*--------------------------------------------------------- */
-static void lub_heap_show_summary(void)
-{
-	lub_heap_leak_t *leak = lub_heap_leak_instance();
-	size_t ok_allocs = leak->m_stats.allocs;
-	size_t ok_bytes = leak->m_stats.alloc_bytes;
-	size_t ok_overhead = leak->m_stats.alloc_overhead;
-
-	ok_allocs -= leak->m_stats.partials;
-	ok_allocs -= leak->m_stats.leaks;
-
-	ok_overhead -= leak->m_stats.partial_overhead;
-	ok_overhead -= leak->m_stats.leaked_overhead;
-
-	printf("\n"
-	       "          +----------+----------+----------+----------+\n");
-	printf("  TOTALS  |    blocks|     bytes|   average|  overhead|\n");
-	printf("+---------+----------+----------+----------+----------+\n");
-	printf("|contexts |%10" SIZE_FMT "|%10" SIZE_FMT "|%10" SIZE_FMT
-	       "|%10s|\n", leak->m_stats.contexts,
-	       leak->m_stats.contexts * sizeof(lub_heap_context_t),
-	       leak->m_stats.contexts ? sizeof(lub_heap_context_t) : 0, "");
-	printf("|allocs   |%10" SIZE_FMT "|%10" SIZE_FMT "|%10" SIZE_FMT "|%10"
-	       SIZE_FMT "|\n", ok_allocs, ok_bytes,
-	       ok_allocs ? (ok_bytes / ok_allocs) : 0, ok_overhead);
-	if (leak->m_stats.partials) {
-		printf("|partials |%10" SIZE_FMT "|%10" SIZE_FMT "|%10" SIZE_FMT
-		       "|%10" SIZE_FMT "|\n", leak->m_stats.partials,
-		       leak->m_stats.partial_bytes,
-		       leak->m_stats.partials ? (leak->m_stats.partial_bytes /
-						 leak->m_stats.partials) : 0,
-		       leak->m_stats.partial_overhead);
-	}
-	if (leak->m_stats.leaks) {
-		printf("|leaks    |%10" SIZE_FMT "|%10" SIZE_FMT "|%10" SIZE_FMT
-		       "|%10" SIZE_FMT "|\n", leak->m_stats.leaks,
-		       leak->m_stats.leaked_bytes,
-		       leak->m_stats.leaks ? (leak->m_stats.leaked_bytes /
-					      leak->m_stats.leaks) : 0,
-		       leak->m_stats.leaked_overhead);
-	}
-	printf("+---------+----------+----------+----------+----------+\n");
-	lub_heap_leak_release(leak);
-}
-
-/*--------------------------------------------------------- */
-
-/*--------------------------------------------------------- 
- * PRIVATE METHODS
- *--------------------------------------------------------- */
-static void
-lub_heap_context_foreach_node(lub_heap_context_t * this,
-			      void (*fn) (lub_heap_node_t *))
-{
-	lub_heap_node_t *node;
-
-	for (node = this->first_node;
-	     node; node = lub_heap_node__get_next(node)) {
-		/* invoke the specified method on this node */
-		fn(node);
-	}
-}
-
-/*--------------------------------------------------------- */
-
-/*--------------------------------------------------------- 
- * PUBLIC METHODS
- *--------------------------------------------------------- */
-void
-lub_heap_context_init(lub_heap_context_t * this,
-		      lub_heap_t * heap, const stackframe_t * stack)
-{
-	lub_heap_context_meta_init();
-
-	this->heap = heap;
-	this->allocs = 0;
-	this->alloc_bytes = 0;
-	this->alloc_overhead = 0;
-	this->leaks = 0;
-	this->leaked_bytes = 0;
-	this->leaked_overhead = 0;
-	this->partials = 0;
-	this->partial_bytes = 0;
-	this->partial_overhead = 0;
-	this->first_node = NULL;
-
-	/* set the current backtrace for the context */
-	this->key = *stack;
-
-	/* intialise this context's binary tree node */
-	lub_bintree_node_init(&this->bt_node);
-
-	{
-		lub_heap_leak_t *leak = lub_heap_leak_instance();
-		/* add this context to the context_tree */
-		lub_bintree_insert(&leak->m_context_tree, this);
-		lub_heap_leak_release(leak);
-	}
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_context_fini(lub_heap_context_t * this)
-{
-	lub_heap_leak_t *leak = lub_heap_leak_instance();
-	/* remove this node from the context_tree */
-	lub_bintree_remove(&leak->m_context_tree, this);
-	lub_heap_leak_release(leak);
-
-	/* cleanup the context */
-	lub_heap_context_clear(this);
-}
-
-/*--------------------------------------------------------- */
-void
-lub_heap_context_insert_node(lub_heap_context_t * this, lub_heap_node_t * node)
-{
-	/* add the node to the linked list */
-	lub_heap_node__set_next(node, this->first_node);
-	node->prev = NULL;
-	if (this->first_node) {
-		this->first_node->prev = node;
-	}
-	this->first_node = node;
-
-}
-
-/*--------------------------------------------------------- */
-void
-lub_heap_context_remove_node(lub_heap_context_t * this, lub_heap_node_t * node)
-{
-	lub_heap_node_t *next, *prev = NULL;
-
-	/* remove the node from the context list */
-	next = lub_heap_node__get_next(node);
-	prev = node->prev;
-
-	if (NULL == prev) {
-		this->first_node = next;
-	} else {
-		lub_heap_node__set_next(prev, next);
-	}
-	if (NULL != next) {
-		next->prev = prev;
-	}
-
-	/* clear the pointers */
-	lub_heap_node__set_next(node, NULL);
-	node->prev = NULL;
-
-	/* is this the last node in a context? */
-	if (0 == this->allocs) {
-		/* removing the last node deletes the context */
-		lub_heap_context_delete(this);
-	}
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_context_show_frame(lub_heap_context_t * this, int frame)
-{
-	if (frame >= 0) {
-		long address = (long)this->key.backtrace[frame];
-		if (address) {
-			lub_heap_symShow(address);
-		}
-	}
-	printf("\n");
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_node_post(lub_heap_node_t * node)
-{
-	/* assume the worst */
-	if (BOOL_TRUE == lub_heap_node__get_leaked(node)) {
-		/* this is a full leak */
-		lub_heap_node__set_partial(node, BOOL_FALSE);
-	}
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_node_prep(lub_heap_node_t * node, void *arg)
-{
-	/* assume the worst */
-	lub_heap_node__set_leaked(node, BOOL_TRUE);
-	lub_heap_node__set_partial(node, BOOL_TRUE);
-	lub_heap_node__set_scanned(node, BOOL_FALSE);
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_node_scan(lub_heap_node_t * node, void *arg)
-{
-	/* only scan nodes which have references */
-	if ((BOOL_FALSE == lub_heap_node__get_leaked(node))
-	    && (BOOL_FALSE == lub_heap_node__get_scanned(node))) {
-		lub_heap_node__set_scanned(node, BOOL_TRUE);
-		lub_heap_scan_memory(lub_heap_node__get_ptr(node),
-				     lub_heap_node__get_size(node));
-	}
-}
-
-/*--------------------------------------------------------- */
-static bool_t lub_heap_context_prep(lub_heap_context_t * this, void *arg)
-{
-	/* start off by assuming the worst */
-	this->partials = this->leaks = this->allocs;
-	this->partial_bytes = this->leaked_bytes = this->alloc_bytes;
-	this->partial_overhead = this->leaked_overhead = this->alloc_overhead;
-	{
-		lub_heap_leak_t *leak = lub_heap_leak_instance();
-		/* initialised the global stats */
-		leak->m_stats.allocs += this->allocs;
-		leak->m_stats.alloc_bytes += this->alloc_bytes;
-		leak->m_stats.alloc_overhead += this->alloc_overhead;
-		lub_heap_leak_release(leak);
-	}
-	return BOOL_TRUE;
-}
-
-/*--------------------------------------------------------- */
-static bool_t lub_heap_context_post(lub_heap_context_t * this, void *arg)
-{
-	/* don't count full leaks as partials */
-	this->partials -= this->leaks;
-	this->partial_bytes -= this->leaked_bytes;
-	this->partial_overhead -= this->leaked_overhead;
-
-	/* post process the contained nodes */
-	lub_heap_context_foreach_node(this, lub_heap_node_post);
-
-	return BOOL_TRUE;
-}
-
-/*--------------------------------------------------------- */
-static void scan_segment(void *ptr, unsigned index, size_t size, void *arg)
-{
-	lub_heap_segment_t *segment = ptr;
-	const char *memory = (const char *)lub_heap_block_getfirst(segment);
-
-	/* now scan the memory in this segment */
-	printf(".");
-	lub_heap_scan_memory(memory, size);
-}
-
-/*--------------------------------------------------------- */
-/** 
- * This function scans all the nodes currently allocated in the
- * system for references to other allocated nodes.
- * First of all we mark all nodes as leaked, then scan all the nodes
- * for any references to other ones. If found those other ones 
- * are cleared from being leaked.
- * At the end of the process all nodes which are leaked then
- * update their context leak count.
- */
-void lub_heap_scan_all(void)
-{
-	lub_heap_t *heap;
-	lub_heap_leak_t *leak = lub_heap_leak_instance();
-
-	/* clear the summary stats */
-	memset(&leak->m_stats, 0, sizeof(leak->m_stats));
-
-	lub_heap_leak_release(leak);
-	/* first of all prepare the contexts for scanning */
-	lub_heap_foreach_context(lub_heap_context_prep, 0);
-
-	/* then prepare all the nodes (including those who have no context) */
-	lub_heap_foreach_node(lub_heap_node_prep, 0);
-
-	printf("  Scanning memory");
-	/* clear out the stacks in the system */
-	lub_heap_clean_stacks();
-
-	/* Scan the current stack */
-	printf(".");
-	lub_heap_scan_stack();
-
-	/* Scan the BSS segment */
-	printf(".");
-	lub_heap_scan_bss();
-
-	/* Scan the DATA segment */
-	printf(".");
-	lub_heap_scan_data();
-
-	/* Scan the non-monitored blocks which are allocated in the system */
-	leak = lub_heap_leak_instance();
-	for (heap = leak->m_heap_list; heap; heap = heap->next) {
-		lub_heap_leak_release(leak);
-		lub_heap_foreach_segment(heap, scan_segment, 0);
-		leak = lub_heap_leak_instance();
-	}
-	lub_heap_leak_release(leak);
-
-	/* 
-	 * now scan the nodes NB. only referenced nodes will be scanned 
-	 * we loop until we stop scanning new nodes
-	 */
-	leak = lub_heap_leak_instance();
-	do {
-		leak->m_stats.scanned = 0;
-		/* scan each node */
-		lub_heap_leak_release(leak);
-		printf(".");
-		lub_heap_foreach_node(lub_heap_node_scan, NULL);
-		leak = lub_heap_leak_instance();
-	} while (leak->m_stats.scanned);
-
-	printf("done\n\n");
-
-	/* post process each context and contained nodes */
-	lub_heap_leak_release(leak);
-	lub_heap_foreach_context(lub_heap_context_post, 0);
-	leak = lub_heap_leak_instance();
-
-	lub_heap_leak_release(leak);
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_node_show(lub_heap_node_t * node)
-{
-	printf("%s%p[%" SIZE_FMT "] ",
-	       lub_heap_node__get_leaked(node) ? "*" :
-	       lub_heap_node__get_partial(node) ? "+" : "",
-	       lub_heap_node__get_ptr(node), lub_heap_node__get_size(node));
-}
-
-/*--------------------------------------------------------- */
-static bool_t
-lub_heap_context_match(lub_heap_context_t * this, const char *substring)
-{
-	bool_t result = BOOL_TRUE;
-	if (substring) {
-		int i;
-		long address;
-		result = BOOL_FALSE;
-		/* 
-		 * search the stacktrace for this context
-		 * to see whether it matches
-		 */
-		for (i = 0; (address = (long)this->key.backtrace[i]); ++i) {
-			if (lub_heap_symMatch(address, substring)) {
-				result = BOOL_TRUE;
-				break;
-			}
-		}
-	}
-	return result;
-}
-
-/*--------------------------------------------------------- */
-typedef struct {
-	lub_heap_show_e how;
-	const char *substring;
-} context_show_arg_t;
-/*--------------------------------------------------------- */
-bool_t lub_heap_context_show_fn(lub_heap_context_t * this, void *arg)
-{
-	bool_t result = BOOL_FALSE;
-	context_show_arg_t *show_arg = arg;
-
-	lub_heap_leak_t *leak = lub_heap_leak_instance();
-	/* add in the context details */
-	++leak->m_stats.contexts;
-	leak->m_stats.allocs += this->allocs;
-	leak->m_stats.alloc_bytes += this->alloc_bytes;
-	leak->m_stats.alloc_overhead += this->alloc_overhead;
-	leak->m_stats.partials += this->partials;
-	leak->m_stats.partial_bytes += this->partial_bytes;
-	leak->m_stats.partial_overhead += this->partial_overhead;
-	leak->m_stats.leaks += this->leaks;
-	leak->m_stats.leaked_bytes += this->leaked_bytes;
-	leak->m_stats.leaked_overhead += this->leaked_overhead;
-	lub_heap_leak_release(leak);
-
-	if (lub_heap_context_match(this, show_arg->substring)) {
-		result = lub_heap_context_show(this, show_arg->how);
-	}
-	return result;
-}
-
-/*--------------------------------------------------------- */
-bool_t lub_heap_context_show(lub_heap_context_t * this, lub_heap_show_e how)
-{
-	long frame = lub_heap_frame_count - 1;
-	size_t ok_allocs = this->allocs;
-	size_t ok_bytes = this->alloc_bytes;
-	size_t ok_overhead = this->alloc_overhead;
-
-	ok_allocs -= this->partials;
-	ok_allocs -= this->leaks;
-
-	ok_bytes -= this->partial_bytes;
-	ok_bytes -= this->leaked_bytes;
-
-	ok_overhead -= this->partial_overhead;
-	ok_overhead -= this->leaked_overhead;
-
-	switch (how) {
-	case LUB_HEAP_SHOW_ALL:
-		{
-			/* show everything */
-			break;
-		}
-	case LUB_HEAP_SHOW_PARTIALS:
-		{
-			if (0 < this->partials) {
-				/* there's at least one partial in this context */
-				break;
-			}
-			/*lint -e(616) fall through */
-		}
-	case LUB_HEAP_SHOW_LEAKS:
-		{
-			if (0 < this->leaks) {
-				/* there's at least one leak in this context */
-				break;
-			}
-			/*lint -e(616) fall through */
-		}
-	default:
-		{
-			/* nothing to be shown */
-			return BOOL_FALSE;
-		}
-	}
-
-	/* find the top of the stack trace */
-	while ((frame >= 0) && (0 == this->key.backtrace[frame])) {
-		--frame;
-	}
-	printf("          +----------+----------+----------+----------+");
-	lub_heap_context_show_frame(this, frame--);
-	printf("%10p|    blocks|     bytes|   average|  overhead|",
-	       (void *)this);
-	lub_heap_context_show_frame(this, frame--);
-	printf("+---------+----------+----------+----------+----------+");
-	lub_heap_context_show_frame(this, frame--);
-
-	printf("|allocs   |%10" SIZE_FMT "|%10" SIZE_FMT "|%10" SIZE_FMT "|%10"
-	       SIZE_FMT "|", ok_allocs, ok_bytes,
-	       ok_allocs ? (ok_bytes / ok_allocs) : 0, ok_overhead);
-	lub_heap_context_show_frame(this, frame--);
-
-	if (this->partials) {
-		printf("|partials |%10" SIZE_FMT "|%10" SIZE_FMT "|%10" SIZE_FMT
-		       "|%10" SIZE_FMT "|", this->partials, this->partial_bytes,
-		       this->partials ? (this->partial_bytes /
-					 this->partials) : 0,
-		       this->partial_overhead);
-		lub_heap_context_show_frame(this, frame--);
-	}
-	if (this->leaks) {
-		printf("|leaks    |%10" SIZE_FMT "|%10" SIZE_FMT "|%10" SIZE_FMT
-		       "|%10" SIZE_FMT "|", this->leaks, this->leaked_bytes,
-		       this->leaks ? (this->leaked_bytes / this->leaks) : 0,
-		       this->leaked_overhead);
-		lub_heap_context_show_frame(this, frame--);
-	}
-
-	printf("+---------+----------+----------+----------+----------+");
-	lub_heap_context_show_frame(this, frame--);
-
-	while (frame >= 0) {
-		printf("%55s", "");
-		lub_heap_context_show_frame(this, frame--);
-	}
-
-	printf("ALLOCATED BLOCKS: ");
-	/* now iterate the allocated nodes */
-	lub_heap_context_foreach_node(this, lub_heap_node_show);
-	printf("\n\n");
-
-	return BOOL_TRUE;
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_context_clear(lub_heap_context_t * this)
-{
-	/* should only ever get cleared when all nodes have left the context */
-	assert(0 == this->first_node);
-	this->heap = 0;
-
-	/* reset the counters */
-	this->allocs = 0;
-	this->alloc_bytes = 0;
-	this->leaks = 0;
-	this->leaked_bytes = 0;
-	this->partials = 0;
-	this->partial_bytes = 0;
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_show_leak_trees(void)
-{
-	lub_heap_leak_t *leak = lub_heap_leak_instance();
-	printf("context_tree   : ");
-	lub_bintree_dump(&leak->m_context_tree);
-	printf("\n");
-	printf("node_tree      : ");
-	lub_bintree_dump(&leak->m_node_tree);
-	printf("\n");
-	printf("clear_node_tree: ");
-	lub_bintree_dump(&leak->m_clear_node_tree);
-	printf("\n");
-	lub_heap_leak_release(leak);
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_leak_scan(void)
-{
-	if (0 < lub_heap_frame_count) {
-		/* check for memory leaks */
-		if (!lub_heap_is_tainting()) {
-			printf("******************************************"
-			       "*** Memory tainting is disabled so results\n"
-			       "*** of scan may miss some real leaks!\n"
-			       "******************************************\n\n");
-		}
-		lub_heap_scan_all();
-	} else {
-		printf("Leak detection currently disabled\n\n");
-	}
-}
-
-/*--------------------------------------------------------- */
-bool_t lub_heap_leak_report(lub_heap_show_e how, const char *substring)
-{
-	bool_t result = BOOL_FALSE;
-
-	if (0 < lub_heap_frame_count) {
-		bool_t bad_arg = BOOL_FALSE;
-		lub_heap_leak_t *leak = lub_heap_leak_instance();
-		context_show_arg_t show_arg;
-		show_arg.how = how;
-		show_arg.substring = substring;
-
-		/* zero these stats which will be accumulated from the contexts */
-		leak->m_stats.contexts = 0;
-		leak->m_stats.allocs = 0;
-		leak->m_stats.alloc_bytes = 0;
-		leak->m_stats.alloc_overhead = 0;
-		leak->m_stats.partials = 0;
-		leak->m_stats.partial_bytes = 0;
-		leak->m_stats.partial_overhead = 0;
-		leak->m_stats.leaks = 0;
-		leak->m_stats.leaked_bytes = 0;
-		leak->m_stats.leaked_overhead = 0;
-		lub_heap_leak_release(leak);
-
-		switch (how) {
-		case LUB_HEAP_SHOW_LEAKS:
-		case LUB_HEAP_SHOW_PARTIALS:
-		case LUB_HEAP_SHOW_ALL:
-			{
-				result =
-				    lub_heap_foreach_context
-				    (lub_heap_context_show_fn,
-				     (void *)&show_arg);
-				break;
-			}
-		default:
-			{
-				printf
-				    ("Invalid argument: 0=leaks, 1=partials and leaks, 2=all allocations\n\n");
-				bad_arg = BOOL_TRUE;
-				break;
-			}
-		}
-		if (BOOL_FALSE == bad_arg) {
-			leak = lub_heap_leak_instance();
-			if (leak->m_stats.leaks) {
-				printf("  '*' = leaked memory\n");
-			}
-			if (leak->m_stats.partials) {
-				printf("  '+' = partially leaked memory\n");
-			}
-			lub_heap_leak_release(leak);
-			lub_heap_show_summary();
-			printf
-			    ("  %lu stack frames held for each allocation.\n\n",
-			     lub_heap_frame_count);
-		}
-	} else {
-		printf("Leak detection currently disabled\n\n");
-	}
-	return result;
-}
-
-/*--------------------------------------------------------- */
-
-/*--------------------------------------------------------- 
- * PUBLIC META FUNCTIONS
- *--------------------------------------------------------- */
-void lub_heap__set_framecount(unsigned frames)
-{
-	static bool_t clear_tainting_on_disable = BOOL_FALSE;
-	lub_heap_leak_t *leak;
-
-	if (frames == lub_heap_frame_count)
-		return;
-
-	/* iterate around clearing all the nodes in the node_tree */
-	lub_heap_foreach_node(lub_heap_node_clear, 0);
-
-	leak = lub_heap_leak_instance();
-	if (frames) {
-		static bool_t registered = BOOL_FALSE;
-		if (frames <= MAX_BACKTRACE) {
-			/* change the number of frames held */
-			lub_heap_frame_count = frames;
-		} else {
-			fprintf(stderr,
-				"--- leak-detection frame count set to a maximum of %d\n",
-				MAX_BACKTRACE);
-			lub_heap_frame_count = MAX_BACKTRACE;
-		}
-		if (!lub_heap_is_tainting()) {
-			/* we need to taint memory to ensure old pointers don't mask leaks */
-			clear_tainting_on_disable = BOOL_TRUE;
-			lub_heap_taint(BOOL_TRUE);
-		}
-		if (BOOL_FALSE == registered) {
-			registered = BOOL_TRUE;
-			/* 
-			 * set up the context pool
-			 */
-			lub_dblockpool_init(&leak->m_context_pool,
-					    sizeof(lub_heap_context_t),
-					    CONTEXT_CHUNK_SIZE,
-					    CONTEXT_MAX_CHUNKS);
-		}
-	} else {
-		/* switch off leak detection */
-		lub_heap_frame_count = 0;
-		if (clear_tainting_on_disable) {
-			lub_heap_taint(BOOL_FALSE);
-			clear_tainting_on_disable = BOOL_FALSE;
-		}
-	}
-	lub_heap_leak_release(leak);
-}
-
-/*--------------------------------------------------------- */
-unsigned lub_heap__get_framecount(void)
-{
-	return lub_heap_frame_count;
-}
-
-/*--------------------------------------------------------- */
-size_t lub_heap_context__get_instanceSize(void)
-{
-	return (sizeof(lub_heap_context_t));
-}
-
-/*--------------------------------------------------------- */
-lub_heap_context_t *lub_heap_context_find(const stackframe_t * stack)
-{
-	lub_heap_context_t *result;
-	lub_heap_leak_t *leak = lub_heap_leak_instance();
-	lub_heap_context_key_t key = *stack;
-
-	result = lub_bintree_find(&leak->m_context_tree, &key);
-
-	lub_heap_leak_release(leak);
-	return result;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 284
lub/heap/context.h

@@ -1,284 +0,0 @@
-/* 
- * context.h 
- */
-/**********************************************************
- * CONTEXT CLASS DEFINITIONS
- ********************************************************** */
-#define MAX_BACKTRACE (32)
-
-typedef struct _lub_heap_stackframe lub_heap_context_key_t;
-typedef void (function_t) (void);
-
-struct _lub_heap_stackframe {
-	function_t *backtrace[MAX_BACKTRACE];
-};
-
-typedef struct _lub_heap_leak_stats lub_heap_leak_stats_t;
-struct _lub_heap_leak_stats {
-	size_t contexts;
-	size_t allocs;
-	size_t alloc_bytes;
-	size_t alloc_overhead;
-	size_t leaks;
-	size_t leaked_bytes;
-	size_t leaked_overhead;
-	size_t partials;
-	size_t partial_bytes;
-	size_t partial_overhead;
-	size_t scanned;
-};
-
-struct _lub_heap_context {
-    /**
-     * The heap to which this context belongs
-     */
-	lub_heap_t *heap;
-    /**
-     * This is needed to maintain a tree of contexts
-     */
-	lub_bintree_node_t bt_node;
-    /**
-     * The first node in this context
-     */
-	lub_heap_node_t *first_node;
-    /**
-     * current number of allocations made from this context
-     */
-	size_t allocs;
-    /**
-     * current number of bytes allocated from this context
-     */
-	size_t alloc_bytes;
-    /**
-     * current overhead in bytes allocated from this context
-     */
-	size_t alloc_overhead;
-    /**
-     * count of leaked allocations made from this context
-     */
-	size_t leaks;
-    /**
-     * number of leaked bytes from this context
-     */
-	size_t leaked_bytes;
-    /**
-     * current overhead in bytes leaked from this context
-     */
-	size_t leaked_overhead;
-    /**
-     * count of partially leaked allocations made from this context
-     */
-	size_t partials;
-    /**
-     * number of partially leaked bytes from this context
-     */
-	size_t partial_bytes;
-    /**
-     * current overhead in bytes partially leaked from this context
-     */
-	size_t partial_overhead;
-    /**
-     * a record of the memory partition associated with this context
-     */
-	lub_heap_context_key_t key;
-};
-
-extern unsigned long lub_heap_frame_count;
-
-typedef struct _lub_heap_leak lub_heap_leak_t;
-struct _lub_heap_leak {
-	lub_bintree_t m_context_tree;
-	lub_bintree_t m_node_tree;
-	lub_bintree_t m_clear_node_tree;
-	lub_bintree_t m_segment_tree;
-	lub_heap_leak_stats_t m_stats;
-	lub_dblockpool_t m_context_pool;
-	lub_heap_t *m_heap_list;
-};
-
-extern lub_heap_leak_t *lub_heap_leak_instance(void);
-
-extern void lub_heap_leak_release(lub_heap_leak_t * instance);
-
-extern bool_t lub_heap_leak_query_node_tree(void);
-
-extern bool_t lub_heap_leak_query_clear_node_tree(void);
-/*---------------------------------------------------------
- * PUBLIC META ATTRIBUTES
- *--------------------------------------------------------- */
-/**
- * Obtains the number of bytes required to allocate a context instance.
- *
- * By default this is set to four.
- */
-size_t lub_heap_context__get_instanceSize(void);
-
-extern lub_bintree_compare_fn lub_heap_context_compare;
-extern lub_bintree_getkey_fn lub_heap_context_getkey;
-
-/*---------------------------------------------------------
- * PUBLIC METHODS
- *--------------------------------------------------------- */
-/**
- * This function finds or creates a context based on the
- * provided leak detector and stack specification.
- * 
- * A context is defined by a pre-configured number of stack frames
- * (see lub_heap_context__set_frameCount()) 
- * All memory allocations which occur with 
- * the same stack frames will be collected together in the same context.
- *
- * \return Pointer to a context object or NULL if one cannot be found or allocated.
- */
-const lub_heap_context_t *lub_heap_context_find_or_create(
-	/** 
-         * The heap in question
-         */
-								 lub_heap_t *
-								 instance,
-	/** 
-         * The memory allocation function must allocate a
-         * local variable, on it's stack, which is passed in 
-         * to this call as a means of getting access to the current
-         * thread's call stack.
-         */
-								 const
-								 stackframe_t *
-								 stack);
-/**
- * This function finds a context based on the
- * provided leak detector and stack specification.
- * 
- * A context is defined by a pre-configured number of stack frames
- * (see lub_heap_context__set_frameCount()) 
- * All memory allocations which occur with 
- * the same stack frames will be collected together in the same context.
- *
- * \return Pointer to a context object or NULL if one cannot be found.
- */
-lub_heap_context_t *lub_heap_context_find(
-	/** 
-         * The memory allocation function must allocate a
-         * local variable, on it's stack, which is passed in 
-         * to this call as a means of getting access to the current
-         * thread's call stack.
-         */
-						 const stackframe_t * stack);
-
-/*---------------------------------------------------------
- * PUBLIC METHODS
- *--------------------------------------------------------- */
-/**
- * This function initialises an instance of a context.
- */
-void lub_heap_context_init(
-	/** 
-         * Context instance on which to operate
-         */
-				  lub_heap_context_t * instance,
-	/** 
-         * heap with with to associate this context
-         */
-				  lub_heap_t * heap,
-	/**
-         * The memory allocation function must allocate a
-         * local variable, on it's stack, which is passed in 
-         * to this call as a means of getting access to the current
-         * thread's call stack.
-         */
-				  const stackframe_t * stack);
-/**
- * This function finalises an instance of a context.
- * 
- * \return the memory partition from which this context was allocated.
- */
-void lub_heap_context_fini(
-	/** 
-         * Context instance on which to operate
-         */
-				  lub_heap_context_t * instance);
-/**
- * This function deletes an instance of a context
- * 
- * \return BOOL_TRUE if deletion was sucessful
- */
-bool_t lub_heap_context_delete(
-	/** 
-         * Context instance on which to operate
-         */
-				      lub_heap_context_t * instance);
-/**
- * This function adds the specified node to the context tree.
- *
- * \return BOOL_TRUE  if the node was added to the tree,
- *          BOOL_FALSE if node was already in the tree.
- */
-bool_t lub_heap_context_add_node(
-	/** 
-         * Context instance on which to operate
-         */
-					lub_heap_context_t * instance,
-	/**
-         * The node to add to this context 
-         */
-					lub_heap_node_t * node,
-	/**
-         * The size in bytes of the allocation 
-         */
-					size_t size);
-/**
- * This function removes the specified node from the context tree.
- *
- * \return BOOL_TRUE  if the node was found and removed,
- *          BOOL_FALSE if the node was not in the tree
- */
-void lub_heap_context_remove_node(
-	/** 
-         * Context instance on which to operate
-         */
-					 lub_heap_context_t * instance,
-	/**
-         * The node to add to this context 
-         */
-					 lub_heap_node_t * node);
-/**
- * This function dumps details of the specified context to stdout
- *
- * /return
- * - BOOL_TRUE if any details were dumped.
- * - BOOL_FALSE if no details were dumped.
- */
-bool_t lub_heap_context_show(
-	/** 
-         * Context instance on which to operate
-         */
-				    lub_heap_context_t * instance,
-	/** 
-         * How to dump the information
-         */
-				    lub_heap_show_e how);
-/**
- * This function "clears" the currently allocated blocks so that lub_heap_context_dump
- * will not show them
- */
-void lub_heap_context_clear(
-	/** 
-         * Context instance on which to operate
-         */
-				   lub_heap_context_t * instance);
-/**
- * This places a node into the context's tree
- */
-void
-lub_heap_context_insert_node(lub_heap_context_t * instance,
-			     lub_heap_node_t * node);
-/*---------------------------------------------------------
- * PUBLIC ATTRIBUTES
- *--------------------------------------------------------- */
-/**
- * Identify whether this is a valid address within the heap
- */
-bool_t leaks_is_valid_heap_address(lub_heap_t * instance, const void *ptr);
-
-void lub_heap_leak_mutex_lock(void);
-void lub_heap_leak_mutex_unlock(void);

+ 0 - 19
lub/heap/heap__get_max_free.c

@@ -1,19 +0,0 @@
-#include "cache.h"
-
-/*--------------------------------------------------------- */
-size_t lub_heap__get_max_free(lub_heap_t * this)
-{
-	size_t result = 0;
-	lub_heap_free_block_t *free_block;
-
-	/* get the last block in the tree */
-	free_block = lub_bintree_findlast(&this->free_tree);
-	if (NULL != free_block) {
-		result =
-		    (free_block->tag.words << 2) -
-		    sizeof(lub_heap_alloc_block_t);
-	}
-	return result;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 54
lub/heap/heap__get_stacktrace.c

@@ -1,54 +0,0 @@
-/*
- * Generic stacktrace function
- */
-#ifdef __GNUC__
-#include <string.h>
-
-#include "private.h"
-#include "context.h"
-
-/*--------------------------------------------------------- */
-void lub_heap__get_stackframe(stackframe_t * stack, unsigned max)
-{
-#define GET_RETURN_ADDRESS(n)                                                       \
-    {                                                                               \
-        if(n < max)                                                                 \
-        {                                                                           \
-            unsigned long fn = (unsigned long)__builtin_return_address(n+2);        \
-            if(!fn || (fn > (unsigned long)lub_heap_data_end))                      \
-            {                                                                       \
-                break;                                                              \
-            }                                                                       \
-            stack->backtrace[n] = (function_t*)fn;                                  \
-        }                                                                           \
-        else                                                                        \
-        {                                                                           \
-            break;                                                                  \
-        }                                                                           \
-    }                                                                               \
-
-	memset(stack, 0, sizeof(*stack));
-	do {
-		GET_RETURN_ADDRESS(0);
-		GET_RETURN_ADDRESS(1);
-		GET_RETURN_ADDRESS(2);
-		GET_RETURN_ADDRESS(3);
-		GET_RETURN_ADDRESS(4);
-		GET_RETURN_ADDRESS(5);
-		GET_RETURN_ADDRESS(6);
-		GET_RETURN_ADDRESS(7);
-		GET_RETURN_ADDRESS(8);
-		GET_RETURN_ADDRESS(9);
-		GET_RETURN_ADDRESS(10);
-		GET_RETURN_ADDRESS(11);
-		GET_RETURN_ADDRESS(12);
-		GET_RETURN_ADDRESS(13);
-		GET_RETURN_ADDRESS(14);
-		GET_RETURN_ADDRESS(15);
-	} while (0);
-}
-
-/*--------------------------------------------------------- */
-#else				/* not __GNUC__ */
-#warning "Generic stack backtrace not implemented for non-GCC compiler..."
-#endif				/* not __GNUC__ */

+ 0 - 8
lub/heap/heap__get_stats.c

@@ -1,8 +0,0 @@
-#include "private.h"
-/*--------------------------------------------------------- */
-void lub_heap__get_stats(lub_heap_t * this, lub_heap_stats_t * stats)
-{
-	*stats = this->stats;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 126
lub/heap/heap_add_segment.c

@@ -1,126 +0,0 @@
-/*
- * heap_add_segment.c
- */
-#include <stdlib.h>
-#include <string.h>
-
-#include "private.h"
-#include "context.h"
-#include "lub/bintree.h"
-
-typedef struct {
-	const lub_heap_segment_t *segment;
-} lub_heap_segment_key_t;
-
-/*--------------------------------------------------------- */
-static int
-lub_heap_segment_compare(const void *clientnode, const void *clientkey)
-{
-	const lub_heap_segment_t *segment = clientnode;
-	const lub_heap_segment_key_t *key = clientkey;
-
-	return ((long)segment - (long)key->segment);
-}
-
-/*--------------------------------------------------------- */
-/* we simply use the segment address as the index */
-static void
-lub_heap_segment_getkey(const void *clientnode, lub_bintree_key_t * key)
-{
-	lub_heap_segment_key_t clientkey;
-	clientkey.segment = clientnode;
-	memcpy(key, &clientkey, sizeof(lub_heap_segment_key_t));
-}
-
-/*--------------------------------------------------------- */
-static void lub_heap_segment_meta_init()
-{
-	static bool_t initialised = BOOL_FALSE;
-
-	if (BOOL_FALSE == initialised) {
-		lub_heap_leak_t *leak = lub_heap_leak_instance();
-		initialised = BOOL_TRUE;
-		/* initialise the segment tree */
-		lub_bintree_init(&leak->m_segment_tree,
-				 offsetof(lub_heap_segment_t, bt_node),
-				 lub_heap_segment_compare,
-				 lub_heap_segment_getkey);
-		lub_heap_leak_release(leak);
-	}
-}
-
-/*--------------------------------------------------------- */
-const lub_heap_segment_t *lub_heap_segment_findnext(const void *address)
-{
-	lub_heap_segment_t *segment;
-	lub_heap_segment_key_t key;
-	lub_heap_leak_t *leak = lub_heap_leak_instance();
-	key.segment = address;
-
-	segment = lub_bintree_findnext(&leak->m_segment_tree, &key);
-	lub_heap_leak_release(leak);
-
-	return segment;
-}
-
-/*--------------------------------------------------------- */
-/*
- * as an optimisation this could be modified to merge 
- * adjacent segments together
- */
-void lub_heap_add_segment(lub_heap_t * this, void *start, size_t size)
-{
-	lub_heap_segment_t *segment;
-
-	/* check for simple adjacent segment as produced by sbrk() type behaviour */
-	if (this->first_segment.words) {
-		lub_heap_tag_t *tail;
-		char *ptr = (char *)&this[1];
-		ptr += (this->first_segment.words << 2);
-		if (ptr == start) {
-			/* simply extend the current first segment */
-			this->first_segment.words += (size >> 2);
-			tail = &((lub_heap_tag_t *) start)[-1];
-			tail->segment = BOOL_FALSE;	/* no longer last block in segment */
-			/* convert the new memory into a free block... */
-			lub_heap_init_free_block(this, start, size, BOOL_FALSE,
-						 BOOL_TRUE);
-			/* try and merge with the previous block */
-			lub_heap_merge_with_previous(this, start);
-
-			this->stats.segs_bytes += size;
-
-			return;
-		}
-	}
-	/* adjust the size which can be used */
-	size -= sizeof(lub_heap_segment_t);
-
-	/* set up the linked list of segments */
-	segment = start;
-
-	/* update the stats */
-	++this->stats.segs;
-	this->stats.segs_bytes += size;
-	this->stats.segs_overhead += sizeof(lub_heap_segment_t);
-
-	if (segment != &this->first_segment) {
-		/* maintain the list of segments */
-		segment->next = this->first_segment.next;
-		this->first_segment.next = segment;
-	}
-	segment->words = (size >> 2);
-
-	lub_heap_init_free_block(this, &segment[1], size, BOOL_TRUE, BOOL_TRUE);
-
-	/* add this segment to the tree */
-	lub_heap_segment_meta_init();
-	lub_bintree_node_init(&segment->bt_node);
-	{
-		lub_heap_leak_t *leak = lub_heap_leak_instance();
-		lub_bintree_insert(&leak->m_segment_tree, segment);
-		lub_heap_leak_release(leak);
-	}
-}
-
-/*--------------------------------------------------------- */

+ 0 - 133
lub/heap/heap_align_block.c

@@ -1,133 +0,0 @@
-#include <assert.h>
-#include "private.h"
-#include "context.h"
-#include "node.h"
-
-/*--------------------------------------------------------- */
-static void
-lub_heap_free_leading_memory(lub_heap_t * this,
-			     lub_heap_block_t * block, size_t size)
-{
-	lub_heap_block_t *prev_block = lub_heap_block_getprevious(block);
-	if (prev_block && prev_block->free.tag.free) {
-		/* 
-		 * add the excess bytes to a preceeding free block
-		 */
-		lub_heap_graft_to_top(this,
-				      prev_block,
-				      block,
-				      (size >> 2), BOOL_FALSE, BOOL_FALSE);
-	} else {
-		/*
-		 * convert the excess bytes into a free block
-		 */
-		lub_heap_init_free_block(this,
-					 block,
-					 size,
-					 block->alloc.tag.segment, BOOL_FALSE);
-	}
-	this->stats.alloc_bytes -= size;
-}
-
-/*--------------------------------------------------------- */
-static void
-lub_heap_free_trailing_memory(lub_heap_t * this,
-			      lub_heap_block_t * block, size_t size)
-{
-	bool_t done = BOOL_FALSE;
-	lub_heap_block_t *next_block = lub_heap_block_getnext(block);
-	lub_heap_tag_t *tail = lub_heap_block__get_tail(block);
-	char *ptr = (char *)&tail[1] - size;
-	if (next_block && next_block->free.tag.free) {
-		/* 
-		 * try and add the excess bytes to a following free block
-		 */
-		lub_heap_graft_to_bottom(this,
-					 next_block,
-					 ptr,
-					 (size >> 2), BOOL_FALSE, BOOL_FALSE);
-		done = BOOL_TRUE;
-	} else if (size >= sizeof(lub_heap_free_block_t)) {
-		/*
-		 * convert the excess bytes into a free block
-		 */
-		lub_heap_init_free_block(this,
-					 ptr, size, BOOL_FALSE, tail->segment);
-		done = BOOL_TRUE;
-	}
-
-	if (done) {
-		/* correct the word count for the block */
-		block->alloc.tag.words -= (size >> 2);
-		tail = lub_heap_block__get_tail(block);
-		tail->segment = 0;
-		tail->free = 0;
-		tail->words = block->alloc.tag.words;
-
-		this->stats.alloc_bytes -= size;
-	}
-}
-
-/*--------------------------------------------------------- */
-void
-lub_heap_align_block(lub_heap_t * this,
-		     lub_heap_align_t alignment, char **ptr, size_t * size)
-{
-	if (*ptr) {
-		lub_heap_block_t *block = lub_heap_block_from_ptr(*ptr);
-		lub_heap_block_t *new_block;
-		lub_heap_tag_t *new_tail;
-		/* find the second occurance of an alignment boundary */
-		size_t tmp = (alignment - 1);
-		char *new_ptr =
-		    (char *)(((size_t) * ptr + tmp + alignment) & ~tmp);
-		size_t leading_bytes = (new_ptr - *ptr);
-		size_t trailing_bytes;
-
-		/* check this is a allocated block */
-		assert(0 == block->alloc.tag.free);
-		/*
-		 * We MUST have left sufficient space to fit a free block and
-		 * leak dection node if necessary.
-		 */
-		assert(leading_bytes >=
-		       (sizeof(lub_heap_free_block_t) +
-			sizeof(lub_heap_node_t)));
-
-		if ((0 < lub_heap_frame_count) && (0 == this->suppress)) {
-			/* 
-			 * If leak detection is enabled then offset the pointer back by the size of 
-			 * a lub_heap_node; which will be filled out by lub_heap_post_realloc()
-			 */
-			new_ptr -= sizeof(lub_heap_node_t);
-			leading_bytes -= sizeof(lub_heap_node_t);
-		}
-		/*
-		 * Create a new header just before the new pointer
-		 */
-		new_block = lub_heap_block_from_ptr(new_ptr);
-		new_block->alloc.tag.free = 0;
-		new_block->alloc.tag.segment = 0;
-		new_block->alloc.tag.words =
-		    block->alloc.tag.words - (leading_bytes >> 2);
-
-		/* fix the size in the tail */
-		new_tail = lub_heap_block__get_tail(new_block);
-		new_tail->words = new_block->alloc.tag.words;
-
-		lub_heap_free_leading_memory(this, block, leading_bytes);
-
-		/* identify any trailing excess memory */
-		trailing_bytes =
-		    (new_block->alloc.tag.words << 2) - (*size -
-							 (alignment << 1));
-
-		if (trailing_bytes) {
-			lub_heap_free_trailing_memory(this,
-						      new_block,
-						      trailing_bytes);
-		}
-		*size = (new_block->alloc.tag.words << 2);	/* size including the lub_heap_alloc_block_t details */
-		*ptr = new_ptr;
-	}
-}

+ 0 - 10
lub/heap/heap_block__get_tail.c

@@ -1,10 +0,0 @@
-#include "private.h"
-
-/*--------------------------------------------------------- */
-lub_heap_tag_t *lub_heap_block__get_tail(lub_heap_block_t * this)
-{
-	lub_heap_tag_t *ptr = &this->alloc.tag;
-	return (ptr + this->alloc.tag.words - 1);
-}
-
-/*--------------------------------------------------------- */

+ 0 - 11
lub/heap/heap_block_check.c

@@ -1,11 +0,0 @@
-#include "private.h"
-
-/*--------------------------------------------------------- */
-bool_t lub_heap_block_check(lub_heap_block_t * this)
-{
-	lub_heap_tag_t *tail = lub_heap_block__get_tail(this);
-
-	return (tail->words == this->alloc.tag.words) ? BOOL_TRUE : BOOL_FALSE;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 9
lub/heap/heap_block_from_ptr.c

@@ -1,9 +0,0 @@
-#include "private.h"
-
-/*--------------------------------------------------------- */
-lub_heap_block_t *lub_heap_block_from_ptr(char *ptr)
-{
-	return ((lub_heap_block_t *) & ((lub_heap_tag_t *) ptr)[-1]);
-}
-
-/*--------------------------------------------------------- */

+ 0 - 9
lub/heap/heap_block_getfirst.c

@@ -1,9 +0,0 @@
-#include "private.h"
-
-/*--------------------------------------------------------- */
-lub_heap_block_t *lub_heap_block_getfirst(const lub_heap_segment_t * seg)
-{
-	return (lub_heap_block_t *) & seg[1];
-}
-
-/*--------------------------------------------------------- */

+ 0 - 17
lub/heap/heap_block_getkey.c

@@ -1,17 +0,0 @@
-#include <string.h>
-
-#include "private.h"
-
-/*--------------------------------------------------------- */
-void lub_heap_block_getkey(const void *clientnode, lub_bintree_key_t * key)
-{
-	const lub_heap_free_block_t *block = clientnode;
-	lub_heap_key_t mykey;
-
-	mykey.words = block->tag.words;
-	mykey.block = block;
-
-	memcpy(key, &mykey, sizeof(lub_heap_key_t));
-}
-
-/*--------------------------------------------------------- */

+ 0 - 17
lub/heap/heap_block_getnext.c

@@ -1,17 +0,0 @@
-#include "private.h"
-
-/*--------------------------------------------------------- */
-lub_heap_block_t *lub_heap_block_getnext(lub_heap_block_t * this)
-{
-	lub_heap_block_t *result = NULL;
-	lub_heap_tag_t *tail = lub_heap_block__get_tail(this);
-
-	/* only go forward if this is not the last block in the segment */
-	if (0 == tail->segment) {
-		/* get a pointer to the first word in the next block */
-		result = (lub_heap_block_t *) & tail[1];
-	}
-	return result;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 24
lub/heap/heap_block_getprevious.c

@@ -1,24 +0,0 @@
-#include "private.h"
-
-/*--------------------------------------------------------- */
-lub_heap_block_t *lub_heap_block_getprevious(lub_heap_block_t * this)
-{
-	lub_heap_block_t *result = NULL;
-
-	/* only go back if this is not the first block in the segment */
-	if (0 == this->alloc.tag.segment) {
-		/* get the tag from the previous block */
-		lub_heap_tag_t *tag = &(&this->alloc.tag)[-1];
-
-		/* get a pointer to the previous block 
-		 * +1 required to account for header tag
-		 */
-		tag = &tag[1 - tag->words];
-
-		/* now point to the start of the previous block */
-		result = (lub_heap_block_t *) tag;
-	}
-	return result;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 90
lub/heap/heap_check.c

@@ -1,90 +0,0 @@
-#include "private.h"
-
-/* flag to indicate whether to check memory or not */
-static bool_t checking = BOOL_FALSE;
-
-typedef struct {
-	bool_t result;
-	unsigned free_blocks;
-	lub_heap_t *heap;
-} check_arg_t;
-/*--------------------------------------------------------- */
-static void process_segment(void *s, unsigned index, size_t size, void *a)
-{
-	lub_heap_segment_t *segment = s;
-	lub_heap_block_t *block = lub_heap_block_getfirst(segment);
-	check_arg_t *arg = a;
-	/*
-	 * don't bother checking if this segment has zero blocks
-	 */
-	if (arg->heap->stats.free_blocks || arg->heap->stats.alloc_blocks) {
-		arg->result = lub_heap_block_check(block);
-		if (BOOL_TRUE == arg->result) {
-			/* check that the first block has the segment set */
-			arg->result =
-			    (block->free.tag.segment ==
-			     1) ? BOOL_TRUE : BOOL_FALSE;
-			if (block->free.tag.free) {
-				++arg->free_blocks;
-			}
-		}
-
-		/* now iterate along the block chain checking each one */
-		while ((BOOL_TRUE == arg->result)
-		       && (block = lub_heap_block_getnext(block))) {
-			/* check this block */
-			arg->result = lub_heap_block_check(block);
-			if (BOOL_TRUE == arg->result) {
-				/* ensure that all non-first blocks have the segment clear */
-				arg->result =
-				    (block->free.tag.segment ==
-				     0) ? BOOL_TRUE : BOOL_FALSE;
-				if (block->free.tag.free) {
-					++arg->free_blocks;
-				}
-			}
-		}
-	}
-}
-
-/*--------------------------------------------------------- */
-bool_t lub_heap_check(bool_t enable)
-{
-	bool_t result = checking;
-
-	checking = enable;
-
-	return result;
-}
-
-/*--------------------------------------------------------- */
-bool_t lub_heap_is_checking(void)
-{
-	return checking;
-}
-
-/*--------------------------------------------------------- */
-bool_t lub_heap_check_memory(lub_heap_t * this)
-{
-	check_arg_t arg;
-
-	arg.result = BOOL_TRUE;
-
-	if (BOOL_TRUE == checking) {
-		arg.free_blocks = 0;
-		arg.heap = this;
-		/* iterate all the segments in the system */
-		lub_heap_foreach_segment(this, process_segment, &arg);
-
-		/* now check that the stats map to the available free blocks 
-		 * checking the alloc blocks is more difficult because of the hidden
-		 * overheads when performing leak detection.
-		 */
-		if ((this->stats.free_blocks != arg.free_blocks)) {
-			arg.result = BOOL_FALSE;
-		}
-	}
-	return arg.result;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 16
lub/heap/heap_context_delete.c

@@ -1,16 +0,0 @@
-#include "private.h"
-#include "context.h"
-
-bool_t lub_heap_context_delete(lub_heap_context_t * context)
-{
-	lub_heap_leak_t *leak = lub_heap_leak_instance();
-
-	/* finalise the instance */
-	lub_heap_context_fini(context);
-
-	/* release the memory */
-	lub_dblockpool_free(&leak->m_context_pool, context);
-	lub_heap_leak_release(leak);
-
-	return BOOL_TRUE;
-}

+ 0 - 29
lub/heap/heap_context_find_or_create.c

@@ -1,29 +0,0 @@
-#include "private.h"
-#include "context.h"
-
-/*--------------------------------------------------------- */
-const lub_heap_context_t *lub_heap_context_find_or_create(lub_heap_t * this,
-							  const stackframe_t *
-							  stack)
-{
-	lub_heap_context_t *context;
-
-	/*
-	 * look to see whether there is an 
-	 * existing context for this allocation 
-	 */
-	context = lub_heap_context_find(stack);
-	if (NULL == context) {
-		lub_heap_leak_t *leak = lub_heap_leak_instance();
-		context = lub_dblockpool_alloc(&leak->m_context_pool);
-		lub_heap_leak_release(leak);
-
-		if (NULL != context) {
-			/* initialise the instance */
-			lub_heap_context_init(context, this, stack);
-		}
-	}
-	return context;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 82
lub/heap/heap_create.c

@@ -1,82 +0,0 @@
-/*
- * heap_create.c
- */
-#include "private.h"
-#include "context.h"
-
-/*--------------------------------------------------------- */
-static int lub_heap_block_compare(const void *clientnode, const void *clientkey)
-{
-	int delta;
-	const lub_heap_free_block_t *block = clientnode;
-	const lub_heap_key_t *key = clientkey;
-
-	delta = (block->tag.words - key->words);
-	if (0 == delta) {
-		/* if same size differentiate by address */
-		delta = (block - key->block);
-	}
-	return delta;
-}
-
-/*--------------------------------------------------------- */
-lub_heap_t *lub_heap_create(void *start, size_t size)
-{
-	lub_heap_t *this = NULL;
-
-	/* we must have at least 1024 bytes for a heap */
-	if (size > (sizeof(lub_heap_t) + 4)) {
-		this = start;
-		/* set up the binary tree for the free blocks */
-		lub_bintree_init(&this->free_tree,
-				 offsetof(lub_heap_free_block_t, bt_node),
-				 lub_heap_block_compare, lub_heap_block_getkey);
-
-		this->cache = 0;
-		this->suppress = 0;
-
-		/* initialise the statistics */
-		this->stats.segs = 0;
-		this->stats.segs_bytes = 0;
-		this->stats.segs_overhead = 0;
-		this->stats.free_blocks = 0;
-		this->stats.free_bytes = 0;
-		this->stats.free_overhead = 0;
-		this->stats.static_blocks = 0;
-		this->stats.static_bytes = 0;
-		this->stats.static_overhead = 0;
-		this->stats.alloc_blocks = 0;
-		this->stats.alloc_bytes = 0;
-		this->stats.alloc_overhead = 0;
-		this->stats.alloc_hightide_blocks = 0;
-		this->stats.alloc_hightide_bytes = 0;
-		this->stats.alloc_hightide_overhead = 0;
-		this->stats.free_hightide_blocks = 0;
-		this->stats.free_hightide_bytes = 0;
-		this->stats.free_hightide_overhead = 0;
-		this->stats.alloc_total_blocks = 0;
-		this->stats.alloc_total_bytes = 0;
-
-		/* initialise the first segment */
-		this->first_segment.next = NULL;
-
-		/* create the default segment */
-		lub_heap_add_segment(this,
-				     &this->first_segment,
-				     size - sizeof(lub_heap_t) +
-				     sizeof(lub_heap_segment_t));
-
-		this->stats.segs_overhead += sizeof(lub_heap_t);
-
-		/* add this heap to the linked list of heaps in the system */
-		{
-			lub_heap_leak_t *leak = lub_heap_leak_instance();
-			this->next = leak->m_heap_list;
-			leak->m_heap_list = this;
-			lub_heap_leak_release(leak);
-		}
-	}
-	return this;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 55
lub/heap/heap_destroy.c

@@ -1,55 +0,0 @@
-/*
- * heap_destroy.c
- */
-#include "private.h"
-#include "node.h"
-#include "context.h"
-
-/*--------------------------------------------------------- */
-static void
-_lub_heap_segment_remove(void *ptr, unsigned index, size_t size, void *arg)
-{
-	lub_heap_segment_t *segment = ptr;
-	lub_heap_leak_t *leak = lub_heap_leak_instance();
-	/* remove segment from the leak tree */
-	lub_bintree_remove(&leak->m_segment_tree, segment);
-	lub_heap_leak_release(leak);
-}
-
-/*--------------------------------------------------------- */
-static void _lub_heap_node_remove(lub_heap_node_t * node, void *arg)
-{
-	lub_heap_t *this = arg;
-	lub_heap_context_t *context = lub_heap_node__get_context(node);
-	lub_heap_leak_t *leak = lub_heap_leak_instance();
-	if (context && (context->heap == this)) {
-		--leak->m_stats.allocs;
-		leak->m_stats.alloc_bytes -= lub_heap_node__get_size(node);
-		/* remove this node from the leak tree */
-		lub_heap_node_fini(node);
-	}
-	lub_heap_leak_release(leak);
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_destroy(lub_heap_t * this)
-{
-	lub_heap_leak_t *leak = lub_heap_leak_instance();
-	lub_heap_t **ptr;
-	for (ptr = &leak->m_heap_list; *ptr; ptr = &(*ptr)->next) {
-		if ((*ptr) == this) {
-			/* remove from the linked list */
-			*ptr = this->next;
-			break;
-		}
-	}
-	lub_heap_leak_release(leak);
-
-	/* remove all segments from the leak tree */
-	lub_heap_foreach_segment(this, _lub_heap_segment_remove, 0);
-
-	/* remove all nodes from the leak tree */
-	lub_heap_foreach_node(_lub_heap_node_remove, this);
-}
-
-/*--------------------------------------------------------- */

+ 0 - 34
lub/heap/heap_extend_both_ways.c

@@ -1,34 +0,0 @@
-#include <assert.h>
-#include "private.h"
-
-/*--------------------------------------------------------- */
-bool_t
-lub_heap_extend_both_ways(lub_heap_t * this,
-			  lub_heap_block_t ** ptr_block, const words_t words)
-{
-	lub_heap_block_t *block = *ptr_block;
-	lub_heap_free_block_t *prev_block =
-	    (lub_heap_free_block_t *) lub_heap_block_getprevious(block);
-	lub_heap_free_block_t *next_block =
-	    (lub_heap_free_block_t *) lub_heap_block_getnext(block);
-	bool_t result = BOOL_FALSE;
-
-	if (prev_block && prev_block->tag.free && next_block
-	    && next_block->tag.free) {
-		/* OK we have a free block above and below us */
-		if (words <= (prev_block->tag.words + next_block->tag.words)) {
-			/* There is sufficient space to extend */
-			words_t delta = words - next_block->tag.words;
-			/* maximise the upward extension */
-			result = lub_heap_extend_downwards(this, &block, delta);
-			assert(BOOL_TRUE == result);
-			result =
-			    lub_heap_extend_upwards(this, &block,
-						    next_block->tag.words);
-			assert(BOOL_TRUE == result);
-		}
-	}
-	return result;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 81
lub/heap/heap_extend_downwards.c

@@ -1,81 +0,0 @@
-#include "private.h"
-
-/*--------------------------------------------------------- */
-bool_t
-lub_heap_extend_downwards(lub_heap_t * this,
-			  lub_heap_block_t ** ptr_block, const words_t words)
-{
-	lub_heap_block_t *block = *ptr_block;
-	lub_heap_free_block_t *prev_block =
-	    (lub_heap_free_block_t *) lub_heap_block_getprevious(block);
-	bool_t result = BOOL_FALSE;
-
-	if (NULL != prev_block) {
-		/* Do we have a free block below us? */
-		if (1 == prev_block->tag.free) {
-			int segment;
-			void *tmp;
-
-			/* work out how many extra words we need */
-			words_t delta = words - block->alloc.tag.words;
-
-			/* remove the block from the tree */
-			lub_bintree_remove(&this->free_tree, prev_block);
-
-			/* remember the segment status */
-			segment = prev_block->tag.segment;
-
-			/* try and slice off a chunk of memory */
-			tmp =
-			    lub_heap_slice_from_top(this, &prev_block, &delta,
-						    BOOL_FALSE);
-
-			if (NULL != prev_block) {
-				/* put the modified free block back into the tree */
-				lub_bintree_insert(&this->free_tree,
-						   prev_block);
-
-				/* there is still a block below us */
-				segment = 0;
-			}
-			if (NULL != tmp) {
-				/* we managed to extend downwards */
-				lub_heap_tag_t *tail =
-				    lub_heap_block__get_tail(block);
-				lub_heap_block_t *new_block = tmp;
-
-				/* get ready to copy the data down accounts for the header */
-				words_t old_words = tail->words;
-				const unsigned int *src = (unsigned int *)block;
-				unsigned int *dst = (unsigned int *)new_block;
-
-				/* copy the old data to the new location */
-				while (old_words--) {
-					*dst++ = *src++;
-				}
-				/* taint the extra memory */
-				lub_heap_taint_memory(((char *)tail) -
-						      (delta << 2),
-						      LUB_HEAP_TAINT_ALLOC,
-						      (delta << 2));
-
-				/* fill out the new block details */
-				tail->words += delta;
-				this->stats.alloc_bytes += (delta << 2);
-				this->stats.alloc_total_bytes += (delta << 2);
-
-				new_block->alloc.tag.segment = segment;
-				new_block->alloc.tag.free = 0;
-				new_block->alloc.tag.words = tail->words;
-
-				/* update the clients pointer */
-				*ptr_block = new_block;
-
-				result = BOOL_TRUE;
-			}
-		}
-	}
-	return result;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 68
lub/heap/heap_extend_upwards.c

@@ -1,68 +0,0 @@
-#include "private.h"
-/*--------------------------------------------------------- */
-bool_t
-lub_heap_extend_upwards(lub_heap_t * this,
-			lub_heap_block_t ** ptr_block, words_t words)
-{
-	lub_heap_block_t *block = *ptr_block;
-	lub_heap_free_block_t *next_block =
-	    (lub_heap_free_block_t *) lub_heap_block_getnext(block);
-	bool_t result = BOOL_FALSE;
-
-	if (NULL != next_block) {
-		/* Do we have a free block above us? */
-		if (1 == next_block->tag.free) {
-			int segment;
-			void *tmp;
-			lub_heap_tag_t *tail =
-			    lub_heap_block__get_tail((lub_heap_block_t *)
-						     next_block);
-
-			/* work out how many extra words we need */
-			words -= block->alloc.tag.words;
-
-			/* remove the block from the tree */
-			lub_bintree_remove(&this->free_tree, next_block);
-
-			/* remember the segment status of the next block */
-			segment = tail->segment;
-
-			/* try and slice off a chunk of memory */
-			tmp =
-			    lub_heap_slice_from_bottom(this, &next_block,
-						       &words, BOOL_FALSE);
-
-			if (NULL != next_block) {
-				/* put the modified free block back into the tree */
-				lub_bintree_insert(&this->free_tree,
-						   next_block);
-
-				/* there is still a block above us */
-				segment = 0;
-			}
-			if (NULL != tmp) {
-				/* we managed to extend upwards */
-				result = BOOL_TRUE;
-
-				/* taint the old tail pointer */
-				tail = lub_heap_block__get_tail(block);
-				lub_heap_taint_memory((char *)tail,
-						      LUB_HEAP_TAINT_ALLOC,
-						      sizeof(lub_heap_tag_t));
-
-				/* fill out the new block details */
-				block->alloc.tag.words += words;
-				this->stats.alloc_bytes += (words << 2);
-				this->stats.alloc_total_bytes += (words << 2);
-
-				tail = lub_heap_block__get_tail(block);
-				tail->segment = segment;
-				tail->free = 0;
-				tail->words = block->alloc.tag.words;
-			}
-		}
-	}
-	return result;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 24
lub/heap/heap_foreach_free_block.c

@@ -1,24 +0,0 @@
-/*
- * heap_foreach_free_block.c
- */
-#include "private.h"
-/*--------------------------------------------------------- */
-void
-lub_heap_foreach_free_block(lub_heap_t * this,
-			    lub_heap_foreach_fn * fn, void *arg)
-{
-	lub_heap_block_t *block = lub_bintree_findfirst(&this->free_tree);
-	lub_bintree_iterator_t iter;
-	unsigned int i = 1;
-
-	for (lub_bintree_iterator_init(&iter, &this->free_tree, block);
-	     block; block = lub_bintree_iterator_next(&iter)) {
-		/* call the client function */
-		fn(&block->free,
-		   i++,
-		   (block->free.tag.words << 2) -
-		   sizeof(lub_heap_alloc_block_t), arg);
-	}
-}
-
-/*--------------------------------------------------------- */

+ 0 - 18
lub/heap/heap_foreach_segment.c

@@ -1,18 +0,0 @@
-/*
- * heap_foreach_segment.c
- */
-#include "private.h"
-/*--------------------------------------------------------- */
-void
-lub_heap_foreach_segment(lub_heap_t * this, lub_heap_foreach_fn * fn, void *arg)
-{
-	lub_heap_segment_t *segment;
-	unsigned int i = 1;
-
-	for (segment = &this->first_segment; segment; segment = segment->next) {
-		/* call the client function */
-		fn(segment, i++, (segment->words << 2), arg);
-	}
-}
-
-/*--------------------------------------------------------- */

+ 0 - 61
lub/heap/heap_graft_to_bottom.c

@@ -1,61 +0,0 @@
-#include <assert.h>
-
-#include "private.h"
-
-/*--------------------------------------------------------- */
-void
-lub_heap_graft_to_bottom(lub_heap_t * this,
-			 lub_heap_block_t * free_block,
-			 void *ptr,
-			 words_t words,
-			 bool_t seg_start, bool_t other_free_block)
-{
-	lub_heap_tag_t *tail;
-	words_t new_words;
-	bool_t seg_end;
-
-	assert(1 == free_block->free.tag.free);
-
-	/* remove the previous block from the free tree */
-	lub_bintree_remove(&this->free_tree, free_block);
-
-	/* update the size of the next block */
-	this->stats.free_bytes += (words << 2);
-
-	new_words = words + free_block->free.tag.words;
-
-	tail = lub_heap_block__get_tail(free_block);
-	seg_end = tail->segment;
-
-	if (BOOL_FALSE == other_free_block) {
-		/* 
-		 * taint the memory being given back 
-		 * NB. we don't bother to taint all the memory if we are
-		 * combining two free blocks; they'll already be tainted.
-		 */
-		lub_heap_taint_memory((char *)ptr, LUB_HEAP_TAINT_FREE,
-				      (words << 2) +
-				      sizeof(lub_heap_free_block_t));
-	} else {
-		/* clear the free block details */
-		lub_heap_taint_memory((char *)free_block, LUB_HEAP_TAINT_FREE,
-				      sizeof(lub_heap_free_block_t));
-	}
-
-	free_block = ptr;
-	/* make sure we retain the segment details */
-	free_block->free.tag.free = 1;
-	free_block->free.tag.words = new_words;
-	free_block->free.tag.segment = seg_start;
-	lub_bintree_node_init(&free_block->free.bt_node);
-
-	/* and update the tail */
-	tail->free = 1;
-	tail->words = free_block->free.tag.words;
-	tail->segment = seg_end;
-
-	/* insert back into the tree */
-	lub_bintree_insert(&this->free_tree, free_block);
-}
-
-/*--------------------------------------------------------- */

+ 0 - 53
lub/heap/heap_graft_to_top.c

@@ -1,53 +0,0 @@
-#include <assert.h>
-
-#include "private.h"
-
-/*--------------------------------------------------------- */
-void
-lub_heap_graft_to_top(lub_heap_t * this,
-		      lub_heap_block_t * free_block,
-		      void *ptr,
-		      words_t words, bool_t seg_end, bool_t other_free_block)
-{
-	lub_heap_tag_t *tail;
-
-	assert(1 == free_block->free.tag.free);
-
-	/* remove the previous block from the free tree */
-	lub_bintree_remove(&this->free_tree, free_block);
-
-	if (BOOL_FALSE == other_free_block) {
-		tail = lub_heap_block__get_tail(free_block);
-		/* 
-		 * taint the memory being given back 
-		 * NB. we don't bother to taint all the memory if we are
-		 * combining two free blocks; they'll already be tainted.
-		 */
-		lub_heap_taint_memory((char *)tail,
-				      LUB_HEAP_TAINT_FREE,
-				      (words << 2) + sizeof(lub_heap_tag_t));
-	} else {
-		char *tmp = ptr;
-		/* clear out the freeblock details */
-		lub_heap_taint_memory(tmp - sizeof(lub_heap_tag_t),
-				      LUB_HEAP_TAINT_FREE,
-				      sizeof(lub_heap_tag_t) +
-				      sizeof(lub_heap_free_block_t));
-	}
-	/* update the size of the previous block */
-	free_block->free.tag.words += words;
-	this->stats.free_bytes += (words << 2);
-
-	/* make sure we retain the segment details */
-	tail = lub_heap_block__get_tail(free_block);
-	tail->segment = seg_end;
-	tail->free = 1;
-
-	/* update the size of the tail */
-	tail->words = free_block->free.tag.words;
-
-	/* insert back into the tree */
-	lub_bintree_insert(&this->free_tree, free_block);
-}
-
-/*--------------------------------------------------------- */

+ 0 - 42
lub/heap/heap_init_free_block.c

@@ -1,42 +0,0 @@
-#include "private.h"
-
-/*--------------------------------------------------------- */
-void
-lub_heap_init_free_block(lub_heap_t * this,
-			 void *start,
-			 size_t size, bool_t seg_start, bool_t seg_end)
-{
-	lub_heap_free_block_t *block = start;
-	lub_heap_tag_t *tail;
-	words_t words;
-
-	/* initialise the given memory */
-	lub_heap_taint_memory(start, LUB_HEAP_TAINT_FREE, size);
-
-	/* calculate the number of words in this segment */
-	words = (size >> 2);
-
-	/* setup the block */
-	block->tag.segment = seg_start;	/* start of a segment */
-	block->tag.free = 1;
-	block->tag.words = words;
-
-	/* initialise the tree node */
-	lub_bintree_node_init(&block->bt_node);
-
-	/* now fill out the trailing tag */
-	tail = lub_heap_block__get_tail((lub_heap_block_t *) block);
-	tail->segment = seg_end;	/* end of a segment */
-	tail->free = 1;
-	tail->words = words;
-
-	/* now insert this free block into the tree */
-	lub_bintree_insert(&this->free_tree, block);
-
-	++this->stats.free_blocks;
-	this->stats.free_bytes += (words << 2);
-	this->stats.free_bytes -= sizeof(lub_heap_alloc_block_t);
-	this->stats.free_overhead += sizeof(lub_heap_alloc_block_t);
-}
-
-/*--------------------------------------------------------- */

+ 0 - 37
lub/heap/heap_merge_with_next.c

@@ -1,37 +0,0 @@
-#include <assert.h>
-
-#include "private.h"
-
-/*--------------------------------------------------------- */
-lub_heap_status_t
-lub_heap_merge_with_next(lub_heap_t * this, lub_heap_block_t * block)
-{
-	lub_heap_status_t result = LUB_HEAP_FAILED;
-	lub_heap_block_t *next_block;
-
-	assert(0 == block->alloc.tag.free);
-
-	do {
-		/* see whether there is a free block just after us */
-		next_block = lub_heap_block_getnext(block);
-		if ((NULL != next_block)
-		    && (1 == next_block->free.tag.free)) {
-			if (BOOL_FALSE == lub_heap_block_check(next_block)) {
-				result = LUB_HEAP_CORRUPTED;
-				break;
-			}
-			lub_heap_graft_to_bottom(this,
-						 next_block,
-						 block,
-						 block->alloc.tag.words,
-						 block->alloc.tag.segment,
-						 block->free.tag.
-						 free ? BOOL_TRUE : BOOL_FALSE);
-			result = LUB_HEAP_OK;
-		}
-	} while (0);
-
-	return result;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 49
lub/heap/heap_merge_with_previous.c

@@ -1,49 +0,0 @@
-#include "private.h"
-
-/*--------------------------------------------------------- */
-lub_heap_status_t
-lub_heap_merge_with_previous(lub_heap_t * this, lub_heap_block_t * block)
-{
-	lub_heap_status_t result = LUB_HEAP_FAILED;
-	lub_heap_block_t *prev_block;
-
-	do {
-		/* see whether there is a free block just before us */
-		prev_block = lub_heap_block_getprevious(block);
-		if ((NULL != prev_block)
-		    && (1 == prev_block->free.tag.free)) {
-			lub_heap_tag_t *tail;
-
-			if (BOOL_FALSE == lub_heap_block_check(prev_block)) {
-				result = LUB_HEAP_CORRUPTED;
-				break;
-			}
-			tail = lub_heap_block__get_tail(block);
-
-			if (1 == block->free.tag.free) {
-				/* remove this free block from the tree */
-				lub_bintree_remove(&this->free_tree, block);
-				--this->stats.free_blocks;
-				this->stats.free_bytes -=
-				    (block->free.tag.words << 2);
-				this->stats.free_bytes +=
-				    sizeof(lub_heap_alloc_block_t);
-				this->stats.free_overhead -=
-				    sizeof(lub_heap_alloc_block_t);
-			}
-			/* now add this memory to the previous free block */
-			lub_heap_graft_to_top(this,
-					      prev_block,
-					      block,
-					      block->alloc.tag.words,
-					      tail->segment,
-					      block->free.tag.
-					      free ? BOOL_TRUE : BOOL_FALSE);
-			result = LUB_HEAP_OK;
-		}
-	} while (0);
-
-	return result;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 74
lub/heap/heap_new_alloc_block.c

@@ -1,74 +0,0 @@
-#include "private.h"
-
-/*--------------------------------------------------------- */
-void *lub_heap_new_alloc_block(lub_heap_t * this, words_t words)
-{
-	void *result = NULL;
-	lub_heap_free_block_t *free_block;
-	lub_heap_block_t *new_block;
-	lub_heap_key_t key;
-
-	/* initialise the seach key */
-	key.words = words;
-	key.block = 0;
-
-	/* find the smallest free block which can take this request */
-	free_block = lub_bintree_findnext(&this->free_tree, &key);
-	if (NULL != free_block) {
-		lub_heap_tag_t *tail;
-		unsigned int seg_end, seg_start;
-
-		/* remember if this is the end of a segment */
-		tail =
-		    lub_heap_block__get_tail((lub_heap_block_t *) free_block);
-		seg_start = free_block->tag.segment;
-		seg_end = tail->segment;
-
-		/* remove the block from the free tree */
-		lub_bintree_remove(&this->free_tree, free_block);
-
-		/* now slice the bottom off for the client */
-		new_block =
-		    lub_heap_slice_from_bottom(this, &free_block, &words,
-					       BOOL_FALSE);
-
-		if (NULL != free_block) {
-			/* put the block back into the tree */
-			lub_bintree_insert(&this->free_tree, free_block);
-		}
-		if (NULL != new_block) {
-			/* set up the tag details */
-			new_block->alloc.tag.segment = seg_start;
-			new_block->alloc.tag.free = 0;
-			new_block->alloc.tag.words = words;
-
-			tail = lub_heap_block__get_tail(new_block);
-			if (NULL == free_block) {
-				/* we've swallowed the whole free block */
-				tail->segment = seg_end;
-			} else {
-				tail->segment = 0;
-			}
-			tail->free = 0;
-			tail->words = words;
-
-			/* update the stats */
-			++this->stats.alloc_blocks;
-			this->stats.alloc_bytes += (words << 2);
-			this->stats.alloc_bytes -=
-			    sizeof(lub_heap_alloc_block_t);
-			++this->stats.alloc_total_blocks;
-			this->stats.alloc_total_bytes += (words << 2);
-			this->stats.alloc_total_bytes -=
-			    sizeof(lub_heap_alloc_block_t);
-			this->stats.alloc_overhead +=
-			    sizeof(lub_heap_alloc_block_t);
-
-			/* fill out the client's pointer */
-			result = new_block->alloc.memory;
-		}
-	}
-	return result;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 27
lub/heap/heap_new_free_block.c

@@ -1,27 +0,0 @@
-#include <assert.h>
-
-#include "private.h"
-
-/*--------------------------------------------------------- */
-lub_heap_status_t
-lub_heap_new_free_block(lub_heap_t * this, lub_heap_block_t * block)
-{
-	lub_heap_status_t result = LUB_HEAP_OK;
-	bool_t seg_start, seg_end;
-	lub_heap_tag_t *tail;
-
-	assert(0 == block->alloc.tag.free);
-
-	/* get the segment details from the current block */
-	seg_start = block->alloc.tag.segment;
-	tail = lub_heap_block__get_tail(block);
-	seg_end = tail->segment;
-
-	/* now set up the free block */
-	lub_heap_init_free_block(this,
-				 block, (tail->words << 2), seg_start, seg_end);
-
-	return result;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 41
lub/heap/heap_post_realloc.c

@@ -1,41 +0,0 @@
-#include <string.h>
-
-#include "private.h"
-#include "context.h"
-#include "node.h"
-
-void lub_heap_post_realloc(lub_heap_t * this, char **ptr)
-{
-	/* only act if we are about to re-enable the monitoring */
-	if ((0 < lub_heap_frame_count) && (2 > this->suppress)) {
-		if (NULL != *ptr) {
-			stackframe_t frame;
-			lub_heap_node_t *node = (lub_heap_node_t *) * ptr;
-			const lub_heap_context_t *context;
-
-			lub_heap__get_stackframe(&frame, lub_heap_frame_count);
-
-			/* make sure we break any recursive behaviour */
-			++this->suppress;
-			context = lub_heap_context_find_or_create(this, &frame);
-			--this->suppress;
-
-			/* initialise the node instance */
-			lub_heap_node_init(node,
-					   (lub_heap_context_t *) context);
-
-			/* make sure we doctor the pointer given back to the client */
-			*ptr = lub_heap_node__get_ptr(node);
-		}
-	}
-}
-
-void lub_heap_leak_suppress_detection(lub_heap_t * this)
-{
-	++this->suppress;
-}
-
-void lub_heap_leak_restore_detection(lub_heap_t * this)
-{
-	--this->suppress;
-}

+ 0 - 35
lub/heap/heap_pre_realloc.c

@@ -1,35 +0,0 @@
-#include <string.h>
-
-#include "private.h"
-#include "context.h"
-#include "node.h"
-
-/*
- * This function
- */
-void lub_heap_pre_realloc(lub_heap_t * this, char **ptr, size_t * size)
-{
-	if (*ptr) {
-		/* is this a pointer to a node in the "leak" trees? */
-		lub_heap_node_t *node =
-		    lub_heap_node_from_start_of_block_ptr(*ptr);
-		if (NULL != node) {
-			lub_heap_node_fini(node);
-			/* move the pointer to the start of the block */
-			*ptr = (char *)node;
-		}
-	}
-	if ((0 < lub_heap_frame_count)) {
-		size_t old_size = *size;
-		if (old_size) {
-			/* allocate enough bytes for a node */
-			*size += lub_heap_node__get_instanceSize();
-			if (*size < old_size) {
-				/* we've wrapped the size variable
-				 * make sure we fail the allocation
-				 */
-				*size = (size_t) - 1;
-			}
-		}
-	}
-}

+ 0 - 238
lub/heap/heap_raw_realloc.c

@@ -1,238 +0,0 @@
-#include <string.h>
-#include <assert.h>
-
-#include "private.h"
-
-/*--------------------------------------------------------- */
-lub_heap_status_t
-lub_heap_raw_realloc(lub_heap_t * this,
-		     char **ptr,
-		     size_t requested_size, lub_heap_align_t alignment)
-{
-	lub_heap_status_t result = LUB_HEAP_FAILED;
-	lub_heap_block_t *block = NULL;
-	words_t words;
-	char *new_ptr = NULL;
-	const size_t MIN_SIZE = sizeof(lub_heap_free_block_t);
-	/* make the minimum alignment leave enough space for 
-	 * (sizeof(lub_heap_free_block_t) + sizeof(lub_heap_alloc_block_t) + sizeof(lub_heap_node_t))
-	 * approx 72 bytes on 64-bit architecture
-	 */
-	const lub_heap_align_t MIN_ALIGN_NON_NATIVE = LUB_HEAP_ALIGN_2_POWER_7;
-	size_t size = requested_size;
-
-	do {
-		if (NULL == ptr)
-			break;	/* The client MUST give us a pointer to play with */
-
-		if (LUB_HEAP_ZERO_ALLOC == *ptr) {
-			*ptr = NULL;
-		}
-		if (*ptr
-		    && (BOOL_FALSE == lub_heap_validate_pointer(this, *ptr))) {
-			/* This is not a valid pointer */
-			result = LUB_HEAP_INVALID_POINTER;
-			break;
-		}
-		/* check the heap integrity */
-		if (BOOL_FALSE == lub_heap_check_memory(this)) {
-			result = LUB_HEAP_CORRUPTED;
-			break;
-		}
-
-		if (size) {
-			/* make sure we get enough space for the header/tail */
-			size += sizeof(lub_heap_alloc_block_t);
-
-			/* make sure we are at least natively aligned */
-			size += (LUB_HEAP_ALIGN_NATIVE - 1);
-			size &= ~(LUB_HEAP_ALIGN_NATIVE - 1);
-
-			if (size < MIN_SIZE) {
-				/* 
-				 * we must ensure that any allocated block is at least
-				 * large enough to hold a free block node when it is released
-				 */
-				size = MIN_SIZE;
-			}
-			if (LUB_HEAP_ALIGN_NATIVE != alignment) {
-				if (alignment < MIN_ALIGN_NON_NATIVE) {
-					/*
-					 * ensure that we always leave enough space
-					 * to be able to collapse the block to the 
-					 * right size
-					 */
-					alignment = MIN_ALIGN_NON_NATIVE;
-				}
-				/* add twice the alignment */
-				size += (alignment << 1);
-			}
-		}
-		words = (size >> 2);
-
-		if (requested_size > size) {
-			/* the size has wrapped when accounting for overheads */
-			break;
-		}
-		if (NULL != *ptr) {
-			/* get reference to the current block */
-			block = lub_heap_block_from_ptr(*ptr);
-
-			/* first of all check this is an allocated block */
-			if (1 == block->alloc.tag.free) {
-				result = LUB_HEAP_DOUBLE_FREE;
-				break;
-			}
-			/* first of all check this is an allocated block */
-			if (BOOL_FALSE == lub_heap_block_check(block)) {
-				result = LUB_HEAP_CORRUPTED;
-				break;
-			}
-			/* is the current block large enough for the request */
-			if (words && (block->alloc.tag.words >= words)) {
-				lub_heap_block_t *next_block =
-				    lub_heap_block_getnext(block);
-				words_t delta =
-				    (block->alloc.tag.words - words);
-				lub_heap_tag_t *tail;
-
-				result = LUB_HEAP_OK;
-				new_ptr = *ptr;
-
-				if (delta && (NULL != next_block)) {
-					/* can we graft this spare memory to a following free block? */
-					if (1 == next_block->free.tag.free) {
-
-						block->alloc.tag.words = words;
-						tail =
-						    lub_heap_block__get_tail
-						    (block);
-						tail->words = words;
-						tail->free = 0;
-						tail->segment = 0;
-
-						lub_heap_graft_to_bottom(this,
-									 next_block,
-									 &tail
-									 [1],
-									 delta,
-									 BOOL_FALSE,
-									 BOOL_FALSE);
-						this->stats.alloc_bytes -=
-						    (delta << 2);
-						break;
-					}
-				}
-				/* Is there enough space to turn the spare memory into a free block? */
-				if (delta >=
-				    (sizeof(lub_heap_free_block_t) >> 2)) {
-					tail = lub_heap_block__get_tail(block);
-
-					lub_heap_init_free_block(this,
-								 &tail[1 -
-								       delta],
-								 (delta << 2),
-								 BOOL_FALSE,
-								 tail->segment);
-
-					block->alloc.tag.words = words;
-					tail = lub_heap_block__get_tail(block);
-					tail->words = words;
-					tail->free = 0;
-					tail->segment = 0;
-					this->stats.alloc_bytes -= (delta << 2);
-				}
-				break;
-			} else if (words) {
-				/* can we simple extend the current allocated block? */
-				if ((BOOL_TRUE ==
-				     lub_heap_extend_upwards(this, &block,
-							     words))
-				    || (BOOL_TRUE ==
-					lub_heap_extend_downwards(this, &block,
-								  words))
-				    || (BOOL_TRUE ==
-					lub_heap_extend_both_ways(this, &block,
-								  words))) {
-					result = LUB_HEAP_OK;
-					new_ptr = (char *)block->alloc.memory;
-					break;
-				}
-			}
-		}
-		if (words && (LUB_HEAP_FAILED == result)) {
-			/* need to reallocate and copy the data */
-			new_ptr = lub_heap_new_alloc_block(this, words);
-			if (NULL != new_ptr) {
-				result = LUB_HEAP_OK;
-
-				if (NULL != block) {
-					/* now copy the old contents across */
-					memcpy(new_ptr,
-					       (const char *)block->alloc.
-					       memory,
-					       (block->alloc.tag.words << 2) -
-					       sizeof(lub_heap_alloc_block_t));
-				}
-			} else {
-				/* couldn't find the space for the request */
-				break;
-			}
-		}
-		/* now it's time to release the memory of the old block */
-		if (NULL != block) {
-			words_t old_words = block->alloc.tag.words;
-			bool_t done = BOOL_FALSE;
-
-			/* combine with the next block */
-			if (LUB_HEAP_OK ==
-			    lub_heap_merge_with_next(this, block)) {
-				done = BOOL_TRUE;
-			}
-			/* combine with the previous block */
-			if (LUB_HEAP_OK ==
-			    lub_heap_merge_with_previous(this, block)) {
-				done = BOOL_TRUE;
-			}
-			if (BOOL_FALSE == done) {
-				/* create a new free block */
-				lub_heap_new_free_block(this, block);
-			}
-			result = LUB_HEAP_OK;
-
-			--this->stats.alloc_blocks;
-			this->stats.alloc_bytes -= (old_words << 2);
-			this->stats.alloc_bytes +=
-			    sizeof(lub_heap_alloc_block_t);
-			this->stats.alloc_overhead -=
-			    sizeof(lub_heap_alloc_block_t);
-		}
-	} while (0);
-
-	if (LUB_HEAP_OK == result) {
-		unsigned delta;
-
-		/* align the block as required */
-		if (LUB_HEAP_ALIGN_NATIVE != alignment) {
-			lub_heap_align_block(this, alignment, &new_ptr, &size);
-		}
-		/* revert to client space available */
-		size -= sizeof(lub_heap_alloc_block_t);
-		*ptr = new_ptr;
-		delta = (size - requested_size);
-
-		if (*ptr && requested_size && (0 < delta)) {
-			/* make sure that any excess memory is tainted */
-			lub_heap_taint_memory(*ptr + requested_size,
-					      LUB_HEAP_TAINT_ALLOC, delta);
-		}
-	} else if ((LUB_HEAP_FAILED == result)
-		   && (0 == requested_size)
-		   && (NULL == *ptr)) {
-		/* freeing zero is always OK */
-		result = LUB_HEAP_OK;
-	}
-	return result;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 57
lub/heap/heap_realloc.c

@@ -1,57 +0,0 @@
-#include <string.h>
-#include <assert.h>
-
-#include "cache.h"
-
-/*--------------------------------------------------------- */
-lub_heap_status_t
-lub_heap_realloc(lub_heap_t * this,
-		 char **ptr, size_t requested_size, lub_heap_align_t alignment)
-{
-	lub_heap_status_t status = LUB_HEAP_FAILED;
-	size_t size = requested_size;
-
-	/* opportunity for leak detection to do it's stuff */
-	lub_heap_pre_realloc(this, ptr, &size);
-
-	if (this->cache && (LUB_HEAP_ALIGN_NATIVE == alignment)) {
-		/* try and get the memory from the cache */
-		status = lub_heap_cache_realloc(this, ptr, size);
-	} else {
-		/* get the memory directly from the dynamic heap */
-		status = lub_heap_raw_realloc(this, ptr, size, alignment);
-	}
-
-	/* opportunity for leak detection to do it's stuff */
-	lub_heap_post_realloc(this, ptr);
-
-	if (LUB_HEAP_OK == status) {
-		/* update the high tide markers */
-		if ((this->stats.alloc_bytes + this->stats.alloc_overhead)
-		    > (this->stats.alloc_hightide_bytes +
-		       this->stats.alloc_hightide_overhead)) {
-			this->stats.alloc_hightide_blocks =
-			    this->stats.alloc_blocks;
-			this->stats.alloc_hightide_bytes =
-			    this->stats.alloc_bytes;
-			this->stats.alloc_hightide_overhead =
-			    this->stats.alloc_overhead;
-			this->stats.free_hightide_blocks =
-			    this->stats.free_blocks;
-			this->stats.free_hightide_bytes =
-			    this->stats.free_bytes;
-			this->stats.free_hightide_overhead =
-			    this->stats.free_overhead;
-		}
-	} else {
-		/* this call enables a debugger to catch failures */
-		lub_heap_stop_here(status, *ptr, requested_size);
-	}
-	if ((0 == requested_size) && (NULL == *ptr) && (LUB_HEAP_OK == status)) {
-		/* make sure that client doesn't use this (non-existant memory) */
-		*ptr = LUB_HEAP_ZERO_ALLOC;
-	}
-	return status;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 66
lub/heap/heap_scan_stack.c

@@ -1,66 +0,0 @@
-/*
- * Generic stack scanning function
- *
- * This currently only scans the last 32 levels of the current stack.
- */
-#ifdef __GNUC__
-#include "private.h"
-#include "node.h"
-/*--------------------------------------------------------- */
-void lub_heap_scan_stack(void)
-{
-	char *start, *end;
-#define FRAME_ADDRESS(n)                            \
-    {                                               \
-        char *fn = __builtin_return_address(n);     \
-        if(!fn || (fn > lub_heap_data_start))       \
-        {                                           \
-            break;                                  \
-        }                                           \
-        end = __builtin_frame_address(n);           \
-    }                                               \
-
-	start = end = __builtin_frame_address(0);
-
-	do {
-		FRAME_ADDRESS(0);
-		FRAME_ADDRESS(1);
-		FRAME_ADDRESS(2);
-		FRAME_ADDRESS(3);
-		FRAME_ADDRESS(4);
-		FRAME_ADDRESS(5);
-		FRAME_ADDRESS(6);
-		FRAME_ADDRESS(7);
-		FRAME_ADDRESS(8);
-		FRAME_ADDRESS(9);
-		FRAME_ADDRESS(10);
-		FRAME_ADDRESS(11);
-		FRAME_ADDRESS(12);
-		FRAME_ADDRESS(13);
-		FRAME_ADDRESS(14);
-		FRAME_ADDRESS(15);
-		FRAME_ADDRESS(16);
-		FRAME_ADDRESS(17);
-		FRAME_ADDRESS(18);
-		FRAME_ADDRESS(19);
-		FRAME_ADDRESS(20);
-		FRAME_ADDRESS(21);
-		FRAME_ADDRESS(22);
-		FRAME_ADDRESS(23);
-		FRAME_ADDRESS(24);
-		FRAME_ADDRESS(25);
-		FRAME_ADDRESS(26);
-		FRAME_ADDRESS(27);
-		FRAME_ADDRESS(28);
-		FRAME_ADDRESS(29);
-		FRAME_ADDRESS(30);
-		FRAME_ADDRESS(31);
-	} while (0);
-	/* now scan the memory */
-	lub_heap_scan_memory(start, end - start);
-}
-
-/*--------------------------------------------------------- */
-#else				/* not __GNUC__ */
-#warning "Generic stack scanning not implemented for non-GCC compiler..."
-#endif				/* not __GNUC__ */

+ 0 - 135
lub/heap/heap_show.c

@@ -1,135 +0,0 @@
-/* 
- * heap_show.c
- */
-#include <stdio.h>
-#include "cache.h"
-
-/*--------------------------------------------------------- */
-static void
-process_free_block(void *block, unsigned index, size_t size, void *arg)
-{
-	/* dump the details for this block */
-	printf(" %8p[%" SIZE_FMT "]", block, size);
-}
-
-/*--------------------------------------------------------- */
-static void
-process_segment(void *segment, unsigned index, size_t size, void *arg)
-{
-	/* dump the details for this segment */
-	printf(" %8p[%" SIZE_FMT "]", segment, size);
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_show(lub_heap_t * this, bool_t verbose)
-{
-	static char *state_names[] = { "DISABLED", "ENABLED" };
-	lub_heap_stats_t stats;
-
-	if (BOOL_FALSE == lub_heap_check_memory(this)) {
-		printf("*** HEAP CORRUPTED!!! ***\n");
-	}
-	if (BOOL_TRUE == verbose) {
-		printf("HEAP:\n" "  %8p\n", (void *)this);
-		printf("\nHEAP SEGMENTS:\n");
-		lub_heap_foreach_segment(this, process_segment, NULL);
-		printf("\n");
-		if (this->cache) {
-			printf("\nCACHE:\n");
-			lub_heap_cache_show(this->cache);
-		}
-		/* dump each free block's details */
-		printf("\nFREE BLOCKS:\n");
-		lub_heap_foreach_free_block(this, process_free_block, NULL);
-		printf("\n");
-		printf("\nSUMMARY:\n");
-	}
-	{
-		/*lint -esym(644,cache_stats) may not have been initialized */
-		lub_heap_stats_t cache_stats;
-		/* get the stats */
-		lub_heap__get_stats(this, &stats);
-
-		/* dump the statistics for this heap */
-		printf
-		    ("  status      bytes    blocks  avg block  max block   overhead\n");
-		printf
-		    ("  ------ ---------- --------- ---------- ---------- ----------\n");
-
-		printf("current\n");
-		printf("    free %10" SIZE_FMT " %9" SIZE_FMT " %10" SIZE_FMT
-		       " %10" SIZE_FMT " %10" SIZE_FMT "\n", stats.free_bytes,
-		       stats.free_blocks,
-		       stats.free_blocks ? stats.free_bytes /
-		       stats.free_blocks : 0, lub_heap__get_max_free(this),
-		       stats.free_overhead + stats.segs_overhead);
-		printf("   alloc %10" SIZE_FMT " %9" SIZE_FMT " %10" SIZE_FMT
-		       " %10s %10" SIZE_FMT "\n", stats.alloc_bytes,
-		       stats.alloc_blocks,
-		       stats.alloc_blocks ? stats.alloc_bytes /
-		       stats.alloc_blocks : 0, "-", stats.alloc_overhead);
-		printf("  static %10" SIZE_FMT " %9" SIZE_FMT " %10" SIZE_FMT
-		       " %10s %10" SIZE_FMT "\n", stats.static_bytes,
-		       stats.static_blocks,
-		       stats.static_blocks ? stats.static_bytes /
-		       stats.static_blocks : 0, "-", stats.static_overhead);
-		if (this->cache) {
-			printf(" (cache)\n");
-			lub_heap_cache__get_stats(this->cache, &cache_stats);
-			printf("    free %10" SIZE_FMT " %9" SIZE_FMT " %10"
-			       SIZE_FMT " %10" SIZE_FMT " %10" SIZE_FMT "\n",
-			       cache_stats.free_bytes, cache_stats.free_blocks,
-			       cache_stats.free_blocks ? cache_stats.
-			       free_bytes / cache_stats.free_blocks : 0,
-			       lub_heap_cache__get_max_free(this->cache),
-			       cache_stats.free_overhead);
-			printf("   alloc %10" SIZE_FMT " %9" SIZE_FMT " %10"
-			       SIZE_FMT " %10s %10" SIZE_FMT "\n",
-			       cache_stats.alloc_bytes,
-			       cache_stats.alloc_blocks,
-			       cache_stats.alloc_blocks ? cache_stats.
-			       alloc_bytes / cache_stats.alloc_blocks : 0, "-",
-			       cache_stats.alloc_overhead);
-		}
-
-		printf("cumulative\n");
-		printf("   alloc %10" SIZE_FMT " %9" SIZE_FMT " %10" SIZE_FMT
-		       " %10s %10s\n", stats.alloc_total_bytes,
-		       stats.alloc_total_blocks,
-		       stats.alloc_total_blocks ? stats.alloc_total_bytes /
-		       stats.alloc_total_blocks : 0, "-", "-");
-		if (this->cache) {
-			printf(" (cache)\n");
-			printf("   alloc %10" SIZE_FMT " %9" SIZE_FMT " %10"
-			       SIZE_FMT " %10s %10s\n",
-			       cache_stats.alloc_total_bytes,
-			       cache_stats.alloc_total_blocks,
-			       cache_stats.alloc_total_blocks ? cache_stats.
-			       alloc_total_bytes /
-			       cache_stats.alloc_total_blocks : 0, "-", "-");
-		}
-		printf("high-tide\n");
-		printf("    free %10" SIZE_FMT " %9" SIZE_FMT " %10" SIZE_FMT
-		       " %10s %10" SIZE_FMT "\n", stats.free_hightide_bytes,
-		       stats.free_hightide_blocks,
-		       stats.free_hightide_blocks ? stats.free_hightide_bytes /
-		       stats.free_hightide_blocks : 0, "-",
-		       stats.free_hightide_overhead);
-		printf("   alloc %10" SIZE_FMT " %9" SIZE_FMT " %10" SIZE_FMT
-		       " %10s %10" SIZE_FMT "\n", stats.alloc_hightide_bytes,
-		       stats.alloc_hightide_blocks,
-		       stats.alloc_hightide_blocks ? stats.
-		       alloc_hightide_bytes / stats.alloc_hightide_blocks : 0,
-		       "-", stats.alloc_hightide_overhead);
-	}
-	if (BOOL_TRUE == verbose) {
-		printf("\nSYSTEM:\n"
-		       "  tainting(%s), full checking(%s), leak detection(%s),\n"
-		       "  native alignment of %d bytes\n",
-		       state_names[lub_heap_is_tainting()],
-		       state_names[lub_heap_is_checking()],
-		       state_names[lub_heap__get_framecount()? 0 : 1],
-		       LUB_HEAP_ALIGN_NATIVE);
-	}
-	printf("\n");
-}

+ 0 - 75
lub/heap/heap_slice_from_bottom.c

@@ -1,75 +0,0 @@
-#include <assert.h>
-
-#include "private.h"
-/*--------------------------------------------------------- */
-void *lub_heap_slice_from_bottom(lub_heap_t * this,
-				 lub_heap_free_block_t ** ptr_block,
-				 words_t * words, bool_t seg_start)
-{
-	void *result = NULL;
-	lub_heap_free_block_t *block = *ptr_block;
-
-	/* check this is a free block */
-	assert(1 == block->tag.free);
-
-	if (BOOL_TRUE == lub_heap_block_check((lub_heap_block_t *) block)
-	    && (*words <= block->tag.words)) {
-		words_t new_words = (block->tag.words - *words);
-
-		/* get the tag at the end of the current free block */
-		lub_heap_tag_t *tail =
-		    lub_heap_block__get_tail((lub_heap_block_t *) block);
-
-		/* 
-		 * Is there sufficient memory to perform the task? 
-		 * we must leave enough space for the free block to work
-		 */
-		if (new_words > (sizeof(lub_heap_free_block_t) >> 2)) {
-			lub_heap_free_block_t *new_block;
-
-			/* adjust the free block size */
-			tail->words -= *words;
-
-			/* create a new free block header */
-			new_block =
-			    (lub_heap_free_block_t *) (&block->tag + *words);
-			new_block->tag.segment = seg_start;
-			new_block->tag.free = 1;	/* this is a free block */
-			new_block->tag.words = tail->words;
-
-			/* update the stats */
-			this->stats.free_bytes -= (*words << 2);
-
-			/* set up the tree node */
-			lub_bintree_node_init(&new_block->bt_node);
-
-			result = block;
-			*ptr_block = new_block;
-		} else {
-			/* 
-			 * there is only just enough space for the request
-			 * so we also throw in the memory used for the tags
-			 */
-			--this->stats.free_blocks;
-			this->stats.free_bytes -= (block->tag.words << 2);
-			this->stats.free_bytes +=
-			    sizeof(lub_heap_alloc_block_t);
-			this->stats.free_overhead -=
-			    sizeof(lub_heap_alloc_block_t);
-			/* update the client's word count */
-			*words = block->tag.words;
-
-			/* there is no free block left!!! */
-			result = block;
-			*ptr_block = NULL;
-		}
-		if (NULL != result) {
-			/* taint the memory */
-			lub_heap_taint_memory(result, LUB_HEAP_TAINT_ALLOC,
-					      (*words << 2));
-		}
-	}
-	return result;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 68
lub/heap/heap_slice_from_top.c

@@ -1,68 +0,0 @@
-#include <assert.h>
-
-#include "private.h"
-
-/*--------------------------------------------------------- */
-void *lub_heap_slice_from_top(lub_heap_t * this,
-			      lub_heap_free_block_t ** ptr_block,
-			      words_t * words, bool_t seg_end)
-{
-	void *result = NULL;
-	lub_heap_free_block_t *block = *ptr_block;
-
-	/* check this is a free block */
-	assert(1 == block->tag.free);
-
-	if (BOOL_TRUE == lub_heap_block_check((lub_heap_block_t *) block)
-	    && (*words <= block->tag.words)) {
-		words_t new_words = (block->tag.words - *words);
-		lub_heap_tag_t *tail;
-
-		/* Is there sufficient memory to perform the task? */
-		if (new_words > (sizeof(lub_heap_free_block_t) >> 2)) {
-			/* update the free block */
-			block->tag.words -= *words;
-
-			/* get the new tail tag */
-			tail =
-			    lub_heap_block__get_tail((lub_heap_block_t *)
-						     block);
-
-			/* set up the tag */
-			tail->segment = seg_end;
-			tail->free = 1;
-			tail->words = block->tag.words;
-
-			/* update the stats */
-			this->stats.free_bytes -= (*words << 2);
-
-			result = &tail[1];
-		} else {
-			/* 
-			 * there is only just enough space for the request
-			 * so we also throw in the memory used for the tags
-			 */
-			--this->stats.free_blocks;
-			this->stats.free_bytes -= (block->tag.words << 2);
-			this->stats.free_bytes +=
-			    sizeof(lub_heap_alloc_block_t);
-			this->stats.free_overhead -=
-			    sizeof(lub_heap_alloc_block_t);
-
-			/* update the client's word count */
-			*words = block->tag.words;
-
-			/* there is no free block left!!! */
-			result = block;
-			*ptr_block = NULL;
-		}
-		if (NULL != result) {
-			/* taint the memory */
-			lub_heap_taint_memory(result, LUB_HEAP_TAINT_ALLOC,
-					      (*words << 2));
-		}
-	}
-	return result;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 98
lub/heap/heap_static_alloc.c

@@ -1,98 +0,0 @@
-#include "cache.h"
-
-/*--------------------------------------------------------- */
-size_t lub_heap__get_block_overhead(lub_heap_t * this, const void *block)
-{
-	size_t overhead;
-	lub_heap_cache_bucket_t *bucket = 0;
-	if (this->cache) {
-		bucket =
-		    lub_heap_cache_find_bucket_from_address(this->cache, block);
-	}
-	if (bucket) {
-		overhead =
-		    lub_heap_cache_bucket__get_block_overhead(bucket, block);
-	} else {
-		overhead = sizeof(lub_heap_alloc_block_t);
-	}
-	return overhead;
-}
-
-/*--------------------------------------------------------- */
-size_t lub_heap__get_block_size(lub_heap_t * this, const void *block)
-{
-	size_t bytes = 0;
-	lub_heap_cache_bucket_t *bucket = 0;
-	if (this->cache) {
-		bucket =
-		    lub_heap_cache_find_bucket_from_address(this->cache, block);
-	}
-	if (bucket) {
-		bytes = lub_heap_cache_bucket__get_block_size(bucket, block);
-	} else {
-		const lub_heap_tag_t *header = block;
-		--header;
-		bytes = (header->words << 2);
-		bytes -= sizeof(lub_heap_alloc_block_t);
-	}
-	return bytes;
-}
-
-/*--------------------------------------------------------- */
-void *lub_heap_static_alloc(lub_heap_t * this, size_t requested_size)
-{
-	void *result = NULL;
-	lub_heap_free_block_t *free_block;
-	/* round up to native alignment */
-	words_t words;
-	lub_heap_key_t key;
-	size_t size = requested_size;
-
-	size = (size + (LUB_HEAP_ALIGN_NATIVE - 1)) / LUB_HEAP_ALIGN_NATIVE;
-	size *= LUB_HEAP_ALIGN_NATIVE;
-	words = (size >> 2);
-
-	/* initialise the search key */
-	key.words = words;
-	key.block = 0;
-
-	/* search for the start of a segment which is large enough for the request */
-	while ((free_block = lub_bintree_findnext(&this->free_tree, &key))) {
-		lub_heap_tag_t *tail =
-		    lub_heap_block__get_tail((lub_heap_block_t *) free_block);
-
-		/* is this free block at the start of a segment? */
-		if (1 == tail->segment) {
-			/* yes this is the end of a segment */
-			break;
-		}
-		/* update the search key */
-		lub_heap_block_getkey(free_block, (lub_bintree_key_t *) & key);
-	}
-	if (NULL != free_block) {
-		/* remove this block from the free tree */
-		lub_bintree_remove(&this->free_tree, free_block);
-
-		/* 
-		 * get some memory from the bottom of this free block 
-		 */
-		result = lub_heap_slice_from_top(this,
-						 &free_block,
-						 &words, BOOL_TRUE);
-
-		if (NULL != free_block) {
-			/* put the free block back into the tree */
-			lub_bintree_insert(&this->free_tree, free_block);
-		}
-		if (NULL != result) {
-			size_t allocated_size = (words << 2);
-			/* update the stats */
-			++this->stats.static_blocks;
-			this->stats.static_bytes += size;
-			this->stats.static_overhead += (allocated_size - size);
-		}
-	}
-	return result;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 61
lub/heap/heap_stop_here.c

@@ -1,61 +0,0 @@
-#include <stdio.h>
-
-#include "private.h"
-#include "context.h"
-
-/* 
- * This global variable is used to control error output when 
- * lub_heap_stop_here is called
- */
-int lub_heap_verbose_errors = 0;
-
-static const char *status_names[] = {
-	"LUB_HEAP_OK",
-	"LUB_HEAP_FAILED",
-	"LUB_HEAP_DOUBLE_FREE",
-	"LUB_HEAP_CORRUPTED",
-	"LUB_HEAP_INVALID_POINTER"
-};
-
-/*--------------------------------------------------------- */
-void
-lub_heap_stop_here(lub_heap_status_t status, char *old_ptr, size_t new_size)
-{
-	/* This is provided as a debug aid */
-	status = status;
-	old_ptr = old_ptr;
-	new_size = new_size;
-
-	if (lub_heap_verbose_errors) {
-		switch (status) {
-		case LUB_HEAP_OK:
-		case LUB_HEAP_FAILED:
-			{
-				/* this is normal */
-				break;
-			}
-		case LUB_HEAP_DOUBLE_FREE:
-		case LUB_HEAP_CORRUPTED:
-		case LUB_HEAP_INVALID_POINTER:
-			{
-				/* obtain the backtrace of the stack */
-				stackframe_t frame;
-				long address;
-				int i;
-				lub_heap__get_stackframe(&frame, MAX_BACKTRACE);
-				/* and output it */
-				printf("lub_heap_stop_here(%s,%p,%" SIZE_FMT
-				       ")\n", status_names[status], old_ptr,
-				       new_size);
-				for (i = 0;
-				     (address = (long)frame.backtrace[i]);
-				     i++) {
-					lub_heap_symShow(address);
-					printf("\n");
-				}
-			}
-		}
-	}
-}
-
-/*--------------------------------------------------------- */

+ 0 - 58
lub/heap/heap_tainted_memory.c

@@ -1,58 +0,0 @@
-#include "string.h"
-
-#include "private.h"
-#include "context.h"
-
-/* flag to indicate whether to taint memory or not */
-static bool_t tainted = BOOL_FALSE;
-
-/*--------------------------------------------------------- */
-bool_t lub_heap_taint(bool_t enable)
-{
-	bool_t result = tainted;
-
-	tainted = enable;
-
-	return result;
-}
-
-/*--------------------------------------------------------- */
-bool_t lub_heap_is_tainting(void)
-{
-	return tainted;
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_taint_memory(char *ptr, lub_heap_taint_t type, size_t size)
-{
-	if (BOOL_TRUE == tainted) {
-#ifdef __vxworks
-		extern function_t taskDestroy;	/* fiddle a reference to the function ... */
-		extern function_t taskSuspend;	/* ...and the next function in the library */
-		/* 
-		 * VxWorks taskDestroy() relies on being able to access
-		 * free memory.
-		 * It calls objFree() followed by objTerminate() !!!!
-		 * So we have to perform a crufty hack to avoid this
-		 * mistake blowing us out of the water...
-		 */
-		if (LUB_HEAP_TAINT_FREE == type) {
-			int i;
-			/* obtain the backtrace of the stack */
-			stackframe_t frame;
-			lub_heap__get_stackframe(&frame, 10);
-			for (i = 0; i < 10; i++) {
-				function_t *address = frame.backtrace[i];
-				if ((address > &taskDestroy)
-				    && (address < &taskSuspend)) {
-					return;
-				}
-			}
-		}
-#endif				/* __vxworks */
-		/* taint the memory */
-		memset(ptr, type, size);
-	}
-}
-
-/*--------------------------------------------------------- */

+ 0 - 57
lub/heap/module.am

@@ -1,57 +0,0 @@
-if LUBHEAP
-  liblub_la_SOURCES +=  lub/heap/cache.c                        \
-                        lub/heap/cache.h                        \
-                        lub/heap/cache_bucket.c                 \
-                        lub/heap/context.c                      \
-                        lub/heap/context.h                      \
-                        lub/heap/heap__get_max_free.c           \
-                        lub/heap/heap__get_stacktrace.c         \
-                        lub/heap/heap__get_stats.c              \
-                        lub/heap/heap_add_segment.c             \
-                        lub/heap/heap_align_block.c             \
-                        lub/heap/heap_block__get_tail.c         \
-                        lub/heap/heap_block_from_ptr.c          \
-                        lub/heap/heap_block_getfirst.c          \
-                        lub/heap/heap_block_getkey.c            \
-                        lub/heap/heap_block_getnext.c           \
-                        lub/heap/heap_block_getprevious.c       \
-                        lub/heap/heap_block_check.c             \
-                        lub/heap/heap_check.c                   \
-                        lub/heap/heap_context_delete.c          \
-                        lub/heap/heap_context_find_or_create.c  \
-                        lub/heap/heap_create.c                  \
-                        lub/heap/heap_destroy.c                 \
-                        lub/heap/heap_extend_both_ways.c        \
-                        lub/heap/heap_extend_downwards.c        \
-                        lub/heap/heap_extend_upwards.c          \
-                        lub/heap/heap_foreach_free_block.c      \
-                        lub/heap/heap_foreach_segment.c         \
-                        lub/heap/heap_graft_to_bottom.c         \
-                        lub/heap/heap_graft_to_top.c            \
-                        lub/heap/heap_init_free_block.c         \
-                        lub/heap/heap_merge_with_next.c         \
-                        lub/heap/heap_merge_with_previous.c     \
-                        lub/heap/heap_new_alloc_block.c         \
-                        lub/heap/heap_new_free_block.c          \
-                        lub/heap/heap_post_realloc.c            \
-                        lub/heap/heap_pre_realloc.c             \
-                        lub/heap/heap_raw_realloc.c             \
-                        lub/heap/heap_realloc.c                 \
-                        lub/heap/heap_scan_stack.c              \
-                        lub/heap/heap_show.c                    \
-                        lub/heap/heap_slice_from_bottom.c       \
-                        lub/heap/heap_slice_from_top.c          \
-                        lub/heap/heap_static_alloc.c            \
-                        lub/heap/heap_stop_here.c               \
-                        lub/heap/heap_tainted_memory.c          \
-                        lub/heap/node.c                         \
-                        lub/heap/node.h                         \
-                        lub/heap/private.h
-endif
-
-EXTRA_DIST             +=       \
-    lub/heap/posix/module.am    \
-    lub/heap/vxworks/module.am
-
-include $(top_srcdir)/lub/heap/posix/module.am
-include $(top_srcdir)/lub/heap/vxworks/module.am

+ 0 - 483
lub/heap/node.c

@@ -1,483 +0,0 @@
-/*
- * node.c
- */
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-
-#include "private.h"
-#include "context.h"
-#include "node.h"
-
-int lub_heap_leak_verbose = 0;
-/*--------------------------------------------------------- */
-int lub_heap_node_compare(const void *clientnode, const void *clientkey)
-{
-	const lub_heap_node_t *node = clientnode;
-	const lub_heap_node_key_t *key = clientkey;
-
-	return ((long)node - (long)key->node);
-}
-
-/*--------------------------------------------------------- */
-/* we simply use the node address as the index */
-void lub_heap_node_getkey(const void *clientnode, lub_bintree_key_t * key)
-{
-	lub_heap_node_key_t clientkey;
-	clientkey.node = clientnode;
-	memcpy(key, &clientkey, sizeof(lub_heap_node_key_t));
-}
-
-/*--------------------------------------------------------- */
-static void lub_heap_node_meta_init(void)
-{
-	static bool_t initialised = BOOL_FALSE;
-
-	if (BOOL_FALSE == initialised) {
-		lub_heap_leak_t *leak = lub_heap_leak_instance();
-		initialised = BOOL_TRUE;
-		/* initialise the node tree */
-		lub_bintree_init(&leak->m_node_tree,
-				 offsetof(lub_heap_node_t, bt_node),
-				 lub_heap_node_compare, lub_heap_node_getkey);
-		/* initialise the clear node tree */
-		lub_bintree_init(&leak->m_clear_node_tree,
-				 offsetof(lub_heap_node_t, bt_node),
-				 lub_heap_node_compare, lub_heap_node_getkey);
-		lub_heap_leak_release(leak);
-	}
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_node_init(lub_heap_node_t * this, lub_heap_context_t * context)
-{
-	lub_heap_node_meta_init();
-
-	/* initialise the control blocks */
-	lub_bintree_node_init(&this->bt_node);
-
-	lub_heap_node__set_context(this, context);
-	lub_heap_node__set_leaked(this, BOOL_FALSE);
-	lub_heap_node__set_partial(this, BOOL_FALSE);
-	lub_heap_node__set_next(this, NULL);
-	lub_heap_node__set_scanned(this, BOOL_FALSE);
-	this->prev = NULL;
-	{
-		lub_heap_leak_t *leak = lub_heap_leak_instance();
-		/* add this to the node tree */
-		lub_bintree_insert(context ? &leak->m_node_tree : &leak->
-				   m_clear_node_tree, this);
-		lub_heap_leak_release(leak);
-	}
-	if (context) {
-		/* add ourselves to this context */
-		lub_heap_context_insert_node(context, this);
-
-		/* maintain the leak statistics */
-		++context->allocs;
-		context->alloc_bytes += lub_heap_node__get_size(this);
-		context->alloc_overhead += lub_heap_node__get_overhead(this);
-	}
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_node_fini(lub_heap_node_t * this)
-{
-	/* remove this node from this context */
-	lub_heap_node_clear(this, 0);
-	{
-		lub_heap_leak_t *leak = lub_heap_leak_instance();
-		/* remove this from the clear_node tree */
-		lub_bintree_remove(&leak->m_clear_node_tree, this);
-		lub_heap_leak_release(leak);
-	}
-}
-
-/*--------------------------------------------------------- */
-size_t lub_heap_node__get_instanceSize(void)
-{
-	return sizeof(lub_heap_node_t);
-}
-
-/*--------------------------------------------------------- */
-size_t lub_heap_node__get_size(const lub_heap_node_t * this)
-{
-	size_t size =
-	    lub_heap__get_block_size(lub_heap_node__get_context(this)->heap,
-				     this);
-	size -= sizeof(lub_heap_node_t);
-	return size;
-}
-
-/*--------------------------------------------------------- */
-size_t lub_heap_node__get_overhead(const lub_heap_node_t * this)
-{
-	size_t overhead;
-
-	overhead =
-	    lub_heap__get_block_overhead(lub_heap_node__get_context(this)->heap,
-					 lub_heap_node__get_ptr(this));
-
-	overhead += sizeof(lub_heap_node_t);
-	return overhead;
-}
-
-/*--------------------------------------------------------- */
-char *lub_heap_node__get_ptr(const lub_heap_node_t * this)
-{
-	return (char *)&this[1];
-}
-
-/*--------------------------------------------------------- */
-bool_t lub_heap_validate_pointer(lub_heap_t * this, char *ptr)
-{
-	bool_t result = BOOL_FALSE;
-	do {
-		lub_heap_segment_t *seg;
-		if ((0 < lub_heap_frame_count)) {
-			/*
-			 * When leak detection is enabled we can perform detailed 
-			 * validation of pointers.
-			 */
-			lub_heap_node_t *node =
-			    lub_heap_node_from_start_of_block_ptr(ptr);
-			if (NULL != node) {
-				lub_heap_context_t *context =
-				    lub_heap_node__get_context(node);
-				/* we've found a context so can give a definative answer */
-				if (this == context->heap) {
-					result = BOOL_TRUE;
-				}
-				break;
-			}
-		}
-		/* iterate around each of the segments belonging to this heap */
-		for (seg = &this->first_segment; seg; seg = seg->next) {
-			char *start = (char *)&seg[1];
-			if (ptr >= start) {
-				char *end = start + (seg->words << 2);
-				if (ptr < end) {
-					/* we've found a parent segment for this pointer */
-					result = BOOL_TRUE;
-					break;
-				}
-			}
-		}
-	} while (0);
-	ptr = 0;		/* don't leave a pointer on the stack */
-	return result;
-}
-
-/*--------------------------------------------------------- */
-static lub_heap_node_t *_lub_heap_node_from_ptr(lub_bintree_t * tree,
-						const char *ptr,
-						bool_t start_of_block)
-{
-	lub_heap_node_t *result = 0;
-	if (tree->root) {
-		lub_heap_node_key_t key;
-
-		/* search for the node which comes immediately before this pointer */
-		key.node = (lub_heap_node_t *) ptr;
-		result = lub_bintree_findprevious(tree, &key);
-
-		if (NULL != result) {
-			char *tmp = lub_heap_node__get_ptr(result);
-			/* ensure that the pointer is within the scope of this node */
-			if (start_of_block) {
-				if (ptr != tmp) {
-					/* 
-					 * this should be an exact match and isn't
-					 */
-					result = NULL;
-				}
-			} else if (ptr < tmp) {
-				/* 
-				 * this is referencing part of the node header
-				 */
-				result = NULL;
-			} else {
-				/* compare with the end of the allocated memory */
-				tmp += lub_heap_node__get_size(result);
-				/* ensure that the pointer is within the scope of this node */
-				if (ptr >= tmp) {
-					/* out of range of this node */
-					result = NULL;
-				}
-			}
-			tmp = 0;	/* don't leave a pointer on the stack */
-		}
-	}
-	ptr = 0;		/* don't leave a pointer on the stack */
-	return result;
-}
-
-/*--------------------------------------------------------- */
-lub_heap_node_t *lub_heap_node_from_start_of_block_ptr(char *ptr)
-{
-	lub_heap_node_t *result = 0;
-	if (lub_heap_leak_query_node_tree()) {
-		lub_heap_leak_t *leak = lub_heap_leak_instance();
-		result =
-		    _lub_heap_node_from_ptr(&leak->m_node_tree, ptr, BOOL_TRUE);
-		lub_heap_leak_release(leak);
-	}
-	if ((0 == result) && lub_heap_leak_query_clear_node_tree()) {
-		lub_heap_leak_t *leak = lub_heap_leak_instance();
-		result =
-		    _lub_heap_node_from_ptr(&leak->m_clear_node_tree, ptr,
-					    BOOL_TRUE);
-		lub_heap_leak_release(leak);
-	}
-	ptr = 0;		/* don't leave a pointer on the stack */
-	return result;
-}
-
-/*--------------------------------------------------------- */
-void
-lub_heap_node__set_context(lub_heap_node_t * this, lub_heap_context_t * value)
-{
-	unsigned long mask =
-	    ((unsigned long)value & ~(LEAKED_MASK | PARTIAL_MASK));
-	this->_context = (lub_heap_context_t *) mask;
-}
-
-/*--------------------------------------------------------- */
-lub_heap_context_t *lub_heap_node__get_context(const lub_heap_node_t * this)
-{
-	unsigned long mask =
-	    (unsigned long)this->_context & ~(LEAKED_MASK | PARTIAL_MASK);
-	return (lub_heap_context_t *) mask;
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_node__set_next(lub_heap_node_t * this, lub_heap_node_t * value)
-{
-	unsigned long mask = ((unsigned long)value & ~(SCANNED_MASK));
-	this->_next = (lub_heap_node_t *) mask;
-}
-
-/*--------------------------------------------------------- */
-lub_heap_node_t *lub_heap_node__get_next(const lub_heap_node_t * this)
-{
-	unsigned long mask = (unsigned long)this->_next & ~(SCANNED_MASK);
-	return (lub_heap_node_t *) mask;
-}
-
-/*--------------------------------------------------------- */
-bool_t lub_heap_node__get_leaked(const lub_heap_node_t * this)
-{
-	return ((unsigned long)this->
-		_context & LEAKED_MASK) ? BOOL_TRUE : BOOL_FALSE;
-}
-
-/*--------------------------------------------------------- */
-bool_t lub_heap_node__get_partial(const lub_heap_node_t * this)
-{
-	return ((unsigned long)this->
-		_context & PARTIAL_MASK) ? BOOL_TRUE : BOOL_FALSE;
-}
-
-/*--------------------------------------------------------- */
-bool_t lub_heap_node__get_scanned(const lub_heap_node_t * this)
-{
-	return ((unsigned long)this->
-		_next & SCANNED_MASK) ? BOOL_TRUE : BOOL_FALSE;
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_node__set_leaked(lub_heap_node_t * this, bool_t value)
-{
-	unsigned long mask = (unsigned long)this->_context;
-	if (BOOL_TRUE == value) {
-		mask |= LEAKED_MASK;
-	} else {
-		mask &= ~LEAKED_MASK;
-	}
-	this->_context = (lub_heap_context_t *) mask;
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_node__set_partial(lub_heap_node_t * this, bool_t value)
-{
-	unsigned long mask = (unsigned long)this->_context;
-	if (BOOL_TRUE == value) {
-		mask |= PARTIAL_MASK;
-	} else {
-		mask &= ~PARTIAL_MASK;
-	}
-	this->_context = (lub_heap_context_t *) mask;
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_node__set_scanned(lub_heap_node_t * this, bool_t value)
-{
-	unsigned long mask = (unsigned long)this->_next;
-	if (BOOL_TRUE == value) {
-		mask |= SCANNED_MASK;
-	} else {
-		mask &= ~SCANNED_MASK;
-	}
-	this->_next = (lub_heap_node_t *) mask;
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_foreach_node(void (*fn) (lub_heap_node_t *, void *), void *arg)
-{
-	lub_heap_leak_t *leak = lub_heap_leak_instance();
-	lub_heap_node_t *node;
-	lub_heap_node_key_t key;
-
-	for (node = lub_bintree_findfirst(&leak->m_node_tree);
-	     node; node = lub_bintree_findnext(&leak->m_node_tree, &key)) {
-		lub_heap_leak_release(leak);
-
-		lub_heap_node_getkey(node, (lub_bintree_key_t *) & key);
-		/* invoke the specified method on this node */
-		fn(node, arg);
-
-		leak = lub_heap_leak_instance();
-	}
-	lub_heap_leak_release(leak);
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_node_clear(lub_heap_node_t * this, void *arg)
-{
-	/* clearing a node removes it from it's context */
-	lub_heap_context_t *context = lub_heap_node__get_context(this);
-	if (NULL != context) {
-		lub_heap_leak_t *leak = lub_heap_leak_instance();
-		/* remove from the node tree and place into the clear tree */
-		lub_bintree_remove(&leak->m_node_tree, this);
-		lub_bintree_insert(&leak->m_clear_node_tree, this);
-		lub_heap_leak_release(leak);
-
-		/* maintain the leak statistics */
-		--context->allocs;
-		context->alloc_bytes -= lub_heap_node__get_size(this);
-		context->alloc_overhead -= lub_heap_node__get_overhead(this);
-
-		lub_heap_node__set_context(this, NULL);
-		lub_heap_node__set_leaked(this, BOOL_FALSE);
-		lub_heap_node__set_partial(this, BOOL_FALSE);
-
-		lub_heap_context_remove_node(context, this);
-	}
-}
-
-/*--------------------------------------------------------- */
-#define RELEASE_COUNT 2048
-void lub_heap_scan_memory(const void *mem, size_t size)
-{
-	size_t bytes_left = size;
-	typedef const void *void_ptr;
-	void_ptr *ptr, last_ptr = 0;
-	lub_heap_leak_t *leak = lub_heap_leak_instance();
-	unsigned release_count = RELEASE_COUNT;
-	if (lub_heap_leak_verbose) {
-		printf("lub_heap_scan_memory(%p,%" SIZE_FMT ")\n", mem, size);
-	}
-	++leak->m_stats.scanned;
-
-	/* scan all the words in this allocated block of memory */
-	for (ptr = (void_ptr *) mem; bytes_left;) {
-		if (0 == --release_count) {
-			/* make space for other memory tasks to get in... */
-			lub_heap_leak_release(leak);
-			leak = lub_heap_leak_instance();
-			release_count = RELEASE_COUNT;
-		}
-		if (*ptr != last_ptr) {
-			lub_heap_node_t *node;
-			lub_heap_node_key_t key;
-
-			/* search for a node */
-			key.node = (lub_heap_node_t *) ptr;
-			node = lub_bintree_find(&leak->m_node_tree, &key);
-			if (NULL != node) {
-				/*
-				 * If we stumble across a node don't scan it's contents as this could cause
-				 * false negatives. This situation could occur if an allocated block of memory
-				 * was used as a heap in it's own right.
-				 */
-				char *tmp = lub_heap_node__get_ptr(node);
-				size_t node_size =
-				    lub_heap_node__get_size(node);
-
-				/* skip forward past the node contents */
-				ptr = (void_ptr *) (tmp + node_size);
-				bytes_left -=
-				    (node_size + sizeof(lub_heap_node_t));
-				tmp = 0;	/* don't leave pointers on our stack */
-				last_ptr = 0;
-				continue;
-			}
-			/* 
-			 * see whether this is a reference to a node 
-			 * NB. we only resolve a node if the pointer lies
-			 * within the memory allocated to the client; any direct
-			 * references to nodes will not resolve to a node
-			 * object.
-			 */
-			node =
-			    _lub_heap_node_from_ptr(&leak->m_node_tree, *ptr,
-						    BOOL_FALSE);
-			if ((NULL != node)) {
-				/* this looks like a valid node */
-				lub_heap_context_t *context =
-				    lub_heap_node__get_context(node);
-				size_t node_size =
-				    lub_heap_node__get_size(node);
-				size_t node_overhead =
-				    lub_heap_node__get_overhead(node);
-				char *tmp = lub_heap_node__get_ptr(node);
-				if (tmp == *ptr) {
-					/* reference to start of block */
-					if (BOOL_TRUE ==
-					    lub_heap_node__get_partial(node)) {
-						lub_heap_node__set_partial(node,
-									   BOOL_FALSE);
-
-						if (NULL != context) {
-							--context->partials;
-							context->
-							    partial_bytes -=
-							    node_size;
-							context->
-							    partial_overhead -=
-							    node_overhead;
-						}
-					}
-				}
-				tmp = 0;	/* don't leave pointers on our stack */
-				/* this is definately not a leak */
-				if (BOOL_TRUE ==
-				    lub_heap_node__get_leaked(node)) {
-					lub_heap_node__set_leaked(node,
-								  BOOL_FALSE);
-
-					if (NULL != context) {
-						--context->leaks;
-						context->leaked_bytes -=
-						    node_size;
-						context->leaked_overhead -=
-						    node_overhead;
-
-						--leak->m_stats.leaks;
-						leak->m_stats.leaked_bytes -=
-						    node_size;
-						leak->m_stats.leaked_overhead -=
-						    node_overhead;
-					}
-				}
-			}
-		}
-		last_ptr = *ptr++;
-		bytes_left -= sizeof(void *);
-	}
-	lub_heap_leak_release(leak);
-	last_ptr = ptr = 0;	/* don't leave pointers on the stack */
-}
-
-/*--------------------------------------------------------- */

+ 0 - 100
lub/heap/node.h

@@ -1,100 +0,0 @@
-/* node.h */
-
-/**********************************************************
- * NODE CLASS DEFINTIONS
- ********************************************************** */
-
-#define LEAKED_MASK 0x00000001
-#define PARTIAL_MASK 0x00000002
-
-#define SCANNED_MASK 0x00000001
-
-struct _lub_heap_node {
-	lub_heap_context_t *_context;	/* bottom two bits used for leaked, partial flags */
-	lub_heap_node_t *_next;	/* linked list of nodes per context (bottom bit used for scanned mask) */
-	lub_heap_node_t *prev;
-	lub_bintree_node_t bt_node;
-};
-
-typedef struct _lub_heap_node_key lub_heap_node_key_t;
-struct _lub_heap_node_key {
-	const lub_heap_node_t *node;
-};
-
-/*---------------------------------------------------------
- * PUBLIC META DATA
- *--------------------------------------------------------- */
-/*
- * Get the size (in bytes) of an instance of a node object
- */
-extern size_t lub_heap_node__get_instanceSize(void);
-
-/*---------------------------------------------------------
- * PUBLIC META FUNCTIONS
- *--------------------------------------------------------- */
-extern void lub_heap_node_clear(lub_heap_node_t * instance, void *arg);
-
-extern void
-lub_heap_foreach_node(void (*fn) (lub_heap_node_t *, void *), void *arg);
-
-extern void lub_heap_scan_memory(const void *mem, size_t size);
-/*
- * Given a pointer to the start of a data area of a node obtain the
- * node reference. Returns NULL if the node is not valid. 
- */
-extern lub_heap_node_t *lub_heap_node_from_start_of_block_ptr(char *ptr);
-
-extern void lub_heap_node_initialise(void);
-
-/*---------------------------------------------------------
- * PUBLIC METHODS
- *--------------------------------------------------------- */
-/*
- * Given a node return a pointer to the data area allocated.
- */
-extern char *lub_heap_node__get_ptr(const lub_heap_node_t * instance);
-/*
- * Given a node return the size of memory that it encapsulates.
- */
-extern size_t lub_heap_node__get_size(const lub_heap_node_t * instance);
-/*
- * Given a node return the size of memory overhead that it encapsulates.
- */
-extern size_t lub_heap_node__get_overhead(const lub_heap_node_t * instance);
-/*
- * Get a node to remove itself from it's allocation tree
- */
-extern void lub_heap_node_fini(lub_heap_node_t * instance);
-
-extern void
-lub_heap_node_init(lub_heap_node_t * instance, lub_heap_context_t * context);
-
-extern lub_bintree_compare_fn lub_heap_node_compare;
-extern lub_bintree_getkey_fn lub_heap_node_getkey;
-
-extern bool_t lub_heap_node__get_leaked(const lub_heap_node_t * instance);
-
-extern bool_t lub_heap_node__get_partial(const lub_heap_node_t * instance);
-
-extern bool_t lub_heap_node__get_scanned(const lub_heap_node_t * instance);
-
-extern void lub_heap_node__set_leaked(lub_heap_node_t * instance, bool_t value);
-
-extern void
-lub_heap_node__set_partial(lub_heap_node_t * instance, bool_t value);
-
-extern void
-lub_heap_node__set_scanned(lub_heap_node_t * instance, bool_t value);
-
-extern lub_heap_context_t *lub_heap_node__get_context(const lub_heap_node_t *
-						      instance);
-
-extern void
-lub_heap_node__set_context(lub_heap_node_t * instance,
-			   lub_heap_context_t * context);
-
-extern lub_heap_node_t *lub_heap_node__get_next(const lub_heap_node_t *
-						instance);
-
-extern void
-lub_heap_node__set_next(lub_heap_node_t * instance, lub_heap_node_t * context);

+ 0 - 7
lub/heap/posix/heap_clean_stacks.c

@@ -1,7 +0,0 @@
-#include "../private.h"
-/*--------------------------------------------------------- */
-void lub_heap_clean_stacks(void)
-{
-}
-
-/*--------------------------------------------------------- */

+ 0 - 52
lub/heap/posix/heap_leak_mutex.c

@@ -1,52 +0,0 @@
-#include <pthread.h>
-#include <stdio.h>
-
-#include "../private.h"
-#include "../context.h"
-
-static pthread_mutex_t leak_mutex = PTHREAD_MUTEX_INITIALIZER;
-static lub_heap_leak_t instance;
-/*--------------------------------------------------------- */
-void lub_heap_leak_mutex_lock(void)
-{
-	int status = pthread_mutex_lock(&leak_mutex);
-	if (0 != status) {
-		perror("pthread_mutex_lock() failed");
-	}
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_leak_mutex_unlock(void)
-{
-	int status = pthread_mutex_unlock(&leak_mutex);
-	if (0 != status) {
-		perror("pthread_mutex_unlock() failed");
-	}
-}
-
-/*--------------------------------------------------------- */
-lub_heap_leak_t *lub_heap_leak_instance(void)
-{
-	lub_heap_leak_mutex_lock();
-	return &instance;
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_leak_release(lub_heap_leak_t * instance)
-{
-	lub_heap_leak_mutex_unlock();
-}
-
-/*--------------------------------------------------------- */
-bool_t lub_heap_leak_query_node_tree(void)
-{
-	return BOOL_TRUE;
-}
-
-/*--------------------------------------------------------- */
-bool_t lub_heap_leak_query_clear_node_tree(void)
-{
-	return BOOL_TRUE;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 21
lub/heap/posix/heap_scan_bss.c

@@ -1,21 +0,0 @@
-#include "../private.h"
-#include "../node.h"
-
-#ifdef __CYGWIN__
-#  define START _bss_start__
-#  define END   _bss_end__
-#else
-#  define START edata
-#  define END   end
-#endif
-
-extern char START, END;
-
-/*--------------------------------------------------------- */
-void lub_heap_scan_bss(void)
-{
-	/* now scan the memory */
-	lub_heap_scan_memory(&START, &END - &START);
-}
-
-/*--------------------------------------------------------- */

+ 0 - 24
lub/heap/posix/heap_scan_data.c

@@ -1,24 +0,0 @@
-#include "../private.h"
-#include "../node.h"
-
-#ifdef __CYGWIN__
-#  define START _data_start__
-#  define END   _data_end__
-#else
-#  define START etext
-#  define END   edata
-#endif
-
-extern char START, END;
-char *lub_heap_data_start = &START;
-char *lub_heap_data_end = &END;
-
-/*--------------------------------------------------------- */
-void lub_heap_scan_data(void)
-{
-	/* now scan the memory */
-	lub_heap_scan_memory(lub_heap_data_start,
-			     lub_heap_data_end - lub_heap_data_start);
-}
-
-/*--------------------------------------------------------- */

+ 0 - 291
lub/heap/posix/heap_symShow.c

@@ -1,291 +0,0 @@
-/* 
- * heap_symShow.c - convert addresses to line number and function name
- */
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "../private.h"
-#include "../context.h"
-
-#undef lub_heap_init		/* defined for cygwin builds */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif				/* HAVE_CONFIG_H */
-
-extern void sysheap_suppress_leak_detection(void);
-extern void sysheap_restore_leak_detection(void);
-
-#if defined(__CYGWIN__)
-/*---------------------------------------------------------
- * under CYGWIN we have the nasty behaviour that
- * argv[0] is the program name without the .exe extension
- * which is needed to load the symbol table; hence this
- * crufty hack *8-)
- *--------------------------------------------------------- */
-void cygwin_lub_heap_init(const char *file_name)
-{
-	char buffer[80];
-	sprintf(buffer, "%s.exe", file_name);
-	lub_heap_init(buffer);
-}
-
-/*--------------------------------------------------------- */
-#endif				/* __CYGWIN__ */
-
-#ifndef HAVE_LIBBFD
-/*--------------------------------------------------------- */
-/*
- * Simple vanilla dump of symbols address
- * This is automatically used unless GPL support has been
- * configured.
- */
-void lub_heap_symShow(unsigned address)
-{
-	printf(" 0x%08x", address);
-}
-
-/*--------------------------------------------------------- */
-bool_t lub_heap_symMatch(unsigned address, const char *substring)
-{
-	return BOOL_TRUE;
-}
-
-/*--------------------------------------------------------- */
-/*
- * dummy initialisation call
- */
-void lub_heap_init(const char *file_name)
-{
-	file_name = file_name;
-	lub_heap__set_framecount(MAX_BACKTRACE);
-}
-
-/*--------------------------------------------------------- */
-#else				/* HAVE_LIBBFD */
-/*
-   This file is part of the CLISH project http://clish.sourceforge.net/
-
-   The code in this file is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; version 2
-   
-   This code is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-   Derived from addr2line.c in the GNU binutils package by Ulrich.Lauther@mchp.siemens.de 
-*/
-#include "bfd.h"
-
-/*--------------------------------------------------------- */
-/* These global variables are used to pass information between
-   translate_addresses and find_address_in_section.  */
-/*--------------------------------------------------------- */
-typedef struct {
-	bfd_vma pc;
-	asymbol **syms;
-	const char *file_name;
-	const char *fn_name;
-	unsigned int line_num;
-	bfd_boolean found;
-} info_t;
-/*--------------------------------------------------------- */
-typedef struct {
-	bfd *abfd;
-	asymbol **syms;		/* Symbol table.  */
-} lub_heap_posix_t;
-/*--------------------------------------------------------- */
-static lub_heap_posix_t my_instance;	/* instance of this class */
-
-/*--------------------------------------------------------- */
-/* Look for an address in a section.  This is called via
-   bfd_map_over_sections.  */
-/*--------------------------------------------------------- */
-static void find_address_in_section(bfd * abfd, asection * section, void *data)
-{
-	info_t *info = data;
-	bfd_vma vma;
-	bfd_size_type size;
-
-	if (info->found)
-		return;
-
-	if ((bfd_get_section_flags(abfd, section) & SEC_ALLOC) == 0)
-		return;
-
-	vma = bfd_get_section_vma(abfd, section);
-	if (info->pc < vma)
-		return;
-
-	size = bfd_get_section_size(section);
-	if (info->pc >= vma + size)
-		return;
-
-	info->found = bfd_find_nearest_line(abfd,
-					    section,
-					    info->syms,
-					    info->pc - vma,
-					    &info->file_name,
-					    &info->fn_name, &info->line_num);
-	if (!info->line_num || !info->file_name) {
-		info->found = 0;
-	}
-	if (info->found) {
-		const char *last_file_name;
-		const char *last_fn_name;
-		unsigned last_line_num;
-
-		bfd_find_nearest_line(abfd,
-				      section,
-				      info->syms,
-				      vma + size - 1,
-				      &last_file_name,
-				      &last_fn_name, &last_line_num);
-		if ((last_file_name == info->file_name)
-		    && (last_fn_name == info->fn_name)
-		    && (last_line_num == info->line_num)) {
-			info->found = FALSE;
-		}
-	}
-	if (info->found) {
-		/* strip to the basename */
-		char *p;
-
-		p = strrchr(info->file_name, '/');
-		if (NULL != p) {
-			info->file_name = p + 1;
-		}
-	}
-}
-
-/*--------------------------------------------------------- */
-static void lub_heap_posix_fini(void)
-{
-	lub_heap_posix_t *this = &my_instance;
-	if (this->syms != NULL) {
-		free(this->syms);
-		this->syms = NULL;
-	}
-
-	if (this->abfd) {
-		bfd_close(this->abfd);
-	}
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_init(const char *file_name)
-{
-	lub_heap_posix_t *this = &my_instance;
-
-	/* remember to cleanup */
-	atexit(lub_heap_posix_fini);
-
-	/* switch on leak detection */
-	lub_heap__set_framecount(MAX_BACKTRACE);
-
-	sysheap_suppress_leak_detection();
-
-	bfd_init();
-
-	this->syms = NULL;
-	this->abfd = bfd_openr(file_name, "pe-i386");
-	if (this->abfd) {
-		if (bfd_check_format_matches(this->abfd, bfd_object, NULL)) {
-			unsigned int size;
-			long symcount = 0;
-
-			if (!(bfd_get_file_flags(this->abfd) & HAS_SYMS) == 0) {
-				/* Read in the symbol table.  */
-				symcount = bfd_read_minisymbols(this->abfd,
-								FALSE,
-								(void *)&this->
-								syms, &size);
-				if (0 == symcount) {
-					/* try reading dynamic symbols */
-					symcount =
-					    bfd_read_minisymbols(this->abfd,
-								 TRUE
-								 /* dynamic */ ,
-								 (void *)&this->
-								 syms, &size);
-				}
-			}
-			if (0 == symcount) {
-				fprintf(stderr,
-					"*** no symbols found in '%s'\n",
-					bfd_get_filename(this->abfd));
-			}
-		}
-	}
-	sysheap_restore_leak_detection();
-}
-
-/*--------------------------------------------------------- */
-static void
-_lub_heap_symGetInfo(lub_heap_posix_t * this, unsigned address, info_t * info)
-{
-	info->pc = address;
-	info->syms = this->syms;
-	info->fn_name = NULL;
-	info->file_name = NULL;
-	info->line_num = 0;
-	info->found = FALSE;
-
-	sysheap_suppress_leak_detection();
-	if (NULL != this->abfd) {
-
-		bfd_map_over_sections(this->abfd,
-				      find_address_in_section, info);
-	}
-	sysheap_restore_leak_detection();
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_symShow(unsigned address)
-{
-	lub_heap_posix_t *this = &my_instance;
-	info_t info;
-
-	_lub_heap_symGetInfo(this, address, &info);
-
-	if (!info.found) {
-		if (this->abfd && this->syms) {
-			/* a line with the function names */
-			printf("%26s", "");
-		}
-		printf(" 0x%08x", address);
-		if (!this->abfd) {
-			/* aline with the function names */
-			printf(" - lub_heap_init() not called.");
-		}
-	} else {
-		printf(" %20s:%-4d", info.file_name, info.line_num);
-		printf(" %s()", info.fn_name);
-	}
-}
-
-/*--------------------------------------------------------- */
-bool_t lub_heap_symMatch(unsigned address, const char *substring)
-{
-	lub_heap_posix_t *this = &my_instance;
-	info_t info;
-	bool_t result = BOOL_FALSE;
-	_lub_heap_symGetInfo(this, address, &info);
-
-	if (info.found) {
-		if (strstr(info.fn_name, substring)) {
-			result = TRUE;
-		}
-	}
-	return result;
-}
-
-/*--------------------------------------------------------- */
-#endif				/* HAVE_LIBBFD */

+ 0 - 8
lub/heap/posix/module.am

@@ -1,8 +0,0 @@
-if LUBHEAP
-  liblub_la_SOURCES +=  lub/heap/posix/heap_clean_stacks.c  \
-                        lub/heap/posix/heap_leak_mutex.c    \
-                        lub/heap/posix/heap_scan_bss.c      \
-                        lub/heap/posix/heap_scan_data.c     \
-                        lub/heap/posix/heap_symShow.c       \
-                        lub/heap/posix/sysheap_stubs.c
-endif

+ 0 - 17
lub/heap/posix/sysheap_stubs.c

@@ -1,17 +0,0 @@
-/*
- * a couple of dummy function to aid linkage when the 
- * lubheap POSIX library is not linked in.
- */
-/*--------------------------------------------------------- */
-void sysheap_suppress_leak_detection(void)
-{
-	/* dummy function */
-}
-
-/*--------------------------------------------------------- */
-void sysheap_restore_leak_detection(void)
-{
-	/* dummy function */
-}
-
-/*--------------------------------------------------------- */

+ 0 - 451
lub/heap/private.h

@@ -1,451 +0,0 @@
-/*
- * private.h
- */
-#include "lub/heap.h"
-#include "lub/bintree.h"
-#include "lub/types.h"
-#include "lub/dblockpool.h"
-#include "lub/size_fmt.h"
-
-/**********************************************************
- * PRIVATE TYPES
- ********************************************************** */
-typedef struct _lub_heap_node lub_heap_node_t;
-typedef struct _lub_heap_context lub_heap_context_t;
-typedef struct _lub_heap_cache lub_heap_cache_t;
-
-typedef enum {
-	LUB_HEAP_TAINT_INITIAL = 0xBB,
-	LUB_HEAP_TAINT_FREE = 0xFF,
-	LUB_HEAP_TAINT_ALLOC = 0xAA
-} lub_heap_taint_t;
-
-typedef struct _lub_heap_stackframe stackframe_t;
-
-/**********************************************************
- * PRIVATE TYPES
- ********************************************************** */
-/* type to indicate the number of long words in a block */
-typedef unsigned long words_t;
-typedef struct lub_heap_tag_s lub_heap_tag_t;
-typedef struct lub_heap_segment_s lub_heap_segment_t;
-typedef union lub_heap_block_u lub_heap_block_t;
-typedef struct lub_heap_alloc_block_s lub_heap_alloc_block_t;
-
-/*
- * a special type which hold both a size and block type
- */
-struct lub_heap_tag_s {
-	unsigned free:1;	/* indicates whether free/alloc block */
-	unsigned segment:1;	/* indicates boundary of segment */
-	unsigned words:30;	/* number of 4 byte words in block */
-};
-
-typedef struct lub_heap_key_s lub_heap_key_t;
-struct lub_heap_key_s {
-	words_t words;
-	const lub_heap_free_block_t *block;
-};
-/*
- * A specialisation of a generic block to hold free block information
- */
-struct lub_heap_free_block_s {
-	lub_heap_tag_t tag;
-	/*
-	 * node to hold this block in the size based binary tree 
-	 */
-	lub_bintree_node_t bt_node;
-	/* space holder for the trailing tag */
-	lub_heap_tag_t _tail;
-};
-
-/*
- * A specialisation of a generic block to hold free block information
- */
-struct lub_heap_alloc_block_s {
-	lub_heap_tag_t tag;
-	/* space holder for trailing tag */
-	lub_heap_tag_t memory[1];
-};
-
-/* a generic block instance */
-union lub_heap_block_u {
-	lub_heap_alloc_block_t alloc;
-	lub_heap_free_block_t free;
-};
-
-/* 
- * This is the control block for a segment
- */
-struct lub_heap_segment_s {
-	lub_heap_segment_t *next;
-	words_t words;
-	lub_bintree_node_t bt_node;
-};
-
-/*
- * This is the control block assigned to represent the heap instance
- */
-struct lub_heap_s {
-	/*
-	 * A cache control block if one exists
-	 */
-	lub_heap_cache_t *cache;
-	/*
-	 * A binary tree of free blocks 
-	 */
-	lub_bintree_t free_tree;
-	/*
-	 * This is used to supress leak tracking
-	 */
-	unsigned long suppress;
-	/* 
-	 * statistics for this heap 
-	 */
-	lub_heap_stats_t stats;
-	/*
-	 * reference to next heap in the system
-	 */
-	struct lub_heap_s *next;
-	/* 
-	 * reference to next segment (this must be last in the structure)
-	 */
-	lub_heap_segment_t first_segment;
-};
-
-/*---------------------------------------------------------
- * PRIVATE META DATA
- *--------------------------------------------------------- */
-/*
- * a pointer to the start of data segment
- */
-extern char *lub_heap_data_start;
-/*
- * a pointer to the end of data segment
- */
-extern char *lub_heap_data_end;
-
-/*---------------------------------------------------------
- * PRIVATE META FUNCTIONS
- *--------------------------------------------------------- */
-/*
- * This operation sends to STDOUT the textual representation
- * of the provided address in memory.
- */
-extern void lub_heap_symShow(
-				    /*
-				     * The address of the function name to resolve
-				     */
-				    unsigned address);
-/*
- * This operation indicates whether the function represented by the
- * specified address contains the specified string.
- */
-extern bool_t lub_heap_symMatch(
-				       /*
-				        * The address of the function name to resolve
-				        */
-				       unsigned address,
-				       /*
-				        * The substring to match against
-				        */
-				       const char *substring);
-/*
- * This operation fills out the current stackframe
- */
-extern void lub_heap__get_stackframe(stackframe_t * stack, unsigned max);
-/*
- * A platform implementation should scan the BSS section
- * for any memory references.
- */
-extern void lub_heap_scan_bss(void);
-/*
- * A platform implementation should scan the DATA section
- * for any memory references.
- */
-extern void lub_heap_scan_data(void);
-/*
- * If possible a platform implementation should scan the current
- * stack for any memory references.
- * NB. if a platform happens to have allocated it stack from the 
- * BSS or DATA section then this doesn't need to do anything.
- */
-extern void lub_heap_scan_stack(void);
-/*
- * This function fills out the specified memory with tainted
- * bytes if tainting is enabled for the system.
- */
-extern void lub_heap_taint_memory(
-					 /*
-					  * a pointer to the start of the memory to taint
-					  */
-					 char *ptr,
-					 /*
-					  * the type of tainting to perform
-					  */
-					 lub_heap_taint_t type,
-					 /*
-					  * the number of bytes to taint
-					  */
-					 size_t size);
-/*
- * If possible a platform implementation should
- * take this oportunity to write the value 0xCC 
- * to all the stacks between the high water mark 
- * and the current stack pointer.
- * This prevents any pointer droppings from hiding
- * memory leaks.
- */
-extern void lub_heap_clean_stacks(void);
-
-/*---------------------------------------------------------
- * PRIVATE METHODS
- *--------------------------------------------------------- */
-/*
- * This operation is the raw interface for allocating/releasing memory
- * to/from the dynamic heap. Memory allocated by this call will not be
- * monitored by the leak detection code.
- *
- * It changes the size of the object referenced by a passed in 
- * pointer to "size". The contents will be unchanged up to the minimum of the old 
- * and new sizes. If the new size is larger, the new space is uninitialised.
- *
- * \pre
- * - The heap needs to have been created with an initial memory segment.
- * - If "*ptr" contains a non-NULL value then this MUST have 
- *   been allocated using this operation, from the same heap instance.
- *
- * \return 
- * - the status of the operation.
- *
- * \post
- * - The client takes responsiblity for releasing any allocated memory when they
- *   are finished with it.
- * - If *ptr contains a non-NULL value, then after a succesfull call, the 
- *   initial memory referenced by it may have been released for reuse,
- *   and the pointer modified to reference some new memory.
- * - *ptr may contain NULL in which case no memory will be released back to the
- *   heap for reuse, and the pointer is filled out with the allocated memory.
- * - (size == 0) No new memory will be allocated, *ptr will be set to NULL,
- *   and any original memory referenced by it will have been released.
- */
-extern lub_heap_status_t lub_heap_raw_realloc(
-						     /*
-						      * The heap instance.
-						      */
-						     lub_heap_t * instance,
-						     /*
-						      * A reference to the client pointer which was previously handed out.
-						      */
-						     char **ptr,
-						     /*
-						      * The size of the requested memory
-						      */
-						     size_t size,
-						     /*
-						      * The alignment of the requested memory
-						      */
-						     lub_heap_align_t
-						     alignment);
-/*
- * This is called before an actual realloc operation runs.
- * It provides the opportunity for the leak detector to release
- * any previous details and to modify the size and pointer to account
- * for its internal overheads.
- *
- * \return 
- * The number of bytes which should be allocated by the realloc call.
- *
- * \post
- * - the 'node' currently held in the database will be removed, potentially 
- *   deleting the 'context' in the process.
- * - the leak_detector will note the fact that it is wrapping a realloc
- *   call and any further calls which are invoked during the process will 
- *   NOT be monitored.
- */
-extern void lub_heap_pre_realloc(
-					/*
-					 * The heap instance.
-					 */
-					lub_heap_t * instance,
-					/*
-					 * A reference to the client pointer which was previously handed out.
-					 */
-					char **ptr,
-					/*
-					 * A reference to the size of the requested memory
-					 */
-					size_t * size);
-/*
- * This is called after a realloc has been done, just before the results
- * are returned to the client. 
- * It provides the opportunity for the leak detector to store details 
- * on the allocation and track it.
- *
- * \return 
- * The pointer which should be returned to the client. This will skip any
- * housekeeping details which will have been added to the start of the
- * block.
- *
- * \post
- * - the 'node' currently will be added into the database, creating a
- *   context if appropriate.
- * - the leak_detector will note the fact that the wrapping of a realloc()
- *   call has completed and will start to monitor further calls again.
- */
-extern void lub_heap_post_realloc(
-					 /*
-					  * The heap instance
-					  */
-					 lub_heap_t * instance,
-					 /*
-					  * A reference to the client pointer which has been allocated.
-					  */
-					 char **ptr);
-/*
- * This function clears all the current leak information from the heap
- *
- * It is also used to define the number of stack frames which are 
- * used to specify a context.
- *
- */
-void lub_heap_clearAll(
-			      /*
-			       * The heap instance 
-			       */
-			      lub_heap_t * instance,
-			      /*
-			       * The number of stack frames to account for when evaluating
-			       * a context. A value of zero means "don't change"
-			       */
-			      unsigned frames);
-/*
- * This allows the tracking of allocation failures.
- */
-void lub_heap_alloc_failed(lub_heap_context_t * instance);
-
-/*
- * This allows the tracking of free failures.
- */
-void lub_heap_free_failed(void);
-
-/*
- * This method slices the specified number of words off the
- * bottom of the specified free block.
- * The original block is then shrunk appropriately and the 
- * address of the new free block updated accordingly.
- * The result returned is a pointer to the requested memory.
- * If the slice cannot be taken then NULL is returned and the
- * free block is unaltered.
- *
- * It is assumed that the free block has been removed from the
- * tree prior to calling this method.
- */
-extern void *lub_heap_slice_from_bottom(lub_heap_t * instance,
-					lub_heap_free_block_t ** ptr_block,
-					words_t * words, bool_t seg_start);
-/* 
- * This method slices the specified number of words off the
- * top of the current free block.
- * The block is then shrunk appropriately and the assigned memory
- * is returned. The client's free block pointer is updated accordingly
- * e.g. if the request absorbs all of the free_block the client's 
- * pointer is set to NULL.
- * If there is insufficient space to slice this free block then
- * NULL is returned and the free block is unaltered.
- */
-extern void *lub_heap_slice_from_top(lub_heap_t * instance,
-				     lub_heap_free_block_t ** ptr_block,
-				     words_t * words, bool_t seg_end);
-/*
- * This method initialises a free block from some specified memory.
- */
-extern void
-lub_heap_init_free_block(lub_heap_t * instance,
-			 void *ptr,
-			 size_t size, bool_t seg_start, bool_t seg_end);
-/* 
- * This method takes an existing allocated block and extends it by 
- * trying to take memory from a free block immediately 
- * above it
- */
-extern bool_t
-lub_heap_extend_upwards(lub_heap_t * instance,
-			lub_heap_block_t ** block, words_t words);
-/* 
- * This method takes an existing allocated block and extends it by 
- * trying to take memory from a free block immediately 
- * below it
- */
-extern bool_t
-lub_heap_extend_downwards(lub_heap_t * instance,
-			  lub_heap_block_t ** block, words_t words);
-/* 
- * This method takes an existing allocated block and extends it by 
- * trying to take memory from free blocks immediately 
- * above and below it.
- */
-extern bool_t
-lub_heap_extend_both_ways(lub_heap_t * instance,
-			  lub_heap_block_t ** block, words_t words);
-/*
- * This method creates a new alloc block from the specified heap
- */
-extern void *lub_heap_new_alloc_block(lub_heap_t * instance, words_t words);
-extern void
-lub_heap_graft_to_top(lub_heap_t * instance,
-		      lub_heap_block_t * free_block,
-		      void *ptr,
-		      words_t words, bool_t seg_end, bool_t other_free_block);
-extern void
-lub_heap_graft_to_bottom(lub_heap_t * instance,
-			 lub_heap_block_t * free_block,
-			 void *ptr,
-			 words_t words,
-			 bool_t seg_start, bool_t other_free_block);
-extern lub_heap_status_t
-lub_heap_merge_with_next(lub_heap_t * instance, lub_heap_block_t * block);
-extern lub_heap_status_t
-lub_heap_merge_with_previous(lub_heap_t * instance, lub_heap_block_t * block);
-extern lub_heap_status_t
-lub_heap_new_free_block(lub_heap_t * instance, lub_heap_block_t * block);
-/* 
- * Given a block reference find the trailing tag
- */
-extern lub_heap_tag_t *lub_heap_block__get_tail(lub_heap_block_t * block);
-
-/*
- * Find the first block reference in the specified segment
- */
-lub_heap_block_t *lub_heap_block_getfirst(const lub_heap_segment_t * seg);
-/* 
- * Given a block reference find the next one
- */
-extern lub_heap_block_t *lub_heap_block_getnext(lub_heap_block_t * block);
-/* 
- * Given a block reference find the previous one
- */
-extern lub_heap_block_t *lub_heap_block_getprevious(lub_heap_block_t * block);
-/* 
- * This checks the integrity of the current block
- * If the header and trailer values are different then
- * some form of memory corruption must have occured.
- */
-extern bool_t lub_heap_block_check(lub_heap_block_t * block);
-
-extern void
-lub_heap_block_getkey(const void *clientnode, lub_bintree_key_t * key);
-extern void lub_heap_scan_all(void);
-
-extern bool_t lub_heap_check_memory(lub_heap_t * instance);
-
-extern lub_heap_block_t *lub_heap_block_from_ptr(char *ptr);
-
-extern const lub_heap_segment_t *lub_heap_segment_findnext(const void *address);
-
-extern void
-lub_heap_align_block(lub_heap_t * this,
-		     lub_heap_align_t alignment, char **ptr, size_t * size);
-lub_heap_status_t
-lub_heap_cache_realloc(lub_heap_t * this, char **ptr, size_t requested_size);
-void lub_heap_cache_show(lub_heap_cache_t * this);

+ 0 - 48
lub/heap/vxworks/heap_clean_stacks.c

@@ -1,48 +0,0 @@
-#include <string.h>
-
-#include <taskLib.h>
-
-#include "../private.h"
-
-#define MAX_TASKS 1024
-
-/* 
- * We use global variables to avoid having anything from this
- * procedure on the stack as we are clearing it!!!
- * We are task locked so these shouldn't get corrupted 
- */
-
-static int id_list[MAX_TASKS];
-static int i, num_tasks;
-static TASK_DESC info;
-static char *p;
-static unsigned delta;
-
-/*--------------------------------------------------------- */
-void lub_heap_clean_stacks(void)
-{
-	/* disable task switching */
-	taskLock();
-
-	num_tasks = taskIdListGet(id_list, MAX_TASKS);
-
-	/* deschedule to ensure that the current task stack details are upto date */
-	taskDelay(1);
-
-	/* iterate round the tasks in the system */
-	for (i = 0; i < num_tasks; i++) {
-		if (OK == taskInfoGet(id_list[i], &info)) {
-			p = info.td_pStackBase - info.td_stackHigh;
-			delta = info.td_stackHigh - info.td_stackCurrent;
-			/* now clean the stack */
-			for (; delta--; p++) {
-				*p = 0xCC;
-			}
-		}
-	}
-
-	/* reenable task switching */
-	taskUnlock();
-}
-
-/*--------------------------------------------------------- */

+ 0 - 34
lub/heap/vxworks/heap_leak_mutex.c

@@ -1,34 +0,0 @@
-#include <semLib.h>
-#include <private/semLibP.h>
-
-#include "../private.h"
-#include "../context.h"
-
-static SEMAPHORE leak_sem;
-
-/*--------------------------------------------------------- */
-static void meta_init(void)
-{
-	static bool_t initialised = BOOL_FALSE;
-	if (BOOL_FALSE == initialised) {
-		initialised = BOOL_TRUE;
-		/* initialise the semaphore for the partition */
-		semMInit(&leak_sem,
-			 SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE);
-	}
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_leak_mutex_lock(void)
-{
-	meta_init();
-	semTake(&leak_sem, WAIT_FOREVER);
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_leak_mutex_unlock(void)
-{
-	semGive(&leak_sem);
-}
-
-/*--------------------------------------------------------- */

+ 0 - 21
lub/heap/vxworks/heap_scan_bss.c

@@ -1,21 +0,0 @@
-#include "../private.h"
-#include "../node.h"
-
-#ifdef TARGET_SIMNT
-#  define START _bss_start__
-#  define END   _bss_end__
-#else
-#  define START wrs_kernel_bss_start
-#  define END   wrs_kernel_bss_end
-#endif
-
-extern char START, END;
-
-/*--------------------------------------------------------- */
-void lub_heap_scan_bss(void)
-{
-	/* now scan the memory */
-	lub_heap_scan_memory(&START, &END - &START);
-}
-
-/*--------------------------------------------------------- */

+ 0 - 24
lub/heap/vxworks/heap_scan_data.c

@@ -1,24 +0,0 @@
-#include "../private.h"
-#include "../node.h"
-
-#ifdef TARGET_SIMNT
-#  define START _data_start__
-#  define END   _data_end__
-#else
-#  define START wrs_kernel_data_start
-#  define END   wrs_kernel_data_end
-#endif
-
-extern char START, END;
-char *lub_heap_data_start = &START;
-char *lub_heap_data_end = &END;
-
-/*--------------------------------------------------------- */
-void lub_heap_scan_data(void)
-{
-	/* now scan the memory */
-	lub_heap_scan_memory(lub_heap_data_start,
-			     lub_heap_data_end - lub_heap_data_start);
-}
-
-/*--------------------------------------------------------- */

+ 0 - 135
lub/heap/vxworks/heap_symShow.c

@@ -1,135 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <symLib.h>
-#include <sysSymTbl.h>
-#include <taskLib.h>
-
-#include "../private.h"
-#include "../context.h"
-
-/*--------------------------------------------------------- */
-/* VxWorks version of this doesn't use the program_name */
-void lub_heap_init(const char *program_name)
-{
-	program_name = program_name;
-
-	/* switch on leak detection */
-	lub_heap__set_framecount(MAX_BACKTRACE);
-}
-
-/*--------------------------------------------------------- */
-void lub_heap_symShow(unsigned address)
-{
-	int value;
-	char *name;
-	SYM_TYPE type;
-
-	if (OK == symByValueFind(sysSymTbl, address, &name, &value, &type)) {
-		printf(" %s+%d", name, address - value);
-		free(name);
-	} else {
-		printf("UNKNOWN @ %p", (void *)address);
-	}
-}
-
-/*--------------------------------------------------------- */
-bool_t lub_heap_symMatch(unsigned address, const char *substring)
-{
-	bool_t result = BOOL_FALSE;
-	int value;
-	char *name;
-	SYM_TYPE type;
-
-	if (OK == symByValueFind(sysSymTbl, address, &name, &value, &type)) {
-		if (strstr(name, substring)) {
-			result = TRUE;
-		}
-		free(name);
-	}
-	return result;
-}
-
-/*--------------------------------------------------------- */
-int leakEnable(unsigned frame_count)
-{
-	taskLock();
-
-	lub_heap__set_framecount(frame_count ? frame_count : MAX_BACKTRACE);
-
-	taskUnlock();
-
-	return 0;
-}
-
-/*--------------------------------------------------------- */
-int leakDisable(void)
-{
-	taskLock();
-
-	lub_heap__set_framecount(0);
-
-	taskUnlock();
-
-	return 0;
-}
-
-/*--------------------------------------------------------- */
-int leakShow(unsigned how, const char *substring)
-{
-	/* let's go low priority for this... */
-	int old_priority = taskPriorityGet(taskIdSelf(), &old_priority);
-
-	taskPrioritySet(taskIdSelf(), 254);
-	lub_heap_leak_report(how, substring);
-	taskPrioritySet(taskIdSelf(), old_priority);
-
-	return 0;
-}
-
-/*--------------------------------------------------------- */
-int leakScan(unsigned how, const char *substring)
-{
-	/* let's go low priority for this... */
-	int old_priority = taskPriorityGet(taskIdSelf(), &old_priority);
-
-	taskPrioritySet(taskIdSelf(), 254);
-	lub_heap_leak_scan();
-	lub_heap_leak_report(how, substring);
-	taskPrioritySet(taskIdSelf(), old_priority);
-
-	return 0;
-}
-
-/*--------------------------------------------------------- */
-int leakHelp(void)
-{
-	printf("The following commands can be used for leak detection:\n\n");
-	printf
-	    ("  leakHelp                    - Display this command summary.\n\n");
-	printf
-	    ("  leakEnable [frame_count]    - Enable leak detection collecting the \n"
-	     "                                specified number of stack frames.\n\n");
-	printf
-	    ("  leakDisable                 - Disable leak detection, clearing out \n"
-	     "                                any currently monitored allocations\n\n");
-	printf
-	    ("  leakScan [how] [,substring] - Scan and show memory leak details.\n"
-	     "                                'how' can be 0 - leaks only [default]\n"
-	     "                                             1 - leaks and partials\n"
-	     "                                             2 - all monitored allocations\n\n"
-	     "                                'substring' can be specified to only display contexts\n"
-	     "                                            which contain the string in their backtrace\n\n");
-	printf
-	    ("  leakShow [how] [,substring] - Display details for currently monitored allocations.\n"
-	     "                                Leak information will be as per the last scan performed.\n\n");
-	printf
-	    ("A 'leak' occurs when there is no reference to any of the memory\n"
-	     "within an allocated block.\n\n"
-	     "A 'partial' leak occurs when there is no reference to the start of\n"
-	     "an allocated block of memory.\n\n");
-	return 0;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 6
lub/heap/vxworks/module.am

@@ -1,6 +0,0 @@
-EXTRA_DIST  +=                                       \
-            lub/heap/vxworks/heap_clean_stacks.c     \
-            lub/heap/vxworks/heap_leak_mutex.c       \
-            lub/heap/vxworks/heap_scan_bss.c         \
-            lub/heap/vxworks/heap_scan_data.c        \
-            lub/heap/vxworks/heap_symShow.c

+ 0 - 15
lub/module.am

@@ -7,16 +7,10 @@ nobase_include_HEADERS += \
     lub/argv.h \
     lub/bintree.h \
     lub/list.h \
-    lub/blockpool.h \
     lub/ctype.h \
-    lub/dblockpool.h \
     lub/c_decl.h \
     lub/dump.h \
-    lub/heap.h \
-    lub/partition.h \
     lub/string.h \
-    lub/size_fmt.h \
-    lub/test.h \
     lub/types.h \
     lub/system.h \
     lub/db.h
@@ -25,13 +19,9 @@ EXTRA_DIST +=   \
     lub/argv/module.am \
     lub/bintree/module.am \
     lub/list/module.am \
-    lub/blockpool/module.am \
     lub/ctype/module.am \
-    lub/dblockpool/module.am \
     lub/dump/module.am \
-    lub/heap/module.am \
     lub/string/module.am \
-    lub/test/module.am \
     lub/system/module.am \
     lub/db/module.am \
     lub/README
@@ -39,13 +29,8 @@ EXTRA_DIST +=   \
 include $(top_srcdir)/lub/argv/module.am
 include $(top_srcdir)/lub/bintree/module.am
 include $(top_srcdir)/lub/list/module.am
-include $(top_srcdir)/lub/blockpool/module.am
 include $(top_srcdir)/lub/ctype/module.am
-include $(top_srcdir)/lub/dblockpool/module.am
 include $(top_srcdir)/lub/dump/module.am
-include $(top_srcdir)/lub/heap/module.am
-include $(top_srcdir)/lub/partition/module.am
 include $(top_srcdir)/lub/string/module.am
-include $(top_srcdir)/lub/test/module.am
 include $(top_srcdir)/lub/system/module.am
 include $(top_srcdir)/lub/db/module.am

+ 0 - 241
lub/partition.h

@@ -1,241 +0,0 @@
-/*
- * lub_partition.c
- */
- /**
-\ingroup lub
-\defgroup lub_heap heap
-@{
-
-\brief A thread safe dynamic memory alloction system for use in a multitasking
-operating system.
-
-This is a high level client of the lub_heap component and provides the following
-additional features:
-
-\section auto_resources Automatically obtains its resources
-The client doesn't need to provide memory storage for this partition. It
-will automatically obtain this from the system pool (malloc/free etc)
-
-\section performance Multi-threading performance
-If cache details are provided then a small high performance heap, 
-just big enough to hold the cache, is created on a per thread 
-basis. This is referenced using thread specific storage within the 
-owning thread and if it is unable to satisfy the request then a
-slower mutex locked global heap is created and used instead.
-
-\section auto_extension Automatically extends itself
-- The (slower) global heap will automatically extend itself as needed.
-
-\author  Graeme McKerrell
-\date    Created On      : Wed Jun 27 14:00:00 2007
-\version UNTESTED
-*/
-#ifndef _lub_partition_h
-#define _lub_partition_h
-#include <stddef.h>
-
-#include "lub/types.h"
-#include "lub/c_decl.h"
-#include "lub/heap.h"
-
-_BEGIN_C_DECL
-/**
- * This type is used to reference an instance of a heap.
- */
-typedef struct _lub_partition lub_partition_t;
-
-/**
- * This type defines a fundamental allocation function which 
- * can be used to extend the partition as needed.
- */
-typedef void *lub_partition_sysalloc_fn(size_t required);
-/**
- * This type is used to specify any local requirements
- */
-typedef struct _lub_partition_spec lub_partition_spec_t;
-struct _lub_partition_spec {
-    /**
-     * Indicates whether or not to use a thread specific heap will be created
-     * for each client of the partition.
-     */
-	bool_t use_local_heap;
-    /**
-     * The maximum block size for the local heap.
-     */
-	lub_heap_align_t max_local_block_size;
-    /**
-     * The number of maximum sized blocks to make available.
-     *
-     * If this is non zero then a local heap containing a cache with
-     * (num_max_block * max_block_size) size buckets will be created
-     *
-     * If this is zero then a local heap of size max_block_size
-     * will be created (without a cache)
-     */
-	size_t num_local_max_blocks;
-    /**
-     * When the partition grows each new segment will be at least this many bytes in size
-     */
-	size_t min_segment_size;
-    /**
-     * The limit in total bytes which can be allocated from the malloc hook
-     * for the growth of this partition
-     */
-	size_t memory_limit;
-    /**
-     * If non-NULL then this pointer references the fundamental memory allocation
-     * function which should be used to extend the partition.
-     * If NULL then the standard 'malloc' function will be used. 
-     */
-	lub_partition_sysalloc_fn *sysalloc;
-};
-
-/**
-  * This operation creates a partition
-  *
-  * \pre
-  * - The system pool needs to be accessible
-  *
-  * \return
-  * - a reference to a partition object which can be used to allocate
-  *   memory
-  *
-  * \post
-  * - memory allocations can be invoked on the returned intance.
-  */
-lub_partition_t *lub_partition_create(
-	/**
-         * This is used to specify the details to be used for 
-         * the partition.
-         */
-					     const lub_partition_spec_t * spec);
-/**
-  * This operation starts the process of killing a partition.
-  *
-  * \pre
- * - The partition needs to have been created.
-  *
-  * \return
-  * - none
-  *
-  * \post
-  * - The partition will no longer hand out memory.
-  * - When the final outstanding piece of memory is handed back
-  *   the partition will destroy itself.
-  * - Upon final destruction any resources obtained from the
-  *   system pool will be returned.
-  */
-void lub_partition_kill(
-	/**
-         * The heap instance on which to operate
-         */
-			       lub_partition_t * instance);
-/**
- * This operation changes the size of the object referenced by a passed in 
- * pointer to "size". The contents will be unchanged up to the minimum of the old 
- * and new sizes. If the new size is larger, the new space is uninitialised.
- *
- * \pre
- * - The partition needs to have been created.
- * - If "*ptr" contains a non-NULL value then this MUST have 
- *   been allocated using this operation, from the same heap instance.
- *
- * \return 
- * - the status of the operation.
- *
- * \post
- * - The client takes responsiblity for releasing any allocated memory when they
- *   are finished with it.
- * - If *ptr contains a non-NULL value, then after a succesfull call, the 
- *   initial memory referenced by it may have been released for reuse,
- *   and the pointer modified to reference some new memory.
- * - *ptr may contain NULL in which case no memory will be released back to the
- *   heap for reuse, and the pointer is filled out with the allocated memory.
- * - (size == 0) No new memory will be allocated, *ptr will be set to NULL,
- *   and any original memory referenced by it will have been released.
- */
-lub_heap_status_t lub_partition_realloc(
-	/**
-         * The partition instance on which to operate
-         */
-					       lub_partition_t * instance,
-	/**
-         * Reference to a pointer containing previously allocated memory 
-         * or NULL.
-         */
-					       char **ptr,
-	/**
-         * The number of bytes required for the object 
-         */
-					       size_t size,
-	/**
-         * The alignment required for a new allocations.
-         */
-					       lub_heap_align_t alignment);
-/**
- * This operation checks the integrety of the memory in the specified
- * partition.
- * Corruption will be spotted the first time a check is performed AFTER 
- * it has occured.
- * \pre
- * - the specified partition will have been created
- *
- * \return 
- * - BOOL_TRUE if the partition is OK
- * - BOOL_FALSE if the partition is corrupted.
- *
- * \post
- * - none
- */
-extern bool_t lub_partition_check_memory(lub_partition_t * instance);
-/**
- * This operation dumps the salient details of the specified partition to stdout
- */
-void lub_partition_show(
-	/**
-         * The instance on which to operate
-         */
-			       lub_partition_t * instance,
-	/**
-         * Whether to be verbose or not
-         */
-			       bool_t verbose);
-/**
- * This function is invoked whenever a call to lub_partition_realloc()
- * fails.
- * It is provided as a debugging aid; simple set a breakpoint to
- * stop execution of the program and any failures will be caught in context.
- */
-void lub_partition_stop_here(
-	/**
-         * The failure status of the the call to realloc
-         */
-				    lub_heap_status_t status,
-	/**
-         * The old value of the pointer passed in
-         */
-				    char *old_ptr,
-	/**
-         * The requested number of bytes
-         */
-				    size_t new_size);
-/**
- * This causes leak detection to be disabled for this partition 
- */
-void lub_partition_disable_leak_detection(
-	/**
-         * The instance on which to operate
-         */
-						 lub_partition_t * instance);
-/**
- * This causes leak detection to be enabled for this partition
- */
-void lub_partition_enable_leak_detection(
-	/**
-         * The instance on which to operate
-         */
-						lub_partition_t * instance);
-
-_END_C_DECL
-#endif				/* _lub_partition_h */
-/** @} */

+ 0 - 24
lub/partition/module.am

@@ -1,24 +0,0 @@
-if LUBHEAP
-  liblub_la_SOURCES +=  lub/partition/partition_check_memory.c           \
-                        lub/partition/partition_destroy_local_heap.c     \
-                        lub/partition/partition_disable_leak_detection.c \
-                        lub/partition/partition_enable_leak_detection.c  \
-                        lub/partition/partition_extend_memory.c          \
-                        lub/partition/partition_findcreate_local_heap.c  \
-                        lub/partition/partition_fini.c                   \
-                        lub/partition/partition_init.c                   \
-                        lub/partition/partition_realloc.c                \
-                        lub/partition/partition_segment_alloc.c          \
-                        lub/partition/partition_show.c                   \
-                        lub/partition/partition_sysalloc.c               \
-                        lub/partition/private.h
-
-endif
-
-EXTRA_DIST             +=            \
-    lub/partition/posix/module.am    \
-    lub/partition/vxworks/module.am
-
-include $(top_srcdir)/lub/partition/posix/module.am
-include $(top_srcdir)/lub/partition/vxworks/module.am
-

+ 0 - 22
lub/partition/partition_check_memory.c

@@ -1,22 +0,0 @@
-/*
- * partition_check_memory.c
- */
-#include "private.h"
-
-/*-------------------------------------------------------- */
-bool_t lub_partition_check_memory(lub_partition_t * this)
-{
-	bool_t result = BOOL_TRUE;
-	lub_heap_t *local_heap = lub_partition__get_local_heap(this);
-	if (local_heap) {
-		result = lub_heap_check_memory(local_heap);
-	}
-	if (BOOL_TRUE == result) {
-		lub_partition_lock(this);
-		result = lub_heap_check_memory(this->m_global_heap);
-		lub_partition_unlock(this);
-	}
-	return result;
-}
-
-/*-------------------------------------------------------- */

+ 0 - 19
lub/partition/partition_destroy_local_heap.c

@@ -1,19 +0,0 @@
-/*
- * partition_destroy_local_heap.c
- */
-#include <stdlib.h>
-
-#include "private.h"
-
-/*-------------------------------------------------------- */
-void
-lub_partition_destroy_local_heap(lub_partition_t * this,
-				 lub_heap_t * local_heap)
-{
-	lub_heap_destroy(local_heap);
-	/* now release the memory */
-	lub_partition_global_realloc(this, (char **)&local_heap, 0,
-				     LUB_HEAP_ALIGN_NATIVE);
-}
-
-/*-------------------------------------------------------- */

+ 0 - 19
lub/partition/partition_disable_leak_detection.c

@@ -1,19 +0,0 @@
-/*
- * partition_disable_leak_detection.c
- */
-#include "private.h"
-/*-------------------------------------------------------- */
-void lub_partition_disable_leak_detection(lub_partition_t * this)
-{
-	lub_heap_t *local_heap = lub_partition__get_local_heap(this);
-	if (local_heap) {
-		lub_heap_leak_restore_detection(local_heap);
-	}
-	if (this->m_global_heap) {
-		lub_partition_lock(this);
-		lub_heap_leak_restore_detection(this->m_global_heap);
-		lub_partition_unlock(this);
-	}
-}
-
-/*-------------------------------------------------------- */

+ 0 - 19
lub/partition/partition_enable_leak_detection.c

@@ -1,19 +0,0 @@
-/*
- * partition_enable_leak_detection.c
- */
-#include "private.h"
-/*-------------------------------------------------------- */
-void lub_partition_enable_leak_detection(lub_partition_t * this)
-{
-	lub_heap_t *local_heap = lub_partition__get_local_heap(this);
-	if (local_heap) {
-		lub_heap_leak_suppress_detection(local_heap);
-	}
-	if (this->m_global_heap) {
-		lub_partition_lock(this);
-		lub_heap_leak_suppress_detection(this->m_global_heap);
-		lub_partition_unlock(this);
-	}
-}
-
-/*-------------------------------------------------------- */

+ 0 - 20
lub/partition/partition_extend_memory.c

@@ -1,20 +0,0 @@
-/*
- * partition_extend_memory.c
- */
-#include "private.h"
-
-/*-------------------------------------------------------- */
-bool_t lub_partition_extend_memory(lub_partition_t * this, size_t required)
-{
-	bool_t result = BOOL_FALSE;
-	void *segment = lub_partition_segment_alloc(this, &required);
-	if (segment) {
-		lub_partition_lock(this);
-		lub_heap_add_segment(this->m_global_heap, segment, required);
-		lub_partition_unlock(this);
-		result = BOOL_TRUE;
-	}
-	return result;
-}
-
-/*-------------------------------------------------------- */

+ 0 - 47
lub/partition/partition_findcreate_local_heap.c

@@ -1,47 +0,0 @@
-/*
- * partition_findcreate_local_heap.c
- */
-#include "private.h"
-
-/*-------------------------------------------------------- */
-lub_heap_t *lub_partition_findcreate_local_heap(lub_partition_t * this)
-{
-	/* see whether one already exists */
-	lub_heap_t *local_heap = 0;
-	if (this->m_spec.use_local_heap) {
-		local_heap = lub_partition__get_local_heap(this);
-		if (!local_heap) {
-			size_t required;
-
-			/* work out how big the local heap will be... */
-			required =
-			    lub_heap_overhead_size(this->m_spec.
-						   max_local_block_size,
-						   this->m_spec.
-						   num_local_max_blocks);
-			/* 
-			 * create a local heap for the current thread which 
-			 * just contains a cache
-			 */
-			(void)lub_partition_global_realloc(this,
-							   (char **)&local_heap,
-							   required,
-							   LUB_HEAP_ALIGN_NATIVE);
-			if (local_heap) {
-				/* initialise the heap object */
-				lub_heap_create(local_heap, required);
-				lub_heap_cache_init(local_heap,
-						    this->m_spec.
-						    max_local_block_size,
-						    this->m_spec.
-						    num_local_max_blocks);
-
-				/* store this in the thread specific storage */
-				lub_partition__set_local_heap(this, local_heap);
-			}
-		}
-	}
-	return local_heap;
-}
-
-/*-------------------------------------------------------- */

+ 0 - 25
lub/partition/partition_fini.c

@@ -1,25 +0,0 @@
-/*
- * partition_fini.c
- */
-#include <stdlib.h>
-
-#include "private.h"
-
-/*-------------------------------------------------------- */
-void lub_partition_fini(lub_partition_t * this)
-{
-	lub_heap_t *local_heap = lub_partition__get_local_heap(this);
-
-	if (local_heap) {
-		lub_partition_destroy_local_heap(this, local_heap);
-	}
-	/*
-	 * we need to have destroyed any client threads 
-	 * before calling this function
-	 */
-	lub_partition_lock(this);
-	lub_heap_destroy(this->m_global_heap);
-	lub_partition_unlock(this);
-}
-
-/*-------------------------------------------------------- */

+ 0 - 31
lub/partition/partition_init.c

@@ -1,31 +0,0 @@
-/*
- * partition_init.c
- */
-#include <stdlib.h>
-#include <assert.h>
-
-#include "private.h"
-/*-------------------------------------------------------- */
-void lub_partition_kill(lub_partition_t * this)
-{
-	this->m_dying = BOOL_TRUE;
-	/* try and die immediately... */
-	lub_partition_time_to_die(this);
-}
-
-/*-------------------------------------------------------- */
-void
-lub_partition_init(lub_partition_t * this, const lub_partition_spec_t * spec)
-{
-	this->m_spec = *spec;
-	if (!this->m_spec.sysalloc) {
-		this->m_spec.sysalloc = malloc;
-	}
-	this->m_partition_ceiling =
-	    spec->memory_limit ? (spec->memory_limit -
-				  sizeof(lub_partition_t)) : -1;
-	this->m_dying = BOOL_FALSE;
-	this->m_global_heap = 0;	/* do this on demand */
-}
-
-/*-------------------------------------------------------- */

+ 0 - 137
lub/partition/partition_realloc.c

@@ -1,137 +0,0 @@
-/*
- * partition_realloc.c
- */
-#include <string.h>
-
-#include "private.h"
-
-/*--------------------------------------------------------- */
-void
-lub_partition_stop_here(lub_heap_status_t status,
-			char *old_ptr, size_t new_size)
-{
-	/* This is provided as a debug aid */
-	status = status;
-	old_ptr = old_ptr;
-	new_size = new_size;
-}
-
-/*--------------------------------------------------------- */
-void lub_partition_time_to_die(lub_partition_t * this)
-{
-	bool_t time_to_die = BOOL_TRUE;
-	lub_heap_stats_t stats;
-	lub_heap_t *local_heap = lub_partition__get_local_heap(this);
-	if (local_heap) {
-		lub_heap__get_stats(local_heap, &stats);
-		if (stats.alloc_blocks) {
-			time_to_die = BOOL_FALSE;
-		}
-	}
-	if (BOOL_FALSE == time_to_die) {
-		lub_partition_lock(this);
-		lub_heap__get_stats(this->m_global_heap, &stats);
-		lub_partition_unlock(this);
-		if (stats.alloc_blocks) {
-			time_to_die = BOOL_FALSE;
-		}
-	}
-	if (BOOL_TRUE == time_to_die) {
-		/* and so the time has come... */
-		lub_partition_destroy(this);
-	}
-}
-
-/*--------------------------------------------------------- */
-lub_heap_status_t
-lub_partition_global_realloc(lub_partition_t * this,
-			     char **ptr,
-			     size_t size, lub_heap_align_t alignment)
-{
-	lub_heap_status_t status = LUB_HEAP_FAILED;
-	lub_partition_lock(this);
-	if (!this->m_global_heap) {
-		/*
-		 * Create the global heap
-		 */
-		size_t required = size;
-		void *segment = lub_partition_segment_alloc(this, &required);
-		this->m_global_heap = lub_heap_create(segment, required);
-	}
-	if (this->m_global_heap) {
-		status =
-		    lub_heap_realloc(this->m_global_heap, ptr, size, alignment);
-		if (LUB_HEAP_FAILED == status) {
-			/* expand memory and try again */
-			if (lub_partition_extend_memory(this, size)) {
-				status = lub_heap_realloc(this->m_global_heap,
-							  ptr, size, alignment);
-			}
-		}
-	}
-	lub_partition_unlock(this);
-	return status;
-}
-
-/*--------------------------------------------------------- */
-lub_heap_status_t
-lub_partition_realloc(lub_partition_t * this,
-		      char **ptr, size_t size, lub_heap_align_t alignment)
-{
-	lub_heap_status_t status = LUB_HEAP_FAILED;
-	size_t requested_size = size;
-	lub_heap_t *local_heap;
-
-	if ((0 == size) && (0 == *ptr)) {
-		/* simple optimisation */
-		return LUB_HEAP_OK;
-	}
-	if (this->m_dying) {
-		local_heap = lub_partition__get_local_heap(this);
-		if (size) {
-			/* don't allocate any new memory when dying */
-			size = 0;
-		}
-	} else {
-		local_heap = lub_partition_findcreate_local_heap(this);
-	}
-	if (local_heap) {
-		/* try the fast local heap first */
-		status = lub_heap_realloc(local_heap, ptr, size, alignment);
-	}
-	if ((LUB_HEAP_FAILED == status) || (LUB_HEAP_INVALID_POINTER == status)) {
-		char *old_ptr = 0;
-
-		if (local_heap && (LUB_HEAP_FAILED == status) && size) {
-			/* we need to reallocate from the global and copy from the local */
-			old_ptr = *ptr;
-			*ptr = 0;
-		}
-		/* time to use the slower global heap */
-		status =
-		    lub_partition_global_realloc(this, ptr, size, alignment);
-		if (old_ptr && (LUB_HEAP_OK == status)) {
-			/* copy from the local to the global */
-			memcpy(*ptr, old_ptr, size);
-
-			/* and release the local block */
-			status =
-			    lub_heap_realloc(local_heap, &old_ptr, 0,
-					     alignment);
-		}
-	}
-	if (LUB_HEAP_OK != status) {
-		lub_partition_stop_here(status, *ptr, size);
-	}
-	/* allow the partion to destroy itself if necessary */
-	if (this->m_dying) {
-		lub_partition_time_to_die(this);
-		if (requested_size) {
-			/* we don't allocate memory whilst dying */
-			status = LUB_HEAP_FAILED;
-		}
-	}
-	return status;
-}
-
-/*-------------------------------------------------------- */

+ 0 - 17
lub/partition/partition_segment_alloc.c

@@ -1,17 +0,0 @@
-/*
- * partition_segment_alloc.c
- */
-#include "private.h"
-
-/*-------------------------------------------------------- */
-void *lub_partition_segment_alloc(lub_partition_t * this, size_t * required)
-{
-	if (*required < this->m_spec.min_segment_size) {
-		*required = (this->m_spec.min_segment_size >> 1);
-	}
-	/* double the required size */
-	*required <<= 1;
-	return lub_partition_sysalloc(this, *required);
-}
-
-/*-------------------------------------------------------- */

+ 0 - 40
lub/partition/partition_show.c

@@ -1,40 +0,0 @@
-/*
- * partition_show.c
- */
-#include <stdio.h>
-#include "private.h"
-
-/*-------------------------------------------------------- */
-void lub_partition_show(lub_partition_t * this, bool_t verbose)
-{
-	lub_heap_t *local_heap = lub_partition__get_local_heap(this);
-	lub_partition_lock(this);
-	if (verbose) {
-		printf("PARTITION:\n"
-		       " %p syspool usage(%" SIZE_FMT "/%" SIZE_FMT
-		       " bytes), minimum segment size(%" SIZE_FMT " bytes)\n",
-		       (void *)this,
-		       (this->m_spec.memory_limit - this->m_partition_ceiling),
-		       this->m_spec.memory_limit,
-		       this->m_spec.min_segment_size);
-	}
-	if (local_heap) {
-		if (verbose) {
-			printf
-			    ("............................................................\n");
-			printf("LOCAL ");
-		}
-		lub_heap_show(local_heap, verbose);
-	}
-	if (this->m_global_heap) {
-		if (verbose) {
-			printf
-			    ("............................................................\n");
-			printf("GLOBAL ");
-		}
-		lub_heap_show(this->m_global_heap, verbose);
-	}
-	lub_partition_unlock(this);
-}
-
-/*-------------------------------------------------------- */

+ 0 - 21
lub/partition/partition_sysalloc.c

@@ -1,21 +0,0 @@
-/*
- * partition_sysalloc.c
- */
-#include <stdlib.h>
-
-#include "private.h"
-
-/*-------------------------------------------------------- */
-void *lub_partition_sysalloc(lub_partition_t * this, size_t required)
-{
-	void *result = 0;
-	if (required < this->m_partition_ceiling) {
-		result = this->m_spec.sysalloc(required);
-		if (result) {
-			this->m_partition_ceiling -= required;
-		}
-	}
-	return result;
-}
-
-/*-------------------------------------------------------- */

+ 0 - 4
lub/partition/posix/module.am

@@ -1,4 +0,0 @@
-if LUBHEAP
-  liblub_la_SOURCES +=  lub/partition/posix/posix_partition.c  \
-                        lub/partition/posix/private.h
-endif

+ 0 - 145
lub/partition/posix/posix_partition.c

@@ -1,145 +0,0 @@
-/*
- * posix_partition.c
- */
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-#include <string.h>
-
-#include "private.h"
-
-extern void sysheap_suppress_leak_detection(void);
-extern void sysheap_restore_leak_detection(void);
-
-typedef struct _key_data key_data_t;
-struct _key_data {
-	lub_partition_t *partition;
-	lub_heap_t *local_heap;
-};
-/*-------------------------------------------------------- */
-static void lub_posix_partition_destroy_key(void *arg)
-{
-	key_data_t *key_data = arg;
-	lub_partition_destroy_local_heap(key_data->partition,
-					 key_data->local_heap);
-	lub_partition_global_realloc(key_data->partition, (char **)key_data, 0,
-				     LUB_HEAP_ALIGN_NATIVE);
-}
-
-/*-------------------------------------------------------- */
-lub_partition_t *lub_partition_create(const lub_partition_spec_t * spec)
-{
-	lub_posix_partition_t *this;
-	lub_partition_sysalloc_fn *alloc_fn = spec->sysalloc;
-	if (!alloc_fn) {
-		alloc_fn = malloc;
-	}
-	this = alloc_fn(sizeof(lub_posix_partition_t));
-	if (this) {
-		lub_posix_partition_init(this, spec);
-	}
-	return &this->m_base;
-}
-
-/*-------------------------------------------------------- */
-void
-lub_posix_partition_init(lub_posix_partition_t * this,
-			 const lub_partition_spec_t * spec)
-{
-	memset(this, sizeof(*this), 0);
-	/* initialise the base class */
-	lub_partition_init(&this->m_base, spec);
-
-	/* initialise the global mutex */
-	if (0 != pthread_mutex_init(&this->m_mutex, 0)) {
-		perror("pthread_mutex_init() failed!");
-	}
-	/* initialise the local key */
-	if (0 != pthread_key_create(&this->m_key,
-				    lub_posix_partition_destroy_key)) {
-		perror("pthread_key_create() failed!");
-	}
-}
-
-/*-------------------------------------------------------- */
-void lub_partition_destroy(lub_partition_t * instance)
-{
-	lub_posix_partition_t *this = (void *)instance;
-
-	/* finalise the base class */
-	lub_partition_fini(&this->m_base);
-
-	/* now clean up the global mutex */
-	if (0 != pthread_mutex_destroy(&this->m_mutex)) {
-		perror("pthread_mutex_destroy() failed!");
-	}
-
-	/* now clean up the local key */
-	if (0 != pthread_key_delete(this->m_key)) {
-		perror("pthread_key_delete() failed!");
-	}
-
-	free(this);
-}
-
-/*-------------------------------------------------------- */
-lub_heap_t *lub_partition__get_local_heap(lub_partition_t * instance)
-{
-	lub_heap_t *result = 0;
-	lub_posix_partition_t *this = (void *)instance;
-	key_data_t *key_data = pthread_getspecific(this->m_key);
-	if (key_data) {
-		result = key_data->local_heap;
-	}
-	return result;
-}
-
-/*-------------------------------------------------------- */
-void
-lub_partition__set_local_heap(lub_partition_t * instance, lub_heap_t * heap)
-{
-	lub_posix_partition_t *this = (void *)instance;
-	key_data_t *key_data = 0;
-
-#if defined(__CYGWIN__)
-	/* cygwin seems to leak key_data!!! so we ignore this for the time being... */
-	lub_heap_leak_suppress_detection(instance->m_global_heap);
-#endif				/* __CYGWIN__ */
-	lub_partition_global_realloc(instance, (char **)&key_data,
-				     sizeof(key_data_t), LUB_HEAP_ALIGN_NATIVE);
-#if defined(__CYGWIN__)
-	/* cygwin seems to leak key_data!!! so we ignore this for the time being... */
-	lub_heap_leak_restore_detection(instance->m_global_heap);
-#endif				/* __CYGWIN__ */
-	assert(key_data);
-	key_data->partition = instance;
-	key_data->local_heap = heap;
-	if (0 != pthread_getspecific(this->m_key)) {
-		assert(NULL == "Local heap already exists!");
-	}
-	if (0 != pthread_setspecific(this->m_key, key_data)) {
-		perror("pthread_setspecific() failed!");
-	}
-}
-
-/*-------------------------------------------------------- */
-void lub_partition_lock(lub_partition_t * instance)
-{
-	lub_posix_partition_t *this = (void *)instance;
-
-	if (0 != pthread_mutex_lock(&this->m_mutex)) {
-		perror("pthread_mutex_lock() failed!");
-	}
-}
-
-/*-------------------------------------------------------- */
-void lub_partition_unlock(lub_partition_t * instance)
-{
-	lub_posix_partition_t *this = (void *)instance;
-
-	if (0 != pthread_mutex_unlock(&this->m_mutex)) {
-		perror("pthread_mutex_unlock() failed!");
-	}
-}
-
-/*-------------------------------------------------------- */

+ 0 - 18
lub/partition/posix/private.h

@@ -1,18 +0,0 @@
-/*
- * private.h
- */
-#include <pthread.h>
-#include "../private.h"
-
-/**********************************************************
- * PRIVATE TYPES
- ********************************************************** */
-typedef struct _lub_posix_partition lub_posix_partition_t;
-struct _lub_posix_partition {
-	lub_partition_t m_base;
-	pthread_key_t m_key;
-	pthread_mutex_t m_mutex;
-};
-void
-lub_posix_partition_init(lub_posix_partition_t * instance,
-			 const lub_partition_spec_t * spec);

+ 0 - 34
lub/partition/private.h

@@ -1,34 +0,0 @@
-#include "lub/types.h"
-#include "lub/partition.h"
-#include "lub/heap.h"
-#include "lub/size_fmt.h"
-
 
struct _lub_partition 
 {
-	
lub_heap_t * m_global_heap;
-	
lub_partition_spec_t m_spec;
-	
bool_t m_dying;
-	
size_t m_partition_ceiling;
-
};
-

lub_heap_t * 
lub_partition__get_local_heap(lub_partition_t * instance);
-

void 
-lub_partition__set_local_heap(lub_partition_t * instance, 
-			      lub_heap_t * local_heap);
-

void 
 lub_partition_lock(lub_partition_t * instance);
-

void 
 lub_partition_unlock(lub_partition_t * instance);
-


lub_heap_status_t 
-lub_partition_global_realloc(lub_partition_t * instance, 
char **ptr,
-			     
size_t size, 
lub_heap_align_t alignment);
-
void *
 lub_partition_segment_alloc(lub_partition_t * instance,
-				     
 size_t * required);
-

void 
 lub_partition_destroy_local_heap(lub_partition_t * instance,
-					  
 lub_heap_t * local_heap);
-
void 
 lub_partition_time_to_die(lub_partition_t * instance);
-

bool_t 
-lub_partition_extend_memory(lub_partition_t * instance, 
size_t required);
-
void 
 lub_partition_destroy(lub_partition_t * instance);
-

lub_heap_t * 
lub_partition_findcreate_local_heap(lub_partition_t * instance);
-

void *
 lub_partition_sysalloc(lub_partition_t * instance, 
 size_t required);
-

void 
-lub_partition_init(lub_partition_t * instance, 
-		   const lub_partition_spec_t * spec);
-

void 
 lub_partition_fini(lub_partition_t * instance);
-

+ 0 - 3
lub/partition/vxworks/module.am

@@ -1,3 +0,0 @@
-EXTRA_DIST  +=                                       \
-            lub/partition/vxworks/vxworks_partition.c\
-            lub/partition/vxworks/private.h

+ 0 - 18
lub/partition/vxworks/private.h

@@ -1,18 +0,0 @@
-/*
- * private.h
- */
-#include <private/semLibP.h>
-#include <taskVarLib.h>
-
-#include "../private.h"
-
-/**********************************************************
- * PRIVATE TYPES
- ********************************************************** */
-typedef struct _lub_vxworks_partition lub_vxworks_partition_t;
-struct _lub_vxworks_partition {
-	lub_partition_t m_base;
-	lub_heap_t *m_local_heap;
-	SEMAPHORE m_sem;
-	lub_vxworks_partition_t *m_next_partition;
-};

+ 0 - 142
lub/partition/vxworks/vxworks_partition.c

@@ -1,142 +0,0 @@
-/*
- * vxworks_partition.c
- */
-#include <stdlib.h>
-#include <assert.h>
-
-#include <taskLib.h>
-#include <taskHookLib.h>
-
-#include "private.h"
-
-static lub_vxworks_partition_t *first_partition;
-
-/*-------------------------------------------------------- */
-static void lub_vxworks_partition_task_delete_hook(WIND_TCB * pTcb)
-{
-	lub_vxworks_partition_t **ptr;
-	int tid = (int)pTcb;
-
-	/* iterate the list of partitions */
-	taskLock();
-	for (ptr = &first_partition; *ptr; ptr = &(*ptr)->m_next_partition) {
-		int val = taskVarGet(tid, (int *)&(*ptr)->m_local_heap);
-		if (ERROR != val) {
-			/* destroy this local heap */
-			lub_partition_destroy_local_heap(&(*ptr)->m_base,
-							 (void *)val);
-
-			/* and remove the task variable */
-			taskVarDelete(tid, (int *)&(*ptr)->m_local_heap);
-		}
-	}
-	taskUnlock();
-}
-
-/*-------------------------------------------------------- */
-lub_partition_t *lub_partition_create(const lub_partition_spec_t * spec)
-{
-	lub_vxworks_partition_t *this;
-	this = calloc(sizeof(lub_vxworks_partition_t), 1);
-	if (this) {
-		/* initialise the global mutex */
-		if (ERROR ==
-		    semMInit(&this->m_sem,
-			     SEM_Q_PRIORITY | SEM_DELETE_SAFE |
-			     SEM_INVERSION_SAFE)) {
-			assert(NULL == "semMInit() failed!");
-		}
-
-		lub_partition_lock(&this->m_base);
-		/* initialise the local task variable system */
-		taskVarInit();
-
-		/* initialise the base class */
-		lub_partition_init(&this->m_base, spec);
-
-		/* add to the list of partitions */
-		this->m_next_partition = first_partition;
-		first_partition = this;
-
-		if (this == first_partition) {
-			/* register a task deletion hook */
-			taskDeleteHookAdd((FUNCPTR)
-					  lub_vxworks_partition_task_delete_hook);
-		}
-		lub_partition_unlock(&this->m_base);
-	}
-	return this ? &this->m_base : 0;
-}
-
-/*-------------------------------------------------------- */
-void lub_partition_destroy(lub_partition_t * instance)
-{
-	lub_vxworks_partition_t *this = (void *)instance;
-	lub_vxworks_partition_t **ptr;
-
-	/* finalise the base class */
-	lub_partition_fini(&this->m_base);
-
-	lub_partition_lock(&this->m_base);
-	/* remove from the list of partitions */
-	for (ptr = &first_partition; *ptr; ptr = &(*ptr)->m_next_partition) {
-		if (&(*ptr)->m_base == instance) {
-			/* remove from list */
-			*ptr = (*ptr)->m_next_partition;
-			break;
-		}
-	}
-	if (!first_partition) {
-		/* deregister delete hook */
-		taskDeleteHookDelete((FUNCPTR)
-				     lub_vxworks_partition_task_delete_hook);
-	}
-	lub_partition_unlock(&this->m_base);
-	free(this);
-}
-
-/*-------------------------------------------------------- */
-lub_heap_t *lub_partition__get_local_heap(lub_partition_t * instance)
-{
-	lub_vxworks_partition_t *this = (void *)instance;
-
-	return this->m_local_heap;
-}
-
-/*-------------------------------------------------------- */
-void
-lub_partition__set_local_heap(lub_partition_t * instance, lub_heap_t * heap)
-{
-	lub_vxworks_partition_t *this = (void *)instance;
-
-	if (this->m_local_heap) {
-		assert(NULL == "Local heap already exists!");
-	}
-	/* add this memory to the local task */
-	taskVarAdd(0, (int *)&this->m_local_heap);
-
-	/* add set the value */
-	this->m_local_heap = heap;
-}
-
-/*-------------------------------------------------------- */
-void lub_partition_lock(lub_partition_t * instance)
-{
-	lub_vxworks_partition_t *this = (void *)instance;
-
-	if (ERROR == semTake(&this->m_sem, WAIT_FOREVER)) {
-		assert(NULL == "semTake() failed!");
-	}
-}
-
-/*-------------------------------------------------------- */
-void lub_partition_unlock(lub_partition_t * instance)
-{
-	lub_vxworks_partition_t *this = (void *)instance;
-
-	if (ERROR == semGive(&this->m_sem)) {
-		assert(NULL == "semGive() failed!");
-	}
-}
-
-/*-------------------------------------------------------- */

Some files were not shown because too many files changed in this diff