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