@@ -688,13 +688,22 @@ bool kprocess_yield (ProcessRegisterState* currentState)
688688 return s_switchProcess (pinfo , currentState );
689689}
690690
691- bool kprocess_exit (U8 exitCode )
691+ bool kprocess_exit (U8 exitCode , bool killBranch )
692692{
693- FUNC_ENTRY ("Exit Code: %x" , exitCode );
693+ FUNC_ENTRY ("Exit Code: %x, killBranch: %x" , exitCode , killBranch );
694+
695+ k_assert (currentProcess != NULL , "Nothing to exit" );
694696
695697 UINT ret ;
696- UINT flags = ( currentProcess != NULL ) ? currentProcess -> flags : 0 ;
698+ UINT flags = currentProcess -> flags ;
697699 UINT l_exitCode = (UINT )exitCode ;
700+ KProcessInfo * process = currentProcess ;
701+
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 ) {
705+ process = currentProcess -> parent ;
706+ }
698707
699708 // clang-format off
700709 // In a Kernel process, no stack switch happens in a system call and the same process stack is
@@ -721,10 +730,9 @@ bool kprocess_exit (U8 exitCode)
721730 //////////////////////////////////////////////////////////////////////////////
722731 ".cont:;"
723732 //////////////////////////////////////////////////////////////////////////////
724- // Call to kprocess_kill_process to kill 'currentProcess '.
733+ // Call to kprocess_kill_process to kill 'current process '.
725734 " push %2;" // exit code
726- " lea eax, [currentProcess];"
727- " push eax;" // ¤tProcess
735+ " push %3;"
728736 " call kprocess_kill_process;"
729737 " add esp, 16;"
730738 //////////////////////////////////////////////////////////////////////////////
@@ -734,6 +742,7 @@ bool kprocess_exit (U8 exitCode)
734742 //////////////////////////////////////////////////////////////////////////////
735743 // Call to kprocess_yield to go to the next process now that the current one is
736744 // destoryed.
745+ " mov DWORD PTR [currentProcess], 0;"
737746 " xor eax, eax;" // NULL is passed in the first argument of yeld.
738747 " push eax;"
739748 " call kprocess_yield;"
@@ -747,8 +756,8 @@ bool kprocess_exit (U8 exitCode)
747756 " pop ebp;"
748757 //////////////////////////////////////////////////////////////////////////////
749758 : "= r "(ret )
750- : "r "(flags ), "r" (l_exitCode )
751- : // No clobber
759+ : "r "(flags ), "r" (l_exitCode ), "r" ( & process )
760+ : " memory "
752761 );
753762 // clang-format on
754763
0 commit comments