The need for setting up a stack in user mode?
-
02-07-2021 - |
Question
I have been playing with assembly and OS development for a while (in both real and protected modes) and since I was working in kernel mode ("Ring 0" a.k.a "Full Privileges") I always had to worry about setting up a stack before using stack instructions (push/pop).
Now I've been looking at user mode 32 bit assembly programs (for both windows and linux) and noticed that all the program examples I saw, simply used stack instructions without first setting a stack. What is the meaning of this? Does the OS sets the process stack itself before starting said process?
Thanks in advance,
João Silva.
Solution
You gave the answer yourself already:
It's part of the system's duty to provide all necessary memory, for code, global data (heap) and local data (stack).
[update: This shouldn't remain unmentioned: Once in a less privileged ring, as any user space application is usually, it would not easily be possible for this very user space application to setup a stack. It would have to make a system call in order to allocate it. But since about 99.999% of all applications require a stack, it is equally economic to provide a stack for all user space application in the first place, without forcing the developer to request it in each program. /update]