zodiacon / windowskernelprogrammingbook2e

Samples for the book Windows Kernel Programming, 2nd edition
MIT License
293 stars 83 forks source link

CH8: KMelody blocks when the client melody is trying to closeHandle #26

Closed tonychen007 closed 1 year ago

tonychen007 commented 1 year ago

When the client melody calls closeHandle, the kmelody method will block:

PlaybackState.cpp: status = KeWaitForMultipleObjects(2, objects, WaitAny, ...

I found stop is never call. So I added in KMelody.cpp::MelodyCreateClose:

NTSTATUS MelodyCreateClose(PDEVICE_OBJECT DeviceObject, PIRP Irp) {
    auto status = STATUS_SUCCESS;
    UCHAR func = IoGetCurrentIrpStackLocation(Irp)->MajorFunction;

    if (func == IRP_MJ_CREATE) {
        //
        // create the "playback" thread (if needed)
        //
        status = g_State->Start(DeviceObject);
    }
    if (func == IRP_MJ_CLOSE) {
        g_State->Stop();
    }

    return CompleteRequest(Irp, status);
}

It solves the issue

zodiacon commented 1 year ago

Thank you :)