mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 09:17:35 +00:00
Kernel+LibC: Clean up how assertions work in the kernel and LibC
This also brings LibC's abort() function closer to the spec.
This commit is contained in:
parent
33a9b2a3c3
commit
f033416893
13 changed files with 36 additions and 73 deletions
|
@ -189,7 +189,6 @@ namespace Kernel {
|
|||
S(prctl) \
|
||||
S(mremap) \
|
||||
S(set_coredump_metadata) \
|
||||
S(abort) \
|
||||
S(anon_create) \
|
||||
S(msyscall) \
|
||||
S(readv) \
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include <Kernel/Arch/x86/ISRStubs.h>
|
||||
#include <Kernel/Arch/x86/ProcessorInfo.h>
|
||||
#include <Kernel/Arch/x86/SafeMem.h>
|
||||
#include <Kernel/Assertions.h>
|
||||
#include <Kernel/Debug.h>
|
||||
#include <Kernel/IO.h>
|
||||
#include <Kernel/Interrupts/APIC.h>
|
||||
|
@ -2419,6 +2420,13 @@ void __assertion_failed(const char* msg, const char* file, unsigned line, const
|
|||
dmesgln("ASSERTION FAILED: {}", msg);
|
||||
dmesgln("{}:{} in {}", file, line, func);
|
||||
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
|
||||
[[noreturn]] void abort()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
// Switch back to the current process's page tables if there are any.
|
||||
// Otherwise stack walking will be a disaster.
|
||||
auto process = Process::current();
|
||||
|
@ -2427,9 +2435,17 @@ void __assertion_failed(const char* msg, const char* file, unsigned line, const
|
|||
|
||||
Kernel::dump_backtrace();
|
||||
Processor::halt();
|
||||
}
|
||||
#endif
|
||||
|
||||
abort();
|
||||
}
|
||||
|
||||
[[noreturn]] void _abort()
|
||||
{
|
||||
asm volatile("ud2");
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
NonMaskableInterruptDisabler::NonMaskableInterruptDisabler()
|
||||
{
|
||||
IO::out8(0x70, IO::in8(0x70) | 0x80);
|
||||
|
|
|
@ -35,12 +35,13 @@
|
|||
# define VERIFY_NOT_REACHED() VERIFY(false)
|
||||
#else
|
||||
# define VERIFY(expr)
|
||||
# define VERIFY_NOT_REACHED() CRASH()
|
||||
# define VERIFY_NOT_REACHED() _abort()
|
||||
#endif
|
||||
#define CRASH() \
|
||||
do { \
|
||||
asm volatile("ud2"); \
|
||||
} while (0)
|
||||
|
||||
extern "C" {
|
||||
[[noreturn]] void _abort();
|
||||
[[noreturn]] void abort();
|
||||
}
|
||||
|
||||
#define VERIFY_INTERRUPTS_DISABLED() VERIFY(!(cpu_flags() & 0x200))
|
||||
#define VERIFY_INTERRUPTS_ENABLED() VERIFY(cpu_flags() & 0x200)
|
||||
|
|
|
@ -131,7 +131,6 @@ set(KERNEL_SOURCES
|
|||
StdLib.cpp
|
||||
Syscall.cpp
|
||||
Syscalls/anon_create.cpp
|
||||
Syscalls/abort.cpp
|
||||
Syscalls/access.cpp
|
||||
Syscalls/alarm.cpp
|
||||
Syscalls/beep.cpp
|
||||
|
|
|
@ -408,7 +408,6 @@ public:
|
|||
KResultOr<FlatPtr> sys$allocate_tls(size_t);
|
||||
KResultOr<int> sys$prctl(int option, FlatPtr arg1, FlatPtr arg2);
|
||||
KResultOr<int> sys$set_coredump_metadata(Userspace<const Syscall::SC_set_coredump_metadata_params*>);
|
||||
[[noreturn]] void sys$abort();
|
||||
KResultOr<int> sys$anon_create(size_t, int options);
|
||||
|
||||
template<bool sockname, typename Params>
|
||||
|
|
|
@ -99,7 +99,7 @@ KResultOr<FlatPtr> handle(RegisterState& regs, FlatPtr function, FlatPtr arg1, F
|
|||
auto& process = current_thread->process();
|
||||
current_thread->did_syscall();
|
||||
|
||||
if (function == SC_abort || function == SC_exit || function == SC_exit_thread) {
|
||||
if (function == SC_exit || function == SC_exit_thread) {
|
||||
// These syscalls need special handling since they never return to the caller.
|
||||
|
||||
if (auto* tracer = process.tracer(); tracer && tracer->is_tracing_syscalls()) {
|
||||
|
@ -109,9 +109,6 @@ KResultOr<FlatPtr> handle(RegisterState& regs, FlatPtr function, FlatPtr arg1, F
|
|||
}
|
||||
|
||||
switch (function) {
|
||||
case SC_abort:
|
||||
process.sys$abort();
|
||||
break;
|
||||
case SC_exit:
|
||||
process.sys$exit(arg1);
|
||||
break;
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
||||
#include <Kernel/Process.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
void Process::sys$abort()
|
||||
{
|
||||
crash(SIGABRT, 0);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue