xref: /oneTBB/src/tbbmalloc_proxy/proxy.h (revision 8827ea7d)
151c0b2f7Stbbdev /*
2b15aabb3Stbbdev     Copyright (c) 2005-2021 Intel Corporation
351c0b2f7Stbbdev 
451c0b2f7Stbbdev     Licensed under the Apache License, Version 2.0 (the "License");
551c0b2f7Stbbdev     you may not use this file except in compliance with the License.
651c0b2f7Stbbdev     You may obtain a copy of the License at
751c0b2f7Stbbdev 
851c0b2f7Stbbdev         http://www.apache.org/licenses/LICENSE-2.0
951c0b2f7Stbbdev 
1051c0b2f7Stbbdev     Unless required by applicable law or agreed to in writing, software
1151c0b2f7Stbbdev     distributed under the License is distributed on an "AS IS" BASIS,
1251c0b2f7Stbbdev     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1351c0b2f7Stbbdev     See the License for the specific language governing permissions and
1451c0b2f7Stbbdev     limitations under the License.
1551c0b2f7Stbbdev */
1651c0b2f7Stbbdev 
1751c0b2f7Stbbdev #ifndef _TBB_malloc_proxy_H_
1851c0b2f7Stbbdev #define _TBB_malloc_proxy_H_
1951c0b2f7Stbbdev 
2051c0b2f7Stbbdev #define MALLOC_UNIXLIKE_OVERLOAD_ENABLED __linux__
2151c0b2f7Stbbdev #define MALLOC_ZONE_OVERLOAD_ENABLED __APPLE__
2251c0b2f7Stbbdev 
2351c0b2f7Stbbdev // MALLOC_UNIXLIKE_OVERLOAD_ENABLED depends on MALLOC_CHECK_RECURSION stuff
2451c0b2f7Stbbdev // TODO: limit MALLOC_CHECK_RECURSION to *_OVERLOAD_ENABLED only
25734f0bc0SPablo Romero #if __unix__ || __APPLE__ || MALLOC_UNIXLIKE_OVERLOAD_ENABLED
2651c0b2f7Stbbdev #define MALLOC_CHECK_RECURSION 1
2751c0b2f7Stbbdev #endif
2851c0b2f7Stbbdev 
29*8827ea7dSLong Nguyen #include "oneapi/tbb/detail/_config.h"
3051c0b2f7Stbbdev #include <stddef.h>
3151c0b2f7Stbbdev 
3251c0b2f7Stbbdev extern "C" {
33*8827ea7dSLong Nguyen     TBBMALLOC_EXPORT void   __TBB_malloc_safer_free( void *ptr, void (*original_free)(void*));
34*8827ea7dSLong Nguyen     TBBMALLOC_EXPORT void * __TBB_malloc_safer_realloc( void *ptr, size_t, void* );
35*8827ea7dSLong Nguyen     TBBMALLOC_EXPORT void * __TBB_malloc_safer_aligned_realloc( void *ptr, size_t, size_t, void* );
36*8827ea7dSLong Nguyen     TBBMALLOC_EXPORT size_t __TBB_malloc_safer_msize( void *ptr, size_t (*orig_msize_crt80d)(void*));
37*8827ea7dSLong Nguyen     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));
3851c0b2f7Stbbdev 
3951c0b2f7Stbbdev #if MALLOC_ZONE_OVERLOAD_ENABLED
4051c0b2f7Stbbdev     void   __TBB_malloc_free_definite_size(void *object, size_t size);
4151c0b2f7Stbbdev #endif
4251c0b2f7Stbbdev } // extern "C"
4351c0b2f7Stbbdev 
4451c0b2f7Stbbdev // Struct with original free() and _msize() pointers
4551c0b2f7Stbbdev struct orig_ptrs {
4651c0b2f7Stbbdev     void   (*free) (void*);
4751c0b2f7Stbbdev     size_t (*msize)(void*);
4851c0b2f7Stbbdev };
4951c0b2f7Stbbdev 
5051c0b2f7Stbbdev struct orig_aligned_ptrs {
5151c0b2f7Stbbdev     void   (*aligned_free) (void*);
5251c0b2f7Stbbdev     size_t (*aligned_msize)(void*,size_t,size_t);
5351c0b2f7Stbbdev };
5451c0b2f7Stbbdev 
5551c0b2f7Stbbdev #endif /* _TBB_malloc_proxy_H_ */
56