2019-03-15 21:01:26 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2019 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#include <RB_INC_SIGNAL_H
|
2019-05-29 00:53:25 +02:00
|
|
|
|
2022-07-16 22:09:14 +02:00
|
|
|
#if defined(RB_ASSERT_OPTIMISTIC)
|
|
|
|
decltype(ircd::assertion)
|
|
|
|
ircd::assertion
|
|
|
|
alignas(64);
|
|
|
|
#endif
|
|
|
|
|
2020-04-11 22:35:15 +02:00
|
|
|
#if defined(RB_ASSERT) && !defined(RB_ASSERT_INTRINSIC)
|
2019-07-21 00:11:01 +02:00
|
|
|
#ifdef __clang__
|
2019-06-23 08:28:48 +02:00
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wunreachable-code"
|
2019-07-21 00:11:01 +02:00
|
|
|
#endif __clang__
|
2022-05-26 21:00:07 +02:00
|
|
|
[[gnu::cold]]
|
2019-03-15 21:01:26 +01:00
|
|
|
void
|
|
|
|
__assert_fail(const char *__assertion,
|
|
|
|
const char *__file,
|
|
|
|
unsigned int __line,
|
|
|
|
const char *__function)
|
2022-07-16 22:09:14 +02:00
|
|
|
noexcept
|
2019-03-15 21:01:26 +01:00
|
|
|
{
|
2019-08-12 04:02:50 +02:00
|
|
|
ircd::print_assertion(__assertion, __file, __line, __function);
|
2019-03-15 21:01:26 +01:00
|
|
|
|
2019-06-01 11:02:37 +02:00
|
|
|
if(ircd::soft_assert)
|
|
|
|
return;
|
|
|
|
|
2019-03-15 22:42:22 +01:00
|
|
|
if(strcmp(RB_ASSERT, "quit") == 0)
|
2019-03-15 21:01:26 +01:00
|
|
|
ircd::quit();
|
|
|
|
|
2022-07-16 22:09:14 +02:00
|
|
|
else if(strcmp(RB_ASSERT, "opt") == 0)
|
|
|
|
ircd::debugtrap();
|
|
|
|
|
2019-03-15 22:42:22 +01:00
|
|
|
else if(strcmp(RB_ASSERT, "trap") == 0)
|
2019-05-29 00:53:25 +02:00
|
|
|
ircd::debugtrap();
|
2019-03-15 22:42:22 +01:00
|
|
|
|
2019-03-15 21:01:26 +01:00
|
|
|
#if defined(HAVE_EXCEPTION)
|
|
|
|
else if(strcmp(RB_ASSERT, "term") == 0)
|
|
|
|
{
|
|
|
|
std::terminate();
|
|
|
|
__builtin_unreachable();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_CSTDLIB)
|
|
|
|
else if(strcmp(RB_ASSERT, "abort") == 0)
|
|
|
|
{
|
|
|
|
abort();
|
|
|
|
__builtin_unreachable();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_SIGNAL_H)
|
|
|
|
else if(strcmp(RB_ASSERT, "SIGTRAP") == 0)
|
|
|
|
raise(SIGTRAP);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_SIGNAL_H)
|
2019-07-14 20:47:58 +02:00
|
|
|
else if(strcmp(RB_ASSERT, "SIGSTOP") == 0)
|
2019-03-15 21:01:26 +01:00
|
|
|
raise(SIGSTOP);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_SIGNAL_H)
|
|
|
|
else if(strcmp(RB_ASSERT, "SIGQUIT") == 0)
|
|
|
|
raise(SIGQUIT);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
else __builtin_trap();
|
|
|
|
}
|
2019-07-21 00:11:01 +02:00
|
|
|
#ifdef __clang__
|
2019-06-23 08:28:48 +02:00
|
|
|
#pragma clang diagnostic pop
|
2019-07-21 00:11:01 +02:00
|
|
|
#endif __clang__
|
2019-03-15 21:01:26 +01:00
|
|
|
#endif
|
2019-08-12 04:02:50 +02:00
|
|
|
|
2022-05-26 21:00:07 +02:00
|
|
|
[[gnu::cold]]
|
2019-08-12 04:02:50 +02:00
|
|
|
void
|
2021-09-04 08:32:00 +02:00
|
|
|
ircd::print_assertion(const char *const __assertion,
|
|
|
|
const char *const __file,
|
|
|
|
const unsigned __line,
|
|
|
|
const char *const __function)
|
2019-08-12 04:02:50 +02:00
|
|
|
noexcept
|
|
|
|
{
|
2022-07-16 22:09:14 +02:00
|
|
|
if(__assertion && strcmp(__assertion, "critical") == 0)
|
2019-08-12 04:02:50 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
fprintf(stderr, "\nassertion failed [%s +%u] %s :%s\n",
|
|
|
|
__file,
|
|
|
|
__line,
|
|
|
|
__function,
|
|
|
|
__assertion);
|
|
|
|
}
|