blue screen using ksmethod in avstream driver

I am new to driver development, and currently, I am developping a virtual AVStream video capture driver following avssamp from DDK. I used ksevent and ksmethod in the driver. The situation is that the driver generate event to notifiy client, and the
as the client received the event, it called ::KsMethod. The event notification is successful, but as the client ran ::KsMethod, the system crashed. What is KsMethod do is to send some data to the driver. Below is some code. Thanks for your help.

Driver part:

DEFINE_KSMETHOD_ITEM
(
KSMETHOD_ID,
KSMETHOD_TYPE_READ,
&FMethod,
sizeof(KSMETHOD),
nByteCount,
NULL
)

Client part:

//method
KSMETHOD Method;
ULONG nBytesReturned;

Method.Set = KSMETHODSETID_ID;
Method.Id = KSMETHOD_ID;
Method.Flags = KSMETHOD_TYPE_SEND;

hr = pIKsControl -> KsMethod (&Method, sizeof (Method),
pData, nByteCount, &nBytesReturned);

In the defination of KsMethod, I even did not use the data buffer received from client, but the system still crashed.

I appreciate any help you provide.

Please enable kernel crash dumps and then analyze it with WinDbg. Load the
crash dump into windbg and type “!analyze -v” on the command window. This
will provide you a lot of debug information you can start with.

Have a nice day
GV

wrote in message news:xxxxx@ntdev…
>I am new to driver development, and currently, I am developping a virtual
>AVStream video capture driver following avssamp from DDK. I used ksevent
>and ksmethod in the driver. The situation is that the driver generate event
>to notifiy client, and the
> as the client received the event, it called ::KsMethod. The event
> notification is successful, but as the client ran ::KsMethod, the system
> crashed. What is KsMethod do is to send some data to the driver. Below is
> some code. Thanks for your help.
>
> Driver part:
>
>
> DEFINE_KSMETHOD_ITEM
> (
> KSMETHOD_ID,
> KSMETHOD_TYPE_READ,
> &FMethod,
> sizeof(KSMETHOD),
> nByteCount,
> NULL
> )
>
>
> Client part:
>
>
> //method
> KSMETHOD Method;
> ULONG nBytesReturned;
>
>
> Method.Set = KSMETHODSETID_ID;
> Method.Id = KSMETHOD_ID;
> Method.Flags = KSMETHOD_TYPE_SEND;
>
>
> hr = pIKsControl -> KsMethod (&Method, sizeof (Method),
> pData, nByteCount, &nBytesReturned);
>
>
> In the defination of KsMethod, I even did not use the data buffer received
> from client, but the system still crashed.
>
>
> I appreciate any help you provide.
>
>
>
>

Thank you very much for your reply. But I am new to driver development, so could you please tell me how to enable kernel crash dumps, or some helpful link referring using kernel crash dump and windbg? Thank you.

You enable crash dumps by going to control panel->system, advanced tab,
startup and recovery settings, write debugging information. Use “kernl
memory dump” or “full memory dump”. The dump gets created in
c:\windows\memory.dmp.

Windbg is freely available on MS website. I suggest you to subscribe to the
windbg newsgroups as well, i think there is one on OSR (not sure), otherwise
microsfot.public.windbg.

Just a bit of advice, learning driver development has a pretty steep
learning curve. The usual suggestion is to take one of the classes for
driver development. A colleague working on windows drivers is pretty useful
too (mailing lists like ntdev are *extremely* useful, but at the beginning
it’s very difficult to help with e-mail :frowning: )

Hope it helps
GV

wrote in message news:xxxxx@ntdev…
> Thank you very much for your reply. But I am new to driver development, so
> could you please tell me how to enable kernel crash dumps, or some helpful
> link referring using kernel crash dump and windbg? Thank you.
>

Thank you so much for your information. I followed your instruction, and got those error messages.

xxxxx@gmail.com wrote:

I am new to driver development, and currently, I am developping a virtual AVStream video capture driver following avssamp from DDK. I used ksevent and ksmethod in the driver. The situation is that the driver generate event to notifiy client, and the
as the client received the event, it called ::KsMethod. The event notification is successful, but as the client ran ::KsMethod, the system crashed. What is KsMethod do is to send some data to the driver. Below is some code. Thanks for your help.

Driver part:

DEFINE_KSMETHOD_ITEM
(
KSMETHOD_ID,
KSMETHOD_TYPE_READ,
&FMethod,
sizeof(KSMETHOD),
nByteCount,
NULL
)

The most obvious thing to check is the signature of the FMethod
function. DEFINE_KSMETHOD_ITEM uses a cast to assign the handler
pointer, so you won’t get an error if the function doesn’t match. Your
function must look like this:
NTSTATUS FMethod( PIRP Irp, PKSIDENTIFIER Request, PVOID Data );


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Thanks for all your reply. I used windbg to look into the dump file, and found where is the error code. I declared the method in filter descriptor. Below is the code of FMethod:

NTSTATUS CCaptureFilter::FMethod( PIRP pIrp, PKSIDENTIFIER Request, PVOID pData )
{
NTSTATUS ntStatus = STATUS_SUCCESS;

// Get the filter this method corresponds to
PKSFILTER pKsFilter = KsGetFilterFromIrp( pIrp );
if( pKsFilter == NULL )
return STATUS_INVALID_PARAMETER;

PKSPIN pKsPin = KsGetPinFromIrp(pIrp);
if(pKsPin == NULL)
{
pKsPin = KsFilterGetFirstChildPin (pKsFilter, 0);
ASSERT(pKsPin != NULL); ---------- error code
}

return ntStatus;
}

The error code shows that I could not get KSPIN object either from pIrp or from KsFilterGetFirstChildPin. Failed from pIrp is because the ksmethod is described in filter descriptor, but I do not why I could not get the KSPIN object from KsFilterGetFirstChildPin.

Thank you for your help.

xxxxx@gmail.com wrote:

Thanks for all your reply. I used windbg to look into the dump file, and found where is the error code. I declared the method in filter descriptor. Below is the code of FMethod:

NTSTATUS CCaptureFilter::FMethod( PIRP pIrp, PKSIDENTIFIER Request, PVOID pData )

I assume this is a static method, otherwise it shouldn’t have compiled.

PKSPIN pKsPin = KsGetPinFromIrp(pIrp);
if(pKsPin == NULL)
{
pKsPin = KsFilterGetFirstChildPin (pKsFilter, 0);
ASSERT(pKsPin != NULL); ---------- error code
}

return ntStatus;
}

The error code shows that I could not get KSPIN object either from pIrp or from KsFilterGetFirstChildPin. Failed from pIrp is because the ksmethod is described in filter descriptor, but I do not why I could not get the KSPIN object from KsFilterGetFirstChildPin.

Is it possible the method call is coming in before the pins have been
created? Have you added the filter to a graph before you call the method?


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Thanks for your reply. I thought this point. I should describe the whole situation. The driver developed is running in GraphEdit to get tested, so the pin is created in the GraphEdit too. The client is running to try to send data to the driver running in GraphEdit. The client is notified by event from the driver. I have some problem to get the client notified. The client just creates the filter, no pin instantiated from the filter. Since there are two filters created, one is in GraphEdit, the other is in the client, the driver goes through each filter instantiated to generate the event, so that the client gets notified, otherwise, the client could not be notified. As the client receives the event, it calls KsMethod to send the data to the driver. I think KsFilterGetFirstChildPin function return the KsPin object no matter it was created in GraphEdit or in client. Maybe I was wrong. If I was wrong, should I build another filter graph in client to get the pin instantiated? Thank you.

Tim, you are right. I solved the problem just like get the client to be notified. Thank you very much.

xxxxx@gmail.com wrote:

Thanks for your reply. I thought this point. I should describe the whole situation. The driver developed is running in GraphEdit to get tested, so the pin is created in the GraphEdit too. The client is running to try to send data to the driver running in GraphEdit. The client is notified by event from the driver. I have some problem to get the client notified. The client just creates the filter, no pin instantiated from the filter. Since there are two filters created, one is in GraphEdit, the other is in the client, the driver goes through each filter instantiated to generate the event, so that the client gets notified, otherwise, the client could not be notified. As the client receives the event, it calls KsMethod to send the data to the driver. I think KsFilterGetFirstChildPin function return the KsPin object no matter it was created in GraphEdit or in client. Maybe I was wrong. If I was wrong, should I build another filter graph in client to get the pin instantiated?

I see you already solved your problem, but that won’t stop me from
pointing out the solution I would have chosen.

If you need to issue properties to a filter that might not yet have any
pins created, then the obvious solution is not to fetch a pin in your
property handler. If the property applies to a pin, then the client
must instantiate a pin. If the property applies to the filter, then
don’t even TRY to fetch a pin in the property handler.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.