Author: ion
Date: Sat Jun 24 23:49:28 2006
New Revision: 22583
URL:
http://svn.reactos.org/svn/reactos?rev=22583&view=rev
Log:
- Reformat heap.c to ROS standards
- HeapCreate should mask out NT flags and tag allocations with CLASS 1.
- Implemented HeapCreateTagsW, HeapExtend, HeapQueryTagW, HeapSummary, HeapUsage.
- Stubbed RtlUsageHeap, RtlQueryTagHeap, RtlExtendHeap, RtlCreateTagHeap.
Modified:
trunk/reactos/dll/ntdll/def/ntdll.def
trunk/reactos/dll/win32/kernel32/mem/heap.c
trunk/reactos/include/ndk/rtlfuncs.h
trunk/reactos/include/ndk/rtltypes.h
trunk/reactos/lib/rtl/heap.c
Modified: trunk/reactos/dll/ntdll/def/ntdll.def
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/def/ntdll.def?re…
==============================================================================
--- trunk/reactos/dll/ntdll/def/ntdll.def (original)
+++ trunk/reactos/dll/ntdll/def/ntdll.def Sat Jun 24 23:49:28 2006
@@ -361,7 +361,7 @@
RtlCreateQueryDebugBuffer@8
RtlCreateRegistryKey@8
RtlCreateSecurityDescriptor@8
-;RtlCreateTagHeap
+RtlCreateTagHeap@16
RtlCreateTimer@28
RtlCreateTimerQueue@4
RtlCreateUnicodeString@8
@@ -427,7 +427,7 @@
RtlEraseUnicodeString@4
RtlExitUserThread@4
RtlExpandEnvironmentStrings_U@16
-;RtlExtendHeap
+RtlExtendHeap@16
RtlExtendedIntegerMultiply@12
RtlExtendedLargeIntegerDivide@16
RtlExtendedMagicDivide@20
@@ -595,7 +595,7 @@
;RtlQueryProcessLockInformation
RtlQueryRegistryValues@20
RtlQuerySecurityObject@20
-;RtlQueryTagHeap
+RtlQueryTagHeap@20
RtlQueryTimeZoneInformation@4
RtlRaiseException@4
RtlRaiseStatus@4
@@ -682,7 +682,7 @@
RtlUpdateTimer@16
RtlUpperChar@4
RtlUpperString@8
-;RtlUsageHeap
+RtlUsageHeap@12
@RtlUshortByteSwap@4
RtlValidAcl@4
RtlValidRelativeSecurityDescriptor@12
Modified: trunk/reactos/dll/win32/kernel32/mem/heap.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/mem/hea…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/mem/heap.c (original)
+++ trunk/reactos/dll/win32/kernel32/mem/heap.c Sat Jun 24 23:49:28 2006
@@ -1,256 +1,266 @@
-/* $Id$
- *
- * kernel/heap.c
- * Copyright (C) 1996, Onno Hovers, All rights reserved
- *
- * This software is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this software; see the file COPYING.LIB. If
- * not, write to the Free Software Foundation, Inc., 675 Mass Ave,
- * Cambridge, MA 02139, USA.
- *
- * Win32 heap functions (HeapXXX).
- *
- */
-
-/*
- * Adapted for the ReactOS system libraries by David Welch (welch(a)mcmail.com)
- * Put the type definitions of the heap in a seperate header. Boudewijn Dekker
- */
+/*
+ * PROJECT: ReactOS Win32 Base API
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: dll/win32/kernel32/mem/heap.c
+ * PURPOSE: Heap Memory APIs (wrappers for RtlHeap*)
+ * PROGRAMMERS: Alex Ionescu (alex.ionescu(a)reactos.org)
+ */
+
+/* INCLUDES ******************************************************************/
#include <k32.h>
#define NDEBUG
-#include "../include/debug.h"
-
-/*********************************************************************
-* HeapCreate -- KERNEL32 *
-*********************************************************************/
-/*
- * @implemented
- */
-HANDLE STDCALL HeapCreate(DWORD flags, DWORD dwInitialSize, DWORD dwMaximumSize)
-{
- HANDLE hRet;
- DPRINT("HeapCreate( 0x%lX, 0x%lX, 0x%lX )\n", flags, dwInitialSize,
dwMaximumSize);
-
- hRet = RtlCreateHeap(flags, NULL, dwMaximumSize, dwInitialSize, NULL, NULL);
-
- if (!hRet)
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-
- return hRet;
-}
-
-/*********************************************************************
-* HeapDestroy -- KERNEL32 *
-*********************************************************************/
-/*
- * @implemented
- */
-BOOL WINAPI HeapDestroy(HANDLE hheap)
-{
- if (hheap == RtlGetProcessHeap())
- {
- return FALSE;
- }
-
- if (RtlDestroyHeap( hheap )==NULL) return TRUE;
- SetLastError( ERROR_INVALID_HANDLE );
- return FALSE;
-}
-
-/*********************************************************************
-* GetProcessHeap -- KERNEL32 *
-*********************************************************************/
-/*
- * @implemented
- */
-HANDLE WINAPI GetProcessHeap(VOID)
-{
- DPRINT("GetProcessHeap()\n");
- return(RtlGetProcessHeap());
-}
-
-/********************************************************************
-* GetProcessHeaps -- KERNEL32 *
-********************************************************************/
-/*
- * @implemented
- */
-DWORD WINAPI GetProcessHeaps(DWORD maxheaps, PHANDLE phandles)
-{
- return(RtlGetProcessHeaps(maxheaps, phandles));
-}
-
-/*********************************************************************
-* HeapLock -- KERNEL32 *
-*********************************************************************/
-/*
- * @implemented
- */
-BOOL WINAPI HeapLock(HANDLE hheap)
-{
- return(RtlLockHeap(hheap));
-}
-
-/*********************************************************************
-* HeapUnlock -- KERNEL32 *
-*********************************************************************/
-/*
- * @implemented
- */
-BOOL WINAPI HeapUnlock(HANDLE hheap)
-{
- return(RtlUnlockHeap(hheap));
-}
-
-/*********************************************************************
-* HeapCompact -- KERNEL32 *
-* *
-* NT uses this function to compact moveable blocks and other things *
-* Here it does not compact, but it finds the largest free region *
-*********************************************************************/
-/*
- * @implemented
- */
-SIZE_T WINAPI HeapCompact(HANDLE hheap, DWORD flags)
-{
- return RtlCompactHeap(hheap, flags);
-}
-
-/*********************************************************************
-* HeapValidate -- KERNEL32 *
-*********************************************************************/
-/*
- * @implemented
- */
-BOOL WINAPI HeapValidate(HANDLE hheap, DWORD flags, LPCVOID pmem)
-{
- return(RtlValidateHeap(hheap, flags, (PVOID)pmem));
-}
-
+#include "debug.h"
+
+/* 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;
+
+ /* 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 */
+ Status = RtlExtendHeap(hHeap, dwFlags, BaseAddress, dwBytes);
+ if (!NT_SUCCESS(Status))
+ {
+ /* We failed */
+ SetLastErrorByStatus(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,
+ 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 */
+ Status = RtlUsageHeap(hHeap, dwFlags, &Usage);
+ if (!NT_SUCCESS(Status))
+ {
+ /* We failed */
+ SetLastErrorByStatus(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 */
+ Status = RtlUsageHeap(hHeap, dwFlags, Usage);
+ if (!NT_SUCCESS(Status))
+ {
+ /* We failed */
+ SetLastErrorByStatus(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;
+}
/*
* @unimplemented
*/
-DWORD
+BOOL
STDCALL
-HeapCreateTagsW (
- DWORD Unknown0,
- DWORD Unknown1,
- DWORD Unknown2,
- DWORD Unknown3
- )
-{
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-DWORD
-STDCALL
-HeapExtend (
- DWORD Unknown0,
- DWORD Unknown1,
- DWORD Unknown2,
- DWORD Unknown3
- )
-{
-#if 0
- NTSTATUS Status;
-
- Status = RtlExtendHeap(Unknown1, Unknown2, Unknown3, Unknown4);
- if (!NT_SUCCESS(Status))
- {
- SetLastErrorByStatus(Status);
- return FALSE;
- }
- return TRUE;
-#endif
-
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-DWORD
-STDCALL
-HeapQueryTagW (
- DWORD Unknown0,
- DWORD Unknown1,
- DWORD Unknown2,
- DWORD Unknown3,
- DWORD Unknown4
- )
-{
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-DWORD
-STDCALL
-HeapSummary (
- DWORD Unknown0,
- DWORD Unknown1,
- DWORD Unknown2
- )
-{
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-DWORD
-STDCALL
-HeapUsage (
- DWORD Unknown0,
- DWORD Unknown1,
- DWORD Unknown2,
- DWORD Unknown3,
- DWORD Unknown4
- )
-{
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-BOOL
-STDCALL
-HeapWalk (
- HANDLE hHeap,
- LPPROCESS_HEAP_ENTRY lpEntry
- )
-{
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return FALSE;
-}
-
+HeapWalk(HANDLE hHeap,
+ LPPROCESS_HEAP_ENTRY lpEntry)
+{
+ /* Not implemented */
+ SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+ return FALSE;
+}
/* EOF */
Modified: trunk/reactos/include/ndk/rtlfuncs.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/rtlfuncs.h?rev…
==============================================================================
--- trunk/reactos/include/ndk/rtlfuncs.h (original)
+++ trunk/reactos/include/ndk/rtlfuncs.h Sat Jun 24 23:49:28 2006
@@ -452,8 +452,8 @@
ULONG
NTAPI
RtlCompactHeap(
- HANDLE heap,
- ULONG flags
+ HANDLE Heap,
+ ULONG Flags
);
NTSYSAPI
@@ -471,7 +471,26 @@
NTSYSAPI
HANDLE
NTAPI
-RtlDestroyHeap(HANDLE hheap);
+RtlDestroyHeap(
+ IN HANDLE Heap
+);
+
+NTSYSAPI
+HANDLE
+NTAPI
+RtlDestroyHeap(
+ IN HANDLE Heap
+);
+
+NTSYSAPI
+ULONG
+NTAPI
+RtlExtendHeap(
+ IN HANDLE Heap,
+ IN ULONG Flags,
+ IN PVOID P,
+ IN ULONG Size
+);
NTSYSAPI
BOOLEAN
@@ -507,6 +526,17 @@
);
NTSYSAPI
+PWSTR
+NTAPI
+RtlQueryTagHeap(
+ IN PVOID HeapHandle,
+ IN ULONG Flags,
+ IN USHORT TagIndex,
+ IN BOOLEAN ResetCounters,
+ OUT PRTL_HEAP_TAG_INFO HeapTagInfo
+);
+
+NTSYSAPI
PVOID
NTAPI
RtlReAllocateHeap(
@@ -519,12 +549,25 @@
NTSYSAPI
BOOLEAN
NTAPI
-RtlLockHeap(IN HANDLE Heap);
-
-NTSYSAPI
-BOOLEAN
-NTAPI
-RtlUnlockHeap(IN HANDLE Heap);
+RtlLockHeap(
+ IN HANDLE Heap
+);
+
+NTSYSAPI
+NTSTATUS
+NTAPI
+RtlUsageHeap(
+ IN HANDLE Heap,
+ IN ULONG Flags,
+ OUT PRTL_HEAP_USAGE Usage
+);
+
+NTSYSAPI
+BOOLEAN
+NTAPI
+RtlUnlockHeap(
+ IN HANDLE Heap
+);
BOOLEAN
NTAPI
@@ -550,7 +593,7 @@
RtlValidateHeap(
HANDLE Heap,
ULONG Flags,
- PVOID pmem
+ PVOID P
);
#define RtlGetProcessHeap() (NtCurrentPeb()->ProcessHeap)
Modified: trunk/reactos/include/ndk/rtltypes.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/rtltypes.h?rev…
==============================================================================
--- trunk/reactos/include/ndk/rtltypes.h (original)
+++ trunk/reactos/include/ndk/rtltypes.h Sat Jun 24 23:49:28 2006
@@ -779,6 +779,31 @@
ULONG TimeDateStamp;
PVOID DefaultBase;
} RTL_PROCESS_MODULE_INFORMATION_EX, *PRTL_PROCESS_MODULE_INFORMATION_EX;
+
+typedef struct _RTL_HEAP_TAG_INFO
+{
+ ULONG NumberOfAllocations;
+ ULONG NumberOfFrees;
+ ULONG BytesAllocated;
+} RTL_HEAP_TAG_INFO, *PRTL_HEAP_TAG_INFO;
+
+typedef struct _RTL_HEAP_USAGE_ENTRY
+{
+ struct _RTL_HEAP_USAGE_ENTRY *Next;
+} RTL_HEAP_USAGE_ENTRY, *PRTL_HEAP_USAGE_ENTRY;
+
+typedef struct _RTL_HEAP_USAGE
+{
+ ULONG Length;
+ ULONG BytesAllocated;
+ ULONG BytesCommitted;
+ ULONG BytesReserved;
+ ULONG BytesReservedMaximum;
+ PRTL_HEAP_USAGE_ENTRY Entries;
+ PRTL_HEAP_USAGE_ENTRY AddedEntries;
+ PRTL_HEAP_USAGE_ENTRY RemovedEntries;
+ UCHAR Reserved[32];
+} RTL_HEAP_USAGE, *PRTL_HEAP_USAGE;
typedef struct _RTL_HEAP_INFORMATION
{
Modified: trunk/reactos/lib/rtl/heap.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/heap.c?rev=22583&a…
==============================================================================
--- trunk/reactos/lib/rtl/heap.c (original)
+++ trunk/reactos/lib/rtl/heap.c Sat Jun 24 23:49:28 2006
@@ -1897,4 +1897,55 @@
return TRUE;
}
+/*
+ * @unimplemented
+ */
+NTSTATUS
+NTAPI
+RtlUsageHeap(IN HANDLE Heap,
+ IN ULONG Flags,
+ OUT PRTL_HEAP_USAGE Usage)
+{
+ /* TODO */
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+PWSTR
+NTAPI
+RtlQueryTagHeap(IN PVOID HeapHandle,
+ IN ULONG Flags,
+ IN USHORT TagIndex,
+ IN BOOLEAN ResetCounters,
+ OUT PRTL_HEAP_TAG_INFO HeapTagInfo)
+{
+ /* TODO */
+ UNIMPLEMENTED;
+ return NULL;
+}
+
+ULONG
+NTAPI
+RtlExtendHeap(IN HANDLE Heap,
+ IN ULONG Flags,
+ IN PVOID P,
+ IN ULONG Size)
+{
+ /* TODO */
+ UNIMPLEMENTED;
+ return 0;
+}
+
+ULONG
+NTAPI
+RtlCreateTagHeap(IN HANDLE HeapHandle,
+ IN ULONG Flags,
+ IN PWSTR TagName,
+ IN PWSTR TagSubName)
+{
+ /* TODO */
+ UNIMPLEMENTED;
+ return 0;
+}
+
/* EOF */