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