Magic number with MmMapIoSpace

So when mapping the memory space to, MmMapIoSpace

I noticed that in the past certain point, the data was just being discarded when written. No errors, breakpoints, or even errors were thrown. Everything worked fine, without any negative consequences.

I decided to do a write / read test (the driver will write 1 for every byte for the length of the assumed size) and the reader mode (user) will read and report where 1 ended.

The number he encountered was 3208, which would seem to be a nice round number (/ 8 = 401, / 256 = 12, etc.)

What's with that? Why can't I display the full buffer space?

EDIT And in 64-bit mode it drops to 2492.

0


source to share


1 answer


I'm not an expert, but I don't see how MmMapIoSpace can be relied on for what you ask, because there is no guarantee that the user space buffer is contiguous in physical memory.

Instead, I think you should use IoAllocateMdl

and MmProbeAndLockPages

to lock the custom buffer and then MmGetSystemAddressForMdlSafe

to map it to the system's address space. This process is described here .



As said earlier, I believe the point at which the display fails (3208/2492 bytes to buffer) is probably only the end of the page, but simple enough for you to get the user space for the application to report the (virtual) address of the first a byte that is not written, not an offset, and check if it is a multiple of 4096 or not.

+1


source







All Articles