summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2017-08-22 21:38:30 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2017-08-22 21:38:30 (GMT)
commit4fb2ac107092671fe27fc3ebf9fc86dff7c3ec19 (patch)
tree92cf5860302b4ba485c85fef3062f1179a978560 /src
parent0f73369ad9cd15cb17ae44aadfc035cb12778b93 (diff)
Reorganized the global variables for the work queue singleton.
Diffstat (limited to 'src')
-rw-r--r--src/analysis/disass/area.c1
-rw-r--r--src/analysis/disass/disassembler.c1
-rw-r--r--src/analysis/disass/fetch.c1
-rw-r--r--src/analysis/loading.c1
-rw-r--r--src/analysis/project.c1
-rwxr-xr-xsrc/core/Makefile.am1
-rw-r--r--src/core/core.c5
-rw-r--r--src/core/global.c73
-rw-r--r--src/core/global.h40
-rwxr-xr-xsrc/format/dex/dex.c1
-rw-r--r--src/format/dex/pool.c1
-rw-r--r--src/format/elf/symbols.c1
-rw-r--r--src/glibext/delayed.c74
-rw-r--r--src/glibext/delayed.h10
-rw-r--r--src/gui/panels/errors.c2
-rw-r--r--src/main.c3
16 files changed, 146 insertions, 70 deletions
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 <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "global.h"
+
+
+#include <assert.h>
+
+
+
+/* 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 <http://www.gnu.org/licenses/>.
+ */
+
+
+#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();