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


Before Posting...

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

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:

Initializing shared memory at startup

IgnoreExceptionIgnoreException Member Posts: 47
edited October 2023 in NTDEV

I am making a filter driver that needs to create a shared memory region however I noticed adding this to my DriverEntry function results in it failing. I then tried moving it to my Filter_EvtDeviceAdd function since that loads later but that also fails. However, when my VM is already running and then I start my driver it works fine which is why I think its an issue where I can't create a shared memory region / IoNotificationEvent during the startup process because its too early. Not sure if this is correct but I would like a solution so that it can always work. Here is the code that fails and I would greatly appreciate anyone who explains how this is typically handled since I wan't to ensure I use the best solution when working with things as sensitive as drivers.

        RtlInitUnicodeString(&eventUniName, L"\\BaseNamedObjects\\MyCustomEvent");
        g_hEvent = IoCreateNotificationEvent(&eventUniName, &g_hEvent);
        if (!g_hEvent) {
            DebugMessage("Failed g_hEvent \n");

        // Initialize section name and create shared section
        sectionSize.QuadPart = sizeof(INPUT_DATA);
        RtlInitUnicodeString(&sectionUniName, L"\\BaseNamedObjects\\SharedSection");
        InitializeObjectAttributes(&objAttributes, &sectionUniName, OBJ_KERNEL_HANDLE, NULL, NULL);

        if (!NT_SUCCESS(status = ZwCreateSection(&g_hSection, PAGE_READWRITE, &objAttributes, &sectionSize, PAGE_READWRITE, SEC_COMMIT, NULL))) {
            DebugMessage("Failed mouse ZwCreateSection \n");
        else if (!NT_SUCCESS(status = ZwMapViewOfSection(g_hSection, NtCurrentProcess(), &g_pSharedBuffer, 0, sizeof(INPUT_DATA), NULL, &viewSize, ViewUnmap, 0, PAGE_READWRITE))) {
            DebugMessage("Failed mouse ZwMapViewOfSection \n");
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!
Kernel Debugging 13-17 May 2024 Live, Online
Developing Minifilters 1-5 Apr 2024 Live, Online
Internals & Software Drivers 11-15 Mar 2024 Live, Online
Writing WDF Drivers 20-24 May 2024 Live, Online