Is it bad that a process should self create an own stack?

130 Views Asked by At

Is it bad that a process should self create an own stack? If a kernel does not want to do it.

Like here

_start:
    mov $stack_head, %rsp
    jmp main

.data
.align 8
stack:
    .quad 0
    .quad 0
    .quad 0
    .quad 0
stack_head:

or using the malloc syscall.

2

There are 2 best solutions below

4
On

Some OSs even require setting up the stack like this.

However malloc() will not work because functions like malloc() typically require an already set-up stack pointer.

Under Linux - for example - doing it like this is a very bad idea because Linux observes the stack pointer and automatically allocates more memory if required. If you move the stack pointer like this you'll possibly cause a crash of your program.

0
On

No, not as such. Some systems even require it. But it's always a good idea to follow the conventions, if possible.


I don't think it's THAT dangerous - even in linux - to prepare another stack for a program. Linux sets up a stack anyway (unless you explicitly say "no thanks"). But one better be careful not to get confused with the stacks.

A good and beautiful idea it is not, in case of Linux or Windows, because it's against the conventions. Also it's somewhat more (unnecessary) trouble.

In many RTOSes you have to set up the stacks yourself.