Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTFSD

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

Problem about making kernel dll shared data segment safe

ILBPNSILBPNS Member Posts: 11

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?

Comments

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 8,704

    Could somebody tell me what is the problem?

    Hmmmm... You have a bug in your code??

    Just guessin'

    Peter

    Peter Viscarola
    OSR
    @OSRDrivers

  • ILBPNSILBPNS Member Posts: 11

    @Peter_Viscarola_(OSR) said:

    Could somebody tell me what is the problem?

    Hmmmm... You have a bug in your code??

    Just guessin'

    Peter

    I've solved this problem. It's not the problem of my code, but I didn't realize that
    some Irp will complete in file system because they are written in page buffer and a new
    Irp will be created later. That's the reason why I can not catch the Irp that I have put
    int the table.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Internals & Software Drivers 15 November 2021 Live, Online
Writing WDF Drivers 24 January 2022 Live, Online
Developing Minifilters 7 February 2022 Live, Online
Kernel Debugging 21 March 2022 Live, Online