diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2024-01-21 22:36:47 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2024-01-21 22:36:47 (GMT) |
commit | 0ff1e52622828663d01f98c97f2cd8eccb8facf8 (patch) | |
tree | 88b5fcf2412f863276876d0b8ad8db91903f3758 /src/analysis/scan/matches/pending.c | |
parent | 0fac40d5a5752e8d7b92f57ea3cfa089f13a2d1f (diff) |
Refactor the scan match storage.
Diffstat (limited to 'src/analysis/scan/matches/pending.c')
-rw-r--r-- | src/analysis/scan/matches/pending.c | 150 |
1 files changed, 111 insertions, 39 deletions
diff --git a/src/analysis/scan/matches/pending.c b/src/analysis/scan/matches/pending.c index 57c63d7..c653257 100644 --- a/src/analysis/scan/matches/pending.c +++ b/src/analysis/scan/matches/pending.c @@ -33,6 +33,8 @@ + + /* ------------------------- MEMORISATION D'UNE ZONE BORNEE ------------------------- */ @@ -48,6 +50,8 @@ static int compare_match_area(const match_area_t *, const match_area_t *); + + /* ---------------------------------------------------------------------------------- */ /* MEMORISATION D'UNE ZONE BORNEE */ /* ---------------------------------------------------------------------------------- */ @@ -55,6 +59,104 @@ static int compare_match_area(const match_area_t *, const match_area_t *); /****************************************************************************** * * +* Paramètres : allocator = allocateur dédié à l'ensemble de zones. * +* start = point de départ d'une nouvelle correspondance. * +* length = taille de la zone couverte. * +* * +* Description : Crée une nouvelle structure de suivi de correspondance. * +* * +* Retour : Structure initialisée mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static match_area_t *create_match_area(GUMemCache *allocator, phys_t start, phys_t length) +{ + match_area_t *result; /* Zone à retourner */ + + result = g_umem_cache_alloc(allocator); + + DL_LIST_ITEM_INIT(&result->link); + + result->start = start; + result->end = start + length; + + assert(matches->content_start <= result->start); + assert(result->end <= matches->content_end); + + result->ttl = 1; + + result->has_mod_path = false; + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : allocator = allocateur dédié à l'ensemble de zones. * +* start = point de départ d'une nouvelle correspondance. * +* length = taille de la zone couverte. * +* index = indice de construction pour le motif concerné. * +* * +* Description : Crée une nouvelle structure de suivi de correspondance. * +* * +* Retour : Structure initialisée mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static match_area_t *create_match_area_with_path(GUMemCache *allocator, phys_t start, phys_t length, size_t index) +{ + match_area_t *result; /* Zone à retourner */ + + result = g_umem_cache_alloc(allocator); + + DL_LIST_ITEM_INIT(&result->link); + + result->start = start; + result->end = start + length; + + assert(matches->content_start <= result->start); + assert(result->end <= matches->content_end); + + result->ttl = 1; + + result->mod_path_index = index; + result->has_mod_path = true; + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : area = zone de suivi à supprimer. * +* allocator = allocateur dédié à l'ensemble de zones. * +* * +* Description : Supprime une structure de suivi de correspondance. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void delete_match_area(match_area_t *area, GUMemCache *allocator) +{ + // TODO : assert(alone) + + g_umem_cache_free(allocator, area); + +} + + +/****************************************************************************** +* * * Paramètres : a = pointeur vers la première zone à analyser. * * b = pointeur vers la seconde zone à analyser. * * * @@ -114,6 +216,7 @@ void init_pending_matches(pending_matches_t *matches, const phys_t *start, const matches->content_start = *start; matches->content_end = *end; + matches->allocator = NULL; matches->areas = NULL; matches->allocated = 0; matches->used = 0; @@ -275,27 +378,12 @@ match_area_t * const *get_all_pending_matches(const pending_matches_t *matches, void add_pending_match(pending_matches_t *matches, phys_t start, phys_t length) { - match_area_t *area; /* Zone à initialiser */ - - if (matches->used == matches->allocated) - { - matches->allocated += PENDING_ALLOC_SIZE; - - matches->areas = realloc(matches->areas, matches->allocated * sizeof(match_area_t)); - - } - - area = &matches->areas[matches->used++]; + match_area_t *area; /* Nouvelle zone à intégrer */ - area->start = start; - area->end = start + length; + area = create_match_area(matches->allocator, start, length); - assert(matches->content_start <= area->start); - assert(area->end <= matches->content_end); - - area->ttl = 1; - - area->has_mod_path = false; + dl_list_add_tail(area, &matches->areas, match_area_t, link); + matches->used++; } @@ -317,28 +405,12 @@ void add_pending_match(pending_matches_t *matches, phys_t start, phys_t length) void add_pending_match_with_path(pending_matches_t *matches, phys_t start, phys_t length, size_t index) { - match_area_t *area; /* Zone à initialiser */ - - if (matches->used == matches->allocated) - { - matches->allocated += PENDING_ALLOC_SIZE; - - matches->areas = realloc(matches->areas, matches->allocated * sizeof(match_area_t)); - - } - - area = &matches->areas[matches->used++]; - - area->start = start; - area->end = start + length; - - assert(matches->content_start <= area->start); - assert(area->end <= matches->content_end); + match_area_t *area; /* Nouvelle zone à intégrer */ - area->ttl = 1; + area = create_match_area_with_path(matches->allocator, start, length, index); - area->mod_path_index = index; - area->has_mod_path = true; + dl_list_add_tail(area, &matches->areas, match_area_t, link); + matches->used++; } |