2021-06-23 19:54:41 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <AK/Assertions.h>
|
2022-10-25 16:34:38 +00:00
|
|
|
#include <Kernel/Arch/CPU.h>
|
2021-07-25 21:26:07 +00:00
|
|
|
#include <Kernel/Panic.h>
|
2021-06-23 19:54:41 +00:00
|
|
|
#include <Kernel/Process.h>
|
|
|
|
|
2021-10-02 06:45:15 +00:00
|
|
|
using namespace Kernel;
|
|
|
|
|
2022-04-01 17:58:27 +00:00
|
|
|
void __assertion_failed(char const* msg, char const* file, unsigned line, char const* func)
|
2021-06-23 19:54:41 +00:00
|
|
|
{
|
|
|
|
asm volatile("cli");
|
|
|
|
critical_dmesgln("ASSERTION FAILED: {}", msg);
|
|
|
|
critical_dmesgln("{}:{} in {}", file, line, func);
|
|
|
|
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
[[noreturn]] void abort()
|
|
|
|
{
|
2021-09-07 07:17:45 +00:00
|
|
|
// Avoid lock ranking checks on crashing paths, just try to get some debugging messages out.
|
|
|
|
auto thread = Thread::current();
|
|
|
|
if (thread)
|
|
|
|
thread->set_crashing();
|
|
|
|
|
2021-06-23 19:54:41 +00:00
|
|
|
// Switch back to the current process's page tables if there are any.
|
|
|
|
// Otherwise stack walking will be a disaster.
|
2021-08-19 19:45:07 +00:00
|
|
|
if (Process::has_current())
|
2021-10-02 06:45:15 +00:00
|
|
|
Memory::MemoryManager::enter_process_address_space(Process::current());
|
2021-06-23 19:54:41 +00:00
|
|
|
|
2021-07-25 21:26:07 +00:00
|
|
|
PANIC("Aborted");
|
2021-06-23 19:54:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[[noreturn]] void _abort()
|
|
|
|
{
|
|
|
|
asm volatile("ud2");
|
|
|
|
__builtin_unreachable();
|
|
|
|
}
|