Comments (12)
from dmf.
from dmf.
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.
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.
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.
Also, in the Init() function, we are calling:
WDF_OBJECT_ATTRIBUTES lockAttributes; WDF_OBJECT_ATTRIBUTES_INIT(&lockAttributes); status = WdfWaitLockCreate(&lockAttributes, &m_CodecPowerLock);
from dmf.
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:
- Static (in ModulesAdd() callback which is called during DeviceAdd).
- 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.
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.
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.
@samtertzakian Thanks Sam! That resolved the issue, should I set values for the other members that are xxx_Invalid ?
from dmf.
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.
Closing issue for now as it appears to be resolved.
from dmf.
Related Issues (20)
- Isn't it better to design DMF on C++ code base? HOT 3
- Unexpected behaviour of ScheduledTask module HOT 7
- [UMDF] DMF_VirtualHidMini fails WriteReport requests on descriptors without Report IDs HOT 2
- Latest code generates following linker errors in my project HOT 17
- Do not use Visual Studio 16.10.0 or 16.10.1 or 16.10.2 with DMF due to link regressions HOT 4
- Question Regarding SoundWire bus support HOT 11
- Unused config param in DMF_VirtualHidKeyboard module HOT 4
- How can I disable WPP for the DMF driver ? HOT 5
- Duplicated lines HOT 2
- This repo is missing important files
- EyeGazeIoctl sample fails ApiValidator HOT 2
- Pdo_DevicePropertyTableWrite adds properties to parent device instead of PDO HOT 32
- Building with Windows 11, version 22H2 WDK (10.0.22621.0) supported? HOT 9
- Trying to use Dmf_IoctlHandler with Control Device Object, supported? HOT 15
- fatal error C1510: Cannot load language resource clui.dll HOT 12
- WDF Verifier (Handle Tracking) trips over FILEOJECT de-reference without using the right tag HOT 2
- Dmf_VirtualHidKeyboard work in User-mode? HOT 1
- Why are lib files added to linker manually? HOT 5
- Why is `EnableLookAside` a `ULONG` and not a `BOOLEAN`? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dmf.