123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451 |
- #include "lub/heap.h"
- #include "lub/bintree.h"
- #include "lub/types.h"
- #include "lub/dblockpool.h"
- #include "lub/size_fmt.h"
- 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;
- 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;
- struct lub_heap_tag_s {
- unsigned free:1;
- unsigned segment:1;
- unsigned words:30;
- };
- 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;
- };
- struct lub_heap_free_block_s {
- lub_heap_tag_t tag;
-
- lub_bintree_node_t bt_node;
-
- lub_heap_tag_t _tail;
- };
- struct lub_heap_alloc_block_s {
- lub_heap_tag_t tag;
-
- lub_heap_tag_t memory[1];
- };
- union lub_heap_block_u {
- lub_heap_alloc_block_t alloc;
- lub_heap_free_block_t free;
- };
- struct lub_heap_segment_s {
- lub_heap_segment_t *next;
- words_t words;
- lub_bintree_node_t bt_node;
- };
- struct lub_heap_s {
-
- lub_heap_cache_t *cache;
-
- lub_bintree_t free_tree;
-
- unsigned long suppress;
-
- lub_heap_stats_t stats;
-
- struct lub_heap_s *next;
-
- lub_heap_segment_t first_segment;
- };
- extern char *lub_heap_data_start;
- extern char *lub_heap_data_end;
- extern void lub_heap_symShow(
-
- unsigned address);
- extern bool_t lub_heap_symMatch(
-
- unsigned address,
-
- const char *substring);
- extern void lub_heap__get_stackframe(stackframe_t * stack, unsigned max);
- extern void lub_heap_scan_bss(void);
- extern void lub_heap_scan_data(void);
- extern void lub_heap_scan_stack(void);
- extern void lub_heap_taint_memory(
-
- char *ptr,
-
- lub_heap_taint_t type,
-
- size_t size);
- extern void lub_heap_clean_stacks(void);
- extern lub_heap_status_t lub_heap_raw_realloc(
-
- lub_heap_t * instance,
-
- char **ptr,
-
- size_t size,
-
- lub_heap_align_t
- alignment);
- extern void lub_heap_pre_realloc(
-
- lub_heap_t * instance,
-
- char **ptr,
-
- size_t * size);
- extern void lub_heap_post_realloc(
-
- lub_heap_t * instance,
-
- char **ptr);
- void lub_heap_clearAll(
-
- lub_heap_t * instance,
-
- unsigned frames);
- void lub_heap_alloc_failed(lub_heap_context_t * instance);
- void lub_heap_free_failed(void);
- 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);
- 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);
- extern void
- lub_heap_init_free_block(lub_heap_t * instance,
- void *ptr,
- size_t size, bool_t seg_start, bool_t seg_end);
- extern bool_t
- lub_heap_extend_upwards(lub_heap_t * instance,
- lub_heap_block_t ** block, words_t words);
- extern bool_t
- lub_heap_extend_downwards(lub_heap_t * instance,
- lub_heap_block_t ** block, words_t words);
- extern bool_t
- lub_heap_extend_both_ways(lub_heap_t * instance,
- lub_heap_block_t ** block, words_t words);
- 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);
- extern lub_heap_tag_t *lub_heap_block__get_tail(lub_heap_block_t * block);
- lub_heap_block_t *lub_heap_block_getfirst(const lub_heap_segment_t * seg);
- extern lub_heap_block_t *lub_heap_block_getnext(lub_heap_block_t * block);
- extern lub_heap_block_t *lub_heap_block_getprevious(lub_heap_block_t * block);
- 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);
|