Search code examples
c++memory-managementmemory-addressvirtual-memorywindows-embedded-compact

Mapping virtual address to physical address


I have a project which I need to get working in C++ in VS2010 under Windows 7. The project was originally developed to run on WinCE . It was developed in VC++ but linked to some libraries used in the WinCE dev environment.

The project uses ::VirtualCopy which fails to compile as I believe it’s in Coredll.lib. in the WinCE environment. https://msdn.microsoft.com/en-us/library/aa450977.aspx

error LNK2028: unresolved token (0A000B85) "extern "C" int __cdecl VirtualCopy(void *,void *,unsigned long,unsigned long)" (?VirtualCopy@@$$J0YAHPAX0KK@Z) referenced in ..
error LNK2019: unresolved external symbol "extern "C" int __cdecl VirtualCopy(void *,void *,unsigned long,unsigned long)" (?VirtualCopy@@$$J0YAHPAX0KK@Z) referenced in ..

The function in my code is reference through:

extern "C" 
{
BOOL VirtualCopy(LPVOID lpvDest, LPVOID lpvSrc, DWORD cbSize, DWORD fdwProtect);
}

And then used:

if( ! ::VirtualCopy(pVMem, reinterpret_cast<void *>(dwASIC_REGISTERS_BASE), tSystemInfo.dwPageSize, PAGE_READWRITE | PAGE_NOCACHE) )
{
    DWORD dwError = ::GetLastError();

    TRACE1("Failed ", dwError);
    return;
}

The projects uses:

  • MFC in a shared dll
  • Static link to ATL
  • Common Language Runtime Support (/clr)

I have a few of question:

  1. Is there an alternative?
  2. Is there any way I can import some of the old winCE libraries and link against those, allowing me to use this function?

Any help would be greatly appreciated

Many Thanks


Solution

  • I'm not an expert in WinCE programming, but below are some thoughts:

    It seems that this function is used to map a pointer accessible in program code (virtual address) to some device registers (physical address). In embedded programming such approach is used to directly drive a device (e.g. light a LED connected to SoC).

    1. I believe that in Win32 such function isn't accessible because direct setting/reading registers is reserved for device drivers, not application code.

    2. I believe that there is no way to link against WinCE libraries in Win32 environment. But what is more important, even if there is a way to achieve this, you would gain nothing - the registers (physical address) is specific to the embedded device. On a PC this particular physical address probably points to RAM so you'll be writing in address space of other application.

    3. You should not get around lack of VirtualCopy function. You should understand what the code did on the device and then either remove it (if it isn't necessary to application behavior) or implement it in a way that is correct for Win32 environment.