Page 1 of 1
Stack for new processes
Posted: Sat May 31, 2008 4:55 am
by thepowersgang
I'm currently working on the process loader for Acess, and I was wondering how the stack should be initialized for a new process.
At the moment it resides at the end of the .bss segment but is it supposed to be allocated by the kernel to a set size or specified in the executable image?
The executable format I'm using is ELF-32.
Posted: Sat May 31, 2008 5:40 am
by xyzzy
On ELF binaries at least the stack size and where it is (within reason, as in, must be accessible by the process if it is in usermode
) is up to you. When switching to usermode in a new process, I allocate a 4MB stack using my virtual memory manager, and the process uses that.
Posted: Sat May 31, 2008 9:38 am
by thepowersgang
Thanks, I was thinking that that was the case, but I wanted to be sure.
Posted: Sat May 31, 2008 9:44 am
by CmpXchg
An idea might be to push some value on the stack so that the program will be able to execute RET to exit. The exit code could than be returned in EAX.
Posted: Sat May 31, 2008 9:45 am
by Combuster
I have a piece of assembly in the C runtime which is called first thing at process startup. Amongst others, it asks the kernel for a piece of memory and sets the stack to that.
Posted: Sat May 31, 2008 10:48 am
by lukem95
Combuster wrote:I have a piece of assembly in the C runtime which is called first thing at process startup. Amongst others, it asks the kernel for a piece of memory and sets the stack to that.
this is what i'm going to do (when i get round to porting my c library). it seems like the easiest and most effective approach