技术开发 频道

Windows Embedded CE 6.0 Internals下

 内核态地址空间

 内核地址空间位于虚拟地址空间的较高的2GB,对于所有进程在任何时候它都是存在的。相比来说每个进程所具有的较低的2GB用户态地址空间相互之间是隔离的。

 ▲CPU Specific VM

 ▲Kernel VM(if supported by CPU)  256 MB

 ▲Kernel VM                                   256 MB

 ▲Object Store                               128 MB

 ▲Kernel XIP DLLs                          128 MB

 ▲Static Mapped Uncached            512 MB

 ▲Static Mapped Cached                512 MB

 用户态地址空间

 ▲Shared System Heap   255 MB

 ▲RAM Backed Mapfiles   256 MB

 RAM backed map files are memory mapped file objects that do not have an actual file underneath them. This region provides backward compatibility for applications that used RAM-backed map files for cross-process communication, expecting all processes to map views at the same virtual address. Every process that opens the same RAM backed memory mapped file will get the same pointer value. File backed memory mapped files will be allocated from the virtual memory area of the process, and differ for each process.

 ▲Shared User DLLs        512 MB

 When a process initializes, the OS maps the following DLLs and memory components: DLLs and ROM DLL read/write sections are loaded bottom up starting at 1GB. DLLs are controlled by the loader, which loads all the DLLs at the same address for each process.

 ▲Process Space             1024 MB

 The stack, the heap, and the executable (.exe) file are created and mapped from the bottom up starting at 64KB. Virtual memory allocations occur in the first 1GB after the executable code and data. The bottom 64 KB of memory always remains free.

 程序的内存

 一个进程至少有一个默认的堆,每个线程都有一个栈。

 1.堆

 堆被作为应用程序主要的内存使用。堆分为以下几种:

 ▲Local Heap (Default)

 Each application has a default, or local, heap created by the OS when an application launches. By default, Windows Embedded CE 6.0 initially reserves 64 KB of virtual memory for the local heap, but only commits the pages as they are allocated. If the application allocates more than the 64 KB in the local heap, the system allocates more virtual memory by using VirtualAlloc to fulfill the request for memory. (第一次系统默认给应用程序堆的大小事64K,当超过这个大小时,系统使用VirtualAlloc分配更多的内存来满足你的需求。)

 ▲Private Heap

 An application can also create any number of separate heaps. These private heaps have the same properties as the local heap but are managed through a separate set of heap functions. You can specify the maximum or initial size when creating private heaps.(这系列堆函数是HeapCreate, HeapAlloc, HeapFree, HeapReAlloc, HeapSize等。)

 ▲Shared Heap

 Shared heaps allow for efficient data transfer from kernel mode components to user processes. Shared heaps are writeable to kernel components, and read only to user processes. Shared heaps are located in a system wide area at the top of the user address space, and visible to all user processes. Therefore you should not put any sensitive data in a shared heap.(上图用户态地址空间中红色部分即是,它对于内核是可读的,但对用户态进程是只读的。)

 ▲Remote Heap

 Remote heaps are a new feature of WindowsCE Embedded 6.0. A remote heap allows a server and client process to share memory safely. The server process creates and has full access to the remote heap, while the client process can read and optionally write to it. The client process can’t destroy the heap metadata.(为了更好的满足客户端/服务器端通信而产生的。)

 2.栈

 Storage area for variables referenced in a program.

 3.Heap Walker工具

 下图显示你可以从哪儿打开这个工具:

 下图是Windows Mobile 6.0 Prefessional模拟器的堆截图:

 Each process has at least one heap, with the HF32_DEFAULT flag. This is the local heap that is created for every process. Notice some processes have more heaps (unnamed), these are private heaps that the process chose to create. Fixed means they are in use. Free means that they can be reused. BigBlock is a region of memory that was allocated outside the heap due to its size. Notice that BigBlock areas are created on 64KB boundaries, that is the granularity of the low level memory allocation APIs.(内存分配的粒度是64K,这是编程时应该注意的问题,负责会造成内存浪费。)

 Target Control工具

 安装了Platform Builder插件的Visual Studio 2005 SP1可以从Target->Target Control打开Windows CE命令提示符窗口。在命令提示符后键入'mi’即可以看到内核和单独进程的内存信息。比如mi ["kernel","full"], kernel代表列出内核内存详细信息,full代表列出全部内存信息。

 下图示出进程HeapTest1.exe的内存信息,内存信息具体的含义见后面的解释。

 <blank>  A blank space indicates a virtual page that is not currently allocated. Does not require a physical page.

 -             Reserved but not in use. Indicates a virtual page that is currently allocated but not mapped to any physical memory. Does not require a physical page.

 C            Code pages in ROM. Does not require a physical page.

 c             Code pages in RAM. Requires a physical page.

 S             Indicates a virtual page that holds a stack. Requires a physical page.

 P             Peripheral memory (pages used to map target device memory by using VirtualAlloc). Indicates a virtual page that is used to map a range of hardware addresses. Does not require a physical page. Peripheral memory may include frame buffer memory.

 W             Indicates a virtual page that holds read-write data. Requires a physical page. Read-write pages include global variables as well as dynamically allocated memory.

 O             Indicates a virtual page that is used by the object store. Requires a physical page. Should only appear in the Filesys process.

 ?             Contents unknown.

 r             Read-only data pages in RAM. Requires a physical page. Read-only data primarily comes from data items that are declared as a const type in the source code.

 R             Read-only data pages in ROM. Does not require a physical page. Read-only data primarily comes from data items that are declared as a const type in the source code.

 Note: For CPUs such as ARM and SHx that do not distinguish between read-only and executable code pages in hardware, use R(r) to represent both data and code.

查看原文地址

0
相关文章