2012-04-05 17:00:47 -04:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
Copyright(C) Jonas 'Sortie' Termansen 2012.
|
2012-04-05 17:00:47 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
This file is part of the Sortix C Library.
|
2012-04-05 17:00:47 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
The Sortix C Library is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
option) any later version.
|
2012-04-05 17:00:47 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
The Sortix C Library is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
2012-04-05 17:00:47 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
2012-04-05 17:00:47 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
x86/fork.s
|
|
|
|
Assembly functions related to forking x86 processes.
|
2012-04-05 17:00:47 -04:00
|
|
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
.section .text
|
|
|
|
|
2012-08-05 11:35:19 -04:00
|
|
|
.globl __call_tfork_with_regs
|
|
|
|
.type __call_tfork_with_regs, @function
|
|
|
|
__call_tfork_with_regs:
|
2012-04-05 17:00:47 -04:00
|
|
|
pushl %ebp
|
|
|
|
movl %esp, %ebp
|
|
|
|
|
|
|
|
movl 8(%ebp), %edx # flags parameter, edx need not be preserved.
|
|
|
|
|
2012-08-05 11:35:19 -04:00
|
|
|
# The actual system call expects a struct tforkregs_x86 containing the state
|
2012-04-05 17:00:47 -04:00
|
|
|
# of each register in the child. Since we create an identical copy, we
|
|
|
|
# simply set each member of the structure to our own state. Note that since
|
|
|
|
# the stack goes downwards, we create it in the reverse order.
|
|
|
|
pushfl
|
|
|
|
pushl %ebp
|
|
|
|
pushl %esp
|
|
|
|
pushl %esi
|
|
|
|
pushl %edi
|
|
|
|
pushl %edx
|
|
|
|
pushl %ecx
|
|
|
|
pushl %ebx
|
|
|
|
pushl $0 # rax, result of sfork is 0 for the child.
|
|
|
|
pushl $after_fork # rip, child will start execution from here.
|
|
|
|
|
2012-08-05 11:35:19 -04:00
|
|
|
# Call tfork with a nice pointer to our structure. Note that %edi contains
|
2012-04-05 17:00:47 -04:00
|
|
|
# the flag parameter that this function accepted.
|
|
|
|
pushl %esp
|
|
|
|
pushl %edx
|
2012-08-05 11:35:19 -04:00
|
|
|
call tfork
|
2012-04-05 17:00:47 -04:00
|
|
|
|
|
|
|
after_fork:
|
|
|
|
# The value in %eax determines whether we are child or parent. There is no
|
|
|
|
# need to clean up the stack from the above pushes, leavel sets %esp to %ebp
|
|
|
|
# which does that for us.
|
|
|
|
leavel
|
|
|
|
retl
|
2013-05-22 16:06:18 -04:00
|
|
|
.size __call_tfork_with_regs, . - __call_tfork_with_regs
|