- Sync with trunk r51050.

svn path=/branches/cmake-bringup/; revision=51154
This commit is contained in:
Amine Khaldi 2011-03-26 13:00:21 +00:00
commit 785bea480a
469 changed files with 16304 additions and 9647 deletions

View file

@ -29,6 +29,7 @@ list(APPEND SOURCE
handle.c
heap.c
heapdbg.c
heappage.c
image.c
interlck.c
message.c

View file

@ -12,7 +12,6 @@
typedef struct _TABLE_ENTRY_HEADER
{
RTL_BALANCED_LINKS BalancedLinks;
LIST_ENTRY ListEntry;
LONGLONG UserData;
} TABLE_ENTRY_HEADER, *PTABLE_ENTRY_HEADER;

View file

@ -70,11 +70,12 @@ RtlInsertElementGenericTableFullAvl(IN PRTL_AVL_TABLE Table,
if (NewElement) *NewElement = FALSE;
return NULL;
}
/* Data to return to user */
UserData = &((PTABLE_ENTRY_HEADER)NewNode)->UserData;
/* Insert the node in the tree */
RtlZeroMemory(NewNode, sizeof(RTL_BALANCED_LINKS));
RtlpInsertAvlTreeNode(Table, NewNode, NodeOrParent, SearchResult);
/* Copy user buffer */
@ -88,7 +89,7 @@ RtlInsertElementGenericTableFullAvl(IN PRTL_AVL_TABLE Table,
}
/* Return status */
if (NewElement) *NewElement = (SearchResult == TableFoundNode);
if (NewElement) *NewElement = (SearchResult != TableFoundNode);
/* Return pointer to user data */
return UserData;

View file

@ -604,7 +604,7 @@ NTAPI
RtlLeaveCriticalSection(PRTL_CRITICAL_SECTION CriticalSection)
{
#ifndef NDEBUG
HANDLE Thread = (HANDLE)NtCurrentTeb()->Cid.UniqueThread;
HANDLE Thread = (HANDLE)NtCurrentTeb()->ClientId.UniqueThread;
/* In win this case isn't checked. However it's a valid check so it should only
be performed in debug builds! */

View file

@ -414,7 +414,7 @@ RtlpCreateUnCommittedRange(PHEAP_SEGMENT Segment)
if (IsListEmpty(&Heap->UCRList))
{
/* Get a pointer to the first UCR segment */
UcrSegment = CONTAINING_RECORD(&Heap->UCRSegments.Flink, HEAP_UCR_SEGMENT, ListEntry);
UcrSegment = CONTAINING_RECORD(Heap->UCRSegments.Flink, HEAP_UCR_SEGMENT, ListEntry);
/* Check the list of UCR segments */
if (IsListEmpty(&Heap->UCRSegments) ||
@ -539,8 +539,11 @@ RtlpInsertUnCommittedPages(PHEAP_SEGMENT Segment,
Address = (ULONG_PTR)UcrDescriptor->Address;
Size += UcrDescriptor->Size;
/* Remove it from the list and destroy it */
RemoveEntryList(Current);
/* Advance to the next descriptor */
Current = Current->Flink;
/* Remove the current descriptor from the list and destroy it */
RemoveEntryList(&UcrDescriptor->SegmentEntry);
RtlpDestroyUnCommittedRange(Segment, UcrDescriptor);
Segment->NumberOfUnCommittedRanges--;
@ -1362,8 +1365,11 @@ RtlCreateHeap(ULONG Flags,
Heap = RtlpPageHeapCreate(Flags, Addr, TotalSize, CommitSize, Lock, Parameters);
if (Heap) return Heap;
//ASSERT(FALSE);
DPRINT1("Enabling page heap failed\n");
/* Reset a special Parameters == -1 hack */
if ((ULONG_PTR)Parameters == (ULONG_PTR)-1)
Parameters = NULL;
else
DPRINT1("Enabling page heap failed\n");
}
/* Check validation flags */
@ -1716,6 +1722,9 @@ RtlDestroyHeap(HANDLE HeapPtr) /* [in] Handle of heap */
if (!HeapPtr) return NULL;
/* Call page heap routine if required */
if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS) return RtlpPageHeapDestroy(HeapPtr);
/* Call special heap */
if (RtlpHeapIsSpecial(Heap->Flags))
{
@ -3701,7 +3710,9 @@ BOOLEAN NTAPI RtlValidateHeap(
BOOLEAN HeapLocked = FALSE;
BOOLEAN HeapValid;
// FIXME Check for special heap
/* Check for page heap */
if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
return RtlpDebugPageHeapValidate(HeapPtr, Flags, Block);
/* Check signature */
if (Heap->Signature != HEAP_SIGNATURE)

View file

@ -182,6 +182,19 @@ typedef struct _HEAP_TUNING_PARAMETERS
ULONG MaxPreCommittThreshold;
} HEAP_TUNING_PARAMETERS, *PHEAP_TUNING_PARAMETERS;
typedef struct _HEAP_LIST_LOOKUP
{
struct _HEAP_LIST_LOOKUP *ExtendedLookup;
ULONG ArraySize;
ULONG ExtraItem;
ULONG ItemCount;
ULONG OutOfRangeItems;
ULONG BaseIndex;
PLIST_ENTRY ListHead;
PULONG ListsInUseUlong;
PLIST_ENTRY *ListHints;
} HEAP_LIST_LOOKUP, *PHEAP_LIST_LOOKUP;
typedef struct _HEAP
{
HEAP_ENTRY Entry;
@ -229,10 +242,11 @@ typedef struct _HEAP
struct _HEAP_SEGMENT *Segments[HEAP_SEGMENTS]; //FIXME: non-Vista
USHORT AllocatorBackTraceIndex;
ULONG NonDedicatedListLength;
PVOID BlocksIndex;
PVOID BlocksIndex; // HEAP_LIST_LOOKUP
PVOID UCRIndex;
PHEAP_PSEUDO_TAG_ENTRY PseudoTagEntries;
LIST_ENTRY FreeLists[HEAP_FREELISTS]; //FIXME: non-Vista
//LIST_ENTRY FreeLists;
union
{
ULONG FreeListsInUseUlong[HEAP_FREELISTS / (sizeof(ULONG) * 8)]; //FIXME: non-Vista
@ -385,6 +399,8 @@ RtlDebugSizeHeap(HANDLE HeapPtr,
ULONG Flags,
PVOID Ptr);
/* heappage.c */
HANDLE NTAPI
RtlpPageHeapCreate(ULONG Flags,
PVOID Addr,
@ -393,4 +409,55 @@ RtlpPageHeapCreate(ULONG Flags,
PVOID Lock,
PRTL_HEAP_PARAMETERS Parameters);
PVOID NTAPI
RtlpPageHeapDestroy(HANDLE HeapPtr);
PVOID NTAPI
RtlpPageHeapAllocate(IN PVOID HeapPtr,
IN ULONG Flags,
IN SIZE_T Size);
BOOLEAN NTAPI
RtlpPageHeapFree(HANDLE HeapPtr,
ULONG Flags,
PVOID Ptr);
PVOID NTAPI
RtlpPageHeapReAllocate(HANDLE HeapPtr,
ULONG Flags,
PVOID Ptr,
SIZE_T Size);
BOOLEAN NTAPI
RtlpPageHeapGetUserInfo(PVOID HeapHandle,
ULONG Flags,
PVOID BaseAddress,
PVOID *UserValue,
PULONG UserFlags);
BOOLEAN NTAPI
RtlpPageHeapSetUserValue(PVOID HeapHandle,
ULONG Flags,
PVOID BaseAddress,
PVOID UserValue);
BOOLEAN
NTAPI
RtlpPageHeapSetUserFlags(PVOID HeapHandle,
ULONG Flags,
PVOID BaseAddress,
ULONG UserFlagsReset,
ULONG UserFlagsSet);
BOOLEAN
NTAPI
RtlpDebugPageHeapValidate(PVOID HeapPtr,
ULONG Flags,
PVOID Block);
SIZE_T NTAPI
RtlpPageHeapSize(HANDLE HeapPtr,
ULONG Flags,
PVOID Ptr);
#endif

View file

@ -14,12 +14,6 @@
#define NDEBUG
#include <debug.h>
BOOLEAN RtlpPageHeapEnabled = FALSE;
ULONG RtlpPageHeapGlobalFlags;
ULONG RtlpPageHeapSizeRangeStart, RtlpPageHeapSizeRangeEnd;
ULONG RtlpPageHeapDllRangeStart, RtlpPageHeapDllRangeEnd;
WCHAR RtlpPageHeapTargetDlls[512];
/* FUNCTIONS ******************************************************************/
HANDLE NTAPI
@ -142,8 +136,8 @@ RtlDebugAllocateHeap(PVOID HeapPtr,
BOOLEAN HeapLocked = FALSE;
PVOID Result;
//if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
//return RtlpPageHeapAllocateHeap(HeapPtr, Flags, Size);
if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
return RtlpPageHeapAllocate(HeapPtr, Flags, Size);
if (Heap->Signature != HEAP_SIGNATURE)
{
@ -209,8 +203,8 @@ RtlDebugReAllocateHeap(HANDLE HeapPtr,
PVOID Result = NULL;
PHEAP_ENTRY HeapEntry;
//if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
//return RtlpPageHeapReAllocateHeap(HeapPtr, Flags, Size);
if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
return RtlpPageHeapReAllocate(HeapPtr, Flags, Ptr, Size);
if (Heap->Signature != HEAP_SIGNATURE)
{
@ -279,8 +273,8 @@ RtlDebugFreeHeap(HANDLE HeapPtr,
PHEAP_ENTRY HeapEntry;
BOOLEAN Result = FALSE;
//if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
//return RtlpPageHeapFreeHeap(HeapPtr, Flags, Size);
if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
return RtlpPageHeapFree(HeapPtr, Flags, Ptr);
if (Heap->Signature != HEAP_SIGNATURE)
{
@ -336,8 +330,8 @@ RtlDebugGetUserInfoHeap(PVOID HeapHandle,
PHEAP_ENTRY HeapEntry;
BOOLEAN Result = FALSE;
//if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
//return RtlpPageHeapGetUserInfoHeap(HeapPtr, Flags, Size);
if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
return RtlpPageHeapGetUserInfo(HeapHandle, Flags, BaseAddress, UserValue, UserFlags);
if (Heap->Signature != HEAP_SIGNATURE)
{
@ -388,8 +382,8 @@ RtlDebugSetUserValueHeap(PVOID HeapHandle,
PHEAP_ENTRY HeapEntry;
BOOLEAN Result = FALSE;
//if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
//return RtlpPageHeapSetUserValueHeap(HeapPtr, Flags, Size);
if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
return RtlpPageHeapSetUserValue(HeapHandle, Flags, BaseAddress, UserValue);
if (Heap->Signature != HEAP_SIGNATURE)
{
@ -445,8 +439,8 @@ RtlDebugSetUserFlagsHeap(PVOID HeapHandle,
PHEAP_ENTRY HeapEntry;
BOOLEAN Result = FALSE;
//if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
//return RtlPageHeapSetUserFlagsHeap(HeapPtr, Flags, BaseAddress, UserFlagsReset, UserFlagsSet);
if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
return RtlpPageHeapSetUserFlags(HeapHandle, Flags, BaseAddress, UserFlagsReset, UserFlagsSet);
/* Check if this heap allows flags to be set at all */
if (UserFlagsSet & ~HEAP_SETTABLE_USER_FLAGS ||
@ -506,8 +500,8 @@ RtlDebugSizeHeap(HANDLE HeapPtr,
PHEAP_ENTRY HeapEntry;
SIZE_T Result = ~(SIZE_T)0;
//if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
//return RtlPageHeapSizeHeap(HeapPtr, Flags, Ptr);
if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
return RtlpPageHeapSize(HeapPtr, Flags, Ptr);
/* Check heap signature */
if (Heap->Signature != HEAP_SIGNATURE)
@ -548,18 +542,4 @@ RtlDebugSizeHeap(HANDLE HeapPtr,
return Result;
}
// Page heap -> move to another file
HANDLE NTAPI
RtlpPageHeapCreate(ULONG Flags,
PVOID Addr,
SIZE_T TotalSize,
SIZE_T CommitSize,
PVOID Lock,
PRTL_HEAP_PARAMETERS Parameters)
{
return NULL;
}
/* EOF */

2295
lib/rtl/heappage.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -226,9 +226,9 @@ RtlInitNlsTables(IN PUSHORT AnsiTableBase,
*/
NTSTATUS NTAPI
RtlMultiByteToUnicodeN(
IN PWCHAR UnicodeString,
OUT PWCHAR UnicodeString,
IN ULONG UnicodeSize,
IN PULONG ResultSize,
OUT PULONG ResultSize,
IN PCSTR MbString,
IN ULONG MbSize)
{
@ -286,7 +286,7 @@ RtlMultiByteToUnicodeN(
*ResultSize = i * sizeof(WCHAR);
}
return(STATUS_SUCCESS);
return STATUS_SUCCESS;
}

View file

@ -3,7 +3,9 @@
* PROJECT: ReactOS system libraries
* FILE: lib/rtl/path.c
* PURPOSE: Path and current directory functions
* PROGRAMMERS:
* PROGRAMMERS: Wine team
* Thomas Weidenmueller
* Gunnar Dalsnes
*/
/* INCLUDES *****************************************************************/
@ -112,30 +114,24 @@ RtlIsDosDeviceName_U(PWSTR dos_name)
if (!_wcsicmp( dos_name, consoleW ))
return MAKELONG( sizeof(conW), 4 * sizeof(WCHAR) ); /* 4 is length of \\.\ prefix */
return 0;
case RtlPathTypeDriveAbsolute:
case RtlPathTypeDriveRelative:
start = dos_name + 2; /* skip drive letter */
break;
default:
start = dos_name;
break;
}
end = dos_name + wcslen(dos_name) - 1;
while (end >= dos_name && *end == ':') end--; /* remove all trailing ':' */
/* find start of file name */
for (start = end; start >= dos_name; start--)
{
if (IS_PATH_SEPARATOR(start[0])) break;
/* check for ':' but ignore if before extension (for things like NUL:.txt) */
if (start[0] == ':' && start[1] != '.') break;
}
start++;
for (p = start; *p; p++) if (IS_PATH_SEPARATOR(*p)) start = p + 1;
/* truncate at extension and ':' */
for (end = start; *end; end++) if (*end == '.' || *end == ':') break;
end--;
/* remove extension */
if ((p = wcschr( start, '.' )))
{
end = p - 1;
if (end >= dos_name && *end == ':') end--; /* remove trailing ':' before extension */
}
/* remove trailing spaces */
while (end >= dos_name && *end == ' ') end--;
while (end >= start && *end == ' ') end--;
/* now we have a potential device name between start and end, check it */
switch(end - start + 1)
@ -218,6 +214,8 @@ RtlSetCurrentDirectory_U(PUNICODE_STRING dir)
DPRINT("RtlSetCurrentDirectory %wZ\n", dir);
full.Buffer = NULL;
RtlAcquirePebLock ();
cd = (PCURDIR)&NtCurrentPeb ()->ProcessParameters->CurrentDirectory.DosPath;
@ -287,16 +285,13 @@ RtlSetCurrentDirectory_U(PUNICODE_STRING dir)
}
/******************************************************************
* collapse_path
* collapse_path
*
* Helper for RtlGetFullPathName_U.
* 1) Convert slashes into backslashes
* 2) Get rid of duplicate backslashes
* 3) Get rid of . and .. components in the path.
* Get rid of . and .. components in the path.
*/
static __inline void collapse_path( WCHAR *path, UINT mark )
void FORCEINLINE collapse_path( WCHAR *path, UINT mark )
{
WCHAR *p, *next;
@ -469,9 +464,11 @@ static ULONG get_full_path_helper(
tmp[1] = ':';
tmp[2] = '\\';
ins_str = tmp;
RtlFreeHeap(RtlGetProcessHeap(), 0, val.Buffer);
break;
default:
DPRINT1("Unsupported status code\n");
RtlFreeHeap(RtlGetProcessHeap(), 0, val.Buffer);
break;
}
mark = 3;
@ -554,7 +551,7 @@ static ULONG get_full_path_helper(
if (reqsize) memcpy(buffer, ins_str, reqsize);
reqsize += deplen;
if (ins_str && ins_str != tmp && ins_str != cd->Buffer)
if (ins_str != tmp && ins_str != cd->Buffer)
RtlFreeHeap(RtlGetProcessHeap(), 0, ins_str);
collapse_path( buffer, mark );
@ -614,10 +611,9 @@ ULONG NTAPI RtlGetFullPathName_U(
if (reqsize > size)
{
LPWSTR tmp = RtlAllocateHeap(RtlGetProcessHeap(), 0, reqsize);
if (tmp == NULL)
return 0;
if (tmp == NULL) return 0;
reqsize = get_full_path_helper(name, tmp, reqsize);
if (reqsize > size) /* it may have worked the second time */
if (reqsize + sizeof(WCHAR) > size) /* it may have worked the second time */
{
RtlFreeHeap(RtlGetProcessHeap(), 0, tmp);
return reqsize + sizeof(WCHAR);
@ -799,77 +795,79 @@ RtlDosPathNameToNtPathName_U(IN PCWSTR DosPathName,
/*
* @implemented
*/
/******************************************************************
* RtlDosSearchPath_U
*
* Searches a file of name 'name' into a ';' separated list of paths
* (stored in paths)
* Doesn't seem to search elsewhere than the paths list
* Stores the result in buffer (file_part will point to the position
* of the file name in the buffer)
* FIXME:
* - how long shall the paths be ??? (MAX_PATH or larger with \\?\ constructs ???)
*/
ULONG
NTAPI
RtlDosSearchPath_U (
PCWSTR sp,
PCWSTR name,
PCWSTR ext,
ULONG buf_sz,
WCHAR *buffer,
PWSTR *FilePart
)
RtlDosSearchPath_U(PCWSTR paths,
PCWSTR search,
PCWSTR ext,
ULONG buffer_size,
PWSTR buffer,
PWSTR* file_part)
{
ULONG Type;
ULONG Length = 0;
PWSTR full_name;
PWSTR wcs;
PCWSTR path;
RTL_PATH_TYPE type = RtlDetermineDosPathNameType_U(search);
ULONG len = 0;
Type = RtlDetermineDosPathNameType_U (name);
if (type == RtlPathTypeRelative)
{
ULONG allocated = 0, needed, filelen;
WCHAR *name = NULL;
if (Type == 5)
{
Length = wcslen (sp);
Length += wcslen (name);
if (wcschr (name, L'.'))
ext = NULL;
if (ext != NULL)
Length += wcslen (ext);
filelen = 1 /* for \ */ + wcslen(search) + 1 /* \0 */;
full_name = (WCHAR*)RtlAllocateHeap (RtlGetProcessHeap (),
0,
(Length + 1) * sizeof(WCHAR));
Length = 0;
if (full_name != NULL)
{
path = sp;
while (*path)
{
wcs = full_name;
while (*path && *path != L';')
*wcs++ = *path++;
if (*path)
path++;
if (wcs != full_name && *(wcs - 1) != L'\\')
*wcs++ = L'\\';
wcscpy (wcs, name);
if (ext)
wcscat (wcs, ext);
if (RtlDoesFileExists_U (full_name))
{
Length = RtlGetFullPathName_U (full_name,
buf_sz,
buffer,
FilePart);
break;
}
}
/* Windows only checks for '.' without worrying about path components */
if (wcschr( search, '.' )) ext = NULL;
if (ext != NULL) filelen += wcslen(ext);
RtlFreeHeap (RtlGetProcessHeap (),
0,
full_name);
}
}
else if (RtlDoesFileExists_U (name))
{
Length = RtlGetFullPathName_U (name,
buf_sz,
buffer,
FilePart);
}
while (*paths)
{
LPCWSTR ptr;
return Length;
for (needed = 0, ptr = paths; *ptr != 0 && *ptr++ != ';'; needed++);
if (needed + filelen > allocated)
{
if (!name) name = RtlAllocateHeap(RtlGetProcessHeap(), 0,
(needed + filelen) * sizeof(WCHAR));
else
{
WCHAR *newname = RtlReAllocateHeap(RtlGetProcessHeap(), 0, name,
(needed + filelen) * sizeof(WCHAR));
if (!newname) RtlFreeHeap(RtlGetProcessHeap(), 0, name);
name = newname;
}
if (!name) return 0;
allocated = needed + filelen;
}
memmove(name, paths, needed * sizeof(WCHAR));
/* append '\\' if none is present */
if (needed > 0 && name[needed - 1] != '\\') name[needed++] = '\\';
wcscpy(&name[needed], search);
if (ext) wcscat(&name[needed], ext);
if (RtlDoesFileExists_U(name))
{
len = RtlGetFullPathName_U(name, buffer_size, buffer, file_part);
break;
}
paths = ptr;
}
RtlFreeHeap(RtlGetProcessHeap(), 0, name);
}
else if (RtlDoesFileExists_U(search))
{
len = RtlGetFullPathName_U(search, buffer_size, buffer, file_part);
}
return len;
}
@ -881,11 +879,10 @@ RtlDoesFileExists_U(IN PCWSTR FileName)
{
UNICODE_STRING NtFileName;
OBJECT_ATTRIBUTES Attr;
FILE_BASIC_INFORMATION Info;
FILE_BASIC_INFORMATION Info;
NTSTATUS Status;
CURDIR CurDir;
if (!RtlDosPathNameToNtPathName_U (FileName,
&NtFileName,
NULL,
@ -905,7 +902,7 @@ RtlDoesFileExists_U(IN PCWSTR FileName)
Status = ZwQueryAttributesFile (&Attr, &Info);
RtlFreeUnicodeString(&NtFileName);
RtlFreeUnicodeString(&NtFileName);
if (NT_SUCCESS(Status) ||

View file

@ -33,13 +33,23 @@ extern USHORT NlsUnicodeDefaultChar;
*/
WCHAR
NTAPI
RtlAnsiCharToUnicodeChar(IN PUCHAR *AnsiChar)
RtlAnsiCharToUnicodeChar(IN OUT PUCHAR *AnsiChar)
{
ULONG Size;
NTSTATUS Status;
WCHAR UnicodeChar = L' ';
Size = (NlsLeadByteInfo[**AnsiChar] == 0) ? 1 : 2;
PAGED_CODE_RTL();
if (NlsLeadByteInfo)
{
Size = (NlsLeadByteInfo[**AnsiChar] == 0) ? 1 : 2;
}
else
{
DPRINT("HACK::Shouldn't have happened! Consider fixing Usetup and registry entries it creates on install\n");
Size = 1;
}
Status = RtlMultiByteToUnicodeN(&UnicodeChar,
sizeof(WCHAR),