Assertions.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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(const char* msg, const char* file, unsigned line, const char* 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() VERIFY(false)
  17. extern "C" {
  18. [[noreturn]] void _abort();
  19. [[noreturn]] void abort();
  20. }
  21. static constexpr bool TODO = false;
  22. #define TODO() VERIFY(TODO)
  23. #if ARCH(I386) || ARCH(X86_64)
  24. # define VERIFY_INTERRUPTS_DISABLED() VERIFY(!(cpu_flags() & 0x200))
  25. # define VERIFY_INTERRUPTS_ENABLED() VERIFY(cpu_flags() & 0x200)
  26. #else
  27. # define VERIFY_INTERRUPTS_DISABLED() TODO()
  28. # define VERIFY_INTERRUPTS_ENABLED() TODO()
  29. #endif