简体   繁体   English

将虚拟地址映射到物理地址

[英]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 . 我有一个项目,需要在Windows 7下的VS2010中使用C ++进行工作。该项目最初开发为在WinCE上运行。 It was developed in VC++ but linked to some libraries used in the WinCE dev environment. 它是用VC ++开发的,但链接到WinCE开发环境中使用的某些库。

The project uses ::VirtualCopy which fails to compile as I believe it's in Coredll.lib. 该项目使用:: VirtualCopy无法编译,因为我认为它位于Coredll.lib中。 in the WinCE environment. 在WinCE环境中。 https://msdn.microsoft.com/en-us/library/aa450977.aspx https://msdn.microsoft.com/zh-CN/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 共享dll中的MFC
  • Static link to ATL 静态链接到ATL
  • Common Language Runtime Support (/clr) 公共语言运行时支持(/ 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? 有什么办法可以导入一些旧的winCE库并针对这些库进行链接,从而允许我使用此功能?

Any help would be greatly appreciated 任何帮助将不胜感激

Many Thanks 非常感谢

I'm not an expert in WinCE programming, but below are some thoughts: 我不是WinCE编程专家,但以下是一些想法:

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 (eg light a LED connected to SoC). 在嵌入式编程中,这种方法用于直接驱动设备(例如,点亮连接到SoC的LED)。

  1. I believe that in Win32 such function isn't accessible because direct setting/reading registers is reserved for device drivers, not application code. 我相信在Win32中无法访问该功能,因为直接设置/读取寄存器是为设备驱动程序而不是应用程序代码保留的。

  2. I believe that there is no way to link against WinCE libraries in Win32 environment. 我相信在Win32环境中无法链接到WinCE库。 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. 在PC上,该特定物理地址可能指向RAM,因此您将在其他应用程序的地址空间中进行写入。

  3. You should not get around lack of VirtualCopy function. 您不应该避免缺少VirtualCopy功能。 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. 您应该了解代码在设备上做了什么,然后删除它(如果应用程序行为不是必需的)或以对Win32环境正确的方式实现它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM