Hello all,
I have the following questions that could be answered
by the list experts:
- I create a device with DIRECT_IO option. From the
read dispatch function, I pend the Irp, and send it to
a separate driver thread. In the thread, I complete
the Irp by reading the data into the user buffers. My
question is, since in the driver thread I would be
running at arbitrary thread context, how am I able to
access the user MDL in the thread? Is it because it is
locked in non-paged memory by the IO subsystem?
- If I have two threads in my kernel driver, the
handles to files that are opened in each thread will
only be accessible from that specific thread. All the
thread context applicable to user mode also apply to
the kernel threads. Is this correct?
regards
DK
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools
Comments inline:
“Dileep Kumar” wrote in message news:xxxxx@ntfsd…
> Hello all,
> I have the following questions that could be answered
> by the list experts:
> 1. I create a device with DIRECT_IO option. From the
> read dispatch function, I pend the Irp, and send it to
> a separate driver thread. In the thread, I complete
> the Irp by reading the data into the user buffers. My
> question is, since in the driver thread I would be
> running at arbitrary thread context, how am I able to
> access the user MDL in the thread? Is it because it is
> locked in non-paged memory by the IO subsystem?
Yes it is because you have the MDL mapped to the kernel memory space.
> 2. If I have two threads in my kernel driver, the
> handles to files that are opened in each thread will
> only be accessible from that specific thread. All the
> thread context applicable to user mode also apply to
> the kernel threads. Is this correct?
Handles are on a per process basis, not per thread. If you are opening
these
in the kernel for use by the kernel you should use the OBJ_KERNEL_HANDLE
flag.
–
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply
> running at arbitrary thread context, how am I able to
access the user MDL in the thread?
Yes, you can do this. Just do not dereference the MDL’s virtual address. If you
need a pointer - call MmGetSystemAddressForMdlSafe, this maps the MDL’s pages
to the global kernel address space accessible from any kernel-mode context.
MmGetSystemAddressForMdlSafe has no “undo” counterpart - all is done
automatically.
You can also build a partial MDL (sub-range descriptor from range descriptor)
by IoAllocateMdl+IoBuildPartialMdl (and do not forget to do IoFreeMdl later),
or pass the MDL to the DMA routines.
These are the 3 ways of using the MDL.
Is it because it is
locked in non-paged memory by the IO subsystem?
Yes.
thread context applicable to user mode also apply to
the kernel threads. Is this correct?
Yes. If the syscall or a page fault occurs in the user-mode thread - then the
same thread enters the kernel and runs in the kernel, the thread identity is
preserved.
You can also run the code in the kernel-only threads which cannot return to
user - by IoQueueWorkItem or PsCreateSystemThread.
As about the DPCs and the ISRs - they interrupt any thread (as the things were
laid off at this particular random moment) and thus are called to run in
“arbitrary thread context”.
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com