在Windows和Linux上,堆栈增长如何工作? [英] how does stack growing work on windows and linux?

查看:138
本文介绍了在Windows和Linux上,堆栈增长如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚读到,如果Windows程序需要大于4k的堆栈,则它们会在函数入口上调用_alloca来增大堆栈.我想知道每次访问防护页面时,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(或其他oses)如何在不需要_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屋!

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