glibc_hooks.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright Rubber Duck Software P.C.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. /**
  18. * @file src/glibc_hooks.c
  19. * @author Ioannis Koutras (joko@microlab.ntua.gr)
  20. * @date October 2013
  21. *
  22. * @brief Override GLIBC hooks with dmmlib's functions
  23. */
  24. #include <features.h>
  25. #if (defined(__GLIBC__) && !defined(__UCLIBC__))
  26. #include <stddef.h>
  27. #include <dmmlib/dmmlib.h>
  28. /*
  29. * glibc provides the RTLD_DEEPBIND flag for dlopen which can make it possible
  30. * to inconsistently reference libc's malloc(3)-compatible functions
  31. * (https://bugzilla.mozilla.org/show_bug.cgi?id=493541).
  32. *
  33. * These definitions interpose hooks in glibc. The functions are actually
  34. * passed an extra argument for the caller return address, which will be
  35. * ignored.
  36. */
  37. void (* __free_hook)(void *ptr) = free;
  38. void *(* __malloc_hook)(size_t size) = malloc;
  39. void *(* __realloc_hook)(void *ptr, size_t size) = realloc;
  40. #ifdef WITH_MEMALIGN
  41. void *(* __memalign_hook)(size_t alignment, size_t size) = memalign;
  42. #endif /* WITH_MEMALIGN */
  43. #endif /* __GLIBC__ && !__UCLIBC__ */