From d9916587949ba232297ad908146ae0885a5e3c22 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 4 Jan 2021 21:26:32 +0100 Subject: [PATCH] Kernel+LibC: Tidy up assertion failures with a dedicated syscall This patch adds sys$abort() which immediately crashes the process with SIGABRT. This makes assertion backtraces a lot nicer by removing all the gunk that otherwise happens between __assertion_failed() and actually crashing from the SIGABRT. --- Kernel/API/Syscall.h | 3 ++- Kernel/CMakeLists.txt | 1 + Kernel/Process.h | 1 + Kernel/Syscalls/abort.cpp | 39 +++++++++++++++++++++++++++++++++++++++ Libraries/LibC/assert.cpp | 4 ++-- 5 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 Kernel/Syscalls/abort.cpp diff --git a/Kernel/API/Syscall.h b/Kernel/API/Syscall.h index 1567de7fc9..4d98eb19e9 100644 --- a/Kernel/API/Syscall.h +++ b/Kernel/API/Syscall.h @@ -197,7 +197,8 @@ namespace Kernel { S(allocate_tls) \ S(prctl) \ S(mremap) \ - S(set_coredump_metadata) + S(set_coredump_metadata) \ + S(abort) namespace Syscall { diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index 451060bf2b..0208a58e50 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -104,6 +104,7 @@ set(KERNEL_SOURCES SharedBuffer.cpp StdLib.cpp Syscall.cpp + Syscalls/abort.cpp Syscalls/access.cpp Syscalls/alarm.cpp Syscalls/beep.cpp diff --git a/Kernel/Process.h b/Kernel/Process.h index d6d6cbd000..3d511f9079 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -365,6 +365,7 @@ public: void* sys$allocate_tls(size_t); int sys$prctl(int option, FlatPtr arg1, FlatPtr arg2); int sys$set_coredump_metadata(Userspace); + void sys$abort(); template int get_sock_or_peer_name(const Params&); diff --git a/Kernel/Syscalls/abort.cpp b/Kernel/Syscalls/abort.cpp new file mode 100644 index 0000000000..d9bd27ebae --- /dev/null +++ b/Kernel/Syscalls/abort.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2021, Andreas Kling + * 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 +#include +#include + +namespace Kernel { + +void Process::sys$abort() +{ + cli(); + crash(SIGABRT, 0); +} + +} diff --git a/Libraries/LibC/assert.cpp b/Libraries/LibC/assert.cpp index 45b358639e..7dcd7a5258 100644 --- a/Libraries/LibC/assert.cpp +++ b/Libraries/LibC/assert.cpp @@ -47,8 +47,8 @@ void __assertion_failed(const char* msg) { msg, strlen(msg) }, }; syscall(SC_set_coredump_metadata, ¶ms); - - abort(); + syscall(SC_abort); + for (;;) { } } #endif }