I’m writing a kernel-mode dll hash table. And I want to use data_segment to share data between two filter drivers.
There is a file system filter and a volume filter. When the file system driver get an important irp, it will put the
irp pointer into the shared hash table. The volume filter will check if the irp it filtered is in the hash table, if
it is, volume filter will delete it from table.
To keep it safe, I used a spin_lock like below:
#pragma data_seg("SharedHashSet")
HashSet set;
KSPIN_LOCK PLock;
#pragma data_seg
And the operation method for hash table is like this:
//Node
typedef struct _ENTRY {
PIRP key;
struct _ENTRY* next;
}Entry , *PEntry;
//Node array
typedef struct _HASHSET {
PEntry bucket[BUCKETCAPICITY];
}HashSet, *PHashSet;
void insertValue(PIRP key)
{
KIRQL irql;
KeAcquireSpinLock(&PLock, &irql);
PEntry mEntry;
INT i = getLocation(key);
PEntry entry = set.bucket[i];
//head insert
if (entry == NULL) {
mEntry = newEntry(key, NULL);
}
else {
mEntry = newEntry(key, entry);
}
set.bucket[i] = mEntry;
KeReleaseSpinLock(&PLock, irql);
}
Now two filter drivers share a table and a lock. But, I find that volume filter may not find the irp
which file system filter already put into the table sometimes.
Could somebody tell me what is the problem?