Stack for new processes

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Stack for new processes

Post 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.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
xyzzy
Member
Member
Posts: 391
Joined: Wed Jul 25, 2007 8:45 am
Libera.chat IRC: aejsmith
Location: London, UK
Contact:

Post 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.
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Post by thepowersgang »

Thanks, I was thinking that that was the case, but I wanted to be sure.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
User avatar
CmpXchg
Member
Member
Posts: 61
Joined: Mon Apr 28, 2008 12:14 pm
Location: Petrozavodsk, Russia during school months, Vänersborg Sweden in the summertime

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
lukem95
Member
Member
Posts: 536
Joined: Fri Aug 03, 2007 6:03 am
Location: Cambridge, UK

Post 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
~ Lukem95 [ Cake ]
Release: 0.08b
Image
Post Reply