bss 段并将它们加载到内存中
Section bss and loading them to the memory
这里https://web.stanford.edu/~ouster/cgi-bin/cs140-winter16/pintos/pintos_6.html写的是:
The first step in main() is to call bss_init(), which clears out the
kernel's "BSS", which is the traditional name for a segment that
should be initialized to all zeros. In most C implementations,
whenever you declare a variable outside a function without providing
an initializer, that variable goes into the BSS. Because it's all
zeros, the BSS isn't stored in the image that the loader brought into
memory. We just use memset() to zero it out.
我标出了我不明白的部分。为什么 bss section "equal to 0" 会导致这种行为?当且仅当它是一般点而不依赖于实现时,这个问题才有意义。
不是存储全零的 N 个字节,而是为 BSS 存储的只是一个长度。
将 BSS 与数据部分分开的全部意义在于实现此 space 节省。所以它不会导致行为,它启用它。
您可以将其视为 运行 长度的编码,用于可以用零初始化的所有内容。
So, what do we zero out?
加载图像时分配的内存,表明它需要 N 字节 BSS。
请注意,在非玩具操作系统中,所有 BSS 页面通常开始时都是写时复制映射到单个零物理页面(在系统范围内共享)。当一个进程弄脏这样一个页面时,它会触发一个 "minor" 页面错误,并且内核会给它一个私有的归零页面作为现在变脏的虚拟页面的支持。 (并且在 return 从小故障开始,第一次出错的存储指令成功执行,导致 TLB 未命中读取新更新的页面 table。)
这里https://web.stanford.edu/~ouster/cgi-bin/cs140-winter16/pintos/pintos_6.html写的是:
The first step in main() is to call bss_init(), which clears out the kernel's "BSS", which is the traditional name for a segment that should be initialized to all zeros. In most C implementations, whenever you declare a variable outside a function without providing an initializer, that variable goes into the BSS. Because it's all zeros, the BSS isn't stored in the image that the loader brought into memory. We just use memset() to zero it out.
我标出了我不明白的部分。为什么 bss section "equal to 0" 会导致这种行为?当且仅当它是一般点而不依赖于实现时,这个问题才有意义。
不是存储全零的 N 个字节,而是为 BSS 存储的只是一个长度。
将 BSS 与数据部分分开的全部意义在于实现此 space 节省。所以它不会导致行为,它启用它。
您可以将其视为 运行 长度的编码,用于可以用零初始化的所有内容。
So, what do we zero out?
加载图像时分配的内存,表明它需要 N 字节 BSS。
请注意,在非玩具操作系统中,所有 BSS 页面通常开始时都是写时复制映射到单个零物理页面(在系统范围内共享)。当一个进程弄脏这样一个页面时,它会触发一个 "minor" 页面错误,并且内核会给它一个私有的归零页面作为现在变脏的虚拟页面的支持。 (并且在 return 从小故障开始,第一次出错的存储指令成功执行,导致 TLB 未命中读取新更新的页面 table。)