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

@ -226,6 +226,14 @@ ExceptionHandler (ExceptionType which)
do_ThreadExit();
break;
}
case SC_ForkExec:
{
int s = machine->ReadRegister(4);
char * command = new char[MAX_STRING_SIZE];
int size = copyStringFromMachine(s, command, MAX_STRING_SIZE);
do_ForkExec(command);
break;
}
#endif
default:
{

View file

@ -40,6 +40,7 @@
#define SC_GetInt 16
#define SC_ThreadCreate 17
#define SC_ThreadExit 18
#define SC_ForkExec 19
#endif
#ifdef IN_USER_MODE
@ -148,6 +149,7 @@ void PutInt(int n);
void GetInt( int * n);
int ThreadCreate(void f(void * args), void * args);
void ThreadExit(void);
int ForkExec ( const char * s);
#endif // CHANGED

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

View file

@ -11,4 +11,5 @@ typedef struct {
extern int do_ThreadCreate(int f, int arg);
extern void do_ThreadExit();
extern int do_ForkExec( const char * s);
#endif