From 4fb2ac107092671fe27fc3ebf9fc86dff7c3ec19 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Tue, 22 Aug 2017 23:38:30 +0200 Subject: Reorganized the global variables for the work queue singleton. --- ChangeLog | 31 ++++++++++++++++ plugins/pychrysa/pychrysa.c | 8 ----- src/analysis/disass/area.c | 1 + src/analysis/disass/disassembler.c | 1 + src/analysis/disass/fetch.c | 1 + src/analysis/loading.c | 1 + src/analysis/project.c | 1 + src/core/Makefile.am | 1 + src/core/core.c | 5 +++ src/core/global.c | 73 +++++++++++++++++++++++++++++++++++++ src/core/global.h | 40 +++++++++++++++++++++ src/format/dex/dex.c | 1 + src/format/dex/pool.c | 1 + src/format/elf/symbols.c | 1 + src/glibext/delayed.c | 74 ++++++++------------------------------ src/glibext/delayed.h | 10 ++---- src/gui/panels/errors.c | 2 +- src/main.c | 3 +- 18 files changed, 177 insertions(+), 78 deletions(-) create mode 100644 src/core/global.c create mode 100644 src/core/global.h diff --git a/ChangeLog b/ChangeLog index c56cc94..d88cfe6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,34 @@ +17-08-22 Cyrille Bagard + + * plugins/pychrysa/pychrysa.c: + * src/analysis/disass/area.c: + * src/analysis/disass/disassembler.c: + * src/analysis/disass/fetch.c: + * src/analysis/loading.c: + * src/analysis/project.c: + Update code. + + * src/core/Makefile.am: + Add the 'global.[ch]' files to libcore_la_SOURCES. + + * src/core/core.c: + Reorganize the global variables for the work queue singleton. + + * src/core/global.c: + * src/core/global.h: + New entries: store and provide the global work queue. + + * src/format/dex/dex.c: + * src/format/dex/pool.c: + * src/format/elf/symbols.c: + * src/glibext/delayed.c: + * src/glibext/delayed.h: + Reorganize the global variables for the work queue singleton. + + * src/gui/panels/errors.c: + * src/main.c: + Update code. + 17-08-21 Cyrille Bagard * configure.ac: diff --git a/plugins/pychrysa/pychrysa.c b/plugins/pychrysa/pychrysa.c index bcd2284..f4cfe90 100644 --- a/plugins/pychrysa/pychrysa.c +++ b/plugins/pychrysa/pychrysa.c @@ -392,14 +392,6 @@ PyMODINIT_FUNC PyInit_pychrysalide(void) init_work_queue(NULL/* !! */); #endif - /** - * On évite d'initialiser deux fois... - */ - if (get_work_queue() == NULL) - init_work_queue(NULL/* !! */); - - //////////////////////// - diff --git a/src/analysis/disass/area.c b/src/analysis/disass/area.c index 5c70e72..f97a5c9 100644 --- a/src/analysis/disass/area.c +++ b/src/analysis/disass/area.c @@ -37,6 +37,7 @@ #include "../../arch/raw.h" #include "../../common/bits.h" #include "../../common/sort.h" +#include "../../core/global.h" #include "../../format/format.h" #include "../../glibext/delayed-int.h" #include "../../gui/panels/log.h" diff --git a/src/analysis/disass/disassembler.c b/src/analysis/disass/disassembler.c index fc95a96..976ef11 100644 --- a/src/analysis/disass/disassembler.c +++ b/src/analysis/disass/disassembler.c @@ -37,6 +37,7 @@ #include "instructions.h" #include "routines.h" +#include "../../core/global.h" #include "../../format/format.h" #include "../../glibext/delayed-int.h" #include "../../glibext/generators/prologue.h" diff --git a/src/analysis/disass/fetch.c b/src/analysis/disass/fetch.c index 586c084..c33cad9 100644 --- a/src/analysis/disass/fetch.c +++ b/src/analysis/disass/fetch.c @@ -31,6 +31,7 @@ #include "area.h" +#include "../../core/global.h" #include "../../format/format.h" #include "../../glibext/delayed-int.h" diff --git a/src/analysis/loading.c b/src/analysis/loading.c index bfc62aa..254939b 100644 --- a/src/analysis/loading.c +++ b/src/analysis/loading.c @@ -25,6 +25,7 @@ #include "../core/formats.h" +#include "../core/global.h" #include "../glibext/delayed-int.h" #include "../gui/panels/log.h" diff --git a/src/analysis/project.c b/src/analysis/project.c index 5c5c653..83b1ee4 100644 --- a/src/analysis/project.c +++ b/src/analysis/project.c @@ -35,6 +35,7 @@ #include "loading.h" #include "../common/xml.h" +#include "../core/global.h" #include "../core/params.h" #include "../glibext/signal.h" #include "../gtkext/easygtk.h" diff --git a/src/core/Makefile.am b/src/core/Makefile.am index f76f520..26d43a5 100755 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -5,6 +5,7 @@ libcore_la_SOURCES = \ collections.h collections.c \ core.h core.c \ formats.h formats.c \ + global.h global.c \ params.h params.c \ processors.h processors.c diff --git a/src/core/core.c b/src/core/core.c index b382e34..5b60384 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -35,6 +35,7 @@ #include "collections.h" #include "formats.h" +#include "global.h" #include "params.h" #include "processors.h" #include "../analysis/db/keymgn.h" @@ -61,6 +62,7 @@ bool load_all_basic_components(void) { static bool result = false; /* Bilan à retourner */ char *cfgdir; /* Répertoire de configuration */ + GWorkQueue *queue; /* Singleton pour tâches */ /** * On mémorise les passages réussis. @@ -91,6 +93,9 @@ bool load_all_basic_components(void) result &= g_generic_config_read(get_main_configuration()); + queue = g_work_queue_new(); + set_work_queue(queue); + result &= init_segment_content_hash_table(); result &= load_hard_coded_processors_definitions(); diff --git a/src/core/global.c b/src/core/global.c new file mode 100644 index 0000000..86c7e5f --- /dev/null +++ b/src/core/global.c @@ -0,0 +1,73 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * global.c - conservation et accès aux variables globales + * + * Copyright (C) 2017 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Foobar. If not, see . + */ + + +#include "global.h" + + +#include + + + +/* Gestionnaire de tâches parallèles */ +static GWorkQueue *_queue = NULL; + + + +/****************************************************************************** +* * +* Paramètres : queue = nouveau gestionnaire à mémoriser ou NULL. * +* * +* Description : Définit le gestionnaire de traitements parallèles courant. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void set_work_queue(GWorkQueue *queue) +{ + assert(_queue == NULL); + + _queue = queue; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit le gestionnaire de traitements parallèles courant. * +* * +* Retour : Gestionnaire de traitements parallèles courant. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GWorkQueue *get_work_queue(void) +{ + return _queue; + +} diff --git a/src/core/global.h b/src/core/global.h new file mode 100644 index 0000000..d29cb76 --- /dev/null +++ b/src/core/global.h @@ -0,0 +1,40 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * global.h - prototypes pour la conservation et l'accès aux variables globales + * + * Copyright (C) 2017 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Foobar. If not, see . + */ + + +#ifndef _CORE_GLOBAL_H +#define _CORE_GLOBAL_H + + +#include "../glibext/delayed.h" + + + +/* Définit le gestionnaire de traitements parallèles courant. */ +void set_work_queue(GWorkQueue *); + +/* Fournit le gestionnaire de traitements parallèles courant. */ +GWorkQueue *get_work_queue(void); + + + +#endif /* _CORE_GLOBAL_H */ diff --git a/src/format/dex/dex.c b/src/format/dex/dex.c index b0b32a7..c2eaece 100755 --- a/src/format/dex/dex.c +++ b/src/format/dex/dex.c @@ -32,6 +32,7 @@ #include "dex-int.h" #include "pool.h" +#include "../../core/global.h" #include "../../plugins/pglist.h" diff --git a/src/format/dex/pool.c b/src/format/dex/pool.c index 0180b19..a561a8f 100644 --- a/src/format/dex/pool.c +++ b/src/format/dex/pool.c @@ -35,6 +35,7 @@ #include "loading.h" #include "../mangling/demangler.h" #include "../mangling/dex/context.h" +#include "../../core/global.h" diff --git a/src/format/elf/symbols.c b/src/format/elf/symbols.c index 62fae58..c6056ca 100644 --- a/src/format/elf/symbols.c +++ b/src/format/elf/symbols.c @@ -42,6 +42,7 @@ #include "../mangling/demangler.h" #include "../../arch/raw.h" #include "../../common/extstr.h" +#include "../../core/global.h" #include "../../core/params.h" #include "../../gui/panels/log.h" diff --git a/src/glibext/delayed.c b/src/glibext/delayed.c index ddd84a0..6251766 100644 --- a/src/glibext/delayed.c +++ b/src/glibext/delayed.c @@ -31,6 +31,7 @@ #include "delayed-int.h" +#include "../gui/core/global.h" @@ -72,8 +73,6 @@ typedef struct _GWorkGroup wgroup_id_t id; /* Identifiant de travaux menés*/ - GtkStatusStack *status; /* Barre de statut principale */ - GDelayedWork *works; /* Tâches à mener à bien */ GMutex mutex; /* Verrou pour l'accès */ GCond cond; /* Réveil pour un traitement */ @@ -113,7 +112,7 @@ static void g_work_group_dispose(GWorkGroup *); static void g_work_group_finalize(GWorkGroup *); /* Crée un nouveau thread dédié à un type de travaux donné. */ -static GWorkGroup *g_work_group_new(wgroup_id_t, GtkStatusStack *); +static GWorkGroup *g_work_group_new(wgroup_id_t); /* Fournit l'identifiant associé à un groupe de travail. */ static wgroup_id_t g_work_group_get_id(const GWorkGroup *); @@ -143,11 +142,9 @@ struct _GWorkQueue { GObject parent; /* A laisser en premier */ - GtkStatusStack *status; /* Barre de statut principale */ - wgroup_id_t generator; /* Générateur d'identifiants */ - GWorkGroup **groups; /* Files de traitement */ + GWorkGroup **groups; /* Files de traitement */ size_t groups_count; /* Nombre de files internes */ GMutex mutex; /* Verrou pour l'accès */ @@ -446,8 +443,6 @@ static void g_work_group_dispose(GWorkGroup *group) for (i = 0; i < group->threads_count; i++) g_thread_join(group->threads[i]); - g_object_unref(group->status); - while (!dl_list_empty(group->works)) { work = group->works; @@ -490,8 +485,7 @@ static void g_work_group_finalize(GWorkGroup *group) /****************************************************************************** * * -* Paramètres : type = type dont seront marqués tous les travaux donnés. * -* status = barre de statut à tenir informée. * +* Paramètres : type = type dont seront marqués tous les travaux donnés. * * * * Description : Crée un nouveau thread dédié à un type de travaux donné. * * * @@ -501,7 +495,7 @@ static void g_work_group_finalize(GWorkGroup *group) * * ******************************************************************************/ -static GWorkGroup *g_work_group_new(wgroup_id_t id, GtkStatusStack *status) +static GWorkGroup *g_work_group_new(wgroup_id_t id) { GWorkGroup *result; /* Traiteur à retourner */ @@ -509,12 +503,6 @@ static GWorkGroup *g_work_group_new(wgroup_id_t id, GtkStatusStack *status) result->id = id; - if (status != NULL) - { - result->status = status; - g_object_ref(status); - } - return result; } @@ -582,6 +570,7 @@ static void g_work_group_schedule(GWorkGroup *group, GDelayedWork *work) static void *g_work_group_process(GWorkGroup *group) { GDelayedWork *work; /* Traitement à mener */ + GtkStatusStack *status; /* Zone d'info éventuelle */ while (1) { @@ -601,7 +590,8 @@ static void *g_work_group_process(GWorkGroup *group) g_mutex_unlock(&group->mutex); - g_delayed_work_process(work, group->status); + status = get_global_status(); + g_delayed_work_process(work, status); g_object_unref(G_OBJECT(work)); @@ -774,8 +764,6 @@ static void g_work_queue_dispose(GWorkQueue *queue) { size_t i; /* Boucle de parcours */ - g_object_unref(G_OBJECT(queue->status)); - g_mutex_lock(&queue->mutex); for (i = 0; i < queue->groups_count; i++) @@ -814,53 +802,21 @@ static void g_work_queue_finalize(GWorkQueue *queue) /****************************************************************************** * * -* Paramètres : status = barre de statut à tenir informée. * -* * -* Description : Procède au chargement du gestionnaire d'analyse différées. * -* * -* Retour : true pour indiquer un chargement réussi, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool init_work_queue(GtkStatusStack *status) -{ - GWorkQueue *queue; /* Singleton à mettre en place */ - - queue = g_object_new(G_TYPE_WORK_QUEUE, NULL); - - queue->status = status; - - if (status != NULL) - g_object_ref(G_OBJECT(queue->status)); - - if (queue != NULL) - _get_work_queue(queue); - - return (queue != NULL); - -} - - -/****************************************************************************** -* * -* Paramètres : queue = nouveau gestionnaire à mémoriser ou NULL. * +* Paramètres : - * * * -* Description : Fournit le gestionnaire de traitements parallèles courant. * +* Description : Créé un nouveau gestionnaire de tâches parallèles. * * * -* Retour : Gestionnaire de traitements parallèles courant. * +* Retour : Gestionnaire de traitements mis en place. * * * * Remarques : - * * * ******************************************************************************/ -GWorkQueue *_get_work_queue(GWorkQueue *queue) +GWorkQueue *g_work_queue_new(void) { - static GWorkQueue *result = NULL; /* Singleton à retourner */ + GWorkQueue *result; /* Instance à retourner */ - if (queue != NULL) - result = queue; + result = g_object_new(G_TYPE_WORK_QUEUE, NULL); return result; @@ -900,7 +856,7 @@ static GWorkGroup *g_work_queue_ensure_group_exists(GWorkQueue *queue, wgroup_id queue->groups = (GWorkGroup **)realloc(queue->groups, queue->groups_count * sizeof(GWorkGroup *)); - result = g_work_group_new(id, queue->status); + result = g_work_group_new(id); queue->groups[queue->groups_count - 1] = result; } diff --git a/src/glibext/delayed.h b/src/glibext/delayed.h index 277d958..d3e084d 100644 --- a/src/glibext/delayed.h +++ b/src/glibext/delayed.h @@ -86,17 +86,11 @@ typedef unsigned long long wgroup_id_t; #define DEFAULT_WORK_GROUP 0 -#define get_work_queue() _get_work_queue(NULL) - - /* Indique le type défini pour le gestionnaire des travaux différés. */ GType g_work_queue_get_type(void); -/* Procède au chargement du gestionnaire d'analyse différées. */ -bool init_work_queue(GtkStatusStack *); - -/* Fournit le gestionnaire de traitements parallèles courant. */ -GWorkQueue *_get_work_queue(GWorkQueue *); +/* Créé un nouveau gestionnaire de tâches parallèles. */ +GWorkQueue *g_work_queue_new(void); /* Constitue un nouveau groupe de travail. */ wgroup_id_t g_work_queue_define_work_group(GWorkQueue *); diff --git a/src/gui/panels/errors.c b/src/gui/panels/errors.c index 7d7226f..842f0ec 100644 --- a/src/gui/panels/errors.c +++ b/src/gui/panels/errors.c @@ -34,6 +34,7 @@ #include "panel-int.h" +#include "../../core/global.h" #include "../../format/format.h" #include "../../gtkext/support.h" @@ -469,7 +470,6 @@ static void update_panel_with_binary_errors(GErrorPanel *panel, GLoadedBinary *b g_signal_connect(update, "work-completed", G_CALLBACK(update_error_panel_summary), panel); - if (get_work_queue() != NULL) /* FIXME */ g_work_queue_schedule_work(get_work_queue(), G_DELAYED_WORK(update), DEFAULT_WORK_GROUP); } diff --git a/src/main.c b/src/main.c index 27f5f94..46eb3e8 100644 --- a/src/main.c +++ b/src/main.c @@ -36,6 +36,7 @@ #include "analysis/db/server.h" #include "common/xdg.h" #include "core/core.h" +#include "core/global.h" #include "core/params.h" #include "glibext/delayed.h" #include "gui/editor.h" @@ -255,8 +256,6 @@ int main(int argc, char **argv) if (!batch_mode) gtk_widget_show_now(editor); - init_work_queue(get_global_status()); - init_all_plugins(G_OBJECT(editor)); config = get_main_configuration(); -- cgit v0.11.2-87-g4458