[PATCH] Interception macros for sanitizers on FreeBSD

Viktor Kutuzov vkutuzov at accesssoftek.com
Wed Feb 19 07:45:04 PST 2014


Hi kcc, samsonov,

This patch introduce FreeBSD-specific versions of the interception macros.

http://llvm-reviews.chandlerc.com/D2828

Files:
  lib/interception/interception.h
  lib/interception/interception_freebsd.h
  lib/sanitizer_common/sanitizer_platform.h

Index: lib/interception/interception.h
===================================================================
--- lib/interception/interception.h
+++ lib/interception/interception.h
@@ -15,7 +15,8 @@
 #ifndef INTERCEPTION_H
 #define INTERCEPTION_H
 
-#if !defined(__linux__) && !defined(__APPLE__) && !defined(_WIN32)
+#if !defined(__linux__) && !defined(__APPLE__) && \
+  !defined(_WIN32) && !defined(__FreeBSD__)
 # error "Interception doesn't work on this operating system."
 #endif
 
@@ -138,9 +139,15 @@
 # define WRAP(x) __interceptor_ ## x
 # define WRAPPER_NAME(x) "__interceptor_" #x
 # define INTERCEPTOR_ATTRIBUTE __attribute__((visibility("default")))
-# define DECLARE_WRAPPER(ret_type, func, ...) \
+# if defined(__FreeBSD__)
+#  define DECLARE_WRAPPER(ret_type, func, ...) \
+    extern "C" ret_type func(__VA_ARGS__) \
+    __attribute__((alias("__interceptor_" #func), visibility("default")));
+# else
+#  define DECLARE_WRAPPER(ret_type, func, ...) \
     extern "C" ret_type func(__VA_ARGS__) \
     __attribute__((weak, alias("__interceptor_" #func), visibility("default")));
+# endif
 #endif
 
 #if !defined(__APPLE__)
@@ -240,6 +247,9 @@
 # define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_LINUX(func)
 # define INTERCEPT_FUNCTION_VER(func, symver) \
     INTERCEPT_FUNCTION_VER_LINUX(func, symver)
+#elif defined(__FreeBSD__)
+# include "interception_freebsd.h"
+# define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_FREEBSD(func)
 #elif defined(__APPLE__)
 # include "interception_mac.h"
 # define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_MAC(func)
Index: lib/interception/interception_freebsd.h
===================================================================
--- lib/interception/interception_freebsd.h
+++ lib/interception/interception_freebsd.h
@@ -0,0 +1,41 @@
+//===-- interception_freebsd.h ----------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a part of AddressSanitizer, an address sanity checker.
+//
+// FreeBSD-specific interception methods.
+//===----------------------------------------------------------------------===//
+
+#ifdef __FreeBSD__
+
+#if !defined(INCLUDED_FROM_INTERCEPTION_LIB)
+# error "interception_freebsd.h should be included from interception library only"  // NOLINT
+#endif
+
+#ifndef INTERCEPTION_FREEBSD_H
+#define INTERCEPTION_FREEBSD_H
+
+namespace __interception {
+namespace freebsd {
+
+// returns true if a function with the given name was found.
+bool GetRealFunctionAddress(const char *func_name, uptr *func_addr,
+    uptr real, uptr wrapper);
+
+}  // namespace freebsd
+}  // namespace __interception
+
+#define INTERCEPT_FUNCTION_FREEBSD(func)                \
+  ::__interception::freebsd::GetRealFunctionAddress(    \
+          #func, (::__interception::uptr*) &REAL(func), \
+          (::__interception::uptr) &(func),             \
+          (::__interception::uptr) &WRAP(func))
+
+#endif  // INTERCEPTION_FREEBSD_H
+#endif  // __FreeBSD__
Index: lib/sanitizer_common/sanitizer_platform.h
===================================================================
--- lib/sanitizer_common/sanitizer_platform.h
+++ lib/sanitizer_common/sanitizer_platform.h
@@ -13,7 +13,8 @@
 #ifndef SANITIZER_PLATFORM_H
 #define SANITIZER_PLATFORM_H
 
-#if !defined(__linux__) && !defined(__APPLE__) && !defined(_WIN32)
+#if !defined(__linux__) && !defined(__APPLE__) && \
+  !defined(_WIN32) && !defined(__FreeBSD__)
 # error "This operating system is not supported"
 #endif
 
@@ -23,6 +24,12 @@
 # define SANITIZER_LINUX   0
 #endif
 
+#if defined(__FreeBSD__)
+# define SANITIZER_FREEBSD 1
+#else
+# define SANITIZER_FREEBSD 0
+#endif
+
 #if defined(__APPLE__)
 # define SANITIZER_MAC     1
 # include <TargetConditionals.h>
@@ -48,7 +55,7 @@
 # define SANITIZER_ANDROID 0
 #endif
 
-#define SANITIZER_POSIX (SANITIZER_LINUX || SANITIZER_MAC)
+#define SANITIZER_POSIX (SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_MAC)
 
 #if __LP64__ || defined(_WIN64)
 #  define SANITIZER_WORDSIZE 64
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2828.1.patch
Type: text/x-patch
Size: 4242 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140219/65952fde/attachment.bin>


More information about the llvm-commits mailing list