Link to home
Start Free TrialLog in
Avatar of kjboughton
kjboughton

asked on

IODeviceControl call doesn't seem to execute in the context (process/thread processor affinity) of the calling DLL

I've written a DLL that creates a driver service, starts it and then uses IODeviceControl to read some information from the driver.  I am trying to use either SetThreadAffinityMask or GetProcessAffinityMask/SetProcessAffinityMask to set the process/thread affinity to each core in the system, one at a time, in order to read a CPU specific MSR (via the device driver).  This is done in a loop, where the loop cycles for each cpu detected.

Psuedo-code that illustrates what I am trying to do:

for ( i = 0 ; i < numProcessorsDetected; i++ ) {

    SetProcessAffinityMask(); //set process to run only on the CPU 0, then CPU 1, then CPU2, then...

    IODeviceControl(); //get some information from my driver

    //do something with data return from IODeviceControl call
}

    SetProcessAffinityMask(); // back to all CPUs running

It appears that the mask is being set correctly but the driver is not executing code in the context of my calling user mode DLL.  Is this a limitation of the Window's IO subsystem?  Am I going to need to set affinity in kernel mode to ensure that the assembly code utilitized in the driver routine is actually running on the CPU that I need it to run on?

I am really confused on where to go next.  I really don't want to have to mess with my driver and create DPCs just to do this.  I would much rather do the coding in user mode as the driver is working great right now.

I can't find information ANYWHERE on this subject.  Anything anyone can add would be extremely helpful.
Avatar of jkr
jkr
Flag of Germany image

>>IODeviceControl

Did yo umean 'DeviceIoControl()'?

>>It appears that the mask is being set correctly but the driver is not executing code in the context of my calling
>>user mode DL

The call is execited in the context of the kernel. If it was executed in your call context, that would not be in kernel mode. As the docs state "The DeviceIoControl function sends a control code directly to a specified device driver, causing the corresponding device to perform the specified operation.". This does not mean calling a function in the driver.
Avatar of kjboughton
kjboughton

ASKER

correct, should read DeviceIoControl - don't know why I wrote that and didn't catch it.

I understand your context comment - does this mean the only way to set driver processor affinity is to use a DPC in which I set the processor affinity using kernel level calls?  If so I'm in trouble because my driver experience is still young and thats going to be a steep learning curve (probably lots of self-induced BSODs).
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Undocumented.  Nice.  I can't really tell if it is doing anything.  Kernel debugging is not my forte.