exit.cpp 923 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <Kernel/KSyms.h>
  7. #include <Kernel/PerformanceManager.h>
  8. #include <Kernel/Process.h>
  9. #include <Kernel/Thread.h>
  10. namespace Kernel {
  11. void Process::sys$exit(int status)
  12. {
  13. // FIXME: We have callers from kernel which don't aquire the big process lock.
  14. if (Thread::current()->previous_mode() == Thread::PreviousMode::UserMode) {
  15. VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
  16. }
  17. {
  18. ProtectedDataMutationScope scope { *this };
  19. m_protected_values.termination_status = status;
  20. m_protected_values.termination_signal = 0;
  21. }
  22. auto* current_thread = Thread::current();
  23. current_thread->set_profiling_suppressed();
  24. PerformanceManager::add_thread_exit_event(*current_thread);
  25. die();
  26. current_thread->die_if_needed();
  27. VERIFY_NOT_REACHED();
  28. }
  29. }