Browse Source

add support for glibc hooks, currently the memalign one only

Ioannis Koutras 11 years ago
parent
commit
05c7f86678
6 changed files with 56 additions and 0 deletions
  1. 1 0
      CMakeLists.txt
  2. 4 0
      DefineOptions.cmake
  3. 1 0
      leon3.preset
  4. 5 0
      src/CMakeLists.txt
  5. 44 0
      src/glibc_hooks.c
  6. 1 0
      sthorm.preset

+ 1 - 0
CMakeLists.txt

@@ -198,5 +198,6 @@ message(STATUS "Support for statistics traces: " ${WITH_STATS_TRACE})
 message(STATUS "Support for realloc(): " ${WITH_REALLOC})
 message(STATUS "Support for calloc(): " ${WITH_CALLOC})
 message(STATUS "Support for memalign(): " ${WITH_MEMALIGN})
+message(STATUS "Support for GLIBC hooks: " ${WITH_GLIBC_HOOKS})
 message(STATUS "Support to parse dmmlib environment variables: " ${PARSE_ENV})
 message(STATUS "********************************************")

+ 4 - 0
DefineOptions.cmake

@@ -24,6 +24,10 @@ option(WITH_REALLOC "Build with realloc() support" ON)
 option(WITH_CALLOC "Build with calloc() support" ON)
 option(WITH_MEMALIGN "Build with memalign() support" ON)
 
+# GLIBC Hooks Settings
+
+option(WITH_GLIBC_HOOKS "Place dmmlib functions on GLIBC hooks" ON)
+
 # Knobs Settings
 
 option(WITH_KNOBS "Build with knobs support" OFF)

+ 1 - 0
leon3.preset

@@ -10,6 +10,7 @@ option(FREELIST_COALESCE_AFTER_SPLIT "Try to coalesce blocks after split" OFF)
 option(WITH_REALLOC "Build with realloc() support" OFF)
 option(WITH_CALLOC "Build with calloc() support" OFF)
 option(WITH_MEMALIGN "Build with memalign() support" OFF)
+option(WITH_GLIBC_HOOKS "Place dmmlib functions on GLIBC hooks" OFF)
 option(WITH_KNOBS "Build with knobs support" OFF)
 set(STATS "none" CACHE STRING "Choose if the memory allocator keeps internally statistics per raw block or globally, options are: none, global")
 option(REQUEST_SIZE_INFO "Keep request size information in metadata" OFF)

+ 5 - 0
src/CMakeLists.txt

@@ -227,6 +227,11 @@ if(PARSE_ENV)
   set(dmmlib_SRCS ${dmmlib_SRCS} parse_env.c)
 endif(PARSE_ENV)
 
+if(WITH_GLIBC_HOOKS AND WITH_MEMALIGN)
+# Currently there is a hook on memalign only
+  set(dmmlib_SRCS ${dmmlib_SRCS} glibc_hooks.c)
+endif(WITH_GLIBC_HOOKS AND WITH_MEMALIGN)
+
 include_directories(
   ${DMMLIB_PUBLIC_INCLUDE_DIRS}
   ${DMMLIB_PRIVATE_INCLUDE_DIRS}

+ 44 - 0
src/glibc_hooks.c

@@ -0,0 +1,44 @@
+/*
+ *   Copyright Rubber Duck Software P.C.
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+/**
+ * @file   src/glibc_hooks.c
+ * @author Ioannis Koutras (joko@rdsoftware.eu)
+ * @date   October 2013
+ *
+ * @brief  Override GLIBC hooks with dmmlib's functions
+ */
+
+#include <features.h>
+
+#if (defined(__GLIBC__) && !defined(__UCLIBC__))
+
+#include <stddef.h>
+#include <dmmlib/memalign.h>
+
+/*
+ * glibc provides the RTLD_DEEPBIND flag for dlopen which can make it possible
+ * to inconsistently reference libc's malloc(3)-compatible functions
+ * (https://bugzilla.mozilla.org/show_bug.cgi?id=493541).
+ *
+ * These definitions interpose hooks in glibc. The functions are actually
+ * passed an extra argument for the caller return address, which will be
+ * ignored.
+ */
+void *(* __memalign_hook)(size_t alignment, size_t size) = memalign;
+
+#endif /* __GLIBC__ && !__UCLIBC__ */

+ 1 - 0
sthorm.preset

@@ -14,6 +14,7 @@ option(FREELIST_COALESCE_AFTER_SPLIT "Try to coalesce blocks after split" OFF)
 option(WITH_REALLOC "Build with realloc() support" OFF)
 option(WITH_CALLOC "Build with calloc() support" OFF)
 option(WITH_MEMALIGN "Build with memalign() support" OFF)
+option(WITH_GLIBC_HOOKS "Place dmmlib functions on GLIBC hooks" OFF)
 option(WITH_KNOBS "Build with knobs support" OFF)
 set(STATS "none" CACHE STRING "Choose if the memory allocator keeps internally statistics per raw block or globally, options are: none, global")
 option(REQUEST_SIZE_INFO "Keep request size information in metadata" OFF)