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
October 2013
----- 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
14 participants
325 discussions
Start a n
N
ew thread
[aandrejevic] 60801: [NTVDM] Fix an EOI condition in the BIOS IRQ handler.
by aandrejevic@svn.reactos.org
Author: aandrejevic Date: Wed Oct 30 22:42:32 2013 New Revision: 60801 URL:
http://svn.reactos.org/svn/reactos?rev=60801&view=rev
Log: [NTVDM] Fix an EOI condition in the BIOS IRQ handler. Modified: branches/ntvdm/subsystems/ntvdm/bios.c Modified: branches/ntvdm/subsystems/ntvdm/bios.c URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/bios.c?r…
============================================================================== --- branches/ntvdm/subsystems/ntvdm/bios.c [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/bios.c [iso-8859-1] Wed Oct 30 22:42:32 2013 @@ -1170,7 +1170,7 @@ } /* Send End-of-Interrupt to the PIC */ - if (IrqNumber > 8) PicWriteCommand(PIC_SLAVE_CMD, PIC_OCW2_EOI); + if (IrqNumber >= 8) PicWriteCommand(PIC_SLAVE_CMD, PIC_OCW2_EOI); PicWriteCommand(PIC_MASTER_CMD, PIC_OCW2_EOI); }
11 years, 1 month
1
0
0
0
[ekohl] 60800: [ADVAPI32] Enable the new SAM-based logon system. Using your own accounts to log-on to ReactOS will still fail because of bugs in winlogon, userenv.dll and the registry. But at least...
by ekohl@svn.reactos.org
Author: ekohl Date: Wed Oct 30 21:19:03 2013 New Revision: 60800 URL:
http://svn.reactos.org/svn/reactos?rev=60800&view=rev
Log: [ADVAPI32] Enable the new SAM-based logon system. Using your own accounts to log-on to ReactOS will still fail because of bugs in winlogon, userenv.dll and the registry. But at least the infrastructure is in place and we can start to fix the reamining bugs. All accounts still use a hard-coded privilege set, but this will be fixed as soon as possible. Modified: trunk/reactos/boot/bootdata/hivesft.inf trunk/reactos/dll/win32/advapi32/CMakeLists.txt trunk/reactos/dll/win32/advapi32/misc/logon.c Modified: trunk/reactos/boot/bootdata/hivesft.inf URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/bootdata/hivesft.inf?…
============================================================================== --- trunk/reactos/boot/bootdata/hivesft.inf [iso-8859-1] (original) +++ trunk/reactos/boot/bootdata/hivesft.inf [iso-8859-1] Wed Oct 30 21:19:03 2013 @@ -324,7 +324,7 @@ "81d", "125",\ "422", "125",\ "402", "125",\ - "427", "125",\ + "427", "125",\ "408", "130",\ "41f", "130",\ "418", "130",\ @@ -1067,7 +1067,8 @@ HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","Userinit",0x00020000,"%SystemRoot%\system32\userinit.exe" HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","AutoAdminLogon",0x00000000,"1" HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","DefaultUserName",0x00000000,"Administrator" -HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","DefaultPassword",0x00000000,"Secret" +;HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","DefaultPassword",0x00000000,"Secret" +HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","DefaultPassword",0x00000000,"" ; Time Zone Servers HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\DateTime\Servers","1",0x00000000,"
pool.ntp.org
" Modified: trunk/reactos/dll/win32/advapi32/CMakeLists.txt URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/CMakeLi…
============================================================================== --- trunk/reactos/dll/win32/advapi32/CMakeLists.txt [iso-8859-1] (original) +++ trunk/reactos/dll/win32/advapi32/CMakeLists.txt [iso-8859-1] Wed Oct 30 21:19:03 2013 @@ -58,7 +58,7 @@ set_module_type(advapi32 win32dll UNICODE) target_link_libraries(advapi32 wine ${PSEH_LIB}) add_delay_importlibs(advapi32 rpcrt4) -add_importlibs(advapi32 msvcrt kernel32 ntdll) +add_importlibs(advapi32 secur32 msvcrt kernel32 ntdll) add_pch(advapi32 advapi32.h ${CMAKE_CURRENT_BINARY_DIR}/lsa_c.h Modified: trunk/reactos/dll/win32/advapi32/misc/logon.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/misc/lo…
============================================================================== --- trunk/reactos/dll/win32/advapi32/misc/logon.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/advapi32/misc/logon.c [iso-8859-1] Wed Oct 30 21:19:03 2013 @@ -9,6 +9,7 @@ #include <advapi32.h> WINE_DEFAULT_DEBUG_CHANNEL(advapi); +#define NEW_LOGON /* FUNCTIONS ***************************************************************/ @@ -212,6 +213,7 @@ } +#ifndef NEW_LOGON static BOOL WINAPI GetAccountDomainSid(PSID *Sid) { @@ -565,6 +567,7 @@ RtlFreeHeap(GetProcessHeap(), 0, TokenGroups); } +#endif /* @@ -578,6 +581,196 @@ DWORD dwLogonProvider, PHANDLE phToken) { +#ifdef NEW_LOGON + LSA_STRING LogonProcessName; + LSA_STRING PackageName; + HANDLE LsaHandle = NULL; + LSA_OPERATIONAL_MODE SecurityMode = 0; + ULONG AuthenticationPackage = 0; + + LSA_STRING OriginName; + UNICODE_STRING DomainName; + UNICODE_STRING UserName; + UNICODE_STRING Password; + PMSV1_0_INTERACTIVE_LOGON AuthInfo = NULL; + ULONG AuthInfoLength; + ULONG_PTR Ptr; + TOKEN_SOURCE TokenSource; + + PMSV1_0_INTERACTIVE_PROFILE ProfileBuffer = NULL; + ULONG ProfileBufferLength = 0; + LUID Luid = {0, 0}; + HANDLE TokenHandle = NULL; + QUOTA_LIMITS QuotaLimits; + NTSTATUS SubStatus = STATUS_SUCCESS; + NTSTATUS Status; + + *phToken = NULL; + + RtlInitAnsiString((PANSI_STRING)&LogonProcessName, + "User32LogonProcess"); + + Status = LsaRegisterLogonProcess(&LogonProcessName, + &LsaHandle, + &SecurityMode); + if (!NT_SUCCESS(Status)) + { + TRACE("LsaRegisterLogonProcess failed (Status 0x%08lx)\n", Status); + goto done; + } + + RtlInitAnsiString((PANSI_STRING)&PackageName, + MSV1_0_PACKAGE_NAME); + + Status = LsaLookupAuthenticationPackage(LsaHandle, + &PackageName, + &AuthenticationPackage); + if (!NT_SUCCESS(Status)) + { + TRACE("LsaLookupAuthenticationPackage failed (Status 0x%08lx)\n", Status); + goto done; + } + + TRACE("AuthenticationPackage: 0x%08lx\n", AuthenticationPackage); + + + RtlInitAnsiString((PANSI_STRING)&OriginName, + "Testapp"); + + RtlInitUnicodeString(&DomainName, + lpszDomain); + + RtlInitUnicodeString(&UserName, + lpszUsername); + + RtlInitUnicodeString(&Password, + lpszPassword); + + AuthInfoLength = sizeof(MSV1_0_INTERACTIVE_LOGON)+ + DomainName.MaximumLength + + UserName.MaximumLength + + Password.MaximumLength; + + AuthInfo = RtlAllocateHeap(RtlGetProcessHeap(), + HEAP_ZERO_MEMORY, + AuthInfoLength); + if (AuthInfo == NULL) + { + Status = STATUS_INSUFFICIENT_RESOURCES; + goto done; + } + + + AuthInfo->MessageType = MsV1_0InteractiveLogon; + + Ptr = (ULONG_PTR)AuthInfo + sizeof(MSV1_0_INTERACTIVE_LOGON); + + AuthInfo->LogonDomainName.Length = DomainName.Length; + AuthInfo->LogonDomainName.MaximumLength = DomainName.MaximumLength; + AuthInfo->LogonDomainName.Buffer = (DomainName.Buffer == NULL) ? NULL : (PWCHAR)Ptr; + if (DomainName.MaximumLength > 0) + { + RtlCopyMemory(AuthInfo->LogonDomainName.Buffer, + DomainName.Buffer, + DomainName.MaximumLength); + + Ptr += DomainName.MaximumLength; + } + + AuthInfo->UserName.Length = UserName.Length; + AuthInfo->UserName.MaximumLength = UserName.MaximumLength; + AuthInfo->UserName.Buffer = (PWCHAR)Ptr; + if (UserName.MaximumLength > 0) + RtlCopyMemory(AuthInfo->UserName.Buffer, + UserName.Buffer, + UserName.MaximumLength); + + Ptr += UserName.MaximumLength; + + AuthInfo->Password.Length = Password.Length; + AuthInfo->Password.MaximumLength = Password.MaximumLength; + AuthInfo->Password.Buffer = (PWCHAR)Ptr; + if (Password.MaximumLength > 0) + RtlCopyMemory(AuthInfo->Password.Buffer, + Password.Buffer, + Password.MaximumLength); + + /* FIXME: Add LocalGroups here */ + + strcpy(TokenSource.SourceName, "Bla"); + AllocateLocallyUniqueId(&TokenSource.SourceIdentifier); + + Status = LsaLogonUser(LsaHandle, + &OriginName, + Interactive, + AuthenticationPackage, + (PVOID)AuthInfo, + AuthInfoLength, + NULL, /* LocalGroups */ + &TokenSource, + (PVOID*)&ProfileBuffer, + &ProfileBufferLength, + &Luid, + &TokenHandle, + &QuotaLimits, + &SubStatus); + if (!NT_SUCCESS(Status)) + { + TRACE("LsaLogonUser failed (Status 0x%08lx)\n", Status); + goto done; + } + + if (ProfileBuffer != NULL) + { + TRACE("ProfileBuffer: %p\n", ProfileBuffer); + TRACE("MessageType: %u\n", ProfileBuffer->MessageType); + + TRACE("FullName: %p\n", ProfileBuffer->FullName.Buffer); + TRACE("FullName: %S\n", ProfileBuffer->FullName.Buffer); + + TRACE("LogonServer: %p\n", ProfileBuffer->LogonServer.Buffer); + TRACE("LogonServer: %S\n", ProfileBuffer->LogonServer.Buffer); + } + + TRACE("Luid: 0x%08lx%08lx\n", Luid.HighPart, Luid.LowPart); + + if (TokenHandle != NULL) + { + TRACE("TokenHandle: %p\n", TokenHandle); + } + + *phToken = TokenHandle; + +done: + if (ProfileBuffer != NULL) + LsaFreeReturnBuffer(ProfileBuffer); + + if (!NT_SUCCESS(Status)) + { + if (TokenHandle != NULL) + CloseHandle(TokenHandle); + } + + if (AuthInfo != NULL) + RtlFreeHeap(RtlGetProcessHeap(), 0, AuthInfo); + + if (LsaHandle != NULL) + { + Status = LsaDeregisterLogonProcess(LsaHandle); + if (!NT_SUCCESS(Status)) + { + TRACE("LsaDeregisterLogonProcess failed (Status 0x%08lx)\n", Status); + } + } + + if (!NT_SUCCESS(Status)) + { + SetLastError(RtlNtStatusToDosError(Status)); + return FALSE; + } + + return TRUE; +#else /* FIXME shouldn't use hard-coded list of privileges */ static struct { @@ -776,6 +969,7 @@ RtlFreeHeap(GetProcessHeap(), 0, UserSid); return NT_SUCCESS(Status); +#endif } /* EOF */
11 years, 1 month
1
0
0
0
[pschweitzer] 60799: [PSAPI] void -> VOID
by pschweitzer@svn.reactos.org
Author: pschweitzer Date: Wed Oct 30 17:59:20 2013 New Revision: 60799 URL:
http://svn.reactos.org/svn/reactos?rev=60799&view=rev
Log: [PSAPI] void -> VOID Modified: trunk/reactos/dll/win32/psapi/psapi.c Modified: trunk/reactos/dll/win32/psapi/psapi.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/psapi/psapi.c?re…
============================================================================== --- trunk/reactos/dll/win32/psapi/psapi.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/psapi/psapi.c [iso-8859-1] Wed Oct 30 17:59:20 2013 @@ -249,8 +249,8 @@ /* * @unimplemented */ -static void NTAPI -PsParseCommandLine(void) +static VOID NTAPI +PsParseCommandLine(VOID) { UNIMPLEMENTED; } @@ -258,8 +258,8 @@ /* * @unimplemented */ -static void NTAPI -PsInitializeAndStartProfile(void) +static VOID NTAPI +PsInitializeAndStartProfile(VOID) { UNIMPLEMENTED; } @@ -267,8 +267,8 @@ /* * @unimplemented */ -static void NTAPI -PsStopAndAnalyzeProfile(void) +static VOID NTAPI +PsStopAndAnalyzeProfile(VOID) { UNIMPLEMENTED; }
11 years, 1 month
1
0
0
0
[pschweitzer] 60798: [NTOSKRNL] Implement a helper function ExpConvertLdrModuleToRtlModule() that converts a Ldr represented module to a Rtl represented module (structure matters). Use it for kerne...
by pschweitzer@svn.reactos.org
Author: pschweitzer Date: Wed Oct 30 17:56:25 2013 New Revision: 60798 URL:
http://svn.reactos.org/svn/reactos?rev=60798&view=rev
Log: [NTOSKRNL] Implement a helper function ExpConvertLdrModuleToRtlModule() that converts a Ldr represented module to a Rtl represented module (structure matters). Use it for kernel modules list AND user modules list. This fixes the FIXME of that section but it actually doesn't fix anything given that our user module lists is still empty (whereas it should be filled in). Modified: trunk/reactos/ntoskrnl/ex/sysinfo.c Modified: trunk/reactos/ntoskrnl/ex/sysinfo.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/sysinfo.c?rev=…
============================================================================== --- trunk/reactos/ntoskrnl/ex/sysinfo.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/ex/sysinfo.c [iso-8859-1] Wed Oct 30 17:56:25 2013 @@ -21,6 +21,62 @@ ERESOURCE ExpFirmwareTableResource; LIST_ENTRY ExpFirmwareTableProviderListHead; +FORCEINLINE +NTSTATUS +ExpConvertLdrModuleToRtlModule(IN ULONG ModuleCount, + IN PLDR_DATA_TABLE_ENTRY LdrEntry, + OUT PRTL_PROCESS_MODULE_INFORMATION ModuleInfo) +{ + PCHAR p; + NTSTATUS Status; + ANSI_STRING ModuleName; + + /* Fill it out */ + ModuleInfo->MappedBase = NULL; + ModuleInfo->ImageBase = LdrEntry->DllBase; + ModuleInfo->ImageSize = LdrEntry->SizeOfImage; + ModuleInfo->Flags = LdrEntry->Flags; + ModuleInfo->LoadCount = LdrEntry->LoadCount; + ModuleInfo->LoadOrderIndex = (USHORT)ModuleCount; + ModuleInfo->InitOrderIndex = 0; + + /* Setup name */ + RtlInitEmptyAnsiString(&ModuleName, + ModuleInfo->FullPathName, + sizeof(ModuleInfo->FullPathName)); + + /* Convert it */ + Status = RtlUnicodeStringToAnsiString(&ModuleName, + &LdrEntry->FullDllName, + FALSE); + if ((NT_SUCCESS(Status)) || (Status == STATUS_BUFFER_OVERFLOW)) + { + /* Calculate offset to name */ + p = ModuleName.Buffer + ModuleName.Length; + while ((p > ModuleName.Buffer) && (*--p)) + { + /* Check if we found the separator */ + if (*p == OBJ_NAME_PATH_SEPARATOR) + { + /* We did, break out */ + p++; + break; + } + } + + /* Set the offset */ + ModuleInfo->OffsetToFileName = (USHORT)(p - ModuleName.Buffer); + } + else + { + /* Return empty name */ + ModuleInfo->FullPathName[0] = ANSI_NULL; + ModuleInfo->OffsetToFileName = 0; + } + + return Status; +} + NTSTATUS NTAPI ExpQueryModuleInformation(IN PLIST_ENTRY KernelModeList, @@ -33,10 +89,8 @@ ULONG RequiredLength; PRTL_PROCESS_MODULE_INFORMATION ModuleInfo; PLDR_DATA_TABLE_ENTRY LdrEntry; - ANSI_STRING ModuleName; ULONG ModuleCount = 0; PLIST_ENTRY NextEntry; - PCHAR p; /* Setup defaults */ RequiredLength = FIELD_OFFSET(RTL_PROCESS_MODULES, Modules); @@ -55,68 +109,56 @@ RequiredLength += sizeof(RTL_PROCESS_MODULE_INFORMATION); if (Length >= RequiredLength) { - /* Fill it out */ - ModuleInfo->MappedBase = NULL; - ModuleInfo->ImageBase = LdrEntry->DllBase; - ModuleInfo->ImageSize = LdrEntry->SizeOfImage; - ModuleInfo->Flags = LdrEntry->Flags; - ModuleInfo->LoadCount = LdrEntry->LoadCount; - ModuleInfo->LoadOrderIndex = (USHORT)ModuleCount; - ModuleInfo->InitOrderIndex = 0; - - /* Setup name */ - RtlInitEmptyAnsiString(&ModuleName, - ModuleInfo->FullPathName, - sizeof(ModuleInfo->FullPathName)); - - /* Convert it */ - Status = RtlUnicodeStringToAnsiString(&ModuleName, - &LdrEntry->FullDllName, - FALSE); - if ((NT_SUCCESS(Status)) || (Status == STATUS_BUFFER_OVERFLOW)) + Status = ExpConvertLdrModuleToRtlModule(ModuleCount, + LdrEntry, + ModuleInfo); + + /* Go to the next module */ + ModuleInfo++; + } + else + { + /* Set error code */ + Status = STATUS_INFO_LENGTH_MISMATCH; + } + + /* Update count and move to next entry */ + ModuleCount++; + NextEntry = NextEntry->Flink; + } + + /* Check if caller also wanted user modules */ + if (UserModeList) + { + NextEntry = UserModeList->Flink; + while (NextEntry != UserModeList) + { + /* Get the entry */ + LdrEntry = CONTAINING_RECORD(NextEntry, + LDR_DATA_TABLE_ENTRY, + InLoadOrderLinks); + + /* Update size and check if we can manage one more entry */ + RequiredLength += sizeof(RTL_PROCESS_MODULE_INFORMATION); + if (Length >= RequiredLength) { - /* Calculate offset to name */ - p = ModuleName.Buffer + ModuleName.Length; - while ((p > ModuleName.Buffer) && (*--p)) - { - /* Check if we found the separator */ - if (*p == OBJ_NAME_PATH_SEPARATOR) - { - /* We did, break out */ - p++; - break; - } - } - - /* Set the offset */ - ModuleInfo->OffsetToFileName = (USHORT)(p - ModuleName.Buffer); + Status = ExpConvertLdrModuleToRtlModule(ModuleCount, + LdrEntry, + ModuleInfo); + + /* Go to the next module */ + ModuleInfo++; } else { - /* Return empty name */ - ModuleInfo->FullPathName[0] = ANSI_NULL; - ModuleInfo->OffsetToFileName = 0; + /* Set error code */ + Status = STATUS_INFO_LENGTH_MISMATCH; } - /* Go to the next module */ - ModuleInfo++; - } - else - { - /* Set error code */ - Status = STATUS_INFO_LENGTH_MISMATCH; - } - - /* Update count and move to next entry */ - ModuleCount++; - NextEntry = NextEntry->Flink; - } - - /* Check if caller also wanted user modules */ - if (UserModeList) - { - /* FIXME: TODO */ - DPRINT1("User-mode list not yet supported in ReactOS!\n"); + /* Update count and move to next entry */ + ModuleCount++; + NextEntry = NextEntry->Flink; + } } /* Update return length */
11 years, 1 month
1
0
0
0
[pschweitzer] 60797: [PSAPI] Stub support for profiling
by pschweitzer@svn.reactos.org
Author: pschweitzer Date: Wed Oct 30 15:19:35 2013 New Revision: 60797 URL:
http://svn.reactos.org/svn/reactos?rev=60797&view=rev
Log: [PSAPI] Stub support for profiling Modified: trunk/reactos/dll/win32/psapi/psapi.c Modified: trunk/reactos/dll/win32/psapi/psapi.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/psapi/psapi.c?re…
============================================================================== --- trunk/reactos/dll/win32/psapi/psapi.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/psapi/psapi.c [iso-8859-1] Wed Oct 30 15:19:35 2013 @@ -18,22 +18,6 @@ #define MAX_MODULES 0x2710 // Matches 10.000 modules #define INIT_MEMORY_SIZE 0x1000 // Matches 4kB - -BOOLEAN -WINAPI -DllMain(HINSTANCE hDllHandle, - DWORD nReason, - LPVOID Reserved) -{ - switch(nReason) - { - case DLL_PROCESS_ATTACH: - DisableThreadLibraryCalls(hDllHandle); - break; - } - - return TRUE; -} /* INTERNAL *******************************************************************/ @@ -262,7 +246,66 @@ return Ret; } +/* + * @unimplemented + */ +static void NTAPI +PsParseCommandLine(void) +{ + UNIMPLEMENTED; +} + +/* + * @unimplemented + */ +static void NTAPI +PsInitializeAndStartProfile(void) +{ + UNIMPLEMENTED; +} + +/* + * @unimplemented + */ +static void NTAPI +PsStopAndAnalyzeProfile(void) +{ + UNIMPLEMENTED; +} + /* PUBLIC *********************************************************************/ + +/* + * @implemented + */ +BOOLEAN +WINAPI +DllMain(HINSTANCE hDllHandle, + DWORD nReason, + LPVOID Reserved) +{ + switch(nReason) + { + case DLL_PROCESS_ATTACH: + DisableThreadLibraryCalls(hDllHandle); + if (NtCurrentPeb()->ProcessParameters->Flags & RTL_USER_PROCESS_PARAMETERS_PROFILE_USER) + { + PsParseCommandLine(); + PsInitializeAndStartProfile(); + } + break; + + case DLL_PROCESS_DETACH: + if (NtCurrentPeb()->ProcessParameters->Flags & RTL_USER_PROCESS_PARAMETERS_PROFILE_USER) + { + PsStopAndAnalyzeProfile(); + } + break; + } + + return TRUE; +} + /* * @implemented
11 years, 1 month
1
0
0
0
[pschweitzer] 60796: [PSAPI] Reduce DLL verbosity
by pschweitzer@svn.reactos.org
Author: pschweitzer Date: Wed Oct 30 10:58:31 2013 New Revision: 60796 URL:
http://svn.reactos.org/svn/reactos?rev=60796&view=rev
Log: [PSAPI] Reduce DLL verbosity Modified: trunk/reactos/dll/win32/psapi/psapi.c Modified: trunk/reactos/dll/win32/psapi/psapi.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/psapi/psapi.c?re…
============================================================================== --- trunk/reactos/dll/win32/psapi/psapi.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/psapi/psapi.c [iso-8859-1] Wed Oct 30 10:58:31 2013 @@ -749,7 +749,7 @@ DWORD Len; LPWSTR FileName; - DPRINT1("GetMappedFileNameA(%p, %p, %p, %lu)\n", hProcess, lpv, lpFilename, nSize); + DPRINT("GetMappedFileNameA(%p, %p, %p, %lu)\n", hProcess, lpv, lpFilename, nSize); /* Allocate internal buffer for conversion */ FileName = LocalAlloc(LMEM_FIXED, nSize * sizeof(WCHAR)); @@ -760,9 +760,6 @@ /* Call W API */ Len = GetMappedFileNameW(hProcess, lpv, FileName, nSize); - - DPRINT1("Got: %wS\n", FileName); - DPRINT1("Len: %lu\n", Len); /* And convert output */ if (WideCharToMultiByte(CP_ACP, 0, FileName, (Len < nSize) ? Len + 1 : Len, lpFilename, nSize, NULL, NULL) == 0) @@ -794,7 +791,7 @@ WCHAR CharBuffer[MAX_PATH]; } SectionName; - DPRINT1("GetMappedFileNameW(%p, %p, %p, %lu)\n", hProcess, lpv, lpFilename, nSize); + DPRINT("GetMappedFileNameW(%p, %p, %p, %lu)\n", hProcess, lpv, lpFilename, nSize); /* If no buffer, no need to keep going on */ if (nSize == 0) @@ -808,13 +805,9 @@ &SectionName, sizeof(SectionName), &OutSize); if (!NT_SUCCESS(Status)) { - DPRINT1("Failed!\n"); SetLastError(RtlNtStatusToDosError(Status)); return 0; } - - DPRINT1("Found: %wZ\n", &SectionName.SectionFileName); - DPRINT1("Len = %lu, nSize = %lu\n", SectionName.SectionFileName.Length / sizeof(WCHAR), nSize); /* Prepare to copy file name */ Len =
11 years, 1 month
1
0
0
0
[pschweitzer] 60795: [PSAPI_WINETESTS] No need to skip these tests, they are working again. ROSTESTS-122
by pschweitzer@svn.reactos.org
Author: pschweitzer Date: Wed Oct 30 10:57:05 2013 New Revision: 60795 URL:
http://svn.reactos.org/svn/reactos?rev=60795&view=rev
Log: [PSAPI_WINETESTS] No need to skip these tests, they are working again. ROSTESTS-122 Modified: trunk/rostests/winetests/psapi/psapi_main.c Modified: trunk/rostests/winetests/psapi/psapi_main.c URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/winetests/psapi/psapi_mai…
============================================================================== --- trunk/rostests/winetests/psapi/psapi_main.c [iso-8859-1] (original) +++ trunk/rostests/winetests/psapi/psapi_main.c [iso-8859-1] Wed Oct 30 10:57:05 2013 @@ -105,12 +105,6 @@ HMODULE hMod = GetModuleHandle(NULL); DWORD ret, cbNeeded = 0xdeadbeef; - if (!winetest_interactive) - { - win_skip("Stack corruption - ROSTESTS-122\n"); - return; - } - SetLastError(0xdeadbeef); pEnumProcessModules(NULL, NULL, 0, &cbNeeded); ok(GetLastError() == ERROR_INVALID_HANDLE, "expected error=ERROR_INVALID_HANDLE but got %d\n", GetLastError());
11 years, 1 month
1
0
0
0
[pschweitzer] 60794: [PSAPI] Bye bye PSAPI. Welcome PSAPI :-). This is a rewrite of the PSAPI DLL to make it match the W2K3 DLL. It fixes several bugs and implements missing features. It doesn't us...
by pschweitzer@svn.reactos.org
Author: pschweitzer Date: Wed Oct 30 10:56:02 2013 New Revision: 60794 URL:
http://svn.reactos.org/svn/reactos?rev=60794&view=rev
Log: [PSAPI] Bye bye PSAPI. Welcome PSAPI :-). This is a rewrite of the PSAPI DLL to make it match the W2K3 DLL. It fixes several bugs and implements missing features. It doesn't use the EPSAPI library anylonger (which old and buggy). All winetests are passing when executed on W2K3 with this DLL. Not all tests are passing on ReactOS though, because of missing features in the kernel. Anyway, this greatly reduces the amount of failed tests. ROSTESTS-122 #comment Fixed with r60794 #resolve Removed: trunk/reactos/dll/win32/psapi/internal.h trunk/reactos/dll/win32/psapi/malloc.c Modified: trunk/reactos/dll/win32/psapi/CMakeLists.txt trunk/reactos/dll/win32/psapi/precomp.h trunk/reactos/dll/win32/psapi/psapi.c Modified: trunk/reactos/dll/win32/psapi/CMakeLists.txt URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/psapi/CMakeLists…
============================================================================== --- trunk/reactos/dll/win32/psapi/CMakeLists.txt [iso-8859-1] (original) +++ trunk/reactos/dll/win32/psapi/CMakeLists.txt [iso-8859-1] Wed Oct 30 10:56:02 2013 @@ -2,7 +2,6 @@ spec2def(psapi.dll psapi.spec ADD_IMPORTLIB) list(APPEND SOURCE - malloc.c psapi.c psapi.rc ${CMAKE_CURRENT_BINARY_DIR}/psapi.def) @@ -10,7 +9,7 @@ add_library(psapi SHARED ${SOURCE}) set_module_type(psapi win32dll) -target_link_libraries(psapi epsapi ${PSEH_LIB}) +target_link_libraries(psapi ${PSEH_LIB}) add_importlibs(psapi msvcrt kernel32 ntdll) add_pch(psapi precomp.h) Removed: trunk/reactos/dll/win32/psapi/internal.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/psapi/internal.h…
============================================================================== --- trunk/reactos/dll/win32/psapi/internal.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/psapi/internal.h (removed) @@ -1,33 +0,0 @@ -/* - * epsapi.h - * - * Process Status Helper API, native interface - * - * This file is part of the ReactOS Operating System. - * - * Contributors: - * Created by KJK::Hyperion <noog(a)libero.it> - * - * THIS SOFTWARE IS NOT COPYRIGHTED - * - * This source code is offered for use in the public domain. You may - * use, modify or distribute it freely. - * - * This code is distributed in the hope that it will be useful but - * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY - * DISCLAMED. This includes but is not limited to warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - */ - -#ifndef __INTERNAL_PSAPI_H_INCLUDED__ -#define __INTERNAL_PSAPI_H_INCLUDED__ - -#ifndef SetLastErrorByStatus -#define SetLastErrorByStatus(__S__) \ - ((void)SetLastError(RtlNtStatusToDosError(__S__))) -#endif /* SetLastErrorByStatus */ - -#endif /* __INTERNAL_PSAPI_H_INCLUDED__ */ - -/* EOF */ Removed: trunk/reactos/dll/win32/psapi/malloc.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/psapi/malloc.c?r…
============================================================================== --- trunk/reactos/dll/win32/psapi/malloc.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/psapi/malloc.c (removed) @@ -1,69 +0,0 @@ -/* - * COPYRIGHT: None - * LICENSE: Public domain - * PROJECT: ReactOS system libraries - * FILE: reactos/lib/psapi/misc/malloc.c - * PURPOSE: Memory allocator for PSAPI - * PROGRAMMER: KJK::Hyperion <noog(a)libero.it> - * UPDATE HISTORY: - * 10/06/2002: Created - * 12/02/2003: malloc and free renamed to PsaiMalloc and PsaiFree, - * for better reusability - */ - -#include "precomp.h" - -#define NDEBUG -#include <debug.h> - -PVOID -WINAPI -MemAlloc(IN HANDLE Heap, - IN PVOID Ptr, - IN ULONG Size) -{ - PVOID pBuf = NULL; - - if(Size == 0 && Ptr == NULL) - { - return NULL; - } - - if(Heap == NULL) - { - Heap = NtCurrentPeb()->ProcessHeap; - } - - if(Size > 0) - { - if(Ptr == NULL) - /* malloc */ - pBuf = RtlAllocateHeap(Heap, 0, Size); - else - /* realloc */ - pBuf = RtlReAllocateHeap(Heap, 0, Ptr, Size); - } - else - /* free */ - RtlFreeHeap(Heap, 0, Ptr); - - return pBuf; -} - -void *PsaiMalloc(SIZE_T size) -{ - return MemAlloc(NULL, NULL, size); -} - -void *PsaiRealloc(void *ptr, SIZE_T size) -{ - return MemAlloc(NULL, ptr, size); -} - -void PsaiFree(void *ptr) -{ - MemAlloc(NULL, ptr, 0); -} - -/* EOF */ - Modified: trunk/reactos/dll/win32/psapi/precomp.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/psapi/precomp.h?…
============================================================================== --- trunk/reactos/dll/win32/psapi/precomp.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/psapi/precomp.h [iso-8859-1] Wed Oct 30 10:56:02 2013 @@ -10,8 +10,5 @@ #include <ndk/rtlfuncs.h> #include <psapi.h> -#include <epsapi/epsapi.h> - -#include "internal.h" #include <pseh/pseh2.h> Modified: trunk/reactos/dll/win32/psapi/psapi.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/psapi/psapi.c?re…
============================================================================== --- trunk/reactos/dll/win32/psapi/psapi.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/psapi/psapi.c [iso-8859-1] Wed Oct 30 10:56:02 2013 @@ -6,6 +6,7 @@ * PURPOSE: Win32 interfaces for PSAPI * PROGRAMMER: KJK::Hyperion <noog(a)libero.it> * Thomas Weidenmueller <w3seek(a)reactos.com> + * Pierre Schweitzer <pierre(a)reactos.org> * UPDATE HISTORY: * 10/06/2002: Created */ @@ -14,6 +15,9 @@ #define NDEBUG #include <debug.h> + +#define MAX_MODULES 0x2710 // Matches 10.000 modules +#define INIT_MEMORY_SIZE 0x1000 // Matches 4kB BOOLEAN WINAPI @@ -33,591 +37,229 @@ /* INTERNAL *******************************************************************/ -typedef struct _ENUM_DEVICE_DRIVERS_CONTEXT -{ - LPVOID *lpImageBase; - DWORD nCount; - DWORD nTotal; -} ENUM_DEVICE_DRIVERS_CONTEXT, *PENUM_DEVICE_DRIVERS_CONTEXT; - -NTSTATUS WINAPI -EnumDeviceDriversCallback(IN PRTL_PROCESS_MODULE_INFORMATION CurrentModule, - IN OUT PVOID CallbackContext) -{ - PENUM_DEVICE_DRIVERS_CONTEXT Context = (PENUM_DEVICE_DRIVERS_CONTEXT)CallbackContext; - - /* check if more buffer space is available */ - if(Context->nCount != 0) - { - /* return current module */ - *Context->lpImageBase = CurrentModule->ImageBase; - - /* go to next array slot */ - Context->lpImageBase++; - Context->nCount--; - } - - Context->nTotal++; - return STATUS_SUCCESS; -} - - -typedef struct _ENUM_PROCESSES_CONTEXT -{ - DWORD *lpidProcess; - DWORD nCount; -} ENUM_PROCESSES_CONTEXT, *PENUM_PROCESSES_CONTEXT; - -NTSTATUS WINAPI -EnumProcessesCallback(IN PSYSTEM_PROCESS_INFORMATION CurrentProcess, - IN OUT PVOID CallbackContext) -{ - PENUM_PROCESSES_CONTEXT Context = (PENUM_PROCESSES_CONTEXT)CallbackContext; - - /* no more buffer space */ - if(Context->nCount == 0) - { - return STATUS_INFO_LENGTH_MISMATCH; - } - - /* return current process */ - *Context->lpidProcess = (DWORD_PTR)CurrentProcess->UniqueProcessId; - - /* go to next array slot */ - Context->lpidProcess++; - Context->nCount--; - - return STATUS_SUCCESS; -} - - -typedef struct _ENUM_PROCESS_MODULES_CONTEXT -{ - HMODULE *lphModule; - DWORD nCount; - DWORD nTotal; -} ENUM_PROCESS_MODULES_CONTEXT, *PENUM_PROCESS_MODULES_CONTEXT; - -NTSTATUS WINAPI -EnumProcessModulesCallback(IN HANDLE ProcessHandle, - IN PLDR_DATA_TABLE_ENTRY CurrentModule, - IN OUT PVOID CallbackContext) -{ - PENUM_PROCESS_MODULES_CONTEXT Context = (PENUM_PROCESS_MODULES_CONTEXT)CallbackContext; - - /* check if more buffer space is available */ - if(Context->nCount != 0) - { - /* return current process */ - *Context->lphModule = CurrentModule->DllBase; - - /* go to next array slot */ - Context->lphModule++; - Context->nCount--; - } - - Context->nTotal++; - return STATUS_SUCCESS; -} - - -typedef struct _GET_DEVICE_DRIVER_NAME_CONTEXT -{ - LPVOID ImageBase; - struct - { - ULONG bFullName : sizeof(ULONG) * 8 / 2; - ULONG bUnicode : sizeof(ULONG) * 8 / 2; - }; - DWORD nSize; - union - { - LPVOID lpName; - LPSTR lpAnsiName; - LPWSTR lpUnicodeName; - }; -} GET_DEVICE_DRIVER_NAME_CONTEXT, *PGET_DEVICE_DRIVER_NAME_CONTEXT; - -NTSTATUS WINAPI -GetDeviceDriverNameCallback(IN PRTL_PROCESS_MODULE_INFORMATION CurrentModule, - IN OUT PVOID CallbackContext) -{ - PGET_DEVICE_DRIVER_NAME_CONTEXT Context = (PGET_DEVICE_DRIVER_NAME_CONTEXT)CallbackContext; - - /* module found */ - if(Context->ImageBase == CurrentModule->ImageBase) - { - PCHAR pcModuleName; - ULONG l; - - /* get the full name or just the filename part */ - if(Context->bFullName) - pcModuleName = &CurrentModule->FullPathName[0]; - else - pcModuleName = &CurrentModule->FullPathName[CurrentModule->OffsetToFileName]; - - /* get the length of the name */ - l = strlen(pcModuleName); - - if(Context->nSize <= l) - { - /* use the user buffer's length */ - l = Context->nSize; - } - else - { - /* enough space for the null terminator */ - Context->nSize = ++l; - } - - /* copy the string */ - if(Context->bUnicode) - { - ANSI_STRING AnsiString; - UNICODE_STRING UnicodeString; - - UnicodeString.Length = 0; - UnicodeString.MaximumLength = l * sizeof(WCHAR); - UnicodeString.Buffer = Context->lpUnicodeName; - - RtlInitAnsiString(&AnsiString, pcModuleName); - /* driver names should always be in language-neutral ASCII, so we don't - bother calling AreFileApisANSI() */ - RtlAnsiStringToUnicodeString(&UnicodeString, &AnsiString, FALSE); - } - else - { - memcpy(Context->lpAnsiName, pcModuleName, l); - } - - /* terminate the enumeration */ - return STATUS_NO_MORE_FILES; - } - else - { - /* continue searching */ - return STATUS_SUCCESS; - } -} - - -static DWORD -InternalGetDeviceDriverName(BOOLEAN bUnicode, - BOOLEAN bFullName, - LPVOID ImageBase, - LPVOID lpName, - DWORD nSize) -{ - GET_DEVICE_DRIVER_NAME_CONTEXT Context; - NTSTATUS Status; - - if(lpName == NULL || nSize == 0) - { - return 0; - } - - if(ImageBase == NULL) - { +/* + * @implemented + */ +static BOOL NTAPI +FindDeviceDriver(IN PVOID ImageBase, + OUT PRTL_PROCESS_MODULE_INFORMATION MatchingModule) +{ + NTSTATUS Status; + DWORD NewSize, Count; + PRTL_PROCESS_MODULES Information; + RTL_PROCESS_MODULE_INFORMATION Module; + /* By default, to prevent too many reallocations, we already make room for 4 modules */ + DWORD Size = sizeof(RTL_PROCESS_MODULES) + 3 * sizeof(RTL_PROCESS_MODULE_INFORMATION); + + do + { + /* Allocate a buffer to hold modules information */ + Information = LocalAlloc(LMEM_FIXED, Size); + if (!Information) + { + SetLastError(ERROR_NO_SYSTEM_RESOURCES); + return FALSE; + } + + /* Query information */ + Status = NtQuerySystemInformation(SystemModuleInformation, Information, Size, &Count); + /* In case of an error */ + if (!NT_SUCCESS(Status)) + { + /* Save the amount of output modules */ + NewSize = Information->NumberOfModules; + /* And free buffer */ + LocalFree(Information); + + /* If it was not a length mismatch (ie, buffer too small), just leave */ + if (Status != STATUS_INFO_LENGTH_MISMATCH) + { + SetLastError(RtlNtStatusToDosError(Status)); + return FALSE; + } + + /* Compute new size length */ + ASSERT(Size >= sizeof(RTL_PROCESS_MODULES)); + NewSize *= sizeof(RTL_PROCESS_MODULE_INFORMATION); + NewSize += sizeof(ULONG); + ASSERT(NewSize >= sizeof(RTL_PROCESS_MODULES)); + /* Check whether it is really bigger - otherwise, leave */ + if (NewSize < Size) + { + ASSERT(NewSize > Size); + SetLastError(RtlNtStatusToDosError(STATUS_INFO_LENGTH_MISMATCH)); + return FALSE; + } + + /* Loop again with that new buffer */ + Size = NewSize; + continue; + } + + /* No modules returned? Leave */ + if (Information->NumberOfModules == 0) + { + break; + } + + /* Try to find which module matches the base address given */ + for (Count = 0; Count < Information->NumberOfModules; ++Count) + { + Module = Information->Modules[Count]; + if (Module.ImageBase == ImageBase) + { + /* Copy the matching module and leave */ + memcpy(MatchingModule, &Module, sizeof(Module)); + LocalFree(Information); + return TRUE; + } + } + + /* If we arrive here, it means we were not able to find matching base address */ + break; + } while (TRUE); + + /* Release and leave */ + LocalFree(Information); SetLastError(ERROR_INVALID_HANDLE); - return 0; - } - - Context.ImageBase = ImageBase; - Context.bFullName = bFullName; - Context.bUnicode = bUnicode; - Context.nSize = nSize; - Context.lpName = lpName; - - /* start the enumeration */ - Status = PsaEnumerateSystemModules(GetDeviceDriverNameCallback, &Context); - - if(Status == STATUS_NO_MORE_FILES) - { - /* module was found, return string size */ - return Context.nSize; - } - else if(NT_SUCCESS(Status)) - { - /* module was not found */ + + return FALSE; +} + +/* + * @implemented + */ +static BOOL NTAPI +FindModule(IN HANDLE hProcess, + IN HMODULE hModule OPTIONAL, + OUT PLDR_DATA_TABLE_ENTRY Module) +{ + DWORD Count; + NTSTATUS Status; + PPEB_LDR_DATA LoaderData; + PLIST_ENTRY ListHead, ListEntry; + PROCESS_BASIC_INFORMATION ProcInfo; + + /* Query the process information to get its PEB address */ + Status = NtQueryInformationProcess(hProcess, ProcessBasicInformation, &ProcInfo, sizeof(ProcInfo), NULL); + if (!NT_SUCCESS(Status)) + { + SetLastError(RtlNtStatusToDosError(Status)); + return FALSE; + } + + /* If no module was provided, get base as module */ + if (hModule == NULL) + { + if (!ReadProcessMemory(hProcess, &ProcInfo.PebBaseAddress->ImageBaseAddress, &hModule, sizeof(hModule), NULL)) + { + return FALSE; + } + } + + /* Read loader data address from PEB */ + if (!ReadProcessMemory(hProcess, &ProcInfo.PebBaseAddress->Ldr, &LoaderData, sizeof(LoaderData), NULL)) + { + return FALSE; + } + + if (LoaderData == NULL) + { + SetLastError(ERROR_INVALID_HANDLE); + return FALSE; + } + + /* Store list head address */ + ListHead = &(LoaderData->InMemoryOrderModuleList); + + /* Read first element in the modules list */ + if (!ReadProcessMemory(hProcess, + &(LoaderData->InMemoryOrderModuleList.Flink), + &ListEntry, + sizeof(ListEntry), + NULL)) + { + return FALSE; + } + + Count = 0; + + /* Loop on the modules */ + while (ListEntry != ListHead) + { + /* Load module data */ + if (!ReadProcessMemory(hProcess, + CONTAINING_RECORD(ListEntry, LDR_DATA_TABLE_ENTRY, InMemoryOrderModuleList), + Module, + sizeof(*Module), + NULL)) + { + return FALSE; + } + + /* Does that match the module we're looking for? */ + if (Module->DllBase == hModule) + { + return TRUE; + } + + ++Count; + if (Count > MAX_MODULES) + { + break; + } + + /* Get to next listed module */ + ListEntry = Module->InMemoryOrderModuleList.Flink; + } + SetLastError(ERROR_INVALID_HANDLE); - } - else - { - /* an error occurred */ - SetLastErrorByStatus(Status); - } - return 0; -} - - -static DWORD -InternalGetMappedFileName(BOOLEAN bUnicode, - HANDLE hProcess, - LPVOID lpv, - LPVOID lpName, - DWORD nSize) -{ - PMEMORY_SECTION_NAME pmsnName; - ULONG nBufSize; - NTSTATUS Status; - - if(nSize == 0 || lpName == NULL) - { - return 0; - } - - if(nSize > (0xFFFF / sizeof(WCHAR))) - { - /* if the user buffer contains more characters than would fit in an - UNICODE_STRING, limit the buffer size. RATIONALE: we don't limit buffer - size elsewhere because here superfluous buffer size will mean a larger - temporary buffer */ - nBufSize = 0xFFFF / sizeof(WCHAR); - } - else - { - nBufSize = nSize * sizeof(WCHAR); - } - - /* allocate the memory */ - pmsnName = PsaiMalloc(nBufSize + sizeof(MEMORY_SECTION_NAME)); - - if(pmsnName == NULL) - { - SetLastError(ERROR_OUTOFMEMORY); - return 0; - } - - /* initialize the destination buffer */ - pmsnName->SectionFileName.Length = 0; - pmsnName->SectionFileName.Length = nBufSize; - -#if 0 - __try - { -#endif - /* query the name */ - Status = NtQueryVirtualMemory(hProcess, - lpv, - MemorySectionName, - pmsnName, - nBufSize, - NULL); - if(!NT_SUCCESS(Status)) - { - PsaiFree(pmsnName); - SetLastErrorByStatus(Status); - return 0; - } - - if(bUnicode) - { - /* destination is an Unicode string: direct copy */ - memcpy((LPWSTR)lpName, pmsnName + 1, pmsnName->SectionFileName.Length); - - PsaiFree(pmsnName); - - if(pmsnName->SectionFileName.Length < nSize) - { - /* null-terminate the string */ - ((LPWSTR)lpName)[pmsnName->SectionFileName.Length] = 0; - return pmsnName->SectionFileName.Length + 1; - } - - return pmsnName->SectionFileName.Length; - } - else - { - ANSI_STRING AnsiString; - - AnsiString.Length = 0; - AnsiString.MaximumLength = nSize; - AnsiString.Buffer = (LPSTR)lpName; - - if(AreFileApisANSI()) - RtlUnicodeStringToAnsiString(&AnsiString, &pmsnName->SectionFileName, FALSE); - else - RtlUnicodeStringToOemString(&AnsiString, &pmsnName->SectionFileName, FALSE); - - PsaiFree(pmsnName); - - if(AnsiString.Length < nSize) - { - /* null-terminate the string */ - ((LPSTR)lpName)[AnsiString.Length] = 0; - return AnsiString.Length + 1; - } - - return AnsiString.Length; - } - -#if 0 - } - __finally - { - PsaiFree(pmsnName); - } -#endif -} - - -typedef struct _GET_MODULE_INFORMATION_FLAGS -{ - ULONG bWantName : sizeof(ULONG) * 8 / 4; - ULONG bUnicode : sizeof(ULONG) * 8 / 4; - ULONG bFullName : sizeof(ULONG) * 8 / 4; -} GET_MODULE_INFORMATION_FLAGS, *PGET_MODULE_INFORMATION_FLAGS; - -typedef struct _GET_MODULE_INFORMATION_CONTEXT -{ - HMODULE hModule; - GET_MODULE_INFORMATION_FLAGS Flags; - DWORD nBufSize; - union - { - LPWSTR lpUnicodeName; - LPSTR lpAnsiName; - LPMODULEINFO lpmodinfo; - LPVOID lpBuffer; - }; -} GET_MODULE_INFORMATION_CONTEXT, *PGET_MODULE_INFORMATION_CONTEXT; - -NTSTATUS WINAPI -GetModuleInformationCallback(IN HANDLE ProcessHandle, - IN PLDR_DATA_TABLE_ENTRY CurrentModule, - IN OUT PVOID CallbackContext) -{ - PGET_MODULE_INFORMATION_CONTEXT Context = (PGET_MODULE_INFORMATION_CONTEXT)CallbackContext; - - /* found the module we were looking for */ - if(CurrentModule->DllBase == Context->hModule) - { - /* we want the module name */ - if(Context->Flags.bWantName) - { - PUNICODE_STRING SourceString; - ULONG l; - NTSTATUS Status; - - if(Context->Flags.bFullName) - SourceString = &(CurrentModule->FullDllName); - else - SourceString = &(CurrentModule->BaseDllName); - - SourceString->Length -= SourceString->Length % sizeof(WCHAR); - - /* l is the byte size of the user buffer */ - l = Context->nBufSize * sizeof(WCHAR); - - /* if the user buffer has room for the string and a null terminator */ - if(l >= (SourceString->Length + sizeof(WCHAR))) - { - /* limit the buffer size */ - l = SourceString->Length; - - /* null-terminate the string */ - if(Context->Flags.bUnicode) - Context->lpUnicodeName[l / sizeof(WCHAR)] = 0; - else - Context->lpAnsiName[l / sizeof(WCHAR)] = 0; - } - - if(Context->Flags.bUnicode) - { - /* Unicode: direct copy */ - /* NOTE: I've chosen not to check for ProcessHandle == NtCurrentProcess(), - this function is complicated enough as it is */ - Status = NtReadVirtualMemory(ProcessHandle, - SourceString->Buffer, - Context->lpUnicodeName, - l, - NULL); - - if(!NT_SUCCESS(Status)) - { - Context->nBufSize = 0; - return Status; - } - - Context->nBufSize = l / sizeof(WCHAR); - } - else - { - /* ANSI/OEM: convert and copy */ - LPWSTR pwcUnicodeBuf; - ANSI_STRING AnsiString; - UNICODE_STRING UnicodeString; - - AnsiString.Length = 0; - AnsiString.MaximumLength = Context->nBufSize; - AnsiString.Buffer = Context->lpAnsiName; - - /* allocate the local buffer */ - pwcUnicodeBuf = PsaiMalloc(SourceString->Length); - -#if 0 - __try - { -#endif - if(pwcUnicodeBuf == NULL) - { - Status = STATUS_NO_MEMORY; - goto exitWithStatus; - } - - /* copy the string in the local buffer */ - Status = NtReadVirtualMemory(ProcessHandle, - SourceString->Buffer, - pwcUnicodeBuf, - l, - NULL); - - if(!NT_SUCCESS(Status)) - { - goto exitWithStatus; - } - - /* initialize Unicode string buffer */ - UnicodeString.Length = UnicodeString.MaximumLength = l; - UnicodeString.Buffer = pwcUnicodeBuf; - - /* convert and copy */ - if(AreFileApisANSI()) - RtlUnicodeStringToAnsiString(&AnsiString, &UnicodeString, FALSE); - else - RtlUnicodeStringToOemString(&AnsiString, &UnicodeString, FALSE); - - /* return the string size */ - Context->nBufSize = AnsiString.Length; -#if 0 - } - __finally - { - /* free the buffer */ - PsaiFree(pwcUnicodeBuf); - } -#else - Status = STATUS_NO_MORE_FILES; - -exitWithStatus: - /* free the buffer */ - PsaiFree(pwcUnicodeBuf); - return Status; -#endif - } - } - else - { - /* we want other module information */ - ULONG nSize = Context->nBufSize; - - /* base address */ - if(nSize >= sizeof(CurrentModule->DllBase)) - { - Context->lpmodinfo->lpBaseOfDll = CurrentModule->DllBase; - nSize -= sizeof(CurrentModule->DllBase); - } - - /* image size */ - if(nSize >= sizeof(CurrentModule->SizeOfImage)) - { - Context->lpmodinfo->SizeOfImage = CurrentModule->SizeOfImage; - nSize -= sizeof(CurrentModule->SizeOfImage); - } - - /* entry point */ - if(nSize >= sizeof(CurrentModule->EntryPoint)) - { - /* ??? FIXME? is "EntryPoint" just the offset, or the real address? */ - Context->lpmodinfo->EntryPoint = (PVOID)CurrentModule->EntryPoint; - } - - Context->nBufSize = TRUE; - } - - return STATUS_NO_MORE_FILES; - } - - return STATUS_SUCCESS; -} - - -static DWORD -InternalGetModuleInformation(HANDLE hProcess, - HMODULE hModule, - GET_MODULE_INFORMATION_FLAGS Flags, - LPVOID lpBuffer, - DWORD nBufSize) -{ - GET_MODULE_INFORMATION_CONTEXT Context; - NTSTATUS Status; - - Context.hModule = hModule; - Context.Flags = Flags; - Context.nBufSize = nBufSize; - Context.lpBuffer = lpBuffer; - - Status = PsaEnumerateProcessModules(hProcess, GetModuleInformationCallback, &Context); - - if(Status == STATUS_NO_MORE_FILES) - { - /* module was found, return string size */ - return Context.nBufSize; - } - else if(NT_SUCCESS(Status)) - { - /* module was not found */ - SetLastError(ERROR_INVALID_HANDLE); - } - else - { - /* an error occurred */ - SetLastErrorByStatus(Status); - } - return 0; -} - + return FALSE; +} typedef struct _INTERNAL_ENUM_PAGE_FILES_CONTEXT { - PENUM_PAGE_FILE_CALLBACKA pCallbackRoutine; - LPVOID lpContext; + LPVOID lpContext; + PENUM_PAGE_FILE_CALLBACKA pCallbackRoutine; + DWORD dwErrCode; } INTERNAL_ENUM_PAGE_FILES_CONTEXT, *PINTERNAL_ENUM_PAGE_FILES_CONTEXT; - +/* + * @implemented + */ static BOOL CALLBACK -InternalAnsiPageFileCallback(LPVOID pContext, - PENUM_PAGE_FILE_INFORMATION pPageFileInfo, - LPCWSTR lpFilename) -{ - size_t slen; - LPSTR AnsiFileName; - PINTERNAL_ENUM_PAGE_FILES_CONTEXT Context = (PINTERNAL_ENUM_PAGE_FILES_CONTEXT)pContext; - - slen = wcslen(lpFilename); - - AnsiFileName = (LPSTR)LocalAlloc(LMEM_FIXED, (slen + 1) * sizeof(CHAR)); - if(AnsiFileName != NULL) - { +CallBackConvertToAscii(LPVOID pContext, + PENUM_PAGE_FILE_INFORMATION pPageFileInfo, + LPCWSTR lpFilename) +{ BOOL Ret; - - WideCharToMultiByte(CP_ACP, - 0, - lpFilename, - -1, /* only works if the string is NULL-terminated!!! */ - AnsiFileName, - (slen + 1) * sizeof(CHAR), - NULL, - NULL); - + DWORD Len; + LPSTR AnsiFileName; + PINTERNAL_ENUM_PAGE_FILES_CONTEXT Context = (PINTERNAL_ENUM_PAGE_FILES_CONTEXT)pContext; + + Len = wcslen(lpFilename); + + /* Alloc space for the ANSI string */ + AnsiFileName = LocalAlloc(LMEM_FIXED, (Len * sizeof(CHAR)) + sizeof(ANSI_NULL)); + if (AnsiFileName == NULL) + { + Context->dwErrCode = RtlNtStatusToDosError(STATUS_INSUFFICIENT_RESOURCES); + return FALSE; + } + + /* Convert string to ANSI */ + if (WideCharToMultiByte(CP_ACP, 0, lpFilename, -1, AnsiFileName, (Len * sizeof(CHAR)) + sizeof(ANSI_NULL), NULL, NULL) == 0) + { + Context->dwErrCode = GetLastError(); + LocalFree(AnsiFileName); + return FALSE; + } + + /* And finally call "real" callback */ Ret = Context->pCallbackRoutine(Context->lpContext, pPageFileInfo, AnsiFileName); - - LocalFree((HLOCAL)AnsiFileName); + LocalFree(AnsiFileName); return Ret; - } - - return FALSE; } /* PUBLIC *********************************************************************/ @@ -629,38 +271,41 @@ WINAPI EmptyWorkingSet(HANDLE hProcess) { - QUOTA_LIMITS QuotaLimits; - NTSTATUS Status; - - /* query the working set */ - Status = NtQueryInformationProcess(hProcess, + SYSTEM_INFO SystemInfo; + QUOTA_LIMITS QuotaLimits; + NTSTATUS Status; + + GetSystemInfo(&SystemInfo); + + /* Query the working set */ + Status = NtQueryInformationProcess(hProcess, + ProcessQuotaLimits, + &QuotaLimits, + sizeof(QuotaLimits), + NULL); + + if (!NT_SUCCESS(Status)) + { + SetLastError(RtlNtStatusToDosError(Status)); + return FALSE; + } + + /* Empty the working set */ + QuotaLimits.MinimumWorkingSetSize = -1; + QuotaLimits.MaximumWorkingSetSize = -1; + + /* Set the working set */ + Status = NtSetInformationProcess(hProcess, ProcessQuotaLimits, &QuotaLimits, - sizeof(QuotaLimits), - NULL); - - if(!NT_SUCCESS(Status)) - { - SetLastErrorByStatus(Status); - return FALSE; - } - - /* empty the working set */ - QuotaLimits.MinimumWorkingSetSize = -1; - QuotaLimits.MaximumWorkingSetSize = -1; - - /* set the working set */ - Status = NtSetInformationProcess(hProcess, - ProcessQuotaLimits, - &QuotaLimits, - sizeof(QuotaLimits)); - if(!NT_SUCCESS(Status)) - { - SetLastErrorByStatus(Status); - return FALSE; - } - - return TRUE; + sizeof(QuotaLimits)); + if (!NT_SUCCESS(Status) && Status != STATUS_PRIVILEGE_NOT_HELD) + { + SetLastError(RtlNtStatusToDosError(Status)); + return FALSE; + } + + return TRUE; } @@ -673,27 +318,78 @@ DWORD cb, LPDWORD lpcbNeeded) { - ENUM_DEVICE_DRIVERS_CONTEXT Context; - NTSTATUS Status; - - cb /= sizeof(PVOID); - - Context.lpImageBase = lpImageBase; - Context.nCount = cb; - Context.nTotal = 0; - - Status = PsaEnumerateSystemModules(EnumDeviceDriversCallback, &Context); - - /* return the count of bytes that would be needed for a complete enumeration */ - *lpcbNeeded = Context.nTotal * sizeof(PVOID); - - if(!NT_SUCCESS(Status)) - { - SetLastErrorByStatus(Status); - return FALSE; - } - - return TRUE; + NTSTATUS Status; + DWORD NewSize, Count; + PRTL_PROCESS_MODULES Information; + /* By default, to prevent too many reallocations, we already make room for 4 modules */ + DWORD Size = sizeof(RTL_PROCESS_MODULES) + 3 * sizeof(RTL_PROCESS_MODULE_INFORMATION); + + do + { + /* Allocate a buffer to hold modules information */ + Information = LocalAlloc(LMEM_FIXED, Size); + if (!Information) + { + SetLastError(ERROR_NO_SYSTEM_RESOURCES); + return FALSE; + } + + /* Query information */ + Status = NtQuerySystemInformation(SystemModuleInformation, Information, Size, &Count); + /* In case of an error */ + if (!NT_SUCCESS(Status)) + { + /* Save the amount of output modules */ + NewSize = Information->NumberOfModules; + /* And free buffer */ + LocalFree(Information); + + /* If it was not a length mismatch (ie, buffer too small), just leave */ + if (Status != STATUS_INFO_LENGTH_MISMATCH) + { + SetLastError(RtlNtStatusToDosError(Status)); + return FALSE; + } + + /* Compute new size length */ + ASSERT(Size >= sizeof(RTL_PROCESS_MODULES)); + NewSize *= sizeof(RTL_PROCESS_MODULE_INFORMATION); + NewSize += sizeof(ULONG); + ASSERT(NewSize >= sizeof(RTL_PROCESS_MODULES)); + /* Check whether it is really bigger - otherwise, leave */ + if (NewSize < Size) + { + ASSERT(NewSize > Size); + SetLastError(RtlNtStatusToDosError(STATUS_INFO_LENGTH_MISMATCH)); + return FALSE; + } + + /* Loop again with that new buffer */ + Size = NewSize; + continue; + } + + /* End of allocation loop */ + break; + } while (TRUE); + + _SEH2_TRY + { + for (Count = 0; Count < Information->NumberOfModules && Count < cb / sizeof(LPVOID); ++Count) + { + lpImageBase[Count] = Information->Modules[Count].ImageBase; + } + + *lpcbNeeded = Information->NumberOfModules * sizeof(LPVOID); + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + SetLastError(RtlNtStatusToDosError(_SEH2_GetExceptionCode())); + _SEH2_YIELD(return FALSE); + } + _SEH2_END; + + return TRUE; } @@ -706,32 +402,78 @@ DWORD cb, LPDWORD lpcbNeeded) { - ENUM_PROCESSES_CONTEXT Context; - NTSTATUS Status; - - cb /= sizeof(DWORD); - - if(cb == 0 || lpidProcess == NULL) - { - *lpcbNeeded = 0; + NTSTATUS Status; + DWORD Size = MAXSHORT, Count; + PSYSTEM_PROCESS_INFORMATION ProcInfo; + PSYSTEM_PROCESS_INFORMATION ProcInfoArray; + + /* First of all, query all the processes */ + do + { + ProcInfoArray = LocalAlloc(LMEM_FIXED, Size); + if (ProcInfoArray == NULL) + { + return FALSE; + } + + Status = NtQuerySystemInformation(SystemProcessInformation, ProcInfoArray, Size, NULL); + if (Status == STATUS_INFO_LENGTH_MISMATCH) + { + LocalFree(ProcInfoArray); + Size += MAXSHORT; + continue; + } + + break; + } + while (TRUE); + + if (!NT_SUCCESS(Status)) + { + LocalFree(ProcInfoArray); + SetLastError(RtlNtStatusToDosError(Status)); + return FALSE; + } + + /* Then, loop to output data */ + Count = 0; + ProcInfo = ProcInfoArray; + + _SEH2_TRY + { + do + { + /* It may sound weird, but actually MS only updated Count on + * successful write. So, it cannot measure the amount of space needed! + * This is really tricky. + */ + if (Count < cb / sizeof(DWORD)) + { + lpidProcess[Count] = (DWORD)ProcInfo->UniqueProcessId; + Count++; + } + + if (ProcInfo->NextEntryOffset == 0) + { + break; + } + + ProcInfo = (PSYSTEM_PROCESS_INFORMATION)((ULONG_PTR)ProcInfo + ProcInfo->NextEntryOffset); + } + while (TRUE); + + *lpcbNeeded = Count * sizeof(DWORD); + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + SetLastError(RtlNtStatusToDosError(_SEH2_GetExceptionCode())); + LocalFree(ProcInfoArray); + _SEH2_YIELD(return FALSE); + } + _SEH2_END; + + LocalFree(ProcInfoArray); return TRUE; - } - - Context.lpidProcess = lpidProcess; - Context.nCount = cb; - - /* enumerate the process ids */ - Status = PsaEnumerateProcesses(EnumProcessesCallback, &Context); - - *lpcbNeeded = (cb - Context.nCount) * sizeof(DWORD); - - if(!NT_SUCCESS(Status) && (Status != STATUS_INFO_LENGTH_MISMATCH)) - { - SetLastErrorByStatus(Status); - return FALSE; - } - - return TRUE; } @@ -745,27 +487,96 @@ DWORD cb, LPDWORD lpcbNeeded) { - ENUM_PROCESS_MODULES_CONTEXT Context; - NTSTATUS Status; - - cb /= sizeof(HMODULE); - - Context.lphModule = lphModule; - Context.nCount = cb; - Context.nTotal = 0; - - /* enumerate the process modules */ - Status = PsaEnumerateProcessModules(hProcess, EnumProcessModulesCallback, &Context); - - *lpcbNeeded = Context.nTotal * sizeof(HMODULE); - - if(!NT_SUCCESS(Status)) - { - SetLastErrorByStatus(Status); - return FALSE; - } - - return TRUE; + NTSTATUS Status; + DWORD NbOfModules, Count; + PPEB_LDR_DATA LoaderData; + PLIST_ENTRY ListHead, ListEntry; + PROCESS_BASIC_INFORMATION ProcInfo; + LDR_DATA_TABLE_ENTRY CurrentModule; + + /* Query the process information to get its PEB address */ + Status = NtQueryInformationProcess(hProcess, ProcessBasicInformation, &ProcInfo, sizeof(ProcInfo), NULL); + if (!NT_SUCCESS(Status)) + { + SetLastError(RtlNtStatusToDosError(Status)); + return FALSE; + } + + if (ProcInfo.PebBaseAddress == NULL) + { + SetLastError(RtlNtStatusToDosError(STATUS_PARTIAL_COPY)); + return FALSE; + } + + /* Read loader data address from PEB */ + if (!ReadProcessMemory(hProcess, &ProcInfo.PebBaseAddress->Ldr, &LoaderData, sizeof(LoaderData), NULL)) + { + return FALSE; + } + + /* Store list head address */ + ListHead = &LoaderData->InLoadOrderModuleList; + + /* Read first element in the modules list */ + if (!ReadProcessMemory(hProcess, &LoaderData->InLoadOrderModuleList.Flink, &ListEntry, sizeof(ListEntry), NULL)) + { + return FALSE; + } + + NbOfModules = cb / sizeof(HMODULE); + Count = 0; + + /* Loop on the modules */ + while (ListEntry != ListHead) + { + /* Load module data */ + if (!ReadProcessMemory(hProcess, + CONTAINING_RECORD(ListEntry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks), + &CurrentModule, + sizeof(CurrentModule), + NULL)) + { + return FALSE; + } + + /* Check if we can output module, do it if so */ + if (Count < NbOfModules) + { + _SEH2_TRY + { + lphModule[Count] = CurrentModule.DllBase; + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + SetLastError(RtlNtStatusToDosError(_SEH2_GetExceptionCode())); + _SEH2_YIELD(return FALSE); + } + _SEH2_END; + } + + ++Count; + if (Count > MAX_MODULES) + { + SetLastError(ERROR_INVALID_HANDLE); + return FALSE; + } + + /* Get to next listed module */ + ListEntry = CurrentModule.InLoadOrderLinks.Flink; + } + + _SEH2_TRY + { + *lpcbNeeded = Count * sizeof(HMODULE); + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + SetLastError(RtlNtStatusToDosError(_SEH2_GetExceptionCode())); + _SEH2_YIELD(return FALSE); + } + _SEH2_END; + + return TRUE; } @@ -778,7 +589,33 @@ LPSTR lpBaseName, DWORD nSize) { - return InternalGetDeviceDriverName(FALSE, FALSE, ImageBase, lpBaseName, nSize); + DWORD Len, LenWithNull; + RTL_PROCESS_MODULE_INFORMATION Module; + + /* Get the associated device driver to the base address */ + if (!FindDeviceDriver(ImageBase, &Module)) + { + return 0; + } + + /* And copy as much as possible to output buffer. + * Try to add 1 to the len, to copy the null char as well. + */ + Len = + LenWithNull = strlen(&Module.FullPathName[Module.OffsetToFileName]) + 1; + if (Len > nSize) + { + Len = nSize; + } + + memcpy(lpBaseName, &Module.FullPathName[Module.OffsetToFileName], Len); + /* In case we copied null char, remove it from final len */ + if (Len == LenWithNull) + { + --Len; + } + + return Len; } @@ -791,7 +628,33 @@ LPSTR lpFilename, DWORD nSize) { - return InternalGetDeviceDriverName(FALSE, TRUE, ImageBase, lpFilename, nSize); + DWORD Len, LenWithNull; + RTL_PROCESS_MODULE_INFORMATION Module; + + /* Get the associated device driver to the base address */ + if (!FindDeviceDriver(ImageBase, &Module)) + { + return 0; + } + + /* And copy as much as possible to output buffer. + * Try to add 1 to the len, to copy the null char as well. + */ + Len = + LenWithNull = strlen(Module.FullPathName) + 1; + if (Len > nSize) + { + Len = nSize; + } + + memcpy(lpFilename, Module.FullPathName, Len); + /* In case we copied null char, remove it from final len */ + if (Len == LenWithNull) + { + --Len; + } + + return Len; } @@ -804,7 +667,33 @@ LPWSTR lpBaseName, DWORD nSize) { - return InternalGetDeviceDriverName(TRUE, FALSE, ImageBase, lpBaseName, nSize); + DWORD Len; + LPSTR BaseName; + + /* Allocate internal buffer for conversion */ + BaseName = LocalAlloc(LMEM_FIXED, nSize); + if (BaseName == 0) + { + return 0; + } + + /* Call A API */ + Len = GetDeviceDriverBaseNameA(ImageBase, BaseName, nSize); + if (Len == 0) + { + LocalFree(BaseName); + return 0; + } + + /* And convert output */ + if (MultiByteToWideChar(CP_ACP, 0, BaseName, (Len < nSize) ? Len + 1 : Len, lpBaseName, nSize) == 0) + { + LocalFree(BaseName); + return 0; + } + + LocalFree(BaseName); + return Len; } @@ -817,7 +706,33 @@ LPWSTR lpFilename, DWORD nSize) { - return InternalGetDeviceDriverName(TRUE, TRUE, ImageBase, lpFilename, nSize); + DWORD Len; + LPSTR FileName; + + /* Allocate internal buffer for conversion */ + FileName = LocalAlloc(LMEM_FIXED, nSize); + if (FileName == 0) + { + return 0; + } + + /* Call A API */ + Len = GetDeviceDriverFileNameA(ImageBase, FileName, nSize); + if (Len == 0) + { + LocalFree(FileName); + return 0; + } + + /* And convert output */ + if (MultiByteToWideChar(CP_ACP, 0, FileName, (Len < nSize) ? Len + 1 : Len, lpFilename, nSize) == 0) + { + LocalFree(FileName); + return 0; + } + + LocalFree(FileName); + return Len; } @@ -831,7 +746,32 @@ LPSTR lpFilename, DWORD nSize) { - return InternalGetMappedFileName(FALSE, hProcess, lpv, lpFilename, nSize); + DWORD Len; + LPWSTR FileName; + + DPRINT1("GetMappedFileNameA(%p, %p, %p, %lu)\n", hProcess, lpv, lpFilename, nSize); + + /* Allocate internal buffer for conversion */ + FileName = LocalAlloc(LMEM_FIXED, nSize * sizeof(WCHAR)); + if (FileName == NULL) + { + return 0; + } + + /* Call W API */ + Len = GetMappedFileNameW(hProcess, lpv, FileName, nSize); + + DPRINT1("Got: %wS\n", FileName); + DPRINT1("Len: %lu\n", Len); + + /* And convert output */ + if (WideCharToMultiByte(CP_ACP, 0, FileName, (Len < nSize) ? Len + 1 : Len, lpFilename, nSize, NULL, NULL) == 0) + { + Len = 0; + } + + LocalFree(FileName); + return Len; } @@ -845,7 +785,56 @@ LPWSTR lpFilename, DWORD nSize) { - return InternalGetMappedFileName(TRUE, hProcess, lpv, lpFilename, nSize); + DWORD Len; + DWORD OutSize; + NTSTATUS Status; + struct + { + MEMORY_SECTION_NAME; + WCHAR CharBuffer[MAX_PATH]; + } SectionName; + + DPRINT1("GetMappedFileNameW(%p, %p, %p, %lu)\n", hProcess, lpv, lpFilename, nSize); + + /* If no buffer, no need to keep going on */ + if (nSize == 0) + { + SetLastError(ERROR_INSUFFICIENT_BUFFER); + return 0; + } + + /* Query section name */ + Status = NtQueryVirtualMemory(hProcess, lpv, MemorySectionName, + &SectionName, sizeof(SectionName), &OutSize); + if (!NT_SUCCESS(Status)) + { + DPRINT1("Failed!\n"); + SetLastError(RtlNtStatusToDosError(Status)); + return 0; + } + + DPRINT1("Found: %wZ\n", &SectionName.SectionFileName); + DPRINT1("Len = %lu, nSize = %lu\n", SectionName.SectionFileName.Length / sizeof(WCHAR), nSize); + + /* Prepare to copy file name */ + Len = + OutSize = SectionName.SectionFileName.Length / sizeof(WCHAR); + if (OutSize + 1 > nSize) + { + Len = nSize - 1; + OutSize = nSize; + SetLastError(ERROR_INSUFFICIENT_BUFFER); + } + else + { + SetLastError(ERROR_SUCCESS); + } + + /* Copy, zero and return */ + memcpy(lpFilename, SectionName.SectionFileName.Buffer, Len * sizeof(WCHAR)); + lpFilename[Len] = 0; + + return OutSize; } @@ -859,8 +848,27 @@ LPSTR lpBaseName, DWORD nSize) { - GET_MODULE_INFORMATION_FLAGS Flags = {TRUE, FALSE, FALSE}; - return InternalGetModuleInformation(hProcess, hModule, Flags, lpBaseName, nSize); + DWORD Len; + PWSTR BaseName; + + /* Allocate internal buffer for conversion */ + BaseName = LocalAlloc(LMEM_FIXED, nSize * sizeof(WCHAR)); + if (BaseName == NULL) + { + return 0; + } + + /* Call W API */ + Len = GetModuleBaseNameW(hProcess, hModule, BaseName, nSize); + /* And convert output */ + if (WideCharToMultiByte(CP_ACP, 0, BaseName, (Len < nSize) ? Len + 1 : Len, lpBaseName, nSize, NULL, NULL) == 0) + { + Len = 0; + } + + LocalFree(BaseName); + + return Len; } @@ -874,8 +882,51 @@ LPWSTR lpBaseName, DWORD nSize) { - GET_MODULE_INFORMATION_FLAGS Flags = {TRUE, TRUE, FALSE}; - return InternalGetModuleInformation(hProcess, hModule, Flags, lpBaseName, nSize); + DWORD Len; + LDR_DATA_TABLE_ENTRY Module; + + /* Get the matching module */ + if (!FindModule(hProcess, hModule, &Module)) + { + return 0; + } + + /* Get the maximum len we have/can write in given size */ + Len = Module.BaseDllName.Length + sizeof(UNICODE_NULL); + if (nSize * sizeof(WCHAR) < Len) + { + Len = nSize * sizeof(WCHAR); + } + + /* Read string */ + if (!ReadProcessMemory(hProcess, (&Module.BaseDllName)->Buffer, lpBaseName, Len, NULL)) + { + return 0; + } + + /* If we are at the end of the string, prepare to override to nullify string */ + if (Len == Module.BaseDllName.Length + sizeof(UNICODE_NULL)) + { + Len -= sizeof(UNICODE_NULL); + } + + /* Nullify at the end if needed */ + if (Len >= nSize * sizeof(WCHAR)) + { + if (nSize) + { + ASSERT(nSize >= sizeof(UNICODE_NULL)); + lpBaseName[nSize - 1] = UNICODE_NULL; + } + } + /* Otherwise, nullify at last writen char */ + else + { + ASSERT(Len + sizeof(UNICODE_NULL) <= nSize * sizeof(WCHAR)); + lpBaseName[Len / sizeof(WCHAR)] = UNICODE_NULL; + } + + return Len / sizeof(WCHAR); } @@ -889,8 +940,27 @@ LPSTR lpFilename, DWORD nSize) { - GET_MODULE_INFORMATION_FLAGS Flags = {TRUE, FALSE, TRUE}; - return InternalGetModuleInformation(hProcess, hModule, Flags, lpFilename, nSize); + DWORD Len; + PWSTR Filename; + + /* Allocate internal buffer for conversion */ + Filename = LocalAlloc(LMEM_FIXED, nSize * sizeof(WCHAR)); + if (Filename == NULL) + { + return 0; + } + + /* Call W API */ + Len = GetModuleFileNameExW(hProcess, hModule, Filename, nSize); + /* And convert output */ + if (WideCharToMultiByte(CP_ACP, 0, Filename, (Len < nSize) ? Len + 1 : Len, lpFilename, nSize, NULL, NULL) == 0) + { + Len = 0; + } + + LocalFree(Filename); + + return Len; } @@ -904,8 +974,51 @@ LPWSTR lpFilename, DWORD nSize) { - GET_MODULE_INFORMATION_FLAGS Flags = {TRUE, TRUE, TRUE}; - return InternalGetModuleInformation(hProcess, hModule, Flags, lpFilename, nSize); + DWORD Len; + LDR_DATA_TABLE_ENTRY Module; + + /* Get the matching module */ + if (!FindModule(hProcess, hModule, &Module)) + { + return 0; + } + + /* Get the maximum len we have/can write in given size */ + Len = Module.FullDllName.Length + sizeof(UNICODE_NULL); + if (nSize * sizeof(WCHAR) < Len) + { + Len = nSize * sizeof(WCHAR); + } + + /* Read string */ + if (!ReadProcessMemory(hProcess, (&Module.FullDllName)->Buffer, lpFilename, Len, NULL)) + { + return 0; + } + + /* If we are at the end of the string, prepare to override to nullify string */ + if (Len == Module.FullDllName.Length + sizeof(UNICODE_NULL)) + { + Len -= sizeof(UNICODE_NULL); + } + + /* Nullify at the end if needed */ + if (Len >= nSize * sizeof(WCHAR)) + { + if (nSize) + { + ASSERT(nSize >= sizeof(UNICODE_NULL)); + lpFilename[nSize - 1] = UNICODE_NULL; + } + } + /* Otherwise, nullify at last writen char */ + else + { + ASSERT(Len + sizeof(UNICODE_NULL) <= nSize * sizeof(WCHAR)); + lpFilename[Len / sizeof(WCHAR)] = UNICODE_NULL; + } + + return Len / sizeof(WCHAR); } @@ -919,37 +1032,65 @@ LPMODULEINFO lpmodinfo, DWORD cb) { - GET_MODULE_INFORMATION_FLAGS Flags = {FALSE, FALSE, FALSE}; - - if (cb < sizeof(MODULEINFO)) - { - SetLastError(ERROR_INSUFFICIENT_BUFFER); + MODULEINFO LocalInfo; + LDR_DATA_TABLE_ENTRY Module; + + /* Check output size */ + if (cb < sizeof(MODULEINFO)) + { + SetLastError(ERROR_INSUFFICIENT_BUFFER); + return FALSE; + } + + /* Get the matching module */ + if (!FindModule(hProcess, hModule, &Module)) + { + return FALSE; + } + + /* Get a local copy first, to check for valid pointer once */ + LocalInfo.lpBaseOfDll = hModule; + LocalInfo.SizeOfImage = Module.SizeOfImage; + LocalInfo.EntryPoint = Module.EntryPoint; + + /* Attempt to copy to output */ + _SEH2_TRY + { + memcpy(lpmodinfo, &LocalInfo, sizeof(LocalInfo)); + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + SetLastError(RtlNtStatusToDosError(_SEH2_GetExceptionCode())); + _SEH2_YIELD(return FALSE); + } + _SEH2_END; + + return TRUE; +} + + +/* + * @implemented + */ +BOOL +WINAPI +InitializeProcessForWsWatch(HANDLE hProcess) +{ + NTSTATUS Status; + + /* Simply forward the call */ + Status = NtSetInformationProcess(hProcess, + ProcessWorkingSetWatch, + NULL, + 0); + /* In case the function returns this, MS considers the call as a success */ + if (NT_SUCCESS(Status) || Status == STATUS_PORT_ALREADY_SET || Status == STATUS_ACCESS_DENIED) + { + return TRUE; + } + + SetLastError(RtlNtStatusToDosError(Status)); return FALSE; - } - return (BOOL)InternalGetModuleInformation(hProcess, hModule, Flags, lpmodinfo, cb); -} - - -/* - * @implemented - */ -BOOL -WINAPI -InitializeProcessForWsWatch(HANDLE hProcess) -{ - NTSTATUS Status; - - Status = NtSetInformationProcess(hProcess, - ProcessWorkingSetWatch, - NULL, - 0); - if(!NT_SUCCESS(Status)) - { - SetLastErrorByStatus(Status); - return FALSE; - } - - return TRUE; } @@ -962,20 +1103,21 @@ PPSAPI_WS_WATCH_INFORMATION lpWatchInfo, DWORD cb) { - NTSTATUS Status; - - Status = NtQueryInformationProcess(hProcess, - ProcessWorkingSetWatch, - (PVOID)lpWatchInfo, - cb, - NULL); - if(!NT_SUCCESS(Status)) - { - SetLastErrorByStatus(Status); - return FALSE; - } - - return TRUE; + NTSTATUS Status; + + /* Simply forward the call */ + Status = NtQueryInformationProcess(hProcess, + ProcessWorkingSetWatch, + lpWatchInfo, + cb, + NULL); + if(!NT_SUCCESS(Status)) + { + SetLastError(RtlNtStatusToDosError(Status)); + return FALSE; + } + + return TRUE; } @@ -988,43 +1130,47 @@ LPWSTR lpImageFileName, DWORD nSize) { - PUNICODE_STRING ImageFileName; - SIZE_T BufferSize; - NTSTATUS Status; - DWORD Ret = 0; - - BufferSize = sizeof(UNICODE_STRING) + (nSize * sizeof(WCHAR)); - - ImageFileName = (PUNICODE_STRING)LocalAlloc(LMEM_FIXED, BufferSize); - if(ImageFileName != NULL) - { + PUNICODE_STRING ImageFileName; + SIZE_T BufferSize; + NTSTATUS Status; + DWORD Len; + + /* Allocate string big enough to hold name */ + BufferSize = sizeof(UNICODE_STRING) + (nSize * sizeof(WCHAR)); + ImageFileName = LocalAlloc(LMEM_FIXED, BufferSize); + if (ImageFileName == NULL) + { + return 0; + } + + /* Query name */ Status = NtQueryInformationProcess(hProcess, ProcessImageFileName, ImageFileName, BufferSize, NULL); - if(NT_SUCCESS(Status)) - { - memcpy(lpImageFileName, ImageFileName->Buffer, ImageFileName->Length); - - /* make sure the string is null-terminated! */ - lpImageFileName[ImageFileName->Length / sizeof(WCHAR)] = L'\0'; - Ret = ImageFileName->Length / sizeof(WCHAR); - } - else if(Status == STATUS_INFO_LENGTH_MISMATCH) - { - /* XP sets this error code for some reason if the buffer is too small */ - SetLastError(ERROR_INSUFFICIENT_BUFFER); - } - else - { - SetLastErrorByStatus(Status); - } - - LocalFree((HLOCAL)ImageFileName); - } - - return Ret; + /* Len mismatch => buffer too small */ + if (Status == STATUS_INFO_LENGTH_MISMATCH) + { + Status = STATUS_BUFFER_TOO_SMALL; + } + if (!NT_SUCCESS(Status)) + { + SetLastError(RtlNtStatusToDosError(Status)); + LocalFree(ImageFileName); + return 0; + } + + /* Copy name and null-terminate if possible */ + memcpy(lpImageFileName, ImageFileName->Buffer, ImageFileName->Length); + Len = ImageFileName->Length / sizeof(WCHAR); + if (Len < nSize) + { + lpImageFileName[Len] = UNICODE_NULL; + } + + LocalFree(ImageFileName); + return Len; } @@ -1037,50 +1183,48 @@ LPSTR lpImageFileName, DWORD nSize) { - PUNICODE_STRING ImageFileName; - SIZE_T BufferSize; - NTSTATUS Status; - DWORD Ret = 0; - - BufferSize = sizeof(UNICODE_STRING) + (nSize * sizeof(WCHAR)); - - ImageFileName = (PUNICODE_STRING)LocalAlloc(LMEM_FIXED, BufferSize); - if(ImageFileName != NULL) - { + PUNICODE_STRING ImageFileName; + SIZE_T BufferSize; + NTSTATUS Status; + DWORD Len; + + /* Allocate string big enough to hold name */ + BufferSize = sizeof(UNICODE_STRING) + (nSize * sizeof(WCHAR)); + ImageFileName = LocalAlloc(LMEM_FIXED, BufferSize); + if (ImageFileName == NULL) + { + return 0; + } + + /* Query name */ Status = NtQueryInformationProcess(hProcess, ProcessImageFileName, ImageFileName, BufferSize, NULL); - if(NT_SUCCESS(Status)) - { - WideCharToMultiByte(CP_ACP, - 0, - ImageFileName->Buffer, - ImageFileName->Length / sizeof(WCHAR), - lpImageFileName, - nSize, - NULL, - NULL); - - /* make sure the string is null-terminated! */ - lpImageFileName[ImageFileName->Length / sizeof(WCHAR)] = '\0'; - Ret = ImageFileName->Length / sizeof(WCHAR); - } - else if(Status == STATUS_INFO_LENGTH_MISMATCH) - { - /* XP sets this error code for some reason if the buffer is too small */ - SetLastError(ERROR_INSUFFICIENT_BUFFER); - } - else - { - SetLastErrorByStatus(Status); - } - - LocalFree((HLOCAL)ImageFileName); - } - - return Ret; + /* Len mismatch => buffer too small */ + if (Status == STATUS_INFO_LENGTH_MISMATCH) + { + Status = STATUS_BUFFER_TOO_SMALL; + } + if (!NT_SUCCESS(Status)) + { + SetLastError(RtlNtStatusToDosError(Status)); + LocalFree(ImageFileName); + return 0; + } + + /* Copy name */ + Len = WideCharToMultiByte(CP_ACP, 0, ImageFileName->Buffer, + ImageFileName->Length, lpImageFileName, nSize, NULL, NULL); + /* If conversion was successfull, don't return len with added \0 */ + if (Len != 0) + { + Len -= sizeof(ANSI_NULL); + } + + LocalFree(ImageFileName); + return Len; } @@ -1092,12 +1236,23 @@ EnumPageFilesA(PENUM_PAGE_FILE_CALLBACKA pCallbackRoutine, LPVOID lpContext) { - INTERNAL_ENUM_PAGE_FILES_CONTEXT Context; - - Context.pCallbackRoutine = pCallbackRoutine; - Context.lpContext = lpContext; - - return EnumPageFilesW(InternalAnsiPageFileCallback, &Context); + BOOL Ret; + INTERNAL_ENUM_PAGE_FILES_CONTEXT Context; + + Context.dwErrCode = ERROR_SUCCESS; + Context.lpContext = lpContext; + Context.pCallbackRoutine = pCallbackRoutine; + + /* Call W with our own callback for W -> A conversions */ + Ret = EnumPageFilesW(CallBackConvertToAscii, &Context); + /* If we succeed but we have error code, fail and set error */ + if (Ret && Context.dwErrCode != ERROR_SUCCESS) + { + Ret = FALSE; + SetLastError(Context.dwErrCode); + } + + return Ret; } @@ -1109,83 +1264,91 @@ EnumPageFilesW(PENUM_PAGE_FILE_CALLBACKW pCallbackRoutine, LPVOID lpContext) { - NTSTATUS Status; - PVOID Buffer; - ULONG BufferSize = 0; - BOOL Ret = FALSE; - - for(;;) - { - BufferSize += 0x1000; - Buffer = LocalAlloc(LMEM_FIXED, BufferSize); - if(Buffer == NULL) - { - return FALSE; - } - - Status = NtQuerySystemInformation(SystemPageFileInformation, - Buffer, - BufferSize, - NULL); - if(Status == STATUS_INFO_LENGTH_MISMATCH) - { - LocalFree((HLOCAL)Buffer); - } - else - { - break; - } - } - - if(NT_SUCCESS(Status)) - { + PWSTR Colon; + NTSTATUS Status; + DWORD Size = INIT_MEMORY_SIZE, Needed; ENUM_PAGE_FILE_INFORMATION Information; - PSYSTEM_PAGEFILE_INFORMATION pfi = (PSYSTEM_PAGEFILE_INFORMATION)Buffer; - ULONG Offset = 0; - + PSYSTEM_PAGEFILE_INFORMATION PageFileInfoArray, PageFileInfo; + + /* First loop till we have all the information about page files */ do { - PWCHAR Colon; - - pfi = (PSYSTEM_PAGEFILE_INFORMATION)((ULONG_PTR)pfi + Offset); - - Information.cb = sizeof(Information); - Information.Reserved = 0; - Information.TotalSize = pfi->TotalSize; - Information.TotalInUse = pfi->TotalInUse; - Information.PeakUsage = pfi->PeakUsage; - - /* strip the \??\ prefix from the file name. We do this by searching for the first - : character and then just change Buffer to point to the previous character. */ - - Colon = wcschr(pfi->PageFileName.Buffer, L':'); - if(Colon != NULL) - { - pfi->PageFileName.Buffer = --Colon; - } - - /* FIXME - looks like the PageFileName string is always NULL-terminated on win. - At least I haven't encountered a different case so far, we should - propably manually NULL-terminate the string here... */ - - if(!pCallbackRoutine(lpContext, &Information, pfi->PageFileName.Buffer)) - { - break; - } - - Offset = pfi->NextEntryOffset; - } while(Offset != 0); - - Ret = TRUE; - } - else - { - SetLastErrorByStatus(Status); - } - - LocalFree((HLOCAL)Buffer); - - return Ret; + PageFileInfoArray = LocalAlloc(LMEM_FIXED, Size); + if (PageFileInfoArray == NULL) + { + SetLastError(RtlNtStatusToDosError(STATUS_INSUFFICIENT_RESOURCES)); + return FALSE; + } + + Status = NtQuerySystemInformation(SystemPageFileInformation, PageFileInfoArray, Size, &Needed); + if (NT_SUCCESS(Status)) + { + break; + } + + LocalFree(PageFileInfoArray); + + /* In case we have unexpected status, quit */ + if (Status != STATUS_INFO_LENGTH_MISMATCH) + { + SetLastError(RtlNtStatusToDosError(Status)); + return FALSE; + } + + /* If needed size is smaller than actual size, guess it's something to add to our current size */ + if (Needed <= Size) + { + Size += Needed; + } + /* Otherwise, take it as size to allocate */ + else + { + Size = Needed; + } + } + while (TRUE); + + /* Start browsing all our entries */ + PageFileInfo = PageFileInfoArray; + do + { + /* Ensure we really have an entry */ + if (Needed < sizeof(SYSTEM_PAGEFILE_INFORMATION)) + { + break; + } + + /* Prepare structure to hand to the user */ + Information.Reserved = 0; + Information.cb = sizeof(Information); + Information.TotalSize = PageFileInfo->TotalSize; + Information.TotalInUse = PageFileInfo->TotalInUse; + Information.PeakUsage = PageFileInfo->PeakUsage; + + /* Search for colon */ + Colon = wcschr(PageFileInfo->PageFileName.Buffer, L':'); + /* If it's found and not at the begin of the string */ + if (Colon != 0 && Colon != PageFileInfo->PageFileName.Buffer) + { + /* We can call the user callback routine with the colon */ + Colon -= sizeof(WCHAR); + pCallbackRoutine(lpContext, &Information, Colon); + } + + /* If no next entry, then, it's over */ + if (PageFileInfo->NextEntryOffset == 0 || PageFileInfo->NextEntryOffset > Needed) + { + break; + } + + /* Jump to next entry while keeping accurate bytes left count */ + Needed -= PageFileInfo->NextEntryOffset; + PageFileInfo = (PSYSTEM_PAGEFILE_INFORMATION)((ULONG_PTR)PageFileInfo + PageFileInfo->NextEntryOffset); + } + while (TRUE); + + LocalFree(PageFileInfoArray); + return TRUE; } @@ -1197,119 +1360,140 @@ GetPerformanceInfo(PPERFORMANCE_INFORMATION pPerformanceInformation, DWORD cb) { - SYSTEM_PERFORMANCE_INFORMATION spi; - SYSTEM_BASIC_INFORMATION sbi; - SYSTEM_HANDLE_INFORMATION shi; - PSYSTEM_PROCESS_INFORMATION ProcessInfo; - ULONG BufferSize, ProcOffset, ProcessCount, ThreadCount; - PVOID Buffer; - NTSTATUS Status; - - Status = NtQuerySystemInformation(SystemPerformanceInformation, - &spi, - sizeof(spi), - NULL); - if(!NT_SUCCESS(Status)) - { - SetLastErrorByStatus(Status); - return FALSE; - } - - Status = NtQuerySystemInformation(SystemBasicInformation, - &sbi, - sizeof(sbi), - NULL); - if(!NT_SUCCESS(Status)) - { - SetLastErrorByStatus(Status); - return FALSE; - } - - /* - * allocate enough memory to get a dump of all processes and threads - */ - BufferSize = 0; - for(;;) - { - BufferSize += 0x10000; - Buffer = (PVOID)LocalAlloc(LMEM_FIXED, BufferSize); - if(Buffer == NULL) - { - return FALSE; - } - - Status = NtQuerySystemInformation(SystemProcessInformation, - Buffer, - BufferSize, + NTSTATUS Status; + SYSTEM_BASIC_INFORMATION SystemBasicInfo; + SYSTEM_PERFORMANCE_INFORMATION SystemPerfInfo; + SYSTEM_FILECACHE_INFORMATION SystemFileCacheInfo; + PSYSTEM_PROCESS_INFORMATION ProcInfoArray, SystemProcInfo; + DWORD Size = INIT_MEMORY_SIZE, Needed, ProcCount, ThreadsCount, HandleCount; + + /* Validate output buffer */ + if (cb < sizeof(PERFORMANCE_INFORMATION)) + { + SetLastError(RtlNtStatusToDosError(STATUS_INFO_LENGTH_MISMATCH)); + return FALSE; + } + + /* First, gather as many information about the system as possible */ + Status = NtQuerySystemInformation(SystemBasicInformation, + &SystemBasicInfo, + sizeof(SystemBasicInfo), NULL); - if(Status == STATUS_INFO_LENGTH_MISMATCH) - { - LocalFree((HLOCAL)Buffer); - } - else - { - break; - } - } - - if(!NT_SUCCESS(Status)) - { - LocalFree((HLOCAL)Buffer); - SetLastErrorByStatus(Status); - return FALSE; - } - - /* - * determine the process and thread count - */ - ProcessCount = ThreadCount = ProcOffset = 0; - ProcessInfo = (PSYSTEM_PROCESS_INFORMATION)Buffer; - do - { - ProcessInfo = (PSYSTEM_PROCESS_INFORMATION)((ULONG_PTR)ProcessInfo + ProcOffset); - ProcessCount++; - ThreadCount += ProcessInfo->NumberOfThreads; - - ProcOffset = ProcessInfo->NextEntryOffset; - } while(ProcOffset != 0); - - LocalFree((HLOCAL)Buffer); - - /* - * it's enough to supply a SYSTEM_HANDLE_INFORMATION structure as buffer. Even - * though it returns STATUS_INFO_LENGTH_MISMATCH, it already sets the NumberOfHandles - * field which is all we're looking for anyway. - */ - Status = NtQuerySystemInformation(SystemHandleInformation, - &shi, - sizeof(shi), - NULL); - if(!NT_SUCCESS(Status) && (Status != STATUS_INFO_LENGTH_MISMATCH)) - { - SetLastErrorByStatus(Status); - return FALSE; - } - - /* - * all required information collected, fill the structure - */ - - pPerformanceInformation->cb = sizeof(PERFORMANCE_INFORMATION); - pPerformanceInformation->CommitTotal = spi.CommittedPages; - pPerformanceInformation->CommitLimit = spi.CommitLimit; - pPerformanceInformation->CommitPeak = spi.PeakCommitment; - pPerformanceInformation->PhysicalTotal = sbi.NumberOfPhysicalPages; - pPerformanceInformation->PhysicalAvailable = spi.AvailablePages; - pPerformanceInformation->SystemCache = 0; /* FIXME - where to get this information from? */ - pPerformanceInformation->KernelTotal = spi.PagedPoolPages + spi.NonPagedPoolPages; - pPerformanceInformation->KernelPaged = spi.PagedPoolPages; - pPerformanceInformation->KernelNonpaged = spi.NonPagedPoolPages; - pPerformanceInformation->PageSize = sbi.PageSize; - pPerformanceInformation->HandleCount = shi.NumberOfHandles; - pPerformanceInformation->ProcessCount = ProcessCount; - pPerformanceInformation->ThreadCount = ThreadCount; - - return TRUE; + if (!NT_SUCCESS(Status)) + { + SetLastError(RtlNtStatusToDosError(Status)); + return FALSE; + } + + Status = NtQuerySystemInformation(SystemPerformanceInformation, + &SystemPerfInfo, + sizeof(SystemPerfInfo), + NULL); + if (!NT_SUCCESS(Status)) + { + SetLastError(RtlNtStatusToDosError(Status)); + return FALSE; + } + + Status = NtQuerySystemInformation(SystemFileCacheInformation, + &SystemFileCacheInfo, + sizeof(SystemFileCacheInfo), + NULL); + if (!NT_SUCCESS(Status)) + { + SetLastError(RtlNtStatusToDosError(Status)); + return FALSE; + } + + /* Then loop till we have all the information about processes */ + do + { + ProcInfoArray = LocalAlloc(LMEM_FIXED, Size); + if (ProcInfoArray == NULL) + { + SetLastError(RtlNtStatusToDosError(STATUS_INSUFFICIENT_RESOURCES)); + return FALSE; + } + + Status = NtQuerySystemInformation(SystemProcessInformation, + ProcInfoArray, + Size, + &Needed); + if (NT_SUCCESS(Status)) + { + break; + } + + LocalFree(ProcInfoArray); + + /* In case we have unexpected status, quit */ + if (Status != STATUS_INFO_LENGTH_MISMATCH) + { + SetLastError(RtlNtStatusToDosError(Status)); + return FALSE; + } + + /* If needed size is smaller than actual size, guess it's something to add to our current size */ + if (Needed <= Size) + { + Size += Needed; + } + /* Otherwise, take it as size to allocate */ + else + { + Size = Needed; + } + } while (TRUE); + + /* Start browsing all our entries */ + ProcCount = 0; + HandleCount = 0; + ThreadsCount = 0; + SystemProcInfo = ProcInfoArray; + do + { + /* Ensure we really have an entry */ + if (Needed < sizeof(SYSTEM_PROCESS_INFORMATION)) + { + break; + } + + /* Sum procs, threads and handles */ + ++ProcCount; + ThreadsCount += SystemProcInfo->NumberOfThreads; + HandleCount += SystemProcInfo->HandleCount; + + /* If no next entry, then, it's over */ + if (SystemProcInfo->NextEntryOffset == 0 || SystemProcInfo->NextEntryOffset > Needed) + { + break; + } + + /* Jump to next entry while keeping accurate bytes left count */ + Needed -= SystemProcInfo->NextEntryOffset; + SystemProcInfo = (PSYSTEM_PROCESS_INFORMATION)((ULONG_PTR)SystemProcInfo + SystemProcInfo->NextEntryOffset); + } + while (TRUE); + + LocalFree(ProcInfoArray); + + /* Output data */ + pPerformanceInformation->CommitTotal = SystemPerfInfo.CommittedPages; + pPerformanceInformation->CommitLimit = SystemPerfInfo.CommitLimit; + pPerformanceInformation->CommitPeak = SystemPerfInfo.PeakCommitment; + pPerformanceInformation->PhysicalTotal = SystemBasicInfo.NumberOfPhysicalPages; + pPerformanceInformation->PhysicalAvailable = SystemPerfInfo.AvailablePages; + pPerformanceInformation->SystemCache = SystemFileCacheInfo.CurrentSizeIncludingTransitionInPages; + pPerformanceInformation->KernelNonpaged = SystemPerfInfo.NonPagedPoolPages; + pPerformanceInformation->PageSize = SystemBasicInfo.PageSize; + pPerformanceInformation->cb = sizeof(PERFORMANCE_INFORMATION); + pPerformanceInformation->KernelTotal = SystemPerfInfo.PagedPoolPages + SystemPerfInfo.NonPagedPoolPages; + pPerformanceInformation->KernelPaged = SystemPerfInfo.PagedPoolPages; + pPerformanceInformation->HandleCount = HandleCount; + pPerformanceInformation->ProcessCount = ProcCount; + pPerformanceInformation->ThreadCount = ThreadsCount; + + return TRUE; } @@ -1322,57 +1506,68 @@ PPROCESS_MEMORY_COUNTERS ppsmemCounters, DWORD cb) { - NTSTATUS Status; - VM_COUNTERS vmc; - BOOL Ret = FALSE; - - /* XP's implementation secures access to ppsmemCounters in SEH, we should behave - similar so we can return the proper error codes when bad pointers are passed - to this function! */ - - _SEH2_TRY - { - if(cb < sizeof(PROCESS_MEMORY_COUNTERS)) - { - SetLastError(ERROR_INSUFFICIENT_BUFFER); - _SEH2_LEAVE; - } - - /* ppsmemCounters->cb isn't checked at all! */ - - Status = NtQueryInformationProcess(Process, - ProcessVmCounters, - &vmc, - sizeof(vmc), - NULL); - if(!NT_SUCCESS(Status)) - { - SetLastErrorByStatus(Status); - _SEH2_LEAVE; - } - - /* fill the structure with the collected information, in case of bad pointers - SEH will catch the exception and set the appropriate error code */ - ppsmemCounters->cb = sizeof(PROCESS_MEMORY_COUNTERS); - ppsmemCounters->PageFaultCount = vmc.PageFaultCount; - ppsmemCounters->PeakWorkingSetSize = vmc.PeakWorkingSetSize; - ppsmemCounters->WorkingSetSize = vmc.WorkingSetSize; - ppsmemCounters->QuotaPeakPagedPoolUsage = vmc.QuotaPeakPagedPoolUsage; - ppsmemCounters->QuotaPagedPoolUsage = vmc.QuotaPagedPoolUsage; - ppsmemCounters->QuotaPeakNonPagedPoolUsage = vmc.QuotaPeakNonPagedPoolUsage; - ppsmemCounters->QuotaNonPagedPoolUsage = vmc.QuotaNonPagedPoolUsage; - ppsmemCounters->PagefileUsage = vmc.PagefileUsage; - ppsmemCounters->PeakPagefileUsage = vmc.PeakPagefileUsage; - - Ret = TRUE; - } - _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - SetLastErrorByStatus(_SEH2_GetExceptionCode()); - } - _SEH2_END; - - return Ret; + NTSTATUS Status; + VM_COUNTERS_EX Counters; + + /* Validate output size + * It can be either PROCESS_MEMORY_COUNTERS or PROCESS_MEMORY_COUNTERS_EX + */ + if (cb < sizeof(PROCESS_MEMORY_COUNTERS)) + { + SetLastError(ERROR_INSUFFICIENT_BUFFER); + return FALSE; + } + + _SEH2_TRY + { + ppsmemCounters->PeakPagefileUsage = 0; + + /* Query counters */ + Status = NtQueryInformationProcess(Process, + ProcessVmCounters, + &Counters, + sizeof(Counters), + NULL); + if (!NT_SUCCESS(Status)) + { + SetLastError(RtlNtStatusToDosError(Status)); + _SEH2_YIELD(return FALSE); + } + + /* Properly set cb, according to what we received */ + if (cb >= sizeof(PROCESS_MEMORY_COUNTERS_EX)) + { + ppsmemCounters->cb = sizeof(PROCESS_MEMORY_COUNTERS_EX); + } + else + { + ppsmemCounters->cb = sizeof(PROCESS_MEMORY_COUNTERS); + } + + /* Output data */ + ppsmemCounters->PageFaultCount = Counters.PageFaultCount; + ppsmemCounters->PeakWorkingSetSize = Counters.PeakWorkingSetSize; + ppsmemCounters->WorkingSetSize = Counters.WorkingSetSize; + ppsmemCounters->QuotaPeakPagedPoolUsage = Counters.QuotaPeakPagedPoolUsage; + ppsmemCounters->QuotaPagedPoolUsage = Counters.QuotaPagedPoolUsage; + ppsmemCounters->QuotaPeakNonPagedPoolUsage = Counters.QuotaPeakNonPagedPoolUsage; + ppsmemCounters->QuotaNonPagedPoolUsage = Counters.QuotaNonPagedPoolUsage; + ppsmemCounters->PagefileUsage = Counters.PagefileUsage; + ppsmemCounters->PeakPagefileUsage = Counters.PeakPagefileUsage; + /* And if needed, additionnal field for _EX version */ + if (cb >= sizeof(PROCESS_MEMORY_COUNTERS_EX)) + { + ((PPROCESS_MEMORY_COUNTERS_EX)ppsmemCounters)->PrivateUsage = Counters.PrivateUsage; + } + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + SetLastError(RtlNtStatusToDosError(_SEH2_GetExceptionCode())); + _SEH2_YIELD(return FALSE); + } + _SEH2_END; + + return TRUE; } @@ -1385,25 +1580,26 @@ PVOID pv, DWORD cb) { - NTSTATUS Status; - - Status = NtQueryVirtualMemory(hProcess, - NULL, - MemoryWorkingSetList, - pv, - cb, - NULL); - if(!NT_SUCCESS(Status)) - { - SetLastErrorByStatus(Status); - return FALSE; - } - - return TRUE; -} - -/* - * @unimplemented + NTSTATUS Status; + + /* Simply forward the call */ + Status = NtQueryVirtualMemory(hProcess, + NULL, + MemoryWorkingSetList, + pv, + cb, + NULL); + if (!NT_SUCCESS(Status)) + { + SetLastError(RtlNtStatusToDosError(Status)); + return FALSE; + } + + return TRUE; +} + +/* + * @implemented */ BOOL WINAPI @@ -1411,8 +1607,22 @@ IN OUT PVOID pv, IN DWORD cb) { - UNIMPLEMENTED; - return FALSE; + NTSTATUS Status; + + /* Simply forward the call */ + Status = NtQueryVirtualMemory(hProcess, + NULL, + MemoryWorkingSetExList, + pv, + cb, + NULL); + if (!NT_SUCCESS(Status)) + { + SetLastError(RtlNtStatusToDosError(Status)); + return FALSE; + } + + return TRUE; } /* EOF */
11 years, 1 month
1
0
0
0
[pschweitzer] 60793: [NDK] Complete MEMORY_INFORMATION_CLASS by adding a missing class (at the proper place): MemoryWorkingSetExList Alex, could you review please? Not fully sure about the name of ...
by pschweitzer@svn.reactos.org
Author: pschweitzer Date: Wed Oct 30 10:51:30 2013 New Revision: 60793 URL:
http://svn.reactos.org/svn/reactos?rev=60793&view=rev
Log: [NDK] Complete MEMORY_INFORMATION_CLASS by adding a missing class (at the proper place): MemoryWorkingSetExList Alex, could you review please? Not fully sure about the name of such class. Modified: trunk/reactos/include/ndk/mmtypes.h Modified: trunk/reactos/include/ndk/mmtypes.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/mmtypes.h?rev=…
============================================================================== --- trunk/reactos/include/ndk/mmtypes.h [iso-8859-1] (original) +++ trunk/reactos/include/ndk/mmtypes.h [iso-8859-1] Wed Oct 30 10:51:30 2013 @@ -169,7 +169,8 @@ MemoryBasicInformation, MemoryWorkingSetList, MemorySectionName, - MemoryBasicVlmInformation + MemoryBasicVlmInformation, + MemoryWorkingSetExList } MEMORY_INFORMATION_CLASS; //
11 years, 1 month
1
0
0
0
[pschweitzer] 60792: [PSDK] - Fix definition of PROCESS_MEMORY_COUNTERS - Add defintion for PROCESS_MEMORY_COUNTERS_EX
by pschweitzer@svn.reactos.org
Author: pschweitzer Date: Wed Oct 30 10:48:29 2013 New Revision: 60792 URL:
http://svn.reactos.org/svn/reactos?rev=60792&view=rev
Log: [PSDK] - Fix definition of PROCESS_MEMORY_COUNTERS - Add defintion for PROCESS_MEMORY_COUNTERS_EX Modified: trunk/reactos/include/psdk/psapi.h Modified: trunk/reactos/include/psdk/psapi.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/psdk/psapi.h?rev=6…
============================================================================== --- trunk/reactos/include/psdk/psapi.h [iso-8859-1] (original) +++ trunk/reactos/include/psdk/psapi.h [iso-8859-1] Wed Oct 30 10:48:29 2013 @@ -37,15 +37,29 @@ typedef struct _PROCESS_MEMORY_COUNTERS { DWORD cb; DWORD PageFaultCount; - DWORD PeakWorkingSetSize; - DWORD WorkingSetSize; - DWORD QuotaPeakPagedPoolUsage; - DWORD QuotaPagedPoolUsage; - DWORD QuotaPeakNonPagedPoolUsage; - DWORD QuotaNonPagedPoolUsage; - DWORD PagefileUsage; - DWORD PeakPagefileUsage; -} PROCESS_MEMORY_COUNTERS,*PPROCESS_MEMORY_COUNTERS; + SIZE_T PeakWorkingSetSize; + SIZE_T WorkingSetSize; + SIZE_T QuotaPeakPagedPoolUsage; + SIZE_T QuotaPagedPoolUsage; + SIZE_T QuotaPeakNonPagedPoolUsage; + SIZE_T QuotaNonPagedPoolUsage; + SIZE_T PagefileUsage; + SIZE_T PeakPagefileUsage; +} PROCESS_MEMORY_COUNTERS, *PPROCESS_MEMORY_COUNTERS; + +typedef struct _PROCESS_MEMORY_COUNTERS_EX { + DWORD cb; + DWORD PageFaultCount; + SIZE_T PeakWorkingSetSize; + SIZE_T WorkingSetSize; + SIZE_T QuotaPeakPagedPoolUsage; + SIZE_T QuotaPagedPoolUsage; + SIZE_T QuotaPeakNonPagedPoolUsage; + SIZE_T QuotaNonPagedPoolUsage; + SIZE_T PagefileUsage; + SIZE_T PeakPagefileUsage; + SIZE_T PrivateUsage; +} PROCESS_MEMORY_COUNTERS_EX, *PPROCESS_MEMORY_COUNTERS_EX; typedef struct _PERFORMANCE_INFORMATION { DWORD cb;
11 years, 1 month
1
0
0
0
← Newer
1
2
3
4
5
...
33
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
Results per page:
10
25
50
100
200