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 PERF_ENTRY(LocalFree);
96 ENTRY("LocalFree (hmem=%p)\n", hMem);
100 bRetVal = HeapFree( GetProcessHeap(), 0, hMem );
107 LOGEXIT( "LocalFree returning %p.\n", bRetVal == TRUE ? (HLOCAL)NULL : hMem );
108 PERF_EXIT(LocalFree);
109 return bRetVal == TRUE ? (HLOCAL)NULL : hMem;