• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 554
  • Last Modified:

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.
0
kjboughton
Asked:
kjboughton
  • 3
  • 2
1 Solution
 
jkrCommented:
>>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.
0
 
kjboughtonAuthor Commented:
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).
0
 
jkrCommented:
Yes, if you want to set the processor affinity of your driver's thread in kernel mode, that has to be inside the driver itself. The call is 'ZwSetInformationThread()' with the 'ThreadAffinityMask' parameter.
0
 
kjboughtonAuthor Commented:
Undocumented.  Nice.  I can't really tell if it is doing anything.  Kernel debugging is not my forte.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now