- Update to r53061
[reactos.git] / dll / win32 / kernel32 / client / heapmem.c
similarity index 57%
rename from dll/win32/kernel32/mem/global.c
rename to dll/win32/kernel32/client/heapmem.c
index a0449e3..808e31b 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * PROJECT:         ReactOS Win32 Base API
  * LICENSE:         GPL - See COPYING in the top level directory
- * FILE:            dll/win32/kernel32/mem/global.c
- * PURPOSE:         Global Memory APIs (sits on top of Heap*)
+ * FILE:            dll/win32/kernel32/mem/heap.c
+ * PURPOSE:         Heap Memory APIs (wrappers for RtlHeap*)
  * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
  */
 
 
 /* TYPES *********************************************************************/
 
-extern SYSTEM_BASIC_INFORMATION BaseCachedSysInfo;
 RTL_HANDLE_TABLE BaseHeapHandleTable;
 
 /* FUNCTIONS ***************************************************************/
 
+/*
+ * @implemented
+ */
+HANDLE
+WINAPI
+HeapCreate(DWORD flOptions,
+           DWORD dwInitialSize,
+           DWORD dwMaximumSize)
+{
+    HANDLE hRet;
+    ULONG Flags;
+
+    /* Remove non-Win32 flags and tag this allocation */
+    Flags = (flOptions & (HEAP_GENERATE_EXCEPTIONS | HEAP_NO_SERIALIZE)) |
+            HEAP_CLASS_1;
+
+    /* Check if heap is growable and ensure max size is correct */
+    if (dwMaximumSize == 0)
+        Flags |= HEAP_GROWABLE;
+    else if (dwMaximumSize < BaseStaticServerData->SysInfo.PageSize &&
+            dwInitialSize > dwMaximumSize)
+    {
+        /* Max size is non-zero but less than page size which can't be correct.
+           Fix it up by bumping it to the initial size whatever it is. */
+        dwMaximumSize = dwInitialSize;
+    }
+
+    /* Call RTL Heap */
+    hRet = RtlCreateHeap(Flags,
+                         NULL,
+                         dwMaximumSize,
+                         dwInitialSize,
+                         NULL,
+                         NULL);
+
+    /* Set the last error if we failed, and return the pointer */
+    if (!hRet) SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+    return hRet;
+}
+
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
+HeapDestroy(HANDLE hHeap)
+{
+    /* Return TRUE if the heap was destroyed */
+   if (!RtlDestroyHeap(hHeap)) return TRUE;
+
+    /* Otherwise, we got the handle back, so fail */
+    SetLastError(ERROR_INVALID_HANDLE);
+    return FALSE;
+}
+
+/*
+ * @implemented
+ */
+HANDLE
+WINAPI
+GetProcessHeap(VOID)
+{
+    /* Call the RTL API */
+    return RtlGetProcessHeap();
+}
+
+/*
+ * @implemented
+ */
+DWORD
+WINAPI
+GetProcessHeaps(DWORD NumberOfHeaps,
+                PHANDLE ProcessHeaps)
+{
+    /* Call the RTL API */
+    return RtlGetProcessHeaps(NumberOfHeaps, ProcessHeaps);
+}
+
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
+HeapLock(HANDLE hHeap)
+{
+    /* Call the RTL API */
+    return RtlLockHeap(hHeap);
+}
+
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
+HeapUnlock(HANDLE hHeap)
+{
+    /* Call the RTL API */
+    return RtlUnlockHeap(hHeap);
+}
+
+/*
+ * @implemented
+ */
+SIZE_T
+WINAPI
+HeapCompact(HANDLE hHeap, DWORD dwFlags)
+{
+    /* Call the RTL API */
+    return RtlCompactHeap(hHeap, dwFlags);
+}
+
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
+HeapValidate(HANDLE hHeap,
+             DWORD dwFlags,
+             LPCVOID lpMem)
+{
+    /* Call the RTL API */
+    return RtlValidateHeap(hHeap, dwFlags, (PVOID)lpMem);
+}
+
+/*
+ * @implemented
+ */
+DWORD
+WINAPI
+HeapCreateTagsW(HANDLE hHeap,
+                DWORD dwFlags,
+                PWSTR lpTagName,
+                PWSTR lpTagSubName)
+{
+    /* Call the RTL API */
+    return RtlCreateTagHeap(hHeap,
+                            dwFlags,
+                            lpTagName,
+                            lpTagSubName);
+}
+
+/*
+ * @implemented
+ */
+DWORD
+WINAPI
+HeapExtend(HANDLE hHeap,
+           DWORD dwFlags,
+           PVOID BaseAddress,
+           DWORD dwBytes)
+{
+    NTSTATUS Status;
+
+    /* Call the RTL API. Gone in Vista, so commented out. */
+    Status = STATUS_NOT_IMPLEMENTED; //RtlExtendHeap(hHeap, dwFlags, BaseAddress, dwBytes);
+    if (!NT_SUCCESS(Status))
+    {
+        /* We failed */
+        BaseSetLastNTError(Status);
+        return FALSE;
+    }
+
+    /* Return success */
+    return TRUE;
+}
+
+/*
+ * @implemented
+ */
+PWSTR
+WINAPI
+HeapQueryTagW(HANDLE hHeap,
+              DWORD dwFlags,
+              WORD wTagIndex,
+              BOOL bResetCounters,
+              PVOID lpTagInfo)
+{
+    /* Call the RTL API */
+    return RtlQueryTagHeap(hHeap,
+                           dwFlags,
+                           wTagIndex,
+                           (BOOLEAN)bResetCounters,
+                           lpTagInfo);
+}
+
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
+HeapSummary(HANDLE hHeap,
+            DWORD dwFlags,
+            PVOID Summary)
+{
+    NTSTATUS Status;
+    RTL_HEAP_USAGE Usage;
+
+    /* Fill in the length information */
+    Usage.Length = sizeof(Usage);
+
+    /* Call RTL. Gone in Vista, so commented out */
+    Status = STATUS_NOT_IMPLEMENTED; //RtlUsageHeap(hHeap, dwFlags, &Usage);
+    if (!NT_SUCCESS(Status))
+    {
+        /* We failed */
+        BaseSetLastNTError(Status);
+        return FALSE;
+    }
+
+    /* FIXME: Summary == Usage?! */
+    RtlCopyMemory(Summary, &Usage, sizeof(Usage));
+    return TRUE;
+}
+
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
+HeapUsage(HANDLE hHeap,
+          DWORD dwFlags,
+          DWORD Unknown,
+          DWORD Unknown2,
+          IN PVOID Usage)
+{
+    NTSTATUS Status;
+
+    /* Call RTL. Gone in Vista, so commented out */
+    Status = STATUS_NOT_IMPLEMENTED; //RtlUsageHeap(hHeap, dwFlags, &Usage);
+    if (!NT_SUCCESS(Status))
+    {
+        /* We failed */
+        BaseSetLastNTError(Status);
+        return FALSE;
+    }
+    else if (Status == STATUS_MORE_ENTRIES)
+    {
+        /* There are still more entries to parse */
+        return TRUE;
+    }
+
+    /* Otherwise, we're completely done, so we return FALSE, but NO_ERROR */
+    SetLastError(NO_ERROR);
+    return FALSE;
+}
+
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
+HeapWalk(HANDLE        hHeap,
+         LPPROCESS_HEAP_ENTRY lpEntry)
+{
+    NTSTATUS Status;
+
+    Status = RtlWalkHeap(hHeap, lpEntry);
+
+    if (!NT_SUCCESS(Status))
+    {
+        SetLastError(RtlNtStatusToDosError(Status));
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
+HeapQueryInformation(HANDLE HeapHandle,
+                     HEAP_INFORMATION_CLASS HeapInformationClass,
+                     PVOID HeapInformation OPTIONAL,
+                     SIZE_T HeapInformationLength OPTIONAL,
+                     PSIZE_T ReturnLength OPTIONAL)
+{
+    NTSTATUS Status;
+
+    Status = RtlQueryHeapInformation(HeapHandle,
+                                     HeapInformationClass,
+                                     HeapInformation,
+                                     HeapInformationLength,
+                                     ReturnLength);
+
+    if (!NT_SUCCESS(Status))
+    {
+        BaseSetLastNTError(Status);
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
+HeapSetInformation(HANDLE HeapHandle,
+                   HEAP_INFORMATION_CLASS HeapInformationClass,
+                   PVOID HeapInformation OPTIONAL,
+                   SIZE_T HeapInformationLength OPTIONAL)
+{
+    NTSTATUS Status;
+
+    Status = RtlSetHeapInformation(HeapHandle,
+                                   HeapInformationClass,
+                                   HeapInformation,
+                                   HeapInformationLength);
+
+    if (!NT_SUCCESS(Status))
+    {
+        BaseSetLastNTError(Status);
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
 /*
  * @implemented
  */
@@ -884,18 +1204,18 @@ GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer)
                              NULL);
 
     /* Calculate memory load */
-    lpBuffer->dwMemoryLoad = ((DWORD)(BaseCachedSysInfo.NumberOfPhysicalPages -
+    lpBuffer->dwMemoryLoad = ((DWORD)(BaseStaticServerData->SysInfo.NumberOfPhysicalPages -
                                       PerformanceInfo.AvailablePages) * 100) /
-                                      BaseCachedSysInfo.NumberOfPhysicalPages;
+                                      BaseStaticServerData->SysInfo.NumberOfPhysicalPages;
 
     /* Save physical memory */
-    PhysicalMemory = BaseCachedSysInfo.NumberOfPhysicalPages *
-                     BaseCachedSysInfo.PageSize;
+    PhysicalMemory = BaseStaticServerData->SysInfo.NumberOfPhysicalPages *
+                     BaseStaticServerData->SysInfo.PageSize;
     lpBuffer->ullTotalPhys = PhysicalMemory;
 
     /* Now save available physical memory */
     PhysicalMemory = PerformanceInfo.AvailablePages *
-                     BaseCachedSysInfo.PageSize;
+                     BaseStaticServerData->SysInfo.PageSize;
     lpBuffer->ullAvailPhys = PhysicalMemory;
 
     /* Query VM and Quota Limits */
@@ -921,11 +1241,11 @@ GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer)
     lpBuffer->ullAvailPageFile = min(PageFile,
                                      QuotaLimits.PagefileLimit -
                                      VmCounters.PagefileUsage);
-    lpBuffer->ullAvailPageFile *= BaseCachedSysInfo.PageSize;
+    lpBuffer->ullAvailPageFile *= BaseStaticServerData->SysInfo.PageSize;
 
     /* Now calculate the total virtual space */
-    lpBuffer->ullTotalVirtual = (BaseCachedSysInfo.MaximumUserModeAddress -
-                                 BaseCachedSysInfo.MinimumUserModeAddress) + 1;
+    lpBuffer->ullTotalVirtual = (BaseStaticServerData->SysInfo.MaximumUserModeAddress -
+                                 BaseStaticServerData->SysInfo.MinimumUserModeAddress) + 1;
 
     /* And finally the avilable virtual space */
     lpBuffer->ullAvailVirtual = lpBuffer->ullTotalVirtual -
@@ -959,4 +1279,484 @@ GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer)
     }
 }
 
+/*
+ * @implemented
+ */
+HLOCAL
+NTAPI
+LocalAlloc(UINT uFlags,
+           SIZE_T dwBytes)
+{
+    ULONG Flags = 0;
+    PVOID Ptr = NULL;
+    HANDLE hMemory;
+    PBASE_HEAP_HANDLE_ENTRY HandleEntry;
+    BASE_TRACE_ALLOC(dwBytes, uFlags);
+    ASSERT(hProcessHeap);
+
+    /* Make sure the flags are valid */
+    if (uFlags & ~LMEM_VALID_FLAGS)
+    {
+        /* They aren't, fail */
+        BASE_TRACE_FAILURE();
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return NULL;
+    }
+
+    /* Convert ZEROINIT */
+    if (uFlags & LMEM_ZEROINIT) Flags |= HEAP_ZERO_MEMORY;
+
+    /* Check if we're not movable, which means pointer-based heap */
+    if (!(uFlags & LMEM_MOVEABLE))
+    {
+        /* Allocate heap for it */
+        Ptr = RtlAllocateHeap(hProcessHeap, Flags, dwBytes);
+        BASE_TRACE_ALLOC2(Ptr);
+        return Ptr;
+    }
+
+    /* This is heap based, so lock it in first */
+    RtlLockHeap(hProcessHeap);
+
+    /*
+     * Disable locking, enable custom flags, and write the
+     * movable flag (deprecated)
+     */
+    Flags |= HEAP_NO_SERIALIZE |
+             HEAP_SETTABLE_USER_VALUE |
+             BASE_HEAP_FLAG_MOVABLE;
+
+    /* Allocate the handle */
+    HandleEntry = BaseHeapAllocEntry();
+    if (!HandleEntry)
+    {
+        /* Fail */
+        hMemory = NULL;
+        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+        BASE_TRACE_FAILURE();
+        goto Quickie;
+    }
+
+    /* Get the object and make sure we have size */
+    hMemory = &HandleEntry->Object;
+    if (dwBytes)
+    {
+        /* Allocate the actual memory for it */
+        Ptr = RtlAllocateHeap(hProcessHeap, Flags, dwBytes);
+        BASE_TRACE_PTR(HandleEntry, Ptr);
+        if (!Ptr)
+        {
+            /* We failed, manually set the allocate flag and free the handle */
+            HandleEntry->Flags = RTL_HANDLE_VALID;
+            BaseHeapFreeEntry(HandleEntry);
+
+            /* For the cleanup case */
+            HandleEntry = NULL;
+        }
+        else
+        {
+            /* All worked well, save our heap entry */
+            RtlSetUserValueHeap(hProcessHeap, HEAP_NO_SERIALIZE, Ptr, hMemory);
+        }
+    }
+
+Quickie:
+    /* Cleanup! First unlock the heap */
+    RtlUnlockHeap(hProcessHeap);
+
+    /* Check if a handle was allocated */
+    if (HandleEntry)
+    {
+        /* Set the pointer and allocated flag */
+        HandleEntry->Object = Ptr;
+        HandleEntry->Flags = RTL_HANDLE_VALID;
+        if (!Ptr)
+        {
+            /* We don't have a valid pointer, but so reuse this handle */
+            HandleEntry->Flags |= BASE_HEAP_ENTRY_FLAG_REUSE;
+        }
+
+        /* Check if the handle is discardable */
+        if (uFlags & GMEM_DISCARDABLE)
+        {
+            /* Save it in the handle entry */
+            HandleEntry->Flags |= BASE_HEAP_ENTRY_FLAG_REUSABLE;
+        }
+
+        /* Check if the handle is moveable */
+        if (uFlags & GMEM_MOVEABLE)
+        {
+            /* Save it in the handle entry */
+            HandleEntry->Flags |= BASE_HEAP_ENTRY_FLAG_MOVABLE;
+        }
+
+        /* Set the pointer */
+        Ptr = hMemory;
+    }
+
+    /* Return the pointer */
+    return Ptr;
+}
+
+/*
+ * @implemented
+ */
+SIZE_T
+NTAPI
+LocalCompact(UINT dwMinFree)
+{
+    /* Call the RTL Heap Manager */
+    return RtlCompactHeap(hProcessHeap, 0);
+}
+
+/*
+ * @implemented
+ */
+UINT
+NTAPI
+LocalFlags(HLOCAL hMem)
+{
+    PBASE_HEAP_HANDLE_ENTRY HandleEntry;
+    HANDLE Handle = NULL;
+    ULONG Flags = 0;
+    UINT uFlags = LMEM_INVALID_HANDLE;
+
+    /* Start by locking the heap */
+    RtlLockHeap(hProcessHeap);
+
+    /* Check if this is a simple RTL Heap Managed block */
+    if (!((ULONG_PTR)hMem & BASE_HEAP_IS_HANDLE_ENTRY))
+    {
+        /* Then we'll query RTL Heap */
+        RtlGetUserInfoHeap(hProcessHeap, Flags, hMem, &Handle, &Flags);
+        BASE_TRACE_PTR(Handle, hMem);
+
+        /*
+         * Check if RTL Heap didn't find a handle associated with us or
+         * said that this heap isn't movable, which means something we're
+         * really not a handle-based heap.
+         */
+        if (!(Handle) || !(Flags & BASE_HEAP_FLAG_MOVABLE))
+        {
+            /* Then set the flags to 0 */
+            uFlags = 0;
+        }
+        else
+        {
+            /* Otherwise we're handle-based, so get the internal handle */
+            hMem = Handle;
+        }
+    }
+
+    /* Check if the handle is actually an entry in our table */
+    if ((ULONG_PTR)hMem & BASE_HEAP_IS_HANDLE_ENTRY)
+    {
+        /* Then get the entry */
+        HandleEntry = BaseHeapGetEntry(hMem);
+        BASE_TRACE_HANDLE(HandleEntry, hMem);
+
+        /* Make sure it's a valid handle */
+        if (BaseHeapValidateEntry(HandleEntry))
+        {
+            /* Get the lock count first */
+            uFlags = HandleEntry->LockCount & LMEM_LOCKCOUNT;
+
+            /* Now check if it's discardable */
+            if (HandleEntry->Flags & BASE_HEAP_ENTRY_FLAG_REUSABLE)
+            {
+                /* Set the Win32 Flag */
+                uFlags |= LMEM_DISCARDABLE;
+            }
+
+            /* Now check if it's discarded */
+            if (HandleEntry->Flags & BASE_HEAP_ENTRY_FLAG_REUSE)
+               /* Set the Win32 Flag */
+               uFlags |= LMEM_DISCARDED;
+        }
+    }
+
+    /* Check if by now, we still haven't gotten any useful flags */
+    if (uFlags == LMEM_INVALID_HANDLE) SetLastError(ERROR_INVALID_HANDLE);
+
+    /* All done! Unlock heap and return Win32 Flags */
+    RtlUnlockHeap(hProcessHeap);
+    return uFlags;
+}
+
+/*
+ * @implemented
+ */
+HLOCAL
+NTAPI
+LocalFree(HLOCAL hMem)
+{
+    /* This is identical to a Global Free */
+    return GlobalFree(hMem);
+}
+
+/*
+ * @implemented
+ */
+HLOCAL
+NTAPI
+LocalHandle(LPCVOID pMem)
+{
+    /* This is identical to a Global Handle */
+    return GlobalHandle(pMem);
+}
+
+/*
+ * @implemented
+ */
+LPVOID
+NTAPI
+LocalLock(HLOCAL hMem)
+{
+    /* This is the same as a GlobalLock, assuming these never change */
+    C_ASSERT(LMEM_LOCKCOUNT == GMEM_LOCKCOUNT);
+    return GlobalLock(hMem);
+}
+
+HLOCAL
+NTAPI
+LocalReAlloc(HLOCAL hMem,
+             SIZE_T dwBytes,
+             UINT uFlags)
+{
+    PBASE_HEAP_HANDLE_ENTRY HandleEntry;
+    LPVOID Ptr;
+    ULONG Flags = 0;
+
+    /* Convert ZEROINIT */
+    if (uFlags & LMEM_ZEROINIT) Flags |= HEAP_ZERO_MEMORY;
+
+    /* If this wasn't a movable heap, then we MUST re-alloc in place */
+    if (!(uFlags & LMEM_MOVEABLE)) Flags |= HEAP_REALLOC_IN_PLACE_ONLY;
+
+    /* Lock the heap and disable built-in locking in the RTL Heap funcitons */
+    RtlLockHeap(hProcessHeap);
+    Flags |= HEAP_NO_SERIALIZE;
+
+    /* Check if this is a simple handle-based block */
+    if (((ULONG_PTR)hMem & BASE_HEAP_IS_HANDLE_ENTRY))
+    {
+        /* Get the entry */
+        HandleEntry = BaseHeapGetEntry(hMem);
+        BASE_TRACE_HANDLE(HandleEntry, hMem);
+
+        /* Make sure the handle is valid */
+        if (!BaseHeapValidateEntry(HandleEntry))
+        {
+            /* Fail */
+            BASE_TRACE_FAILURE();
+            SetLastError(ERROR_INVALID_HANDLE);
+            hMem = NULL;
+        }
+        else if (uFlags & LMEM_MODIFY)
+        {
+            /* User is changing flags... check if the memory was discardable */
+            if (uFlags & LMEM_DISCARDABLE)
+            {
+                /* Then set the flag */
+                HandleEntry->Flags |= BASE_HEAP_ENTRY_FLAG_REUSABLE;
+            }
+            else
+            {
+                /* Otherwise, remove the flag */
+                HandleEntry->Flags &= BASE_HEAP_ENTRY_FLAG_REUSABLE;
+            }
+        }
+        else
+        {
+            /* Otherwise, get the object and check if we have no size */
+            Ptr = HandleEntry->Object;
+            if (!dwBytes)
+            {
+                /* Clear the handle and check for a pointer */
+                hMem = NULL;
+                if (Ptr)
+                {
+                    /* Make sure the handle isn't locked */
+                    if ((uFlags & LMEM_MOVEABLE) && !(HandleEntry->LockCount))
+                    {
+                        /* Free the current heap */
+                        RtlFreeHeap(hProcessHeap, Flags, Ptr);
+
+                        /* Free the handle */
+                        HandleEntry->Object = NULL;
+                        HandleEntry->Flags |= BASE_HEAP_ENTRY_FLAG_REUSE;
+
+                        /* Get the object pointer */
+                        hMem = &HandleEntry->Object;
+                    }
+                }
+                else
+                {
+                    /* Otherwise just return the object pointer */
+                    hMem = &HandleEntry->Object;
+                }
+            }
+            else
+            {
+                /* Otherwise, we're allocating, so set the new flags needed */
+                Flags |= HEAP_SETTABLE_USER_VALUE | BASE_HEAP_FLAG_MOVABLE;
+                if (!Ptr)
+                {
+                    /* We don't have a base, so allocate one */
+                    Ptr = RtlAllocateHeap(hProcessHeap, Flags, dwBytes);
+                    BASE_TRACE_ALLOC2(Ptr);
+                    if (Ptr)
+                    {
+                        /* Allocation succeeded, so save our entry */
+                        RtlSetUserValueHeap(hProcessHeap,
+                                            HEAP_NO_SERIALIZE,
+                                            Ptr,
+                                            hMem);
+                    }
+                }
+                else
+                {
+                    /*
+                     * If it's not movable or currently locked, we MUST allocate
+                     * in-place!
+                     */
+                    if (!(uFlags & LMEM_MOVEABLE) && (HandleEntry->LockCount))
+                    {
+                        /* Set the flag */
+                        Flags |= HEAP_REALLOC_IN_PLACE_ONLY;
+                    }
+                    else
+                    {
+                        /* Otherwise clear the flag if we set it previously */
+                        Flags &= ~HEAP_REALLOC_IN_PLACE_ONLY;
+                    }
+
+                    /* And do the re-allocation */
+                    Ptr = RtlReAllocateHeap(hProcessHeap, Flags, Ptr, dwBytes);
+                }
+
+                /* Make sure we have a pointer by now */
+                if (Ptr)
+                {
+                    /* Write it in the handle entry and mark it in use */
+                    HandleEntry->Object = Ptr;
+                    HandleEntry->Flags &= ~BASE_HEAP_ENTRY_FLAG_REUSE;
+                }
+                else
+                {
+                    /* Otherwise we failed */
+                    hMem = NULL;
+                    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+                }
+            }
+        }
+    }
+    else if (!(uFlags & LMEM_MODIFY))
+    {
+        /* Otherwise, this is a simple RTL Managed Heap, so just call it */
+        hMem = RtlReAllocateHeap(hProcessHeap,
+                                 Flags | HEAP_NO_SERIALIZE,
+                                 hMem,
+                                 dwBytes);
+        if (!hMem)
+        {
+            /* Fail */
+            BASE_TRACE_FAILURE();
+            SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+        }
+    }
+
+    /* All done, unlock the heap and return the pointer */
+    RtlUnlockHeap(hProcessHeap);
+    return hMem;
+}
+
+/*
+ * @implemented
+ */
+SIZE_T
+WINAPI
+LocalShrink(HLOCAL hMem,
+            UINT cbNewSize)
+{
+    /* Call RTL */
+    return RtlCompactHeap(hProcessHeap, 0);
+}
+
+/*
+ * @implemented
+ */
+SIZE_T
+NTAPI
+LocalSize(HLOCAL hMem)
+{
+    /* This is the same as a Global Size */
+    return GlobalSize(hMem);
+}
+
+/*
+ * @implemented
+ */
+BOOL
+NTAPI
+LocalUnlock(HLOCAL hMem)
+{
+    PBASE_HEAP_HANDLE_ENTRY HandleEntry;
+    BOOL RetVal = TRUE;
+
+    /* Check if this was a simple allocated heap entry */
+    if (!((ULONG_PTR)hMem & BASE_HEAP_IS_HANDLE_ENTRY))
+    {
+       /* Fail, because LocalUnlock is not supported on LMEM_FIXED allocations */
+       SetLastError(ERROR_NOT_LOCKED);
+       return FALSE;
+    }
+
+    /* Otherwise, lock the heap */
+    RtlLockHeap(hProcessHeap);
+
+    /* Get the handle entry */
+    HandleEntry = BaseHeapGetEntry(hMem);
+    BASE_TRACE_HANDLE(HandleEntry, hMem);
+
+    _SEH2_TRY
+    {
+        /* Make sure it's valid */
+        if (!BaseHeapValidateEntry(HandleEntry))
+        {
+            /* It's not, fail */
+            BASE_TRACE_FAILURE();
+            SetLastError(ERROR_INVALID_HANDLE);
+            RetVal = FALSE;
+        }
+        else
+        {
+            /* Otherwise, decrement lock count, unless we're already at 0*/
+            if (!HandleEntry->LockCount--)
+            {
+                /* In which case we simply lock it back and fail */
+                HandleEntry->LockCount++;
+                SetLastError(ERROR_NOT_LOCKED);
+                RetVal = FALSE;
+            }
+            else if (!HandleEntry->LockCount)
+            {
+                /* Nothing to unlock */
+                SetLastError(NO_ERROR);
+                RetVal = FALSE;
+            }
+        }
+    }
+    _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        RetVal = FALSE;
+    }
+    _SEH2_END
+
+    /* All done. Unlock the heap and return the pointer */
+    RtlUnlockHeap(hProcessHeap);
+    return RetVal;
+}
+
 /* EOF */