00001
00002
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;
00215 size_t free_hightide_overhead;
00216
00221 size_t static_blocks;
00226 size_t static_bytes;
00231 size_t static_overhead;
00232
00233 };
00238 typedef enum
00239 {
00243 LUB_HEAP_OK,
00247 LUB_HEAP_FAILED,
00252 LUB_HEAP_DOUBLE_FREE,
00257 LUB_HEAP_CORRUPTED,
00262 LUB_HEAP_INVALID_POINTER
00263 } lub_heap_status_t;
00264
00265 typedef struct {void *ptr;} struct_void_ptr;
00270 typedef enum
00271 {
00276 LUB_HEAP_ALIGN_NATIVE = sizeof(struct_void_ptr),
00280 LUB_HEAP_ALIGN_2_POWER_2 = 0x00000004,
00284 LUB_HEAP_ALIGN_2_POWER_3 = 0x00000008,
00288 LUB_HEAP_ALIGN_2_POWER_4 = 0x00000010,
00292 LUB_HEAP_ALIGN_2_POWER_5 = 0x00000020,
00296 LUB_HEAP_ALIGN_2_POWER_6 = 0x00000040,
00300 LUB_HEAP_ALIGN_2_POWER_7 = 0x00000080,
00304 LUB_HEAP_ALIGN_2_POWER_8 = 0x00000100,
00308 LUB_HEAP_ALIGN_2_POWER_9 = 0x00000200,
00312 LUB_HEAP_ALIGN_2_POWER_10 = 0x00000400,
00316 LUB_HEAP_ALIGN_2_POWER_11 = 0x00000800,
00320 LUB_HEAP_ALIGN_2_POWER_12 = 0x00001000,
00324 LUB_HEAP_ALIGN_2_POWER_13 = 0x00002000,
00328 LUB_HEAP_ALIGN_2_POWER_14 = 0x00004000,
00332 LUB_HEAP_ALIGN_2_POWER_15 = 0x00008000,
00336 LUB_HEAP_ALIGN_2_POWER_16 = 0x00010000,
00340 LUB_HEAP_ALIGN_2_POWER_17 = 0x00020000,
00344 LUB_HEAP_ALIGN_2_POWER_18 = 0x00040000,
00348 LUB_HEAP_ALIGN_2_POWER_19 = 0x00080000,
00352 LUB_HEAP_ALIGN_2_POWER_20 = 0x00100000,
00356 LUB_HEAP_ALIGN_2_POWER_21 = 0x00200000,
00360 LUB_HEAP_ALIGN_2_POWER_22 = 0x00400000,
00364 LUB_HEAP_ALIGN_2_POWER_23 = 0x00800000,
00368 LUB_HEAP_ALIGN_2_POWER_24 = 0x01000000,
00372 LUB_HEAP_ALIGN_2_POWER_25 = 0x02000000,
00376 LUB_HEAP_ALIGN_2_POWER_26 = 0x04000000,
00380 LUB_HEAP_ALIGN_2_POWER_27 = 0x08000000
00381 } lub_heap_align_t;
00382
00386 typedef enum
00387 {
00392 LUB_HEAP_SHOW_LEAKS,
00397 LUB_HEAP_SHOW_PARTIALS,
00401 LUB_HEAP_SHOW_ALL
00402 } lub_heap_show_e;
00403
00408 typedef void
00409 lub_heap_foreach_fn(
00413 void *block,
00417 unsigned index,
00421 size_t size,
00425 void *arg);
00426
00443 void
00444 lub_heap_foreach_segment(
00448 lub_heap_t *instance,
00452 lub_heap_foreach_fn *fn,
00457 void *arg);
00474 void
00475 lub_heap_foreach_free_block(
00479 lub_heap_t *instance,
00483 lub_heap_foreach_fn *fn,
00488 void *arg);
00489
00506 lub_heap_t *
00507 lub_heap_create(
00512 void *start,
00516 size_t size
00517 );
00534 void
00535 lub_heap_destroy(
00539 lub_heap_t *instance
00540 );
00558 void
00559 lub_heap_add_segment(
00563 lub_heap_t *instance,
00567 void *start,
00571 size_t size
00572 );
00592 void *
00593 lub_heap_static_alloc(
00597 lub_heap_t *instance,
00601 size_t size
00602 );
00627 lub_heap_status_t
00628 lub_heap_realloc(
00632 lub_heap_t *instance,
00637 char **ptr,
00641 size_t size,
00645 lub_heap_align_t alignment
00646 );
00671 bool_t
00672 lub_heap_taint(
00676 bool_t enable
00677 );
00692 bool_t
00693 lub_heap_is_tainting(void);
00717 bool_t
00718 lub_heap_check(
00722 bool_t enable
00723 );
00724
00739 bool_t
00740 lub_heap_is_checking(void);
00741
00757 extern bool_t
00758 lub_heap_check_memory(lub_heap_t *instance);
00759
00765 void
00766 lub_heap_stop_here(
00770 lub_heap_status_t status,
00774 char *old_ptr,
00778 size_t new_size
00779 );
00780
00792 void
00793 lub_heap__get_stats(
00797 lub_heap_t *instance,
00801 lub_heap_stats_t *stats
00802 );
00803
00807 void
00808 lub_heap_show(
00812 lub_heap_t *instance,
00816 bool_t verbose
00817 );
00830 size_t
00831 lub_heap__get_max_free(
00835 lub_heap_t *instance
00836 );
00837
00838 extern size_t
00839 lub_heap__get_block_overhead(lub_heap_t *instance,
00840 const void *ptr);
00841
00842 extern size_t
00843 lub_heap__get_block_size(lub_heap_t *instance,
00844 const void *ptr);
00852 extern void
00853 lub_heap_leak_scan(void);
00868 extern bool_t
00869 lub_heap_leak_report(
00873 lub_heap_show_e how,
00878 const char *substring
00879 );
00880
00881 void
00882 lub_heap__set_framecount(
00886 unsigned framecount
00887 );
00888
00889 unsigned
00890 lub_heap__get_framecount(void);
00891
00892 extern bool_t
00893 lub_heap_validate_pointer(lub_heap_t *instance,
00894 char *ptr);
00901 #define LUB_HEAP_ZERO_ALLOC ((void*)-1)
00902
00918 extern void
00919 lub_heap_init(
00924 const char *program_name
00925 );
00926
00927
00928 #if defined(__CYGWIN__)
00929
00934 extern void
00935 cygwin_lub_heap_init(const char *file_name);
00936
00937 #define lub_heap_init(arg0) cygwin_lub_heap_init(arg0)
00938
00939 #endif
00940
00956 lub_heap_status_t
00957 lub_heap_cache_init(
00961 lub_heap_t *instance,
00965 lub_heap_align_t max_block_size,
00969 size_t num_max_blocks
00970 );
00986 void
00987 lub_heap_leak_suppress_detection(
00991 lub_heap_t *instance
00992 );
01013 void
01014 lub_heap_leak_restore_detection(
01018 lub_heap_t *instance
01019 );
01020
01036 size_t
01037 lub_heap_overhead_size(
01041 lub_heap_align_t max_block_size,
01045 size_t num_max_blocks
01046 );
01047
01048
01049 _END_C_DECL
01050
01051 #endif
01052