sanitizer_win_weak_interception.h 1.6 KB

1234567891011121314151617181920212223242526272829303132
  1. //===-- sanitizer_win_weak_interception.h ---------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // This header provide helper macros to delegate calls of weak functions to the
  9. // implementation in the main executable when a strong definition is present.
  10. //===----------------------------------------------------------------------===//
  11. #ifndef SANITIZER_WIN_WEAK_INTERCEPTION_H
  12. #define SANITIZER_WIN_WEAK_INTERCEPTION_H
  13. #include "sanitizer_internal_defs.h"
  14. namespace __sanitizer {
  15. int interceptWhenPossible(uptr dll_function, const char *real_function);
  16. }
  17. // ----------------- Function interception helper macros -------------------- //
  18. // Weak functions, could be redefined in the main executable, but that is not
  19. // necessary, so we shouldn't die if we can not find a reference.
  20. #define INTERCEPT_WEAK(Name) interceptWhenPossible((uptr) Name, #Name);
  21. #define INTERCEPT_SANITIZER_WEAK_FUNCTION(Name) \
  22. static int intercept_##Name() { \
  23. return __sanitizer::interceptWhenPossible((__sanitizer::uptr) Name, #Name);\
  24. } \
  25. __pragma(section(".WEAK$M", long, read)) \
  26. __declspec(allocate(".WEAK$M")) int (*__weak_intercept_##Name)() = \
  27. intercept_##Name;
  28. #endif // SANITIZER_WIN_WEAK_INTERCEPTION_H