ReactOS.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
List overview
Download
Ros-diffs
July 2011
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
24 participants
517 discussions
Start a n
N
ew thread
[ion] 52603: [NTDLL]: More fixes to the PE parsing code. [NTDLL]: Move and fix LdrUnloadDll to ldrapi.c [NTDLL]: Remove yet another cruft file.
by ion@svn.reactos.org
Author: ion Date: Sun Jul 10 13:23:19 2011 New Revision: 52603 URL:
http://svn.reactos.org/svn/reactos?rev=52603&view=rev
Log: [NTDLL]: More fixes to the PE parsing code. [NTDLL]: Move and fix LdrUnloadDll to ldrapi.c [NTDLL]: Remove yet another cruft file. Modified: trunk/reactos/dll/ntdll/include/ntdllp.h trunk/reactos/dll/ntdll/ldr/ldrapi.c trunk/reactos/dll/ntdll/ldr/ldrpe.c trunk/reactos/dll/ntdll/ldr/ldrutils.c trunk/reactos/dll/ntdll/ntdll.rbuild Modified: trunk/reactos/dll/ntdll/include/ntdllp.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/include/ntdllp.h…
============================================================================== --- trunk/reactos/dll/ntdll/include/ntdllp.h [iso-8859-1] (original) +++ trunk/reactos/dll/ntdll/include/ntdllp.h [iso-8859-1] Sun Jul 10 13:23:19 2011 @@ -9,6 +9,7 @@ /* INCLUDES ******************************************************************/ #define LDR_HASH_TABLE_ENTRIES 32 +#define LDR_GET_HASH_ENTRY(x) (RtlUpcaseUnicodeChar((x)) & (LDR_HASH_TABLE_ENTRIES - 1)) /* LdrpUpdateLoadCount2 flags */ #define LDRP_UPDATE_REFCOUNT 0x01 @@ -41,7 +42,7 @@ extern ULONG LdrpActiveUnloadCount; extern BOOLEAN LdrpShutdownInProgress; extern UNICODE_STRING LdrpKnownDllPath; -extern PLDR_DATA_TABLE_ENTRY LdrpGetModuleHandleCache; +extern PLDR_DATA_TABLE_ENTRY LdrpGetModuleHandleCache, LdrpLoadedDllHandleCache; /* ldrinit.c */ NTSTATUS NTAPI LdrpRunInitializeRoutines(IN PCONTEXT Context OPTIONAL); @@ -153,6 +154,10 @@ OUT PLDR_DATA_TABLE_ENTRY *DataTableEntry, OUT PBOOLEAN Existing); +VOID +NTAPI +LdrpFinalizeAndDeallocateDataTableEntry(IN PLDR_DATA_TABLE_ENTRY Entry); + extern HANDLE WindowsApiPort; /* EOF */ Modified: trunk/reactos/dll/ntdll/ldr/ldrapi.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/ldrapi.c?rev…
============================================================================== --- trunk/reactos/dll/ntdll/ldr/ldrapi.c [iso-8859-1] (original) +++ trunk/reactos/dll/ntdll/ldr/ldrapi.c [iso-8859-1] Sun Jul 10 13:23:19 2011 @@ -15,6 +15,7 @@ /* GLOBALS *******************************************************************/ +LIST_ENTRY LdrpUnloadHead; LONG LdrpLoaderLockAcquisitonCount; BOOLEAN LdrpShowRecursiveLoads, LdrpBreakOnRecursiveDllLoads; UNICODE_STRING LdrApiDefaultExtension = RTL_CONSTANT_STRING(L".DLL"); @@ -1044,9 +1045,14 @@ return LdrQueryProcessModuleInformationEx(0, 0, ModuleInformation, Size, ReturnedSize); } +/* + * @implemented + */ NTSTATUS NTAPI -LdrEnumerateLoadedModules(BOOLEAN ReservedFlag, PLDR_ENUM_CALLBACK EnumProc, PVOID Context) +LdrEnumerateLoadedModules(IN BOOLEAN ReservedFlag, + IN PLDR_ENUM_CALLBACK EnumProc, + IN PVOID Context) { PLIST_ENTRY ListHead, ListEntry; PLDR_DATA_TABLE_ENTRY LdrEntry; @@ -1244,6 +1250,270 @@ /* * @implemented */ +NTSTATUS +NTAPI +LdrUnloadDll(IN PVOID BaseAddress) +{ + NTSTATUS Status = STATUS_SUCCESS; + PPEB Peb = NtCurrentPeb(); + PLDR_DATA_TABLE_ENTRY LdrEntry, CurrentEntry; + PVOID EntryPoint; + PLIST_ENTRY NextEntry; + LIST_ENTRY UnloadList; + RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED ActCtx; + PVOID CorImageData; + ULONG ComSectionSize; + + /* Get the LDR Lock */ + if (!LdrpInLdrInit) RtlEnterCriticalSection(Peb->LoaderLock); + + /* Increase the unload count */ + LdrpActiveUnloadCount++; + + /* Skip unload */ + if (LdrpShutdownInProgress) goto Quickie; + + /* Make sure the DLL is valid and get its entry */ + if (!LdrpCheckForLoadedDllHandle(BaseAddress, &LdrEntry)) + { + Status = STATUS_DLL_NOT_FOUND; + goto Quickie; + } + + /* Check the current Load Count */ + if (LdrEntry->LoadCount != -1) + { + /* Decrease it */ + LdrEntry->LoadCount--; + + /* If it's a dll */ + if (LdrEntry->Flags & LDRP_IMAGE_DLL) + { + /* Set up the Act Ctx */ + ActCtx.Size = sizeof(ActCtx); + ActCtx.Format = RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_FORMAT_WHISTLER; + RtlZeroMemory(&ActCtx.Frame, sizeof(ActCtx)); + + /* Activate the ActCtx */ + RtlActivateActivationContextUnsafeFast(&ActCtx, + LdrEntry->EntryPointActivationContext); + + /* Update the load count */ + LdrpUpdateLoadCount2(LdrEntry, LDRP_UPDATE_DEREFCOUNT); + + /* Release the context */ + RtlDeactivateActivationContextUnsafeFast(&ActCtx); + } + } + else + { + /* The DLL is locked */ + goto Quickie; + } + + /* Show debug message */ + if (ShowSnaps) DPRINT1("LDR: UNINIT LIST\n"); + + /* Check if this is our only unload and initialize the list if so */ + if (LdrpActiveUnloadCount == 1) InitializeListHead(&LdrpUnloadHead); + + /* Loop the modules to build the list */ + NextEntry = Peb->Ldr->InInitializationOrderModuleList.Blink; + while (NextEntry != &Peb->Ldr->InInitializationOrderModuleList) + { + /* Get the entry */ + LdrEntry = CONTAINING_RECORD(NextEntry, + LDR_DATA_TABLE_ENTRY, + InInitializationOrderModuleList); + NextEntry = NextEntry->Blink; + + /* Remove flag */ + LdrEntry->Flags &= ~LDRP_UNLOAD_IN_PROGRESS; + + /* If the load count is now 0 */ + if (!LdrEntry->LoadCount) + { + /* Show message */ + if (ShowSnaps) + { + DPRINT1("(%d) [%ws] %ws (%lx) deinit %lx\n", + LdrpActiveUnloadCount, + LdrEntry->BaseDllName.Buffer, + LdrEntry->FullDllName.Buffer, + (ULONG)LdrEntry->LoadCount, + LdrEntry->EntryPoint); + } + + /* FIXME: Call Shim Engine and notify */ + + /* Unlink it */ + CurrentEntry = LdrEntry; + RemoveEntryList(&CurrentEntry->InInitializationOrderModuleList); + RemoveEntryList(&CurrentEntry->InMemoryOrderModuleList); + RemoveEntryList(&CurrentEntry->HashLinks); + + /* If there's more then one active unload */ + if (LdrpActiveUnloadCount > 1) + { + /* Flush the cached DLL handle and clear the list */ + LdrpLoadedDllHandleCache = NULL; + CurrentEntry->InMemoryOrderModuleList.Flink = NULL; + } + + /* Add the entry on the unload list */ + InsertTailList(&LdrpUnloadHead, &CurrentEntry->HashLinks); + } + } + + /* Only call the entrypoints once */ + if (LdrpActiveUnloadCount > 1) goto Quickie; + + /* Now loop the unload list and create our own */ + InitializeListHead(&UnloadList); + CurrentEntry = NULL; + NextEntry = LdrpUnloadHead.Flink; + while (NextEntry != &LdrpUnloadHead) + { + /* If we have an active entry */ + if (CurrentEntry) + { + /* Remove it */ + RemoveEntryList(&CurrentEntry->InLoadOrderLinks); + CurrentEntry = NULL; + + /* Reset list pointers */ + NextEntry = LdrpUnloadHead.Flink; + if (NextEntry == &LdrpUnloadHead) break; + } + + /* Get the current entry */ + LdrEntry = CONTAINING_RECORD(NextEntry, LDR_DATA_TABLE_ENTRY, HashLinks); + + /* FIXME: Log the Unload Event */ + //LdrpRecordUnloadEvent(LdrEntry); + + /* Set the entry and clear it from the list */ + CurrentEntry = LdrEntry; + LdrpLoadedDllHandleCache = NULL; + CurrentEntry->InMemoryOrderModuleList.Flink = NULL; + + /* Move it from the global to the local list */ + RemoveEntryList(&CurrentEntry->HashLinks); + InsertTailList(&UnloadList, &CurrentEntry->HashLinks); + + /* Get the entrypoint */ + EntryPoint = LdrEntry->EntryPoint; + + /* Check if we should call it */ + if ((EntryPoint) && (LdrEntry->Flags & LDRP_PROCESS_ATTACH_CALLED)) + { + /* Show message */ + if (ShowSnaps) + { + DPRINT1("LDR: Calling deinit %lx\n", EntryPoint); + } + + /* Set up the Act Ctx */ + ActCtx.Size = sizeof(ActCtx); + ActCtx.Format = RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_FORMAT_WHISTLER; + RtlZeroMemory(&ActCtx.Frame, sizeof(ActCtx)); + + /* Activate the ActCtx */ + RtlActivateActivationContextUnsafeFast(&ActCtx, + LdrEntry->EntryPointActivationContext); + + /* Call the entrypoint */ + LdrpCallInitRoutine(LdrEntry->EntryPoint, + LdrEntry->DllBase, + DLL_PROCESS_DETACH, + NULL); + + /* Release the context */ + RtlDeactivateActivationContextUnsafeFast(&ActCtx); + } + + /* Remove it from the list */ + RemoveEntryList(&CurrentEntry->InLoadOrderLinks); + CurrentEntry = NULL; + NextEntry = LdrpUnloadHead.Flink; + } + + /* Now loop our local list */ + NextEntry = UnloadList.Flink; + while (NextEntry != &UnloadList) + { + /* Get the entry */ + LdrEntry = CONTAINING_RECORD(NextEntry, LDR_DATA_TABLE_ENTRY, HashLinks); + NextEntry = NextEntry->Flink; + CurrentEntry = LdrEntry; + + /* Notify Application Verifier */ + if (Peb->NtGlobalFlag & FLG_HEAP_ENABLE_TAIL_CHECK) + { + DPRINT1("We don't support Application Verifier yet\n"); + } + + /* Show message */ + if (ShowSnaps) + { + DPRINT1("LDR: Unmapping [%ws]\n", LdrEntry->BaseDllName.Buffer); + } + + /* Check if this is a .NET executable */ + CorImageData = RtlImageDirectoryEntryToData(LdrEntry->DllBase, + TRUE, + IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR, + &ComSectionSize); + if (CorImageData) + { + /* FIXME */ + DPRINT1(".NET Images are not supported yet\n"); + } + + /* Check if we should unmap*/ + if (!(CurrentEntry->Flags & LDR_COR_OWNS_UNMAP)) + { + /* Unmap the DLL */ + Status = NtUnmapViewOfSection(NtCurrentProcess(), + CurrentEntry->DllBase); + ASSERT(NT_SUCCESS(Status)); + } + + /* Unload the alternate resource module, if any */ + LdrUnloadAlternateResourceModule(CurrentEntry->DllBase); + + /* FIXME: Send shutdown notification */ + //LdrpSendDllNotifications(CurrentEntry, 2, LdrpShutdownInProgress); + + /* Check if a Hotpatch is active */ + if (LdrEntry->PatchInformation) + { + /* FIXME */ + DPRINT1("We don't support Hotpatching yet\n"); + } + + /* Deallocate the Entry */ + LdrpFinalizeAndDeallocateDataTableEntry(CurrentEntry); + + /* If this is the cached entry, invalidate it */ + if (LdrpGetModuleHandleCache == CurrentEntry) + { + LdrpGetModuleHandleCache = NULL; + } + } + +Quickie: + /* Decrease unload count */ + LdrpActiveUnloadCount--; + if (!LdrpInLdrInit) RtlLeaveCriticalSection(Peb->LoaderLock); + + /* Return to caller */ + return Status; +} + +/* + * @implemented + */ BOOLEAN NTAPI RtlDllShutdownInProgress(VOID) Modified: trunk/reactos/dll/ntdll/ldr/ldrpe.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/ldrpe.c?rev=…
============================================================================== --- trunk/reactos/dll/ntdll/ldr/ldrpe.c [iso-8859-1] (original) +++ trunk/reactos/dll/ntdll/ldr/ldrpe.c [iso-8859-1] Sun Jul 10 13:23:19 2011 @@ -27,21 +27,15 @@ IN PIMAGE_IMPORT_DESCRIPTOR IatEntry, IN BOOLEAN EntriesValid) { - PIMAGE_EXPORT_DIRECTORY ExportDirectory; - ULONG ExportSize; PVOID Iat; - SIZE_T ImportSize; - ULONG IatSize; - //PPEB Peb = NtCurrentPeb(); NTSTATUS Status; PIMAGE_THUNK_DATA OriginalThunk, FirstThunk; - LPSTR ImportName; - ULONG ForwarderChain; PIMAGE_NT_HEADERS NtHeader; PIMAGE_SECTION_HEADER SectionHeader; - ULONG i, Rva; - ULONG OldProtect; - + PIMAGE_EXPORT_DIRECTORY ExportDirectory; + LPSTR ImportName; + ULONG ForwarderChain, i, Rva, OldProtect, IatSize, ExportSize; + SIZE_T ImportSize; DPRINT("LdrpSnapIAT(%wZ %wZ %p %d)\n", &ExportLdrEntry->BaseDllName, &ImportLdrEntry->BaseDllName, IatEntry, EntriesValid); /* Get export directory */ @@ -51,7 +45,13 @@ &ExportSize); /* Make sure it has one */ - if (!ExportDirectory) return STATUS_INVALID_IMAGE_FORMAT; + if (!ExportDirectory) + { + /* Fail */ + DbgPrint("LDR: %wZ doesn't contain an EXPORT table\n", + &ExportLdrEntry->BaseDllName); + return STATUS_INVALID_IMAGE_FORMAT; + } /* Get the IAT */ Iat = RtlImageDirectoryEntryToData(ImportLdrEntry->DllBase, @@ -65,6 +65,7 @@ { /* Get the NT Header and the first section */ NtHeader = RtlImageNtHeader(ImportLdrEntry->DllBase); + if (!NtHeader) return STATUS_INVALID_IMAGE_FORMAT; SectionHeader = IMAGE_FIRST_SECTION(NtHeader); /* Get the RVA of the import directory */ @@ -89,8 +90,7 @@ IatSize = SectionHeader->Misc.VirtualSize; /* Deal with Watcom and other retarded compilers */ - if (!IatSize) - IatSize = SectionHeader->SizeOfRawData; + if (!IatSize) IatSize = SectionHeader->SizeOfRawData; /* Found it, get out */ break; @@ -102,7 +102,14 @@ } /* If we still don't have an IAT, that's bad */ - if (!Iat) return STATUS_INVALID_IMAGE_FORMAT; + if (!Iat) + { + /* Fail */ + DbgPrint("LDR: Unable to unprotect IAT for %wZ (Image Base %p)\n", + &ImportLdrEntry->BaseDllName, + ImportLdrEntry->DllBase); + return STATUS_INVALID_IMAGE_FORMAT; + } /* Set the right size */ ImportSize = IatSize; @@ -114,7 +121,14 @@ &ImportSize, PAGE_READWRITE, &OldProtect); - if (!NT_SUCCESS(Status)) return Status; + if (!NT_SUCCESS(Status)) + { + /* Fail */ + DbgPrint("LDR: Unable to unprotect IAT for %wZ (Status %x)\n", + &ImportLdrEntry->BaseDllName, + Status); + return Status; + } /* Check if the Thunks are already valid */ if (EntriesValid) @@ -400,6 +414,7 @@ if (Stale) { /* It was, so find the IAT entry for it */ + ++LdrpNormalSnap; ImportEntry = RtlImageDirectoryEntryToData(LdrEntry->DllBase, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, Modified: trunk/reactos/dll/ntdll/ldr/ldrutils.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/ldrutils.c?r…
============================================================================== --- trunk/reactos/dll/ntdll/ldr/ldrutils.c [iso-8859-1] (original) +++ trunk/reactos/dll/ntdll/ldr/ldrutils.c [iso-8859-1] Sun Jul 10 13:23:19 2011 @@ -15,10 +15,7 @@ /* GLOBALS *******************************************************************/ -LIST_ENTRY LdrpUnloadHead; PLDR_DATA_TABLE_ENTRY LdrpLoadedDllHandleCache, LdrpGetModuleHandleCache; - -#define LDR_GET_HASH_ENTRY(x) (RtlUpcaseUnicodeChar((x)) & (LDR_HASH_TABLE_ENTRIES - 1)) /* FUNCTIONS *****************************************************************/ @@ -283,35 +280,39 @@ /* Protect against invalid pointers */ _SEH2_TRY { - /* Make sure it's valid and we have an array */ - Array = (PIMAGE_TLS_CALLBACK *)TlsDirectory->AddressOfCallBacks; - if ((TlsDirectory) && (Array)) - { - /* Display debug */ - if (ShowSnaps) - { - DPRINT1("LDR: Tls Callbacks Found. Imagebase %p Tls %p CallBacks %p\n", - BaseAddress, TlsDirectory, Array); - } - - /* Loop the array */ - while (*Array) - { - /* Get the TLS Entrypoint */ - Callback = *Array++; - + /* Make sure it's valid */ + if (TlsDirectory) + { + /* Get the array */ + Array = (PIMAGE_TLS_CALLBACK *)TlsDirectory->AddressOfCallBacks; + if (Array) + { /* Display debug */ if (ShowSnaps) { - DPRINT1("LDR: Calling Tls Callback Imagebase %p Function %p\n", - BaseAddress, Callback); + DPRINT1("LDR: Tls Callbacks Found. Imagebase %p Tls %p CallBacks %p\n", + BaseAddress, TlsDirectory, Array); } - /* Call it */ - LdrpCallInitRoutine((PDLL_INIT_ROUTINE)Callback, - BaseAddress, - Reason, - NULL); + /* Loop the array */ + while (*Array) + { + /* Get the TLS Entrypoint */ + Callback = *Array++; + + /* Display debug */ + if (ShowSnaps) + { + DPRINT1("LDR: Calling Tls Callback Imagebase %p Function %p\n", + BaseAddress, Callback); + } + + /* Call it */ + LdrpCallInitRoutine((PDLL_INIT_ROUTINE)Callback, + BaseAddress, + Reason, + NULL); + } } } } @@ -2050,272 +2051,6 @@ return Status; } -/* - * @implemented - */ -NTSTATUS -NTAPI -LdrUnloadDll(IN PVOID BaseAddress) -{ - NTSTATUS Status = STATUS_SUCCESS; - PPEB Peb = NtCurrentPeb(); - PLDR_DATA_TABLE_ENTRY LdrEntry, CurrentEntry; - PVOID EntryPoint; - PLIST_ENTRY NextEntry; - LIST_ENTRY UnloadList; - RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED ActCtx; - PVOID CorImageData; - ULONG ComSectionSize; - - /* Get the LDR Lock */ - if (!LdrpInLdrInit) RtlEnterCriticalSection(Peb->LoaderLock); - - /* Increase the unload count */ - LdrpActiveUnloadCount++; - - /* Skip unload */ - if (LdrpShutdownInProgress) goto Quickie; - - /* Make sure the DLL is valid and get its entry */ - if (!LdrpCheckForLoadedDllHandle(BaseAddress, &LdrEntry)) - { - Status = STATUS_DLL_NOT_FOUND; - goto Quickie; - } - - /* Check the current Load Count */ - if (LdrEntry->LoadCount != 0xFFFF) - { - /* Decrease it */ - LdrEntry->LoadCount--; - - /* If it's a dll */ - if (LdrEntry->Flags & LDRP_IMAGE_DLL) - { - /* Set up the Act Ctx */ - ActCtx.Size = sizeof(ActCtx); - ActCtx.Format = 1; - RtlZeroMemory(&ActCtx.Frame, sizeof(RTL_ACTIVATION_CONTEXT_STACK_FRAME)); - - /* Activate the ActCtx */ - RtlActivateActivationContextUnsafeFast(&ActCtx, - LdrEntry->EntryPointActivationContext); - - /* Update the load count */ - LdrpUpdateLoadCount2(LdrEntry, LDRP_UPDATE_DEREFCOUNT); - - /* Release the context */ - RtlDeactivateActivationContextUnsafeFast(&ActCtx); - } - } - else - { - /* The DLL is locked */ - goto Quickie; - } - - /* Show debug message */ - if (ShowSnaps) DPRINT1("LDR: UNINIT LIST\n"); - - /* Check if this is our only unload */ - if (LdrpActiveUnloadCount == 1) - { - /* Initialize the unload list */ - InitializeListHead(&LdrpUnloadHead); - } - - /* Loop the modules to build the list */ - NextEntry = Peb->Ldr->InInitializationOrderModuleList.Blink; - while (NextEntry != &Peb->Ldr->InInitializationOrderModuleList) - { - /* Get the entry */ - LdrEntry = CONTAINING_RECORD(NextEntry, LDR_DATA_TABLE_ENTRY, InInitializationOrderModuleList); - NextEntry = NextEntry->Blink; - - /* Remove flag */ - LdrEntry->Flags &= ~LDRP_UNLOAD_IN_PROGRESS; - - /* If the load count is now 0 */ - if (!LdrEntry->LoadCount) - { - /* Show message */ - if (ShowSnaps) - { - DPRINT1("(%d) [%ws] %ws (%lx) deinit %lx\n", - LdrpActiveUnloadCount, - LdrEntry->BaseDllName.Buffer, - LdrEntry->FullDllName.Buffer, - (ULONG)LdrEntry->LoadCount, - LdrEntry->EntryPoint); - } - - /* FIXME: Call Shim Engine and notify */ - - /* Unlink it */ - CurrentEntry = LdrEntry; - RemoveEntryList(&CurrentEntry->InInitializationOrderModuleList); - RemoveEntryList(&CurrentEntry->InMemoryOrderModuleList); - RemoveEntryList(&CurrentEntry->HashLinks); - - /* If there's more then one active unload */ - if (LdrpActiveUnloadCount > 1) - { - /* Flush the cached DLL handle and clear the list */ - LdrpLoadedDllHandleCache = NULL; - CurrentEntry->InMemoryOrderModuleList.Flink = NULL; - } - - /* Add the entry on the unload list */ - InsertTailList(&LdrpUnloadHead, &CurrentEntry->HashLinks); - } - } - - /* Only call the entrypoints once */ - if (LdrpActiveUnloadCount > 1) goto Quickie; - - /* Now loop the unload list and create our own */ - InitializeListHead(&UnloadList); - CurrentEntry = NULL; - NextEntry = LdrpUnloadHead.Flink; - while (NextEntry != &LdrpUnloadHead) - { - /* If we have an active entry */ - if (CurrentEntry) - { - /* Remove it */ - RemoveEntryList(&CurrentEntry->InLoadOrderLinks); - CurrentEntry = NULL; - - /* Reset list pointers */ - NextEntry = LdrpUnloadHead.Flink; - if (NextEntry == &LdrpUnloadHead) break; - } - - /* Get the current entry */ - LdrEntry = CONTAINING_RECORD(NextEntry, LDR_DATA_TABLE_ENTRY, HashLinks); - - /* Log the Unload Event */ - //LdrpRecordUnloadEvent(LdrEntry); - - /* Set the entry and clear it from the list */ - CurrentEntry = LdrEntry; - LdrpLoadedDllHandleCache = NULL; - CurrentEntry->InMemoryOrderModuleList.Flink = NULL; - - /* Move it from the global to the local list */ - RemoveEntryList(&CurrentEntry->HashLinks); - InsertTailList(&UnloadList, &CurrentEntry->HashLinks); - - /* Get the entrypoint */ - EntryPoint = LdrEntry->EntryPoint; - - /* Check if we should call it */ - if (EntryPoint && (LdrEntry->Flags & LDRP_PROCESS_ATTACH_CALLED)) - { - /* Show message */ - if (ShowSnaps) - { - DPRINT1("LDR: Calling deinit %lx\n", EntryPoint); - } - - /* Set up the Act Ctx */ - ActCtx.Size = sizeof(ActCtx); - ActCtx.Format = 1; - RtlZeroMemory(&ActCtx.Frame, sizeof(RTL_ACTIVATION_CONTEXT_STACK_FRAME)); - - /* Activate the ActCtx */ - RtlActivateActivationContextUnsafeFast(&ActCtx, - LdrEntry->EntryPointActivationContext); - - /* Call the entrypoint */ - LdrpCallInitRoutine(LdrEntry->EntryPoint, - LdrEntry->DllBase, - DLL_PROCESS_DETACH, - NULL); - - /* Release the context */ - RtlDeactivateActivationContextUnsafeFast(&ActCtx); - } - - /* Remove it from the list */ - RemoveEntryList(&CurrentEntry->InLoadOrderLinks); - CurrentEntry = NULL; - NextEntry = LdrpUnloadHead.Flink; - } - - /* Now loop our local list */ - NextEntry = UnloadList.Flink; - while (NextEntry != &UnloadList) - { - /* Get the entry */ - LdrEntry = CONTAINING_RECORD(NextEntry, LDR_DATA_TABLE_ENTRY, HashLinks); - NextEntry = NextEntry->Flink; - CurrentEntry = LdrEntry; - - /* Notify Application Verifier */ - if (Peb->NtGlobalFlag & FLG_HEAP_ENABLE_TAIL_CHECK) - { - DPRINT1("We don't support Application Verifier yet\n"); - } - - /* Show message */ - if (ShowSnaps) - { - DPRINT1("LDR: Unmapping [%ws]\n", LdrEntry->BaseDllName.Buffer); - } - - /* Check if this is a .NET executable */ - if ((CorImageData = RtlImageDirectoryEntryToData(LdrEntry->DllBase, - TRUE, - IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR, - &ComSectionSize))) - { - /* FIXME */ - DPRINT1(".NET Images are not supported yet\n"); - } - - /* Check if we should unmap*/ - if (!(CurrentEntry->Flags & LDR_COR_OWNS_UNMAP)) - { - /* Unmap the DLL */ - Status = NtUnmapViewOfSection(NtCurrentProcess(), - CurrentEntry->DllBase); - } - - /* Unload the alternate resource module, if any */ - LdrUnloadAlternateResourceModule(CurrentEntry->DllBase); - - /* Send shutdown notification */ - //LdrpSendDllNotifications(CurrentEntry, 2, LdrpShutdownInProgress); - - /* Check if a Hotpatch is active */ - if (LdrEntry->PatchInformation) - { - /* FIXME */ - DPRINT1("We don't support Hotpatching yet\n"); - } - - /* Deallocate the Entry */ - LdrpFinalizeAndDeallocateDataTableEntry(CurrentEntry); - - /* If this is the cached entry, invalide it */ - if (LdrpGetModuleHandleCache == CurrentEntry) - { - LdrpGetModuleHandleCache = NULL; - } - } - -Quickie: - /* Decrease unload count */ - LdrpActiveUnloadCount--; - if (!LdrpInLdrInit) RtlLeaveCriticalSection(Peb->LoaderLock); - - /* FIXME: Rundown the Hotpatch data, if present */ - - /* Return to caller */ - return Status; -} - ULONG NTAPI LdrpClearLoadInProgress(VOID) Modified: trunk/reactos/dll/ntdll/ntdll.rbuild URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ntdll.rbuild?rev…
============================================================================== --- trunk/reactos/dll/ntdll/ntdll.rbuild [iso-8859-1] (original) +++ trunk/reactos/dll/ntdll/ntdll.rbuild [iso-8859-1] Sun Jul 10 13:23:19 2011 @@ -51,7 +51,6 @@ <file>ldrinit.c</file> <file>ldrpe.c</file> <file>ldrutils.c</file> - <file>actctx.c</file> </directory> <directory name="rtl"> <file>libsupp.c</file>
13 years, 5 months
1
0
0
0
[nyadav] 52602: [AUDSRV] Fix some Thread Synchronization bugs and some style fixes
by nyadav@svn.reactos.org
Author: nyadav Date: Sun Jul 10 12:55:38 2011 New Revision: 52602 URL:
http://svn.reactos.org/svn/reactos?rev=52602&view=rev
Log: [AUDSRV] Fix some Thread Synchronization bugs and some style fixes Modified: branches/nyadav-audio-branch/base/services/audsrv/audsrv.h branches/nyadav-audio-branch/base/services/audsrv/mixer.c branches/nyadav-audio-branch/base/services/audsrv/stream.c branches/nyadav-audio-branch/dll/win32/audsrvapi/audsrvapi.c branches/nyadav-audio-branch/include/reactos/libs/audsrv/audsrvapi.h Modified: branches/nyadav-audio-branch/base/services/audsrv/audsrv.h URL:
http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/base/servic…
============================================================================== --- branches/nyadav-audio-branch/base/services/audsrv/audsrv.h [iso-8859-1] (original) +++ branches/nyadav-audio-branch/base/services/audsrv/audsrv.h [iso-8859-1] Sun Jul 10 12:55:38 2011 @@ -55,9 +55,10 @@ PVOID minsamplevalue; PVOID maxsamplevalue; - HANDLE played; + HANDLE stream_played_event; HANDLE threadready; HANDLE thread; + CRITICAL_SECTION CriticalSection; struct ServerStream * next; } ServerStream; Modified: branches/nyadav-audio-branch/base/services/audsrv/mixer.c URL:
http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/base/servic…
============================================================================== --- branches/nyadav-audio-branch/base/services/audsrv/mixer.c [iso-8859-1] (original) +++ branches/nyadav-audio-branch/base/services/audsrv/mixer.c [iso-8859-1] Sun Jul 10 12:55:38 2011 @@ -13,6 +13,9 @@ { return NULL; } + +/*Filter Should ensure that sample data is divided equally on both side of Analog-Zero Sample value[0 for signed data,maxattainablevalue/2 for unsigned]*/ + void * MixS16(MixerEngine * mixer, int buffer) { @@ -41,15 +44,24 @@ /*Perform Actual Mixing*/ stream = mixer->serverstreamlist; - minsamplevalue = *(short *) stream->minsamplevalue; - maxsamplevalue = *(short *) stream->maxsamplevalue; + minsamplevalue = 0; + maxsamplevalue = 0; while( stream != NULL) { - localsrcbuf = stream->filteredbuf; - if(stream->ready == TRUE ) + EnterCriticalSection(&(stream->CriticalSection)); + + if(stream->ready == TRUE && *(short *) stream->minsamplevalue != 0 && *(short *) stream->minsamplevalue != 0) { coefficient = 1.0; + + localsrcbuf = stream->filteredbuf; + + if(minsamplevalue == 0) + minsamplevalue = *(short *) stream->minsamplevalue; + + if(maxsamplevalue == 0) + maxsamplevalue = *(short *) stream->maxsamplevalue; if( *(short *)stream->maxsamplevalue != maxsamplevalue || *(short *)stream->minsamplevalue != minsamplevalue ) @@ -60,12 +72,20 @@ else coefficient = (float) minsamplevalue / (float)*(short *)stream->minsamplevalue; } + for(i=0;i<stream->length_filtered/sizeof(short);i++) { localsinkbuf[i] = (short) (( (localsinkbuf[i] * streamcount) + ((short)((float) localsrcbuf[i] ) * coefficient) ) / (streamcount +1)); } + } //stream->ready = 0; /*TODO Enable it when actual filter thread starts working*/ + //HeapFree(GetProcessHeap(), + // 0, + // stream->filteredbuf); + SetEvent(stream->stream_played_event); + LeaveCriticalSection(&(stream->CriticalSection)); + streamcount++; stream = stream->next; } Modified: branches/nyadav-audio-branch/base/services/audsrv/stream.c URL:
http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/base/servic…
============================================================================== --- branches/nyadav-audio-branch/base/services/audsrv/stream.c [iso-8859-1] (original) +++ branches/nyadav-audio-branch/base/services/audsrv/stream.c [iso-8859-1] Sun Jul 10 12:55:38 2011 @@ -12,7 +12,7 @@ long GetNewStreamID() { long streamid= pengine->streamidpool; - pengine->streamidpool+=1; + pengine->streamidpool += 1; return streamid; } @@ -23,11 +23,11 @@ /*UGLY HACK--WILL be removed soon-- fill filtered buffer (1 second duration in the master stream format) directly until we are in a condition to get buffer directly from the client*/ /******************************************************/ - BOOL initmin=FALSE,initmax =FALSE; - short minimum=0,maximum=0; + BOOL initmin=FALSE,initmax = FALSE; + short minimum=0,maximum = 0; PSHORT tempbuf; - localstream->ready =TRUE; + localstream->length_filtered = localstream->freq * localstream->channels * localstream->bitspersample / 8; tempbuf = (PSHORT) HeapAlloc(GetProcessHeap(), 0, @@ -35,12 +35,12 @@ while (i < localstream->length_filtered / 2) { - tempbuf[i] = 0x7FFF * sin(0.5 * (i - 1) * 500 * 6.28 / 48000); + tempbuf[i] = 0x7FFF * sin(0.5 * i * 500 * 6.28 / 48000); if((localstream->streamid %2) == 0) - tempbuf[i] = 0; - - if(initmin) + tempbuf[i] = 0x7FFF * sin(0.5 * i * 500 * 6.28 / 24000); + + if(initmin) { if(tempbuf[i]<minimum) minimum = tempbuf[i]; @@ -60,10 +60,10 @@ } i++; - tempbuf[i] = 0x7FFF * sin(0.5 * (i - 2) * 500 * 6.28 / 48000); - - if((localstream->streamid %2) != 0) - tempbuf[i] = 0; + tempbuf[i] = 0x7FFF * sin(0.5 * i * 500 * 6.28 / 48000); + + if((localstream->streamid %2) == 0) + tempbuf[i] = 0x7FFF * sin(0.5 * i * 500 * 6.28 / 24000); if(initmin) @@ -86,13 +86,21 @@ *((int *)localstream->minsamplevalue) = minimum; *((int *)localstream->maxsamplevalue) = maximum; localstream->filteredbuf = tempbuf; + localstream->ready =TRUE; + /******************************************************/ +/*Do Some Initialization If needed.Only After these Initialization remaining system will be told that stream is ready*/ SetEvent(localstream->threadready); - while (1) - { - OutputDebugStringA("Stream Thread Running."); - Sleep(100); + while (TRUE) + { + /*Wait For Data Write Event,currently NO Wait considering Data has always been written*/ + + EnterCriticalSection(&(localstream->CriticalSection)); + + LeaveCriticalSection(&(localstream->CriticalSection)); + /*Wait For Stream Played Event*/ + WaitForSingleObject(localstream->stream_played_event,INFINITE); } /*Clean Stream's data*/ } @@ -164,7 +172,7 @@ newstream->next = NULL; - newstream->played = CreateEvent(NULL, + newstream->stream_played_event = CreateEvent(NULL, FALSE, FALSE, NULL); @@ -174,7 +182,13 @@ FALSE, NULL); - if(newstream->played == NULL || newstream->threadready == NULL) + if(newstream->stream_played_event == NULL || newstream->threadready == NULL) + goto error; + + newstream->streamid=GetNewStreamID(); + + if (!InitializeCriticalSectionAndSpinCount(&(newstream->CriticalSection), + 0x00000400) ) goto error; newstream->thread=CreateThread(NULL, @@ -187,11 +201,10 @@ if(newstream->thread == NULL) goto error; - WaitForSingleObject(newstream->threadready, INFINITE); - newstream->streamid=GetNewStreamID(); + if(localstream == NULL) { @@ -212,8 +225,11 @@ return newstream->streamid; error: - HeapFree(GetProcessHeap(), 0, newstream); + HeapFree(GetProcessHeap(), + 0, + newstream); return 0; } -/*Dont forget to clean ServerStream's minsamplevalue and maxsamplevalue while removing the stream*/ +/*Dont forget to clean ServerStream's minsamplevalue and maxsamplevalue while removing the stream*/ +/*Delete Critical Section while cleaning Stream*/ Modified: branches/nyadav-audio-branch/dll/win32/audsrvapi/audsrvapi.c URL:
http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/dll/win32/a…
============================================================================== --- branches/nyadav-audio-branch/dll/win32/audsrvapi/audsrvapi.c [iso-8859-1] (original) +++ branches/nyadav-audio-branch/dll/win32/audsrvapi/audsrvapi.c [iso-8859-1] Sun Jul 10 12:55:38 2011 @@ -14,7 +14,9 @@ /*Initialize an audio stream *Return -1 if callbacks are NULL pointers */ -WINAPI int InitStream (ClientStream * clientstream, +int +WINAPI +InitStream (ClientStream * clientstream, LONG frequency, int channels, int bitspersample, @@ -69,7 +71,9 @@ return 0; } -WINAPI int PlayAudio ( ClientStream * clientstream ) +int +WINAPI +PlayAudio ( ClientStream * clientstream ) { /*This is an ActiveScheduler*/ clientstream->callbacks.OpenComplete(0); @@ -97,7 +101,9 @@ return 0; } -WINAPI int StopAudio (ClientStream * clientstream ) +int +WINAPI +StopAudio (ClientStream * clientstream ) { /*Server Side termination is remaining*/ /*If connected Properly call the remote audsrv_stop() function*/ @@ -106,19 +112,25 @@ return 0; } -WINAPI int Volume(ClientStream * clientstream, +int +WINAPI +Volume(ClientStream * clientstream, int * volume ) { return 0; } -WINAPI int SetVolume(ClientStream * clientstream , +int +WINAPI +SetVolume(ClientStream * clientstream , const int newvolume) { return 0; } -WINAPI int Write(ClientStream * clientstream , +int +WINAPI +Write(ClientStream * clientstream , const char * aData) { if(clientstream->dead) @@ -129,13 +141,17 @@ return 0; } -WINAPI int SetBalance(ClientStream * clientstream , +int +WINAPI +SetBalance(ClientStream * clientstream , float balance) { return 0; } -WINAPI int GetBalance(ClientStream * clientstream , +int +WINAPI +GetBalance(ClientStream * clientstream , float * balance) { return 0; Modified: branches/nyadav-audio-branch/include/reactos/libs/audsrv/audsrvapi.h URL:
http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/include/rea…
============================================================================== --- branches/nyadav-audio-branch/include/reactos/libs/audsrv/audsrvapi.h [iso-8859-1] (original) +++ branches/nyadav-audio-branch/include/reactos/libs/audsrv/audsrvapi.h [iso-8859-1] Sun Jul 10 12:55:38 2011 @@ -24,7 +24,9 @@ } ClientStream; /********************API Functions******************/ -WINAPI int InitStream (ClientStream * clientstream, +int +WINAPI +InitStream (ClientStream * clientstream, LONG frequency, int channels, int bitspersample, @@ -34,18 +36,34 @@ int mute, float balance); -WINAPI int PlayAudio ( ClientStream * clientstream); -WINAPI int StopAudio (ClientStream * clientstream ); +int +WINAPI +PlayAudio ( ClientStream * clientstream); -WINAPI int Volume(ClientStream * clientstream, +int +WINAPI +StopAudio (ClientStream * clientstream ); + +int +WINAPI +Volume(ClientStream * clientstream, int * volume ); -WINAPI int SetVolume(ClientStream * clientstream , +int +WINAPI +SetVolume(ClientStream * clientstream , const int newvolume); -WINAPI int Write(ClientStream * clientstream , +int +WINAPI +Write(ClientStream * clientstream , const char * aData); -WINAPI int SetBalance(ClientStream * clientstream , + +int +WINAPI +SetBalance(ClientStream * clientstream , float balance); -WINAPI int GetBalance(ClientStream * clientstream , +int +WINAPI +GetBalance(ClientStream * clientstream , float * balance); #endif
13 years, 5 months
1
0
0
0
[rharabien] 52601: [NTDLL/LDR] - Don't use -1 for USHORT LDR_DATA_TABLE_ENTRY::LoadCount. When comparing ((USHORT)-1) == 0xFFFF vs (int)-1 it ends in comparison 0xFFFF vs 0xFFFFFFFF with is wrong. ...
by rharabien@svn.reactos.org
Author: rharabien Date: Sun Jul 10 11:49:52 2011 New Revision: 52601 URL:
http://svn.reactos.org/svn/reactos?rev=52601&view=rev
Log: [NTDLL/LDR] - Don't use -1 for USHORT LDR_DATA_TABLE_ENTRY::LoadCount. When comparing ((USHORT)-1) == 0xFFFF vs (int)-1 it ends in comparison 0xFFFF vs 0xFFFFFFFF with is wrong. Fixes shutdown from shell See issue #6345 for more details. Modified: trunk/reactos/dll/ntdll/ldr/ldrutils.c Modified: trunk/reactos/dll/ntdll/ldr/ldrutils.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/ldrutils.c?r…
============================================================================== --- trunk/reactos/dll/ntdll/ldr/ldrutils.c [iso-8859-1] (original) +++ trunk/reactos/dll/ntdll/ldr/ldrutils.c [iso-8859-1] Sun Jul 10 11:49:52 2011 @@ -105,7 +105,7 @@ FALSE, &Entry)) { - if (Entry->LoadCount != -1) + if (Entry->LoadCount != 0xFFFF) { /* Perform the required action */ switch (Flags) @@ -117,7 +117,7 @@ Entry->LoadCount--; break; case LDRP_UPDATE_PIN: - Entry->LoadCount = -1; + Entry->LoadCount = 0xFFFF; break; } @@ -149,7 +149,7 @@ FALSE, &Entry)) { - if (Entry->LoadCount != -1) + if (Entry->LoadCount != 0xFFFF) { /* Perform the required action */ switch (Flags) @@ -161,7 +161,7 @@ Entry->LoadCount--; break; case LDRP_UPDATE_PIN: - Entry->LoadCount = -1; + Entry->LoadCount = 0xFFFF; break; } @@ -218,7 +218,7 @@ FALSE, &Entry)) { - if (Entry->LoadCount != -1) + if (Entry->LoadCount != 0xFFFF) { /* Perform the required action */ switch (Flags) @@ -230,7 +230,7 @@ Entry->LoadCount--; break; case LDRP_UPDATE_PIN: - Entry->LoadCount = -1; + Entry->LoadCount = 0xFFFF; break; } @@ -1963,7 +1963,7 @@ } /* Update load count, unless it's locked */ - if (LdrEntry->LoadCount != -1) LdrEntry->LoadCount++; + if (LdrEntry->LoadCount != 0xFFFF) LdrEntry->LoadCount++; LdrpUpdateLoadCount2(LdrEntry, LDRP_UPDATE_REFCOUNT); /* Check if we failed */ @@ -1982,7 +1982,7 @@ goto Quickie; } } - else if (LdrEntry->LoadCount != -1) + else if (LdrEntry->LoadCount != 0xFFFF) { /* Increase load count */ LdrEntry->LoadCount++; @@ -2014,7 +2014,7 @@ else { /* We were already loaded. Are we a DLL? */ - if ((LdrEntry->Flags & LDRP_IMAGE_DLL) && (LdrEntry->LoadCount != -1)) + if ((LdrEntry->Flags & LDRP_IMAGE_DLL) && (LdrEntry->LoadCount != 0xFFFF)) { /* Increase load count */ LdrEntry->LoadCount++; @@ -2026,7 +2026,7 @@ else { /* Not a DLL, just increase the load count */ - if (LdrEntry->LoadCount != -1) LdrEntry->LoadCount++; + if (LdrEntry->LoadCount != 0xFFFF) LdrEntry->LoadCount++; } } @@ -2084,7 +2084,7 @@ } /* Check the current Load Count */ - if (LdrEntry->LoadCount != -1) + if (LdrEntry->LoadCount != 0xFFFF) { /* Decrease it */ LdrEntry->LoadCount--;
13 years, 5 months
1
0
0
0
[cgutman] 52600: [AFD] - Fix broken TDI address functions which were causing subtle memory corruptions, wasted memory, and incorrect or uninitialized values of the address length field - Remove som...
by cgutman@svn.reactos.org
Author: cgutman Date: Sun Jul 10 08:25:31 2011 New Revision: 52600 URL:
http://svn.reactos.org/svn/reactos?rev=52600&view=rev
Log: [AFD] - Fix broken TDI address functions which were causing subtle memory corruptions, wasted memory, and incorrect or uninitialized values of the address length field - Remove some buggy code that wasn't used anywhere - General refactoring to reduce code duplication - Handle an invalid address type properly Modified: trunk/reactos/drivers/network/afd/afd/tdiconn.c trunk/reactos/drivers/network/afd/include/tdiconn.h Modified: trunk/reactos/drivers/network/afd/afd/tdiconn.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/afd/afd/td…
============================================================================== --- trunk/reactos/drivers/network/afd/afd/tdiconn.c [iso-8859-1] (original) +++ trunk/reactos/drivers/network/afd/afd/tdiconn.c [iso-8859-1] Sun Jul 10 08:25:31 2011 @@ -15,38 +15,61 @@ UINT TdiAddressSizeFromType( UINT AddressType ) { switch( AddressType ) { case TDI_ADDRESS_TYPE_IP: - return sizeof(TA_IP_ADDRESS); + return TDI_ADDRESS_LENGTH_IP; case TDI_ADDRESS_TYPE_APPLETALK: - return sizeof(TA_APPLETALK_ADDRESS); + return TDI_ADDRESS_LENGTH_APPLETALK; case TDI_ADDRESS_TYPE_NETBIOS: - return sizeof(TA_NETBIOS_ADDRESS); + return TDI_ADDRESS_LENGTH_NETBIOS; /* case TDI_ADDRESS_TYPE_NS: */ case TDI_ADDRESS_TYPE_IPX: - return sizeof(TA_IPX_ADDRESS); + return TDI_ADDRESS_LENGTH_IPX; case TDI_ADDRESS_TYPE_VNS: - return sizeof(TA_VNS_ADDRESS); + return TDI_ADDRESS_LENGTH_VNS; default: DbgPrint("TdiAddressSizeFromType - invalid type: %x\n", AddressType); return 0; } } -UINT TaLengthOfAddress( PTA_ADDRESS Addr ) { - UINT AddrLen = 2 * sizeof( USHORT ) + Addr->AddressLength; +UINT TaLengthOfAddress( PTA_ADDRESS Addr ) +{ + UINT AddrLen = Addr->AddressLength; + + if (!AddrLen) + return 0; + + AddrLen += 2 * sizeof( USHORT ); + AFD_DbgPrint(MID_TRACE,("AddrLen %x\n", AddrLen)); + return AddrLen; } -UINT TaLengthOfTransportAddress( PTRANSPORT_ADDRESS Addr ) { - UINT AddrLen = sizeof(ULONG) + TaLengthOfAddress(&Addr->Address[0]); +UINT TaLengthOfTransportAddress( PTRANSPORT_ADDRESS Addr ) +{ + UINT AddrLen = TaLengthOfAddress(&Addr->Address[0]); + + if (!AddrLen) + return 0; + + AddrLen += sizeof(ULONG); + AFD_DbgPrint(MID_TRACE,("AddrLen %x\n", AddrLen)); + return AddrLen; } UINT TaLengthOfTransportAddressByType(UINT AddressType) { - UINT AddrLen = sizeof(ULONG) + 2 * sizeof(USHORT) + TdiAddressSizeFromType(AddressType); + UINT AddrLen = TdiAddressSizeFromType(AddressType); + + if (!AddrLen) + return 0; + + AddrLen += sizeof(ULONG) + 2 * sizeof(USHORT); + AFD_DbgPrint(MID_TRACE,("AddrLen %x\n", AddrLen)); + return AddrLen; } @@ -58,9 +81,14 @@ PTA_ADDRESS TaCopyAddress( PTA_ADDRESS Source ) { UINT AddrLen = TaLengthOfAddress( Source ); + if (!AddrLen) + return NULL; + PVOID Buffer = ExAllocatePool( NonPagedPool, AddrLen ); + if (Buffer) RtlCopyMemory( Buffer, Source, AddrLen ); + return Buffer; } @@ -74,8 +102,10 @@ UINT AddrLen; PTRANSPORT_ADDRESS A; - ASSERT(OtherAddress->TAAddressCount == 1); AddrLen = TaLengthOfTransportAddress( OtherAddress ); + if (!AddrLen) + return NULL; + A = ExAllocatePool( NonPagedPool, AddrLen ); if( A ) @@ -84,20 +114,39 @@ return A; } +NTSTATUS TdiBuildNullTransportAddressInPlace(PTRANSPORT_ADDRESS A, UINT AddressType) +{ + A->TAAddressCount = 1; + + A->Address[0].AddressLength = TdiAddressSizeFromType(AddressType); + if (!A->Address[0].AddressLength) + return STATUS_INVALID_PARAMETER; + + A->Address[0].AddressType = AddressType; + + RtlZeroMemory(A->Address[0].Address, A->Address[0].AddressLength); + + return STATUS_SUCCESS; +} + PTRANSPORT_ADDRESS TaBuildNullTransportAddress(UINT AddressType) { UINT AddrLen; PTRANSPORT_ADDRESS A; AddrLen = TaLengthOfTransportAddressByType(AddressType); + if (!AddrLen) + return NULL; + A = ExAllocatePool(NonPagedPool, AddrLen); if (A) { - A->TAAddressCount = 1; - A->Address[0].AddressLength = TdiAddressSizeFromType(AddressType); - A->Address[0].AddressType = AddressType; - RtlZeroMemory(A->Address[0].Address, A->Address[0].AddressLength); + if (TdiBuildNullTransportAddressInPlace(A, AddressType) != STATUS_SUCCESS) + { + ExFreePool(A); + return NULL; + } } return A; @@ -118,7 +167,7 @@ ULONG TdiAddressSize; PTRANSPORT_ADDRESS TransportAddress; - TdiAddressSize = TdiAddressSizeFromType(Type); + TdiAddressSize = TaLengthOfTransportAddressByType(Type); if (!TdiAddressSize) return STATUS_INVALID_PARAMETER; @@ -130,10 +179,8 @@ ConnInfo->RemoteAddressLength = TdiAddressSize; ConnInfo->RemoteAddress = TransportAddress = (PTRANSPORT_ADDRESS)&ConnInfo[1]; - TransportAddress->TAAddressCount = 1; - TransportAddress->Address[0].AddressType = Type; - - return STATUS_SUCCESS; + + return TdiBuildNullTransportAddressInPlace(TransportAddress, Type); } NTSTATUS TdiBuildNullConnectionInfo @@ -153,7 +200,7 @@ ULONG TdiAddressSize; NTSTATUS Status; - TdiAddressSize = TdiAddressSizeFromType(Type); + TdiAddressSize = TaLengthOfTransportAddressByType(Type); if (!TdiAddressSize) { *ConnectionInfo = NULL; return STATUS_INVALID_PARAMETER; @@ -170,15 +217,13 @@ Status = TdiBuildNullConnectionInfoInPlace( ConnInfo, Type ); - if (!NT_SUCCESS(Status)) { + if (!NT_SUCCESS(Status)) + { ExFreePool( ConnInfo ); - *ConnectionInfo = NULL; - return Status; - } else - *ConnectionInfo = ConnInfo; - - ConnInfo->RemoteAddress = (PTA_ADDRESS)&ConnInfo[1]; - ConnInfo->RemoteAddressLength = TdiAddressSize; + ConnInfo = NULL; + } + + *ConnectionInfo = ConnInfo; return Status; } @@ -215,60 +260,3 @@ return Status; } -NTSTATUS -TdiBuildConnectionInfoPair -( PTDI_CONNECTION_INFO_PAIR ConnectionInfo, - PTRANSPORT_ADDRESS From, PTRANSPORT_ADDRESS To ) -/* - * FUNCTION: Fill a TDI_CONNECTION_INFO_PAIR struct will the two addresses - * given. - * ARGUMENTS: - * ConnectionInfo: The pair - * From: The from address - * To: The to address - * RETURNS: - * Status of the operation - */ -{ - PCHAR LayoutFrame; - UINT SizeOfEntry; - ULONG TdiAddressSize; - PTDI_CONNECTION_INFORMATION FromTdiConn, ToTdiConn; - - if (!From) return STATUS_INVALID_PARAMETER; - - /* FIXME: Get from socket information */ - TdiAddressSize = TdiAddressSizeFromType(From->Address[0].AddressType); - if (!TdiAddressSize) - return STATUS_INVALID_PARAMETER; - - SizeOfEntry = TdiAddressSize + sizeof(TDI_CONNECTION_INFORMATION); - - LayoutFrame = (PCHAR)ExAllocatePool(NonPagedPool, 2 * SizeOfEntry); - - if (!LayoutFrame) { - AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n")); - return STATUS_INSUFFICIENT_RESOURCES; - } - - RtlZeroMemory( LayoutFrame, 2 * SizeOfEntry ); - - FromTdiConn = (PTDI_CONNECTION_INFORMATION)LayoutFrame; - ToTdiConn = (PTDI_CONNECTION_INFORMATION)LayoutFrame + SizeOfEntry; - - TdiBuildConnectionInfoInPlace( FromTdiConn, From ); - - TdiBuildConnectionInfoInPlace( ToTdiConn, To ); - - return STATUS_SUCCESS; -} - -PTA_ADDRESS TdiGetRemoteAddress( PTDI_CONNECTION_INFORMATION TdiConn ) -/* - * Convenience function that rounds out the abstraction of - * the TDI_CONNECTION_INFORMATION struct. - */ -{ - return TdiConn->RemoteAddress; -} - Modified: trunk/reactos/drivers/network/afd/include/tdiconn.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/afd/includ…
============================================================================== --- trunk/reactos/drivers/network/afd/include/tdiconn.h [iso-8859-1] (original) +++ trunk/reactos/drivers/network/afd/include/tdiconn.h [iso-8859-1] Sun Jul 10 08:25:31 2011 @@ -24,8 +24,3 @@ ( PTDI_CONNECTION_INFORMATION ConnInfo, ULONG Type ); NTSTATUS TdiBuildNullConnectionInfo ( PTDI_CONNECTION_INFORMATION *ConnectionInfo, ULONG Type ); -NTSTATUS TdiBuildConnectionInfoPair -( PTDI_CONNECTION_INFO_PAIR ConnectionInfo, - PTRANSPORT_ADDRESS From, - PTRANSPORT_ADDRESS To ); -PTA_ADDRESS TdiGetRemoteAddress( PTDI_CONNECTION_INFORMATION TdiConn );
13 years, 5 months
1
0
0
0
[tfaber] 52599: [KMTEST] - improve user friendliness by making the service management functions actually work
by tfaber@svn.reactos.org
Author: tfaber Date: Sun Jul 10 08:03:15 2011 New Revision: 52599 URL:
http://svn.reactos.org/svn/reactos?rev=52599&view=rev
Log: [KMTEST] - improve user friendliness by making the service management functions actually work Modified: branches/GSoC_2011/KMTestSuite/kmtests/kmtest/kmtest.c branches/GSoC_2011/KMTestSuite/kmtests/kmtest/support.c branches/GSoC_2011/KMTestSuite/kmtests/kmtest/testlist.c Modified: branches/GSoC_2011/KMTestSuite/kmtests/kmtest/kmtest.c URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/KMTestSuite/kmtests/k…
============================================================================== --- branches/GSoC_2011/KMTestSuite/kmtests/kmtest/kmtest.c [iso-8859-1] (original) +++ branches/GSoC_2011/KMTestSuite/kmtests/kmtest/kmtest.c [iso-8859-1] Sun Jul 10 08:03:15 2011 @@ -22,11 +22,20 @@ #define SERVICE_NAME L"Kmtest" #define SERVICE_PATH L"kmtest_drv.sys" +#define SERVICE_DESCRIPTION L"ReactOS Kernel-Mode Test Suite Driver" #define LOGBUFFER_SIZE 16364 #define RESULTBUFFER_SIZE FIELD_OFFSET(KMT_RESULTBUFFER, LogBuffer[LOGBUFFER_SIZE]) +typedef enum +{ + KMT_DO_NOTHING, + KMT_LIST_TESTS, + KMT_RUN_TEST, +} KMT_OPERATION; + HANDLE KmtestHandle; +SC_HANDLE KmtestServiceHandle; PCSTR ErrorFileAndLine = "No error"; static void OutputError(DWORD Error); @@ -211,6 +220,8 @@ PKMT_TESTFUNC TestFunction; DWORD BytesRead; + assert(TestName != NULL); + ResultBuffer = KmtAllocateResultBuffer(LOGBUFFER_SIZE); if (!DeviceIoControl(KmtestHandle, IOCTL_KMTEST_SET_RESULTBUFFER, ResultBuffer, RESULTBUFFER_SIZE, NULL, 0, &BytesRead, NULL)) error_goto(Error, cleanup); @@ -253,44 +264,70 @@ { INT Status = EXIT_SUCCESS; DWORD Error = ERROR_SUCCESS; - SC_HANDLE ServiceHandle; PCSTR AppName = "kmtest.exe"; - PCSTR TestName; + PCSTR TestName = NULL; + KMT_OPERATION Operation = KMT_DO_NOTHING; Error = KmtServiceInit(); if (Error) goto cleanup; - Error = KmtCreateAndStartService(SERVICE_NAME, SERVICE_PATH, L"ReactOS Kernel-Mode Test Suite Driver", &ServiceHandle, FALSE); - if (Error) - goto cleanup; - - KmtestHandle = CreateFile(KMTEST_DEVICE_PATH, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); - if (KmtestHandle == INVALID_HANDLE_VALUE) - error_goto(Error, cleanup); - if (ArgCount >= 1) AppName = Arguments[0]; if (ArgCount <= 1) { - printf("Usage: %s <test_name> - run the specified test\n", AppName); + printf("Usage: %s <test_name> - run the specified test (creates/starts the driver(s) as appropriate)\n", AppName); printf(" %s --list - list available tests\n", AppName); printf(" %s <create|delete|start|stop> - manage the kmtest driver\n\n", AppName); - Error = ListTests(); + Operation = KMT_LIST_TESTS; } else { TestName = Arguments[1]; - if (!lstrcmpA(Arguments[1], "--list")) - Error = ListTests(); + if (!lstrcmpA(TestName, "create")) + Error = KmtCreateService(SERVICE_NAME, SERVICE_PATH, SERVICE_DESCRIPTION, &KmtestServiceHandle); + else if (!lstrcmpA(TestName, "delete")) + Error = KmtDeleteService(SERVICE_NAME, &KmtestServiceHandle); + else if (!lstrcmpA(TestName, "start")) + Error = KmtStartService(SERVICE_NAME, &KmtestServiceHandle); + else if (!lstrcmpA(TestName, "stop")) + Error = KmtStopService(SERVICE_NAME, &KmtestServiceHandle); + + else if (!lstrcmpA(TestName, "--list")) + Operation = KMT_LIST_TESTS; else - Error = RunTest(TestName); + Operation = KMT_RUN_TEST; + } + + if (Operation) + { + Error = KmtCreateAndStartService(SERVICE_NAME, SERVICE_PATH, SERVICE_DESCRIPTION, &KmtestServiceHandle, FALSE); + if (Error) + goto cleanup; + + KmtestHandle = CreateFile(KMTEST_DEVICE_PATH, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); + if (KmtestHandle == INVALID_HANDLE_VALUE) + error_goto(Error, cleanup); + + switch (Operation) + { + case KMT_LIST_TESTS: + Error = ListTests(); + break; + case KMT_RUN_TEST: + Error = RunTest(TestName); + break; + default: + assert(FALSE); + } } cleanup: if (KmtestHandle) CloseHandle(KmtestHandle); + + KmtCloseService(&KmtestServiceHandle); if (Error) KmtServiceCleanup(TRUE); @@ -298,10 +335,11 @@ Error = KmtServiceCleanup(FALSE); if (Error) + { OutputError(Error); - if (Error) Status = EXIT_FAILURE; + } return Status; } Modified: branches/GSoC_2011/KMTestSuite/kmtests/kmtest/support.c URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/KMTestSuite/kmtests/k…
============================================================================== --- branches/GSoC_2011/KMTestSuite/kmtests/kmtest/support.c [iso-8859-1] (original) +++ branches/GSoC_2011/KMTestSuite/kmtests/kmtest/support.c [iso-8859-1] Sun Jul 10 08:03:15 2011 @@ -17,39 +17,6 @@ #include <kmt_public.h> #include <kmt_test.h> -/* pseudo-tests */ -START_TEST(Create) -{ - // nothing to do here. All tests create the service if needed -} - -START_TEST(Delete) -{ - SC_HANDLE Handle = NULL; - DWORD Error = KmtDeleteService(L"Kmtest", &Handle); - - ok_eq_hex(Error, (DWORD)ERROR_SUCCESS); -} - -START_TEST(Start) -{ - // nothing to do here. All tests start the service -} - -START_TEST(Stop) -{ - // TODO: requiring the service to be started for this is... bad, - // especially when it's marked for deletion and won't start ;) - SC_HANDLE Handle = NULL; - DWORD Error = KmtStopService(L"Kmtest", &Handle); - - ok_eq_hex(Error, (DWORD)ERROR_SUCCESS); - Error = KmtCloseService(&Handle); - ok_eq_hex(Error, (DWORD)ERROR_SUCCESS); -} - -/* test support functions for special-purpose drivers */ - extern HANDLE KmtestHandle; /** Modified: branches/GSoC_2011/KMTestSuite/kmtests/kmtest/testlist.c URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/KMTestSuite/kmtests/k…
============================================================================== --- branches/GSoC_2011/KMTestSuite/kmtests/kmtest/testlist.c [iso-8859-1] (original) +++ branches/GSoC_2011/KMTestSuite/kmtests/kmtest/testlist.c [iso-8859-1] Sun Jul 10 08:03:15 2011 @@ -10,19 +10,11 @@ #include <windows.h> #include <kmt_test.h> -VOID Test_Create(VOID); -VOID Test_Delete(VOID); -VOID Test_Start(VOID); -VOID Test_Stop(VOID); VOID Test_Example(VOID); /* tests with a leading '-' will not be listed */ const KMT_TEST TestList[] = { - { "-create", Test_Create }, - { "-delete", Test_Delete }, - { "-start", Test_Start }, - { "-stop", Test_Stop, }, { "Example", Test_Example }, { NULL, NULL }, };
13 years, 5 months
1
0
0
0
[cgutman] 52598: [KERNEL32]: Fix build
by cgutman@svn.reactos.org
Author: cgutman Date: Sun Jul 10 07:15:26 2011 New Revision: 52598 URL:
http://svn.reactos.org/svn/reactos?rev=52598&view=rev
Log: [KERNEL32]: Fix build Modified: trunk/reactos/dll/win32/kernel32/misc/ldr.c Modified: trunk/reactos/dll/win32/kernel32/misc/ldr.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/misc/ld…
============================================================================== --- trunk/reactos/dll/win32/kernel32/misc/ldr.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/kernel32/misc/ldr.c [iso-8859-1] Sun Jul 10 07:15:26 2011 @@ -863,7 +863,7 @@ if (!(dwPublicFlags & GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT)) { /* Add reference to this DLL */ - Status = LdrAddRefDll((dwPublicFlags & GET_MODULE_HANDLE_EX_FLAG_PIN) ? LDR_PIN_MODULE : 0, + Status = LdrAddRefDll((dwPublicFlags & GET_MODULE_HANDLE_EX_FLAG_PIN) ? LDR_ADDREF_DLL_PIN : 0, hModule); }
13 years, 5 months
1
0
0
0
[cgutman] 52597: [AFD] - Probe and lock pages with the KernelMode access mode instead of Irp->RequestorMode (UserMode) since we're dealing with memory that we allocated in kernel-mode - Fixes getpe...
by cgutman@svn.reactos.org
Author: cgutman Date: Sun Jul 10 02:23:12 2011 New Revision: 52597 URL:
http://svn.reactos.org/svn/reactos?rev=52597&view=rev
Log: [AFD] - Probe and lock pages with the KernelMode access mode instead of Irp->RequestorMode (UserMode) since we're dealing with memory that we allocated in kernel-mode - Fixes getpeername() and HTTPS browsing in Firefox Modified: trunk/reactos/drivers/network/afd/afd/info.c Modified: trunk/reactos/drivers/network/afd/afd/info.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/afd/afd/in…
============================================================================== --- trunk/reactos/drivers/network/afd/afd/info.c [iso-8859-1] (original) +++ trunk/reactos/drivers/network/afd/afd/info.c [iso-8859-1] Sun Jul 10 02:23:12 2011 @@ -262,7 +262,7 @@ if (Mdl) { _SEH2_TRY { - MmProbeAndLockPages(Mdl, Irp->RequestorMode, IoModifyAccess); + MmProbeAndLockPages(Mdl, KernelMode, IoModifyAccess); } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n")); Status = _SEH2_GetExceptionCode();
13 years, 5 months
1
0
0
0
[ion] 52596: [NTDLL]: More attempts at fixing up the loader, this time in the PE side of things.
by ion@svn.reactos.org
Author: ion Date: Sun Jul 10 02:14:29 2011 New Revision: 52596 URL:
http://svn.reactos.org/svn/reactos?rev=52596&view=rev
Log: [NTDLL]: More attempts at fixing up the loader, this time in the PE side of things. Modified: trunk/reactos/dll/ntdll/include/ntdllp.h trunk/reactos/dll/ntdll/ldr/ldrpe.c Modified: trunk/reactos/dll/ntdll/include/ntdllp.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/include/ntdllp.h…
============================================================================== --- trunk/reactos/dll/ntdll/include/ntdllp.h [iso-8859-1] (original) +++ trunk/reactos/dll/ntdll/include/ntdllp.h [iso-8859-1] Sun Jul 10 02:14:29 2011 @@ -145,6 +145,14 @@ ULONG LdrpGetResidentSize(PIMAGE_NT_HEADERS NTHeaders); +NTSTATUS +NTAPI +LdrpLoadImportModule(IN PWSTR DllPath OPTIONAL, + IN LPSTR ImportName, + IN PVOID DllBase, + OUT PLDR_DATA_TABLE_ENTRY *DataTableEntry, + OUT PBOOLEAN Existing); + extern HANDLE WindowsApiPort; /* EOF */ Modified: trunk/reactos/dll/ntdll/ldr/ldrpe.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/ldrpe.c?rev=…
============================================================================== --- trunk/reactos/dll/ntdll/ldr/ldrpe.c [iso-8859-1] (original) +++ trunk/reactos/dll/ntdll/ldr/ldrpe.c [iso-8859-1] Sun Jul 10 02:14:29 2011 @@ -13,20 +13,10 @@ #include <debug.h> /* GLOBALS *******************************************************************/ + ULONG LdrpFatalHardErrorCount; PVOID LdrpManifestProberRoutine; - -/* PROTOTYPES ****************************************************************/ - -#define IMAGE_REL_BASED_HIGH3ADJ 11 - -NTSTATUS -NTAPI -LdrpLoadImportModule(IN PWSTR DllPath OPTIONAL, - IN LPSTR ImportName, - IN PVOID DllBase, - OUT PLDR_DATA_TABLE_ENTRY *DataTableEntry, - OUT PBOOLEAN Existing); +ULONG LdrpNormalSnap; /* FUNCTIONS *****************************************************************/ @@ -511,22 +501,21 @@ NTAPI LdrpHandleOneOldFormatImportDescriptor(IN LPWSTR DllPath OPTIONAL, IN PLDR_DATA_TABLE_ENTRY LdrEntry, - IN PIMAGE_IMPORT_DESCRIPTOR ImportEntry) + IN PIMAGE_IMPORT_DESCRIPTOR *ImportEntry) { - //ULONG IatSize, i; LPSTR ImportName; NTSTATUS Status; - BOOLEAN AlreadyLoaded = FALSE, StaticEntriesValid = FALSE, SkipSnap = FALSE; + BOOLEAN AlreadyLoaded = FALSE; PLDR_DATA_TABLE_ENTRY DllLdrEntry; PIMAGE_THUNK_DATA FirstThunk; PPEB Peb = NtCurrentPeb(); /* Get the import name's VA */ - ImportName = (LPSTR)((ULONG_PTR)LdrEntry->DllBase + ImportEntry->Name); + ImportName = (LPSTR)((ULONG_PTR)LdrEntry->DllBase + (*ImportEntry)->Name); /* Get the first thunk */ FirstThunk = (PIMAGE_THUNK_DATA)((ULONG_PTR)LdrEntry->DllBase + - ImportEntry->FirstThunk); + (*ImportEntry)->FirstThunk); /* Make sure it's valid */ if (!FirstThunk->u1.Function) goto SkipEntry; @@ -545,7 +534,21 @@ LdrEntry->DllBase, &DllLdrEntry, &AlreadyLoaded); - if (!NT_SUCCESS(Status)) return Status; + if (!NT_SUCCESS(Status)) + { + /* Fail */ + if (ShowSnaps) + { + DbgPrint("LDR: LdrpWalkImportTable - LdrpLoadImportModule failed " + "on import %s with status %x\n", + ImportName, + Status); + } + + /* Return */ + *ImportEntry = *ImportEntry; + return Status; + } /* Show debug message */ if (ShowSnaps) @@ -555,41 +558,8 @@ ImportName); } - /* Check if the image was bound when compiled */ - if (ImportEntry->OriginalFirstThunk) - { - /* It was, so check if the static IAT entries are still valid */ - if ((ImportEntry->TimeDateStamp) && - (ImportEntry->TimeDateStamp == DllLdrEntry->TimeDateStamp) && - (!(DllLdrEntry->Flags & LDRP_IMAGE_NOT_AT_BASE))) - { - /* Show debug message */ - if (ShowSnaps) - { - DPRINT1("LDR: Snap bypass %s from %wZ\n", - ImportName, - &LdrEntry->BaseDllName); - } - - /* - * They are still valid, so we can skip snapping them. - * Additionally, if we have no forwarders, we are totally - * done. - */ - if (ImportEntry->ForwarderChain == -1) - { - /* Totally skip LdrpSnapIAT */ - SkipSnap = TRUE; - } - else - { - /* Set this so LdrpSnapIAT will only do forwarders */ - StaticEntriesValid = TRUE; - } - } - } - /* Check if it wasn't already loaded */ + ++LdrpNormalSnap; if (!AlreadyLoaded) { /* Add the DLL to our list */ @@ -597,18 +567,26 @@ &DllLdrEntry->InInitializationOrderModuleList); } - /* Check if we should snap at all */ - if (!SkipSnap) - { - /* Now snap the IAT Entry */ - Status = LdrpSnapIAT(DllLdrEntry, - LdrEntry, - ImportEntry, - StaticEntriesValid); - if (!NT_SUCCESS(Status)) return Status; + /* Now snap the IAT Entry */ + Status = LdrpSnapIAT(DllLdrEntry, LdrEntry, *ImportEntry, FALSE); + if (!NT_SUCCESS(Status)) + { + /* Fail */ + if (ShowSnaps) + { + DbgPrint("LDR: LdrpWalkImportTable - LdrpSnapIAT #2 failed with " + "status %x\n", + Status); + } + + /* Return */ + *ImportEntry = *ImportEntry; + return Status; } SkipEntry: + /* Move on */ + *ImportEntry = (*ImportEntry)++; return STATUS_SUCCESS; } @@ -621,34 +599,31 @@ NTSTATUS Status; /* Check for Name and Thunk */ - while (ImportEntry->Name && ImportEntry->FirstThunk) + while ((ImportEntry->Name) && (ImportEntry->FirstThunk)) { /* Parse this descriptor */ Status = LdrpHandleOneOldFormatImportDescriptor(DllPath, LdrEntry, - ImportEntry); + &ImportEntry); if (!NT_SUCCESS(Status)) return Status; - - /* Move to the next entry */ - ImportEntry++; } /* Done */ return STATUS_SUCCESS; } -USHORT NTAPI -LdrpNameToOrdinal(LPSTR ImportName, - ULONG NumberOfNames, - PVOID ExportBase, - PULONG NameTable, - PUSHORT OrdinalTable) +USHORT +NTAPI +LdrpNameToOrdinal(IN LPSTR ImportName, + IN ULONG NumberOfNames, + IN PVOID ExportBase, + IN PULONG NameTable, + IN PUSHORT OrdinalTable) { - ULONG Start, End, Next; - LONG CmpResult; + LONG Start, End, Next, CmpResult; /* Use classical binary search to find the ordinal */ - Start = 0; + Start = Next = 0; End = NumberOfNames - 1; while (End >= Start) { @@ -663,9 +638,13 @@ /* We didn't find, update our range then */ if (CmpResult < 0) + { End = Next - 1; + } else if (CmpResult > 0) + { Start = Next + 1; + } } /* If end is before start, then the search failed */ @@ -686,13 +665,12 @@ PIMAGE_BOUND_IMPORT_DESCRIPTOR BoundEntry = NULL; PIMAGE_IMPORT_DESCRIPTOR ImportEntry; ULONG BoundSize, IatSize; - DPRINT("LdrpWalkImportDescriptor('%S' %x)\n", DllPath, LdrEntry); /* Set up the Act Ctx */ ActCtx.Size = sizeof(ActCtx); - ActCtx.Format = 1; - RtlZeroMemory(&ActCtx.Frame, sizeof(RTL_ACTIVATION_CONTEXT_STACK_FRAME)); + ActCtx.Format = RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_FORMAT_WHISTLER; + RtlZeroMemory(&ActCtx.Frame, sizeof(ActCtx)); /* Check if we have a manifest prober routine */ if (LdrpManifestProberRoutine) @@ -705,7 +683,16 @@ /* Get the Active ActCtx */ Status = RtlGetActiveActivationContext(&LdrEntry->EntryPointActivationContext); - if (!NT_SUCCESS(Status)) return Status; + if (!NT_SUCCESS(Status)) + { + /* Exit */ + DbgPrintEx(51, // DPFLTR_SXS_ID + DPFLTR_WARNING_LEVEL, + "LDR: RtlGetActiveActivationContext() failed; ntstatus = " + "0x%08lx\n", + Status); + return Status; + } /* Activate the ActCtx */ RtlActivateActivationContextUnsafeFast(&ActCtx, @@ -728,7 +715,7 @@ &IatSize); /* Check if we got at least one */ - if (BoundEntry || ImportEntry) + if ((BoundEntry) || (ImportEntry)) { /* Do we have a Bound IAT */ if (BoundEntry) @@ -782,6 +769,7 @@ return Status; } +/* FIXME: This function is missing SxS support and has wrong prototype */ NTSTATUS NTAPI LdrpLoadImportModule(IN PWSTR DllPath OPTIONAL,
13 years, 5 months
1
0
0
0
[ion] 52595: [NTDLL]: Multiple fixes and cleanups to several loader functions in ldrutils. [NTDLL]: Use original symbolic function names instead of modified ones. [NTDLL]: Fixup some incorrect flag...
by ion@svn.reactos.org
Author: ion Date: Sun Jul 10 01:34:19 2011 New Revision: 52595 URL:
http://svn.reactos.org/svn/reactos?rev=52595&view=rev
Log: [NTDLL]: Multiple fixes and cleanups to several loader functions in ldrutils. [NTDLL]: Use original symbolic function names instead of modified ones. [NTDLL]: Fixup some incorrect flag and typedef definitions with correct ones. [NTDLL]: Tag functions which seem broken/lacking in functionality/very different from the rest of the code the LDR rewrite was based on. Modified: trunk/reactos/dll/ntdll/include/ntdllp.h trunk/reactos/dll/ntdll/ldr/ldrapi.c trunk/reactos/dll/ntdll/ldr/ldrinit.c trunk/reactos/dll/ntdll/ldr/ldrutils.c trunk/reactos/include/ndk/ldrtypes.h Modified: trunk/reactos/dll/ntdll/include/ntdllp.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/include/ntdllp.h…
============================================================================== --- trunk/reactos/dll/ntdll/include/ntdllp.h [iso-8859-1] (original) +++ trunk/reactos/dll/ntdll/include/ntdllp.h [iso-8859-1] Sun Jul 10 01:34:19 2011 @@ -25,11 +25,6 @@ IMAGE_TLS_DIRECTORY TlsDirectory; } LDRP_TLS_DATA, *PLDRP_TLS_DATA; -typedef BOOL -(NTAPI *PDLLMAIN_FUNC)(HANDLE hInst, - ULONG ul_reason_for_call, - LPVOID lpReserved); - /* Global data */ extern RTL_CRITICAL_SECTION LdrpLoaderLock; extern BOOLEAN LdrpInLdrInit; @@ -54,8 +49,8 @@ NTSTATUS NTAPI LdrpInitializeTls(VOID); NTSTATUS NTAPI LdrpAllocateTls(VOID); VOID NTAPI LdrpFreeTls(VOID); -VOID NTAPI LdrpTlsCallback(PVOID BaseAddress, ULONG Reason); -BOOLEAN NTAPI LdrpCallDllEntry(PDLLMAIN_FUNC EntryPoint, PVOID BaseAddress, ULONG Reason, PVOID Context); +VOID NTAPI LdrpCallTlsInitializers(PVOID BaseAddress, ULONG Reason); +BOOLEAN NTAPI LdrpCallInitRoutine(PDLL_INIT_ROUTINE EntryPoint, PVOID BaseAddress, ULONG Reason, PVOID Context); NTSTATUS NTAPI LdrpInitializeProcess(PCONTEXT Context, PVOID SystemArgument1); VOID NTAPI LdrpInitFailure(NTSTATUS Status); VOID NTAPI LdrpValidateImageForMp(IN PLDR_DATA_TABLE_ENTRY LdrDataTableEntry); @@ -135,7 +130,7 @@ PVOID NTAPI LdrpFetchAddressOfEntryPoint(PVOID ImageBase); -BOOLEAN NTAPI +VOID NTAPI LdrpFreeUnicodeString(PUNICODE_STRING String); Modified: trunk/reactos/dll/ntdll/ldr/ldrapi.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/ldrapi.c?rev…
============================================================================== --- trunk/reactos/dll/ntdll/ldr/ldrapi.c [iso-8859-1] (original) +++ trunk/reactos/dll/ntdll/ldr/ldrapi.c [iso-8859-1] Sun Jul 10 01:34:19 2011 @@ -1159,6 +1159,91 @@ /* * @implemented */ +NTSTATUS +NTAPI +LdrAddRefDll(IN ULONG Flags, + IN PVOID BaseAddress) +{ + PLDR_DATA_TABLE_ENTRY LdrEntry; + NTSTATUS Status = STATUS_SUCCESS; + ULONG Cookie; + BOOLEAN Locked = FALSE; + + /* Check for invalid flags */ + if (Flags & ~(LDR_ADDREF_DLL_PIN)) + { + /* Fail with invalid parameter status if so */ + Status = STATUS_INVALID_PARAMETER; + goto quickie; + } + + /* Acquire the loader lock if not in init phase */ + if (!LdrpInLdrInit) + { + /* Acquire the lock */ + Status = LdrLockLoaderLock(0, NULL, &Cookie); + if (!NT_SUCCESS(Status)) goto quickie; + Locked = TRUE; + } + + /* Get this module's data table entry */ + if (LdrpCheckForLoadedDllHandle(BaseAddress, &LdrEntry)) + { + if (!LdrEntry) + { + /* Shouldn't happen */ + Status = STATUS_INTERNAL_ERROR; + goto quickie; + } + + /* If this is not a pinned module */ + if (LdrEntry->LoadCount != 0xFFFF) + { + /* Update its load count */ + if (Flags & LDR_ADDREF_DLL_PIN) + { + /* Pin it by setting load count to -1 */ + LdrEntry->LoadCount = 0xFFFF; + LdrpUpdateLoadCount2(LdrEntry, LDRP_UPDATE_PIN); + } + else + { + /* Increase its load count by one */ + LdrEntry->LoadCount++; + LdrpUpdateLoadCount2(LdrEntry, LDRP_UPDATE_REFCOUNT); + } + + /* Clear load in progress */ + LdrpClearLoadInProgress(); + } + } + else + { + /* There was an error getting this module's handle, return invalid param status */ + Status = STATUS_INVALID_PARAMETER; + } + +quickie: + /* Check for error case */ + if (!NT_SUCCESS(Status)) + { + /* Print debug information */ + if ((ShowSnaps) || ((Status != STATUS_NO_SUCH_FILE) && + (Status != STATUS_DLL_NOT_FOUND) && + (Status != STATUS_OBJECT_NAME_NOT_FOUND))) + { + DPRINT1("LDR: LdrAddRefDll(%p) 0x%08lx\n", BaseAddress); + } + } + + /* Release the lock if needed */ + if (Locked) LdrUnlockLoaderLock(LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS, Cookie); + return Status; +} + +/* + * @implemented + */ BOOLEAN NTAPI RtlDllShutdownInProgress(VOID) Modified: trunk/reactos/dll/ntdll/ldr/ldrinit.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/ldrinit.c?re…
============================================================================== --- trunk/reactos/dll/ntdll/ldr/ldrinit.c [iso-8859-1] (original) +++ trunk/reactos/dll/ntdll/ldr/ldrinit.c [iso-8859-1] Sun Jul 10 01:34:19 2011 @@ -561,7 +561,7 @@ if (!LdrpShutdownInProgress) { /* Call TLS */ - LdrpTlsCallback(LdrEntry->DllBase, DLL_THREAD_ATTACH); + LdrpCallTlsInitializers(LdrEntry->DllBase, DLL_THREAD_ATTACH); } } @@ -571,7 +571,7 @@ /* Call the Entrypoint */ DPRINT("%wZ - Calling entry point at %x for thread attaching\n", &LdrEntry->BaseDllName, LdrEntry->EntryPoint); - LdrpCallDllEntry(LdrEntry->EntryPoint, + LdrpCallInitRoutine(LdrEntry->EntryPoint, LdrEntry->DllBase, DLL_THREAD_ATTACH, NULL); @@ -600,7 +600,7 @@ LdrpImageEntry->EntryPointActivationContext); /* Do TLS callbacks */ - LdrpTlsCallback(Peb->ImageBaseAddress, DLL_THREAD_ATTACH); + LdrpCallTlsInitializers(Peb->ImageBaseAddress, DLL_THREAD_ATTACH); /* Deactivate the ActCtx */ RtlDeactivateActivationContextUnsafeFast(&ActCtx); @@ -796,7 +796,7 @@ if (LdrEntry->TlsIndex && Context) { /* Call TLS */ - LdrpTlsCallback(LdrEntry->DllBase, DLL_PROCESS_ATTACH); + LdrpCallTlsInitializers(LdrEntry->DllBase, DLL_PROCESS_ATTACH); } /* Call the Entrypoint */ @@ -805,7 +805,7 @@ DPRINT1("%wZ - Calling entry point at %p for DLL_PROCESS_ATTACH\n", &LdrEntry->BaseDllName, EntryPoint); } - DllStatus = LdrpCallDllEntry(EntryPoint, + DllStatus = LdrpCallInitRoutine(EntryPoint, LdrEntry->DllBase, DLL_PROCESS_ATTACH, Context); @@ -859,7 +859,7 @@ LdrpImageEntry->EntryPointActivationContext); /* Do TLS callbacks */ - LdrpTlsCallback(Peb->ImageBaseAddress, DLL_PROCESS_ATTACH); + LdrpCallTlsInitializers(Peb->ImageBaseAddress, DLL_PROCESS_ATTACH); /* Deactivate the ActCtx */ RtlDeactivateActivationContextUnsafeFast(&ActCtx); @@ -956,13 +956,13 @@ if (LdrEntry->TlsIndex) { /* Call TLS */ - LdrpTlsCallback(LdrEntry->DllBase, DLL_PROCESS_DETACH); + LdrpCallTlsInitializers(LdrEntry->DllBase, DLL_PROCESS_DETACH); } /* Call the Entrypoint */ DPRINT("%wZ - Calling entry point at %x for thread detaching\n", &LdrEntry->BaseDllName, LdrEntry->EntryPoint); - LdrpCallDllEntry(EntryPoint, + LdrpCallInitRoutine(EntryPoint, LdrEntry->DllBase, DLL_PROCESS_DETACH, (PVOID)1); @@ -986,7 +986,7 @@ LdrpImageEntry->EntryPointActivationContext); /* Do TLS callbacks */ - LdrpTlsCallback(Peb->ImageBaseAddress, DLL_PROCESS_DETACH); + LdrpCallTlsInitializers(Peb->ImageBaseAddress, DLL_PROCESS_DETACH); /* Deactivate the ActCtx */ RtlDeactivateActivationContextUnsafeFast(&ActCtx); @@ -1067,7 +1067,7 @@ if (!LdrpShutdownInProgress) { /* Call TLS */ - LdrpTlsCallback(LdrEntry->DllBase, DLL_THREAD_DETACH); + LdrpCallTlsInitializers(LdrEntry->DllBase, DLL_THREAD_DETACH); } } @@ -1077,7 +1077,7 @@ /* Call the Entrypoint */ DPRINT("%wZ - Calling entry point at %x for thread detaching\n", &LdrEntry->BaseDllName, LdrEntry->EntryPoint); - LdrpCallDllEntry(EntryPoint, + LdrpCallInitRoutine(EntryPoint, LdrEntry->DllBase, DLL_THREAD_DETACH, NULL); @@ -1103,7 +1103,7 @@ LdrpImageEntry->EntryPointActivationContext); /* Do TLS callbacks */ - LdrpTlsCallback(Peb->ImageBaseAddress, DLL_THREAD_DETACH); + LdrpCallTlsInitializers(Peb->ImageBaseAddress, DLL_THREAD_DETACH); /* Deactivate the ActCtx */ RtlDeactivateActivationContextUnsafeFast(&ActCtx); Modified: trunk/reactos/dll/ntdll/ldr/ldrutils.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/ldrutils.c?r…
============================================================================== --- trunk/reactos/dll/ntdll/ldr/ldrutils.c [iso-8859-1] (original) +++ trunk/reactos/dll/ntdll/ldr/ldrutils.c [iso-8859-1] Sun Jul 10 01:34:19 2011 @@ -14,11 +14,9 @@ #include <debug.h> /* GLOBALS *******************************************************************/ -#define IMAGE_DLLCHARACTERISTICS_WX86_DLL 0x1000 LIST_ENTRY LdrpUnloadHead; -PLDR_DATA_TABLE_ENTRY LdrpLoadedDllHandleCache; -PLDR_DATA_TABLE_ENTRY LdrpGetModuleHandleCache; +PLDR_DATA_TABLE_ENTRY LdrpLoadedDllHandleCache, LdrpGetModuleHandleCache; #define LDR_GET_HASH_ENTRY(x) (RtlUpcaseUnicodeChar((x)) & (LDR_HASH_TABLE_ENTRIES - 1)) @@ -26,15 +24,16 @@ BOOLEAN NTAPI -LdrpCallDllEntry(PDLLMAIN_FUNC EntryPoint, - PVOID BaseAddress, - ULONG Reason, - PVOID Context) +LdrpCallInitRoutine(IN PDLL_INIT_ROUTINE EntryPoint, + IN PVOID BaseAddress, + IN ULONG Reason, + IN PVOID Context) { /* Call the entry */ return EntryPoint(BaseAddress, Reason, Context); } +/* NOTE: This function is broken */ VOID NTAPI LdrpUpdateLoadCount3(IN PLDR_DATA_TABLE_ENTRY LdrEntry, @@ -261,18 +260,15 @@ WCHAR Buffer[MAX_PATH]; UNICODE_STRING UpdateString; - /* Setup the string */ - UpdateString.Buffer = Buffer; - UpdateString.Length = 0; - UpdateString.MaximumLength = sizeof(Buffer); - - /* Call the extended API */ + /* Setup the string and call the extended API */ + RtlInitEmptyUnicodeString(&UpdateString, Buffer, sizeof(Buffer)); LdrpUpdateLoadCount3(LdrEntry, Flags, &UpdateString); } VOID NTAPI -LdrpTlsCallback(PVOID BaseAddress, ULONG Reason) +LdrpCallTlsInitializers(IN PVOID BaseAddress, + IN ULONG Reason) { PIMAGE_TLS_DIRECTORY TlsDirectory; PIMAGE_TLS_CALLBACK *Array, Callback; @@ -288,7 +284,8 @@ _SEH2_TRY { /* Make sure it's valid and we have an array */ - if (TlsDirectory && (Array = (PIMAGE_TLS_CALLBACK *)TlsDirectory->AddressOfCallBacks)) + Array = (PIMAGE_TLS_CALLBACK *)TlsDirectory->AddressOfCallBacks; + if ((TlsDirectory) && (Array)) { /* Display debug */ if (ShowSnaps) @@ -311,7 +308,10 @@ } /* Call it */ - LdrpCallDllEntry((PDLLMAIN_FUNC)Callback, BaseAddress, Reason, NULL); + LdrpCallInitRoutine((PDLL_INIT_ROUTINE)Callback, + BaseAddress, + Reason, + NULL); } } } @@ -324,9 +324,10 @@ NTSTATUS NTAPI -LdrpCodeAuthzCheckDllAllowed(PUNICODE_STRING FullName, - HANDLE DllHandle) +LdrpCodeAuthzCheckDllAllowed(IN PUNICODE_STRING FullName, + IN HANDLE DllHandle) { + /* Not implemented */ return STATUS_SUCCESS; } @@ -481,6 +482,7 @@ return Status; } +/* NOTE: This function is totally b0rked and doesn't handle the parameters/functionality it should */ BOOLEAN NTAPI LdrpResolveDllName(PWSTR DllPath, @@ -577,25 +579,25 @@ PVOID NTAPI -LdrpFetchAddressOfEntryPoint(PVOID ImageBase) +LdrpFetchAddressOfEntryPoint(IN PVOID ImageBase) { PIMAGE_NT_HEADERS NtHeaders; - ULONG_PTR EntryPoint; + ULONG_PTR EntryPoint = 0; /* Get entry point offset from NT headers */ NtHeaders = RtlImageNtHeader(ImageBase); - EntryPoint = NtHeaders->OptionalHeader.AddressOfEntryPoint; - - /* If it's 0 - return so */ - if (!EntryPoint) return NULL; - - /* Add image base */ - EntryPoint += (ULONG_PTR)ImageBase; - - /* Return calculated pointer */ + if (NtHeaders) + { + /* Add image base */ + EntryPoint = NtHeaders->OptionalHeader.AddressOfEntryPoint; + if (EntryPoint) EntryPoint += (ULONG_PTR)ImageBase; + } + + /* Return calculated pointer (or zero in case of failure) */ return (PVOID)EntryPoint; } +/* NOTE: This function is broken, wrong number of parameters, no SxS, etc */ HANDLE NTAPI LdrpCheckForKnownDll(PWSTR DllName, @@ -702,31 +704,36 @@ /* Get the NT headers */ NtHeaders = RtlImageNtHeader(ViewBase); + if (!NtHeaders) return STATUS_INVALID_IMAGE_FORMAT; /* Compute address of the first section header */ - Section = (PIMAGE_SECTION_HEADER)( - (ULONG_PTR)NtHeaders + sizeof(ULONG) + sizeof(IMAGE_FILE_HEADER) + - NtHeaders->FileHeader.SizeOfOptionalHeader); + Section = IMAGE_FIRST_SECTION(NtHeaders); /* Go through all sections */ for (i = 0; i < NtHeaders->FileHeader.NumberOfSections; i++) { - if (Section->SizeOfRawData && + /* Check for read-only non-zero section */ + if ((Section->SizeOfRawData) && !(Section->Characteristics & IMAGE_SCN_MEM_WRITE)) { - /* This section is not writable and has some size, so we need to change - its protection */ + /* Check if we are setting or restoring protection */ if (Restore) { /* Set it to either EXECUTE or READONLY */ if (Section->Characteristics & IMAGE_SCN_MEM_EXECUTE) + { NewProtection = PAGE_EXECUTE; + } else + { NewProtection = PAGE_READONLY; + } /* Add PAGE_NOCACHE if needed */ if (Section->Characteristics & IMAGE_SCN_MEM_NOT_CACHED) + { NewProtection |= PAGE_NOCACHE; + } } else { @@ -734,9 +741,9 @@ NewProtection = PAGE_READWRITE; } + /* Get the section VA */ SectionBase = (PVOID)((ULONG_PTR)ViewBase + Section->VirtualAddress); SectionSize = Section->SizeOfRawData; - if (SectionSize) { /* Set protection */ @@ -745,7 +752,6 @@ &SectionSize, NewProtection, &OldProtection); - if (!NT_SUCCESS(Status)) return Status; } } @@ -756,10 +762,10 @@ /* Flush instruction cache if necessary */ if (Restore) ZwFlushInstructionCache(NtCurrentProcess(), NULL, 0); - return STATUS_SUCCESS; } +/* NOTE: Not yet reviewed */ NTSTATUS NTAPI LdrpMapDll(IN PWSTR SearchPath OPTIONAL, @@ -1275,11 +1281,11 @@ LdrpAllocateDataTableEntry(IN PVOID BaseAddress) { PLDR_DATA_TABLE_ENTRY LdrEntry = NULL; - PIMAGE_NT_HEADERS NtHeader = RtlImageNtHeader(BaseAddress); - + PIMAGE_NT_HEADERS NtHeader; DPRINT("LdrpAllocateDataTableEntry(%p), NtHeader %p\n", BaseAddress, NtHeader); /* Make sure the header is valid */ + NtHeader = RtlImageNtHeader(BaseAddress); if (NtHeader) { /* Allocate an entry */ @@ -1294,6 +1300,7 @@ LdrEntry->DllBase = BaseAddress; LdrEntry->SizeOfImage = NtHeader->OptionalHeader.SizeOfImage; LdrEntry->TimeDateStamp = NtHeader->FileHeader.TimeDateStamp; + LdrEntry->PatchInformation = NULL; } } @@ -1308,36 +1315,33 @@ PPEB_LDR_DATA PebData = NtCurrentPeb()->Ldr; ULONG i; - /* Get the Hash entry */ + /* Insert into hash table */ i = LDR_GET_HASH_ENTRY(LdrEntry->BaseDllName.Buffer[0]); - InsertTailList(&LdrpHashTable[i], &LdrEntry->HashLinks); + + /* Insert into other lists */ InsertTailList(&PebData->InLoadOrderModuleList, &LdrEntry->InLoadOrderLinks); InsertTailList(&PebData->InMemoryOrderModuleList, &LdrEntry->InMemoryOrderModuleList); } VOID NTAPI -LdrpFinalizeAndDeallocateDataTableEntry(PLDR_DATA_TABLE_ENTRY Entry) +LdrpFinalizeAndDeallocateDataTableEntry(IN PLDR_DATA_TABLE_ENTRY Entry) { + /* Sanity check */ ASSERT(Entry != NULL); - /* Release the activation context if it exists */ - if (Entry->EntryPointActivationContext) - { - /* Check if it wasn't already released */ - if ((HANDLE)Entry->EntryPointActivationContext != INVALID_HANDLE_VALUE) - { - RtlReleaseActivationContext(Entry->EntryPointActivationContext); - - /* Mark it as invalid */ - Entry->EntryPointActivationContext = INVALID_HANDLE_VALUE; - } + /* Release the activation context if it exists and wasn't already released */ + if ((Entry->EntryPointActivationContext) && + (Entry->EntryPointActivationContext != INVALID_HANDLE_VALUE)) + { + /* Mark it as invalid */ + RtlReleaseActivationContext(Entry->EntryPointActivationContext); + Entry->EntryPointActivationContext = INVALID_HANDLE_VALUE; } /* Release the full dll name string */ - if (Entry->FullDllName.Buffer) - LdrpFreeUnicodeString(&Entry->FullDllName); + if (Entry->FullDllName.Buffer) LdrpFreeUnicodeString(&Entry->FullDllName); /* Finally free the entry's memory */ RtlFreeHeap(RtlGetProcessHeap(), 0, Entry); @@ -1352,7 +1356,8 @@ PLIST_ENTRY ListHead, Next; /* Check the cache first */ - if (LdrpLoadedDllHandleCache && LdrpLoadedDllHandleCache->DllBase == Base) + if ((LdrpLoadedDllHandleCache) && + (LdrpLoadedDllHandleCache->DllBase == Base)) { /* We got lucky, return the cached entry */ *LdrEntry = LdrpLoadedDllHandleCache; @@ -1362,12 +1367,12 @@ /* Time for a lookup */ ListHead = &NtCurrentPeb()->Ldr->InLoadOrderModuleList; Next = ListHead->Flink; - while(Next != ListHead) + while (Next != ListHead) { /* Get the current entry */ - Current = CONTAINING_RECORD(Next, - LDR_DATA_TABLE_ENTRY, - InLoadOrderLinks); + Current = CONTAINING_RECORD(Next, + LDR_DATA_TABLE_ENTRY, + InLoadOrderLinks); /* Make sure it's not unloading and check for a match */ if ((Current->InMemoryOrderModuleList.Flink) && (Base == Current->DllBase)) @@ -2223,10 +2228,10 @@ LdrEntry->EntryPointActivationContext); /* Call the entrypoint */ - LdrpCallDllEntry(LdrEntry->EntryPoint, - LdrEntry->DllBase, - DLL_PROCESS_DETACH, - NULL); + LdrpCallInitRoutine(LdrEntry->EntryPoint, + LdrEntry->DllBase, + DLL_PROCESS_DETACH, + NULL); /* Release the context */ RtlDeactivateActivationContextUnsafeFast(&ActCtx); @@ -2313,139 +2318,55 @@ ULONG NTAPI -LdrpClearLoadInProgress() +LdrpClearLoadInProgress(VOID) { - PLIST_ENTRY ListHead; - PLIST_ENTRY Entry; - PLDR_DATA_TABLE_ENTRY Module; + PLIST_ENTRY ListHead, Entry; + PLDR_DATA_TABLE_ENTRY LdrEntry; ULONG ModulesCount = 0; /* Traverse the init list */ ListHead = &NtCurrentPeb()->Ldr->InInitializationOrderModuleList; Entry = ListHead->Flink; - while (Entry != ListHead) { - Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InInitializationOrderModuleList); + /* Get the loader entry */ + LdrEntry = CONTAINING_RECORD(Entry, + LDR_DATA_TABLE_ENTRY, + InInitializationOrderModuleList); /* Clear load in progress flag */ - Module->Flags &= ~LDRP_LOAD_IN_PROGRESS; - - /* Increase counter for modules with entry point count but not processed yet */ - if (Module->EntryPoint && - !(Module->Flags & LDRP_ENTRY_PROCESSED)) ModulesCount++; + LdrEntry->Flags &= ~LDRP_LOAD_IN_PROGRESS; + + /* Check for modules with entry point count but not processed yet */ + if ((LdrEntry->EntryPoint) && + !(LdrEntry->Flags & LDRP_ENTRY_PROCESSED)) + { + /* Increase counter */ + ModulesCount++; + } /* Advance to the next entry */ Entry = Entry->Flink; } + /* Return final count */ return ModulesCount; } -/* - * @implemented - */ -NTSTATUS NTAPI -LdrAddRefDll(IN ULONG Flags, - IN PVOID BaseAddress) +VOID +NTAPI +LdrpFreeUnicodeString(IN PUNICODE_STRING StringIn) { - PLDR_DATA_TABLE_ENTRY LdrEntry; - NTSTATUS Status = STATUS_SUCCESS; - ULONG Cookie; - BOOLEAN Locked = FALSE; - - /* Check for invalid flags */ - if (Flags & ~(LDR_PIN_MODULE)) - { - /* Fail with invalid parameter status if so */ - Status = STATUS_INVALID_PARAMETER; - goto quickie; - } - - /* Acquire the loader lock if not in init phase */ - if (!LdrpInLdrInit) - { - /* Acquire the lock */ - Status = LdrLockLoaderLock(0, NULL, &Cookie); - if (!NT_SUCCESS(Status)) goto quickie; - Locked = TRUE; - } - - /* Get this module's data table entry */ - if (LdrpCheckForLoadedDllHandle(BaseAddress, &LdrEntry)) - { - if (!LdrEntry) - { - /* Shouldn't happen */ - Status = STATUS_INTERNAL_ERROR; - goto quickie; - } - - /* If this is not a pinned module */ - if (LdrEntry->LoadCount != -1) - { - /* Update its load count */ - if (Flags & LDR_PIN_MODULE) - { - /* Pin it by setting load count to -1 */ - LdrEntry->LoadCount = -1; - LdrpUpdateLoadCount2(LdrEntry, LDRP_UPDATE_PIN); - } - else - { - /* Increase its load count by one */ - LdrEntry->LoadCount++; - LdrpUpdateLoadCount2(LdrEntry, LDRP_UPDATE_REFCOUNT); - } - - /* Clear load in progress */ - LdrpClearLoadInProgress(); - } - } - else - { - /* There was an error getting this module's handle, return invalid param status */ - Status = STATUS_INVALID_PARAMETER; - goto quickie; - } - -quickie: - if (!NT_SUCCESS(Status)) - { - if (ShowSnaps || - (Status != STATUS_NO_SUCH_FILE && - Status != STATUS_DLL_NOT_FOUND && - Status != STATUS_OBJECT_NAME_NOT_FOUND)) - { - DPRINT1("LDR: LdrAddRefDll(%p) 0x%08lx\n", BaseAddress); - } - } - - /* Release the lock if needed */ - if (Locked) LdrUnlockLoaderLock(LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS, Cookie); - - return Status; + ASSERT(StringIn != NULL); + + /* If Buffer is not NULL - free it */ + if (StringIn->Buffer) + { + RtlFreeHeap(RtlGetProcessHeap(), 0, StringIn->Buffer); + } + + /* Zero it out */ + RtlInitEmptyUnicodeString(StringIn, NULL, 0); } - -BOOLEAN -NTAPI -LdrpFreeUnicodeString(PUNICODE_STRING String) -{ - BOOLEAN Result = FALSE; - - ASSERT(String != NULL); - - /* If Buffer is not NULL - free it */ - if (String->Buffer) - Result = RtlFreeHeap(RtlGetProcessHeap(), 0, String->Buffer); - - /* Zero it out */ - String->Length = 0; - String->MaximumLength = 0; - String->Buffer = NULL; - - return Result; -} - /* EOF */ Modified: trunk/reactos/include/ndk/ldrtypes.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/ldrtypes.h?rev…
============================================================================== --- trunk/reactos/include/ndk/ldrtypes.h [iso-8859-1] (original) +++ trunk/reactos/include/ndk/ldrtypes.h [iso-8859-1] Sun Jul 10 01:34:19 2011 @@ -66,7 +66,7 @@ // // LdrAddRef Flags // -#define LDR_PIN_MODULE 0x00000001 +#define LDR_ADDREF_DLL_PIN 0x00000001 // // LdrLockLoaderLock Flags @@ -84,6 +84,7 @@ // #define LDR_GET_DLL_HANDLE_EX_UNCHANGED_REFCOUNT 0x00000001 #define LDR_GET_DLL_HANDLE_EX_PIN 0x00000002 + #define LDR_LOCK_LOADER_LOCK_DISPOSITION_INVALID 0 #define LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_ACQUIRED 1 @@ -216,4 +217,14 @@ typedef VOID (NTAPI LDR_ENUM_CALLBACK)(IN PLDR_DATA_TABLE_ENTRY ModuleInformation, IN PVOID Parameter, OUT BOOLEAN *Stop); typedef LDR_ENUM_CALLBACK *PLDR_ENUM_CALLBACK; +// +// DLL Main Routine +// +typedef BOOLEAN +(NTAPI *PDLL_INIT_ROUTINE)( + IN PVOID DllHandle, + IN ULONG Reason, + IN PCONTEXT Context OPTIONAL +); + #endif
13 years, 5 months
1
0
0
0
[cmihail] 52594: [IP/lwIP] - Fix graceful closure hanging bug
by cmihail@svn.reactos.org
Author: cmihail Date: Sun Jul 10 00:38:29 2011 New Revision: 52594 URL:
http://svn.reactos.org/svn/reactos?rev=52594&view=rev
Log: [IP/lwIP] - Fix graceful closure hanging bug Modified: branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/event.c branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rostcp.c Modified: branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/event.c URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/lib/drive…
============================================================================== --- branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/event.c [iso-8859-1] (original) +++ branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/event.c [iso-8859-1] Sun Jul 10 00:38:29 2011 @@ -90,11 +90,18 @@ Bucket->Status = Status; Bucket->Information = 0; - CompleteBucket(Connection, Bucket, TRUE); - } - + CompleteBucket(Connection, Bucket, FALSE); + } + + /* Calling with Status == STATUS_SUCCESS means that we got a graceful closure + * so we don't want to kill everything else since send is still valid in this state + */ if (Status == STATUS_SUCCESS) - Status = STATUS_FILE_CLOSED; + { + DbgPrint("[IP, FlushAllQueues] Flushed recv only after graceful closure\n"); + DereferenceObject(Connection); + return; + } while ((Entry = ExInterlockedRemoveHeadList(&Connection->ListenRequest, &Connection->Lock))) { @@ -106,7 +113,7 @@ DbgPrint("[IP, FlushAllQueues] Completing Listen request for Connection = 0x%x\n", Bucket->AssociatedEndpoint); DereferenceObject(Bucket->AssociatedEndpoint); - CompleteBucket(Connection, Bucket, TRUE); + CompleteBucket(Connection, Bucket, FALSE); } while ((Entry = ExInterlockedRemoveHeadList(&Connection->SendRequest, &Connection->Lock))) @@ -120,7 +127,7 @@ Bucket->Status = Status; Bucket->Information = 0; - CompleteBucket(Connection, Bucket, TRUE); + CompleteBucket(Connection, Bucket, FALSE); } while ((Entry = ExInterlockedRemoveHeadList(&Connection->ConnectRequest, &Connection->Lock))) @@ -132,7 +139,7 @@ DbgPrint("[IP, FlushAllQueues] Completing Connection request for Connection = 0x%x\n", Bucket->AssociatedEndpoint); - CompleteBucket(Connection, Bucket, TRUE); + CompleteBucket(Connection, Bucket, FALSE); } DereferenceObject(Connection); @@ -145,8 +152,12 @@ { PCONNECTION_ENDPOINT Connection = arg; - /* We're already closed so we don't want to call lwip_close */ - Connection->SocketContext = NULL; + /* Only clear the pointer if the shutdown was caused by an error */ + if (err != ERR_OK) + { + /* We're already closed by the error so we don't want to call lwip_close */ + Connection->SocketContext = NULL; + } DbgPrint("[IP, TCPFinEventHandler] Called for Connection( 0x%x )-> SocketContext = pcb (0x%x)\n", Connection, Connection->SocketContext); Modified: branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rostcp.c URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/lib/drive…
============================================================================== --- branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rostcp.c [iso-8859-1] (original) +++ branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rostcp.c [iso-8859-1] Sun Jul 10 00:38:29 2011 @@ -127,8 +127,11 @@ } else if (err == ERR_OK) { + /* Complete pending reads with 0 bytes to indicate a graceful closure, + * but note that send is still possible in this state so we don't close the + * whole socket here (by calling tcp_close()) as that would violate TCP specs + */ TCPFinEventHandler(arg, ERR_OK); - tcp_close(pcb); } DbgPrint("[lwIP, InternalRecvEventHandler] Done ERR_OK 3\n");
13 years, 5 months
1
0
0
0
← Newer
1
...
39
40
41
42
43
44
45
...
52
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Results per page:
10
25
50
100
200