1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
15 Implementation of local memory management functions.
23 #include "pal/palinternal.h"
24 #include "pal/dbgmsg.h"
27 SET_DEFAULT_DEBUG_CHANNEL(MEM);
29 #ifdef TIZEN_ASAN_ENVIRONMENT
31 extern void __sanitizer_disable_interceptors() __attribute__ ((weak));
32 extern void __sanitizer_enable_interceptors() __attribute__ ((weak));
33 extern bool __sanitizer_interceptors_are_enabled() __attribute__ ((weak));
39 AllocFlagsToHeapAllocFlags (IN UINT AllocFlags,
40 OUT PUINT pHeapallocFlags)
43 UINT newFlags = 0, flags = AllocFlags;
44 if (flags & LMEM_ZEROINIT) {
45 newFlags |= HEAP_ZERO_MEMORY;
46 flags &= ~LMEM_ZEROINIT;
49 ASSERT("Invalid parameter AllocFlags=0x%x\n", AllocFlags);
50 SetLastError(ERROR_INVALID_PARAMETER);
54 *pHeapallocFlags = newFlags;
73 LPVOID lpRetVal = NULL;
74 PERF_ENTRY(LocalAlloc);
75 ENTRY("LocalAlloc (uFlags=%#x, uBytes=%u)\n", uFlags, uBytes);
77 if (!AllocFlagsToHeapAllocFlags (uFlags, &uFlags)) {
81 #ifdef TIZEN_ASAN_ENVIRONMENT
82 if (__sanitizer_interceptors_are_enabled != NULL)
85 san_enabled = __sanitizer_interceptors_are_enabled();
87 __sanitizer_enable_interceptors();
89 lpRetVal = HeapAlloc( GetProcessHeap(), uFlags, uBytes );
91 __sanitizer_disable_interceptors();
97 lpRetVal = HeapAlloc( GetProcessHeap(), uFlags, uBytes );
101 LOGEXIT( "LocalAlloc returning %p.\n", lpRetVal );
102 PERF_EXIT(LocalAlloc);
103 return (HLOCAL) lpRetVal;
119 LPVOID lpRetVal = NULL;
120 PERF_ENTRY(LocalReAlloc);
121 ENTRY("LocalReAlloc (hMem=%p, uBytes=%u, uFlags=%#x)\n", hMem, uBytes, uFlags);
123 if (uFlags != LMEM_MOVEABLE) {
124 // Currently valid iff uFlags is LMEM_MOVEABLE
125 ASSERT("Invalid parameter uFlags=0x%x\n", uFlags);
126 SetLastError(ERROR_INVALID_PARAMETER);
131 lpRetVal = HeapReAlloc(GetProcessHeap(), uFlags, hMem, uBytes);
134 LOGEXIT("LocalReAlloc returning %p.\n", lpRetVal);
135 PERF_EXIT(LocalReAlloc);
136 return (HLOCAL)lpRetVal;
150 BOOL bRetVal = FALSE;
151 PERF_ENTRY(LocalFree);
152 ENTRY("LocalFree (hmem=%p)\n", hMem);
156 #ifdef TIZEN_ASAN_ENVIRONMENT
157 if (__sanitizer_interceptors_are_enabled != NULL)
160 san_enabled = __sanitizer_interceptors_are_enabled();
162 __sanitizer_enable_interceptors();
164 bRetVal = HeapFree( GetProcessHeap(), 0, hMem );
166 __sanitizer_disable_interceptors();
172 bRetVal = HeapFree( GetProcessHeap(), 0, hMem );
181 LOGEXIT( "LocalFree returning %p.\n", bRetVal == TRUE ? (HLOCAL)NULL : hMem );
182 PERF_EXIT(LocalFree);
183 return bRetVal == TRUE ? (HLOCAL)NULL : hMem;