快捷搜索:  as  2018  FtCWSyGV  С˵  test  xxx  Ψһ  w3viyKQx

澳门威泥斯人_博格自动化网进入



这篇文章是继文章Windows Embedded CE 6.0 Internals (1)的。内存这块不停是让人头痛的器械,由于对照繁杂,然则我们却必要常常与其打交道——内存透露、非常定位、法度榜样优化等等。这篇文章以及后续的文章我试着能够刨根问底。

5.内存构架

内存的种类

1.Random Access Memory (RAM)

Random access memory can be read or written directly at any address. There are various types of RAM that are differentiated by the underlying hardware technology used to implement them. However they all share the ability to be read or written directly at any random address. RAM memory is volatile, the contents are only maintained as long as power is not lost.

2.Read Only Memory (ROM)

Read Only Memory typically refers to memory that can be read just like RAM, but not written directly. Most ROM used today can be rewritten using a software algorithm, and is often called Flash ROM. Data stored in ROM is nonvolatile, and remains valid even after power is removed. ROM is sometimes used to refer to any kind of memory that is nonvolatile, even if it is not randomly acce澳门威泥斯人ssible (e.g. paged memory).

3.Paged Memory

Some memory technologies are not randomly accessible. These memory technologies must be read and written in blocks. A CPU typically requires memory that it executes code from to be randomly accessible, so Paged memory can’t be used as a medium to execute code. This type of memory is often used for bulk nonvolatile storage, and includes NAND technology.(存储在NAND Flash中的镜像在履行时被拷贝到RAM中。而NOR Flash是支持XIP的,这也是NAND和NOR的主要差别。)

虚拟内存架构

1.虚拟内存

Windows Embedded CE 6.0应用单一的32位(4G)平坦模式虚拟内存寻址空间。

这样可以高效的、保护的应用物理内存。

2.虚拟寻址

有几个概率必要澄清,首先是▲物理内存是被内存治理单元(MMU)拥有的,当然处置惩罚器得有MMU,不然没法跑起来CE 6.0。

▲把虚拟内存转换为物理内存是MMU的事情。

▲一个有效的虚拟内存必须是已经映射到物理内存的。

▲操作系统中近乎所有地址都是虚拟地址,进程不容许直接造访物理地址,物理地址必须首先映射到虚拟地址上,不管是静态映射照样动态映射。

下图是静态映射的例子,CE 5.0版本和6.0版本映射图是相同的。那么有个问题:为什么要静态映射?仅仅动态映射不是很好嘛?

由于动态映射必要光阴,当一个页差错非常发生时,MMU必要光阴把这个虚拟内存映射到真正的物理内存上,这可能导致系统崩溃,由于在实时中断时页差错是不容许的。静态映射便是办理这些问题。

3.物理寻址

在什么环境下必要物理寻址?跟Windows桌面系统一样:在系统上电之后、MMU启动之前。别的Bus Mastering组件(比如DMA节制器)也会用到物理寻址。

虚拟内存总览

下图是Windows CE 5.0的4GB虚拟内存散播图,每个进程零丁的内存是32MB,当前系统最多只容许存在32个进程。

下图是5.0各个进程的内存宣布以及详细一个进程内部的内存宣布,从右边的图可以看出,DLL寄放的位置从高地址向下扩展,而EXE的位置从低地址向高地址扩展,当相遇时就会报地址不够差错。这也是5.0不够的地方。别的nk.exe对照特殊,老是运行在Slot 97位置。

下图是Windows Embedded CE 6.0的4GB虚拟内存散播图,每个进程现在都有2GB的虚拟地址,扬弃了原本的按Slot分配的要领,而是只要你必要你就可以创建内存。关于更具体的请见下面的内核态和用户态地址空间。

内核态地址空间

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

▲CPU Specific VM

▲Kernel VM(if supported by CPU)256 MB

▲Kernel VM256 MB

▲Object Store128 MB

▲Kernel XIP DLLs128 MB

▲Static Mapped Uncached512 MB

▲Static Mapped Cached512 MB

用户态地址空间

▲Shared System Heap255 MB

▲RA澳门威泥斯人M Backed Mapfiles256 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 file澳门威泥斯人s will be allocated from the virtual memory area of the process, and differ for each process.

▲Shared User DLLs512 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 Space1024 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的内存信息,内存信息详细的含义见后面的解释。

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.

CCode pages in ROM. Does not require a physical page.

cCode pages in RAM. Requires a physical page.

SIndicates a virtual page that holds a stack. Requires a physical page.

PPeripheral 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.

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

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

?C澳门威泥斯人ontents unknown.

rRead-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.

RRead-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.

您可能还会对下面的文章感兴趣: