.STACK未在MASM中分配正确的大小 [英] .STACK is not allocating the correct size in MASM
问题描述
基于 Microsoft MASM文档,.STACK指令的用法是
Based on Microsoft MASM Documentation, the usage of .STACK directive is
与.MODEL一起使用时,定义堆栈段(段名称为STACK).可选大小指定堆栈的字节数(默认为1,024). .STACK指令自动关闭堆栈语句. (仅限32位MASM.)
为了实验,我做了.STACK
来分配1,073,741,824 bytes (1 GB)
For the sake of experimentation, I made the .STACK
to allocate 1,073,741,824 bytes (1 GB)
请注意,我正在Visual Studio 2013控制台项目中运行代码.
.586
.MODEL FLAT
.STACK 1073741824
.DATA
a DWORD 50
b DWORD 55
.CODE
main PROC
addLoop: mov eax, a
push eax
mov eax, 0
mov ebx, b
push ebx
jmp addLoop
RET
main ENDP
END
代码将溢出堆栈.我所做的就是记下ESP
寄存器的第一个地址,让代码运行直到溢出,然后从第一个中减去最后一个ESP
以获得堆栈的大小.
The code will overflow the stack. What I did was I noted down the first address of the ESP
register, let the code run until overflowed, and took the final ESP
to be subtracted from the first one to get the size of the stack.
在我的上下文中,它是00DAFEE4 - 00CB3000 + 1 = 000FCEE5
.只是1036005 bytes (~1 MB)
.
In my context, it's 00DAFEE4 - 00CB3000 + 1 = 000FCEE5
. Which is only 1036005 bytes (~1 MB)
.
为什么?
推荐答案
尽管文档说了什么,但是当创建32位PECOFF对象文件时,.STACK指令没有做任何有用的事情.它所做的只是创建一个名为STACK的空部分,而不管给定的大小如何.该指令仅在创建16位代码时使用.
Despite what the documentation says, the .STACK directive doesn't do anything useful when creating a 32-bit PECOFF object file. All it does is create an empty section named STACK, regardless of the size given. This directive is meant only to be use used when creating 16-bit code.
Instead using the .STACK directive you can use the the /STACK linker option. You should be able to set this option from the Visual Studio IDE from your project's Property Page -> Linker -> System -> Stack Reserve Size.
这篇关于.STACK未在MASM中分配正确的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!