dwarf_alloc.h 4.32 KB
/*

    dwarf_alloc.h
    $Revision: 1.1.1.1 $    $Date: 2002/05/02 03:29:20 $

*/

Dwarf_Ptr _dwarf_get_alloc (Dwarf_Debug, Dwarf_Small, Dwarf_Unsigned);
Dwarf_Debug _dwarf_get_debug (void);
Dwarf_Debug _dwarf_setup_debug (Dwarf_Debug);
int _dwarf_free_all_of_one_debug (Dwarf_Debug);


/*
    This macro adds the size of a pointer to the size of a
    struct that is given to it.  It rounds up the size to
    be a multiple of the size of a pointer.  This is done
    so that every struct returned by _dwarf_get_alloc()
    can be preceded by a pointer to the chunk it came from.
    Before, it checks if the size of struct is less than
    the size of a pointer.  If yes, it returns the size
    of 2 pointers.  The returned size should be at least
    the size of 2 pointers, since the first points to the
    chunk the struct was allocated from, and the second
    is used to link the free list.

    If this is n32, we want the sizes to be 64-bit aligned
    so that longlong in the structure we return to user
    is aligned properly. Thus the _dw_fac of 2
   
    Only long longs need to be properly aligned: we don't
    have long double and don't align for that.

*/
#if _MIPS_SIM == _MIPS_SIM_NABI32
#define _DW_FAC 2
#define _DW_PS sizeof(void *)
#else
#define _DW_FAC 1
#define _DW_PS sizeof(void *)
#endif
#define _DW_RESERVE (_DW_FAC * _DW_PS)

#define ROUND_SIZE(inputsize)               \
    ((inputsize) < (_DW_RESERVE) ?          \
	(  _DW_RESERVE)  :                  \
        ((inputsize) % (_DW_RESERVE) == 0 ? \
	    ((inputsize)  ):                \
	    ((inputsize)  +                 \
	       (_DW_RESERVE) - ((inputsize) % (_DW_RESERVE)) )))

#define ROUND_SIZE_WITH_POINTER(i_size) (ROUND_SIZE(i_size) + _DW_RESERVE)


typedef struct Dwarf_Alloc_Area_s	*Dwarf_Alloc_Area;
typedef struct Dwarf_Free_List_s	*Dwarf_Free_List;


/* 
    This struct is used to chain all the deallocated
    structs on the free list of each chain.  The structs
    are chained internally, by using the memory they
    contain.
*/
struct Dwarf_Free_List_s {
    Dwarf_Free_List		fl_next;
};


/*
    This struct is used to manage all the chunks malloc'ed
    for a particular alloc_type.  Many of the fields are
    initialized by dwarf_init().
*/
struct Dwarf_Alloc_Hdr_s {

	/* Count of actual number of structs allocated. */
    Dwarf_Sword			ah_struct_alloc_count;

	/* 
	    Size of each struct that will be allocated for
	    this alloc_type.  Initialized by dwarf_init().
	*/
    Dwarf_Half			ah_alloc_size;

	/* 
	    Number of structs of this alloc_type that will
	    be contained in each chunk that is malloc'ed.
	    Initialized by dwarf_init().
	*/
    Dwarf_Word			ah_alloc_num;

	/* 
	    Number of bytes malloc'ed per chunk, that is
	    ah_alloc_size * ah_alloc_num.
	*/
    Dwarf_Word			ah_malloc_length;

	/* Count of chunks currently allocated for type. */
    Dwarf_Sword			ah_curr_alloc;

        /* Max number of chunks ever allocated for type. */
    Dwarf_Sword			ah_max_alloc;

	/* 
	    Points to a chain of Dwarf_Alloc_Area_s structs
	    that represent all the chunks currently allocated
	    for the alloc_type.
	*/
    Dwarf_Alloc_Area		ah_alloc_area_head;

	/* Last Alloc Area that was allocated from. */
    Dwarf_Alloc_Area		ah_last_alloc_area;
};


/*
    This struct is used to manage each chunk that is
    malloc'ed for a particular alloc_type.  For each
    allocation type, the allocation header points to
    a list of all the chunks malloc'ed for that type.
*/
struct Dwarf_Alloc_Area_s {

	/* Points to the free list of structs in the chunk. */
    Dwarf_Ptr		aa_free_list;

	/* 
	    Count of the number of free structs in the chunk.
	    This includes both those on the free list, and in
	    the blob.
	*/
    Dwarf_Sword		aa_free_count;

	/* 
	    Points to the first byte of the blob from which
	    struct will be allocated.  A struct is put on the
	    free_list only when it dwrf_deallocated.  Initial
	    allocations are from the blob.
	*/
    Dwarf_Small		*aa_blob_start;

	/* Points just past the last byte of the blob. */
    Dwarf_Small		*aa_blob_end;

	/* Points to alloc_hdr this alloc_area is linked to. */
    Dwarf_Alloc_Hdr	aa_alloc_hdr;

	/* 
	    Used for chaining Dwarf_Alloc_Area_s atructs. 
	    Alloc areas are doubly linked to enable deletion
	    from the list in constant time.
	*/
    Dwarf_Alloc_Area	aa_next;
    Dwarf_Alloc_Area	aa_prev;
};