Assertions.h 973 B

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