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
February 2011
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
18 participants
352 discussions
Start a n
N
ew thread
[fireball] 50930: [SERVICES] - Protect whole contents of ScmStartService() with a critical section instead of just a few parts of ScmStartUserModeService(). Seems to fix the comment #8 issue of bug...
by fireball@svn.reactos.org
Author: fireball Date: Sun Feb 27 23:07:04 2011 New Revision: 50930 URL:
http://svn.reactos.org/svn/reactos?rev=50930&view=rev
Log: [SERVICES] - Protect whole contents of ScmStartService() with a critical section instead of just a few parts of ScmStartUserModeService(). Seems to fix the comment #8 issue of bug #5924. Modified: trunk/reactos/base/system/services/database.c Modified: trunk/reactos/base/system/services/database.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/datab…
============================================================================== --- trunk/reactos/base/system/services/database.c [iso-8859-1] (original) +++ trunk/reactos/base/system/services/database.c [iso-8859-1] Sun Feb 27 23:07:04 2011 @@ -922,8 +922,6 @@ return Status; } - EnterCriticalSection(&StartServiceCriticalSection); - /* Create '\\.\pipe\net\NtControlPipeXXX' instance */ swprintf(NtControlPipeName, L"\\\\.\\pipe\\net\\NtControlPipe%u", ServiceCurrent); Service->ControlPipeHandle = CreateNamedPipeW(NtControlPipeName, @@ -938,7 +936,6 @@ if (Service->ControlPipeHandle == INVALID_HANDLE_VALUE) { DPRINT1("Failed to create control pipe!\n"); - LeaveCriticalSection(&StartServiceCriticalSection); return GetLastError(); } @@ -970,7 +967,6 @@ Service->ControlPipeHandle = INVALID_HANDLE_VALUE; DPRINT1("Starting '%S' failed!\n", Service->lpServiceName); - LeaveCriticalSection(&StartServiceCriticalSection); return dwError; } @@ -1030,8 +1026,6 @@ CloseHandle(ProcessInformation.hThread); CloseHandle(ProcessInformation.hProcess); - LeaveCriticalSection(&StartServiceCriticalSection); - return dwError; } @@ -1041,6 +1035,8 @@ { PSERVICE_GROUP Group = Service->lpGroup; DWORD dwError = ERROR_SUCCESS; + + EnterCriticalSection(&StartServiceCriticalSection); DPRINT("ScmStartService() called\n"); @@ -1072,6 +1068,7 @@ } DPRINT("ScmStartService() done (Error %lu)\n", dwError); + LeaveCriticalSection(&StartServiceCriticalSection); if (dwError == ERROR_SUCCESS) {
13 years, 9 months
1
0
0
0
[tkreuzer] 50929: [GDI32_APITEST] More testcases for SelectObject and GetDIBits
by tkreuzer@svn.reactos.org
Author: tkreuzer Date: Sun Feb 27 22:00:13 2011 New Revision: 50929 URL:
http://svn.reactos.org/svn/reactos?rev=50929&view=rev
Log: [GDI32_APITEST] More testcases for SelectObject and GetDIBits Modified: trunk/rostests/apitests/gdi32/GetDIBits.c trunk/rostests/apitests/gdi32/SelectObject.c Modified: trunk/rostests/apitests/gdi32/GetDIBits.c URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/gdi32/GetDIBits.…
============================================================================== --- trunk/rostests/apitests/gdi32/GetDIBits.c [iso-8859-1] (original) +++ trunk/rostests/apitests/gdi32/GetDIBits.c [iso-8859-1] Sun Feb 27 22:00:13 2011 @@ -9,93 +9,161 @@ #include <wine/test.h> #include <windows.h> -#define TEST(x) ok(x, #x"\n") -#define RTEST(x) ok(x, #x"\n") +#define ok_err(dwErr) ok(GetLastError() == dwErr, "LastError is wrong, expected %d, got %ld\n", dwErr, GetLastError()) void Test_GetDIBits() { - HDC hDCScreen; - HBITMAP hBitmap; - BITMAPINFO bi; - INT ScreenBpp; + HDC hdcScreen, hdcMem; + HBITMAP hbmp; + PBITMAPINFO pbi; + INT ret, ScreenBpp; + DWORD ajBits[10] = {0xff, 0x00, 0xcc, 0xf0, 0x0f}; - hDCScreen = GetDC(NULL); - ok(hDCScreen != 0, "GetDC failed, skipping tests\n"); - if (hDCScreen == NULL) return; + pbi = malloc(sizeof(BITMAPV5HEADER) + 256 * sizeof(DWORD)); - hBitmap = CreateCompatibleBitmap(hDCScreen, 16, 16); - RTEST(hBitmap != NULL); + hdcScreen = GetDC(NULL); + ok(hdcScreen != 0, "GetDC failed, skipping tests\n"); + if (hdcScreen == NULL) return; + + hdcMem = CreateCompatibleDC(0); + ok(hdcMem != 0, "CreateCompatibleDC failed, skipping tests\n"); + if (hdcMem == NULL) return; + + hbmp = CreateCompatibleBitmap(hdcScreen, 16, 16); + ok(hbmp != NULL, "CreateCompatibleBitmap failed\n"); /* misc */ SetLastError(ERROR_SUCCESS); - RTEST(GetDIBits(0, 0, 0, 0, NULL, NULL, 0) == 0); - RTEST(GetLastError() == ERROR_INVALID_PARAMETER); + ok(GetDIBits(0, 0, 0, 0, NULL, NULL, 0) == 0, "\n"); + ok_err(ERROR_INVALID_PARAMETER); SetLastError(ERROR_SUCCESS); - RTEST(GetDIBits((HDC)2345, 0, 0, 0, NULL, NULL, 0) == 0); - RTEST(GetLastError() == ERROR_INVALID_PARAMETER); + ok(GetDIBits((HDC)2345, 0, 0, 0, NULL, NULL, 0) == 0, "\n"); + ok_err(ERROR_INVALID_PARAMETER); SetLastError(ERROR_SUCCESS); - RTEST(GetDIBits((HDC)2345, hBitmap, 0, 0, NULL, NULL, 0) == 0); - RTEST(GetLastError() == ERROR_INVALID_PARAMETER); + ok(GetDIBits((HDC)2345, hbmp, 0, 0, NULL, NULL, 0) == 0, "\n"); + ok_err(ERROR_INVALID_PARAMETER); SetLastError(ERROR_SUCCESS); - RTEST(GetDIBits((HDC)2345, hBitmap, 0, 15, NULL, &bi, 0) == 0); - RTEST(GetLastError() == ERROR_INVALID_PARAMETER); + ok(GetDIBits((HDC)2345, hbmp, 0, 15, NULL, pbi, 0) == 0, "\n"); + ok_err(ERROR_INVALID_PARAMETER); /* null hdc */ SetLastError(ERROR_SUCCESS); - ZeroMemory(&bi, sizeof(BITMAPINFO)); - bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - RTEST(GetDIBits(NULL, hBitmap, 0, 15, NULL, &bi, DIB_RGB_COLORS) == 0); - RTEST(GetLastError() == ERROR_INVALID_PARAMETER); + ZeroMemory(pbi, sizeof(BITMAPINFO)); + pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + ok(GetDIBits(NULL, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) == 0, "\n"); + ok_err(ERROR_INVALID_PARAMETER); /* null bitmap */ SetLastError(ERROR_SUCCESS); - ZeroMemory(&bi, sizeof(BITMAPINFO)); - bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - RTEST(GetDIBits(hDCScreen, NULL, 0, 15, NULL, &bi, DIB_RGB_COLORS) == 0); - RTEST(GetLastError() == ERROR_SUCCESS); + ZeroMemory(pbi, sizeof(BITMAPINFO)); + pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + ok(GetDIBits(hdcScreen, NULL, 0, 15, NULL, pbi, DIB_RGB_COLORS) == 0, "\n"); + ok_err(ERROR_SUCCESS); /* 0 scan lines */ SetLastError(ERROR_SUCCESS); - ZeroMemory(&bi, sizeof(BITMAPINFO)); - bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - RTEST(GetDIBits(hDCScreen, hBitmap, 0, 0, NULL, &bi, DIB_RGB_COLORS) > 0); - RTEST(GetLastError() == ERROR_SUCCESS); + ZeroMemory(pbi, sizeof(BITMAPINFO)); + pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + ok(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS) > 0, "\n"); + ok_err(ERROR_SUCCESS); /* null bitmap info - crashes XP*/ //SetLastError(ERROR_SUCCESS); - //RTEST(GetDIBits(hDCScreen, NULL, 0, 15, NULL, NULL, DIB_RGB_COLORS) == 0); - //RTEST(GetLastError() == ERROR_INVALID_PARAMETER); + //ok(GetDIBits(hdcScreen, NULL, 0, 15, NULL, NULL, DIB_RGB_COLORS) == 0); + //ok(GetLastError() == ERROR_INVALID_PARAMETER); /* bad bmi colours (uUsage) */ SetLastError(ERROR_SUCCESS); - ZeroMemory(&bi, sizeof(BITMAPINFO)); - bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - RTEST(GetDIBits(hDCScreen, hBitmap, 0, 15, NULL, &bi, 100) == 0); - RTEST(GetLastError() == ERROR_SUCCESS); - RTEST(bi.bmiHeader.biWidth == 0); - RTEST(bi.bmiHeader.biHeight == 0); - RTEST(bi.bmiHeader.biBitCount == 0); - RTEST(bi.bmiHeader.biSizeImage == 0); + ZeroMemory(pbi, sizeof(BITMAPINFO)); + pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, 100) == 0, "\n"); + ok_err(ERROR_SUCCESS); + ok(pbi->bmiHeader.biWidth == 0, "\n"); + ok(pbi->bmiHeader.biHeight == 0, "\n"); + ok(pbi->bmiHeader.biBitCount == 0, "\n"); + ok(pbi->bmiHeader.biSizeImage == 0, "\n"); /* basic call */ SetLastError(ERROR_SUCCESS); - ZeroMemory(&bi, sizeof(BITMAPINFO)); - bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - RTEST(GetDIBits(hDCScreen, hBitmap, 0, 15, NULL, &bi, DIB_RGB_COLORS) > 0); - RTEST(GetLastError() == ERROR_SUCCESS); - ScreenBpp = GetDeviceCaps(hDCScreen, BITSPIXEL); - RTEST(bi.bmiHeader.biWidth == 16); - RTEST(bi.bmiHeader.biHeight == 16); - RTEST(bi.bmiHeader.biBitCount == ScreenBpp); - RTEST(bi.bmiHeader.biSizeImage == (16 * 16) * (ScreenBpp / 8)); + ZeroMemory(pbi, sizeof(BITMAPINFO)); + pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) > 0, "\n"); + ok_err(ERROR_SUCCESS); + ScreenBpp = GetDeviceCaps(hdcScreen, BITSPIXEL); + ok(pbi->bmiHeader.biWidth == 16, "\n"); + ok(pbi->bmiHeader.biHeight == 16, "\n"); + ok(pbi->bmiHeader.biBitCount == ScreenBpp, "\n"); + ok(pbi->bmiHeader.biSizeImage == (16 * 16) * (ScreenBpp / 8), "\n"); - DeleteObject(hBitmap); - ReleaseDC(NULL, hDCScreen); + /* Test if COREHEADER is supported */ + pbi->bmiHeader.biSize = sizeof(BITMAPCOREHEADER); + ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) > 0, "\n"); + ok(pbi->bmiHeader.biSize == sizeof(BITMAPCOREHEADER), "\n"); + + /* Test different header sizes */ + pbi->bmiHeader.biSize = sizeof(BITMAPCOREHEADER) + 4; + ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) == 0, "should fail.\n"); + pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER) + 4; + ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) == 0, "should fail.\n"); + pbi->bmiHeader.biSize = sizeof(BITMAPV5HEADER); + ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) > 0, "should not fail.\n"); + pbi->bmiHeader.biSize = sizeof(BITMAPV5HEADER) + 4; + ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) > 0, "should not fail.\n"); + + + DeleteObject(hbmp); + + /* Test a mono bitmap */ + hbmp = CreateBitmap(13, 7, 1, 1, ajBits); + ok(hbmp != 0, "failed to create bitmap\n"); + ZeroMemory(pbi, sizeof(BITMAPINFO)); + pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + ret = GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS); + ok(ret == 1, "%d\n", ret); + ok(pbi->bmiHeader.biWidth == 13, "pbi->bmiHeader.biWidth = %ld\n", pbi->bmiHeader.biWidth); + ok(pbi->bmiHeader.biHeight == 7, "pbi->bmiHeader.biHeight = %ld\n", pbi->bmiHeader.biHeight); + ok(pbi->bmiHeader.biBitCount == 1, "pbi->bmiHeader.biBitCount = %d\n", pbi->bmiHeader.biBitCount); + ok(pbi->bmiHeader.biSizeImage == 28, "pbi->bmiHeader.biSizeImage = %ld\n", pbi->bmiHeader.biSizeImage); + + /* Test a mono bitmap with values set */ + ZeroMemory(pbi, sizeof(BITMAPINFO)); + pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + pbi->bmiHeader.biWidth = 12; + pbi->bmiHeader.biHeight = 9; + pbi->bmiHeader.biPlanes = 1; + pbi->bmiHeader.biBitCount = 32; + pbi->bmiHeader.biCompression = BI_RGB; + pbi->bmiHeader.biSizeImage = 123; + ret = GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS); + ok(ret == 1, "%d\n", ret); + ok(pbi->bmiHeader.biWidth == 12, "pbi->bmiHeader.biWidth = %ld\n", pbi->bmiHeader.biWidth); + ok(pbi->bmiHeader.biHeight == 9, "pbi->bmiHeader.biHeight = %ld\n", pbi->bmiHeader.biHeight); + ok(pbi->bmiHeader.biBitCount == 32, "pbi->bmiHeader.biBitCount = %d\n", pbi->bmiHeader.biBitCount); + ok(pbi->bmiHeader.biSizeImage == 432, "pbi->bmiHeader.biSizeImage = %ld\n", pbi->bmiHeader.biSizeImage); + + /* Set individual values */ + ZeroMemory(pbi, sizeof(BITMAPINFO)); + pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + pbi->bmiHeader.biWidth = 12; + ret = GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS); + ok(ret == 1, "%d\n", ret); + pbi->bmiHeader.biWidth = 0; + pbi->bmiHeader.biSizeImage = 123; + ret = GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS); + ok(ret == 0, "%d\n", ret); + pbi->bmiHeader.biSizeImage = 0; + pbi->bmiHeader.biCompression = BI_RGB; + ret = GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS); + ok(ret == 0, "%d\n", ret); + + DeleteObject(hbmp); + DeleteDC(hdcMem); + ReleaseDC(NULL, hdcScreen); } START_TEST(GetDIBits) Modified: trunk/rostests/apitests/gdi32/SelectObject.c URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/gdi32/SelectObje…
============================================================================== --- trunk/rostests/apitests/gdi32/SelectObject.c [iso-8859-1] (original) +++ trunk/rostests/apitests/gdi32/SelectObject.c [iso-8859-1] Sun Feb 27 22:00:13 2011 @@ -15,24 +15,20 @@ #define TEST(x) ok(x, #x"\n") #define RTEST(x) ok(x, #x"\n") -void Test_SelectObject() +#define ok_err(dwErr) ok(GetLastError() == dwErr, "Wrong LastError, expected %d, got %ld\n", dwErr, GetLastError()) + +HDC hdc1, hdc2; + +static void +Test_SelectObject() { HGDIOBJ hOldObj, hNewObj; - HDC hScreenDC, hDC, hDC2; // PGDI_TABLE_ENTRY pEntry; // PDC_ATTR pDc_Attr; // HANDLE hcmXform; - BYTE bmBits[4] = {0}; - - hScreenDC = GetDC(NULL); - ok(hScreenDC != NULL, "GetDC failed. Skipping tests.\n"); - if (hScreenDC == NULL) return; - hDC = CreateCompatibleDC(hScreenDC); - ok(hDC != NULL, "CreateCompatibleDC failed. Skipping tests.\n"); - if (hDC == NULL) return; /* Get the Dc_Attr for later testing */ -// pEntry = &GdiHandleTable[GDI_HANDLE_GET_INDEX(hDC)]; +// pEntry = &GdiHandleTable[GDI_HANDLE_GET_INDEX(hdc1)]; // pDc_Attr = pEntry->UserData; // ok(pDc_Attr != NULL, "Skipping tests.\n"); // if (pDc_Attr == NULL) return; @@ -40,27 +36,27 @@ /* Test incomplete dc handle doesn't work */ SetLastError(ERROR_SUCCESS); hNewObj = GetStockObject(GRAY_BRUSH); - hOldObj = SelectObject((HDC)GDI_HANDLE_GET_INDEX(hDC), hNewObj); - RTEST(GetLastError() == ERROR_INVALID_HANDLE); - RTEST(hOldObj == NULL); -// RTEST(pDc_Attr->hbrush == GetStockObject(WHITE_BRUSH)); - SelectObject(hDC, hOldObj); + hOldObj = SelectObject((HDC)GDI_HANDLE_GET_INDEX(hdc1), hNewObj); + ok_err(ERROR_INVALID_HANDLE); + ok(hOldObj == NULL, "\n"); +// ok(pDc_Attr->hbrush == GetStockObject(WHITE_BRUSH), "\n"); + SelectObject(hdc1, hOldObj); /* Test incomplete hobj handle works */ hNewObj = GetStockObject(GRAY_BRUSH); - hOldObj = SelectObject(hDC, (HGDIOBJ)GDI_HANDLE_GET_INDEX(hNewObj)); - RTEST(hOldObj == GetStockObject(WHITE_BRUSH)); -// RTEST(pDc_Attr->hbrush == hNewObj); - SelectObject(hDC, hOldObj); + hOldObj = SelectObject(hdc1, (HGDIOBJ)GDI_HANDLE_GET_INDEX(hNewObj)); + ok(hOldObj == GetStockObject(WHITE_BRUSH), "\n"); +// ok(pDc_Attr->hbrush == hNewObj, "\n"); + SelectObject(hdc1, hOldObj); /* Test wrong hDC handle type */ SetLastError(ERROR_SUCCESS); hNewObj = GetStockObject(GRAY_BRUSH); - hDC2 = (HDC)((UINT_PTR)hDC & ~GDI_HANDLE_TYPE_MASK); - hDC2 = (HDC)((UINT_PTR)hDC2 | GDI_OBJECT_TYPE_PEN); - hOldObj = SelectObject(hDC2, hNewObj); - RTEST(GetLastError() == ERROR_INVALID_HANDLE); - RTEST(hOldObj == NULL); + hdc2 = (HDC)((UINT_PTR)hdc1 & ~GDI_HANDLE_TYPE_MASK); + hdc2 = (HDC)((UINT_PTR)hdc2 | GDI_OBJECT_TYPE_PEN); + hOldObj = SelectObject(hdc2, hNewObj); + ok_err(ERROR_INVALID_HANDLE); + ok(hOldObj == NULL, "\n"); // RTEST(pDc_Attr->hbrush == GetStockObject(WHITE_BRUSH)); /* Test wrong hobj handle type */ @@ -68,68 +64,35 @@ hNewObj = GetStockObject(GRAY_BRUSH); hNewObj = (HGDIOBJ)((UINT_PTR)hNewObj & ~GDI_HANDLE_TYPE_MASK); hNewObj = (HGDIOBJ)((UINT_PTR)hNewObj | GDI_OBJECT_TYPE_PEN); - hOldObj = SelectObject(hDC, hNewObj); - RTEST(GetLastError() == ERROR_SUCCESS); + hOldObj = SelectObject(hdc1, hNewObj); + ok_err(ERROR_SUCCESS); + ok(hOldObj == NULL, "\n"); +// RTEST(pDc_Attr->hbrush == GetStockObject(WHITE_BRUSH)); + + SetLastError(ERROR_SUCCESS); + hNewObj = (HGDIOBJ)0x00761234; + hOldObj = SelectObject(hdc1, hNewObj); + ok(hOldObj == NULL, "\n"); + ok_err(ERROR_SUCCESS); + SelectObject(hdc1, hOldObj); + + /* Test DC */ + SetLastError(ERROR_SUCCESS); + hOldObj = SelectObject(hdc1, GetDC(NULL)); + ok(hOldObj == NULL, "\n"); + ok_err(ERROR_SUCCESS); + + + /* Test CLIOBJ */ + + /* Test PATH */ + + /* Test PALETTE */ + SetLastError(ERROR_SUCCESS); + hNewObj = GetStockObject(DEFAULT_PALETTE); + hOldObj = SelectObject(hdc1, hNewObj); RTEST(hOldObj == NULL); -// RTEST(pDc_Attr->hbrush == GetStockObject(WHITE_BRUSH)); - - SetLastError(ERROR_SUCCESS); - hNewObj = (HGDIOBJ)0x00761234; - hOldObj = SelectObject(hDC, hNewObj); - RTEST(hOldObj == NULL); - RTEST(GetLastError() == ERROR_SUCCESS); - SelectObject(hDC, hOldObj); - - /* Test DC */ - SetLastError(ERROR_SUCCESS); - hOldObj = SelectObject(hDC, hScreenDC); - RTEST(hOldObj == NULL); - TEST(GetLastError() == ERROR_SUCCESS); - - /* Test REGION */ - SetLastError(ERROR_SUCCESS); - hNewObj = CreateRectRgn(0,0,0,0); - hOldObj = SelectObject(hDC, hNewObj); - RTEST((UINT_PTR)hOldObj == NULLREGION); - DeleteObject(hNewObj); - - hNewObj = CreateRectRgn(0,0,10,10); - RTEST((UINT_PTR)SelectObject(hDC, hNewObj) == SIMPLEREGION); - hOldObj = CreateRectRgn(5,5,20,20); - RTEST(CombineRgn(hNewObj, hNewObj, hOldObj, RGN_OR) == COMPLEXREGION); - DeleteObject(hOldObj); - RTEST((UINT_PTR)SelectObject(hDC, hNewObj) == SIMPLEREGION); // ??? Why this? - DeleteObject(hNewObj); -// TEST(IsHandleValid(hNewObj) == TRUE); - - RTEST(GetLastError() == ERROR_SUCCESS); - - /* Test BITMAP */ - hNewObj = CreateBitmap(2, 2, 1, 1, &bmBits); - ok(hNewObj != NULL, "CreateBitmap failed. Skipping tests.\n"); - if (hNewObj == NULL) return; - hOldObj = SelectObject(hDC, hNewObj); - RTEST(GDI_HANDLE_GET_TYPE(hOldObj) == GDI_OBJECT_TYPE_BITMAP); - hOldObj = SelectObject(hDC, hOldObj); - RTEST(hOldObj == hNewObj); - - /* Test invalid BITMAP */ - hNewObj = CreateBitmap(2, 2, 1, 4, &bmBits); - ok(hNewObj != NULL, "CreateBitmap failed. Skipping tests.\n"); - if (hNewObj == NULL) return; - hOldObj = SelectObject(hDC, hNewObj); - ok(hOldObj == NULL, "should fail\n"); - - /* Test CLIOBJ */ - - /* Test PATH */ - - /* Test PALETTE */ - SetLastError(ERROR_SUCCESS); - hNewObj = GetStockObject(DEFAULT_PALETTE); - hOldObj = SelectObject(hDC, hNewObj); - RTEST(hOldObj == NULL); - RTEST(GetLastError() == ERROR_INVALID_FUNCTION); + ok_err(ERROR_INVALID_FUNCTION); /* Test COLORSPACE */ @@ -139,17 +102,17 @@ /* Test BRUSH */ hNewObj = GetStockObject(GRAY_BRUSH); - hOldObj = SelectObject(hDC, hNewObj); + hOldObj = SelectObject(hdc1, hNewObj); RTEST(hOldObj == GetStockObject(WHITE_BRUSH)); // RTEST(pDc_Attr->hbrush == hNewObj); RTEST(GDI_HANDLE_GET_TYPE(hOldObj) == GDI_OBJECT_TYPE_BRUSH); - SelectObject(hDC, hOldObj); + SelectObject(hdc1, hOldObj); /* Test DC_BRUSH */ hNewObj = GetStockObject(DC_BRUSH); - hOldObj = SelectObject(hDC, hNewObj); + hOldObj = SelectObject(hdc1, hNewObj); // RTEST(pDc_Attr->hbrush == hNewObj); - SelectObject(hDC, hOldObj); + SelectObject(hdc1, hOldObj); /* Test BRUSH color xform */ // hcmXform = (HANDLE)pDc_Attr->hcmXform; @@ -161,22 +124,107 @@ /* Test ENHMETAFILE */ + /* Test EXTPEN */ + + /* Test METADC */ +} + +static void +Test_Bitmap() +{ + HBITMAP hbmp, hbmpInvalid, hbmpOld; + BYTE bmBits[4] = {0}; + HDC hdcTmp; + + hbmp = CreateBitmap(2, 2, 1, 1, &bmBits); + hbmpInvalid = CreateBitmap(2, 2, 1, 4, &bmBits); + if (!hbmp || !hbmpInvalid) + { + printf("couldn't create bitmaps, skipping\n"); + return; + } + + hbmpOld = SelectObject(hdc1, hbmp); + ok(GDI_HANDLE_GET_TYPE(hbmpOld) == GDI_OBJECT_TYPE_BITMAP, "wrong type\n"); + + /* Test invalid BITMAP */ + ok(SelectObject(hdc1, hbmpInvalid) == NULL, "should fail\n"); + + /* Test if we get the right bitmap back */ + hbmpOld = SelectObject(hdc1, hbmpOld); + ok(hbmpOld == hbmp, "didn't get the right bitmap back.\n"); + + /* Test selecting bitmap into 2 DCs */ + hbmpOld = SelectObject(hdc1, hbmp); + ok(SelectObject(hdc2, hbmp) == NULL, "Should fail.\n"); + + /* Test selecting same bitmap twice */ + hbmpOld = SelectObject(hdc1, hbmp); + ok(hbmpOld == hbmp, "didn't get the right bitmap back.\n"); + SelectObject(hdc1, GetStockObject(DEFAULT_BITMAP)); + + /* Test selecting and then deleting the DC */ + hdcTmp = CreateCompatibleDC(NULL); + hbmpOld = SelectObject(hdcTmp, hbmp); + ok(hbmpOld == GetStockObject(DEFAULT_BITMAP), "didn't get the right bitmap back.\n"); + DeleteDC(hdcTmp); + hbmpOld = SelectObject(hdc1, hbmp); + ok(hbmpOld == GetStockObject(DEFAULT_BITMAP), "didn't get the right bitmap back.\n"); + + DeleteObject(hbmp); + DeleteObject(hbmpInvalid); +} + +static void +Test_Pen() +{ + HPEN hpen, hpenOld; + /* Test PEN */ - hNewObj = GetStockObject(GRAY_BRUSH); - hOldObj = SelectObject(hDC, hNewObj); - RTEST(hOldObj == GetStockObject(WHITE_BRUSH)); -// RTEST(pDc_Attr->hbrush == hNewObj); - RTEST(GDI_HANDLE_GET_TYPE(hOldObj) == GDI_OBJECT_TYPE_BRUSH); - SelectObject(hDC, hOldObj); - - - /* Test EXTPEN */ - - /* Test METADC */ + hpen = GetStockObject(GRAY_BRUSH); + hpenOld = SelectObject(hdc1, hpen); + ok(hpenOld == GetStockObject(WHITE_BRUSH), "Got wrong pen.\n"); +// RTEST(pDc_Attr->hbrush == hpen); + ok(GDI_HANDLE_GET_TYPE(hpenOld) == GDI_OBJECT_TYPE_BRUSH, "wrong type.\n"); + SelectObject(hdc1, hpenOld); +} + +static void +Test_Region() +{ + HRGN hrgn, hrgnOld; + + /* Test REGION */ + SetLastError(ERROR_SUCCESS); + hrgn = CreateRectRgn(0,0,0,0); + hrgnOld = SelectObject(hdc1, hrgn); + ok((UINT_PTR)hrgnOld == NULLREGION, "\n"); + DeleteObject(hrgn); + + hrgn = CreateRectRgn(0,0,10,10); + ok((UINT_PTR)SelectObject(hdc1, hrgn) == SIMPLEREGION, "\n"); + hrgnOld = CreateRectRgn(5,5,20,20); + ok(CombineRgn(hrgn, hrgn, hrgnOld, RGN_OR) == COMPLEXREGION, "\n"); + DeleteObject(hrgnOld); + ok((UINT_PTR)SelectObject(hdc1, hrgn) == SIMPLEREGION, "\n"); // ??? Why this? + DeleteObject(hrgn); +// ok(IsHandleValid(hrgn) == TRUE, "\n"); + ok_err(ERROR_SUCCESS); } START_TEST(SelectObject) { + hdc1 = CreateCompatibleDC(NULL); + hdc2 = CreateCompatibleDC(NULL); + if (!hdc1 || !hdc2) + { + printf("couldn't create DCs, skipping all tests\n"); + return; + } + Test_SelectObject(); -} - + Test_Bitmap(); + Test_Pen(); + Test_Region(); +} +
13 years, 9 months
1
0
0
0
[jgardou] 50928: [WIN32K] - remove duplicate prototype - use RGB macro where possible - we create BGR palette for RGB DIB sections, let's do the other way around - simplify overcomplicated IntGetDI...
by jgardou@svn.reactos.org
Author: jgardou Date: Sun Feb 27 21:45:43 2011 New Revision: 50928 URL:
http://svn.reactos.org/svn/reactos?rev=50928&view=rev
Log: [WIN32K] - remove duplicate prototype - use RGB macro where possible - we create BGR palette for RGB DIB sections, let's do the other way around - simplify overcomplicated IntGetDIBColorTable - Add a first implementation of IntRealizePalette No, it's not the VLC icons bugfix Modified: trunk/reactos/subsystems/win32/win32k/include/intgdi.h trunk/reactos/subsystems/win32/win32k/objects/bitblt.c trunk/reactos/subsystems/win32/win32k/objects/bitmaps.c trunk/reactos/subsystems/win32/win32k/objects/dibobj.c trunk/reactos/subsystems/win32/win32k/objects/palette.c Modified: trunk/reactos/subsystems/win32/win32k/include/intgdi.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/in…
============================================================================== --- trunk/reactos/subsystems/win32/win32k/include/intgdi.h [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/win32k/include/intgdi.h [iso-8859-1] Sun Feb 27 21:45:43 2011 @@ -232,8 +232,6 @@ UINT StartIndex, UINT Entries, LPPALETTEENTRY pe); -UINT APIENTRY -IntGetDIBColorTable(HDC hDC, UINT StartIndex, UINT Entries, RGBQUAD *Colors); UINT APIENTRY IntSetDIBColorTable(HDC hDC, UINT StartIndex, UINT Entries, CONST RGBQUAD *Colors); Modified: trunk/reactos/subsystems/win32/win32k/objects/bitblt.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/ob…
============================================================================== --- trunk/reactos/subsystems/win32/win32k/objects/bitblt.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/win32k/objects/bitblt.c [iso-8859-1] Sun Feb 27 21:45:43 2011 @@ -562,8 +562,8 @@ NtGdiBitBlt(hdcBack, 0, 0, nWidth, nHeight, hdcDest, nXDest, nYDest, BKGND_ROP3(dwRop), 0, 0); /* 2.4 Erase the foreground pixels */ - IntGdiSetBkColor(hdcBack, 0xffffffff); - IntGdiSetTextColor(hdcBack, 0); + IntGdiSetBkColor(hdcBack, RGB(0xFF, 0xFF, 0xFF)); + IntGdiSetTextColor(hdcBack, RGB(0, 0, 0)); NtGdiBitBlt(hdcBack, 0, 0, nWidth, nHeight, hdcMask, xMask, yMask, SRCAND, 0, 0); /* 3. Create masked Foreground bitmap */ @@ -583,8 +583,8 @@ NtGdiBitBlt(hdcFore, 0, 0, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, FRGND_ROP3(dwRop), 0,0); /* 2.4 Erase the background pixels */ - IntGdiSetBkColor(hdcFore, 0); - IntGdiSetTextColor(hdcFore, 0xffffffff); + IntGdiSetBkColor(hdcFore, RGB(0, 0, 0)); + IntGdiSetTextColor(hdcFore, RGB(0xFF, 0xFF, 0xFF)); NtGdiBitBlt(hdcFore, 0, 0, nWidth, nHeight, hdcMask, xMask, yMask, SRCAND, 0, 0); /* 3. Combine the fore and background into the background bitmap */ Modified: trunk/reactos/subsystems/win32/win32k/objects/bitmaps.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/ob…
============================================================================== --- trunk/reactos/subsystems/win32/win32k/objects/bitmaps.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/win32k/objects/bitmaps.c [iso-8859-1] Sun Feb 27 21:45:43 2011 @@ -941,7 +941,7 @@ break; case BMF_32BPP: - if (psurf->ppal->flFlags & PAL_RGB) + if (psurf->ppal->flFlags & (PAL_RGB|PAL_BGR)) pds->dsBmih.biCompression = BI_RGB; else pds->dsBmih.biCompression = BI_BITFIELDS; Modified: trunk/reactos/subsystems/win32/win32k/objects/dibobj.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/ob…
============================================================================== --- trunk/reactos/subsystems/win32/win32k/objects/dibobj.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/win32k/objects/dibobj.c [iso-8859-1] Sun Feb 27 21:45:43 2011 @@ -193,9 +193,8 @@ { PDC dc; PSURFACE psurf; - PPALETTE PalGDI; + PPALETTE ppal; UINT Index, Count = 0; - ULONG biBitCount; if (!(dc = DC_LockDc(hDC))) return 0; if (dc->dctype == DC_TYPE_INFO) @@ -219,33 +218,22 @@ return 0; } - biBitCount = BitsPerFormat(psurf->SurfObj.iBitmapFormat); - if (biBitCount <= 8 && - StartIndex < (1 << biBitCount)) - { - if (StartIndex + Entries > (1 << biBitCount)) - Entries = (1 << biBitCount) - StartIndex; - - if (psurf->ppal == NULL) - { - DC_UnlockDc(dc); - EngSetLastError(ERROR_INVALID_HANDLE); - return 0; - } - - PalGDI = PALETTE_LockPalette(psurf->ppal->BaseObject.hHmgr); + ppal = psurf->ppal; + ASSERT(ppal); + + if (ppal->flFlags & PAL_INDEXED) + { for (Index = StartIndex; - Index < StartIndex + Entries && Index < PalGDI->NumColors; + Index < StartIndex + Entries && Index < ppal->NumColors; Index++) { - Colors[Index - StartIndex].rgbRed = PalGDI->IndexedColors[Index].peRed; - Colors[Index - StartIndex].rgbGreen = PalGDI->IndexedColors[Index].peGreen; - Colors[Index - StartIndex].rgbBlue = PalGDI->IndexedColors[Index].peBlue; + Colors[Index - StartIndex].rgbRed = ppal->IndexedColors[Index].peRed; + Colors[Index - StartIndex].rgbGreen = ppal->IndexedColors[Index].peGreen; + Colors[Index - StartIndex].rgbBlue = ppal->IndexedColors[Index].peBlue; Colors[Index - StartIndex].rgbReserved = 0; Count++; } - PALETTE_UnlockPalette(PalGDI); } DC_UnlockDc(dc); Modified: trunk/reactos/subsystems/win32/win32k/objects/palette.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/ob…
============================================================================== --- trunk/reactos/subsystems/win32/win32k/objects/palette.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/win32k/objects/palette.c [iso-8859-1] Sun Feb 27 21:45:43 2011 @@ -725,58 +725,39 @@ FASTCALL IntGdiRealizePalette(HDC hDC) { - /* - * This function doesn't do any real work now and there's plenty - * of bugs in it. - */ - - PPALETTE palGDI, sysGDI; - int realized = 0; - PDC dc; - HPALETTE systemPalette; - - dc = DC_LockDc(hDC); - if (!dc) return 0; - - systemPalette = NtGdiGetStockObject(DEFAULT_PALETTE); - palGDI = PALETTE_LockPalette(dc->dclevel.hpal); - - if (palGDI == NULL) - { - DPRINT1("IntGdiRealizePalette(): palGDI is NULL, exiting\n"); - DC_UnlockDc(dc); - return 0; - } - - sysGDI = PALETTE_LockPalette(systemPalette); - - if (sysGDI == NULL) - { - DPRINT1("IntGdiRealizePalette(): sysGDI is NULL, exiting\n"); - PALETTE_UnlockPalette(palGDI); - DC_UnlockDc(dc); - return 0; - } - - // The RealizePalette function modifies the palette for the device associated with the specified device context. If the - // device context is a memory DC, the color table for the bitmap selected into the DC is modified. If the device - // context is a display DC, the physical palette for that device is modified. - if(dc->dctype == DC_TYPE_MEMORY) - { - // Memory managed DC - DPRINT1("RealizePalette unimplemented for memory managed DCs\n"); - } else - { - DPRINT1("RealizePalette unimplemented for device DCs\n"); - } - - // need to pass this to IntEngCreateXlate with palettes unlocked - PALETTE_UnlockPalette(sysGDI); - PALETTE_UnlockPalette(palGDI); - - DC_UnlockDc(dc); - - return realized; + UINT i, realize = 0; + PDC pdc; + PALETTE *ppalSurf, *ppalDC; + + pdc = DC_LockDc(hDC); + if(!pdc) + { + EngSetLastError(ERROR_INVALID_HANDLE); + return 0; + } + + ppalSurf = pdc->dclevel.pSurface->ppal; + ppalDC = pdc->dclevel.ppal; + + if(!(ppalSurf->flFlags & PAL_INDEXED)) + { + // FIXME : set error? + goto cleanup; + } + + ASSERT(ppalDC->flFlags & PAL_INDEXED); + + // FIXME : should we resize ppalSurf if it's too small? + realize = (ppalDC->NumColors < ppalSurf->NumColors) ? ppalDC->NumColors : ppalSurf->NumColors; + + for(i=0; i<realize; i++) + { + InterlockedExchange((LONG*)&ppalSurf->IndexedColors[i], *(LONG*)&ppalDC->IndexedColors[i]); + } + +cleanup: + DC_UnlockDc(pdc); + return realize; } UINT APIENTRY
13 years, 9 months
1
0
0
0
[fireball] 50927: [RTL/HEAP] - A few comments, and a new structure definition (currently unused). Absolutely no changes to the actual code.
by fireball@svn.reactos.org
Author: fireball Date: Sun Feb 27 19:36:46 2011 New Revision: 50927 URL:
http://svn.reactos.org/svn/reactos?rev=50927&view=rev
Log: [RTL/HEAP] - A few comments, and a new structure definition (currently unused). Absolutely no changes to the actual code. Modified: trunk/reactos/lib/rtl/heap.h Modified: trunk/reactos/lib/rtl/heap.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/heap.h?rev=50927&r…
============================================================================== --- trunk/reactos/lib/rtl/heap.h [iso-8859-1] (original) +++ trunk/reactos/lib/rtl/heap.h [iso-8859-1] Sun Feb 27 19:36:46 2011 @@ -182,6 +182,19 @@ ULONG MaxPreCommittThreshold; } HEAP_TUNING_PARAMETERS, *PHEAP_TUNING_PARAMETERS; +typedef struct _HEAP_LIST_LOOKUP +{ + struct _HEAP_LIST_LOOKUP *ExtendedLookup; + ULONG ArraySize; + ULONG ExtraItem; + ULONG ItemCount; + ULONG OutOfRangeItems; + ULONG BaseIndex; + PLIST_ENTRY ListHead; + PULONG ListsInUseUlong; + PLIST_ENTRY *ListHints; +} HEAP_LIST_LOOKUP, *PHEAP_LIST_LOOKUP; + typedef struct _HEAP { HEAP_ENTRY Entry; @@ -229,10 +242,11 @@ struct _HEAP_SEGMENT *Segments[HEAP_SEGMENTS]; //FIXME: non-Vista USHORT AllocatorBackTraceIndex; ULONG NonDedicatedListLength; - PVOID BlocksIndex; + PVOID BlocksIndex; // HEAP_LIST_LOOKUP PVOID UCRIndex; PHEAP_PSEUDO_TAG_ENTRY PseudoTagEntries; LIST_ENTRY FreeLists[HEAP_FREELISTS]; //FIXME: non-Vista + //LIST_ENTRY FreeLists; union { ULONG FreeListsInUseUlong[HEAP_FREELISTS / (sizeof(ULONG) * 8)]; //FIXME: non-Vista
13 years, 9 months
1
0
0
0
[ekohl] 50926: [SERVICES] Protect the service start and sending of control packages by critical sections. This way, services will be started one by one and control packages will also be sent one by...
by ekohl@svn.reactos.org
Author: ekohl Date: Sun Feb 27 19:25:14 2011 New Revision: 50926 URL:
http://svn.reactos.org/svn/reactos?rev=50926&view=rev
Log: [SERVICES] Protect the service start and sending of control packages by critical sections. This way, services will be started one by one and control packages will also be sent one by one. Please test if this fixes bug #5924. Modified: trunk/reactos/base/system/services/database.c trunk/reactos/base/system/services/services.c trunk/reactos/base/system/services/services.h Modified: trunk/reactos/base/system/services/database.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/datab…
============================================================================== --- trunk/reactos/base/system/services/database.c [iso-8859-1] (original) +++ trunk/reactos/base/system/services/database.c [iso-8859-1] Sun Feb 27 19:25:14 2011 @@ -30,6 +30,8 @@ static RTL_RESOURCE DatabaseLock; static DWORD dwResumeCount = 1; +static CRITICAL_SECTION NamedPipeCriticalSection; +static CRITICAL_SECTION StartServiceCriticalSection; /* FUNCTIONS *****************************************************************/ @@ -704,6 +706,8 @@ ControlPacket->hServiceStatus = (SERVICE_STATUS_HANDLE)Service; wcscpy(&ControlPacket->szArguments[0], Service->lpServiceName); + EnterCriticalSection(&NamedPipeCriticalSection); + /* Send the control packet */ WriteFile(Service->ControlPipeHandle, ControlPacket, @@ -717,6 +721,8 @@ sizeof(SCM_REPLY_PACKET), &dwReadCount, NULL); + + LeaveCriticalSection(&NamedPipeCriticalSection); /* Release the contol packet */ HeapFree(GetProcessHeap(), @@ -795,6 +801,8 @@ /* Terminate the argument list */ *Ptr = 0; + EnterCriticalSection(&NamedPipeCriticalSection); + /* Send the start command */ WriteFile(Service->ControlPipeHandle, ControlPacket, @@ -808,6 +816,8 @@ sizeof(SCM_REPLY_PACKET), &dwReadCount, NULL); + + LeaveCriticalSection(&NamedPipeCriticalSection); /* Release the contol packet */ HeapFree(GetProcessHeap(), @@ -912,6 +922,8 @@ return Status; } + EnterCriticalSection(&StartServiceCriticalSection); + /* Create '\\.\pipe\net\NtControlPipeXXX' instance */ swprintf(NtControlPipeName, L"\\\\.\\pipe\\net\\NtControlPipe%u", ServiceCurrent); Service->ControlPipeHandle = CreateNamedPipeW(NtControlPipeName, @@ -926,6 +938,7 @@ if (Service->ControlPipeHandle == INVALID_HANDLE_VALUE) { DPRINT1("Failed to create control pipe!\n"); + LeaveCriticalSection(&StartServiceCriticalSection); return GetLastError(); } @@ -957,6 +970,7 @@ Service->ControlPipeHandle = INVALID_HANDLE_VALUE; DPRINT1("Starting '%S' failed!\n", Service->lpServiceName); + LeaveCriticalSection(&StartServiceCriticalSection); return dwError; } @@ -1015,6 +1029,8 @@ /* Close process and thread handle */ CloseHandle(ProcessInformation.hThread); CloseHandle(ProcessInformation.hProcess); + + LeaveCriticalSection(&StartServiceCriticalSection); return dwError; } @@ -1257,4 +1273,20 @@ RtlReleaseResource(&DatabaseLock); } + +VOID +ScmInitNamedPipeCriticalSection(VOID) +{ + InitializeCriticalSection(&NamedPipeCriticalSection); + InitializeCriticalSection(&StartServiceCriticalSection); +} + + +VOID +ScmDeleteNamedPipeCriticalSection(VOID) +{ + DeleteCriticalSection(&StartServiceCriticalSection); + DeleteCriticalSection(&NamedPipeCriticalSection); +} + /* EOF */ Modified: trunk/reactos/base/system/services/services.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/servi…
============================================================================== --- trunk/reactos/base/system/services/services.c [iso-8859-1] (original) +++ trunk/reactos/base/system/services/services.c [iso-8859-1] Sun Feb 27 19:25:14 2011 @@ -385,6 +385,8 @@ /* Acquire privileges to load drivers */ AcquireLoadDriverPrivilege(); + ScmInitNamedPipeCriticalSection(); + /* Start auto-start services */ ScmAutoStartServices(); @@ -404,6 +406,8 @@ } #endif + ScmDeleteNamedPipeCriticalSection(); + CloseHandle(hScmStartEvent); DPRINT("SERVICES: Finished.\n"); Modified: trunk/reactos/base/system/services/services.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/servi…
============================================================================== --- trunk/reactos/base/system/services/services.h [iso-8859-1] (original) +++ trunk/reactos/base/system/services/services.h [iso-8859-1] Sun Feb 27 19:25:14 2011 @@ -123,6 +123,9 @@ BOOL ScmLockDatabaseShared(VOID); VOID ScmUnlockDatabase(VOID); +VOID ScmInitNamedPipeCriticalSection(VOID); +VOID ScmDeleteNamedPipeCriticalSection(VOID); + /* driver.c */
13 years, 9 months
1
0
0
0
[fireball] 50925: - Promote service start failures from TRACE to ERR. See issue #5924 for more details.
by fireball@svn.reactos.org
Author: fireball Date: Sun Feb 27 19:09:45 2011 New Revision: 50925 URL:
http://svn.reactos.org/svn/reactos?rev=50925&view=rev
Log: - Promote service start failures from TRACE to ERR. See issue #5924 for more details. Modified: trunk/reactos/dll/win32/advapi32/service/scm.c trunk/reactos/dll/win32/syssetup/install.c Modified: trunk/reactos/dll/win32/advapi32/service/scm.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/service…
============================================================================== --- trunk/reactos/dll/win32/advapi32/service/scm.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/advapi32/service/scm.c [iso-8859-1] Sun Feb 27 19:09:45 2011 @@ -2372,7 +2372,7 @@ if (dwError != ERROR_SUCCESS) { - TRACE("RStartServiceA() failed (Error %lu)\n", dwError); + ERR("RStartServiceA() failed (Error %lu)\n", dwError); SetLastError(dwError); return FALSE; } @@ -2407,7 +2407,7 @@ if (dwError != ERROR_SUCCESS) { - TRACE("RStartServiceW() failed (Error %lu)\n", dwError); + ERR("RStartServiceW() failed (Error %lu)\n", dwError); SetLastError(dwError); return FALSE; } Modified: trunk/reactos/dll/win32/syssetup/install.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/syssetup/install…
============================================================================== --- trunk/reactos/dll/win32/syssetup/install.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/syssetup/install.c [iso-8859-1] Sun Feb 27 19:09:45 2011 @@ -508,7 +508,7 @@ ret = StartServiceW(hService, 0, NULL); if (!ret) { - DPRINT("Unable to start service\n"); + DPRINT1("Unable to start service\n"); goto cleanup; }
13 years, 9 months
1
0
0
0
[tkreuzer] 50924: [NTOSKRNL] Fix aborting of backtraces
by tkreuzer@svn.reactos.org
Author: tkreuzer Date: Sun Feb 27 19:03:12 2011 New Revision: 50924 URL:
http://svn.reactos.org/svn/reactos?rev=50924&view=rev
Log: [NTOSKRNL] Fix aborting of backtraces Modified: trunk/reactos/ntoskrnl/kdbg/kdb_cli.c Modified: trunk/reactos/ntoskrnl/kdbg/kdb_cli.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/kdbg/kdb_cli.c?re…
============================================================================== --- trunk/reactos/ntoskrnl/kdbg/kdb_cli.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/kdbg/kdb_cli.c [iso-8859-1] Sun Feb 27 19:03:12 2011 @@ -877,6 +877,8 @@ else KdbpPrint("\n"); + if (KdbOutputAborted) break; + if (Address == 0) break; @@ -2707,6 +2709,7 @@ /* Call the command */ Continue = KdbpDoCommand(Command); + KdbOutputAborted = FALSE; } while (Continue); }
13 years, 9 months
1
0
0
0
[cwittich] 50923: [imagehlp] -partial winesync
by cwittich@svn.reactos.org
Author: cwittich Date: Sun Feb 27 18:49:27 2011 New Revision: 50923 URL:
http://svn.reactos.org/svn/reactos?rev=50923&view=rev
Log: [imagehlp] -partial winesync Modified: trunk/reactos/dll/win32/imagehlp/integrity.c Modified: trunk/reactos/dll/win32/imagehlp/integrity.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/imagehlp/integri…
============================================================================== --- trunk/reactos/dll/win32/imagehlp/integrity.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/imagehlp/integrity.c [iso-8859-1] Sun Feb 27 18:49:27 2011 @@ -4,6 +4,8 @@ * Copyright 1998 Patrik Stridvall * Copyright 2003 Mike McCormack * Copyright 2009 Owen Rudge for CodeWeavers + * Copyright 2010 Juan Lang + * Copyright 2010 Andrey Turkin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -461,9 +463,10 @@ if (Certificate->dwLength % 8) { char null[8]; + DWORD dwBytesWritten; ZeroMemory(null, 8); - WriteFile(FileHandle, null, 8 - (Certificate->dwLength % 8), NULL, NULL); + WriteFile(FileHandle, null, 8 - (Certificate->dwLength % 8), &dwBytesWritten, NULL); size += 8 - (Certificate->dwLength % 8); } @@ -630,18 +633,255 @@ return TRUE; } +/* Finds the section named section in the array of IMAGE_SECTION_HEADERs hdr. If + * found, returns the offset to the section. Otherwise returns 0. If the section + * is found, optionally returns the size of the section (in size) and the base + * address of the section (in base.) + */ +static DWORD IMAGEHLP_GetSectionOffset( IMAGE_SECTION_HEADER *hdr, + DWORD num_sections, LPCSTR section, PDWORD size, PDWORD base ) +{ + DWORD i, offset = 0; + + for( i = 0; !offset && i < num_sections; i++, hdr++ ) + { + if( !memcmp( hdr->Name, section, strlen(section) ) ) + { + offset = hdr->PointerToRawData; + if( size ) + *size = hdr->SizeOfRawData; + if( base ) + *base = hdr->VirtualAddress; + } + } + return offset; +} + +/* Calls DigestFunction e bytes at offset offset from the file mapped at map. + * Returns the return value of DigestFunction, or FALSE if the data is not available. + */ +static BOOL IMAGEHLP_ReportSectionFromOffset( DWORD offset, DWORD size, + BYTE *map, DWORD fileSize, DIGEST_FUNCTION DigestFunction, DIGEST_HANDLE DigestHandle ) +{ + if( offset + size > fileSize ) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + return DigestFunction( DigestHandle, map + offset, size ); +} + +/* Finds the section named section among the IMAGE_SECTION_HEADERs in + * section_headers and calls DigestFunction for this section. Returns + * the return value from DigestFunction, or FALSE if the data could not be read. + */ +static BOOL IMAGEHLP_ReportSection( IMAGE_SECTION_HEADER *section_headers, + DWORD num_sections, LPCSTR section, BYTE *map, DWORD fileSize, + DIGEST_FUNCTION DigestFunction, DIGEST_HANDLE DigestHandle ) +{ + DWORD offset, size = 0; + + offset = IMAGEHLP_GetSectionOffset( section_headers, num_sections, section, + &size, NULL ); + if( !offset ) + return FALSE; + return IMAGEHLP_ReportSectionFromOffset( offset, size, map, fileSize, + DigestFunction, DigestHandle ); +} + +/* Calls DigestFunction for all sections with the IMAGE_SCN_CNT_CODE flag set. + * Returns the return value from * DigestFunction, or FALSE if a section could not be read. + */ +static BOOL IMAGEHLP_ReportCodeSections( IMAGE_SECTION_HEADER *hdr, DWORD num_sections, + BYTE *map, DWORD fileSize, DIGEST_FUNCTION DigestFunction, DIGEST_HANDLE DigestHandle ) +{ + DWORD i; + BOOL ret = TRUE; + + for( i = 0; ret && i < num_sections; i++, hdr++ ) + { + if( hdr->Characteristics & IMAGE_SCN_CNT_CODE ) + ret = IMAGEHLP_ReportSectionFromOffset( hdr->PointerToRawData, + hdr->SizeOfRawData, map, fileSize, DigestFunction, DigestHandle ); + } + return ret; +} + +/* Reports the import section from the file FileHandle. If + * CERT_PE_IMAGE_DIGEST_ALL_IMPORT_INFO is set in DigestLevel, reports the entire + * import section. + * FIXME: if it's not set, the function currently fails. + */ +static BOOL IMAGEHLP_ReportImportSection( IMAGE_SECTION_HEADER *hdr, + DWORD num_sections, BYTE *map, DWORD fileSize, DWORD DigestLevel, + DIGEST_FUNCTION DigestFunction, DIGEST_HANDLE DigestHandle ) +{ + BOOL ret = FALSE; + DWORD offset, size, base; + + /* Get import data */ + offset = IMAGEHLP_GetSectionOffset( hdr, num_sections, ".idata", &size, + &base ); + if( !offset ) + return FALSE; + + /* If CERT_PE_IMAGE_DIGEST_ALL_IMPORT_INFO is set, the entire + * section is reported. Otherwise, the debug info section is + * decoded and reported piecemeal. See tests. However, I haven't been + * able to figure out how the native implementation decides which values + * to report. Either it's buggy or my understanding is flawed. + */ + if( DigestLevel & CERT_PE_IMAGE_DIGEST_ALL_IMPORT_INFO ) + ret = IMAGEHLP_ReportSectionFromOffset( offset, size, map, fileSize, + DigestFunction, DigestHandle ); + else + { + FIXME("not supported except for CERT_PE_IMAGE_DIGEST_ALL_IMPORT_INFO\n"); + SetLastError(ERROR_INVALID_PARAMETER); + ret = FALSE; + } + + return ret; +} + /*********************************************************************** * ImageGetDigestStream (IMAGEHLP.@) + * + * Gets a stream of bytes from a PE file overwhich a hash might be computed to + * verify that the image has not changed. Useful for creating a certificate to + * be added to the file with ImageAddCertificate. + * + * PARAMS + * FileHandle [In] File for which to return a stream. + * DigestLevel [In] Flags to control which portions of the file to return. + * 0 is allowed, as is any combination of: + * CERT_PE_IMAGE_DIGEST_ALL_IMPORT_INFO: reports the entire + * import section rather than selected portions of it. + * CERT_PE_IMAGE_DIGEST_DEBUG_INFO: reports the debug section. + * CERT_PE_IMAGE_DIGEST_RESOURCES: reports the resources + section. + * DigestFunction [In] Callback function. + * DigestHandle [In] Handle passed as first parameter to DigestFunction. + * + * RETURNS + * TRUE if successful. + * FALSE if unsuccessful. GetLastError returns more about the error. + * + * NOTES + * Only supports 32-bit PE files, not tested with any other format. + * Reports data in the following order: + * 1. The file headers are reported first + * 2. Any code sections are reported next. + * 3. The data (".data" and ".rdata") sections are reported next. + * 4. The import section is reported next. + * 5. If CERT_PE_IMAGE_DIGEST_DEBUG_INFO is set in DigestLevel, the debug section is + * reported next. + * 6. If CERT_PE_IMAGE_DIGEST_RESOURCES is set in DigestLevel, the resources section + * is reported next. + * + * BUGS + * CERT_PE_IMAGE_DIGEST_ALL_IMPORT_INFO must be specified, returns an error if not. */ BOOL WINAPI ImageGetDigestStream( HANDLE FileHandle, DWORD DigestLevel, DIGEST_FUNCTION DigestFunction, DIGEST_HANDLE DigestHandle) { - FIXME("(%p, %d, %p, %p): stub\n", - FileHandle, DigestLevel, DigestFunction, DigestHandle - ); - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return FALSE; + DWORD error = 0; + BOOL ret = FALSE; + DWORD offset, size, num_sections, fileSize; + HANDLE hMap = INVALID_HANDLE_VALUE; + BYTE *map = NULL; + IMAGE_DOS_HEADER *dos_hdr; + IMAGE_NT_HEADERS *nt_hdr; + IMAGE_SECTION_HEADER *section_headers; + + TRACE("(%p, %d, %p, %p)\n", FileHandle, DigestLevel, DigestFunction, + DigestHandle); + + /* Get the file size */ + if( !FileHandle ) + goto invalid_parameter; + fileSize = GetFileSize( FileHandle, NULL ); + if(fileSize == INVALID_FILE_SIZE ) + goto invalid_parameter; + + /* map file */ + hMap = CreateFileMappingW( FileHandle, NULL, PAGE_READONLY, 0, 0, NULL ); + if( hMap == INVALID_HANDLE_VALUE ) + goto invalid_parameter; + map = MapViewOfFile( hMap, FILE_MAP_COPY, 0, 0, 0 ); + if( !map ) + goto invalid_parameter; + + /* Read the file header */ + if( fileSize < sizeof(IMAGE_DOS_HEADER) ) + goto invalid_parameter; + dos_hdr = (IMAGE_DOS_HEADER *)map; + + if( dos_hdr->e_magic != IMAGE_DOS_SIGNATURE ) + goto invalid_parameter; + offset = dos_hdr->e_lfanew; + if( !offset || offset > fileSize ) + goto invalid_parameter; + ret = DigestFunction( DigestHandle, map, offset ); + if( !ret ) + goto end; + + /* Read the NT header */ + if( offset + sizeof(IMAGE_NT_HEADERS) > fileSize ) + goto invalid_parameter; + nt_hdr = (IMAGE_NT_HEADERS *)(map + offset); + if( nt_hdr->Signature != IMAGE_NT_SIGNATURE ) + goto invalid_parameter; + /* It's clear why the checksum is cleared, but why only these size headers? + */ + nt_hdr->OptionalHeader.SizeOfInitializedData = 0; + nt_hdr->OptionalHeader.SizeOfImage = 0; + nt_hdr->OptionalHeader.CheckSum = 0; + size = sizeof(nt_hdr->Signature) + sizeof(nt_hdr->FileHeader) + + nt_hdr->FileHeader.SizeOfOptionalHeader; + ret = DigestFunction( DigestHandle, map + offset, size ); + if( !ret ) + goto end; + + /* Read the section headers */ + offset += size; + num_sections = nt_hdr->FileHeader.NumberOfSections; + size = num_sections * sizeof(IMAGE_SECTION_HEADER); + if( offset + size > fileSize ) + goto invalid_parameter; + ret = DigestFunction( DigestHandle, map + offset, size ); + if( !ret ) + goto end; + + section_headers = (IMAGE_SECTION_HEADER *)(map + offset); + IMAGEHLP_ReportCodeSections( section_headers, num_sections, + map, fileSize, DigestFunction, DigestHandle ); + IMAGEHLP_ReportSection( section_headers, num_sections, ".data", + map, fileSize, DigestFunction, DigestHandle ); + IMAGEHLP_ReportSection( section_headers, num_sections, ".rdata", + map, fileSize, DigestFunction, DigestHandle ); + IMAGEHLP_ReportImportSection( section_headers, num_sections, + map, fileSize, DigestLevel, DigestFunction, DigestHandle ); + if( DigestLevel & CERT_PE_IMAGE_DIGEST_DEBUG_INFO ) + IMAGEHLP_ReportSection( section_headers, num_sections, ".debug", + map, fileSize, DigestFunction, DigestHandle ); + if( DigestLevel & CERT_PE_IMAGE_DIGEST_RESOURCES ) + IMAGEHLP_ReportSection( section_headers, num_sections, ".rsrc", + map, fileSize, DigestFunction, DigestHandle ); + +end: + if( map ) + UnmapViewOfFile( map ); + if( hMap != INVALID_HANDLE_VALUE ) + CloseHandle( hMap ); + if( error ) + SetLastError(error); + return ret; + +invalid_parameter: + error = ERROR_INVALID_PARAMETER; + goto end; } /***********************************************************************
13 years, 9 months
1
0
0
0
[cwittich] 50922: [imagehlp_winetest] -add imagehlp_winetest
by cwittich@svn.reactos.org
Author: cwittich Date: Sun Feb 27 18:30:50 2011 New Revision: 50922 URL:
http://svn.reactos.org/svn/reactos?rev=50922&view=rev
Log: [imagehlp_winetest] -add imagehlp_winetest Added: trunk/rostests/winetests/imagehlp/ (with props) trunk/rostests/winetests/imagehlp/image.c (with props) trunk/rostests/winetests/imagehlp/imagehlp.rbuild (with props) trunk/rostests/winetests/imagehlp/integrity.c (with props) trunk/rostests/winetests/imagehlp/testlist.c (with props) Modified: trunk/rostests/winetests/directory.rbuild Modified: trunk/rostests/winetests/directory.rbuild URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/winetests/directory.rbuil…
============================================================================== --- trunk/rostests/winetests/directory.rbuild [iso-8859-1] (original) +++ trunk/rostests/winetests/directory.rbuild [iso-8859-1] Sun Feb 27 18:30:50 2011 @@ -67,6 +67,9 @@ <directory name="icmp"> <xi:include href="icmp/icmp.rbuild" /> </directory> + <directory name="imagehlp"> + <xi:include href="imagehlp/imagehlp.rbuild" /> + </directory> <directory name="imm32"> <xi:include href="imm32/imm32.rbuild" /> </directory> Propchange: trunk/rostests/winetests/imagehlp/ ------------------------------------------------------------------------------ --- bugtraq:logregex (added) +++ bugtraq:logregex Sun Feb 27 18:30:50 2011 @@ -1,0 +1,2 @@ +([Ii]ssue|[Bb]ug)s? #?(\d+)(,? ?#?(\d+))*(,? ?(and |or )?#?(\d+))? +(\d+) Propchange: trunk/rostests/winetests/imagehlp/ ------------------------------------------------------------------------------ bugtraq:message = See issue #%BUGID% for more details. Propchange: trunk/rostests/winetests/imagehlp/ ------------------------------------------------------------------------------ bugtraq:url =
http://www.reactos.org/bugzilla/show_bug.cgi?id=%BUGID%
Propchange: trunk/rostests/winetests/imagehlp/ ------------------------------------------------------------------------------ tsvn:logminsize = 10 Added: trunk/rostests/winetests/imagehlp/image.c URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/winetests/imagehlp/image.…
============================================================================== --- trunk/rostests/winetests/imagehlp/image.c (added) +++ trunk/rostests/winetests/imagehlp/image.c [iso-8859-1] Sun Feb 27 18:30:50 2011 @@ -1,0 +1,353 @@ +/* + * Copyright 2008 Juan Lang + * Copyright 2010 Andrey Turkin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ +#include <stdio.h> +#include <stdarg.h> + +#define NONAMELESSUNION +#include <windef.h> +#include <winbase.h> +#include <winver.h> +#include <winnt.h> +#include <imagehlp.h> + +#include "wine/test.h" + +static HMODULE hImageHlp; + +static BOOL (WINAPI *pImageGetDigestStream)(HANDLE, DWORD, DIGEST_FUNCTION, DIGEST_HANDLE); + +/* minimal PE file image */ +#define VA_START 0x400000 +#define FILE_PE_START 0x50 +#define NUM_SECTIONS 3 +#define FILE_TEXT 0x200 +#define RVA_TEXT 0x1000 +#define RVA_BSS 0x2000 +#define FILE_IDATA 0x400 +#define RVA_IDATA 0x3000 +#define FILE_TOTAL 0x600 +#define RVA_TOTAL 0x4000 +#include <pshpack1.h> +struct Imports { + IMAGE_IMPORT_DESCRIPTOR descriptors[2]; + IMAGE_THUNK_DATA32 original_thunks[2]; + IMAGE_THUNK_DATA32 thunks[2]; + struct __IMPORT_BY_NAME { + WORD hint; + char funcname[0x20]; + } ibn; + char dllname[0x10]; +}; +#define EXIT_PROCESS (VA_START+RVA_IDATA+FIELD_OFFSET(struct Imports, thunks[0])) + +static struct _PeImage { + IMAGE_DOS_HEADER dos_header; + char __alignment1[FILE_PE_START - sizeof(IMAGE_DOS_HEADER)]; + IMAGE_NT_HEADERS32 nt_headers; + IMAGE_SECTION_HEADER sections[NUM_SECTIONS]; + char __alignment2[FILE_TEXT - FILE_PE_START - sizeof(IMAGE_NT_HEADERS32) - + NUM_SECTIONS * sizeof(IMAGE_SECTION_HEADER)]; + unsigned char text_section[FILE_IDATA-FILE_TEXT]; + struct Imports idata_section; + char __alignment3[FILE_TOTAL-FILE_IDATA-sizeof(struct Imports)]; +} bin = { + /* dos header */ + {IMAGE_DOS_SIGNATURE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {}, 0, 0, {}, FILE_PE_START}, + /* alignment before PE header */ + {}, + /* nt headers */ + {IMAGE_NT_SIGNATURE, + /* basic headers - 3 sections, no symbols, EXE file */ + {IMAGE_FILE_MACHINE_I386, NUM_SECTIONS, 0, 0, 0, sizeof(IMAGE_OPTIONAL_HEADER32), + IMAGE_FILE_32BIT_MACHINE | IMAGE_FILE_EXECUTABLE_IMAGE}, + /* optional header */ + {IMAGE_NT_OPTIONAL_HDR32_MAGIC, 4, 0, FILE_IDATA-FILE_TEXT, + FILE_TOTAL-FILE_IDATA + FILE_IDATA-FILE_TEXT, 0x400, + RVA_TEXT, RVA_TEXT, RVA_BSS, VA_START, 0x1000, 0x200, 4, 0, 1, 0, 4, 0, 0, + RVA_TOTAL, FILE_TEXT, 0, IMAGE_SUBSYSTEM_WINDOWS_GUI, 0, + 0x200000, 0x1000, 0x100000, 0x1000, 0, 0x10, + {{0, 0}, + {RVA_IDATA, sizeof(struct Imports)} + } + } + }, + /* sections */ + { + {".text", {0x100}, RVA_TEXT, FILE_IDATA-FILE_TEXT, FILE_TEXT, + 0, 0, 0, 0, IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ}, + {".bss", {0x400}, RVA_BSS, 0, 0, 0, 0, 0, 0, + IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE}, + {".idata", {sizeof(struct Imports)}, RVA_IDATA, FILE_TOTAL-FILE_IDATA, FILE_IDATA, 0, + 0, 0, 0, IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE} + }, + /* alignment before first section */ + {}, + /* .text section */ + { + 0x31, 0xC0, /* xor eax, eax */ + 0xFF, 0x25, EXIT_PROCESS&0xFF, (EXIT_PROCESS>>8)&0xFF, (EXIT_PROCESS>>16)&0xFF, + (EXIT_PROCESS>>24)&0xFF, /* jmp ExitProcess */ + 0 + }, + /* .idata section */ + { + { + {{RVA_IDATA + FIELD_OFFSET(struct Imports, original_thunks)}, 0, 0, + RVA_IDATA + FIELD_OFFSET(struct Imports, dllname), + RVA_IDATA + FIELD_OFFSET(struct Imports, thunks) + }, + {{0}, 0, 0, 0, 0} + }, + {{{RVA_IDATA+FIELD_OFFSET(struct Imports, ibn)}}, {{0}}}, + {{{RVA_IDATA+FIELD_OFFSET(struct Imports, ibn)}}, {{0}}}, + {0,"ExitProcess"}, + "KERNEL32.DLL" + }, + /* final alignment */ + {} +}; +#include <poppack.h> + +struct blob +{ + DWORD cb; + BYTE *pb; +}; + +struct expected_blob +{ + DWORD cb; + const void *pb; +}; + +struct update_accum +{ + DWORD cUpdates; + struct blob *updates; +}; + +struct expected_update_accum +{ + DWORD cUpdates; + const struct expected_blob *updates; + BOOL todo; +}; + +static BOOL WINAPI accumulating_stream_output(DIGEST_HANDLE handle, BYTE *pb, + DWORD cb) +{ + struct update_accum *accum = (struct update_accum *)handle; + BOOL ret = FALSE; + + if (accum->cUpdates) + accum->updates = HeapReAlloc(GetProcessHeap(), 0, accum->updates, + (accum->cUpdates + 1) * sizeof(struct blob)); + else + accum->updates = HeapAlloc(GetProcessHeap(), 0, sizeof(struct blob)); + if (accum->updates) + { + struct blob *blob = &accum->updates[accum->cUpdates]; + + blob->pb = HeapAlloc(GetProcessHeap(), 0, cb); + if (blob->pb) + { + memcpy(blob->pb, pb, cb); + blob->cb = cb; + ret = TRUE; + } + accum->cUpdates++; + } + return ret; +} + +static void check_updates(LPCSTR header, const struct expected_update_accum *expected, + const struct update_accum *got) +{ + DWORD i; + + if (expected->todo) + todo_wine ok(expected->cUpdates == got->cUpdates, "%s: expected %d updates, got %d\n", + header, expected->cUpdates, got->cUpdates); + else + ok(expected->cUpdates == got->cUpdates, "%s: expected %d updates, got %d\n", + header, expected->cUpdates, got->cUpdates); + for (i = 0; i < min(expected->cUpdates, got->cUpdates); i++) + { + ok(expected->updates[i].cb == got->updates[i].cb, "%s, update %d: expected %d bytes, got %d\n", + header, i, expected->updates[i].cb, got->updates[i].cb); + if (expected->updates[i].cb && expected->updates[i].cb == got->updates[i].cb) + ok(!memcmp(expected->updates[i].pb, got->updates[i].pb, got->updates[i].cb), + "%s, update %d: unexpected value\n", header, i); + } +} + +/* Frees the updates stored in accum */ +static void free_updates(struct update_accum *accum) +{ + DWORD i; + + for (i = 0; i < accum->cUpdates; i++) + HeapFree(GetProcessHeap(), 0, accum->updates[i].pb); + HeapFree(GetProcessHeap(), 0, accum->updates); + accum->updates = NULL; + accum->cUpdates = 0; +} + +static const struct expected_blob b1[] = { + {FILE_PE_START, &bin}, + /* with zeroed Checksum/SizeOfInitializedData/SizeOfImage fields */ + {sizeof(bin.nt_headers), &bin.nt_headers}, + {sizeof(bin.sections), &bin.sections}, + {FILE_IDATA-FILE_TEXT, &bin.text_section}, + {sizeof(bin.idata_section.descriptors[0].u.OriginalFirstThunk), + &bin.idata_section.descriptors[0].u.OriginalFirstThunk}, + {FIELD_OFFSET(struct Imports, thunks)-FIELD_OFFSET(struct Imports, descriptors[0].Name), + &bin.idata_section.descriptors[0].Name}, + {FILE_TOTAL-FILE_IDATA-FIELD_OFFSET(struct Imports, ibn), + &bin.idata_section.ibn} +}; +static const struct expected_update_accum a1 = { sizeof(b1) / sizeof(b1[0]), b1, TRUE }; + +static const struct expected_blob b2[] = { + {FILE_PE_START, &bin}, + /* with zeroed Checksum/SizeOfInitializedData/SizeOfImage fields */ + {sizeof(bin.nt_headers), &bin.nt_headers}, + {sizeof(bin.sections), &bin.sections}, + {FILE_IDATA-FILE_TEXT, &bin.text_section}, + {FILE_TOTAL-FILE_IDATA, &bin.idata_section} +}; +static const struct expected_update_accum a2 = { sizeof(b2) / sizeof(b2[0]), b2, FALSE }; + +/* Creates a test file and returns a handle to it. The file's path is returned + * in temp_file, which must be at least MAX_PATH characters in length. + */ +static HANDLE create_temp_file(char *temp_file) +{ + HANDLE file = INVALID_HANDLE_VALUE; + char temp_path[MAX_PATH]; + + if (GetTempPathA(sizeof(temp_path), temp_path)) + { + if (GetTempFileNameA(temp_path, "img", 0, temp_file)) + file = CreateFileA(temp_file, GENERIC_READ | GENERIC_WRITE, 0, NULL, + CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + } + return file; +} + +static void update_checksum(void) +{ + WORD const * ptr; + DWORD size; + DWORD sum = 0; + + bin.nt_headers.OptionalHeader.CheckSum = 0; + + for(ptr = (WORD const *)&bin, size = (sizeof(bin)+1)/sizeof(WORD); size > 0; ptr++, size--) + { + sum += *ptr; + if (HIWORD(sum) != 0) + { + sum = LOWORD(sum) + HIWORD(sum); + } + } + sum = (WORD)(LOWORD(sum) + HIWORD(sum)); + sum += sizeof(bin); + + bin.nt_headers.OptionalHeader.CheckSum = sum; +} + +static void test_get_digest_stream(void) +{ + BOOL ret; + HANDLE file; + char temp_file[MAX_PATH]; + DWORD count; + struct update_accum accum = { 0, NULL }; + + SetLastError(0xdeadbeef); + ret = pImageGetDigestStream(NULL, 0, NULL, NULL); + ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, + "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); + file = create_temp_file(temp_file); + if (file == INVALID_HANDLE_VALUE) + { + skip("couldn't create temp file\n"); + return; + } + SetLastError(0xdeadbeef); + ret = pImageGetDigestStream(file, 0, NULL, NULL); + ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, + "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); + SetLastError(0xdeadbeef); + ret = pImageGetDigestStream(NULL, 0, accumulating_stream_output, &accum); + ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, + "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); + /* Even with "valid" parameters, it fails with an empty file */ + SetLastError(0xdeadbeef); + ret = pImageGetDigestStream(file, 0, accumulating_stream_output, &accum); + ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, + "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); + /* Finally, with a valid executable in the file, it succeeds. Note that + * the file pointer need not be positioned at the beginning. + */ + update_checksum(); + WriteFile(file, &bin, sizeof(bin), &count, NULL); + FlushFileBuffers(file); + + /* zero out some fields ImageGetDigestStream would zero out */ + bin.nt_headers.OptionalHeader.CheckSum = 0; + bin.nt_headers.OptionalHeader.SizeOfInitializedData = 0; + bin.nt_headers.OptionalHeader.SizeOfImage = 0; + + ret = pImageGetDigestStream(file, 0, accumulating_stream_output, &accum); + ok(ret, "ImageGetDigestStream failed: %d\n", GetLastError()); + check_updates("flags = 0", &a1, &accum); + free_updates(&accum); + ret = pImageGetDigestStream(file, CERT_PE_IMAGE_DIGEST_ALL_IMPORT_INFO, + accumulating_stream_output, &accum); + ok(ret, "ImageGetDigestStream failed: %d\n", GetLastError()); + check_updates("flags = CERT_PE_IMAGE_DIGEST_ALL_IMPORT_INFO", &a2, &accum); + free_updates(&accum); + CloseHandle(file); + DeleteFileA(temp_file); +} + +START_TEST(image) +{ + hImageHlp = LoadLibraryA("imagehlp.dll"); + + if (!hImageHlp) + { + win_skip("ImageHlp unavailable\n"); + return; + } + + pImageGetDigestStream = (void *) GetProcAddress(hImageHlp, "ImageGetDigestStream"); + + if (!pImageGetDigestStream) + { + win_skip("ImageGetDigestStream function is not available\n"); + } else + { + test_get_digest_stream(); + } + + FreeLibrary(hImageHlp); +} Propchange: trunk/rostests/winetests/imagehlp/image.c ------------------------------------------------------------------------------ svn:eol-style = native Added: trunk/rostests/winetests/imagehlp/imagehlp.rbuild URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/winetests/imagehlp/imageh…
============================================================================== --- trunk/rostests/winetests/imagehlp/imagehlp.rbuild (added) +++ trunk/rostests/winetests/imagehlp/imagehlp.rbuild [iso-8859-1] Sun Feb 27 18:30:50 2011 @@ -1,0 +1,16 @@ +<?xml version="1.0"?> +<!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd"> +<group> +<module name="imagehlp_winetest" type="win32cui" installbase="bin" installname="imagehlp_winetest.exe" allowwarnings="true"> + <include base="imagehlp_winetest">.</include> + <define name="__ROS_LONG64__" /> + <file>image.c</file> + <file>integrity.c</file> + <file>testlist.c</file> + <library>wine</library> + <library>user32</library> + <library>ole32</library> + <library>oleaut32</library> + <library>ntdll</library> +</module> +</group> Propchange: trunk/rostests/winetests/imagehlp/imagehlp.rbuild ------------------------------------------------------------------------------ svn:eol-style = native Added: trunk/rostests/winetests/imagehlp/integrity.c URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/winetests/imagehlp/integr…
============================================================================== --- trunk/rostests/winetests/imagehlp/integrity.c (added) +++ trunk/rostests/winetests/imagehlp/integrity.c [iso-8859-1] Sun Feb 27 18:30:50 2011 @@ -1,0 +1,294 @@ +/* + * Test suite for imagehlp integrity functions + * + * Copyright 2009 Owen Rudge for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#define COBJMACROS +#include "wine/test.h" +#include "windef.h" +#include "winbase.h" +#include "winuser.h" +#include "winerror.h" +#include "winnt.h" +#include "imagehlp.h" + +static HMODULE hImageHlp; +static char test_dll_path[MAX_PATH]; + +static BOOL (WINAPI *pImageAddCertificate)(HANDLE, LPWIN_CERTIFICATE, PDWORD); +static BOOL (WINAPI *pImageEnumerateCertificates)(HANDLE, WORD, PDWORD, PDWORD, DWORD); +static BOOL (WINAPI *pImageGetCertificateData)(HANDLE, DWORD, LPWIN_CERTIFICATE, PDWORD); +static BOOL (WINAPI *pImageGetCertificateHeader)(HANDLE, DWORD, LPWIN_CERTIFICATE); +static BOOL (WINAPI *pImageRemoveCertificate)(HANDLE, DWORD); + +static char test_cert_data[] = +{0x30,0x82,0x02,0xE1,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x02 +,0xA0,0x82,0x02,0xD2,0x30,0x82,0x02,0xCE,0x02,0x01,0x01,0x31,0x00,0x30,0x0B +,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x01,0xA0,0x82,0x02,0xB4 +,0x30,0x82,0x02,0xB0,0x30,0x82,0x02,0x19,0xA0,0x03,0x02,0x01,0x02,0x02,0x09 +,0x00,0xE2,0x59,0x17,0xA5,0x87,0x0F,0x88,0x89,0x30,0x0D,0x06,0x09,0x2A,0x86 +,0x48,0x86,0xF7,0x0D,0x01,0x01,0x05,0x05,0x00,0x30,0x45,0x31,0x0B,0x30,0x09 +,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x41,0x55,0x31,0x13,0x30,0x11,0x06,0x03 +,0x55,0x04,0x08,0x13,0x0A,0x53,0x6F,0x6D,0x65,0x2D,0x53,0x74,0x61,0x74,0x65 +,0x31,0x21,0x30,0x1F,0x06,0x03,0x55,0x04,0x0A,0x13,0x18,0x49,0x6E,0x74,0x65 +,0x72,0x6E,0x65,0x74,0x20,0x57,0x69,0x64,0x67,0x69,0x74,0x73,0x20,0x50,0x74 +,0x79,0x20,0x4C,0x74,0x64,0x30,0x1E,0x17,0x0D,0x30,0x39,0x31,0x31,0x32,0x30 +,0x31,0x37,0x33,0x38,0x31,0x32,0x5A,0x17,0x0D,0x31,0x30,0x31,0x31,0x32,0x30 +,0x31,0x37,0x33,0x38,0x31,0x32,0x5A,0x30,0x45,0x31,0x0B,0x30,0x09,0x06,0x03 +,0x55,0x04,0x06,0x13,0x02,0x41,0x55,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04 +,0x08,0x13,0x0A,0x53,0x6F,0x6D,0x65,0x2D,0x53,0x74,0x61,0x74,0x65,0x31,0x21 +,0x30,0x1F,0x06,0x03,0x55,0x04,0x0A,0x13,0x18,0x49,0x6E,0x74,0x65,0x72,0x6E +,0x65,0x74,0x20,0x57,0x69,0x64,0x67,0x69,0x74,0x73,0x20,0x50,0x74,0x79,0x20 +,0x4C,0x74,0x64,0x30,0x81,0x9F,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7 +,0x0D,0x01,0x01,0x01,0x05,0x00,0x03,0x81,0x8D,0x00,0x30,0x81,0x89,0x02,0x81 +,0x81,0x00,0x9B,0xC1,0x5E,0x28,0x70,0x32,0x81,0xEF,0x41,0x5C,0xCA,0x29,0x4A +,0xB0,0x12,0xF7,0xAE,0x1E,0x30,0x93,0x14,0x3E,0x54,0x7C,0xC3,0x60,0x8C,0xB2 +,0x2F,0xC4,0x1F,0x20,0xEE,0x76,0xAC,0x83,0xD9,0xD4,0xC0,0x3C,0x78,0x6B,0xAA +,0xA2,0x35,0x08,0x72,0x4A,0x5F,0xAE,0xD6,0x7D,0x5A,0xD8,0x27,0xEC,0xE0,0x24 +,0xBE,0xBE,0x62,0x86,0xF9,0x83,0x66,0x20,0xBC,0xF6,0x4B,0xC8,0x2D,0x1B,0x4C +,0x5C,0xFA,0x0C,0x42,0x9F,0x57,0x49,0xDC,0xB9,0xC7,0x88,0x53,0xFA,0x26,0x21 +,0xC3,0xAB,0x4D,0x93,0x83,0x48,0x88,0xF1,0x14,0xB8,0x64,0x03,0x46,0x58,0x35 +,0xAC,0xD2,0xD2,0x9C,0xD4,0x6F,0xA4,0xE4,0x88,0x83,0x1C,0xD8,0x98,0xEE,0x2C +,0xA3,0xEC,0x0C,0x4B,0xFB,0x1D,0x6E,0xBE,0xD9,0x77,0x02,0x03,0x01,0x00,0x01 +,0xA3,0x81,0xA7,0x30,0x81,0xA4,0x30,0x1D,0x06,0x03,0x55,0x1D,0x0E,0x04,0x16 +,0x04,0x14,0x3F,0xB3,0xC8,0x15,0x12,0xC7,0xD8,0xC0,0x13,0x3D,0xBE,0xF1,0x2F +,0x5A,0xB3,0x51,0x59,0x79,0x89,0xF8,0x30,0x75,0x06,0x03,0x55,0x1D,0x23,0x04 +,0x6E,0x30,0x6C,0x80,0x14,0x3F,0xB3,0xC8,0x15,0x12,0xC7,0xD8,0xC0,0x13,0x3D +,0xBE,0xF1,0x2F,0x5A,0xB3,0x51,0x59,0x79,0x89,0xF8,0xA1,0x49,0xA4,0x47,0x30 +,0x45,0x31,0x0B,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x41,0x55,0x31 +,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x08,0x13,0x0A,0x53,0x6F,0x6D,0x65,0x2D +,0x53,0x74,0x61,0x74,0x65,0x31,0x21,0x30,0x1F,0x06,0x03,0x55,0x04,0x0A,0x13 +,0x18,0x49,0x6E,0x74,0x65,0x72,0x6E,0x65,0x74,0x20,0x57,0x69,0x64,0x67,0x69 +,0x74,0x73,0x20,0x50,0x74,0x79,0x20,0x4C,0x74,0x64,0x82,0x09,0x00,0xE2,0x59 +,0x17,0xA5,0x87,0x0F,0x88,0x89,0x30,0x0C,0x06,0x03,0x55,0x1D,0x13,0x04,0x05 +,0x30,0x03,0x01,0x01,0xFF,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D +,0x01,0x01,0x05,0x05,0x00,0x03,0x81,0x81,0x00,0x52,0x09,0xA5,0x81,0x63,0xEF +,0xF7,0x76,0x65,0x2B,0xA5,0x48,0xC1,0xC5,0xE0,0x73,0x60,0x9B,0x66,0x2E,0x21 +,0xCF,0xF2,0xBD,0xFF,0x81,0xC4,0x99,0x39,0xD0,0x5D,0x1B,0x12,0xFD,0xAE,0x30 +,0x5D,0x9C,0x1A,0xD4,0x76,0x8A,0x25,0x10,0x0A,0x7E,0x5D,0x78,0xB5,0x94,0xD8 +,0x97,0xBD,0x9A,0x5A,0xD6,0x23,0xCA,0x5C,0x46,0x8C,0xC7,0x30,0x45,0xB4,0x77 +,0x44,0x6F,0x16,0xDD,0xC6,0x58,0xFE,0x16,0x15,0xAD,0xB8,0x58,0x49,0x9A,0xFE +,0x6B,0x87,0x78,0xEE,0x13,0xFF,0x29,0x26,0x8E,0x13,0x83,0x0D,0x18,0xCA,0x9F +,0xA9,0x3E,0x6E,0x3C,0xA6,0x50,0x4A,0x04,0x71,0x9F,0x2E,0xCF,0x25,0xA6,0x03 +,0x46,0xCA,0xEB,0xEA,0x67,0x89,0x49,0x7C,0x43,0xA2,0x52,0xD9,0x41,0xCC,0x65 +,0xED,0x2D,0xA1,0x00,0x31,0x00}; + +static char test_cert_data_2[] = {0xDE,0xAD,0xBE,0xEF,0x01,0x02,0x03}; + +static BOOL copy_dll_file(void) +{ + char sys_dir[MAX_PATH+15]; + char temp_path[MAX_PATH]; + + if (GetSystemDirectoryA(sys_dir, MAX_PATH) == 0) + { + skip("Failed to get system directory. Skipping certificate/PE image tests.\n"); + return FALSE; + } + + if (sys_dir[lstrlenA(sys_dir) - 1] != '\\') + lstrcatA(sys_dir, "\\"); + + lstrcatA(sys_dir, "imagehlp.dll"); + + /* Copy DLL to a temp file */ + GetTempPath(MAX_PATH, temp_path); + GetTempFileName(temp_path, "img", 0, test_dll_path); + + if (CopyFile(sys_dir, test_dll_path, FALSE) == 0) + { + skip("Unable to create copy of imagehlp.dll for tests.\n"); + return FALSE; + } + + return TRUE; +} + +static DWORD get_file_size(void) +{ + HANDLE file; + DWORD filesize = 0; + + file = CreateFileA(test_dll_path, GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (file == INVALID_HANDLE_VALUE) + return 0; + + filesize = GetFileSize(file, NULL); + CloseHandle(file); + + return filesize; +} + +static void test_add_certificate(char *cert_data, int len) +{ + HANDLE hFile; + LPWIN_CERTIFICATE cert; + DWORD cert_len; + DWORD index; + + hFile = CreateFileA(test_dll_path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + skip("Unable to open %s, skipping test\n", test_dll_path); + return; + } + + cert_len = sizeof(WIN_CERTIFICATE) + len; + cert = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cert_len); + + if (!cert) + { + skip("Unable to allocate memory, skipping test\n"); + CloseHandle(hFile); + return; + } + + cert->dwLength = cert_len; + cert->wRevision = WIN_CERT_REVISION_1_0; + cert->wCertificateType = WIN_CERT_TYPE_PKCS_SIGNED_DATA; + CopyMemory(cert->bCertificate, cert_data, len); + + ok(pImageAddCertificate(hFile, cert, &index), "Unable to add certificate to image, error %x\n", GetLastError()); + + HeapFree(GetProcessHeap(), 0, cert); + CloseHandle(hFile); +} + +static void test_get_certificate(char *cert_data, int index) +{ + HANDLE hFile; + LPWIN_CERTIFICATE cert; + DWORD cert_len = 0; + DWORD err, ret; + + hFile = CreateFileA(test_dll_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + skip("Unable to open %s, skipping test\n", test_dll_path); + return; + } + + ret = pImageGetCertificateData(hFile, index, NULL, &cert_len); + err = GetLastError(); + + ok ((ret == FALSE) && (err == ERROR_INSUFFICIENT_BUFFER), "ImageGetCertificateData gave unexpected result; ret=%d / err=%x\n", ret, err); + + cert = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cert_len); + + if (!cert) + { + skip("Unable to allocate memory, skipping test\n"); + CloseHandle(hFile); + return; + } + + ok(ret = pImageGetCertificateData(hFile, index, cert, &cert_len), "Unable to retrieve certificate; err=%x\n", GetLastError()); + ok(memcmp(cert->bCertificate, cert_data, cert_len - sizeof(WIN_CERTIFICATE)) == 0, "Certificate retrieved did not match original\n"); + + HeapFree(GetProcessHeap(), 0, cert); + CloseHandle(hFile); +} + +static void test_remove_certificate(int index) +{ + DWORD orig_count = 0, count = 0; + HANDLE hFile; + + hFile = CreateFileA(test_dll_path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + skip("Unable to open %s, skipping test\n", test_dll_path); + return; + } + + ok (pImageEnumerateCertificates(hFile, CERT_SECTION_TYPE_ANY, &orig_count, NULL, 0), "Unable to enumerate certificates in file; err=%x\n", GetLastError()); + + ok (pImageRemoveCertificate(hFile, index), "Unable to remove certificate from file; err=%x\n", GetLastError()); + + /* Test to see if the certificate has actually been removed */ + pImageEnumerateCertificates(hFile, CERT_SECTION_TYPE_ANY, &count, NULL, 0); + ok (count == orig_count - 1, "Certificate count mismatch; orig=%d new=%d\n", orig_count, count); + + CloseHandle(hFile); +} + +START_TEST(integrity) +{ + DWORD file_size, file_size_orig; + + hImageHlp = LoadLibraryA("imagehlp.dll"); + + if (!hImageHlp) + { + win_skip("ImageHlp unavailable\n"); + return; + } + + if (!copy_dll_file()) + { + FreeLibrary(hImageHlp); + return; + } + + file_size_orig = get_file_size(); + /* + * Align file_size_orig to an 8-byte boundary. This avoids tests failures where + * the original dll is not correctly aligned (but when written to it will be). + */ + if (file_size_orig % 8 != 0) + { + skip("We need to align to an 8-byte boundary\n"); + file_size_orig = (file_size_orig + 7) & ~7; + } + + pImageAddCertificate = (void *) GetProcAddress(hImageHlp, "ImageAddCertificate"); + pImageEnumerateCertificates = (void *) GetProcAddress(hImageHlp, "ImageEnumerateCertificates"); + pImageGetCertificateData = (void *) GetProcAddress(hImageHlp, "ImageGetCertificateData"); + pImageGetCertificateHeader = (void *) GetProcAddress(hImageHlp, "ImageGetCertificateHeader"); + pImageRemoveCertificate = (void *) GetProcAddress(hImageHlp, "ImageRemoveCertificate"); + + test_add_certificate(test_cert_data, sizeof(test_cert_data)); + test_get_certificate(test_cert_data, 0); + test_remove_certificate(0); + + file_size = get_file_size(); + ok(file_size == file_size_orig, "File size different after add and remove (old: %d; new: %d)\n", file_size_orig, file_size); + + /* Try adding multiple certificates */ + test_add_certificate(test_cert_data, sizeof(test_cert_data)); + test_add_certificate(test_cert_data_2, sizeof(test_cert_data_2)); + + test_get_certificate(test_cert_data, 0); + test_get_certificate(test_cert_data_2, 1); + + /* Remove the first one and verify the second certificate is intact */ + test_remove_certificate(0); + test_get_certificate(test_cert_data_2, 0); + + test_remove_certificate(0); + + file_size = get_file_size(); + ok(file_size == file_size_orig, "File size different after add and remove (old: %d; new: %d)\n", file_size_orig, file_size); + + FreeLibrary(hImageHlp); + DeleteFile(test_dll_path); +} Propchange: trunk/rostests/winetests/imagehlp/integrity.c ------------------------------------------------------------------------------ svn:eol-style = native Added: trunk/rostests/winetests/imagehlp/testlist.c URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/winetests/imagehlp/testli…
============================================================================== --- trunk/rostests/winetests/imagehlp/testlist.c (added) +++ trunk/rostests/winetests/imagehlp/testlist.c [iso-8859-1] Sun Feb 27 18:30:50 2011 @@ -1,0 +1,17 @@ +/* Automatically generated file; DO NOT EDIT!! */ + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + +#define STANDALONE +#include "wine/test.h" + +extern void func_image(void); +extern void func_integrity(void); + +const struct test winetest_testlist[] = +{ + { "image", func_image }, + { "integrity", func_integrity }, + { 0, 0 } +}; Propchange: trunk/rostests/winetests/imagehlp/testlist.c ------------------------------------------------------------------------------ svn:eol-style = native
13 years, 9 months
1
0
0
0
[tkreuzer] 50921: [WIN32K] - mark surface as not selected in DC_vSelectSurface when its released from a DC NtGdiSelectBitmap: - Don't allow selecting a bitmap into a dc that is already selected! - ...
by tkreuzer@svn.reactos.org
Author: tkreuzer Date: Sun Feb 27 17:51:37 2011 New Revision: 50921 URL:
http://svn.reactos.org/svn/reactos?rev=50921&view=rev
Log: [WIN32K] - mark surface as not selected in DC_vSelectSurface when its released from a DC NtGdiSelectBitmap: - Don't allow selecting a bitmap into a dc that is already selected! - Use DC_vSelectSurface instead of manually selecting - set the DC size based on bitmap size Modified: trunk/reactos/subsystems/win32/win32k/eng/bitblt.c trunk/reactos/subsystems/win32/win32k/include/dc.h trunk/reactos/subsystems/win32/win32k/objects/dcobjs.c Modified: trunk/reactos/subsystems/win32/win32k/eng/bitblt.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/en…
============================================================================== --- trunk/reactos/subsystems/win32/win32k/eng/bitblt.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/win32k/eng/bitblt.c [iso-8859-1] Sun Feb 27 17:51:37 2011 @@ -541,8 +541,6 @@ BOOL bResult; RECTL rclClipped; RECTL rclSrc; -// INTENG_ENTER_LEAVE EnterLeaveSource; -// INTENG_ENTER_LEAVE EnterLeaveDest; PFN_DrvBitBlt pfnBitBlt; ASSERT(psoTrg); @@ -552,9 +550,9 @@ rclClipped = *prclTrg; RECTL_vMakeWellOrdered(&rclClipped); - /* Clip target rect against the bounds of the clipping region */ if (pco) { + /* Clip target rect against the bounds of the clipping region */ if (!RECTL_bIntersectRect(&rclClipped, &rclClipped, &pco->rclBounds)) { /* Nothing left */ Modified: trunk/reactos/subsystems/win32/win32k/include/dc.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/in…
============================================================================== --- trunk/reactos/subsystems/win32/win32k/include/dc.h [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/win32k/include/dc.h [iso-8859-1] Sun Feb 27 17:51:37 2011 @@ -213,7 +213,10 @@ { PSURFACE psurfOld = pdc->dclevel.pSurface; if (psurfOld) + { + psurfOld->hdc = NULL; SURFACE_ShareUnlockSurface(psurfOld); + } if (psurfNew) GDIOBJ_IncrementShareCount((POBJ)psurfNew); pdc->dclevel.pSurface = psurfNew; Modified: trunk/reactos/subsystems/win32/win32k/objects/dcobjs.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/ob…
============================================================================== --- trunk/reactos/subsystems/win32/win32k/objects/dcobjs.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/win32k/objects/dcobjs.c [iso-8859-1] Sun Feb 27 17:51:37 2011 @@ -257,9 +257,10 @@ PDC pdc; PDC_ATTR pdcattr; HBITMAP hbmpOld; - PSURFACE psurfNew, psurfOld; + PSURFACE psurfNew; HRGN hVisRgn; SIZEL sizlBitmap = {1, 1}; + HDC hdcOld; ASSERT_NOGDILOCKS(); /* Verify parameters */ @@ -280,8 +281,17 @@ return NULL; } - /* Save the old bitmap */ - psurfOld = pdc->dclevel.pSurface; + /* Check if there was a bitmap selected before */ + if (pdc->dclevel.pSurface) + { + /* Return its handle */ + hbmpOld = pdc->dclevel.pSurface->BaseObject.hHmgr; + } + else + { + /* Return default bitmap */ + hbmpOld = StockObjects[DEFAULT_BITMAP]; + } /* Check if the default bitmap was passed */ if (hbmp == StockObjects[DEFAULT_BITMAP]) @@ -300,16 +310,17 @@ DC_UnlockDc(pdc); return NULL; } -#if 0 // FIXME: bug bug, causes problems + /* Set the bitmp's hdc */ - if (InterlockedCompareExchangePointer((PVOID*)&psurfNew->hdc, hdc, 0)) + hdcOld = InterlockedCompareExchangePointer((PVOID*)&psurfNew->hdc, hdc, 0); + if (hdcOld != NULL && hdcOld != hdc) { /* The bitmap is already selected, fail */ SURFACE_ShareUnlockSurface(psurfNew); DC_UnlockDc(pdc); return NULL; } -#endif + /* Get the bitmap size */ sizlBitmap = psurfNew->SurfObj.sizlBitmap; @@ -325,25 +336,14 @@ } } - /* Select the new bitmap */ - pdc->dclevel.pSurface = psurfNew; - - /* Check if there was a bitmap selected before */ - if (psurfOld) - { - hbmpOld = psurfOld->BaseObject.hHmgr; - - /* Reset hdc of old bitmap, this surface isn't selected anymore */ - psurfOld->hdc = NULL; - - /* Release the old bitmap */ - SURFACE_ShareUnlockSurface(psurfOld); - } - else - { - /* Return default bitmap */ - hbmpOld = StockObjects[DEFAULT_BITMAP]; - } + /* Select the new surface, release the old */ + DC_vSelectSurface(pdc, psurfNew); + + /* Set the new size */ + pdc->dclevel.sizl = sizlBitmap; + + /* Release one reference we added */ + SURFACE_ShareUnlockSurface(psurfNew); /* Mark the dc brushes invalid */ pdcattr->ulDirty_ |= DIRTY_FILL | DIRTY_LINE;
13 years, 10 months
1
0
0
0
← Newer
1
2
3
4
5
...
36
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Results per page:
10
25
50
100
200