assert.cpp 796 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Format.h>
  7. #include <assert.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <sys/internals.h>
  12. #include <syscall.h>
  13. #include <unistd.h>
  14. extern "C" {
  15. extern bool __stdio_is_initialized;
  16. #ifndef NDEBUG
  17. void __assertion_failed(const char* msg)
  18. {
  19. dbgln("ASSERTION FAILED: {}", msg);
  20. if (__stdio_is_initialized)
  21. warnln("ASSERTION FAILED: {}", msg);
  22. Syscall::SC_set_coredump_metadata_params params {
  23. { "assertion", strlen("assertion") },
  24. { msg, strlen(msg) },
  25. };
  26. syscall(SC_set_coredump_metadata, &params);
  27. abort();
  28. }
  29. #endif
  30. }
  31. void _abort()
  32. {
  33. asm volatile("ud2");
  34. __builtin_unreachable();
  35. }