I am working on USB device driver & have a requirement to create a mapped buffer with user allocated size. I am using IoAllocateMdl for getting main pMainMdl with required size. Than i am creating sub buffer, in case data is grater than 4Kb into chunks of each 4KB. I am getting pSubMdl for each chunk and than mapping pSubMdl to main buffer i.e pMainMdl using IoBuildPartialMdl.
Now, when i will get completion routine for each block, i want to create a thread & in that thread i want to do division to data received. workevent(thread) created & working fine.
using (PWCHAR)MmGetMdlVirtualAddress(pSubMdl); to get starting virtual address of a buffer whose completion routine occured, getting virtual address correct. But system crashes with error 0x00000050 & read failed flag 0x0000000 (paged memory fault). Actually, I have used MmBuildMdlForNonPagedPool(pMainMdl); after creating main buffer.
division i am doing as below:
PWCHAR currentmdl = (PWCHAR)MmGetMdlVirtualAddress(pSubMdl);
for (UINT length = 0; length < pIndex; length++)
if comment part *currentmdl/= 2; than no crash occurs.