00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "config.h"
00043 #include "libdwarfdefs.h"
00044 #include <stdio.h>
00045 #include <string.h>
00046
00047 #include "pro_incl.h"
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 int
00063 _dwarf_pro_pre_alloc_n_reloc_slots(Dwarf_P_Debug dbg,
00064 int rel_sec_index,
00065 Dwarf_Unsigned newslots)
00066 {
00067 unsigned long len;
00068 struct Dwarf_P_Relocation_Block_s *data;
00069 Dwarf_P_Per_Reloc_Sect prel = &dbg->de_reloc_sect[rel_sec_index];
00070 unsigned long slots_in_blk = (unsigned long) newslots;
00071 unsigned long rel_rec_size = dbg->de_relocation_record_size;
00072
00073 if (prel->pr_first_block)
00074 return DW_DLV_OK;
00075
00076 len = sizeof(struct Dwarf_P_Relocation_Block_s) +
00077 slots_in_blk * rel_rec_size;
00078
00079
00080 data = (struct Dwarf_P_Relocation_Block_s *)
00081 _dwarf_p_get_alloc(dbg, len);
00082 if (!data) {
00083 return DW_DLV_ERROR;
00084 }
00085 data->rb_slots_in_block = slots_in_blk;
00086
00087
00088
00089
00090
00091
00092
00093
00094 data->rb_next_slot_to_use = 0;
00095 data->rb_where_to_add_next =
00096 ((char *) data) + sizeof(struct Dwarf_P_Relocation_Block_s);
00097 data->rb_data = data->rb_where_to_add_next;
00098
00099 prel->pr_first_block = data;
00100 prel->pr_last_block = data;
00101 prel->pr_block_count = 1;
00102
00103
00104 return DW_DLV_OK;
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 int
00116 _dwarf_pro_alloc_reloc_slots(Dwarf_P_Debug dbg, int rel_sec_index)
00117 {
00118 unsigned long len;
00119 struct Dwarf_P_Relocation_Block_s *data;
00120 Dwarf_P_Per_Reloc_Sect prel = &dbg->de_reloc_sect[rel_sec_index];
00121 unsigned long slots_in_blk = prel->pr_slots_per_block_to_alloc;
00122 unsigned long rel_rec_size = dbg->de_relocation_record_size;
00123
00124 len = sizeof(struct Dwarf_P_Relocation_Block_s) +
00125 slots_in_blk * rel_rec_size;
00126
00127 data = (struct Dwarf_P_Relocation_Block_s *)
00128 _dwarf_p_get_alloc(dbg, len);
00129 if (!data) {
00130 return DW_DLV_ERROR;
00131 }
00132
00133 if (prel->pr_first_block) {
00134 prel->pr_last_block->rb_next = data;
00135 prel->pr_last_block = data;
00136 prel->pr_block_count += 1;
00137
00138 } else {
00139
00140 prel->pr_first_block = data;
00141 prel->pr_last_block = data;
00142 prel->pr_block_count = 1;
00143 }
00144
00145 data->rb_slots_in_block = slots_in_blk;
00146 data->rb_next_slot_to_use = 0;
00147 data->rb_where_to_add_next =
00148 ((char *) data) + sizeof(struct Dwarf_P_Relocation_Block_s);
00149 data->rb_data = data->rb_where_to_add_next;
00150
00151 return DW_DLV_OK;
00152
00153 }
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 int
00164 _dwarf_pro_reloc_get_a_slot(Dwarf_P_Debug dbg,
00165 int base_sec_index, void **relrec_to_fill)
00166 {
00167 struct Dwarf_P_Relocation_Block_s *data;
00168 Dwarf_P_Per_Reloc_Sect prel = &dbg->de_reloc_sect[base_sec_index];
00169 unsigned long rel_rec_size = dbg->de_relocation_record_size;
00170
00171 char *ret_addr;
00172
00173 data = prel->pr_last_block;
00174 if ((data == 0) ||
00175 (data->rb_next_slot_to_use >= data->rb_slots_in_block)) {
00176 int res;
00177
00178 res = _dwarf_pro_alloc_reloc_slots(dbg, base_sec_index);
00179 if (res != DW_DLV_OK) {
00180 return res;
00181 }
00182 }
00183
00184 data = prel->pr_last_block;
00185
00186 ret_addr = data->rb_where_to_add_next;
00187
00188 data->rb_where_to_add_next += rel_rec_size;
00189 data->rb_next_slot_to_use += 1;
00190
00191 prel->pr_reloc_total_count += 1;
00192
00193 *relrec_to_fill = (void *) ret_addr;
00194
00195 return DW_DLV_OK;
00196
00197 }
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 int
00217 dwarf_get_relocation_info_count(Dwarf_P_Debug dbg,
00218 Dwarf_Unsigned *
00219 count_of_relocation_sections,
00220 int *drd_buffer_version,
00221 Dwarf_Error * error)
00222 {
00223 if (dbg->de_flags & DW_DLC_SYMBOLIC_RELOCATIONS) {
00224 int i;
00225 unsigned int count = 0;
00226
00227 for (i = 0; i < NUM_DEBUG_SECTIONS; ++i) {
00228 if (dbg->de_reloc_sect[i].pr_reloc_total_count > 0) {
00229 ++count;
00230 }
00231 }
00232 *count_of_relocation_sections = (Dwarf_Unsigned) count;
00233 *drd_buffer_version = DWARF_DRD_BUFFER_VERSION;
00234 return DW_DLV_OK;
00235 }
00236 return DW_DLV_NO_ENTRY;
00237 }
00238
00239 int
00240 dwarf_get_relocation_info(Dwarf_P_Debug dbg,
00241 Dwarf_Signed * elf_section_index,
00242 Dwarf_Signed * elf_section_index_link,
00243 Dwarf_Unsigned * relocation_buffer_count,
00244 Dwarf_Relocation_Data * reldata_buffer,
00245 Dwarf_Error * error)
00246 {
00247 int next = dbg->de_reloc_next_to_return;
00248
00249 if (dbg->de_flags & DW_DLC_SYMBOLIC_RELOCATIONS) {
00250 int i;
00251
00252 for (i = next; i < NUM_DEBUG_SECTIONS; ++i) {
00253 Dwarf_P_Per_Reloc_Sect prel = &dbg->de_reloc_sect[i];
00254
00255 if (prel->pr_reloc_total_count > 0) {
00256 dbg->de_reloc_next_to_return = i + 1;
00257
00258
00259
00260
00261 *elf_section_index = prel->pr_sect_num_of_reloc_sect;
00262 *elf_section_index_link = dbg->de_elf_sects[i];
00263 *relocation_buffer_count = prel->pr_reloc_total_count;
00264 *reldata_buffer = (Dwarf_Relocation_Data)
00265 (prel->pr_first_block->rb_data);
00266 return DW_DLV_OK;
00267 }
00268 }
00269 DWARF_P_DBG_ERROR(dbg, DW_DLE_REL_ALLOC, DW_DLV_ERROR);
00270 }
00271 return DW_DLV_NO_ENTRY;
00272 }