问题描述
平面内存模型和受保护的内存模型之间的区别? VxWorks支持平面内存模型,Linux是否也支持平面内存模型?
Difference between flat memory model and protected memory model? VxWorks supports flat memory model, Does Linux also supports flat memory model?
推荐答案
为了给出一个有意义的答案,让我们首先回顾一些概念.
In order to give an answer that makes sense, let's review some concepts first.
大多数现代处理器都具有用于多种用途的内存管理单元(MMU).
Most modern processors have a Memory Management Unit (MMU) which is used for a number of purpose.
一个目的是在虚拟地址(CPU看到"的地址)和物理地址(实际连接芯片的位置)之间进行映射.这称为地址翻译.
One purpose is to map between the Virtual Address (the one the CPU "sees") and the Physical Address (where the chips are actually connected). This is called address translation.
另一个目的是为某些虚拟内存位置设置访问属性(如内存是读写"或只读"或不可访问)
Another purpose is to set access attributes for certain virtual memory locations (things like memory is Read-Write, or Read-Only, or not accessible)
使用MMU,您可以拥有所谓的统一映射",其中处理器的虚拟地址与物理地址相同(即,您不使用地址转换).例如,如果处理器访问0x10000,则它正在访问物理位置0x10000.
With an MMU, you can have what is called "unity mapping" where the processor's virtual address is the same as the physical address (i.e. you don't use address translation). For example, if the processor accesses 0x10000, then it is accessing the physical location 0x10000.
平面"内存模型通常是指CPU访问的任何虚拟地址都是唯一的事实.因此,对于32位CPU,最大地址空间限制为4G.
A "flat" memory model typically refers to the fact that any virtual address the CPU accesses is unique. Thus, for a 32-bit CPU, you are limited to a maximum of 4G of address space.
最常(尽管不是必须)用来指代虚拟内存和物理内存之间的统一映射.
It is most often (though not necessarily) used to refer to a unity mapping between virtual and physical memory.
相比之下,在工作站世界中,大多数操作系统(Linux/Windows)使用重叠"内存模型.例如,您在Windows中启动的任何程序(进程")的起始地址均为0x10000.
In contrast, in the workstation world, most Operating Systems (Linux/Windows) use an "overlapped" memory model. For example, any program you launch (a Process) in Windows, will have a start address of 0x10000.
Windows如何从地址0x10000运行10个进程?
How can windows have 10 processes all running from address 0x10000?
这是因为每个进程都使用MMU将虚拟地址0x10000映射到不同的物理地址.到P1的可能是0x10000 = 0x10000,而P2的可能是0x10000 = 0x40000,依此类推...
It's because each processes uses the MMU to map the virtual address 0x10000 to different physical addresses. To P1 could have 0x10000 = 0x10000 while P2 has 0x10000 = 0x40000, etc...
在RAM中,程序位于不同的物理地址,但每个进程的CPU虚拟地址空间都相同.
In RAM, the programs are at different physical addresses, but the CPU Virtual address space looks the same for each process.
据我所知,Windows和Standard Linux始终使用重叠模型(即它们没有平面模型). uLinux或其他特殊内核可能具有平面模型.
As far as I know, Windows and Standard Linux always use an overlapped model (i.e. they don't have a flat model). It is possible that uLinux or other special kernel could have a flat model.
现在,保护与平面模型与受保护模型无关.我要说的是,大多数重叠的模型操作系统都将使用保护,以便一个进程不会影响(即写入另一个进程的内存).
Now, protection has nothing to do with a flat vs. protected model.I would say that most overlapped model OSes will use protection so that one process does not affect (i.e. write into the memory of) another one.
借助VxWorks 6.x和Real-Time Processes的引入,即使使用平面内存模型,也可以通过使用保护来保护各个RTP彼此(以及内核应用程序).
With VxWorks 6.x and the introduction of Real-Time Processes, even with a flat memory model, individual RTPs are protected from each other (and kernel apps) by using protection.
如果您不使用RTP并在vxWorks内核中运行所有程序,那么将不使用任何保护措施.
If you don't use RTPs and run everything in the vxWorks kernel, then there is no protection used.
那么,保护是如何工作的(无论是在VxWorks RTP中还是在其他OS中进行处理)?本质上,RTP/进程存在于内存泡"中,该泡具有一定范围的(虚拟)地址,其中包含代码,数据,堆和其他各种内存位置.
So, how does protection work (whether in VxWorks RTPs or other OSes Process)?Essentially, the RTP/Process exists inside a "memory bubble" with a certain range of (virtual) addresses that contains code, data, heap, and other assorted memory location.
如果RTP/Process尝试访问其气泡之外的内存位置,则MMU会生成异常,并调用OS(或信号处理程序).典型的结果是路段违规/总线异常.
If the RTP/Process attempts to access a memory location outside it's bubble, the MMU generates an exception and the OS (or signal handler) gets called. The typical result is a segment violation/bus exception.
但是,如果进程无法逃避其内存气泡,该如何将其发送到以太网端口?这随处理器体系结构的不同而不同,但是从根本上说,例如,用户端(RTP)套接字库会进行系统调用"-这是一条特殊指令,可将cpu切换到内核空间和超级用户模式.此时,某种设备驱动程序(通常驻留在内核中)运行以将数据推送到某些硬件设备.完成后,系统调用返回,我们回到运行用户代码的RTP/进程空间中.
But how can a process send a packet to an ethernet port if it can't escape it's memory bubble? This varies by processor architectures, but essentially, the user-side (RTP) socket library (for example) makes a "system call" - which is a special instruction which switches the cpu to the kernel space and supervisor mode. At this point, some sort of device driver (that typically reside in the kernel) runs to push the data to some hardware device. Once that's done, the system call returns and we're back in the RTP/process space running the user code.
操作系统负责所有MMU编程,系统调用处理等.这对于应用程序是不可见的.
The OS takes care of all the MMU programming, system call handling, etc... This is invisible to the application.
这篇关于平面内存模型和受保护的内存模型之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!