summaryrefslogtreecommitdiff
path: root/src/arch/processor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/processor.c')
-rw-r--r--src/arch/processor.c66
1 files changed, 38 insertions, 28 deletions
diff --git a/src/arch/processor.c b/src/arch/processor.c
index c70d586..6b60c8c 100644
--- a/src/arch/processor.c
+++ b/src/arch/processor.c
@@ -72,9 +72,6 @@ static void g_arch_processor_add_new_coverage(GArchProcessor *, GArchInstruction
/* Termine la définition d'un nouveau groupe d'instructions. */
static void g_arch_processor_finish_last_coverage(GArchProcessor *, GArchInstruction *, size_t);
-/* Recherche un groupe d'instruction d'après son adresse. */
-static bool g_arch_processor_find_coverage_by_address(const GArchProcessor *, const vmpa2t *, size_t *, size_t *);
-
@@ -399,20 +396,18 @@ static void g_arch_processor_finish_last_coverage(GArchProcessor *proc, GArchIns
* *
* Paramètres : proc = processeur recensant diverses instructions. *
* addr = position en mémoire ou physique à chercher. *
-* start = indice de départ du groupe concerné trouvé. [OUT] *
-* end = indice de fin du groupe d'instructions visées. [OUT] *
* *
* Description : Recherche un groupe d'instruction d'après son adresse. *
* *
-* Retour : Bilan de la recherche menée. *
+* Retour : Couverture trouvée ou NULL si aucune. *
* *
* Remarques : - *
* *
******************************************************************************/
-static bool g_arch_processor_find_coverage_by_address(const GArchProcessor *proc, const vmpa2t *addr, size_t *start, size_t *count)
+const instr_coverage *g_arch_processor_find_coverage_by_address(const GArchProcessor *proc, const vmpa2t *addr)
{
- bool result; /* Bilan à retourner */
+ instr_coverage *result; /* Trouvaille à retourner */
void *ptr; /* Résultat des recherches */
int search_for_coverage_by_addr(const vmpa2t *a, const instr_coverage *c)
@@ -428,14 +423,7 @@ static bool g_arch_processor_find_coverage_by_address(const GArchProcessor *proc
ptr = bsearch(addr, proc->coverages, proc->cov_count,
sizeof(instr_coverage), (__compar_fn_t)search_for_coverage_by_addr);
- if (ptr != NULL)
- {
- result = true;
- *start = ((instr_coverage *)ptr)->start;
- *count = ((instr_coverage *)ptr)->count;
- }
- else
- result = false;
+ result = ((instr_coverage *)ptr);
return result;
@@ -543,8 +531,37 @@ GArchInstruction *g_arch_processor_get_disassembled_instructions(const GArchProc
GArchInstruction *g_arch_processor_find_instr_by_address(const GArchProcessor *proc, const vmpa2t *addr)
{
GArchInstruction *result; /* Trouvaille à retourner */
- size_t cov_start; /* Début d'un groupe ciblé */
- size_t cov_count; /* Nombre d'éléments à tester */
+ const instr_coverage *coverage; /* Couverture fine à fouiller */
+
+ coverage = g_arch_processor_find_coverage_by_address(proc, addr);
+
+ if (coverage != NULL)
+ result = g_arch_processor_find_covered_instr_by_address(proc, coverage, addr);
+ else
+ result = NULL;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : proc = processeur recensant diverses instructions. *
+* coverage = zone de couverture fine à fouiller. *
+* addr = position en mémoire ou physique à chercher. *
+* *
+* Description : Recherche rapidement une instruction d'après son adresse. *
+* *
+* Retour : Instruction trouvée à l'adresse donnée, NULL si aucune. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchInstruction *g_arch_processor_find_covered_instr_by_address(const GArchProcessor *proc, const instr_coverage *coverage, const vmpa2t *addr)
+{
+ GArchInstruction *result; /* Trouvaille à retourner */
void *ptr; /* Résultat des recherches */
int search_for_instr_by_addr(const vmpa2t *a, const GArchInstruction **b)
@@ -557,17 +574,10 @@ GArchInstruction *g_arch_processor_find_instr_by_address(const GArchProcessor *p
}
+ ptr = bsearch(addr, &proc->instructions[coverage->start], coverage->count,
+ sizeof(GArchInstruction *), (__compar_fn_t)search_for_instr_by_addr);
- if (g_arch_processor_find_coverage_by_address(proc, addr, &cov_start, &cov_count))
- {
- ptr = bsearch(addr, &proc->instructions[cov_start], cov_count,
- sizeof(GArchInstruction *), (__compar_fn_t)search_for_instr_by_addr);
-
- result = (ptr != NULL ? *((GArchInstruction **)ptr) : NULL);
-
- }
- else
- result = NULL;
+ result = (ptr != NULL ? *((GArchInstruction **)ptr) : NULL);
return result;