将 & 符号应用于 C/C++ 或任何其他此类语言中的变量或数据类型时返回什么类型的地址?

2021-12-24 00:00:00 operating-system c memory-management c++

自从我在我的操作系统课程中听说虚拟和物理内存概念的那一天起,这是一个非常基本的问题.现在我知道在加载时和编译时,虚拟地址和逻辑地址绑定方案是相同的,但在执行时它们不同.

This is a very basic question boggling mind since the day I heard about the concept of virtual and physical memory concept in my OS class. Now I know that at load time and compile time , virtual address and logical adress binding scheme is same but at execution time they differ.

首先为什么在编译和加载时生成虚拟地址是有益的,以及当我们应用与号运算符获取变量地址、原始数据类型、用户定义类型和函数定义地址时返回什么?

First of all why is it beneficial to generate virtual address at compile and load time and and what is returned when we apply the ampersand operator to get the address of a variable, naive datatypes , user-defined type and function definition addresses?

当它这样做时,操作系统如何从虚拟地址精确映射到物理地址?这些问题是出于好奇而提出来的,考虑到现代操作系统,我会喜欢一些好的和深刻的见解,早期操作系统的情况如何.我只针对 C/C++,因为我对其他语言知之甚少.

And how does OS maps exactly from virtual to physical address when it does so? These questions are hust out from curiosity and I would love some good and deep insights considering modern day OS' , How was it in early days OS' .I am only C/C++ specific since I don't know much about other languages.

推荐答案

物理地址出现在硬件中,而不是软件中.操作系统内核中可能/偶尔出现异常.物理意味着它是系统总线和 RAM 芯片看到的地址.

Physical addresses occur in hardware, not software. A possible/occasional exception is in the operating system kernel. Physical means it's the address that the system bus and the RAM chips see.

物理地址不仅对软件无用,而且可能是一个安全问题.无需地址转换即可访问任何物理内存,并知道其他进程的地址,将允许不受限制地访问机器.

Not only are physical addresses useless to software, but it could be a security issue. Being able to access any physical memory without address translation, and knowing the addresses of other processes, would allow unfettered access to the machine.

也就是说,较小的或嵌入式机器可能没有虚拟内存,而一些较旧的操作系统确实允许共享库指定其最终的物理内存位置.此类政策会损害安全性并且已过时.

That said, smaller or embedded machines might have no virtual memory, and some older operating systems did allow shared libraries to specify their final physical memory location. Such policies hurt security and are obsolete.

相关文章