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

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

BSOD on starting service Helloworld

khanh8910khanh8910 Member Posts: 3
edited July 12 in NTDEV

Hey All,
I'm beginner. I wrote a simple "Helloworld" program in Visual Studio 2019 and builded it . I installed driver with Helloworld.sys by OSRLOADER. But when i start service, BSoD occurs.

Here is my code:

include <ntddk.h>

include <wdf.h>

DRIVER_INITIALIZE DriverEntry;

NTSTATUS DriverEntry(
In PDRIVER_OBJECT DriverObject,
In PUNICODE_STRING RegistryPath
)
{
// NTSTATUS variable to record success or failure
NTSTATUS status = STATUS_SUCCESS;

// Allocate the driver configuration object
WDF_DRIVER_CONFIG config;

// Print "Hello World" for DriverEntry
KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "KmdfHelloWorld: DriverEntry\n"));


// Finally, create the driver object
status = WdfDriverCreate(DriverObject,
    RegistryPath,
    WDF_NO_OBJECT_ATTRIBUTES,
    &config,
    WDF_NO_HANDLE
);
return status;

}

Someone please help me :(
Thanks,
Khanh

Comments

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 7,339

    You need to initialize the WDF_DRIVER_CONFIG using WDF_DRIVER_CONFIG_INIT.

    Peter

    Peter Viscarola
    OSR
    @OSRDrivers

  • khanh8910khanh8910 Member Posts: 3

    I tried but still have this error.

    include <ntddk.h>

    include <wdf.h>

    DRIVER_INITIALIZE DriverEntry;
    EVT_WDF_DRIVER_DEVICE_ADD KmdfHelloWorldEvtDeviceAdd;

    NTSTATUS
    DriverEntry(
    In PDRIVER_OBJECT DriverObject,
    In PUNICODE_STRING RegistryPath
    )
    {
    // NTSTATUS variable to record success or failure
    NTSTATUS status = STATUS_SUCCESS;

    // Allocate the driver configuration object
    WDF_DRIVER_CONFIG config;
    
    // Print "Hello World" for DriverEntry
    KdPrintEx(( DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "KmdfHelloWorld: DriverEntry\n" ));
    
    // Initialize the driver configuration object to register the
    // entry point for the EvtDeviceAdd callback, KmdfHelloWorldEvtDeviceAdd
    WDF_DRIVER_CONFIG_INIT(&config, 
                           KmdfHelloWorldEvtDeviceAdd
                           );
    
    // Finally, create the driver object
    status = WdfDriverCreate(DriverObject, 
                             RegistryPath, 
                             WDF_NO_OBJECT_ATTRIBUTES, 
                             &config, 
                             WDF_NO_HANDLE
                             );
    return status;
    

    }

    NTSTATUS
    KmdfHelloWorldEvtDeviceAdd(
    In WDFDRIVER Driver,
    Inout PWDFDEVICE_INIT DeviceInit
    )
    {
    // We're not using the driver object,
    // so we need to mark it as unreferenced
    UNREFERENCED_PARAMETER(Driver);

    NTSTATUS status;
    
    // Allocate the device object
    WDFDEVICE hDevice;    
    
    // Print "Hello World"
    KdPrintEx(( DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "KmdfHelloWorld: KmdfHelloWorldEvtDeviceAdd\n" ));
    
    // Create the device object
    status = WdfDeviceCreate(&DeviceInit, 
                             WDF_NO_OBJECT_ATTRIBUTES,
                             &hDevice
                             );
    return status;
    

    }

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 7,339

    What does the crash dump say? Post the output of !analyze -v... look at the log with !wdfkd.wdflogdump.

    Posting one message at a time in this forum is, by the way, a terrible way to learn how to write a driver. Read a book. Red the WDK docs. Take a class. But just throwing some code together and asking people online “why does this crash?” I suspect won’t be too effective in helping you learn what you’re doing.

    Peter

    Peter Viscarola
    OSR
    @OSRDrivers

  • khanh8910khanh8910 Member Posts: 3

    Thank you very much for your advice.
    Khanh

  • Martin_DrábMartin_Dráb Member - All Emails Posts: 54

    You seem not to initialize the DeviceInit structure In your EtvAddDevice. This should be done similarly to the config one in your DriverEntry.

    Also, you may run into BSOD (0x7f) if you compile the driver for Windows 8 and later versions and attempt to load it on Windows 7 (and possibly older). To solve this issue (if this is an issue for you), you should compile your driver for Windows 7.

    Martin Dráb

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 13,021

    Martin, your first sentence is wrong. The WDFDEVICE_INIT is opaque; it is initialized by the framework, is handed to the EvtDeviceAdd callback and gets passed to WdfDeviceCreate as is. You don't re-initialize it.

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

  • Martin_DrábMartin_Dráb Member - All Emails Posts: 54

    Martin, your first sentence is wrong. The WDFDEVICE_INIT is opaque; it is initialized by the framework, is handed to the EvtDeviceAdd callback and gets passed to WdfDeviceCreate as is. You don't re-initialize it.

    I do apologise for the mistake. I somewhat missed that the WDFDEVICE_INIT was passed via parameters, so I expected it needs to be initialized.

    Martin Dráb

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
Developing Minifilters 29 July 2019 OSR Seminar Space
Writing WDF Drivers 23 Sept 2019 OSR Seminar Space
Kernel Debugging 21 Oct 2019 OSR Seminar Space
Internals & Software Drivers 18 Nov 2019 Dulles, VA