堆栈增长如何在 Windows 和 linux 上工作? [英] how does stack growing work on windows and linux?
问题描述
我刚刚读到 Windows 程序在函数入口调用 _alloca
来增加堆栈,如果它们需要超过 4k 的堆栈.我猜想每次访问保护页面时,windows 都会为堆栈分配一个新页面,因此 _alloca
以 4k 步访问堆栈以分配空间.
I just read that windows programs call _alloca
on function entry to grow the stack if they need more than 4k on the stack. I guss that every time the guard page is hit windows allocates a new page for the stack, therefore _alloca
accesses the stack in 4k steps to allocate the space.
我还读到这仅适用于 Windows.如果linux(或其他ose)不需要_alloca
,他们如何解决这个问题?
I also read that this only applies to windows. How does linux (or other oses) solve this problem if they don't need _alloca
?
推荐答案
Linux 依赖于一个高度优化的页面错误处理,所以发生的情况是程序只是将东西压入堆栈,而页面错误处理程序将扩展堆栈苍蝇.
Linux relies on a heavily optimized page fault handling, so what happens is that the program just pushes things on the stack and the page fault handler will extend the stack on the fly.
这篇关于堆栈增长如何在 Windows 和 linux 上工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!