Skip to content

Commit df90f69

Browse files
committed
Only kill process if main thread
1 parent 01035f6 commit df90f69

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

Kernel/include/TTY/PTY.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class PTMultiplexor final : public Device {
4545

4646
PTMultiplexor();
4747

48-
lock_t m_ptmxLock;
48+
lock_t m_ptmxLock = 0;
4949
int m_nextPT = 0; // PTYs are named /dev/pts/0, 1, 2, ...
5050

5151
PTS m_pts;

Kernel/src/Arch/x86_64/IDT.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,12 @@ extern "C" void isr_handler(int intNum, RegisterContext* regs) {
259259
;
260260
} else {
261261
int res = acquireTestLock(&Scheduler::GetCurrentThread()->kernelLock);
262-
assert(!res); // Make sure we acquired the lock
262+
if(res) { // Make sure we acquired the lock
263+
assert(Process::Current()->State() != Process::Process_Running);
264+
for(;;) {
265+
Scheduler::Yield();
266+
}
267+
}
263268

264269
Process* current = Process::Current();
265270

Kernel/src/Arch/x86_64/Paging.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ void MapVirtualMemory4K(uint64_t phys, uint64_t virt, uint64_t amount, uint64_t
683683
CreatePageTable(pdptIndex, pageDirIndex,
684684
pageMap); // If we don't have a page table at this address, create one.
685685

686+
assert(pageMap->pageTables[pdptIndex][pageDirIndex]);
686687
pageMap->pageTables[pdptIndex][pageDirIndex][pageIndex] = flags;
687688
SetPageFrame(&(pageMap->pageTables[pdptIndex][pageDirIndex][pageIndex]), phys);
688689

Kernel/src/Objects/Process.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,19 @@ void Process::Die() {
303303

304304
CPU* cpu = GetCPULocal();
305305

306-
if(m_state == Process_Dying) {
307-
// Process is already dying, we might be another thread
308-
releaseLock(&Thread::Current()->kernelLock);
306+
// Check if we are main thread
307+
if(cpu->currentThread != cpu->currentThread->parent->GetMainThread().get()) {
308+
acquireLock(&m_processLock);
309+
if(m_state != Process_Dying) {
310+
// Kill the main thread
311+
cpu->currentThread->parent->GetMainThread()->Signal(SIGKILL);
312+
}
313+
314+
asm volatile("cli");
315+
releaseLock(&m_processLock);
316+
releaseLock(&cpu->currentThread->kernelLock);
317+
cpu->currentThread->state = ThreadStateDying;
318+
asm volatile("sti");
309319
for(;;) Scheduler::Yield();
310320
}
311321

0 commit comments

Comments
 (0)