TD3:II.1 First working version of ForkExec

But need to implement Process exit...
This commit is contained in:
Yorick Barbanneau 2021-12-08 01:30:52 +01:00
parent f7eca8c6ac
commit 07853cbcd3
8 changed files with 61 additions and 4 deletions

View file

@ -88,8 +88,46 @@ void do_ThreadExit(){
if ( currentThread->space->threads == 0 ){
// No threads remains, desallocate addrspace
delete currentThread->space;
Exit(0);
currentThread->space = NULL;
}
currentThread->Finish();
}
void StartUserProc( void * args ){
currentThread->space->InitRegisters();
currentThread->space->RestoreState();
machine->DumpMem("memory.svg");
machine->Run();
}
int do_ForkExec( const char * c){
DEBUG('x', "Enter ForkExec\n");
AddrSpace * space;
Thread * fork;
OpenFile * file;
file = fileSystem->Open(c);
if (file == NULL) {
printf("Unable to open file %s\n", file);
return -1;
}
try {
space = new AddrSpace(file);
}catch(const std::bad_alloc& e) {
printf("==> BAD ALLOC ERROR: no empty space\n");
delete space;
ASSERT(false);
}
fork = new Thread("forkThread");
fork->space = space;
fork->Start(StartUserProc, NULL);
delete file;
return 0;
}
#endif