diff --git a/sortix/descriptors.cpp b/sortix/descriptors.cpp index fea77ded..8c3b787f 100644 --- a/sortix/descriptors.cpp +++ b/sortix/descriptors.cpp @@ -42,15 +42,22 @@ namespace Sortix } DescriptorTable::~DescriptorTable() + { + Reset(); + } + + void DescriptorTable::Reset() { for ( int i = 0; i < numdevices; i++ ) { if ( devices[i] == NULL || devices[i] == reserveddevideptr ) { continue; } - // TODO: unref any device here! + devices[i]->Unref(); } delete[] devices; + devices = NULL; + numdevices = 0; } int DescriptorTable::Allocate(Device* object) diff --git a/sortix/descriptors.h b/sortix/descriptors.h index 544186af..91d93cd0 100644 --- a/sortix/descriptors.h +++ b/sortix/descriptors.h @@ -45,10 +45,12 @@ namespace Sortix void Free(int index); void UseReservation(int index, Device* object); bool Fork(DescriptorTable* forkinto); + void Reset(); public: inline Device* Get(int index) { + if ( !devices ) { return NULL; } if ( index < 0 || numdevices <= index ) { return NULL; } return devices[index]; } diff --git a/sortix/process.cpp b/sortix/process.cpp index e3de57c1..b4fd9604 100644 --- a/sortix/process.cpp +++ b/sortix/process.cpp @@ -256,15 +256,6 @@ namespace Sortix // TODO: Delete all threads and their stacks. ResetAddressSpace(); - - // HACK: Don't let VGA buffers survive executes. - // Real Solution: Don't use VGA buffers in this manner. - for ( int i = 0; i < 32; i++ ) - { - Device* dev = descriptors.Get(i); - if ( !dev ) { continue; } - if ( dev->IsType(Device::VGABUFFER) ) { descriptors.Free(i); } - } } int Process::Execute(const char* programname, const byte* program, size_t programsize, int argc, const char* const* argv, CPU::InterruptRegisters* regs) @@ -572,7 +563,8 @@ namespace Sortix nextsibling->prevsibling = prevsibling; } - // TODO: Close all the file descriptors! + // Close all the file descriptors. + descriptors.Reset(); // Make all threads belonging to process unrunnable. for ( Thread* t = firstthread; t; t = t->nextsibling )