assert.cpp 811 B

123456789101112131415161718192021222324252627282930313233343536
  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 <Kernel/API/prctl_numbers.h>
  8. #include <assert.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <sys/internals.h>
  13. #include <syscall.h>
  14. #include <unistd.h>
  15. extern "C" {
  16. extern bool __stdio_is_initialized;
  17. void __assertion_failed(char const* msg)
  18. {
  19. if (__heap_is_stable) {
  20. dbgln("ASSERTION FAILED: {}", msg);
  21. if (__stdio_is_initialized)
  22. warnln("ASSERTION FAILED: {}", msg);
  23. }
  24. Syscall::SC_set_coredump_metadata_params params {
  25. { "assertion", strlen("assertion") },
  26. { msg, strlen(msg) },
  27. };
  28. syscall(SC_prctl, PR_SET_COREDUMP_METADATA_VALUE, &params, nullptr);
  29. abort();
  30. }
  31. }