bmarcot / vega

vega -- The Unix-like Operating System for micro-controllers (ARM Cortex-M4)
6 stars 1 forks source link

vfork() should use parent's process stack #35

Closed bmarcot closed 6 years ago

bmarcot commented 6 years ago

Kernel allocates a new process stack during vfork(). We should reuse the parent stack instead (child->sp = parent->sp at the time of the vfork()), child will push/pop new stackframes, but won't pop any stackframes pushed by the parent because child cannot return from function calling vfork(). The child cannot return from the function calling vfork(), and also cannot modify any other variables than the vfork() return code.

From Linux man page:

vfork() differs from fork(2) in that the calling thread is suspended until the child terminates (either normally, by calling _exit(2), or abnormally, after delivery of a fatal signal), or it makes a call to execve(2). Until that point, the child shares all memory with its parent, including the stack. The child must not return from the current function or call exit(3) (which would have the effect of calling exit handlers established by the parent process and flushing the parent's stdio(3) buffers), but may call _exit(2).

http://man7.org/linux/man-pages/man2/vfork.2.html

bmarcot commented 6 years ago

Fixed in 084900f09