Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1876 from stephentoub/local_realloc
Browse files Browse the repository at this point in the history
Implement LocalReAlloc in PAL
  • Loading branch information
janvorli committed Oct 28, 2015
2 parents 7a08037 + ac360d5 commit 3e97351
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/dlls/mscoree/mscorwks_unixexports.src
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ CloseHandle
CoCreateGuid
CopyFileW
CoTaskMemAlloc
CoTaskMemRealloc
CoTaskMemFree
CreateDirectoryW
CreateEventW
Expand Down Expand Up @@ -58,6 +59,7 @@ GetTempFileNameW
GetTempPathW
LeaveCriticalSection
LocalAlloc
LocalReAlloc
LocalFree
LockFile
lstrlenA
Expand Down
9 changes: 9 additions & 0 deletions src/pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -3944,6 +3944,7 @@ HeapSetInformation(
IN SIZE_T HeapInformationLength);

#define LMEM_FIXED 0x0000
#define LMEM_MOVEABLE 0x0002
#define LMEM_ZEROINIT 0x0040
#define LPTR (LMEM_FIXED | LMEM_ZEROINIT)

Expand All @@ -3954,6 +3955,14 @@ LocalAlloc(
IN UINT uFlags,
IN SIZE_T uBytes);

PALIMPORT
HLOCAL
PALAPI
LocalReAlloc(
IN HLOCAL hMem,
IN SIZE_T uBytes,
IN UINT uFlags);

PALIMPORT
HLOCAL
PALAPI
Expand Down
1 change: 1 addition & 0 deletions src/pal/inc/rt/palrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ typedef union _ULARGE_INTEGER {
/******************* OLE, BSTR, VARIANT *************************/

STDAPI_(LPVOID) CoTaskMemAlloc(SIZE_T cb);
STDAPI_(LPVOID) CoTaskMemRealloc(LPVOID pv, SIZE_T cb);
STDAPI_(void) CoTaskMemFree(LPVOID pv);

typedef SHORT VARIANT_BOOL;
Expand Down
32 changes: 32 additions & 0 deletions src/pal/src/memory/local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,38 @@ LocalAlloc(
return (HLOCAL) lpRetVal;
}

/*++
Function:
LocalReAlloc
See MSDN doc.
--*/
HLOCAL
PALAPI
LocalReAlloc(
IN HLOCAL hMem,
IN SIZE_T uBytes,
IN UINT uFlags)
{
LPVOID lpRetVal = NULL;
PERF_ENTRY(LocalReAlloc);
ENTRY("LocalReAlloc (hMem=%p, uBytes=%u, uFlags=%#x)\n", hMem, uBytes, uFlags);

if (uFlags != LMEM_MOVEABLE) {
// Currently valid iff uFlags is LMEM_MOVEABLE
ASSERT("Invalid parameter uFlags=0x%x\n", uFlags);
SetLastError(ERROR_INVALID_PARAMETER);
goto done;
}
uFlags = 0;

lpRetVal = HeapReAlloc(GetProcessHeap(), uFlags, hMem, uBytes);

done:
LOGEXIT("LocalReAlloc returning %p.\n", lpRetVal);
PERF_EXIT(LocalReAlloc);
return (HLOCAL)lpRetVal;
}

/*++
Function:
Expand Down
5 changes: 5 additions & 0 deletions src/palrt/comem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ STDAPI_(LPVOID) CoTaskMemAlloc(SIZE_T cb)
return LocalAlloc(LMEM_FIXED, cb);
}

STDAPI_(LPVOID) CoTaskMemRealloc(LPVOID pv, SIZE_T cb)
{
return LocalReAlloc(pv, cb, LMEM_MOVEABLE);
}

STDAPI_(void) CoTaskMemFree(LPVOID pv)
{
LocalFree(pv);
Expand Down

0 comments on commit 3e97351

Please sign in to comment.