MallocImpl.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2013-present Facebook, Inc.
  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. #pragma once
  17. #include <stdlib.h>
  18. #include <folly/Portability.h>
  19. extern "C" {
  20. #if FOLLY_HAVE_WEAK_SYMBOLS
  21. void* mallocx(size_t, int) __attribute__((__weak__));
  22. void* rallocx(void*, size_t, int) __attribute__((__weak__));
  23. size_t xallocx(void*, size_t, size_t, int) __attribute__((__weak__));
  24. size_t sallocx(const void*, int) __attribute__((__weak__));
  25. void dallocx(void*, int) __attribute__((__weak__));
  26. void sdallocx(void*, size_t, int) __attribute__((__weak__));
  27. size_t nallocx(size_t, int) __attribute__((__weak__));
  28. int mallctl(const char*, void*, size_t*, void*, size_t)
  29. __attribute__((__weak__));
  30. int mallctlnametomib(const char*, size_t*, size_t*) __attribute__((__weak__));
  31. int mallctlbymib(const size_t*, size_t, void*, size_t*, void*, size_t)
  32. __attribute__((__weak__));
  33. #else
  34. extern void* (*mallocx)(size_t, int);
  35. extern void* (*rallocx)(void*, size_t, int);
  36. extern size_t (*xallocx)(void*, size_t, size_t, int);
  37. extern size_t (*sallocx)(const void*, int);
  38. extern void (*dallocx)(void*, int);
  39. extern void (*sdallocx)(void*, size_t, int);
  40. extern size_t (*nallocx)(size_t, int);
  41. extern int (*mallctl)(const char*, void*, size_t*, void*, size_t);
  42. extern int (*mallctlnametomib)(const char*, size_t*, size_t*);
  43. extern int (
  44. *mallctlbymib)(const size_t*, size_t, void*, size_t*, void*, size_t);
  45. #ifdef _MSC_VER
  46. // We emulate weak linkage for MSVC. The symbols we're
  47. // aliasing to are hiding in MallocImpl.cpp
  48. #pragma comment(linker, "/alternatename:mallocx=mallocxWeak")
  49. #pragma comment(linker, "/alternatename:rallocx=rallocxWeak")
  50. #pragma comment(linker, "/alternatename:xallocx=xallocxWeak")
  51. #pragma comment(linker, "/alternatename:sallocx=sallocxWeak")
  52. #pragma comment(linker, "/alternatename:dallocx=dallocxWeak")
  53. #pragma comment(linker, "/alternatename:sdallocx=sdallocxWeak")
  54. #pragma comment(linker, "/alternatename:nallocx=nallocxWeak")
  55. #pragma comment(linker, "/alternatename:mallctl=mallctlWeak")
  56. #pragma comment(linker, "/alternatename:mallctlnametomib=mallctlnametomibWeak")
  57. #pragma comment(linker, "/alternatename:mallctlbymib=mallctlbymibWeak")
  58. #endif
  59. #endif
  60. }