heap.h

00001 /*
00002  * heap.h
00003  */
00108 #ifndef _lub_heap_h
00109 #define _lub_heap_h
00110 #include <stddef.h>
00111 
00112 #include "lub/types.h"
00113 #include "lub/c_decl.h"
00114 _BEGIN_C_DECL
00115 
00119 typedef struct lub_heap_s lub_heap_t;
00120 
00124 typedef struct lub_heap_free_block_s lub_heap_free_block_t;
00125 
00129 typedef struct lub_heap_stats_s lub_heap_stats_t;
00130 struct lub_heap_stats_s
00131 {
00132     /*----------------------------------------------------- */
00136     size_t segs;
00140     size_t segs_bytes;
00144     size_t segs_overhead;
00145     /*----------------------------------------------------- */
00150     size_t free_blocks;
00154     size_t free_bytes;
00158     size_t free_overhead;
00159     /*----------------------------------------------------- */
00164     size_t alloc_blocks;
00169     size_t alloc_bytes;
00173     size_t alloc_overhead;
00174     /*----------------------------------------------------- */
00179     size_t alloc_total_blocks;
00184     size_t alloc_total_bytes;
00185     /*----------------------------------------------------- */
00190     size_t alloc_hightide_blocks;
00196     size_t alloc_hightide_bytes;
00201     size_t alloc_hightide_overhead;
00206     size_t free_hightide_blocks;
00210     size_t free_hightide_bytes;
00214     size_t free_hightide_largest;
00219     size_t free_hightide_overhead;
00220     /*----------------------------------------------------- */
00225     size_t static_blocks;
00230     size_t static_bytes;    
00235     size_t static_overhead;
00236     /*----------------------------------------------------- */
00237 };
00242 typedef enum
00243 {
00247     LUB_HEAP_OK,
00251     LUB_HEAP_FAILED,
00256     LUB_HEAP_DOUBLE_FREE,
00261     LUB_HEAP_CORRUPTED,
00266     LUB_HEAP_INVALID_POINTER
00267 } lub_heap_status_t;
00268 
00269 typedef struct {void *ptr;} struct_void_ptr;
00274 typedef enum
00275 {
00280     LUB_HEAP_ALIGN_NATIVE = sizeof(struct_void_ptr),
00284     LUB_HEAP_ALIGN_4    = 0x00000004,
00288     LUB_HEAP_ALIGN_8    = 0x00000008,
00292     LUB_HEAP_ALIGN_16   = 0x00000010,
00296     LUB_HEAP_ALIGN_32   = 0x00000020,
00300     LUB_HEAP_ALIGN_64   = 0x00000040,
00304     LUB_HEAP_ALIGN_128  = 0x00000080,
00308     LUB_HEAP_ALIGN_256  = 0x00000100,
00312     LUB_HEAP_ALIGN_512  = 0x00000200,
00316     LUB_HEAP_ALIGN_1024  = 0x00000400,
00320     LUB_HEAP_ALIGN_2048  = 0x00000800,
00324     LUB_HEAP_ALIGN_4096  = 0x00001000,
00328     LUB_HEAP_ALIGN_8192  = 0x00002000,
00332     LUB_HEAP_ALIGN_16384 = 0x00004000,
00336     LUB_HEAP_ALIGN_32768 = 0x00008000
00337 } lub_heap_align_t;
00338 
00342 typedef enum
00343 {
00348     LUB_HEAP_SHOW_LEAKS,
00353     LUB_HEAP_SHOW_PARTIALS,
00357     LUB_HEAP_SHOW_ALL
00358 } lub_heap_show_e;
00359 
00364 typedef void 
00365     lub_heap_foreach_fn(
00369         void *block,
00373         unsigned index,
00377         size_t size,
00381         void *arg);
00382 
00399 void
00400     lub_heap_foreach_segment(
00404         lub_heap_t *instance,
00408         lub_heap_foreach_fn *fn,
00413         void *arg);
00430 void
00431     lub_heap_foreach_free_block(
00435         lub_heap_t *instance,
00439         lub_heap_foreach_fn *fn,
00444         void *arg);
00445 
00462 lub_heap_t *
00463     lub_heap_create(
00468         void *start,
00472         size_t size
00473     );
00490 void
00491     lub_heap_destroy(
00495         lub_heap_t *instance
00496     );
00514 void 
00515     lub_heap_add_segment(
00519         lub_heap_t *instance,
00523         void *start,
00527         size_t size
00528     );
00548 void *
00549     lub_heap_static_alloc(
00553         lub_heap_t *instance,
00557         size_t size
00558     );
00583 lub_heap_status_t
00584     lub_heap_realloc(
00588         lub_heap_t *instance,
00593         char **ptr,
00597         size_t size,
00601         lub_heap_align_t alignment
00602     );
00627 bool_t
00628     lub_heap_taint(
00632         bool_t enable
00633     );
00648 bool_t
00649     lub_heap_is_tainting(void);
00673 bool_t
00674     lub_heap_check(
00678         bool_t enable
00679     );
00680 
00695 bool_t
00696     lub_heap_is_checking(void);
00697 
00713 extern bool_t 
00714     lub_heap_check_memory(lub_heap_t *instance);
00715 
00721 void 
00722     lub_heap_stop_here(
00726         lub_heap_status_t status,
00730         char *old_ptr,
00734         size_t new_size
00735     );
00736 
00748 void
00749     lub_heap__get_stats(
00753         lub_heap_t *instance,
00757         lub_heap_stats_t *stats
00758     );
00759 
00763 void
00764     lub_heap_show(
00768         lub_heap_t *instance,
00772         bool_t verbose
00773     );
00786 size_t    
00787 lub_heap__get_max_free(
00791         lub_heap_t *instance
00792     );
00793 
00794 extern size_t
00795     lub_heap__get_block_overhead(void);
00796 
00797 extern size_t
00798     lub_heap__get_block_size(const void *ptr);
00807 void
00808     lub_heap_show_leaks(
00812         lub_heap_show_e how
00813     );
00814 
00815 void
00816     lub_heap__set_framecount(
00820         unsigned framecount
00821     );
00822 
00823 unsigned
00824     lub_heap__get_framecount(void);
00825     
00826 extern bool_t 
00827     lub_heap_validate_pointer(lub_heap_t *instance,
00828                               char       *ptr);
00835 #define LUB_HEAP_ZERO_ALLOC ((void*)-1)
00836 
00852 extern void
00853     lub_heap_init(
00858         const char *program_name
00859     );
00860 
00861 
00862 #if defined(__CYGWIN__)
00863 
00868 extern void 
00869     cygwin_lub_heap_init(const char *file_name);
00870 
00871 #define lub_heap_init(arg0) cygwin_lub_heap_init(arg0)
00872 
00873 #endif /* __CYGWIN__ */
00874 
00875 _END_C_DECL
00876 
00877 #endif /* _lub_heap_h */
00878 

Generated on Fri Oct 13 15:52:03 2006 for CLISH by  doxygen 1.4.6