平面内存模型和受保护内存模型之间的区别? [英] Difference between flat memory model and protected memory model?

查看:16
本文介绍了平面内存模型和受保护内存模型之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

平面内存模型和受保护内存模型的区别?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 如何让 10 个进程都从地址 0x10000 运行?

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 和标准 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 和实时进程的引入,即使使用扁平内存模型,各个 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 还是其他操作系统进程中)?从本质上讲,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/进程尝试访问气泡外的内存位置,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.

这篇关于平面内存模型和受保护内存模型之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆