Coder Social home page Coder Social logo

Comments (12)

alkovacs avatar alkovacs commented on May 16, 2024

Debug 1

from dmf.

alkovacs avatar alkovacs commented on May 16, 2024

Debug 2

from dmf.

alkovacs avatar alkovacs commented on May 16, 2024

So when I unload the device, it seems to hit this code 3 times, the first 2 (second image) when moduleConfig->ExecuteWhen is set to ScheduledTask_ExecuteWhen_Invalid and the assertion is made. On the third pass when moduleConfig->ExecuteWhen is set to ScheduledTask_ExecuteWhen_Other (first image) the assertion is not made as ModuleClosing gets set. There are 2 instances of the device loaded.

from dmf.

samtertzakian avatar samtertzakian commented on May 16, 2024

The fact that ExecuteWhen is set to "Invalid" tells me that something is wrong. It seems like the callback is executing very late...much later than it should (an that the memory for the object has already been deleted).

Are you instantiating DMF_QueuedWorkitem which uses ScheduledTask as Child Module? Are you instantiating it statically (In ModulesAdd() callback) or dynamically using DMF_QueuedWorkitem_Create().

If dynamically, how are you setting the parent of the Module using WDF_OBJECT_ATTRIBUTES()?

Something is definitely wrong and this error should be fixed.

As for your questions above, what applies to D0Entry also applies to D0Exit. I will clarify documentation about this.

from dmf.

alkovacs avatar alkovacs commented on May 16, 2024

Hi Sam! Thanks for getting back to me so quickly. DMF_QueuedWorkitem is NOT being called in the driver code, should it be?

from dmf.

alkovacs avatar alkovacs commented on May 16, 2024

Also, in the Init() function, we are calling:
WDF_OBJECT_ATTRIBUTES lockAttributes; WDF_OBJECT_ATTRIBUTES_INIT(&lockAttributes); status = WdfWaitLockCreate(&lockAttributes, &m_CodecPowerLock);

from dmf.

samtertzakian avatar samtertzakian commented on May 16, 2024

Hi Sam! Thanks for getting back to me so quickly. DMF_QueuedWorkitem is NOT being called in the driver code, should it be?

Can you tell me what Modules you are instantiating and how you are instantiating them?

Two ways are:

  1. Static (in ModulesAdd() callback which is called during DeviceAdd).
  2. Dynamically (using DMF_[ModuleName]_Create which can be called anywhere in the driver).

Also, in the Init() function, we are calling:
WDF_OBJECT_ATTRIBUTES lockAttributes; WDF_OBJECT_ATTRIBUTES_INIT(&lockAttributes); status = WdfWaitLockCreate(&lockAttributes, &m_CodecPowerLock);

This is not the object attributes that I was talking about. Also, you are initializing object attributes but not setting the parent object afterward. I was asking about the WDF_OBJECT_ATTRIBUTES you use for the DMF Module.

My feeling is you might be using a Module as global variable or doing something funky like that. Let me know what Modules you instantiate and how (and where)?

from dmf.

alkovacs avatar alkovacs commented on May 16, 2024

@samtertzakian

So the modules are added in ModulesAdd().

But I am seeing some strangeness here... (I have inherited this code, it was said to be "almost working"!)

So first (order encountered in code) this is being done...

`#ifdef __cplusplus
extern "C" {
#endif

DRIVER_INITIALIZE DriverEntry;
EVT_WDF_DRIVER_DEVICE_ADD ourDriverEvtDeviceAdd;
EVT_WDF_OBJECT_CONTEXT_CLEANUP ourDriverEvtDriverContextCleanup;
EVT_DMF_DEVICE_MODULES_ADD ourDriverDmfModulesAdd;
EVT_WDF_DEVICE_PREPARE_HARDWARE ourDriverEvtDevicePrepareHardware;
EVT_WDF_DEVICE_RELEASE_HARDWARE ourDriverEvtDeviceReleaseHardware;
EVT_WDF_DEVICE_D0_ENTRY ourDriverEvtDeviceD0Entry;
EVT_WDF_DEVICE_D0_EXIT ourDriverEvtDeviceD0Exit;
EVT_DMF_IoctlHandler_Callback ourDriverIoDeviceControl;

#ifdef __cplusplus
}
#endif`

Then, this is being done ...

` // DMF: Initialize the DMF_EVENT_CALLBACKS to set the callback DMF will call
// to get the list of Modules to instantiate.

DMF_EVENT_CALLBACKS_INIT(&dmfEventCallbacks);
dmfEventCallbacks.EvtDmfDeviceModulesAdd = ourDriverDmfModulesAdd;
DMF_DmfDeviceInitSetEventCallbacks(dmfDeviceInit,  &dmfEventCallbacks);`

And in the ourDriverDmfModulesAdd (honestly I have not yet had the chance to debug the Dmf => WDF interfaces)...

`IRQL_requires_max(PASSIVE_LEVEL)
VOID
ourDriverDmfModulesAdd(
In WDFDEVICE Device,
In PDMFMODULE_INIT DmfModuleInit
)
{
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s\n", FUNCDNAME);

DMF_MODULE_ATTRIBUTES moduleAttributes;
DMF_CONFIG_IoctlHandler moduleConfigIoctlHandler;
DMF_CONFIG_DeviceInterfaceTarget moduleConfigDeviceInterfaceTarget;
DMF_CONFIG_ScheduledTask moduleConfigScheduledTask;

DEVICE_CONTEXT* pDevContext;

pDevContext = GetDeviceContext(Device);

// interface IoctlHandler
DMF_CONFIG_IoctlHandler_AND_ATTRIBUTES_INIT(&moduleConfigIoctlHandler, &moduleAttributes);
moduleConfigIoctlHandler.DeviceInterfaceGuid = OUR_INTERFACE_GUID;
moduleConfigIoctlHandler.IoctlRecords = ourDriverIfcIoctlHandlerTable;
moduleConfigIoctlHandler.IoctlRecordCount = _countof(ourDriverIfcIoctlHandlerTable);
moduleConfigIoctlHandler.ManualMode = TRUE;
DMF_DmfModuleAdd(DmfModuleInit, &moduleAttributes, WDF_NO_OBJECT_ATTRIBUTES, &pDevContext->DmfModuleourDriverIfcIoctlHandler);

// interface request target
DMF_CONFIG_DeviceInterfaceTarget_AND_ATTRIBUTES_INIT(&moduleConfigDeviceInterfaceTarget, &moduleAttributes);
moduleConfigDeviceInterfaceTarget.DeviceInterfaceTargetGuid = OUR_INTERFACE_GUID;
moduleConfigDeviceInterfaceTarget.EvtDeviceInterfaceTargetOnStateChange = ourDriverInterfaceTarget_OnStateChange;
moduleConfigDeviceInterfaceTarget.EvtDeviceInterfaceTargetOnPnpNotification = ourDriverInterfaceTarget_OnPnpNotification;
DMF_DmfModuleAdd(DmfModuleInit, &moduleAttributes, WDF_NO_OBJECT_ATTRIBUTES, &pDevContext->DmfModuleourDriverIfcRequestTarget);

// interface arrival task
DMF_CONFIG_ScheduledTask_AND_ATTRIBUTES_INIT(&moduleConfigScheduledTask, &moduleAttributes);
moduleConfigScheduledTask.CallbackContext = pDevContext;
moduleConfigScheduledTask.EvtScheduledTaskCallback = ourDriverInterfaceArrivalTask;
DMF_DmfModuleAdd(DmfModuleInit, &moduleAttributes, WDF_NO_OBJECT_ATTRIBUTES, &pDevContext->DmfModuleourDriverInterfaceArrivalTask);

// interface removal task
DMF_CONFIG_ScheduledTask_AND_ATTRIBUTES_INIT(&moduleConfigScheduledTask, &moduleAttributes);
moduleConfigScheduledTask.CallbackContext = pDevContext;
moduleConfigScheduledTask.EvtScheduledTaskCallback = ourDriverInterfaceRemovalTask;
moduleConfigScheduledTask.ExecuteWhen = ScheduledTask_ExecuteWhen_Other;  ****// I ADDED THIS AND IT DOES cut the number of assertions detailed previously down to 1 from 2 WHOOPIEEEE! **** 
DMF_DmfModuleAdd(DmfModuleInit, &moduleAttributes, WDF_NO_OBJECT_ATTRIBUTES, &pDevContext->DmfModuleourDriverInterfaceRemovalTask);

TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "<-- %s\n", __FUNCDNAME__);

}`

from dmf.

samtertzakian avatar samtertzakian commented on May 16, 2024

Ok, the good news is you are not doing anything funky! What you are doing is correct. However, I think all you need to do is:

Add this line:
moduleConfigScheduledTask.ExecuteWhen = ScheduledTask_ExecuteWhen_Other; ****// I ADDED THIS AND IT DOES cut the number of assertions detailed previously down to 1 from 2 WHOOPIEEEE! ****

...to the above instantiation for // interface arrival task. just above (for &pDevContext->DmfModuleourDriverInterfaceArrivalTask)

It cannot be set to zero. You have two instances and you did it for second instance but not first.

Can you try that and let me know?

from dmf.

alkovacs avatar alkovacs commented on May 16, 2024

@samtertzakian Thanks Sam! That resolved the issue, should I set values for the other members that are xxx_Invalid ?

Debug 3

from dmf.

samtertzakian avatar samtertzakian commented on May 16, 2024

No you don't need to when ExecutionMode = ScheduledTask_ExecuteWhen_Other.

Unfortunately this Module's interface is not great. It is a very old Module that was updated a few times. We are planning on making an updated version of this Module with a clearer interface. ScheduledTask is only really used when we want to perform an operation a single time. Instead of using ScheduledTask, it is better to use QueuedWorkitem.

One more thing...Are you scheduling work using ScheduledTask from the Arrival/Removal callback? Because, it is almost certain that you can do the work you need to in the callback directly. You probably don't need to use ScheduledTask at all. Whatever work you are doing in ourDriverInterfaceArrivalTask, you should be able to do in ourDriverInterfaceTarget_OnStateChange.

Can you try that and let me know?

from dmf.

samtertzakian avatar samtertzakian commented on May 16, 2024

Closing issue for now as it appears to be resolved.

from dmf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.