OK, this is really good article about sharing memory between user app and driver: http://www.osronline.com/article.cfm?article=39. Thanks OSR to put everything together! I am using the MmMapLockedPagesSpecifyCache method for sharing the memory.
Now the challenge part is the synchronization. My data is a ring buffer with load pointer and unload pointer. The user mode app loads the data the buffer and then updates the load pointer and driver unloads the buffer and updates unload pointer. The driver code that accesses the shared memory is running at the DISPATCH_LEVEL and our code needs to be safe on the multi core/CPU system. I understand I can just use the name event to do the job if we can run driver in the PASSIVE_LEVEL. However it is not option for me as the one of key reason to processing the data in kernel mode is our code can run in the DISPATCH_LEVEL. So is there any way to protect the shared data if the driver is running at DISPATCH_LEVEL?
Well, a second thought I had is: do I really need synchronization for this case: driver and and user app does not write to the same data buffer and they write to their own load/unload pointer. The only possible issue I can think of is when user mode app needs to read the unload pointer(to make sure the buffer is not full) in one CPU while the driver code is update the same unload pointer at the same time in another CPU. Can the X86 CPU/Memory controller guarantee this will not happen? If so, can I say the code has no synchronization issue even without any synchronization mechanism?
Thanks,
William