tools/elf4rom/libs/dwarf-20071209/libdwarf/dwarf_alloc.h
changeset 34 92d87f2e53c2
equal deleted inserted replaced
33:1af5c1be89f8 34:92d87f2e53c2
       
     1 /*
       
     2 
       
     3   Copyright (C) 2000,2005 Silicon Graphics, Inc.  All Rights Reserved.
       
     4 
       
     5   This program is free software; you can redistribute it and/or modify it
       
     6   under the terms of version 2.1 of the GNU Lesser General Public License 
       
     7   as published by the Free Software Foundation.
       
     8 
       
     9   This program is distributed in the hope that it would be useful, but
       
    10   WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
       
    12 
       
    13   Further, this software is distributed without any warranty that it is
       
    14   free of the rightful claim of any third person regarding infringement 
       
    15   or the like.  Any license provided herein, whether implied or 
       
    16   otherwise, applies only to this software file.  Patent licenses, if
       
    17   any, provided herein do not apply to combinations of this program with 
       
    18   other software, or any other product whatsoever.  
       
    19 
       
    20   You should have received a copy of the GNU Lesser General Public
       
    21   License along with this program; if not, write the Free Software
       
    22   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
       
    23   USA.
       
    24 
       
    25   Contact information:  Silicon Graphics, Inc., 1500 Crittenden Lane,
       
    26   Mountain View, CA 94043, or:
       
    27 
       
    28   http://www.sgi.com
       
    29 
       
    30   For further information regarding this notice, see:
       
    31 
       
    32   http://oss.sgi.com/projects/GenInfo/NoticeExplan
       
    33 
       
    34 */
       
    35 
       
    36 
       
    37 
       
    38 Dwarf_Ptr _dwarf_get_alloc(Dwarf_Debug, Dwarf_Small, Dwarf_Unsigned);
       
    39 Dwarf_Debug _dwarf_get_debug(void);
       
    40 Dwarf_Debug _dwarf_setup_debug(Dwarf_Debug);
       
    41 int _dwarf_free_all_of_one_debug(Dwarf_Debug);
       
    42 
       
    43 typedef struct Dwarf_Alloc_Area_s *Dwarf_Alloc_Area;
       
    44 typedef struct Dwarf_Free_List_s *Dwarf_Free_List;
       
    45 
       
    46 #define ALLOC_AREA_INDEX_TABLE_MAX 43
       
    47 #define ALLOC_AREA_REAL_TABLE_MAX 32
       
    48 
       
    49 /* 
       
    50     This struct is used to chain all the deallocated
       
    51     structs on the free list of each chain.  The structs
       
    52     are chained internally, by using the memory they
       
    53     contain.
       
    54 */
       
    55 struct Dwarf_Free_List_s {
       
    56     Dwarf_Free_List fl_next;
       
    57 };
       
    58 
       
    59 
       
    60 /*
       
    61     This struct is used to manage all the chunks malloc'ed
       
    62     for a particular alloc_type.  Many of the fields are
       
    63     initialized by dwarf_init().
       
    64 */
       
    65 struct Dwarf_Alloc_Hdr_s {
       
    66 
       
    67     /* Count of actual number of structs user app holds pointers to
       
    68        currently. */
       
    69     Dwarf_Sword ah_struct_user_holds;
       
    70 
       
    71     /* 
       
    72        Size of each struct that will be allocated for this alloc_type.
       
    73        Initialized by dwarf_init(). */
       
    74     Dwarf_Half ah_bytes_one_struct;
       
    75 
       
    76     /* 
       
    77        Number of structs of this alloc_type that will be contained in
       
    78        each chunk that is malloc'ed. Initialized by dwarf_init(). */
       
    79     Dwarf_Word ah_structs_per_chunk;
       
    80 
       
    81     /* 
       
    82        Number of bytes malloc'ed per chunk which is basically
       
    83        (ah_bytes_one_struct+_DWARF_RESERVE) * ah_alloc_num. */
       
    84     Dwarf_Word ah_bytes_malloc_per_chunk;
       
    85 
       
    86     /* Count of chunks currently allocated for type. */
       
    87     Dwarf_Sword ah_chunks_allocated;
       
    88 
       
    89     /* 
       
    90        Points to a chain of Dwarf_Alloc_Area_s structs that represent
       
    91        all the chunks currently allocated for the alloc_type. */
       
    92     Dwarf_Alloc_Area ah_alloc_area_head;
       
    93 
       
    94     /* Last Alloc Area that was allocated by malloc. The
       
    95        free-space-search area looks here first and only if it is full
       
    96        goes thru the list pointed to by ah_alloc_area_head. */
       
    97     Dwarf_Alloc_Area ah_last_alloc_area;
       
    98 };
       
    99 
       
   100 
       
   101 /*
       
   102     This struct is used to manage each chunk that is
       
   103     malloc'ed for a particular alloc_type.  For each
       
   104     allocation type, the allocation header points to
       
   105     a list of all the chunks malloc'ed for that type.
       
   106 */
       
   107 struct Dwarf_Alloc_Area_s {
       
   108 
       
   109     /* Points to the free list of structs in the chunk. */
       
   110     Dwarf_Ptr aa_free_list;
       
   111 
       
   112     /* 
       
   113        Count of the number of free structs in the chunk. This includes
       
   114        both those on the free list, and in the blob. */
       
   115     Dwarf_Sword aa_free_structs_in_chunk;
       
   116 
       
   117     /* 
       
   118        Points to the first byte of the blob from which struct will be
       
   119        allocated.  A struct is put on the free_list only when it
       
   120        dwarf_deallocated.  Initial allocations are from the blob. */
       
   121     Dwarf_Small *aa_blob_start;
       
   122 
       
   123     /* Points just past the last byte of the blob. */
       
   124     Dwarf_Small *aa_blob_end;
       
   125 
       
   126     /* Points to alloc_hdr this alloc_area is linked to: The owner, in 
       
   127        other words. */
       
   128     Dwarf_Alloc_Hdr aa_alloc_hdr;
       
   129 
       
   130     /* 
       
   131        Used for chaining Dwarf_Alloc_Area_s atructs. Alloc areas are
       
   132        doubly linked to enable deletion from the list in constant time. */
       
   133     Dwarf_Alloc_Area aa_next;
       
   134     Dwarf_Alloc_Area aa_prev;
       
   135 };
       
   136 
       
   137 struct Dwarf_Error_s *_dwarf_special_no_dbg_error_malloc(void);
       
   138 
       
   139 #ifdef DWARF_SIMPLE_MALLOC
       
   140 /*
       
   141    DWARF_SIMPLE_MALLOC is for testing the hypothesis that the existing
       
   142    complex malloc scheme in libdwarf is pointless complexity.
       
   143 
       
   144    DWARF_SIMPLE_MALLOC also makes it easy for a malloc-tracing
       
   145    tool to verify libdwarf malloc has no botches (though of course
       
   146    such does not test the complicated standard-libdwarf-alloc code).
       
   147 
       
   148 */
       
   149 
       
   150 struct simple_malloc_entry_s {
       
   151     Dwarf_Small   *se_addr;
       
   152     unsigned long  se_size;
       
   153     short          se_type;
       
   154 };
       
   155 #define DSM_BLOCK_COUNT (1000)
       
   156 #define DSM_BLOCK_SIZE (sizeof(struct simple_malloc_entry_s)*DSM_BLOCK_COUNT)
       
   157 
       
   158 /* we do this so dwarf_dealloc can really free everything */
       
   159 struct simple_malloc_record_s {
       
   160 	struct simple_malloc_record_s *sr_next;
       
   161 	int 			       sr_used;
       
   162 	struct simple_malloc_entry_s   sr_entry[DSM_BLOCK_COUNT];
       
   163 };
       
   164 
       
   165 
       
   166 
       
   167 #endif /* DWARF_SIMPLE_MALLOC */