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);
31 AllocFlagsToHeapAllocFlags (IN UINT AllocFlags,
32 OUT PUINT pHeapallocFlags)
35 UINT newFlags = 0, flags = AllocFlags;
36 if (flags & LMEM_ZEROINIT) {
37 newFlags |= HEAP_ZERO_MEMORY;
38 flags &= ~LMEM_ZEROINIT;
41 ASSERT("Invalid parameter AllocFlags=0x%x\n", AllocFlags);
42 SetLastError(ERROR_INVALID_PARAMETER);
46 *pHeapallocFlags = newFlags;
65 LPVOID lpRetVal = NULL;
66 PERF_ENTRY(LocalAlloc);
67 ENTRY("LocalAlloc (uFlags=%#x, uBytes=%u)\n", uFlags, uBytes);
69 if (!AllocFlagsToHeapAllocFlags (uFlags, &uFlags)) {
73 lpRetVal = HeapAlloc( GetProcessHeap(), uFlags, uBytes );
76 LOGEXIT( "LocalAlloc returning %p.\n", lpRetVal );
77 PERF_EXIT(LocalAlloc);
78 return (HLOCAL) lpRetVal;
94 LPVOID lpRetVal = NULL;
95 PERF_ENTRY(LocalReAlloc);
96 ENTRY("LocalReAlloc (hMem=%p, uBytes=%u, uFlags=%#x)\n", hMem, uBytes, uFlags);
98 if (uFlags != LMEM_MOVEABLE) {
99 // Currently valid iff uFlags is LMEM_MOVEABLE
100 ASSERT("Invalid parameter uFlags=0x%x\n", uFlags);
101 SetLastError(ERROR_INVALID_PARAMETER);
106 lpRetVal = HeapReAlloc(GetProcessHeap(), uFlags, hMem, uBytes);
109 LOGEXIT("LocalReAlloc returning %p.\n", lpRetVal);
110 PERF_EXIT(LocalReAlloc);
111 return (HLOCAL)lpRetVal;
125 BOOL bRetVal = FALSE;
126 PERF_ENTRY(LocalFree);
127 ENTRY("LocalFree (hmem=%p)\n", hMem);
131 bRetVal = HeapFree( GetProcessHeap(), 0, hMem );
138 LOGEXIT( "LocalFree returning %p.\n", bRetVal == TRUE ? (HLOCAL)NULL : hMem );
139 PERF_EXIT(LocalFree);
140 return bRetVal == TRUE ? (HLOCAL)NULL : hMem;