xref: /oneTBB/src/tbbmalloc_proxy/proxy.h (revision 8827ea7d)
1 /*
2     Copyright (c) 2005-2021 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 __unix__ || __APPLE__ || MALLOC_UNIXLIKE_OVERLOAD_ENABLED
26 #define MALLOC_CHECK_RECURSION 1
27 #endif
28 
29 #include "oneapi/tbb/detail/_config.h"
30 #include <stddef.h>
31 
32 extern "C" {
33     TBBMALLOC_EXPORT void   __TBB_malloc_safer_free( void *ptr, void (*original_free)(void*));
34     TBBMALLOC_EXPORT void * __TBB_malloc_safer_realloc( void *ptr, size_t, void* );
35     TBBMALLOC_EXPORT void * __TBB_malloc_safer_aligned_realloc( void *ptr, size_t, size_t, void* );
36     TBBMALLOC_EXPORT size_t __TBB_malloc_safer_msize( void *ptr, size_t (*orig_msize_crt80d)(void*));
37     TBBMALLOC_EXPORT size_t __TBB_malloc_safer_aligned_msize( void *ptr, size_t, size_t, size_t (*orig_msize_crt80d)(void*,size_t,size_t));
38 
39 #if MALLOC_ZONE_OVERLOAD_ENABLED
40     void   __TBB_malloc_free_definite_size(void *object, size_t size);
41 #endif
42 } // extern "C"
43 
44 // Struct with original free() and _msize() pointers
45 struct orig_ptrs {
46     void   (*free) (void*);
47     size_t (*msize)(void*);
48 };
49 
50 struct orig_aligned_ptrs {
51     void   (*aligned_free) (void*);
52     size_t (*aligned_msize)(void*,size_t,size_t);
53 };
54 
55 #endif /* _TBB_malloc_proxy_H_ */
56