Unless you really want to share the kernel side’s data with the user side (and handle the fun cases that happen when the kernel side is modifying the data while the user side is reading it) you will still need to copy the data from the kernel buffers into user buffers. The best option there is METHOD_DIRECT, since you copy your data directly to user-side pages (rather than METHOD_BUFFERED which would indirect through an additional kernel buffer).
If your kernel-side is taking data from a device and putting it into the user-side buffers then METHOD_DIRECT is also the best option. Whether you’re doing this with PIO or DMA the handling would be identical to how you handle it with copying your own data.
If you really have huge amounts of data that’s contiguously mapped in the kernel and which remains static so that you don’t need any kernel/user synchronization (or is a stream where you’re writing and the user is reading, though you may still need to coordinate around changes to the ring pointers) then you would consider using shared memory. In that case you probably would allocate kernel buffer with an MDL (using MmAllocatePagesForMdl to back it with pages) rather than from pool, and you would have to handle mapping it partially or completely into kernel address space and user address space. If your buffers are really big then you may have trouble mapping them into kernel space unless you’re on a 64-bit machine, since you still need to find a contiguous KVA range.
METHOD_DIRECT is your friend.
-p
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Friday, November 14, 2014 2:50 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Massive data exchange between User and Kernel spaces. Best practice question
Hello there,
We have got a kernel driver and system service which are currently communicating via the IOCTL requests (direct method). And it’s OK for now since the data size is not very big (about 20-30 MB).
But what if we need to get 100-150 MB of data from the kernel space? How should we act in such situation? I guess memory allocation should be done on the driver side and then we should map this memory in user space, but I’m not sure whether this correct or not?
And what if we need to pass about 1 GB of data? The allocation of 1 GB obviously is not very good idea? Should I use memory mapped files in such case?
Thanks in advance,
Vitaly
NTDEV is sponsored by OSR
Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
OSR is HIRING!! See http://www.osr.com/careers
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer