Skip to content

Commit

Permalink
Separate extented insert/update methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pelijah committed May 14, 2024
1 parent a2a2091 commit cc128c8
Show file tree
Hide file tree
Showing 94 changed files with 365 additions and 376 deletions.
2 changes: 1 addition & 1 deletion binrz/rz-test/rz-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ int rz_test_main(int argc, const char **argv) {
RzTestFileCounts *counts = ht_sp_find(state.path_left, test->path, NULL);
if (!counts) {
counts = calloc(1, sizeof(RzTestFileCounts));
ht_sp_insert(state.path_left, test->path, counts, NULL);
ht_sp_insert(state.path_left, test->path, counts);
}
counts->tests_left++;
}
Expand Down
2 changes: 1 addition & 1 deletion librz/arch/asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ RZ_API RzAsmCode *rz_asm_massemble(RzAsm *a, const char *assembly) {
off += (acode->code_align - (off % acode->code_align));
}
char *food = rz_str_newf("0x%" PFMT64x, off);
ht_ss_insert(a->flags, ptr_start, food, NULL);
ht_ss_insert(a->flags, ptr_start, food);
rz_asm_code_set_equ(acode, p, food);
free(p);
free(food);
Expand Down
30 changes: 15 additions & 15 deletions librz/arch/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ static bool block_recurse_successor_cb(ut64 addr, void *user) {
// already visited
return true;
}
ht_up_insert(ctx->visited, addr, NULL, NULL);
ht_up_insert(ctx->visited, addr, NULL);
RzAnalysisBlock *block = rz_analysis_get_block_at(ctx->analysis, addr);
if (!block) {
return true;
Expand All @@ -441,7 +441,7 @@ RZ_API bool rz_analysis_block_recurse(RzAnalysisBlock *block, RzAnalysisBlockCb
goto beach;
}

ht_up_insert(ctx.visited, block->addr, NULL, NULL);
ht_up_insert(ctx.visited, block->addr, NULL);
rz_pvector_push(&ctx.to_visit, block);

while (!rz_pvector_empty(&ctx.to_visit)) {
Expand Down Expand Up @@ -469,7 +469,7 @@ RZ_API bool rz_analysis_block_recurse_followthrough(RzAnalysisBlock *block, RzAn
goto beach;
}

ht_up_insert(ctx.visited, block->addr, NULL, NULL);
ht_up_insert(ctx.visited, block->addr, NULL);
rz_pvector_push(&ctx.to_visit, block);

while (!rz_pvector_empty(&ctx.to_visit)) {
Expand Down Expand Up @@ -506,7 +506,7 @@ RZ_API bool rz_analysis_block_recurse_depth_first(RzAnalysisBlock *block, RzAnal
RzAnalysisBlock *cur_bb = block;
RecurseDepthFirstCtx ctx = { cur_bb, NULL };
rz_vector_push(&path, &ctx);
ht_up_insert(visited, cur_bb->addr, NULL, NULL);
ht_up_insert(visited, cur_bb->addr, NULL);
breaked = !cb(cur_bb, user);
if (breaked) {
goto beach;
Expand Down Expand Up @@ -542,7 +542,7 @@ RZ_API bool rz_analysis_block_recurse_depth_first(RzAnalysisBlock *block, RzAnal
if (cur_bb) {
RecurseDepthFirstCtx ctx = { cur_bb, NULL };
rz_vector_push(&path, &ctx);
ht_up_insert(visited, cur_bb->addr, NULL, NULL);
ht_up_insert(visited, cur_bb->addr, NULL);
bool breaked = !cb(cur_bb, user);
if (breaked) {
break;
Expand Down Expand Up @@ -615,7 +615,7 @@ static bool shortest_path_successor_cb(ut64 addr, void *user) {
// already visited
return true;
}
ht_up_insert(ctx->visited, addr, ctx->cur_parent, NULL);
ht_up_insert(ctx->visited, addr, ctx->cur_parent);
RzAnalysisBlock *block = rz_analysis_get_block_at(ctx->analysis, addr);
if (block) {
rz_pvector_push(ctx->next_visit, block);
Expand All @@ -642,7 +642,7 @@ RZ_API RZ_NULLABLE RzList /*<RzAnalysisBlock *>*/ *rz_analysis_block_shortest_pa
goto beach;
}

ht_up_insert(ctx.visited, block->addr, NULL, NULL);
ht_up_insert(ctx.visited, block->addr, NULL);
rz_pvector_push(cur_visit, block);

// BFS
Expand Down Expand Up @@ -735,7 +735,7 @@ static bool noreturn_successors_cb(RzAnalysisBlock *block, void *user) {
rz_analysis_block_ref(block);
succ->block = block;
succ->reachable = false; // reset for first iteration
ht_up_insert(succs, block->addr, succ, NULL);
ht_up_insert(succs, block->addr, succ);
return true;
}

Expand Down Expand Up @@ -862,11 +862,11 @@ static bool automerge_predecessor_successor_cb(ut64 addr, void *user) {
if (found) {
if (pred) {
// only one predecessor found so far, but we are the second so there are multiple now
ht_up_update(ctx->predecessors, (ut64)(size_t)block, NULL, NULL);
ht_up_update(ctx->predecessors, (ut64)(size_t)block, NULL);
} // else: already found multiple predecessors, nothing to do
} else {
// no predecessor found yet, this is the only one until now
ht_up_insert(ctx->predecessors, (ut64)(size_t)block, ctx->cur_pred, NULL);
ht_up_insert(ctx->predecessors, (ut64)(size_t)block, ctx->cur_pred);
}
return true;
}
Expand All @@ -886,7 +886,7 @@ static bool automerge_get_predecessors_cb(void *user, const ut64 k, const void *
ctx->cur_pred = block;
ctx->cur_succ_count = 0;
rz_analysis_block_successor_addrs_foreach(block, automerge_predecessor_successor_cb, ctx);
ht_up_insert(ctx->visited_blocks, (ut64)(size_t)block, (void *)ctx->cur_succ_count, NULL);
ht_up_insert(ctx->visited_blocks, (ut64)(size_t)block, (void *)ctx->cur_succ_count);
}
return true;
}
Expand Down Expand Up @@ -915,9 +915,9 @@ RZ_API void rz_analysis_block_automerge(RzPVector /*<RzAnalysisBlock *>*/ *block
RzListIter *fit;
RzAnalysisFunction *fcn;
rz_list_foreach (block->fcns, fit, fcn) {
ht_up_insert(relevant_fcns, (ut64)(size_t)fcn, NULL, NULL);
ht_up_insert(relevant_fcns, (ut64)(size_t)fcn, NULL);
}
ht_up_insert(ctx.blocks, block->addr, block, NULL);
ht_up_insert(ctx.blocks, block->addr, block);
}

// Get the single predecessors we might want to merge with
Expand Down Expand Up @@ -964,11 +964,11 @@ RZ_API void rz_analysis_block_automerge(RzPVector /*<RzAnalysisBlock *>*/ *block
// Update number of successors of the predecessor
ctx.cur_succ_count = 0;
rz_analysis_block_successor_addrs_foreach(predecessor, count_successors_cb, &ctx);
ht_up_update(ctx.visited_blocks, (ut64)(size_t)predecessor, (void *)(size_t)ctx.cur_succ_count, NULL);
ht_up_update(ctx.visited_blocks, (ut64)(size_t)predecessor, (void *)(size_t)ctx.cur_succ_count);
RzListIter *bit;
rz_list_foreach (fixup_candidates, bit, clock) {
// Make sure all previous pointers to block now go to predecessor
ht_up_update(ctx.predecessors, (ut64)(size_t)clock, predecessor, NULL);
ht_up_update(ctx.predecessors, (ut64)(size_t)clock, predecessor);
}
// Remove it from the list
rz_pvector_remove_at(blocks, i);
Expand Down
4 changes: 2 additions & 2 deletions librz/arch/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ RZ_API RzGraph /*<RzGraphNodeInfo *>*/ *rz_analysis_class_get_inheritance_graph(
if (!curr_node) {
goto failure;
}
ht_sp_insert(hashmap, name, curr_node, NULL);
ht_sp_insert(hashmap, name, curr_node);
}
// create edges between node and it's parents
RzVector *bases = rz_analysis_class_base_get_all(analysis, name);
Expand All @@ -1312,7 +1312,7 @@ RZ_API RzGraph /*<RzGraphNodeInfo *>*/ *rz_analysis_class_get_inheritance_graph(
if (!base_node) {
goto failure;
}
ht_sp_insert(hashmap, base->class_name, base_node, NULL);
ht_sp_insert(hashmap, base->class_name, base_node);
}
rz_graph_add_edge(class_graph, base_node, curr_node);
}
Expand Down
16 changes: 8 additions & 8 deletions librz/arch/dwarf_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ static char *at_string_escaped(const RzBinDwarfAttr *attr, DwContext *ctx) {
}
str->c_str = c_str;
str->length = strlen(c_str);
ht_up_insert(ctx->str_escaped, (ut64)attr, str, NULL);
ht_up_insert(ctx->str_escaped, (ut64)attr, str);
return rz_mem_dup(str->c_str, str->length + 1);
}

Expand Down Expand Up @@ -749,7 +749,7 @@ static RzBaseType *RzBaseType_from_die(DwContext *ctx, const RzBinDwarfDie *die)
btype->type = rz_type_identifier_of_base_type_str(ctx->analysis->typedb, "void");
}

if (!ht_up_insert(ctx->analysis->debug_info->base_type_by_offset, die->offset, btype, NULL)) {
if (!ht_up_insert(ctx->analysis->debug_info->base_type_by_offset, die->offset, btype)) {
RZ_LOG_WARN("Failed to save base type %s [0x%" PFMT64x "]\n",
btype->name, die->offset);
}
Expand All @@ -758,7 +758,7 @@ static RzBaseType *RzBaseType_from_die(DwContext *ctx, const RzBinDwarfDie *die)
ctx->analysis->debug_info->base_types_by_name, btype->name, NULL);
if (!btypes) {
btypes = rz_pvector_new(NULL);
ht_sp_insert(ctx->analysis->debug_info->base_types_by_name, btype->name, btypes, NULL);
ht_sp_insert(ctx->analysis->debug_info->base_types_by_name, btype->name, btypes);
rz_pvector_push(btypes, btype);
} else {
void **it;
Expand Down Expand Up @@ -1008,7 +1008,7 @@ static RZ_OWN RzType *type_parse_from_offset_internal(
}

RzType *copy = type ? rz_type_clone(type) : NULL;
if (copy && ht_up_insert(ctx->analysis->debug_info->type_by_offset, offset, copy, NULL)) {
if (copy && ht_up_insert(ctx->analysis->debug_info->type_by_offset, offset, copy)) {
#if RZ_BUILD_DEBUG
char *tstring = rz_type_as_string(ctx->analysis->typedb, type);
RZ_LOG_DEBUG("Insert RzType [%s] into type_by_offset\n", tstring);
Expand Down Expand Up @@ -1502,7 +1502,7 @@ static bool function_children_parse(
rz_type_callable_arg_add(callable, arg);
}
RzAnalysisDwarfVariable *ptr = rz_vector_push(&fn->variables, &v);
ht_up_insert(ctx->analysis->debug_info->variable_by_offset, v.offset, ptr, NULL);
ht_up_insert(ctx->analysis->debug_info->variable_by_offset, v.offset, ptr);
continue;
loop_end:
variable_fini(&v);
Expand Down Expand Up @@ -1623,16 +1623,16 @@ static bool function_from_die(

RZ_LOG_DEBUG("DWARF function saving %s 0x%" PFMT64x " [0x%" PFMT64x "]\n",
fcn->prefer_name, fcn->low_pc, die->offset);
if (!ht_up_update(ctx->analysis->debug_info->callable_by_offset, die->offset, callable, NULL)) {
if (!ht_up_update(ctx->analysis->debug_info->callable_by_offset, die->offset, callable)) {
RZ_LOG_ERROR("DWARF callable saving failed [0x%" PFMT64x "]\n", die->offset);
goto cleanup;
}
if (!ht_up_update(ctx->analysis->debug_info->function_by_offset, die->offset, fcn, NULL)) {
if (!ht_up_update(ctx->analysis->debug_info->function_by_offset, die->offset, fcn)) {
RZ_LOG_ERROR("DWARF function saving failed [0x%" PFMT64x "]\n", fcn->low_pc);
goto cleanup;
}
if (fcn->low_pc > 0) {
if (!ht_up_update(ctx->analysis->debug_info->function_by_addr, fcn->low_pc, fcn, NULL)) {
if (!ht_up_update(ctx->analysis->debug_info->function_by_addr, fcn->low_pc, fcn)) {
RZ_LOG_ERROR("DWARF function saving failed with addr: [0x%" PFMT64x "]\n",
fcn->low_pc);
goto cleanup;
Expand Down
2 changes: 1 addition & 1 deletion librz/arch/esil/esil.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ RZ_API bool rz_analysis_esil_set_op(RzAnalysisEsil *esil, const char *op, RzAnal
RZ_LOG_ERROR("Cannot allocate esil-operation %s\n", op);
return false;
}
if (!ht_sp_insert(esil->ops, op, eop, NULL)) {
if (!ht_sp_insert(esil->ops, op, eop)) {
RZ_LOG_ERROR("Cannot set esil-operation %s\n", op);
free(eop);
return false;
Expand Down
2 changes: 1 addition & 1 deletion librz/arch/esil/esil_interrupt.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ RZ_API void rz_analysis_esil_interrupt_free(RzAnalysisEsil *esil, RzAnalysisEsil

RZ_API bool rz_analysis_esil_set_interrupt(RzAnalysisEsil *esil, RzAnalysisEsilInterrupt *intr) {
rz_return_val_if_fail(esil && esil->interrupts && intr && intr->handler && intr->handler->cb, false);
return ht_up_update(esil->interrupts, intr->handler->num, intr, NULL);
return ht_up_update(esil->interrupts, intr->handler->num, intr);
}

RZ_API int rz_analysis_esil_fire_interrupt(RzAnalysisEsil *esil, ut32 intr_num) {
Expand Down
4 changes: 2 additions & 2 deletions librz/arch/esil/esil_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static void add_reg_change(RzAnalysisEsilTrace *trace, int idx, RzRegItem *ri, u
RZ_LOG_ERROR("Creating a register vector.\n");
return;
}
ht_up_insert(trace->registers, addr, vreg, NULL);
ht_up_insert(trace->registers, addr, vreg);
}
RzAnalysisEsilRegChange reg = { idx, data };
rz_vector_push(vreg, &reg);
Expand All @@ -110,7 +110,7 @@ static void add_mem_change(RzAnalysisEsilTrace *trace, int idx, ut64 addr, ut8 d
RZ_LOG_ERROR("Creating a memory vector.\n");
return;
}
ht_up_insert(trace->memory, addr, vmem, NULL);
ht_up_insert(trace->memory, addr, vmem);
}
RzAnalysisEsilMemChange mem = { idx, data };
rz_vector_push(vmem, &mem);
Expand Down
10 changes: 5 additions & 5 deletions librz/arch/fcn.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ static void check_purity(HtUP *ht, RzAnalysisFunction *fcn) {
RzListIter *iter;
RzList *xrefs = rz_analysis_function_get_xrefs_from(fcn);
RzAnalysisXRef *xref;
ht_up_insert(ht, fcn->addr, NULL, NULL);
ht_up_insert(ht, fcn->addr, NULL);
fcn->is_pure = true;
rz_list_foreach (xrefs, iter, xref) {
if (xref->type == RZ_ANALYSIS_XREF_TYPE_CALL || xref->type == RZ_ANALYSIS_XREF_TYPE_CODE) {
Expand Down Expand Up @@ -2242,7 +2242,7 @@ typedef struct {

static bool mark_as_visited(RzAnalysisBlock *bb, void *user) {
BlockRecurseCtx *ctx = user;
ht_up_insert(ctx->visited, bb->addr, NULL, NULL);
ht_up_insert(ctx->visited, bb->addr, NULL);
return true;
}

Expand All @@ -2257,7 +2257,7 @@ static bool analize_addr_cb(ut64 addr, void *user) {
rz_analysis_block_recurse(rz_analysis_get_block_at(analysis, addr), mark_as_visited, user);
}
}
ht_up_insert(ctx->visited, addr, NULL, NULL);
ht_up_insert(ctx->visited, addr, NULL);
return true;
}

Expand Down Expand Up @@ -2340,7 +2340,7 @@ static void update_analysis(RzAnalysis *analysis, RzList /*<RzAnalysisFunction *
}
}
HtUP *ht = ht_up_new(NULL, NULL);
ht_up_insert(ht, bb->addr, NULL, NULL);
ht_up_insert(ht, bb->addr, NULL);
BlockRecurseCtx ctx = { fcn, ht };
rz_analysis_block_recurse(bb, analize_descendents, &ctx);

Expand Down Expand Up @@ -2381,7 +2381,7 @@ static void calc_reachable_and_remove_block(RzList /*<RzAnalysisFunction *>*/ *f
HtUP *ht = ht_up_new(NULL, NULL);
BlockRecurseCtx ctx = { fcn, ht };
rz_analysis_block_recurse(rz_analysis_get_block_at(fcn->analysis, fcn->addr), mark_as_visited, &ctx);
ht_up_insert(reachable, fcn->addr, ht, NULL);
ht_up_insert(reachable, fcn->addr, ht);
}
fcn->ninstr -= bb->ninstr;
rz_analysis_function_remove_block(fcn, bb);
Expand Down
8 changes: 4 additions & 4 deletions librz/arch/function.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ RZ_API bool rz_analysis_add_function(RzAnalysis *analysis, RzAnalysisFunction *f
}
fcn->is_noreturn = rz_analysis_noreturn_at_addr(analysis, fcn->addr);
rz_list_append(analysis->fcns, fcn);
return ht_sp_insert(analysis->ht_name_fun, fcn->name, fcn, NULL) && ht_up_insert(analysis->ht_addr_fun, fcn->addr, fcn, NULL);
return ht_sp_insert(analysis->ht_name_fun, fcn->name, fcn) && ht_up_insert(analysis->ht_addr_fun, fcn->addr, fcn);
}

RZ_API RzAnalysisFunction *rz_analysis_create_function(RzAnalysis *analysis, const char *name, ut64 addr, RzAnalysisFcnType type) {
Expand Down Expand Up @@ -218,7 +218,7 @@ typedef struct {

static bool inst_vars_relocate_cb(void *user, const ut64 k, const void *v) {
InstVarsRelocateCtx *ctx = user;
ht_up_insert(ctx->inst_vars_new, k - ctx->delta, (void *)v, NULL);
ht_up_insert(ctx->inst_vars_new, k - ctx->delta, (void *)v);
return true;
}

Expand Down Expand Up @@ -254,7 +254,7 @@ RZ_API bool rz_analysis_function_relocate(RzAnalysisFunction *fcn, ut64 addr) {
}

fcn->addr = addr;
ht_up_insert(fcn->analysis->ht_addr_fun, addr, fcn, NULL);
ht_up_insert(fcn->analysis->ht_addr_fun, addr, fcn);
return true;
}

Expand All @@ -277,7 +277,7 @@ RZ_API bool rz_analysis_function_rename(RzAnalysisFunction *fcn, const char *nam
fcn->name = newname;
if (in_tree) {
// only re-insert if it really was in the tree before
ht_sp_insert(analysis->ht_name_fun, fcn->name, fcn, NULL);
ht_sp_insert(analysis->ht_name_fun, fcn->name, fcn);
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion librz/arch/hint.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static RzAnalysisAddrHintRecord *ensure_addr_hint_record(RzAnalysis *analysis, R
if (!records) {
return NULL;
}
ht_up_insert(analysis->addr_hints, addr, records, NULL);
ht_up_insert(analysis->addr_hints, addr, records);
}
void *pos;
rz_vector_foreach (records, pos) {
Expand Down
8 changes: 4 additions & 4 deletions librz/arch/isa/arm/arm_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ RZ_API void rz_arm_it_update_block(RzArmITContext *ctx, cs_insn *insn) {
cond.vpt = 0;
#endif
RZ_STATIC_ASSERT(sizeof(cond) == sizeof(cond.packed));
ht_uu_update(ctx->ht_itcond, insn->address + cond.off, cond.packed, NULL);
ht_uu_update(ctx->ht_itcond, insn->address + cond.off, cond.packed);
}
RZ_STATIC_ASSERT(sizeof(block) == sizeof(block.packed));
ht_uu_update(ctx->ht_itblock, insn->address, block.packed, NULL);
ht_uu_update(ctx->ht_itblock, insn->address, block.packed);
}

/**
Expand Down Expand Up @@ -201,8 +201,8 @@ RZ_API bool rz_arm_it_apply_cond(RzArmITContext *ctx, cs_insn *insn) {
}
ht_uu_delete(ctx->ht_itcond, blockaddr + itblock.off[idx]);
adjcond.off = itblock.off[idx] += 2;
ht_uu_update(ctx->ht_itcond, blockaddr + itblock.off[idx], adjcond.packed, NULL);
ht_uu_update(ctx->ht_itcond, blockaddr + itblock.off[idx], adjcond.packed);
}
ht_uu_update(ctx->ht_itblock, blockaddr, itblock.packed, NULL);
ht_uu_update(ctx->ht_itblock, blockaddr, itblock.packed);
return true;
}
2 changes: 1 addition & 1 deletion librz/arch/isa/tms320/tms320_dasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ int tms320_dasm_init(tms320_dasm_t *dasm) {
return 0;
}
for (i = 0; i < RZ_ARRAY_SIZE(c55x_list); i++) {
ht_up_insert(dasm->map, c55x_list[i].byte, &c55x_list[i], NULL);
ht_up_insert(dasm->map, c55x_list[i].byte, &c55x_list[i]);
}

tms320_f_set_cpu(dasm, TMS320_F_CPU_C55X);
Expand Down
4 changes: 2 additions & 2 deletions librz/arch/labels.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ RZ_API bool rz_analysis_function_set_label(RzAnalysisFunction *fcn, const char *
return false;
}
char *n = strdup(name);
if (!ht_up_insert(fcn->labels, addr, n, NULL)) {
if (!ht_up_insert(fcn->labels, addr, n)) {
free(n);
return false;
}
ht_sp_insert(fcn->label_addrs, name, ut64_new(addr), NULL);
ht_sp_insert(fcn->label_addrs, name, ut64_new(addr));
return true;
}

Expand Down
Loading

0 comments on commit cc128c8

Please sign in to comment.