2 // Copyright (c) Microsoft. All rights reserved.
3 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
16 Implementation of local memory management functions.
24 #include "pal/palinternal.h"
25 #include "pal/dbgmsg.h"
28 SET_DEFAULT_DEBUG_CHANNEL(MEM);
32 AllocFlagsToHeapAllocFlags (IN UINT AllocFlags,
33 OUT PUINT pHeapallocFlags)
36 UINT newFlags = 0, flags = AllocFlags;
37 if (flags & LMEM_ZEROINIT) {
38 newFlags |= HEAP_ZERO_MEMORY;
39 flags &= ~LMEM_ZEROINIT;
42 ASSERT("Invalid parameter AllocFlags=0x%x\n", AllocFlags);
43 SetLastError(ERROR_INVALID_PARAMETER);
47 *pHeapallocFlags = newFlags;
66 LPVOID lpRetVal = NULL;
67 PERF_ENTRY(LocalAlloc);
68 ENTRY("LocalAlloc (uFlags=%#x, uBytes=%u)\n", uFlags, uBytes);
70 if (!AllocFlagsToHeapAllocFlags (uFlags, &uFlags)) {
74 lpRetVal = HeapAlloc( GetProcessHeap(), uFlags, uBytes );
77 LOGEXIT( "LocalAlloc returning %p.\n", lpRetVal );
78 PERF_EXIT(LocalAlloc);
79 return (HLOCAL) lpRetVal;
95 LPVOID lpRetVal = NULL;
96 PERF_ENTRY(LocalReAlloc);
97 ENTRY("LocalReAlloc (hMem=%p, uBytes=%u, uFlags=%#x)\n", hMem, uBytes, uFlags);
99 if (uFlags != LMEM_MOVEABLE) {
100 // Currently valid iff uFlags is LMEM_MOVEABLE
101 ASSERT("Invalid parameter uFlags=0x%x\n", uFlags);
102 SetLastError(ERROR_INVALID_PARAMETER);
107 lpRetVal = HeapReAlloc(GetProcessHeap(), uFlags, hMem, uBytes);
110 LOGEXIT("LocalReAlloc returning %p.\n", lpRetVal);
111 PERF_EXIT(LocalReAlloc);
112 return (HLOCAL)lpRetVal;
126 BOOL bRetVal = FALSE;
127 PERF_ENTRY(LocalFree);
128 ENTRY("LocalFree (hmem=%p)\n", hMem);
132 bRetVal = HeapFree( GetProcessHeap(), 0, hMem );
139 LOGEXIT( "LocalFree returning %p.\n", bRetVal == TRUE ? (HLOCAL)NULL : hMem );
140 PERF_EXIT(LocalFree);
141 return bRetVal == TRUE ? (HLOCAL)NULL : hMem;