Assertions.h 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Platform.h>
  8. #define __STRINGIFY_HELPER(x) #x
  9. #define __STRINGIFY(x) __STRINGIFY_HELPER(x)
  10. [[noreturn]] void __assertion_failed(char const* msg, char const* file, unsigned line, char const* func);
  11. #define VERIFY(expr) \
  12. do { \
  13. if (!static_cast<bool>(expr)) [[unlikely]] \
  14. __assertion_failed(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
  15. } while (0)
  16. #define VERIFY_NOT_REACHED() __assertion_failed("not reached", __FILE__, __LINE__, __PRETTY_FUNCTION__)
  17. extern "C" {
  18. [[noreturn]] void _abort();
  19. [[noreturn]] void abort();
  20. }
  21. #define TODO() __assertion_failed("TODO", __FILE__, __LINE__, __PRETTY_FUNCTION__)
  22. #define TODO_AARCH64() __assertion_failed("TODO_AARCH64", __FILE__, __LINE__, __PRETTY_FUNCTION__)
  23. #define TODO_RISCV64() __assertion_failed("TODO_RISCV64", __FILE__, __LINE__, __PRETTY_FUNCTION__)
  24. #define VERIFY_INTERRUPTS_DISABLED() VERIFY(!(Processor::are_interrupts_enabled()))
  25. #define VERIFY_INTERRUPTS_ENABLED() VERIFY(Processor::are_interrupts_enabled())