00001 /***************************************************************************************** 00002 Copyright (c) 2002-2004 The UbixOS Project 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without modification, are 00006 permitted provided that the following conditions are met: 00007 00008 Redistributions of source code must retain the above copyright notice, this list of 00009 conditions, the following disclaimer and the list of authors. Redistributions in binary 00010 form must reproduce the above copyright notice, this list of conditions, the following 00011 disclaimer and the list of authors in the documentation and/or other materials provided 00012 with the distribution. Neither the name of the UbixOS Project nor the names of its 00013 contributors may be used to endorse or promote products derived from this software 00014 without specific prior written permission. 00015 00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 00017 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00018 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 00019 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00020 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00021 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00022 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 00023 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00024 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00025 00026 $Id: fork_8c-source.html 88 2016-01-12 00:11:29Z reddawg $ 00027 00028 *****************************************************************************************/ 00029 00030 #include <ubixos/fork.h> 00031 #include <ubixos/types.h> 00032 #include <ubixos/sched.h> 00033 #include <ubixos/tty.h> 00034 #include <ubixos/vitals.h> 00035 #include <vmm/vmm.h> 00036 #include <string.h> 00037 #include <assert.h> 00038 00039 /***************************************************************************************** 00040 Functoin: static int fork_copyProcess(struct taskStruct *newProcess,long ebp,long edi, 00041 long esi, long none,long ebx,long ecx,long edx,long eip,long cs,long eflags, 00042 long esp,long ss) 00043 00044 Desc: This function will copy a process 00045 00046 Notes: 00047 00048 *****************************************************************************************/ 00049 /* Had to remove static though tihs function is only used in this file */ 00050 int fork_copyProcess(struct taskStruct *newProcess,long ebp,long edi,long esi,long none,long ebx,long ecx,long edx,long eip,long cs,long eflags,long esp,long ss) { 00051 volatile struct taskStruct * tmpProcPtr = newProcess; 00052 assert(newProcess); 00053 assert(_current); 00054 00055 /* Set Up New Tasks Information */ 00056 memcpy(newProcess->oInfo.cwd,_current->oInfo.cwd,1024); 00057 00058 newProcess->tss.eip = eip; 00059 newProcess->oInfo.vmStart = _current->oInfo.vmStart; 00060 newProcess->term = _current->term; 00061 newProcess->term->owner = newProcess->id; 00062 newProcess->uid = _current->uid; 00063 newProcess->gid = _current->gid; 00064 newProcess->tss.back_link = 0x0; 00065 newProcess->tss.esp0 = _current->tss.esp0; 00066 newProcess->tss.ss0 = 0x10; 00067 newProcess->tss.esp1 = 0x0; 00068 newProcess->tss.ss1 = 0x0; 00069 newProcess->tss.esp2 = 0x0; 00070 newProcess->tss.ss2 = 0x0; 00071 newProcess->tss.eflags = eflags; 00072 newProcess->tss.eax = 0x0; 00073 newProcess->tss.ebx = ebx; 00074 newProcess->tss.ecx = ecx; 00075 newProcess->tss.edx = edx; 00076 newProcess->tss.esi = esi; 00077 newProcess->tss.edi = edi; 00078 newProcess->tss.ebp = ebp; 00079 newProcess->tss.esp = esp; 00080 newProcess->tss.cs = cs & 0xFF; 00081 newProcess->tss.ss = ss & 0xFF; 00082 newProcess->tss.ds = _current->tss.ds & 0xFF; 00083 newProcess->tss.fs = _current->tss.fs & 0xFF; 00084 newProcess->tss.gs = _current->tss.gs & 0xFF; 00085 newProcess->tss.es = _current->tss.es & 0xFF; 00086 newProcess->tss.ldt = 0x18; 00087 newProcess->tss.trace_bitmap = 0x0000; 00088 newProcess->tss.io_map = 0x8000; 00089 /* Create A Copy Of The VM Space For New Task */ 00090 newProcess->tss.cr3 = (uInt32)vmmCopyVirtualSpace(newProcess->id); 00091 newProcess->state = FORK; 00092 00093 /* Fix gcc optimization problems */ 00094 while (tmpProcPtr->state == FORK) sched_yield(); 00095 00096 /* Return Id of Proccess */ 00097 return(newProcess->id); 00098 } 00099 00100 /***************************************************************************************** 00101 Functoin: void sysFork(); 00102 00103 Desc: This function will fork a new task 00104 00105 Notes: 00106 00107 08/01/02 - This Seems To Be Working Fine However I'm Not Sure If I 00108 Chose The Best Path To Impliment It I Guess We Will See 00109 What The Future May Bring 00110 00111 *****************************************************************************************/ 00112 asm( 00113 ".globl sysFork \n" 00114 "sysFork: \n" 00115 " xor %eax,%eax \n" 00116 " call schedNewTask \n" 00117 " testl %eax,%eax \n" 00118 " je fork_ret \n" 00119 " pushl %esi \n" 00120 " pushl %edi \n" 00121 " pushl %ebp \n" 00122 " pushl %eax \n" 00123 " call fork_copyProcess \n" 00124 " movl %eax,(%ebx) \n" 00125 " addl $16,%esp \n" 00126 "fork_ret: \n" 00127 " ret \n" 00128 ); 00129 00130 /*** 00131 END 00132 ***/ 00133