Skip to content

Commit c2d3713

Browse files
committed
Fix: Non-Thread processes could not be aborted
Also includes: * Minor refactoring of code, spelling corrections and update to related comments.
1 parent e6ef1d2 commit c2d3713

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

include/process.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ typedef struct KProcessInfo {
7070
void kprocess_init();
7171
INT kprocess_create (void* processStartAddress, SIZE binLengthBytes, KProcessFlags flags);
7272
bool kprocess_yield (ProcessRegisterState* currentState);
73-
bool kprocess_exit (U8 exitCode, bool killBranch);
73+
bool kprocess_exit (U8 exitCode, bool destroyContext);
7474
VMemoryManager* kprocess_getCurrentContext();
7575
UINT kprocess_getCurrentPID();
7676
bool kprocess_popEvent (UINT pid, KProcessEvent* ev);

src/kernel/x86/process.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -688,9 +688,9 @@ bool kprocess_yield (ProcessRegisterState* currentState)
688688
return s_switchProcess (pinfo, currentState);
689689
}
690690

691-
bool kprocess_exit (U8 exitCode, bool killBranch)
691+
bool kprocess_exit (U8 exitCode, bool destroyContext)
692692
{
693-
FUNC_ENTRY ("Exit Code: %x, killBranch: %x", exitCode, killBranch);
693+
FUNC_ENTRY ("Exit Code: %x, destroyContext: %x", exitCode, destroyContext);
694694

695695
k_assert(currentProcess != NULL, "Nothing to exit");
696696

@@ -699,9 +699,12 @@ bool kprocess_exit (U8 exitCode, bool killBranch)
699699
UINT l_exitCode = (UINT)exitCode;
700700
KProcessInfo* process = currentProcess;
701701

702-
// If parent of the current process is NULL, then the current process is the root process
703-
// and branch head. Otherwise its the parent of the current process.
704-
if (killBranch && currentProcess->parent != NULL) {
702+
// Context is destroyed when the process owning it is killed. For thread processes its their
703+
// parent (non-thread) process who owns the shared context. For non-thread processes the context
704+
// is own by themselves, so nothing special needs to be done. Context owned by Root process
705+
// cannot be destroyed.
706+
if (destroyContext && currentProcess->parent != NULL &&
707+
BIT_ISSET (currentProcess->flags, PROCESS_FLAGS_THREAD)) {
705708
process = currentProcess->parent;
706709
}
707710

@@ -741,9 +744,9 @@ bool kprocess_exit (U8 exitCode, bool killBranch)
741744
" jz .fin;"
742745
//////////////////////////////////////////////////////////////////////////////
743746
// Call to kprocess_yield to go to the next process now that the current one is
744-
// destoryed.
747+
// destroyed.
745748
" mov DWORD PTR [currentProcess], 0;"
746-
" xor eax, eax;" // NULL is passed in the first argument of yeld.
749+
" xor eax, eax;" // NULL is passed in the first argument of yield.
747750
" push eax;"
748751
" call kprocess_yield;"
749752
" add esp, 4;"

0 commit comments

Comments
 (0)