Page 1 of 1

Why Xinu OS rounds stack size when creating a new process?

Posted: Wed Mar 14, 2018 8:44 am
by rrd
I'm taking a look into the Xinu's code trying to understand what some parts of the code does in the system.

In the function create, that creates a new process, the stack size of the process, an argument defined by the user, is rounded with a function called roundew. I read the docs but I'm not sure if I understand exactly what that function does and why is needed to do that with size of the stack.

Is it just a 4-byte memory alignment? I'm learning about this subject right now, so I don't understand exactly why memory alignment is so important and how an OS implements it.

Re: Why Xinu OS rounds stack size when creating a new proces

Posted: Wed Mar 14, 2018 12:03 pm
by BrightLight
On i386, the stack should be 4-byte aligned. On x86_64, the stack should be 8-byte aligned. But to comply with the System V ABI, the stack must be 16-byte aligned when you call a function. I haven't looked into the source code you mention, nor have I ever heard about it, but this is what I do know about stack alignment on the x86.

Re: Why Xinu OS rounds stack size when creating a new proces

Posted: Wed Mar 14, 2018 3:58 pm
by zaval
Aligning stack pointer on 8 bytes on 32 bits and on 16 bytes on 64 bits is common not only on x86. An old mips supplement from SCO, that that describes calling conventions and all those elf platform specific things, honestly admits, that even though the processor wants 4-byte alignment for its words (4 bytes) at the best, OS environment "traditionally" wanted it to be 8-byte aligned... It's as much a mystery, roots of which have sank in history, as this XINU thing I guess. :D