I've got the following question: what detrmines the size of the stack of a process in Linux?
Below are two programs written in C and their disassembly (I know Prog1.c is not the way one should handle with pointers :) ). The assembly codes are very similiar but execution of the first program causes segmentation fault. The initial stack of the first program is about 12 KB while for the second it's about 980 KB. What determines this, if the assembly codes are so similiar?
And even assumming that initial stack of the first program is 12 KB - why writing to address from within the stack limit (about 8 MB on my system) doesn't make the system expand the stack?
Is there any stack allocation at the binary level? Is the stack size determined by the compiler?
Prog1.c:
int main()
{
char a;
char* b = &a;
b = b - 999999;
*b = '\0';
}
Prog1.s:
.file "prog1.c" .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp subl $16, %esp leal -5(%ebp), %eax movl %eax, -4(%ebp) subl $999999, -4(%ebp) movl -4(%ebp), %eax movb $0, (%eax) leave ret .size main, .-main .ident "GCC: (GNU) 4.4.3" .section .note.GNU-stack,"",@progbits
Prog2.c:
int main()
{
char a[1000000];
char* b = &a[0];
*b = '\0';
}
Prog2.s:
.file "prog2.c" .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp subl $1000016, %esp leal -1000004(%ebp), %eax movl %eax, -4(%ebp) movl -4(%ebp), %eax movb $0, (%eax) leave ret .size main, .-main .ident "GCC: (GNU) 4.4.3" .section .note.GNU-stack,"",@progbits


Sign In
Create Account

Back to top










