none
How to access kernel mode memory in user mode application in WinCe7 RRS feed

  • Question

  • I have written a direct show filter and a video decoder driver for Win CE 7. The filter is loaded in the user mode and the decoder driver is loaded in the kernel mode. The filter need memory to receive the input buffers and it allocates this memory by calling a video decoder driver function. The decoder driver allocates memory and returns its virtual address from kernel space (>2GB) because it is loaded in the kernel mode. But this memory is not accessible for the filter because it is loaded in the user mode.

    By considering the above scenario, how can I make the memory allocated by the video decoder driver accessible for the filter?

    Monday, July 29, 2013 12:07 PM

All replies

  • See MSDN for VirtualAllocEx and VirtualCopyEx.

    http://msdn.microsoft.com/en-us/library/ee488448.aspx


    Good luck,

    Michel Verhagen, eMVP
    Check out my blog: http://guruce.com/blog

    GuruCE
    Microsoft Embedded Partner
    http://guruce.com
    Consultancy, training and development services.

    Tuesday, July 30, 2013 12:55 AM
    Moderator
  • Thanks for the help Michel.

    I have implemented the VirtuaAllocEx() and VirtualCopyEX() in video decoder driver (kernel mode) and calling this implementation from the filter (user mode) using DeviceIoControl() function.

    The VirtualAllocEx returns the virual address from the user space (<2GB) but VirtualCopyEX functions returns with FALSE.

    lpUserAddr = VirtualAllocEx((void*)GetCallerVMProcessId(), 0, 
                                       SourceSize, MEM_RESERVE,PAGE_NOACCESS);
    if (lpUserAddr == NULL) 
    {
    	dwError = GetLastError();
    	return NULL;
    }
    
    if(!VirtualCopyEx((void*)GetCallerVMProcessId(),(LPVOID)lpUserAddr,
                HANDLE(GetDirectCallerProcessId()),
                (LPVOID)((VMETA_IO_BASE_ADDRESS)>>8),SourceSize,
                PAGE_READWRITE|PAGE_PHYSICAL|PAGE_NOCACHE))
    {
    	dwError = GetLastError();
    	return FALSE;
    }

    I am getting the following debug output when the function VirtualCopyEx is called:

    VMCopyVirtual Failed, cPages = 00000400, cpReserved = 0000005e

    51004e ERROR: VMCopy - Failed, dwErr = 00000057

    And the GetLastError() returns 87. Please guide me, what is wrong in my implementation and why the VirtualCopyEx() is not returning with success?


    • Edited by Zaheer_ Tuesday, July 30, 2013 12:01 PM correcting the code snippet
    Tuesday, July 30, 2013 11:27 AM
  • Error 87 (0x57) is "The parameter is incorrect". That should give you a clue...

    Here's a blog post from Vinoth that may help you further too: http://vinoth-vinothblog.blogspot.co.nz/2008/11/sharing-blocks-of-memory-between-kernel.html


    Good luck,

    Michel Verhagen, eMVP
    Check out my blog: http://guruce.com/blog

    GuruCE
    Microsoft Embedded Partner
    http://guruce.com
    Consultancy, training and development services.

    Tuesday, July 30, 2013 11:38 AM
    Moderator
  • I am following the same Vinoth's blog. Yes, Error 87 mean the parameter is incorrect. I have passed the valid parameters to the VirtualCopyEx function but it is stilling failing.

    Further debugging shows that:

    The 2nd parameter to the VirtualCopyEx() function is a "lpvDest: pointer to the destination memory, which must be reserved". If the value of lpvDest is >2GB (kernel space), the VirtualCopyEx() returns with success but if the value of lpvDest<2GB (user space), the VirtualCopyEx() returns with FAIL.

    I think there is still some missing implementation relatd to user and kernel mode. I have also tried with the Q flag in the bib file but still not work for me.

    Tuesday, July 30, 2013 12:11 PM