summaryrefslogtreecommitdiff
path: root/src/arch/instruction.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/instruction.c')
-rw-r--r--src/arch/instruction.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/arch/instruction.c b/src/arch/instruction.c
index 8f2f262..bb98efb 100644
--- a/src/arch/instruction.c
+++ b/src/arch/instruction.c
@@ -35,6 +35,16 @@
+/* Accès aux décrochages */
+static const char *_hook_names[IPH_COUNT] = {
+
+ [IPH_FETCH] = "IPH_FETCH",
+ [IPH_LINK] = "IPH_LINK",
+ [IPH_POST] = "IPH_POST"
+
+};
+
+
/* Initialise la classe générique des instructions. */
static void g_arch_instruction_class_init(GArchInstructionClass *);
@@ -311,7 +321,10 @@ ArchInstrFlag g_arch_instruction_get_flags(const GArchInstruction *instr)
void g_arch_instruction_set_hooks(GArchInstruction *instr, const instr_hook_fc hooks[IPH_COUNT])
{
- instr->hooks = hooks;
+ InstrProcessHook i; /* Boucle de parcours */
+
+ for (i = 0; i < IPH_COUNT; i++)
+ g_object_set_data(G_OBJECT(instr), _hook_names[i], hooks[i]);
}
@@ -334,10 +347,23 @@ void g_arch_instruction_set_hooks(GArchInstruction *instr, const instr_hook_fc h
void g_arch_instruction_call_hook(GArchInstruction *instr, InstrProcessHook type, GArchProcessor *proc, GProcContext *context, GExeFormat *format)
{
+ instr_hook_fc hook;
+
assert(type < IPH_COUNT);
- if (instr->hooks != NULL && instr->hooks[type] != NULL)
- instr->hooks[type](instr, proc, context, format);
+ hook = g_object_get_data(G_OBJECT(instr), _hook_names[type]);
+
+ if (hook != NULL)
+ {
+ /**
+ * Comme ce genre d'appel n'est effectué normalement qu'une seule fois
+ * par instruction, on libère la mémoire au moment de cet unique appel.
+ */
+ g_object_set_data(G_OBJECT(instr), _hook_names[type], NULL);
+
+ hook(instr, proc, context, format);
+
+ }
}