CommonBasic.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. #include "Banned.h"
  7. #include "CommonDefines.h"
  8. #define _CRT_RAND_S // Enable rand_s in the CRT
  9. #ifndef __has_feature
  10. #define __has_feature(f) 0
  11. #endif
  12. #if __has_feature(address_sanitizer)
  13. #define ADDRESS_SANITIZER_APPEND(x) , x
  14. #define NO_SANITIZE_ADDRESS __attribute__((no_sanitize("address")))
  15. #define NO_SANITIZE_ADDRESS_FIXVC
  16. #else
  17. #define ADDRESS_SANITIZER_APPEND(x)
  18. #define NO_SANITIZE_ADDRESS
  19. #endif
  20. // AddressSanitizer: check if an address is in asan fake stack
  21. #if __has_feature(address_sanitizer)
  22. extern "C"
  23. {
  24. void *__asan_get_current_fake_stack();
  25. void *__asan_addr_is_in_fake_stack(void *fake_stack, void *addr, void **beg, void **end);
  26. }
  27. inline bool IsAsanFakeStackAddr(const void * p)
  28. {
  29. void * fakeStack = __asan_get_current_fake_stack();
  30. return fakeStack && __asan_addr_is_in_fake_stack(fakeStack, const_cast<void*>(p), nullptr, nullptr);
  31. }
  32. #define IS_ASAN_FAKE_STACK_ADDR(p) IsAsanFakeStackAddr(p)
  33. #else
  34. #define IS_ASAN_FAKE_STACK_ADDR(p) false
  35. #endif
  36. #if defined(PROFILE_RECYCLER_ALLOC) || defined(HEAP_TRACK_ALLOC) || defined(ENABLE_DEBUG_CONFIG_OPTIONS)
  37. #ifdef __clang__
  38. #include <typeinfo>
  39. using std::type_info;
  40. #endif
  41. #endif
  42. #include "CommonPal.h"
  43. #include "Core/CommonMinMax.h"
  44. // === Core Header Files ===
  45. #include "Core/CommonTypedefs.h"
  46. #include "Core/Api.h"
  47. #include "Core/CriticalSection.h"
  48. #include "Core/Assertions.h"
  49. // === Exceptions Header Files ===
  50. #include "Exceptions/Throw.h"
  51. #include "Exceptions/ExceptionCheck.h"
  52. #include "Exceptions/ReportError.h"