1/*
2 Copyright (c) 2005-2019 Intel Corporation
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#ifndef _TBB_malloc_proxy_H_
18#define _TBB_malloc_proxy_H_
19
20#define MALLOC_UNIXLIKE_OVERLOAD_ENABLED __linux__
21#define MALLOC_ZONE_OVERLOAD_ENABLED __APPLE__
22
23// MALLOC_UNIXLIKE_OVERLOAD_ENABLED depends on MALLOC_CHECK_RECURSION stuff
24// TODO: limit MALLOC_CHECK_RECURSION to *_OVERLOAD_ENABLED only
25#if __linux__ || __APPLE__ || __sun || __FreeBSD__ || MALLOC_UNIXLIKE_OVERLOAD_ENABLED
26#define MALLOC_CHECK_RECURSION 1
27#endif
28
29#include <stddef.h>
30
31extern "C" {
32 void * scalable_malloc(size_t size);
33 void * scalable_calloc(size_t nobj, size_t size);
34 void scalable_free(void *ptr);
35 void * scalable_realloc(void* ptr, size_t size);
36 void * scalable_aligned_malloc(size_t size, size_t alignment);
37 void * scalable_aligned_realloc(void* ptr, size_t size, size_t alignment);
38 int scalable_posix_memalign(void **memptr, size_t alignment, size_t size);
39 size_t scalable_msize(void *ptr);
40 void __TBB_malloc_safer_free( void *ptr, void (*original_free)(void*));
41 void * __TBB_malloc_safer_realloc( void *ptr, size_t, void* );
42 void * __TBB_malloc_safer_aligned_realloc( void *ptr, size_t, size_t, void* );
43 size_t __TBB_malloc_safer_msize( void *ptr, size_t (*orig_msize_crt80d)(void*));
44 size_t __TBB_malloc_safer_aligned_msize( void *ptr, size_t, size_t, size_t (*orig_msize_crt80d)(void*,size_t,size_t));
45
46#if MALLOC_ZONE_OVERLOAD_ENABLED
47 void __TBB_malloc_free_definite_size(void *object, size_t size);
48#endif
49} // extern "C"
50
51// Struct with original free() and _msize() pointers
52struct orig_ptrs {
53 void (*free) (void*);
54 size_t (*msize)(void*);
55};
56
57struct orig_aligned_ptrs {
58 void (*aligned_free) (void*);
59 size_t (*aligned_msize)(void*,size_t,size_t);
60};
61
62#endif /* _TBB_malloc_proxy_H_ */
63