[ros-diffs] [tfaber] 74603: [HAL] - Fix a broken DPRINT

2017-05-19 Thread tfaber
Author: tfaber
Date: Fri May 19 21:37:50 2017
New Revision: 74603

URL: http://svn.reactos.org/svn/reactos?rev=74603=rev
Log:
[HAL]
- Fix a broken DPRINT

Modified:
trunk/reactos/hal/halx86/generic/bios.c

Modified: trunk/reactos/hal/halx86/generic/bios.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/generic/bios.c?rev=74603=74602=74603=diff
==
--- trunk/reactos/hal/halx86/generic/bios.c [iso-8859-1] (original)
+++ trunk/reactos/hal/halx86/generic/bios.c [iso-8859-1] Fri May 19 
21:37:50 2017
@@ -63,8 +63,8 @@
 PUCHAR Inst = (PUCHAR)(BiosFrame->CsBase + BiosFrame->Eip);
 
 /* Print error message */
-DPRINT1("HAL: An invalid V86 opcode was encountered at address %X:%X\n",
-"Opcode: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X",
+DPRINT1("HAL: An invalid V86 opcode was encountered at address %X:%X\n"
+"Opcode: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n",
 BiosFrame->SegCs, BiosFrame->Eip,
 Inst[0], Inst[1], Inst[2], Inst[3], Inst[4],
 Inst[5], Inst[6], Inst[7], Inst[8], Inst[9]);




[ros-diffs] [mjansen] 74602: [GDI32_APITEST] Improve GetFontResourceInfoW tests. Patch by Katayama Hirofumi MZ. ROSTESTS-269 #resolve #comment Thanks!

2017-05-19 Thread mjansen
Author: mjansen
Date: Fri May 19 20:26:49 2017
New Revision: 74602

URL: http://svn.reactos.org/svn/reactos?rev=74602=rev
Log:
[GDI32_APITEST] Improve GetFontResourceInfoW tests. Patch by Katayama Hirofumi 
MZ. ROSTESTS-269 #resolve #comment Thanks!

Added:
trunk/rostests/apitests/gdi32/ExampleFont.ttf   (with props)
Modified:
trunk/rostests/apitests/gdi32/GetFontResourceInfoW.c
trunk/rostests/apitests/gdi32/resource.rc

Added: trunk/rostests/apitests/gdi32/ExampleFont.ttf
URL: 
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/gdi32/ExampleFont.ttf?rev=74602
==
Binary file - no diff available.

Propchange: trunk/rostests/apitests/gdi32/ExampleFont.ttf
--
svn:mime-type = application/octet-stream

Modified: trunk/rostests/apitests/gdi32/GetFontResourceInfoW.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/gdi32/GetFontResourceInfoW.c?rev=74602=74601=74602=diff
==
--- trunk/rostests/apitests/gdi32/GetFontResourceInfoW.c[iso-8859-1] 
(original)
+++ trunk/rostests/apitests/gdi32/GetFontResourceInfoW.c[iso-8859-1] 
Fri May 19 20:26:49 2017
@@ -5,6 +5,7 @@
  * PROGRAMMERS: Katayama Hirofumi MZ 
  */
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -16,6 +17,7 @@
 typedef struct GFRI_ENTRY
 {
 LPCWSTR File;
+BOOLPreinstalled;
 WCHAR   FontInfo[64];
 INT FontCount;
 WCHAR   FaceNames[10][64];
@@ -24,9 +26,9 @@
 /* test entries */
 static const GFRI_ENTRY TestEntries[] =
 {
-{ L"symbol.ttf", L"Symbol|", 1, { L"Symbol" } },
-{ L"tahoma.ttf", L"Tahoma|", 1, { L"Tahoma" } },
-{ L"tahomabd.ttf", L"Tahoma Bold|", 1, { L"Tahoma" } }
+{ L"symbol.ttf", TRUE, L"Symbol|", 1, { L"Symbol" } },
+{ L"tahoma.ttf", TRUE, L"Tahoma|", 1, { L"Tahoma" } },
+{ L"tahomabd.ttf", TRUE, L"Tahoma Bold|", 1, { L"Tahoma" } }
 };
 
 /* Japanese */
@@ -34,7 +36,7 @@
 {
 {
 /* MS Gothic & MS UI Gothic & MS PGothic */
-L"msgothic.ttc",
+L"msgothic.ttc", TRUE, 
 {
 0xFF2D, 0xFF33, 0x0020, 0x30B4, 0x30B7, 0x30C3, 0x30AF, 0x0020,
 0x0026, 0x0020, 0x004D, 0x0053, 0x0020, 0x0055, 0x0049, 0x0020,
@@ -51,6 +53,14 @@
 { 0xFF2D, 0xFF33, 0x0020, 0xFF30, 0x30B4, 0x30B7, 0x30C3, 0x30AF, 
0 },
 { L'@', 0xFF2D, 0xFF33, 0x0020, 0xFF30, 0x30B4, 0x30B7, 0x30C3, 
0x30AF, 0 }
 }
+},
+{
+L"ExampleFont.ttf", FALSE,
+L"JapaneseDisplayName|",
+1,
+{
+L"JapaneseFamilyName"
+}
 }
 };
 
@@ -59,7 +69,7 @@
 {
 {
 /* MS Gothic & MS UI Gothic & MS PGothic */
-L"msgothic.ttc",
+L"msgothic.ttc", TRUE,
 L"MS Gothic & MS UI Gothic & MS PGothic|",
 6,
 {
@@ -70,6 +80,14 @@
 L"MS PGothic",
 L"@MS PGothic"
 }
+},
+{
+L"ExampleFont.ttf", FALSE,
+L"EnglishDisplayName|",
+1,
+{
+L"EnglishFamilyName"
+}
 }
 };
 
@@ -381,14 +399,56 @@
 static void
 DoEntry(const GFRI_ENTRY *Entry)
 {
-WCHAR szPath[MAX_PATH];
-
-GetSystemFontPath(szPath, Entry->File);
-printf("GetSystemFontPath: %S\n", szPath);
-if (GetFileAttributesW(szPath) == 0x)
-{
-skip("Font file \"%S\" was not found\n", szPath);
-return;
+WCHAR szPath[MAX_PATH], szTempPath[MAX_PATH];
+BOOL Installed = FALSE;
+
+if (Entry->Preinstalled)
+{
+GetSystemFontPath(szPath, Entry->File);
+printf("GetSystemFontPath: %S\n", szPath);
+if (GetFileAttributesW(szPath) == INVALID_FILE_ATTRIBUTES)
+{
+skip("Font file \"%S\" was not found\n", szPath);
+return;
+}
+}
+else
+{
+/* load font data from resource */
+HANDLE hFile;
+HMODULE hMod = GetModuleHandleW(NULL);
+HRSRC hRsrc = FindResourceW(hMod, Entry->File, (LPCWSTR)RT_RCDATA);
+HGLOBAL hGlobal = LoadResource(hMod, hRsrc);
+DWORD Size = SizeofResource(hMod, hRsrc);
+LPVOID pFont = LockResource(hGlobal);
+
+/* get temporary file name */
+GetTempPathW(_countof(szTempPath), szTempPath);
+GetTempFileNameW(szTempPath, L"FNT", 0, szPath);
+printf("GetTempFileNameW: %S\n", szPath);
+
+/* write to file */
+hFile = CreateFileW(szPath, GENERIC_WRITE, FILE_SHARE_READ, NULL,
+CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+WriteFile(hFile, pFont, Size, , NULL);
+CloseHandle(hFile);
+
+/* check existence */
+if (GetFileAttributesW(szPath) == INVALID_FILE_ATTRIBUTES)
+{
+skip("Font file \"%S\" was not 

[ros-diffs] [mjansen] 74601: [APPHELP] Initial implementation of ApphelpCheckRunAppEx. CORE-10368

2017-05-19 Thread mjansen
Author: mjansen
Date: Fri May 19 20:13:08 2017
New Revision: 74601

URL: http://svn.reactos.org/svn/reactos?rev=74601=rev
Log:
[APPHELP] Initial implementation of ApphelpCheckRunAppEx. CORE-10368

Modified:
trunk/reactos/dll/appcompat/apphelp/apphelp.c
trunk/reactos/dll/appcompat/apphelp/apphelp.h
trunk/reactos/dll/appcompat/apphelp/apphelp.spec
trunk/reactos/dll/appcompat/apphelp/hsdb.c

Modified: trunk/reactos/dll/appcompat/apphelp/apphelp.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/appcompat/apphelp/apphelp.c?rev=74601=74600=74601=diff
==
--- trunk/reactos/dll/appcompat/apphelp/apphelp.c   [iso-8859-1] (original)
+++ trunk/reactos/dll/appcompat/apphelp/apphelp.c   [iso-8859-1] Fri May 19 
20:13:08 2017
@@ -1,7 +1,7 @@
 /*
  * Copyright 2011 André Hentschel
  * Copyright 2013 Mislav Blažević
- * Copyright 2015 Mark Jansen
+ * Copyright 2015-2017 Mark Jansen
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -24,8 +24,9 @@
 #include "winver.h"
 #include "strsafe.h"
 #include "apphelp.h"
-
-#include "wine/winternl.h"
+#include "ndk/rtlfuncs.h"
+#include "ndk/kdtypes.h"
+
 
 /* from dpfilter.h */
 #define DPFLTR_APPCOMPAT_ID 123
@@ -35,23 +36,19 @@
 #endif
 
 ULONG g_ShimDebugLevel = 0x;
+HMODULE g_hInstance;
 
 void ApphelppInitDebugLevel(void)
 {
-UNICODE_STRING DebugKey, DebugValue;
+static const UNICODE_STRING DebugKey = 
RTL_CONSTANT_STRING(L"SHIM_DEBUG_LEVEL");
+UNICODE_STRING DebugValue;
 NTSTATUS Status;
 ULONG NewLevel = SHIM_ERR;
 WCHAR Buffer[40];
 
-RtlInitUnicodeString(, L"SHIM_DEBUG_LEVEL");
-DebugValue.MaximumLength = sizeof(Buffer);
-DebugValue.Buffer = Buffer;
-DebugValue.Length = 0;
-
-/* Hold the lock as short as possible. */
-RtlAcquirePebLock();
+RtlInitEmptyUnicodeString(, Buffer, sizeof(Buffer));
+
 Status = RtlQueryEnvironmentVariable_U(NULL, , );
-RtlReleasePebLock();
 
 if (NT_SUCCESS(Status))
 {
@@ -60,6 +57,7 @@
 }
 g_ShimDebugLevel = NewLevel;
 }
+
 
 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
 {
@@ -70,6 +68,7 @@
 return FALSE;/* prefer native version */
 #endif
 case DLL_PROCESS_ATTACH:
+g_hInstance = hinst;
 DisableThreadLibraryCalls( hinst );
 SdbpHeapInit();
 break;
@@ -145,9 +144,11 @@
 break;
 }
 StringCchPrintfExA(Current, Length, , , 
STRSAFE_NULL_ON_FAILURE, "[%s][%-20s] ", LevelStr, FunctionName);
+
 va_start(ArgList, Format);
 StringCchVPrintfExA(Current, Length, , , 
STRSAFE_NULL_ON_FAILURE, Format, ArgList);
 va_end(ArgList);
+
 #if defined(APPCOMPAT_USE_DBGPRINTEX) && APPCOMPAT_USE_DBGPRINTEX
 return NT_SUCCESS(DbgPrintEx(DPFLTR_APPCOMPAT_ID, Level, "%s", Buffer));
 #else
@@ -156,3 +157,102 @@
 #endif
 }
 
+
+#define APPHELP_DONTWRITE_REASON2
+#define APPHELP_CLEARBITS   0x100   /* TODO: Investigate */
+#define APPHELP_IGNORE_ENVIRONMENT  0x400
+
+#define APPHELP_VALID_RESULT0x1
+#define APPHELP_RESULT_NOTFOUND 0x2
+#define APPHELP_RESULT_FOUND0x4
+
+/**
+ * Lookup Shims / Fixes for the specified application
+ *
+ * @param [in]  FileHandle  Handle to the file to check.
+ * @param [in]  Unk1
+ * @param [in]  Unk2
+ * @param [in]  ApplicationName Exe to check
+ * @param [in]  Environment The environment variables to use, 
or NULL to use the current environment.
+ * @param [in]  ExeType Exe type (MACHINE_TYPE_)
+ * @param [in,out]  Reason  Input/output flags
+ * @param [in]  SdbQueryAppCompatData   The resulting data.
+ * @param [in]  SdbQueryAppCompatDataSize   The resulting data size.
+ * @param [in]  SxsData TODO
+ * @param [in]  SxsDataSize TODO
+ * @param [in]  FusionFlags TODO
+ * @param [in]  SomeFlag1   TODO
+ * @param [in]  SomeFlag2   TODO
+ *
+ * @return  TRUE if the application is allowed to run.
+ */
+BOOL
+WINAPI
+ApphelpCheckRunAppEx(
+_In_ HANDLE FileHandle,
+_In_opt_ PVOID Unk1,
+_In_opt_ PVOID Unk2,
+_In_opt_z_ PWCHAR ApplicationName,
+_In_opt_ PVOID Environment,
+_In_opt_ USHORT ExeType,
+_Inout_opt_ PULONG Reason,
+_Out_opt_ PVOID* SdbQueryAppCompatData,
+_Out_opt_ PULONG SdbQueryAppCompatDataSize,
+_Out_opt_ PVOID* SxsData,
+_Out_opt_ PULONG SxsDataSize,
+_Out_opt_ PULONG FusionFlags,
+_Out_opt_ PULONG64 SomeFlag1,
+_Out_opt_ PULONG SomeFlag2)
+{
+SDBQUERYRESULT* result = NULL;
+HSDB hsdb = NULL;
+DWORD dwFlags = 0;
+
+if (SxsData)
+*SxsData = NULL;
+if (SxsDataSize)
+*SxsDataSize = 0;
+if (FusionFlags)
+*FusionFlags = 

[ros-diffs] [tfaber] 74600: [NTDLL:LDR] - Fix logic error in LdrpInit that caused us to busy-wait instead of sleep. This makes LibreOffice start up in a few seconds instead of sitting around at 100% C

2017-05-19 Thread tfaber
Author: tfaber
Date: Fri May 19 19:11:14 2017
New Revision: 74600

URL: http://svn.reactos.org/svn/reactos?rev=74600=rev
Log:
[NTDLL:LDR]
- Fix logic error in LdrpInit that caused us to busy-wait instead of sleep. 
This makes LibreOffice start up in a few seconds instead of sitting around at 
100% CPU for a minute or two.
CORE-13268 #resolve

Modified:
trunk/reactos/dll/ntdll/ldr/ldrinit.c

Modified: trunk/reactos/dll/ntdll/ldr/ldrinit.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/ldrinit.c?rev=74600=74599=74600=diff
==
--- trunk/reactos/dll/ntdll/ldr/ldrinit.c   [iso-8859-1] (original)
+++ trunk/reactos/dll/ntdll/ldr/ldrinit.c   [iso-8859-1] Fri May 19 
19:11:14 2017
@@ -2223,11 +2223,11 @@
   1,
   0) == 1)
 {
-/* Set the timeout to 30 seconds */
+/* Set the timeout to 30 milliseconds */
 Timeout.QuadPart = Int32x32To64(30, -1);
 
 /* Make sure the status hasn't changed */
-while (!LdrpProcessInitialized)
+while (LdrpProcessInitialized == 1)
 {
 /* Do the wait */
 ZwDelayExecution(FALSE, );




[ros-diffs] [tfaber] 74599: [RTL] - Do not change RTL_HANDLE_TABLE::CommittedHandles when committing a new page of handle entries. This value must always point to the beginning of the allocation, to c

2017-05-19 Thread tfaber
Author: tfaber
Date: Fri May 19 18:22:46 2017
New Revision: 74599

URL: http://svn.reactos.org/svn/reactos?rev=74599=rev
Log:
[RTL]
- Do not change RTL_HANDLE_TABLE::CommittedHandles when committing a new page 
of handle entries. This value must always point to the beginning of the 
allocation, to correctly track the entire committed range. Fixes LibreOffice 
Writer (and ntdll_apitest) crash.
CORE-13271 #resolve

Modified:
trunk/reactos/sdk/lib/rtl/handle.c

Modified: trunk/reactos/sdk/lib/rtl/handle.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/sdk/lib/rtl/handle.c?rev=74599=74598=74599=diff
==
--- trunk/reactos/sdk/lib/rtl/handle.c  [iso-8859-1] (original)
+++ trunk/reactos/sdk/lib/rtl/handle.c  [iso-8859-1] Fri May 19 18:22:46 2017
@@ -89,6 +89,7 @@
 return NULL;
 
 /* Update handle array pointers */
+HandleTable->CommittedHandles = 
(PRTL_HANDLE_TABLE_ENTRY)ArrayPointer;
 HandleTable->UnCommittedHandles = 
(PRTL_HANDLE_TABLE_ENTRY)ArrayPointer;
 HandleTable->MaxReservedHandles = 
(PRTL_HANDLE_TABLE_ENTRY)((ULONG_PTR)ArrayPointer + ArraySize);
 }
@@ -107,7 +108,6 @@
 
 /* Update handle array pointers */
 HandleTable->FreeHandles = (PRTL_HANDLE_TABLE_ENTRY)ArrayPointer;
-HandleTable->CommittedHandles = (PRTL_HANDLE_TABLE_ENTRY)ArrayPointer;
 HandleTable->UnCommittedHandles = 
(PRTL_HANDLE_TABLE_ENTRY)((ULONG_PTR)ArrayPointer + ArraySize);
 
 /* Calculate the number of entries we can store in the array */




[ros-diffs] [tfaber] 74598: [NTDLL_APITEST] - Add a test for RTL handle tables CORE-13271

2017-05-19 Thread tfaber
Author: tfaber
Date: Fri May 19 18:05:12 2017
New Revision: 74598

URL: http://svn.reactos.org/svn/reactos?rev=74598=rev
Log:
[NTDLL_APITEST]
- Add a test for RTL handle tables
CORE-13271

Added:
trunk/rostests/apitests/ntdll/RtlHandle.c   (with props)
Modified:
trunk/rostests/apitests/ntdll/CMakeLists.txt
trunk/rostests/apitests/ntdll/testlist.c

Modified: trunk/rostests/apitests/ntdll/CMakeLists.txt
URL: 
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ntdll/CMakeLists.txt?rev=74598=74597=74598=diff
==
--- trunk/rostests/apitests/ntdll/CMakeLists.txt[iso-8859-1] (original)
+++ trunk/rostests/apitests/ntdll/CMakeLists.txt[iso-8859-1] Fri May 19 
18:05:12 2017
@@ -40,6 +40,7 @@
 RtlGetFullPathName_UstrEx.c
 RtlGetLengthWithoutTrailingPathSeperators.c
 RtlGetLongestNtPathLength.c
+RtlHandle.c
 RtlImageRvaToVa.c
 RtlInitializeBitMap.c
 RtlIsNameLegalDOS8Dot3.c

Added: trunk/rostests/apitests/ntdll/RtlHandle.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ntdll/RtlHandle.c?rev=74598
==
--- trunk/rostests/apitests/ntdll/RtlHandle.c   (added)
+++ trunk/rostests/apitests/ntdll/RtlHandle.c   [iso-8859-1] Fri May 19 
18:05:12 2017
@@ -0,0 +1,201 @@
+/*
+ * PROJECT: ReactOS API tests
+ * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
+ * PURPOSE: Test for Rtl handle tables
+ * PROGRAMMER:  Thomas Faber 
+ */
+
+#include 
+
+#define WIN32_NO_STATUS
+#include 
+#include 
+
+typedef struct _TEST_HANDLE_ENTRY
+{
+RTL_HANDLE_TABLE_ENTRY HandleEntry;
+ULONG Data;
+} TEST_HANDLE_ENTRY, *PTEST_HANDLE_ENTRY;
+
+START_TEST(RtlHandle)
+{
+const ULONG MaxHandles = 2048;
+RTL_HANDLE_TABLE HandleTable;
+PUCHAR HandleBase;
+PRTL_HANDLE_TABLE_ENTRY HandleEntry;
+PTEST_HANDLE_ENTRY TestEntry;
+PTEST_HANDLE_ENTRY TestEntry2;
+ULONG Index;
+BOOLEAN Valid;
+ULONG i;
+
+/* Initialize handle table */
+RtlFillMemory(, sizeof(HandleTable), 0x55);
+RtlInitializeHandleTable(MaxHandles, sizeof(TEST_HANDLE_ENTRY), 
);
+ok(HandleTable.MaximumNumberOfHandles == MaxHandles, 
"MaximumNumberOfHandles = %lu\n", HandleTable.MaximumNumberOfHandles);
+ok(HandleTable.SizeOfHandleTableEntry == sizeof(TEST_HANDLE_ENTRY),
+   "SizeOfHandleTableEntry = %lu\n", HandleTable.SizeOfHandleTableEntry);
+ok(HandleTable.Reserved[0] == 0, "Reserved[0] = 0x%lx\n", 
HandleTable.Reserved[0]);
+ok(HandleTable.Reserved[1] == 0, "Reserved[1] = 0x%lx\n", 
HandleTable.Reserved[1]);
+ok(HandleTable.CommittedHandles == NULL, "CommittedHandles = %p\n", 
HandleTable.CommittedHandles);
+ok(HandleTable.UnCommittedHandles == NULL, "UnCommittedHandles = %p\n", 
HandleTable.UnCommittedHandles);
+ok(HandleTable.MaxReservedHandles == NULL, "MaxReservedHandles = %p\n", 
HandleTable.MaxReservedHandles);
+ok(HandleTable.FreeHandles == NULL, "FreeHandles = %p\n", 
HandleTable.FreeHandles);
+
+/* Allocate a handle, now we have a committed page */
+HandleEntry = RtlAllocateHandle(, );
+
+ok(HandleTable.CommittedHandles != NULL, "CommittedHandles = %p\n", 
HandleTable.CommittedHandles);
+HandleBase = (PUCHAR)HandleTable.CommittedHandles;
+
+trace("CommittedHandles = %p\n", HandleBase);
+ok((PUCHAR)HandleTable.UnCommittedHandles == HandleBase + PAGE_SIZE, 
"UnCommittedHandles = %p\n", HandleTable.UnCommittedHandles);
+ok((PUCHAR)HandleTable.MaxReservedHandles == HandleBase + MaxHandles * 
sizeof(TEST_HANDLE_ENTRY), "MaxReservedHandles = %p\n", 
HandleTable.MaxReservedHandles);
+ok((PUCHAR)HandleTable.FreeHandles == HandleBase + 
sizeof(TEST_HANDLE_ENTRY), "FreeHandles = %p\n", HandleTable.FreeHandles);
+
+ok((PUCHAR)HandleEntry == HandleBase, "HandleEntry = %p\n", HandleEntry);
+ok(Index == 0, "Index = %lu\n", Index);
+
+ok(HandleEntry->Flags == 0, "Flags = 0x%lx\n", HandleEntry->Flags);
+
+TestEntry = (PTEST_HANDLE_ENTRY)HandleEntry;
+ok(TestEntry->Data == 0, "Data = %lu\n", TestEntry->Data);
+TestEntry->Data = 0x87654321;
+
+/* Handle is not recognized as valid unless we set the valid flag */
+Valid = RtlIsValidHandle(, >HandleEntry);
+ok(Valid == FALSE, "Valid = %u\n", Valid);
+HandleEntry = InvalidPointer;
+Valid = RtlIsValidIndexHandle(, 0, );
+ok(Valid == FALSE, "Valid = %u\n", Valid);
+ok(HandleEntry == InvalidPointer, "HandleEntry = %p\n", HandleEntry);
+
+TestEntry->HandleEntry.Flags = RTL_HANDLE_VALID;
+Valid = RtlIsValidHandle(, >HandleEntry);
+ok(Valid == TRUE, "Valid = %u\n", Valid);
+HandleEntry = InvalidPointer;
+Valid = RtlIsValidIndexHandle(, 0, );
+ok(Valid == TRUE, "Valid = %u\n", Valid);
+ok(HandleEntry == >HandleEntry, "HandleEntry = %p\n", 
HandleEntry);
+
+/* 

[ros-diffs] [hbelusca] 74597: [SCSIPORT]: Fixes: - In SpiScanAdapter(), after an SCSI INQUIRY command has succeeded and we are setting up a LUN extension structure, cache in its InquiryData member the

2017-05-19 Thread hbelusca
Author: hbelusca
Date: Fri May 19 16:14:10 2017
New Revision: 74597

URL: http://svn.reactos.org/svn/reactos?rev=74597=rev
Log:
[SCSIPORT]: Fixes:
- In SpiScanAdapter(), after an SCSI INQUIRY command has succeeded and we are 
setting up a LUN extension structure,
  cache in its InquiryData member the inquiry data retrieved from the INQUIRY 
command (alternatively we might just cache
  a pointer to a valid "LunInfo" since the latter are also cached elsewhere).
- This allows SpiBuildDeviceMap(), which is called just after SpiScanAdapter(), 
to correctly report in the registry SCSI tree
  the correct Identifier and DeviceType values for the enumerated logical units.
- Use ExFreePoolWithTag in SpiScanAdapter().

Modified:
trunk/reactos/drivers/storage/scsiport/scsiport.c

Modified: trunk/reactos/drivers/storage/scsiport/scsiport.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/storage/scsiport/scsiport.c?rev=74597=74596=74597=diff
==
--- trunk/reactos/drivers/storage/scsiport/scsiport.c   [iso-8859-1] (original)
+++ trunk/reactos/drivers/storage/scsiport/scsiport.c   [iso-8859-1] Fri May 19 
16:14:10 2017
@@ -101,7 +101,7 @@
IN OUT PSCSI_LUN_INFO LunInfo);
 
 static VOID
-SpiScanAdapter (IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension);
+SpiScanAdapter(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension);
 
 static NTSTATUS
 SpiGetInquiryData (IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
@@ -3911,6 +3911,14 @@
 DPRINT("SpiScanAdapter(): Found device of type %d at bus 
%d tid %d lun %d\n",
 InquiryData->DeviceType, Bus, Target, Lun);
 
+/*
+ * Cache the inquiry data into the LUN extension (or 
alternatively
+ * we could save a pointer to LunInfo within the 
LunExtension?)
+ */
+RtlCopyMemory(>InquiryData,
+  InquiryData,
+  INQUIRYDATABUFFERSIZE);
+
 /* Add this info to the linked list */
 LunInfo->Next = NULL;
 if (LastLunInfo)
@@ -3956,10 +3964,10 @@
 
 /* Free allocated buffers */
 if (LunExtension)
-ExFreePool(LunExtension);
+ExFreePoolWithTag(LunExtension, TAG_SCSIPORT);
 
 if (LunInfo)
-ExFreePool(LunInfo);
+ExFreePoolWithTag(LunInfo, TAG_SCSIPORT);
 
 /* Sum what we found */
 BusScanInfo->LogicalUnitsCount += (UCHAR)DevicesFound;




[ros-diffs] [hbelusca] 74596: [SCSIPORT]: Code formatting only.

2017-05-19 Thread hbelusca
Author: hbelusca
Date: Fri May 19 16:08:40 2017
New Revision: 74596

URL: http://svn.reactos.org/svn/reactos?rev=74596=rev
Log:
[SCSIPORT]: Code formatting only.

Modified:
trunk/reactos/drivers/storage/scsiport/scsiport.c

Modified: trunk/reactos/drivers/storage/scsiport/scsiport.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/storage/scsiport/scsiport.c?rev=74596=74595=74596=diff
==
--- trunk/reactos/drivers/storage/scsiport/scsiport.c   [iso-8859-1] (original)
+++ trunk/reactos/drivers/storage/scsiport/scsiport.c   [iso-8859-1] Fri May 19 
16:08:40 2017
@@ -83,7 +83,7 @@
   PVOID MapRegisterBase, PVOID Context);
 
 static PSCSI_PORT_LUN_EXTENSION
-SpiAllocateLunExtension (IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension);
+SpiAllocateLunExtension(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension);
 
 static PSCSI_PORT_LUN_EXTENSION
 SpiGetLunExtension (IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
@@ -97,8 +97,8 @@
  PSCSI_REQUEST_BLOCK Srb);
 
 static NTSTATUS
-SpiSendInquiry (IN PDEVICE_OBJECT DeviceObject,
-   IN PSCSI_LUN_INFO LunInfo);
+SpiSendInquiry(IN PDEVICE_OBJECT DeviceObject,
+   IN OUT PSCSI_LUN_INFO LunInfo);
 
 static VOID
 SpiScanAdapter (IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension);
@@ -136,8 +136,8 @@
IN PVOID Context);
 
 static NTSTATUS
-SpiBuildDeviceMap (PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
-  PUNICODE_STRING RegistryPath);
+SpiBuildDeviceMap(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
+  IN PUNICODE_STRING RegistryPath);
 
 static NTSTATUS
 SpiStatusSrbToNt(UCHAR SrbStatus);
@@ -3322,17 +3322,16 @@
 }
 
 static PSCSI_PORT_LUN_EXTENSION
-SpiAllocateLunExtension (IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension)
+SpiAllocateLunExtension(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension)
 {
 PSCSI_PORT_LUN_EXTENSION LunExtension;
 ULONG LunExtensionSize;
 
-DPRINT("SpiAllocateLunExtension (%p)\n",
-DeviceExtension);
+DPRINT("SpiAllocateLunExtension(%p)\n", DeviceExtension);
 
 /* Round LunExtensionSize first to the sizeof LONGLONG */
 LunExtensionSize = (DeviceExtension->LunExtensionSize +
-sizeof(LONGLONG) - 1) & ~(sizeof(LONGLONG) - 1);
+sizeof(LONGLONG) - 1) & ~(sizeof(LONGLONG) - 1);
 
 LunExtensionSize += sizeof(SCSI_PORT_LUN_EXTENSION);
 DPRINT("LunExtensionSize %lu\n", LunExtensionSize);
@@ -3357,7 +3356,7 @@
 LunExtension->MaxQueueCount = 256;
 
 /* Initialize request queue */
-KeInitializeDeviceQueue (>DeviceQueue);
+KeInitializeDeviceQueue(>DeviceQueue);
 
 return LunExtension;
 }
@@ -3547,8 +3546,8 @@
 
 
 static NTSTATUS
-SpiSendInquiry (IN PDEVICE_OBJECT DeviceObject,
-IN PSCSI_LUN_INFO LunInfo)
+SpiSendInquiry(IN PDEVICE_OBJECT DeviceObject,
+   IN OUT PSCSI_LUN_INFO LunInfo)
 {
 IO_STATUS_BLOCK IoStatusBlock;
 PIO_STACK_LOCATION IrpStack;
@@ -3677,9 +3676,9 @@
 DPRINT("SpiSendInquiry(): the queue is frozen at TargetId %d\n", 
Srb.TargetId);
 
 LunExtension = SpiGetLunExtension(DeviceExtension,
-LunInfo->PathId,
-LunInfo->TargetId,
-LunInfo->Lun);
+  LunInfo->PathId,
+  LunInfo->TargetId,
+  LunInfo->Lun);
 
 /* Clear frozen flag */
 LunExtension->Flags &= ~LUNEX_FROZEN_QUEUE;
@@ -3711,7 +3710,7 @@
 KeepTrying = FALSE;
 }
 else if ((Srb.SrbStatus & SRB_STATUS_AUTOSENSE_VALID) &&
-SenseBuffer->SenseKey == SCSI_SENSE_ILLEGAL_REQUEST)
+ SenseBuffer->SenseKey == SCSI_SENSE_ILLEGAL_REQUEST)
 {
 /* LUN is not valid, but some device responds there.
 Mark it as invalid anyway */
@@ -3801,7 +3800,6 @@
 {
 /* We need to allocate this buffer */
 BusScanInfo = ExAllocatePoolWithTag(NonPagedPool, 
sizeof(SCSI_BUS_SCAN_INFO), TAG_SCSIPORT);
-
 if (!BusScanInfo)
 {
 DPRINT1("Out of resources!\n");
@@ -3823,8 +3821,7 @@
 
 /* Create LUN information structure */
 LunInfo = ExAllocatePoolWithTag(PagedPool, sizeof(SCSI_LUN_INFO), 
TAG_SCSIPORT);
-
-if (LunInfo == NULL)
+if (!LunInfo)
 {
 DPRINT1("Out of resources!\n");
 return;
@@ -3833,7 +3830,7 @@
 RtlZeroMemory(LunInfo, sizeof(SCSI_LUN_INFO));
 
 /* Create LunExtension */
-LunExtension = SpiAllocateLunExtension (DeviceExtension);
+LunExtension = SpiAllocateLunExtension(DeviceExtension);
 
 /* And send 

[ros-diffs] [hbelusca] 74595: [SCSIPORT]: Fixes + documentation: - In SpiSendInquiry(): * use ExFreePoolWithTag; * if IoBuildDeviceIoControlRequest() fails, exit correctly the loop so that the allocat

2017-05-19 Thread hbelusca
Author: hbelusca
Date: Fri May 19 15:02:02 2017
New Revision: 74595

URL: http://svn.reactos.org/svn/reactos?rev=74595=rev
Log:
[SCSIPORT]: Fixes + documentation:
- In SpiSendInquiry():
  * use ExFreePoolWithTag;
  * if IoBuildDeviceIoControlRequest() fails, exit correctly the loop so that 
the allocated buffers are cleaned up;
- In SpiBuildDeviceMap():
  * support new peripheral type names, as documented in the links in the 
comments;
  * fix the "CommunicationsPeripheral" name (communication'S') as documented, 
and as done in windows' scsiport driver.

Modified:
trunk/reactos/drivers/storage/scsiport/scsiport.c

Modified: trunk/reactos/drivers/storage/scsiport/scsiport.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/storage/scsiport/scsiport.c?rev=74595=74594=74595=diff
==
--- trunk/reactos/drivers/storage/scsiport/scsiport.c   [iso-8859-1] (original)
+++ trunk/reactos/drivers/storage/scsiport/scsiport.c   [iso-8859-1] Fri May 19 
15:02:02 2017
@@ -3565,7 +3565,7 @@
 PSCSI_PORT_LUN_EXTENSION LunExtension;
 PSCSI_PORT_DEVICE_EXTENSION DeviceExtension;
 
-DPRINT ("SpiSendInquiry() called\n");
+DPRINT("SpiSendInquiry() called\n");
 
 DeviceExtension = 
(PSCSI_PORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
 
@@ -3576,7 +3576,7 @@
 SenseBuffer = ExAllocatePoolWithTag(NonPagedPool, SENSE_BUFFER_SIZE, 
TAG_SCSIPORT);
 if (SenseBuffer == NULL)
 {
-ExFreePool(InquiryBuffer);
+ExFreePoolWithTag(InquiryBuffer, TAG_SCSIPORT);
 return STATUS_INSUFFICIENT_RESOURCES;
 }
 
@@ -3600,7 +3600,11 @@
 if (Irp == NULL)
 {
 DPRINT("IoBuildDeviceIoControlRequest() failed\n");
-return STATUS_INSUFFICIENT_RESOURCES;
+
+/* Quit the loop */
+Status = STATUS_INSUFFICIENT_RESOURCES;
+KeepTrying = FALSE;
+continue;
 }
 
 /* Prepare SRB */
@@ -3656,6 +3660,7 @@
   InquiryBuffer,
   INQUIRYDATABUFFERSIZE);
 
+/* Quit the loop */
 Status = STATUS_SUCCESS;
 KeepTrying = FALSE;
 continue;
@@ -3701,6 +3706,7 @@
 (Srb.DataTransferLength > INQUIRYDATABUFFERSIZE) ?
 INQUIRYDATABUFFERSIZE : Srb.DataTransferLength);
 
+/* Quit the loop */
 Status = STATUS_SUCCESS;
 KeepTrying = FALSE;
 }
@@ -3710,6 +3716,7 @@
 /* LUN is not valid, but some device responds there.
 Mark it as invalid anyway */
 
+/* Quit the loop */
 Status = STATUS_INVALID_DEVICE_REQUEST;
 KeepTrying = FALSE;
 }
@@ -3725,7 +3732,7 @@
 }
 else
 {
-/* That's all, go to exit */
+/* That's all, quit the loop */
 KeepTrying = FALSE;
 
 /* Set status according to SRB status */
@@ -3743,8 +3750,8 @@
 }
 
 /* Free buffers */
-ExFreePool(InquiryBuffer);
-ExFreePool(SenseBuffer);
+ExFreePoolWithTag(InquiryBuffer, TAG_SCSIPORT);
+ExFreePoolWithTag(SenseBuffer, TAG_SCSIPORT);
 
 DPRINT("SpiSendInquiry() done with Status 0x%08X\n", Status);
 
@@ -5574,6 +5581,11 @@
 }
 
 /* Set 'Type' (REG_SZ) value */
+/*
+ * See 
https://docs.microsoft.com/en-us/windows-hardware/drivers/install/identifiers-for-ide-devices
+ * and 
https://docs.microsoft.com/en-us/windows-hardware/drivers/install/identifiers-for-scsi-devices
+ * for a list of types with their human-readable forms.
+ */
 switch (LunExtension->InquiryData.DeviceType)
 {
 case 0:
@@ -5585,6 +5597,7 @@
 case 2:
 TypeName = L"PrinterPeripheral";
 break;
+// case 3: "ProcessorPeripheral", classified as 'other': 
fall back to default case.
 case 4:
 TypeName = L"WormPeripheral";
 break;
@@ -5601,8 +5614,29 @@
 TypeName = L"MediumChangerPeripheral";
 break;
 case 9:
-TypeName = L"CommunicationPeripheral";
+TypeName = L"CommunicationsPeripheral";
 break;
+
+/* New peripheral types (SCSI only) */
+case 10: case 11:
+TypeName = L"ASCPrePressGraphicsPeripheral";
+break;
+case 12:
+TypeName = L"ArrayPeripheral";
+break;
+case 13:
+TypeName = 

[ros-diffs] [hbelusca] 74594: [SCSIPORT]: Code formatting in the functions I'm going to touch next (in addition, add few "continue; " inside some loops so that I can reduce the indent level of code bl

2017-05-19 Thread hbelusca
Author: hbelusca
Date: Fri May 19 14:49:23 2017
New Revision: 74594

URL: http://svn.reactos.org/svn/reactos?rev=74594=rev
Log:
[SCSIPORT]: Code formatting in the functions I'm going to touch next (in 
addition, add few "continue;" inside some loops so that I can reduce the indent 
level of code blocks).

Modified:
trunk/reactos/drivers/storage/scsiport/scsiport.c

Modified: trunk/reactos/drivers/storage/scsiport/scsiport.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/storage/scsiport/scsiport.c?rev=74594=74593=74594=diff
==
--- trunk/reactos/drivers/storage/scsiport/scsiport.c   [iso-8859-1] (original)
+++ trunk/reactos/drivers/storage/scsiport/scsiport.c   [iso-8859-1] Fri May 19 
14:49:23 2017
@@ -3548,7 +3548,7 @@
 
 static NTSTATUS
 SpiSendInquiry (IN PDEVICE_OBJECT DeviceObject,
-   IN PSCSI_LUN_INFO LunInfo)
+IN PSCSI_LUN_INFO LunInfo)
 {
 IO_STATUS_BLOCK IoStatusBlock;
 PIO_STACK_LOCATION IrpStack;
@@ -3569,11 +3569,11 @@
 
 DeviceExtension = 
(PSCSI_PORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
 
-InquiryBuffer = ExAllocatePoolWithTag (NonPagedPool, 
INQUIRYDATABUFFERSIZE, TAG_SCSIPORT);
+InquiryBuffer = ExAllocatePoolWithTag(NonPagedPool, INQUIRYDATABUFFERSIZE, 
TAG_SCSIPORT);
 if (InquiryBuffer == NULL)
 return STATUS_INSUFFICIENT_RESOURCES;
 
-SenseBuffer = ExAllocatePoolWithTag (NonPagedPool, SENSE_BUFFER_SIZE, 
TAG_SCSIPORT);
+SenseBuffer = ExAllocatePoolWithTag(NonPagedPool, SENSE_BUFFER_SIZE, 
TAG_SCSIPORT);
 if (SenseBuffer == NULL)
 {
 ExFreePool(InquiryBuffer);
@@ -3589,14 +3589,14 @@
 
 /* Create an IRP */
 Irp = IoBuildDeviceIoControlRequest(IOCTL_SCSI_EXECUTE_IN,
-DeviceObject,
-NULL,
-0,
-InquiryBuffer,
-INQUIRYDATABUFFERSIZE,
-TRUE,
-,
-);
+DeviceObject,
+NULL,
+0,
+InquiryBuffer,
+INQUIRYDATABUFFERSIZE,
+TRUE,
+,
+);
 if (Irp == NULL)
 {
 DPRINT("IoBuildDeviceIoControlRequest() failed\n");
@@ -3640,10 +3640,10 @@
 {
 DPRINT("SpiSendInquiry(): Waiting for the driver to process 
request...\n");
 KeWaitForSingleObject(,
-Executive,
-KernelMode,
-FALSE,
-NULL);
+  Executive,
+  KernelMode,
+  FALSE,
+  NULL);
 Status = IoStatusBlock.Status;
 }
 
@@ -3658,84 +3658,85 @@
 
 Status = STATUS_SUCCESS;
 KeepTrying = FALSE;
+continue;
+}
+
+DPRINT("Inquiry SRB failed with SrbStatus 0x%08X\n", Srb.SrbStatus);
+
+/* Check if the queue is frozen */
+if (Srb.SrbStatus & SRB_STATUS_QUEUE_FROZEN)
+{
+/* Something weird happened, deal with it (unfreeze the queue) */
+KeepTrying = FALSE;
+
+DPRINT("SpiSendInquiry(): the queue is frozen at TargetId %d\n", 
Srb.TargetId);
+
+LunExtension = SpiGetLunExtension(DeviceExtension,
+LunInfo->PathId,
+LunInfo->TargetId,
+LunInfo->Lun);
+
+/* Clear frozen flag */
+LunExtension->Flags &= ~LUNEX_FROZEN_QUEUE;
+
+/* Acquire the spinlock */
+KeAcquireSpinLock(>SpinLock, );
+
+/* Process the request */
+SpiGetNextRequestFromLun(DeviceObject->DeviceExtension, 
LunExtension);
+
+/* SpiGetNextRequestFromLun() releases the spinlock,
+so we just lower irql back to what it was before */
+KeLowerIrql(Irql);
+}
+
+/* Check if data overrun happened */
+if (SRB_STATUS(Srb.SrbStatus) == SRB_STATUS_DATA_OVERRUN)
+{
+DPRINT("Data overrun at TargetId %d\n", LunInfo->TargetId);
+
+/* Nothing dramatic, just copy data, but limiting the size */
+RtlCopyMemory(LunInfo->InquiryData,
+InquiryBuffer,
+(Srb.DataTransferLength > INQUIRYDATABUFFERSIZE) ?
+INQUIRYDATABUFFERSIZE : Srb.DataTransferLength);
+
+Status = STATUS_SUCCESS;
+KeepTrying = FALSE;
+}
+else if ((Srb.SrbStatus & SRB_STATUS_AUTOSENSE_VALID) &&
+  

[ros-diffs] [gadamopoulos] 74593: [UXTHEME] -Use and RTL handle table for HTHEME handles. In this way we can ensure that a value we take is valid even if it is non NULL. We can also detect leaks.

2017-05-19 Thread gadamopoulos
Author: gadamopoulos
Date: Fri May 19 11:02:44 2017
New Revision: 74593

URL: http://svn.reactos.org/svn/reactos?rev=74593=rev
Log:
[UXTHEME] -Use and RTL handle table for HTHEME handles. In this way we can 
ensure that a value we take is valid even if it is non NULL. We can also detect 
leaks.

Modified:
trunk/reactos/dll/win32/uxtheme/draw.c
trunk/reactos/dll/win32/uxtheme/metric.c
trunk/reactos/dll/win32/uxtheme/msstyles.c
trunk/reactos/dll/win32/uxtheme/property.c
trunk/reactos/dll/win32/uxtheme/system.c
trunk/reactos/dll/win32/uxtheme/uxthemep.h

Modified: trunk/reactos/dll/win32/uxtheme/draw.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/uxtheme/draw.c?rev=74593=74592=74593=diff
==
--- trunk/reactos/dll/win32/uxtheme/draw.c  [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/uxtheme/draw.c  [iso-8859-1] Fri May 19 
11:02:44 2017
@@ -146,16 +146,19 @@
  */
 static PTHEME_PROPERTY UXTHEME_SelectImage(HTHEME hTheme, HDC hdc, int 
iPartId, int iStateId, const RECT *pRect, BOOL glyph)
 {
+PTHEME_CLASS pClass;
 PTHEME_PROPERTY tp;
 int imageselecttype = IST_NONE;
 int i;
 int image;
+
 if(glyph)
 image = TMT_GLYPHIMAGEFILE;
 else
 image = TMT_IMAGEFILE;
 
-if((tp=MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FILENAME, 
image)))
+pClass = ValidateHandle(hTheme);
+if((tp=MSSTYLES_FindProperty(pClass, iPartId, iStateId, TMT_FILENAME, 
image)))
 return tp;
 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_IMAGESELECTTYPE, 
);
 
@@ -167,19 +170,19 @@
 if(SUCCEEDED(GetThemeInt(hTheme, iPartId, iStateId, i + 
TMT_MINDPI1, ))) {
 if(reqdpi != 0 && screendpi >= reqdpi) {
 TRACE("Using %d DPI, image %d\n", reqdpi, i + 
TMT_IMAGEFILE1);
-return MSSTYLES_FindProperty(hTheme, iPartId, iStateId, 
TMT_FILENAME, i + TMT_IMAGEFILE1);
+return MSSTYLES_FindProperty(pClass, iPartId, iStateId, 
TMT_FILENAME, i + TMT_IMAGEFILE1);
 }
 }
 }
 /* If an image couldn't be selected, choose the first one */
-return MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FILENAME, 
TMT_IMAGEFILE1);
+return MSSTYLES_FindProperty(pClass, iPartId, iStateId, TMT_FILENAME, 
TMT_IMAGEFILE1);
 }
 else if(imageselecttype == IST_SIZE) {
 POINT size = {pRect->right-pRect->left, pRect->bottom-pRect->top};
 POINT reqsize;
 for(i=4; i>=0; i--) {
 PTHEME_PROPERTY fileProp = 
-MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FILENAME, 
i + TMT_IMAGEFILE1);
+MSSTYLES_FindProperty(pClass, iPartId, iStateId, TMT_FILENAME, 
i + TMT_IMAGEFILE1);
 if (!fileProp) continue;
 if(FAILED(GetThemePosition(hTheme, iPartId, iStateId, i + 
TMT_MINSIZE1, ))) {
 /* fall back to size of Nth image */
@@ -192,7 +195,7 @@
 
 lstrcpynW(szPath, fileProp->lpValue, 
 min(fileProp->dwValueLen+1, 
sizeof(szPath)/sizeof(szPath[0])));
-hBmp = MSSTYLES_LoadBitmap(hTheme, szPath, );
+hBmp = MSSTYLES_LoadBitmap(pClass, szPath, );
 if(!hBmp) continue;
 
 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_IMAGELAYOUT, 
);
@@ -214,7 +217,7 @@
 }
 }
 /* If an image couldn't be selected, choose the smallest one */
-return MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FILENAME, 
TMT_IMAGEFILE1);
+return MSSTYLES_FindProperty(pClass, iPartId, iStateId, TMT_FILENAME, 
TMT_IMAGEFILE1);
 }
 return NULL;
 }
@@ -232,13 +235,20 @@
 int imagenum;
 BITMAP bmp;
 WCHAR szPath[MAX_PATH];
-PTHEME_PROPERTY tp = UXTHEME_SelectImage(hTheme, hdc, iPartId, iStateId, 
pRect, glyph);
+PTHEME_PROPERTY tp;
+PTHEME_CLASS pClass;
+
+pClass = ValidateHandle(hTheme);
+if (!pClass)
+return E_HANDLE;
+
+tp = UXTHEME_SelectImage(hTheme, hdc, iPartId, iStateId, pRect, glyph);
 if(!tp) {
 FIXME("Couldn't determine image for part/state %d/%d, invalid 
theme?\n", iPartId, iStateId);
 return E_PROP_ID_UNSUPPORTED;
 }
 lstrcpynW(szPath, tp->lpValue, min(tp->dwValueLen+1, 
sizeof(szPath)/sizeof(szPath[0])));
-*hBmp = MSSTYLES_LoadBitmap(hTheme, szPath, hasImageAlpha);
+*hBmp = MSSTYLES_LoadBitmap(pClass, szPath, hasImageAlpha);
 if(!*hBmp) {
 TRACE("Failed to load bitmap %s\n", debugstr_w(szPath));
 return HRESULT_FROM_WIN32(GetLastError());

Modified: trunk/reactos/dll/win32/uxtheme/metric.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/uxtheme/metric.c?rev=74593=74592=74593=diff
==
--- 

[ros-diffs] [gadamopoulos] 74592: [UXTHEME] Greatly reduce the number of times we open the theme data for the non client area. - Implement OTD_NONCLIENT for OpenThemeDataEx and OpenThemeDataFromFile.

2017-05-19 Thread gadamopoulos
Author: gadamopoulos
Date: Fri May 19 10:01:50 2017
New Revision: 74592

URL: http://svn.reactos.org/svn/reactos?rev=74592=rev
Log:
[UXTHEME] Greatly reduce the number of times we open the theme data for the non 
client area.
- Implement OTD_NONCLIENT for OpenThemeDataEx and OpenThemeDataFromFile.
- Open the WINDOW or the SCROLLBAR theme classes only when needed. Use 
OpenThemeDataEx instead of the internal MSSTYLES_OpenThemeClass. Cache the open 
theme in the WND_DATA for later use.

Modified:
trunk/reactos/dll/win32/uxtheme/nonclient.c
trunk/reactos/dll/win32/uxtheme/system.c
trunk/reactos/dll/win32/uxtheme/themehooks.c
trunk/reactos/dll/win32/uxtheme/uxthemep.h

Modified: trunk/reactos/dll/win32/uxtheme/nonclient.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/uxtheme/nonclient.c?rev=74592=74591=74592=diff
==
--- trunk/reactos/dll/win32/uxtheme/nonclient.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/uxtheme/nonclient.c [iso-8859-1] Fri May 19 
10:01:50 2017
@@ -173,8 +173,8 @@
 GetWindowInfo(hWnd, >wi);
 pcontext->hWnd = hWnd;
 pcontext->Active = IsWindowActive(hWnd, pcontext->wi.dwExStyle);
-pcontext->theme = MSSTYLES_OpenThemeClass(ActiveThemeFile, NULL, 
L"WINDOW");
-pcontext->scrolltheme = MSSTYLES_OpenThemeClass(ActiveThemeFile, NULL, 
L"SCROLLBAR");
+pcontext->theme = GetNCCaptionTheme(hWnd, pcontext->wi.dwStyle);
+pcontext->scrolltheme = GetNCScrollbarTheme(hWnd, pcontext->wi.dwStyle);
 
 pcontext->CaptionHeight = pcontext->wi.cyWindowBorders;
 pcontext->CaptionHeight += GetSystemMetrics(pcontext->wi.dwExStyle & 
WS_EX_TOOLWINDOW ? SM_CYSMCAPTION : SM_CYCAPTION );
@@ -192,9 +192,6 @@
 ThemeCleanupDrawContext(PDRAW_CONTEXT pcontext)
 {
 ReleaseDC(pcontext->hWnd ,pcontext->hDC);
-
-CloseThemeData (pcontext->theme);
-CloseThemeData (pcontext->scrolltheme);
 
 if(pcontext->hRgn != NULL)
 {
@@ -1115,7 +1112,10 @@
 /* Paint the window on the preview hDC */
 rcCurrent = context.wi.rcWindow;
 ThemePaintWindow(, , FALSE);
+
 context.hDC = NULL;
+CloseThemeData (context.theme);
+CloseThemeData (context.scrolltheme);
 ThemeCleanupDrawContext();
 
 /* Cleanup */

Modified: trunk/reactos/dll/win32/uxtheme/system.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/uxtheme/system.c?rev=74592=74591=74592=diff
==
--- trunk/reactos/dll/win32/uxtheme/system.c[iso-8859-1] (original)
+++ trunk/reactos/dll/win32/uxtheme/system.c[iso-8859-1] Fri May 19 
10:01:50 2017
@@ -724,9 +724,6 @@
 return NULL;
 }
 
-if(flags)
-FIXME("unhandled flags: %x\n", flags);
-
 if (ThemeFile)
 {
 pszAppName = UXTHEME_GetWindowProperty(hwnd, atSubAppName, szAppBuff, 
sizeof(szAppBuff)/sizeof(szAppBuff[0]));
@@ -745,7 +742,10 @@
 
 if(IsWindow(hwnd))
 {
-SetPropW(hwnd, (LPCWSTR)MAKEINTATOM(atWindowTheme), hTheme);
+if ((flags & OTD_NONCLIENT) == 0)
+{
+SetPropW(hwnd, (LPCWSTR)MAKEINTATOM(atWindowTheme), hTheme);
+}
 }
 else
 {

Modified: trunk/reactos/dll/win32/uxtheme/themehooks.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/uxtheme/themehooks.c?rev=74592=74591=74592=diff
==
--- trunk/reactos/dll/win32/uxtheme/themehooks.c[iso-8859-1] (original)
+++ trunk/reactos/dll/win32/uxtheme/themehooks.c[iso-8859-1] Fri May 19 
10:01:50 2017
@@ -63,18 +63,66 @@
 CloseThemeData(GetWindowTheme(hWnd));
 
 DeleteObject(pwndData->hTabBackgroundBrush);
-pwndData->hTabBackgroundBrush = NULL;
 }
 
 if (pwndData->hTabBackgroundBmp != NULL)
 {
 DeleteObject(pwndData->hTabBackgroundBmp);
-pwndData->hTabBackgroundBmp = NULL;
+}
+
+if (pwndData->hthemeWindow)
+{
+CloseThemeData(pwndData->hthemeWindow);
+}
+
+if (pwndData->hthemeScrollbar)
+{
+CloseThemeData(pwndData->hthemeScrollbar);
 }
 
 HeapFree(GetProcessHeap(), 0, pwndData);
 
 SetPropW( hWnd, (LPCWSTR)MAKEINTATOM(atWndContext), NULL);
+}
+
+HTHEME GetNCCaptionTheme(HWND hWnd, DWORD style)
+{
+PWND_DATA pwndData;
+
+/* We only get the theme for the window class if the window has a caption 
*/
+if((style & WS_CAPTION) != WS_CAPTION)
+return NULL;
+
+/* Get theme data for this window */
+pwndData = ThemeGetWndData(hWnd);
+if (pwndData == NULL)
+return NULL;
+
+/* If the theme data was not cached, open it now */
+if (!pwndData->hthemeWindow)
+pwndData->hthemeWindow = OpenThemeDataEx(hWnd, L"WINDOW", 
OTD_NONCLIENT);
+
+return pwndData->hthemeWindow;
+}
+
+HTHEME GetNCScrollbarTheme(HWND hWnd, DWORD style)
+{
+PWND_DATA pwndData;

[ros-diffs] [gedmurphy] 74591: Forgot to add the cmake changes

2017-05-19 Thread gedmurphy
Author: gedmurphy
Date: Fri May 19 09:46:41 2017
New Revision: 74591

URL: http://svn.reactos.org/svn/reactos?rev=74591=rev
Log:
Forgot to add the cmake changes

Modified:
trunk/reactos/drivers/filters/fltmgr/CMakeLists.txt

Modified: trunk/reactos/drivers/filters/fltmgr/CMakeLists.txt
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filters/fltmgr/CMakeLists.txt?rev=74591=74590=74591=diff
==
--- trunk/reactos/drivers/filters/fltmgr/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/drivers/filters/fltmgr/CMakeLists.txt [iso-8859-1] Fri May 19 
09:46:41 2017
@@ -1,10 +1,10 @@
-
 list(APPEND SOURCE
 Context.c
 Dispatch.c
 Filter.c
 Interface.c
 Lib.c
+Messaging.c
 Object.c
 ${CMAKE_CURRENT_BINARY_DIR}/fltmgr.def
 fltmgr.h)
@@ -22,5 +22,6 @@
 set_module_type(fltmgr kernelmodedriver)
 target_link_libraries(fltmgr ${PSEH_LIB})
 add_importlibs(fltmgr ntoskrnl hal)
+add_target_compile_definitions(fltmgr NTDDI_VERSION=NTDDI_WS03SP1)
 add_pch(fltmgr fltmgr.h SOURCE)
 add_cd_file(TARGET fltmgr DESTINATION reactos/system32/drivers NO_CAB FOR all)




[ros-diffs] [gedmurphy] 74590: [FLTMGR] - Add a rather messy header that I've been slowly building as I'm starting to understand the internals. - Mostly taken from the MS PDBs and info gained from OSR

2017-05-19 Thread gedmurphy
Author: gedmurphy
Date: Fri May 19 09:42:00 2017
New Revision: 74590

URL: http://svn.reactos.org/svn/reactos?rev=74590=rev
Log:
[FLTMGR]
- Add a rather messy header that I've been slowly building as I'm starting to 
understand the internals.
- Mostly taken from the MS PDBs and info gained from OSR and Alex Carp's blog. 
(https://fsfilters.blogspot.co.uk)

Added:
trunk/reactos/drivers/filters/fltmgr/fltmgrint.h   (with props)

Added: trunk/reactos/drivers/filters/fltmgr/fltmgrint.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filters/fltmgr/fltmgrint.h?rev=74590
==
--- trunk/reactos/drivers/filters/fltmgr/fltmgrint.h(added)
+++ trunk/reactos/drivers/filters/fltmgr/fltmgrint.h[iso-8859-1] Fri May 19 
09:42:00 2017
@@ -0,0 +1,284 @@
+#ifndef _FLTMGR_INTERNAL_H
+#define _FLTMGR_INTERNAL_H
+
+
+#define MAX_CONTEXT_TYPES   6
+
+
+typedef enum _FLT_OBJECT_FLAGS
+{
+FLT_OBFL_DRAINING = 1,
+FLT_OBFL_ZOMBIED = 2,
+FLT_OBFL_TYPE_INSTANCE = 0x100,
+FLT_OBFL_TYPE_FILTER = 0x200,
+FLT_OBFL_TYPE_VOLUME = 0x400
+
+} FLT_OBJECT_FLAGS, *PFLT_OBJECT_FLAGS;
+
+typedef enum _FLT_FILTER_FLAGS
+{
+FLTFL_MANDATORY_UNLOAD_IN_PROGRESS = 1,
+FLTFL_FILTERING_INITIATED = 2
+
+} FLT_FILTER_FLAGS, *PFLT_FILTER_FLAGS;
+
+typedef struct _FLT_OBJECT   // size = 0x14
+{
+volatile FLT_OBJECT_FLAGS Flags;
+ULONG PointerCount;
+EX_RUNDOWN_REF RundownRef;
+LIST_ENTRY PrimaryLink;
+
+} FLT_OBJECT, *PFLT_OBJECT;
+
+typedef struct _ALLOCATE_CONTEXT_HEADER
+{
+PFLT_FILTER Filter;
+PFLT_CONTEXT_CLEANUP_CALLBACK ContextCleanupCallback;
+struct _ALLOCATE_CONTEXT_HEADER *Next;
+FLT_CONTEXT_TYPE ContextType;
+char Flags;
+char AllocationType;
+
+} ALLOCATE_CONTEXT_HEADER, *PALLOCATE_CONTEXT_HEADER;
+
+typedef struct _FLT_RESOURCE_LIST_HEAD
+{
+ERESOURCE rLock;
+LIST_ENTRY rList;
+ULONG rCount;
+
+} FLT_RESOURCE_LIST_HEAD, *PFLT_RESOURCE_LIST_HEAD;
+
+typedef struct _FLT_MUTEX_LIST_HEAD
+{
+FAST_MUTEX mLock;
+LIST_ENTRY mList;
+ULONG mCount;
+
+} FLT_MUTEX_LIST_HEAD, *PFLT_MUTEX_LIST_HEAD;
+
+typedef struct _FLT_FILTER   // size = 0x120
+{
+FLT_OBJECT Base;
+PVOID Frame;  //FLTP_FRAME
+UNICODE_STRING Name;
+UNICODE_STRING DefaultAltitude;
+FLT_FILTER_FLAGS Flags;
+PDRIVER_OBJECT DriverObject;
+FLT_RESOURCE_LIST_HEAD InstanceList;
+PVOID VerifierExtension;
+PFLT_FILTER_UNLOAD_CALLBACK FilterUnload;
+PFLT_INSTANCE_SETUP_CALLBACK InstanceSetup;
+PFLT_INSTANCE_QUERY_TEARDOWN_CALLBACK InstanceQueryTeardown;
+PFLT_INSTANCE_TEARDOWN_CALLBACK InstanceTeardownStart;
+PFLT_INSTANCE_TEARDOWN_CALLBACK InstanceTeardownComplete;
+PALLOCATE_CONTEXT_HEADER SupportedContextsListHead;
+PALLOCATE_CONTEXT_HEADER SupportedContexts[MAX_CONTEXT_TYPES];
+PVOID PreVolumeMount;
+PVOID PostVolumeMount;
+PFLT_GENERATE_FILE_NAME GenerateFileName;
+PFLT_NORMALIZE_NAME_COMPONENT NormalizeNameComponent;
+PFLT_NORMALIZE_CONTEXT_CLEANUP NormalizeContextCleanup;
+PFLT_OPERATION_REGISTRATION Operations;
+PFLT_FILTER_UNLOAD_CALLBACK OldDriverUnload;
+FLT_MUTEX_LIST_HEAD ActiveOpens;
+FLT_MUTEX_LIST_HEAD ConnectionList;
+FLT_MUTEX_LIST_HEAD PortList;
+EX_PUSH_LOCK PortLock;
+
+}  FLT_FILTER, *PFLT_FILTER;
+
+typedef enum _FLT_yINSTANCE_FLAGS
+{
+INSFL_CAN_BE_DETACHED = 0x01,
+INSFL_DELETING = 0x02,
+INSFL_INITING = 0x04
+
+} FLT_INSTANCE_FLAGS, *PFLT_INSTANCE_FLAGS;
+
+typedef struct _FLT_TYPE
+{
+USHORT Signature;
+USHORT Size;
+
+} FLT_TYPE, *PFLT_TYPE;
+
+typedef struct _FLT_INSTANCE   // size = 0x144 (324)
+{
+FLT_OBJECT Base;
+ULONG OperationRundownRef;
+PVOID Volume; //PFLT_VOLUME
+PFLT_FILTER Filter;
+FLT_INSTANCE_FLAGS Flags;
+UNICODE_STRING Altitude;
+UNICODE_STRING Name;
+LIST_ENTRY FilterLink;
+ERESOURCE ContextLock;
+PVOID Context; //PCONTEXT_NODE
+PVOID TrackCompletionNodes; //PRACK_COMPLETION_NODES
+PVOID CallbackNodes[50]; //PCALLBACK_NODE
+
+} FLT_INSTANCE, *PFLT_INSTANCE;
+
+// http://fsfilters.blogspot.co.uk/2010/02/filter-manager-concepts-part-1.html
+typedef struct _FLTP_FRAME
+{
+FLT_TYPE Type;
+LIST_ENTRY Links;
+unsigned int FrameID;
+ERESOURCE AltitudeLock;
+UNICODE_STRING AltitudeIntervalLow;
+UNICODE_STRING AltitudeIntervalHigh;
+char LargeIrpCtrlStackSize;
+char SmallIrpCtrlStackSize;
+FLT_RESOURCE_LIST_HEAD RegisteredFilters;
+FLT_RESOURCE_LIST_HEAD AttachedVolumes;
+LIST_ENTRY MountingVolumes;
+FLT_MUTEX_LIST_HEAD AttachedFileSystems;
+FLT_MUTEX_LIST_HEAD ZombiedFltObjectContexts;
+ERESOURCE FilterUnloadLock;
+FAST_MUTEX DeviceObjectAttachLock;
+//FLT_PRCB *Prcb;
+void *PrcbPoolToFree;
+void *LookasidePoolToFree;
+//FLTP_IRPCTRL_STACK_PROFILER IrpCtrlStackProfiler;
+NPAGED_LOOKASIDE_LIST 

[ros-diffs] [gedmurphy] 74589: [FLTMGR] - Implement FltCreateCommunicationPort, FltCloseCommunicationPort, FltCloseClientPort, and stub FltSendMessage - Add two new object types for the server port an

2017-05-19 Thread gedmurphy
Author: gedmurphy
Date: Fri May 19 09:37:38 2017
New Revision: 74589

URL: http://svn.reactos.org/svn/reactos?rev=74589=rev
Log:
[FLTMGR]
- Implement FltCreateCommunicationPort, FltCloseCommunicationPort, 
FltCloseClientPort, and stub FltSendMessage
- Add two new object types for the server port and client ports
- Implement object type callbacks for closing and deleting these new ports
- Create the comms object and create the symbolic link (FltMgrMsg) to allow 
usermode to open a handle to the comms layer (aka 
FilterConnectCommunicationPort)
- Although untested, the comms layer objects should be mostly setup, and we 
should be able to open a connection from usermode.

Added:
trunk/reactos/drivers/filters/fltmgr/Messaging.c   (with props)
Modified:
trunk/reactos/drivers/filters/fltmgr/fltmgr.h
trunk/reactos/drivers/filters/fltmgr/fltmgr.spec

Added: trunk/reactos/drivers/filters/fltmgr/Messaging.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filters/fltmgr/Messaging.c?rev=74589
==
--- trunk/reactos/drivers/filters/fltmgr/Messaging.c(added)
+++ trunk/reactos/drivers/filters/fltmgr/Messaging.c[iso-8859-1] Fri May 19 
09:37:38 2017
@@ -0,0 +1,373 @@
+/*
+* PROJECT: Filesystem Filter Manager
+* LICENSE: GPL - See COPYING in the top level directory
+* FILE:drivers/filters/fltmgr/Messaging.c
+* PURPOSE: Contains the routines to handle the comms layer
+* PROGRAMMERS: Ged Murphy (gedmur...@reactos.org)
+*/
+
+/* INCLUDES **/
+
+#include "fltmgr.h"
+#include "fltmgrint.h"
+
+#define NDEBUG
+#include 
+
+
+/* DATA */
+
+UNICODE_STRING CommsDeviceName = 
RTL_CONSTANT_STRING(L"\\FileSystem\\Filters\\FltMgrMsg");
+PDEVICE_OBJECT CommsDeviceObject;
+
+POBJECT_TYPE ServerPortObjectType;
+POBJECT_TYPE ClientPortObjectType;
+
+static
+BOOLEAN
+FltpDisconnectPort(
+_In_ PFLT_PORT_OBJECT PortObject
+);
+
+
+
+/* EXPORTED FUNCTIONS **/
+
+_Must_inspect_result_
+_IRQL_requires_max_(PASSIVE_LEVEL)
+NTSTATUS
+FLTAPI
+FltCreateCommunicationPort(_In_ PFLT_FILTER Filter,
+   _Outptr_ PFLT_PORT *ServerPort,
+   _In_ POBJECT_ATTRIBUTES ObjectAttributes,
+   _In_opt_ PVOID ServerPortCookie,
+   _In_ PFLT_CONNECT_NOTIFY ConnectNotifyCallback,
+   _In_ PFLT_DISCONNECT_NOTIFY 
DisconnectNotifyCallback,
+   _In_opt_ PFLT_MESSAGE_NOTIFY MessageNotifyCallback,
+   _In_ LONG MaxConnections)
+{
+PFLT_SERVER_PORT_OBJECT PortObject;
+NTSTATUS Status;
+
+/* The caller must allow at least one connection */
+if (MaxConnections == 0)
+{
+return STATUS_INVALID_PARAMETER;
+}
+
+/* The request must be for a kernel handle */
+if (!(ObjectAttributes->Attributes & OBJ_KERNEL_HANDLE))
+{
+return STATUS_INVALID_PARAMETER;
+}
+
+/*
+ * Get rundown protection on the target to stop the owner
+ * from unloading whilst this port object is open. It gets
+ * removed in the FltpServerPortClose callback
+ */
+Status = FltObjectReference(Filter);
+if (!NT_SUCCESS(Status))
+{
+return Status;
+}
+
+/* Create our new server port object */
+Status = ObCreateObject(0,
+ServerPortObjectType,
+ObjectAttributes,
+KernelMode,
+NULL,
+sizeof(FLT_SERVER_PORT_OBJECT),
+0,
+0,
+(PVOID *));
+if (NT_SUCCESS(Status))
+{
+/* Zero out the struct */
+RtlZeroMemory(PortObject, sizeof(FLT_SERVER_PORT_OBJECT));
+
+/* Increment the ref count on the target filter */
+FltpObjectPointerReference((PFLT_OBJECT)Filter);
+
+/* Setup the filter port object */
+PortObject->Filter = Filter;
+PortObject->ConnectNotify = ConnectNotifyCallback;
+PortObject->DisconnectNotify = DisconnectNotifyCallback;
+PortObject->MessageNotify = MessageNotifyCallback;
+PortObject->Cookie = ServerPortCookie;
+PortObject->MaxConnections = MaxConnections;
+
+/* Insert the object */
+Status = ObInsertObject(PortObject,
+NULL,
+STANDARD_RIGHTS_ALL | FILE_READ_DATA,
+0,
+NULL,
+(PHANDLE)ServerPort);
+if (NT_SUCCESS(Status))
+{
+/* Lock the connection list */
+

[ros-diffs] [gedmurphy] 74588: [FLTMGR} - Implement FltAcquirePushLockExclusive, FltAcquirePushLockShared and FltReleasePushLock. Lifted from ntos' internal pushlock routines. - Implement FltpObjectPo

2017-05-19 Thread gedmurphy
Author: gedmurphy
Date: Fri May 19 09:15:35 2017
New Revision: 74588

URL: http://svn.reactos.org/svn/reactos?rev=74588=rev
Log:
[FLTMGR}
- Implement FltAcquirePushLockExclusive, FltAcquirePushLockShared and 
FltReleasePushLock. Lifted from ntos' internal pushlock routines.
- Implement FltpObjectPointerReference and partially implement 
FltpObjectPointerDerference

Modified:
trunk/reactos/drivers/filters/fltmgr/Object.c

Modified: trunk/reactos/drivers/filters/fltmgr/Object.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filters/fltmgr/Object.c?rev=74588=74587=74588=diff
==
--- trunk/reactos/drivers/filters/fltmgr/Object.c   [iso-8859-1] (original)
+++ trunk/reactos/drivers/filters/fltmgr/Object.c   [iso-8859-1] Fri May 19 
09:15:35 2017
@@ -20,7 +20,18 @@
 
 /* DATA */
 
-
+#define ExpChangePushlock(x, y, z) 
InterlockedCompareExchangePointer((PVOID*)x, (PVOID)y, (PVOID)z)
+
+//
+// Pushlock bits
+//
+#define EX_PUSH_LOCK_LOCK_V ((ULONG_PTR)0x0)
+#define EX_PUSH_LOCK_LOCK   ((ULONG_PTR)0x1)
+#define EX_PUSH_LOCK_WAITING((ULONG_PTR)0x2)
+#define EX_PUSH_LOCK_WAKING ((ULONG_PTR)0x4)
+#define EX_PUSH_LOCK_MULTIPLE_SHARED((ULONG_PTR)0x8)
+#define EX_PUSH_LOCK_SHARE_INC  ((ULONG_PTR)0x10)
+#define EX_PUSH_LOCK_PTR_BITS   ((ULONG_PTR)0xf)
 
 /* EXPORTED FUNCTIONS **/
 
@@ -42,6 +53,85 @@
 FltObjectDereference(_Inout_ PVOID Object)
 {
 FltpExReleaseRundownProtection(&((PFLT_OBJECT)Object)->RundownRef);
+}
+
+
+_Acquires_lock_(_Global_critical_region_)
+_IRQL_requires_max_(APC_LEVEL)
+VOID
+FLTAPI
+FltAcquirePushLockExclusive(_Inout_ _Requires_lock_not_held_(*_Curr_) 
_Acquires_lock_(*_Curr_) PEX_PUSH_LOCK PushLock)
+{
+KeEnterCriticalRegion();
+
+/* Try acquiring the lock */
+if (InterlockedBitTestAndSet((PLONG)PushLock, EX_PUSH_LOCK_LOCK_V))
+{
+/* Someone changed it, use the slow path */
+ExfAcquirePushLockExclusive(PushLock);
+}
+
+/* Sanity check */
+FLT_ASSERT(PushLock->Locked);
+}
+
+
+_Acquires_lock_(_Global_critical_region_)
+_IRQL_requires_max_(APC_LEVEL)
+VOID
+FLTAPI
+FltAcquirePushLockShared(_Inout_ _Requires_lock_not_held_(*_Curr_) 
_Acquires_lock_(*_Curr_) PEX_PUSH_LOCK PushLock)
+{
+EX_PUSH_LOCK NewValue;
+
+KeEnterCriticalRegion();
+
+/* Try acquiring the lock */
+NewValue.Value = EX_PUSH_LOCK_LOCK | EX_PUSH_LOCK_SHARE_INC;
+if (ExpChangePushlock(PushLock, NewValue.Ptr, 0))
+{
+/* Someone changed it, use the slow path */
+ExfAcquirePushLockShared(PushLock);
+}
+
+/* Sanity checks */
+ASSERT(PushLock->Locked);
+}
+
+_Releases_lock_(_Global_critical_region_)
+_IRQL_requires_max_(APC_LEVEL)
+VOID
+FLTAPI
+FltReleasePushLock(_Inout_ _Requires_lock_held_(*_Curr_) 
_Releases_lock_(*_Curr_) PEX_PUSH_LOCK PushLock)
+{
+EX_PUSH_LOCK OldValue = *PushLock;
+EX_PUSH_LOCK NewValue;
+
+/* Sanity checks */
+FLT_ASSERT(OldValue.Locked);
+
+/* Check if the pushlock is shared */
+if (OldValue.Shared > 1)
+{
+/* Decrease the share count */
+NewValue.Value = OldValue.Value - EX_PUSH_LOCK_SHARE_INC;
+}
+else
+{
+/* Clear the pushlock entirely */
+NewValue.Value = 0;
+}
+
+/* Check if nobody is waiting on us and try clearing the lock here */
+if ((OldValue.Waiting) ||
+(ExpChangePushlock(PushLock, NewValue.Ptr, OldValue.Ptr) !=
+ OldValue.Ptr))
+{
+/* We have waiters, use the long path */
+ExfReleasePushLock(PushLock);
+}
+
+KeLeaveCriticalRegion();
 }
 
 
@@ -157,3 +247,26 @@
 
 return Status;
 }
+
+ULONG
+FltpObjectPointerReference(_In_ PFLT_OBJECT Object)
+{
+PULONG Result;
+
+/* Store the old count and increment */
+Result = >PointerCount;
+InterlockedIncrement((PLONG)>PointerCount);
+
+/* Return the initial value */
+return *Result;
+}
+
+VOID
+FltpObjectPointerDereference(_In_ PFLT_OBJECT Object)
+{
+if (!InterlockedDecrement((PLONG)Object->PointerCount))
+{
+// Cleanup
+FLT_ASSERT(FALSE);
+}
+}




[ros-diffs] [gadamopoulos] 74587: [UXTHEME] -Rename WND_CONTEXT to WND_DATA to avoid confusion with the DRAW_CONTEXT. The WND_DATA is information valid throughout the life of a window and DRAW_CONTEXT

2017-05-19 Thread gadamopoulos
Author: gadamopoulos
Date: Fri May 19 08:45:49 2017
New Revision: 74587

URL: http://svn.reactos.org/svn/reactos?rev=74587=rev
Log:
[UXTHEME] -Rename WND_CONTEXT to WND_DATA to avoid confusion with the 
DRAW_CONTEXT. The WND_DATA is information valid throughout the life of a window 
and DRAW_CONTEXT is information throughout a draw operation in the non client 
area of the window.

Modified:
trunk/reactos/dll/win32/uxtheme/ncscrollbar.c
trunk/reactos/dll/win32/uxtheme/nonclient.c
trunk/reactos/dll/win32/uxtheme/themehooks.c
trunk/reactos/dll/win32/uxtheme/uxthemep.h

Modified: trunk/reactos/dll/win32/uxtheme/ncscrollbar.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/uxtheme/ncscrollbar.c?rev=74587=74586=74587=diff
==
--- trunk/reactos/dll/win32/uxtheme/ncscrollbar.c   [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/uxtheme/ncscrollbar.c   [iso-8859-1] Fri May 19 
08:45:49 2017
@@ -239,9 +239,9 @@
 }
 }
 
-static void SCROLL_DrawMovingThumb(PWND_CONTEXT pwndContext, PDRAW_CONTEXT 
pcontext, SCROLLBARINFO* psbi,  BOOL vertical)
-{
-  INT pos = pwndContext->SCROLL_TrackingPos;
+static void SCROLL_DrawMovingThumb(PWND_DATA pwndData, PDRAW_CONTEXT pcontext, 
SCROLLBARINFO* psbi,  BOOL vertical)
+{
+  INT pos = pwndData->SCROLL_TrackingPos;
   INT max_size;
 
   if( vertical )
@@ -258,7 +258,7 @@
 
   SCROLL_DrawInterior(pcontext, psbi, pos, vertical, SCROLL_THUMB, 0);  
 
-  pwndContext->SCROLL_MovingThumb = !pwndContext->SCROLL_MovingThumb;
+  pwndData->SCROLL_MovingThumb = !pwndData->SCROLL_MovingThumb;
 }
 
 
@@ -269,15 +269,15 @@
 SCROLLBARINFO sbi;
 BOOL vertical;
 enum SCROLL_HITTEST htHot = SCROLL_NOWHERE;
-PWND_CONTEXT pwndContext;
+PWND_DATA pwndData;
 
 if (((nBar == SB_VERT) && !(pcontext->wi.dwStyle & WS_VSCROLL)) ||
 ((nBar == SB_HORZ) && !(pcontext->wi.dwStyle & WS_HSCROLL))) return;
 
-if (!(pwndContext = ThemeGetWndContext(pcontext->hWnd)))
+if (!(pwndData = ThemeGetWndData(pcontext->hWnd)))
 return;
 
-if (pwndContext->SCROLL_TrackingWin)
+if (pwndData->SCROLL_TrackingWin)
 return;
 
 /* Retrieve scrollbar info */
@@ -371,7 +371,7 @@
 }
 
 static void 
-SCROLL_HandleScrollEvent(PWND_CONTEXT pwndContext, HWND hwnd, INT nBar, UINT 
msg, POINT pt)
+SCROLL_HandleScrollEvent(PWND_DATA pwndData, HWND hwnd, INT nBar, UINT msg, 
POINT pt)
 {
   /* Previous mouse position for timer events */
 static POINT prevPt;
@@ -401,7 +401,7 @@
 return;
 }
 
-if ((pwndContext->SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != 
WM_LBUTTONDOWN))
+if ((pwndData->SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != 
WM_LBUTTONDOWN))
  return;
 
 ThemeInitDrawContext(, hwnd, 0);
@@ -416,8 +416,8 @@
 {
   case WM_LBUTTONDOWN:  /* Initialise mouse tracking */
   HideCaret(hwnd);  /* hide caret while holding down LBUTTON */
-  pwndContext->SCROLL_trackVertical = vertical;
-  pwndContext->SCROLL_trackHitTest  = hittest = SCROLL_HitTest( hwnd, 
, vertical, pt, FALSE );
+  pwndData->SCROLL_trackVertical = vertical;
+  pwndData->SCROLL_trackHitTest  = hittest = SCROLL_HitTest( hwnd, 
, vertical, pt, FALSE );
   lastClickPos  = vertical ? (pt.y - sbi.rcScrollBar.top) : (pt.x - 
sbi.rcScrollBar.left);
   lastMousePos  = lastClickPos;
   trackThumbPos = sbi.xyThumbTop;
@@ -450,15 +450,15 @@
 //TRACE("Event: hwnd=%p bar=%d msg=%s pt=%d,%d hit=%d\n",
 //  hwnd, nBar, SPY_GetMsgName(msg,hwnd), pt.x, pt.y, hittest );
 
-switch(pwndContext->SCROLL_trackHitTest)
+switch(pwndData->SCROLL_trackHitTest)
 {
 case SCROLL_NOWHERE:  /* No tracking in progress */
 break;
 
 case SCROLL_TOP_ARROW:
-if (hittest == pwndContext->SCROLL_trackHitTest)
-{
-SCROLL_DrawArrows( , , vertical, 
pwndContext->SCROLL_trackHitTest, 0 );
+if (hittest == pwndData->SCROLL_trackHitTest)
+{
+SCROLL_DrawArrows( , , vertical, 
pwndData->SCROLL_trackHitTest, 0 );
 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
 {
 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
@@ -477,8 +477,8 @@
 break;
 
 case SCROLL_TOP_RECT:
-SCROLL_DrawInterior( , , sbi.xyThumbTop, vertical, 
pwndContext->SCROLL_trackHitTest, 0);
-if (hittest == pwndContext->SCROLL_trackHitTest)
+SCROLL_DrawInterior( , , sbi.xyThumbTop, vertical, 
pwndData->SCROLL_trackHitTest, 0);
+if (hittest == pwndData->SCROLL_trackHitTest)
 {
 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
 {
@@ -494,20 +494,20 @@
 case SCROLL_THUMB:
 if (msg == WM_LBUTTONDOWN)
 {
-pwndContext->SCROLL_TrackingWin = hwnd;
-pwndContext->SCROLL_TrackingBar 

[ros-diffs] [gedmurphy] 74586: [FLTMGR] - Add the missing IOCTLs that were added to fltlib

2017-05-19 Thread gedmurphy
Author: gedmurphy
Date: Fri May 19 08:21:41 2017
New Revision: 74586

URL: http://svn.reactos.org/svn/reactos?rev=74586=rev
Log:
[FLTMGR]
- Add the missing IOCTLs that were added to fltlib

Modified:
trunk/reactos/drivers/filters/fltmgr/Dispatch.c

Modified: trunk/reactos/drivers/filters/fltmgr/Dispatch.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filters/fltmgr/Dispatch.c?rev=74586=74585=74586=diff
==
--- trunk/reactos/drivers/filters/fltmgr/Dispatch.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/filters/fltmgr/Dispatch.c [iso-8859-1] Fri May 19 
08:21:41 2017
@@ -47,16 +47,48 @@
 ControlCode = StackPtr->Parameters.DeviceIoControl.IoControlCode;
 switch (ControlCode)
 {
-case IOCTL_LOAD_FILTER:
+case IOCTL_FILTER_LOAD:
 Status = HandleLoadUnloadIoctl(DeviceObject, Irp);
 break;
 
-case IOCTL_UNLOAD_FILTER:
+case IOCTL_FILTER_UNLOAD:
 Status = HandleLoadUnloadIoctl(DeviceObject, Irp);
 break;
 
-case IOCTL_FIND_FIRST_FILTER:
-Status = HandleFindFirstIoctl(DeviceObject, Irp);
+case IOCTL_FILTER_CREATE:
+Status = STATUS_NOT_SUPPORTED;
+break;
+
+case IOCTL_FILTER_ATTATCH:
+Status = STATUS_NOT_SUPPORTED;
+break;
+
+case IOCTL_FILTER_DETATCH:
+Status = STATUS_NOT_SUPPORTED;
+break;
+
+case IOCTL_FILTER_SEND_MESSAGE:
+Status = STATUS_NOT_SUPPORTED;
+break;
+
+case IOCTL_FILTER_GET_MESSAGE:
+Status = STATUS_NOT_SUPPORTED;
+break;
+
+case IOCTL_FILTER_REPLY_MESSAGE:
+Status = STATUS_NOT_SUPPORTED;
+break;
+
+case IOCTL_FILTER_FIND_FIRST:
+Status = STATUS_NOT_SUPPORTED;
+break;
+
+case IOCTL_FILTER_FIND_NEXT:
+Status = STATUS_NOT_SUPPORTED;
+break;
+
+case IOCTL_FILTER_GET_INFO:
+Status = STATUS_NOT_SUPPORTED;
 break;
 
 default:
@@ -92,13 +124,14 @@
 PFILTER_NAME FilterName;
 ULONG BufferLength;
 ULONG ControlCode;
+NTSTATUS Status;
 
 /* Get the IOCTL data from the stack pointer */
 StackPtr = IoGetCurrentIrpStackLocation(Irp);
 BufferLength = StackPtr->Parameters.DeviceIoControl.InputBufferLength;
 ControlCode = StackPtr->Parameters.DeviceIoControl.IoControlCode;
 
-FLT_ASSERT(ControlCode == IOCTL_LOAD_FILTER || ControlCode == 
IOCTL_UNLOAD_FILTER);
+FLT_ASSERT(ControlCode == IOCTL_FILTER_LOAD || ControlCode == 
IOCTL_FILTER_UNLOAD);
 
 /* Make sure the buffer is valid */
 if (BufferLength < sizeof(FILTER_NAME))
@@ -111,19 +144,14 @@
 Name.Buffer = (PWCH)((PCHAR)FilterName + FIELD_OFFSET(FILTER_NAME, 
FilterName[0]));
 
 /* Forward the request to our Flt routines */
-if (ControlCode == IOCTL_LOAD_FILTER)
+if (ControlCode == IOCTL_FILTER_LOAD)
 {
-return FltLoadFilter();
+Status = FltLoadFilter();
 }
 else
 {
-return FltUnloadFilter();
+Status = FltUnloadFilter();
 }
+
+return Status;
 }
-
-NTSTATUS
-HandleFindFirstIoctl(_In_ PDEVICE_OBJECT DeviceObject,
- _Inout_ PIRP Irp)
-{
-return STATUS_NOT_SUPPORTED;
-}