Driver: fortstat: Don't remove process from map when iterating it

This commit is contained in:
Nodir Temirkhodjaev 2023-04-14 12:08:56 +03:00
parent af927793b2
commit a3697289d0
2 changed files with 22 additions and 9 deletions

View File

@ -61,13 +61,18 @@ static PFORT_STAT_PROC fort_stat_proc_get(PFORT_STAT stat, UINT32 process_id, to
static void fort_stat_proc_free(PFORT_STAT stat, PFORT_STAT_PROC proc)
{
tommy_hashdyn_remove_existing(&stat->procs_map, (tommy_hashdyn_node *) proc);
/* Add to free chain */
proc->next = stat->proc_free;
stat->proc_free = proc;
}
static void fort_stat_proc_del(PFORT_STAT stat, PFORT_STAT_PROC proc)
{
tommy_hashdyn_remove_existing(&stat->procs_map, (tommy_hashdyn_node *) proc);
fort_stat_proc_free(stat, proc);
}
static PFORT_STAT_PROC fort_stat_proc_add(PFORT_STAT stat, UINT32 process_id)
{
const tommy_key_t proc_hash = fort_stat_proc_hash(process_id);
@ -445,9 +450,17 @@ static void fort_stat_clear(PFORT_STAT stat)
KLOCK_QUEUE_HANDLE lock_queue;
KeAcquireInStackQueuedSpinLock(&stat->lock, &lock_queue);
/* Clear processes active list */
fort_stat_proc_active_clear(stat);
/* Clear processes map */
if (tommy_hashdyn_count(&stat->procs_map) > 0) {
tommy_hashdyn_foreach_node_arg(&stat->procs_map, &fort_stat_proc_free, stat);
tommy_hashdyn_done(&stat->procs_map);
tommy_hashdyn_init(&stat->procs_map);
}
/* Close flows */
tommy_hashdyn_foreach_node(&stat->flows_map, &fort_flow_close);
KeReleaseInStackQueuedSpinLock(&lock_queue);
@ -609,7 +622,7 @@ FORT_API void fort_stat_dpc_traf_flush(PFORT_STAT stat, UINT16 proc_count, PCHAR
/* The process is inactive */
*out_proc |= 1;
fort_stat_proc_free(stat, proc);
fort_stat_proc_del(stat, proc);
} else {
proc->active = FALSE;

View File

@ -25,17 +25,17 @@ typedef struct fort_stat_proc
tommy_key_t proc_hash; /* tommy_hashdyn_node::index */
UINT16 proc_index : 15; /* Synchronize with FORT_PROC_COUNT_MAX! */
UINT16 active : 1;
UINT16 refcount;
#if defined(_WIN64)
UINT32 process_id;
#else
FORT_TRAF traf;
#endif
UINT16 proc_index : 15; /* Synchronize with FORT_PROC_COUNT_MAX! */
UINT16 active : 1;
UINT16 refcount;
struct fort_stat_proc *next_active;
} FORT_STAT_PROC, *PFORT_STAT_PROC;