在堆栈上分配更多页面大小的缓冲区会损坏内存吗? [英] Allocating a buffer of more a page size on stack will corrupt memory?

查看:63
本文介绍了在堆栈上分配更多页面大小的缓冲区会损坏内存吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows中,堆栈的实现如下:在指定的页面之后紧跟已提交的堆栈页面.它的保护标志受到保护.因此,当thead在受保护的页面上引用地址时,就会出现内存故障,这会使内存管理器将受保护的页面提交到堆栈中并清除该页面的受保护的标志,然后保留受保护的新页面.

In Windows, stack is implemented as followed: a specified page is followed committed stack pages. It's protection flag is as guarded. So when thead references an address on the guared page, an memory fault rises which makes memory manager commits the guarded page to the stack and clean the page's guarded flag, then it reserves a new page as guarded.

当我分配一个大小超过一页(4KB)的缓冲区时,没有发生预期的错误.为什么?

when I allocate an buffer which size is more than one page(4KB), however, an expected error haven't happen. Why?

推荐答案

很好的问题(+1).

有一个窍门,很少有人知道(除了司机作家).

There's a trick, and few people know about it (besides driver writers).

当您在堆栈上分配大缓冲区时,编译器会自动添加所谓的堆栈探针.这是一个额外的代码(通常在CRT中实现),它按需要的顺序逐页探查分配的区域.

When you allocate large buffer on the stack - the compiler automatically adds so-called stack probes. It's an extra code (implemented in CRT usually), which probes the allocated region, page-by-page, in the needed order.

函数是_chkstk.

这篇关于在堆栈上分配更多页面大小的缓冲区会损坏内存吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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