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.
This commit is contained in:
Andreas Kling 2021-01-04 21:26:32 +01:00
parent 8d04bb4d7b
commit d991658794
Notes: sideshowbarker 2024-07-19 00:06:58 +09:00
5 changed files with 45 additions and 3 deletions

View file

@ -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 {

View file

@ -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

View file

@ -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<const Syscall::SC_set_coredump_metadata_params*>);
void sys$abort();
template<bool sockname, typename Params>
int get_sock_or_peer_name(const Params&);

39
Kernel/Syscalls/abort.cpp Normal file
View file

@ -0,0 +1,39 @@
/*
* 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()
{
cli();
crash(SIGABRT, 0);
}
}

View file

@ -47,8 +47,8 @@ void __assertion_failed(const char* msg)
{ msg, strlen(msg) },
};
syscall(SC_set_coredump_metadata, &params);
abort();
syscall(SC_abort);
for (;;) { }
}
#endif
}