Device Extension issue with NdisRegisterDeviceEx

0
down vote
favorite
Want to execute Two applications through Device Object. Application 1 struct looks like : `

typedef struct
{
int log;
char msg[150]
}application1;
application1 *papplication1;
`

//In application1:

application1 *context;
status = NdisRegisterDeviceEx(DriverHandle,
&ObjectAttributes,
&DeviceObject,
&NdisDeviceHandle);

/*Using above NdisRegisterDeviceEx api creating a new DeviceObject based on the following attribute.*/

ObjectAttributes.Header.Type = NDIS_OBJECT_TYPE_DEFAULT;
ObjectAttributes.Header.Revision = NDIS_DEVICE_OBJECT_ATTRIBUTES_REVISION_1;
ObjectAttributes.Header.Size = sizeof(NDIS_DEVICE_OBJECT_ATTRIBUTES);
ObjectAttributes.DeviceName = &DeviceName;
ObjectAttributes.SymbolicName = &DeviceLinkUnicodeString;
ObjectAttributes.MajorFunctions = &DispatchTable[0];
ObjectAttributes.ExtensionSize = sizeof(application1);
ObjectAttributes.DefaultSDDLString = NULL;
ObjectAttributes.DeviceClassGuid = 0;

/* If the status is SUCCESSFULL, then deviceObject is passed to
NdisGetDeviceReservedExtension(function gets a pointer to the device extension
that is associated with a device object). */
context = (application1*)NdisGetDeviceReservedExtension(DeviceObject);
if (context != NULL)
{
papplication1 = context;
}
-> The above code implementation is working fine.

My doubt is for Application2 … I created new device Device object and passed it to NdisRegisterDeviceEx. NdisRegisterDeviceEx is returning following error, I got a memory access violation Bugcheck (0x7E with the first argument 0xC0000005). “!analyze -v” tells me “Attempt to read from address 00000014”. How to fix the issue

xxxxx@gmail.com wrote:

Want to execute Two applications through Device Object. Application 1 struct looks like :

Your terminology is a bit confusing, since these are not really
“applications” in the Windows sense.

-> The above code implementation is working fine.

My doubt is for Application2 … I created new device Device object and passed it to NdisRegisterDeviceEx. NdisRegisterDeviceEx is returning following error, I got a memory access violation Bugcheck (0x7E with the first argument 0xC0000005). “!analyze -v” tells me “Attempt to read from address 00000014”. How to fix the issue

It’s interesting to me that you chose to show us the code that worked,
but not the code that didn’t work. That makes it a little hard to offer
advice.


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

>I created new device Device object and passed it to NdisRegisterDeviceEx…

No, you just pass a pointer to a PDEVICE_OBJECT, the routine creates the device object for you and writes its address to the pointer you passed. Something like:

PDEVICE_OBJECT Object;
Status = NdisRegisterDeviceEx(…,&Object,…);

I got a memory access violation Bugcheck (0x7E with the first argument 0xC0000005). “!analyze -v” tells me “Attempt to read from address 00000014”.

You passed a pointer whose value is 0x14 which is an invalid (user) address. So you get an (unhandled) exception when this pointer is dereferenced. Check your parameters.

Break with the debugger before the call is issued and check the parameters.

-> My doubt is whether it is possible to create two Device Object?
-> The issue is because of Device Object…?, If I comment app1 code implementation and
test app2 then status of NdisRegisterDeviceEx is success.

-> For understanding purpose I mentioned application1, application2.

-> In application 2 I tried by creating new device object PDEVICE_OBJECT Mpapp_deviceobj2,
and passed to NdisRegisterDeviceEx code implementation for app2 is given below.

-> I passed the same device object which is used in application 1.(just tried…)

ISSUE: I got a memory access violation Bugcheck (0x7E with the first argument
0xC0000005). “!analyze -v” tells me “Attempt to read from address 00000014”.

typedef struct
{
int log;
char msg[150]
}application2;
application2 *papplication2;
`

//In application2:

/*Using above NdisRegisterDeviceEx api creating a new DeviceObject
based on the following attribute.*/

ObjectAttributes.Header.Type = NDIS_OBJECT_TYPE_DEFAULT;
ObjectAttributes.Header.Revision = NDIS_DEVICE_OBJECT_ATTRIBUTES_REVISION_1;
ObjectAttributes.Header.Size = sizeof(NDIS_DEVICE_OBJECT_ATTRIBUTES);
ObjectAttributes.DeviceName = &DeviceName;
ObjectAttributes.SymbolicName = &DeviceLinkUnicodeString;
ObjectAttributes.MajorFunctions = &DispatchTable[0];
ObjectAttributes.ExtensionSize = sizeof(application2);
ObjectAttributes.DefaultSDDLString = NULL;
ObjectAttributes.DeviceClassGuid = 0;

application2 *context;
status = NdisRegisterDeviceEx(DriverHandle,
&ObjectAttributes,
&DeviceObject, /* Passed new new DeviceObj and same which is used inapp1*/
&NdisDeviceHandle);

/* Return type of NdisRegisterDeviceEx is 0xC0000005 */
/* If the status is SUCCESSFULL, then deviceObject is passed to
NdisGetDeviceReservedExtension(function gets a pointer to the device
extension that is associated with a device object). */
context = (application2*)NdisGetDeviceReservedExtension(DeviceObject);
if (context != NULL)
{
papplication2 = context;
}

xxxxx@gmail.com wrote:

-> My doubt is whether it is possible to create two Device Object?
-> The issue is because of Device Object…?, If I comment app1 code implementation and
test app2 then status of NdisRegisterDeviceEx is success.

It should certainly be possible, although I’m not sure why it would be
useful in this case.

-> For understanding purpose I mentioned application1, application2.

Perhaps you should explain what you mean by that, because your usage is
not normal. Are you simply creating two devices in one function, one
right after the other? How is that two “applications”?

Rather than doing error-prone cut-and-pastes and retyping, can’t you
just attach the actual source file? There are so many ways to screw
this up in the code you haven’t shown us.

-> In application 2 I tried by creating new device object PDEVICE_OBJECT Mpapp_deviceobj2,
and passed to NdisRegisterDeviceEx code implementation for app2 is given below.

-> I passed the same device object which is used in application 1.(just tried…)

You aren’t paying attention. The PDEVICE_OBJECT* parameter in
NdisRegisterDeviceEx is an OUTPUT parameter. You don’t pass anything
in. Also, your code does not include Mpapp_deviceobj2, which tells me
you are retyping things. That means we aren’t seeing your real code.

Also remember that the parameter is a pointer to pointer. You need to
have something like:

PDEVICE_OBJECT deviceObject;
NdisRegisterDeviceEx( …, &deviceObject, … );


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