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 2012
----- 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
22 participants
577 discussions
Start a n
N
ew thread
[gadamopoulos] 55798: [win32k] - Properly destroy the THREADINFO if we fail to create it. We don't leak the THREADINFO no in case of failure. It should also fix random assertion failure when runnin...
by gadamopoulos@svn.reactos.org
Author: gadamopoulos Date: Tue Feb 21 23:07:30 2012 New Revision: 55798 URL:
http://svn.reactos.org/svn/reactos?rev=55798&view=rev
Log: [win32k] - Properly destroy the THREADINFO if we fail to create it. We don't leak the THREADINFO no in case of failure. It should also fix random assertion failure when running user32:desktop tests Modified: trunk/reactos/subsystems/win32/win32k/main/dllmain.c Modified: trunk/reactos/subsystems/win32/win32k/main/dllmain.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/ma…
============================================================================== --- trunk/reactos/subsystems/win32/win32k/main/dllmain.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/win32k/main/dllmain.c [iso-8859-1] Tue Feb 21 23:07:30 2012 @@ -16,6 +16,7 @@ PGDI_HANDLE_TABLE NTAPI GDIOBJ_iAllocHandleTable(OUT PSECTION_OBJECT *SectionObject); BOOL NTAPI GDI_CleanupForProcess (struct _EPROCESS *Process); +NTSTATUS NTAPI UserDestroyThreadInfo(struct _ETHREAD *Thread); HANDLE GlobalUserHeap = NULL; PSECTION_OBJECT GlobalUserHeapSection = NULL; @@ -56,7 +57,6 @@ ASSERT(Process->Peb); - DPRINT("Enter Win32kProcessCallback\n"); UserEnterExclusive(); if (Create) @@ -74,7 +74,10 @@ USERTAG_PROCESSINFO); if (ppiCurrent == NULL) + { + ERR_CH(UserProcess, "Failed to allocate ppi for PID:%d\n", Process->UniqueProcessId); RETURN( STATUS_NO_MEMORY); + } RtlZeroMemory(ppiCurrent, sizeof(PROCESSINFO)); @@ -84,7 +87,7 @@ DbgInitDebugChannels(); #endif - TRACE_PPI(ppiCurrent, UserProcess,"Allocated ppi for PID:%d\n", Process->UniqueProcessId); + TRACE_CH(UserProcess,"Allocated ppi 0x%x for PID:%d\n", ppiCurrent, Process->UniqueProcessId); /* map the global heap into the process */ Offset.QuadPart = 0; @@ -100,7 +103,7 @@ PAGE_EXECUTE_READ); /* would prefer PAGE_READONLY, but thanks to RTL heaps... */ if (!NT_SUCCESS(Status)) { - DPRINT1("Failed to map the global heap! 0x%x\n", Status); + TRACE_CH(UserProcess,"Failed to map the global heap! 0x%x\n", Status); RETURN(Status); } ppiCurrent->HeapMappings.Next = NULL; @@ -155,7 +158,7 @@ ASSERT(ppiCurrent); - TRACE_CH(UserProcess, "Destroying W32 process PID:%d at IRQ level: %lu\n", Process->UniqueProcessId, KeGetCurrentIrql()); + TRACE_CH(UserProcess, "Destroying ppi 0x%x\n", ppiCurrent); ppiCurrent->W32PF_flags |= W32PF_TERMINATED; if (ppiScrnSaver == ppiCurrent) @@ -200,6 +203,8 @@ GdiPoolDestroy(ppiCurrent->pPoolBrushAttr); GdiPoolDestroy(ppiCurrent->pPoolRgnAttr); + TRACE_CH(UserProcess,"Freeing ppi 0x%x\n", ppiCurrent); + /* Ftee the PROCESSINFO */ PsSetProcessWin32Process(Process, NULL); ExFreePoolWithTag(ppiCurrent, USERTAG_PROCESSINFO); @@ -209,186 +214,193 @@ CLEANUP: UserLeave(); - DPRINT("Leave Win32kProcessCallback, ret=%i\n",_ret_); END_CLEANUP; } - -NTSTATUS -APIENTRY -Win32kThreadCallback(struct _ETHREAD *Thread, - PSW32THREADCALLOUTTYPE Type) +NTSTATUS NTAPI +UserCreateThreadInfo(struct _ETHREAD *Thread) { struct _EPROCESS *Process; + PCLIENTINFO pci; PTHREADINFO ptiCurrent; int i; - NTSTATUS Status; + NTSTATUS Status = STATUS_SUCCESS; PTEB pTeb; - DPRINT("Enter Win32kThreadCallback\n"); - UserEnterExclusive(); - Process = Thread->ThreadsProcess; + pTeb = NtCurrentTeb(); ASSERT(pTeb); - if (Type == PsW32ThreadCalloutInitialize) + ptiCurrent = ExAllocatePoolWithTag(NonPagedPool, + sizeof(THREADINFO), + USERTAG_THREADINFO); + if (ptiCurrent == NULL) + { + ERR_CH(UserThread, "Failed to allocate pti for TID %d\n", Thread->Cid.UniqueThread); + return STATUS_NO_MEMORY; + } + + RtlZeroMemory(ptiCurrent, sizeof(THREADINFO)); + + PsSetThreadWin32Thread(Thread, ptiCurrent); + pTeb->Win32ThreadInfo = ptiCurrent; + ptiCurrent->pClientInfo = (PCLIENTINFO)pTeb->Win32ClientInfo; + + TRACE_CH(UserThread, "Allocated pti 0x%x for TID %d\n", ptiCurrent, Thread->Cid.UniqueThread); + + /* Initialize the THREADINFO */ + InitializeListHead(&ptiCurrent->WindowListHead); + InitializeListHead(&ptiCurrent->W32CallbackListHead); + InitializeListHead(&ptiCurrent->PtiLink); + for (i = 0; i < NB_HOOKS; i++) + { + InitializeListHead(&ptiCurrent->aphkStart[i]); + } + ptiCurrent->pEThread = Thread; + ptiCurrent->ppi = PsGetCurrentProcessWin32Process(); + ptiCurrent->ptiSibling = ptiCurrent->ppi->ptiList; + ptiCurrent->ppi->ptiList = ptiCurrent; + ptiCurrent->ppi->cThreads++; + ptiCurrent->MessageQueue = MsqCreateMessageQueue(Thread); + if(ptiCurrent->MessageQueue == NULL) + { + ERR_CH(UserThread,"Failed to allocate message loop\n"); + Status = STATUS_NO_MEMORY; + goto error; + } + ptiCurrent->KeyboardLayout = W32kGetDefaultKeyLayout(); + if (ptiCurrent->KeyboardLayout) + UserReferenceObject(ptiCurrent->KeyboardLayout); + ptiCurrent->TIF_flags &= ~TIF_INCLEANUP; + + /* Initialize the CLIENTINFO */ + pci = (PCLIENTINFO)pTeb->Win32ClientInfo; + RtlZeroMemory(pci, sizeof(CLIENTINFO)); + pci->ppi = ptiCurrent->ppi; + pci->fsHooks = ptiCurrent->fsHooks; + pci->dwTIFlags = ptiCurrent->TIF_flags; + if (ptiCurrent->KeyboardLayout) + pci->hKL = ptiCurrent->KeyboardLayout->hkl; + + /* Assign a default window station and desktop to the process */ + /* Do not try to open a desktop or window station before winlogon initializes */ + if(ptiCurrent->ppi->hdeskStartup == NULL && LogonProcess != NULL) { HWINSTA hWinSta = NULL; - PCLIENTINFO pci; HDESK hDesk = NULL; UNICODE_STRING DesktopPath; PDESKTOP pdesk; - PRTL_USER_PROCESS_PARAMETERS ProcessParams = Process->Peb->ProcessParameters; - - ASSERT(PsGetThreadWin32Thread(Thread)==NULL); - - ptiCurrent = ExAllocatePoolWithTag(NonPagedPool, - sizeof(THREADINFO), - USERTAG_THREADINFO); - if (ptiCurrent == NULL) - { - Status = STATUS_NO_MEMORY; - goto leave; - } - - RtlZeroMemory(ptiCurrent, sizeof(THREADINFO)); - - PsSetThreadWin32Thread(Thread, ptiCurrent); - pTeb->Win32ThreadInfo = ptiCurrent; - ptiCurrent->pClientInfo = (PCLIENTINFO)pTeb->Win32ClientInfo; - - TRACE_CH(UserThread, "Creating W32 thread TID:%d at IRQ level: %lu\n", Thread->Cid.UniqueThread, KeGetCurrentIrql()); - - /* Initialize the THREADINFO */ - InitializeListHead(&ptiCurrent->WindowListHead); - InitializeListHead(&ptiCurrent->W32CallbackListHead); - InitializeListHead(&ptiCurrent->PtiLink); - for (i = 0; i < NB_HOOKS; i++) - { - InitializeListHead(&ptiCurrent->aphkStart[i]); - } - ptiCurrent->pEThread = Thread; - ptiCurrent->ppi = PsGetCurrentProcessWin32Process(); - ptiCurrent->ptiSibling = ptiCurrent->ppi->ptiList; - ptiCurrent->ppi->ptiList = ptiCurrent; - ptiCurrent->ppi->cThreads++; - ptiCurrent->MessageQueue = MsqCreateMessageQueue(Thread); - ptiCurrent->KeyboardLayout = W32kGetDefaultKeyLayout(); - if (ptiCurrent->KeyboardLayout) - UserReferenceObject(ptiCurrent->KeyboardLayout); - ptiCurrent->TIF_flags &= ~TIF_INCLEANUP; - - /* Initialize the CLIENTINFO */ - pci = (PCLIENTINFO)pTeb->Win32ClientInfo; - RtlZeroMemory(pci, sizeof(CLIENTINFO)); - pci->ppi = ptiCurrent->ppi; - pci->fsHooks = ptiCurrent->fsHooks; - pci->dwTIFlags = ptiCurrent->TIF_flags; - if (ptiCurrent->KeyboardLayout) - pci->hKL = ptiCurrent->KeyboardLayout->hkl; - - /* Assign a default window station and desktop to the process */ - /* Do not try to open a desktop or window station before winlogon initializes */ - if(ptiCurrent->ppi->hdeskStartup == NULL && LogonProcess != NULL) - { - /* - * inherit the thread desktop and process window station (if not yet inherited) from the process startup - * info structure. See documentation of CreateProcess() - */ + PRTL_USER_PROCESS_PARAMETERS ProcessParams; + + /* + * inherit the thread desktop and process window station (if not yet inherited) from the process startup + * info structure. See documentation of CreateProcess() + */ + ProcessParams = pTeb->ProcessEnvironmentBlock->ProcessParameters; + + Status = STATUS_UNSUCCESSFUL; + if(ProcessParams && ProcessParams->DesktopInfo.Length > 0) + { + Status = IntSafeCopyUnicodeStringTerminateNULL(&DesktopPath, &ProcessParams->DesktopInfo); + } + if(!NT_SUCCESS(Status)) + { + RtlInitUnicodeString(&DesktopPath, NULL); + } + + Status = IntParseDesktopPath(Process, + &DesktopPath, + &hWinSta, + &hDesk); + + if (DesktopPath.Buffer) + ExFreePoolWithTag(DesktopPath.Buffer, TAG_STRING); + + if(!NT_SUCCESS(Status)) + { + ERR_CH(UserThread, "Failed to assign default dekstop and winsta to process\n"); + goto error; + } + + if(!UserSetProcessWindowStation(hWinSta)) + { Status = STATUS_UNSUCCESSFUL; - if(ProcessParams && ProcessParams->DesktopInfo.Length > 0) - { - Status = IntSafeCopyUnicodeStringTerminateNULL(&DesktopPath, &ProcessParams->DesktopInfo); - } - if(!NT_SUCCESS(Status)) - { - RtlInitUnicodeString(&DesktopPath, NULL); - } - - Status = IntParseDesktopPath(Process, - &DesktopPath, - &hWinSta, - &hDesk); - - if (DesktopPath.Buffer) - ExFreePoolWithTag(DesktopPath.Buffer, TAG_STRING); - - if(!NT_SUCCESS(Status)) - { - ERR_CH(UserThread, "Failed to assign default dekstop and winsta to process\n"); - goto leave; - } - - if(!UserSetProcessWindowStation(hWinSta)) - { - Status = STATUS_UNSUCCESSFUL; - goto leave; - } - - /* Validate the new desktop. */ - Status = IntValidateDesktopHandle(hDesk, UserMode, 0, &pdesk); - if(!NT_SUCCESS(Status)) - { - goto leave; - } - - /* Store the parsed desktop as the initial desktop */ - ptiCurrent->ppi->hdeskStartup = hDesk; - ptiCurrent->ppi->rpdeskStartup = pdesk; - } - - if (ptiCurrent->ppi->hdeskStartup != NULL) - { - if (!IntSetThreadDesktop(ptiCurrent->ppi->hdeskStartup, FALSE)) - { - ERR_CH(UserThread,"Unable to set thread desktop\n"); - Status = STATUS_UNSUCCESSFUL; - goto leave; - } - } - } - else - { - PTHREADINFO *ppti; - PSINGLE_LIST_ENTRY psle; - PPROCESSINFO ppiCurrent; - - /* Get the Win32 Thread */ - ptiCurrent = PsGetThreadWin32Thread(Thread); - - ASSERT(ptiCurrent); - - TRACE_CH(UserThread,"Destroying W32 thread TID:%d at IRQ level: %lu\n", Thread->Cid.UniqueThread, KeGetCurrentIrql()); - - ppiCurrent = ptiCurrent->ppi; - ptiCurrent->TIF_flags |= TIF_INCLEANUP; - ptiCurrent->pClientInfo->dwTIFlags = ptiCurrent->TIF_flags; - - /* Find the THREADINFO in the PROCESSINFO's list */ - ppti = &ppiCurrent->ptiList; - while (*ppti != NULL && *ppti != ptiCurrent) - { - ppti = &((*ppti)->ptiSibling); - } - - /* we must have found it */ - ASSERT(*ppti == ptiCurrent); - - /* Remove it from the list */ - *ppti = ptiCurrent->ptiSibling; - - /* Decrement thread count and check if its 0 */ - ppiCurrent->cThreads--; - + ERR_CH(UserThread,"Failed to set initial process winsta\n"); + goto error; + } + + /* Validate the new desktop. */ + Status = IntValidateDesktopHandle(hDesk, UserMode, 0, &pdesk); + if(!NT_SUCCESS(Status)) + { + ERR_CH(UserThread,"Failed to validate initial desktop handle\n"); + goto error; + } + + /* Store the parsed desktop as the initial desktop */ + ptiCurrent->ppi->hdeskStartup = hDesk; + ptiCurrent->ppi->rpdeskStartup = pdesk; + } + + if (ptiCurrent->ppi->hdeskStartup != NULL) + { + if (!IntSetThreadDesktop(ptiCurrent->ppi->hdeskStartup, FALSE)) + { + ERR_CH(UserThread,"Failed to set thread desktop\n"); + Status = STATUS_UNSUCCESSFUL; + goto error; + } + } + + /* mark the thread as fully initialized */ + ptiCurrent->TIF_flags |= TIF_GUITHREADINITIALIZED; + ptiCurrent->pClientInfo->dwTIFlags = ptiCurrent->TIF_flags; + + return STATUS_SUCCESS; + +error: + UserDestroyThreadInfo(Thread); + return Status; +} + +NTSTATUS +NTAPI +UserDestroyThreadInfo(struct _ETHREAD *Thread) +{ + PTHREADINFO *ppti; + PSINGLE_LIST_ENTRY psle; + PPROCESSINFO ppiCurrent; + struct _EPROCESS *Process; + PTHREADINFO ptiCurrent; + + Process = Thread->ThreadsProcess; + + /* Get the Win32 Thread */ + ptiCurrent = PsGetThreadWin32Thread(Thread); + + ASSERT(ptiCurrent); + + TRACE_CH(UserThread,"Destroying pti 0x%x\n", ptiCurrent); + + ppiCurrent = ptiCurrent->ppi; + ptiCurrent->TIF_flags |= TIF_INCLEANUP; + ptiCurrent->pClientInfo->dwTIFlags = ptiCurrent->TIF_flags; + + + /* Decrement thread count and check if its 0 */ + ppiCurrent->cThreads--; + + if(ptiCurrent->TIF_flags & TIF_GUITHREADINITIALIZED) + { /* Do now some process cleanup that requires a valid win32 thread */ if(ptiCurrent->ppi->cThreads == 0) { /* Check if we have registered the user api hook */ if(ptiCurrent->ppi == ppiUahServer) { - /* Unregister the api hook without blocking */ + /* Unregister the api hook */ UserUnregisterUserApiHook(); } @@ -399,7 +411,7 @@ { DWORD ExitCode = PsGetProcessExitStatus(Process); - TRACE_PPI(ppiCurrent, UserProcess, "Shell process is exiting (%d)\n", ExitCode); + TRACE_CH(UserProcess, "Shell process is exiting (%d)\n", ExitCode); UserPostMessage(hwndSAS, WM_LOGONNOTIFY, @@ -414,18 +426,12 @@ DceFreeThreadDCE(ptiCurrent); HOOK_DestroyThreadHooks(Thread); EVENT_DestroyThreadEvents(Thread); - - /* Cleanup timers */ DestroyTimersForThread(ptiCurrent); KeSetEvent(ptiCurrent->MessageQueue->NewMessages, IO_NO_INCREMENT, FALSE); UnregisterThreadHotKeys(Thread); - co_DestroyThreadWindows(Thread); IntBlockInput(ptiCurrent, FALSE); - MsqDestroyMessageQueue(ptiCurrent->MessageQueue); IntCleanupThreadCallbacks(ptiCurrent); - if (ptiCurrent->KeyboardLayout) - UserDereferenceObject(ptiCurrent->KeyboardLayout); /* cleanup user object references stack */ psle = PopEntryList(&ptiCurrent->ReferencesList); @@ -437,20 +443,62 @@ psle = PopEntryList(&ptiCurrent->ReferencesList); } - - IntSetThreadDesktop(NULL, TRUE); - - - /* Free the THREADINFO */ - PsSetThreadWin32Thread(Thread, NULL); - ExFreePoolWithTag(ptiCurrent, USERTAG_THREADINFO); - } - - Status = STATUS_SUCCESS; - -leave: + } + + /* Free the message queue */ + if(ptiCurrent->MessageQueue) + MsqDestroyMessageQueue(ptiCurrent->MessageQueue); + + /* Find the THREADINFO in the PROCESSINFO's list */ + ppti = &ppiCurrent->ptiList; + while (*ppti != NULL && *ppti != ptiCurrent) + { + ppti = &((*ppti)->ptiSibling); + } + + /* we must have found it */ + ASSERT(*ppti == ptiCurrent); + + /* Remove it from the list */ + *ppti = ptiCurrent->ptiSibling; + + if (ptiCurrent->KeyboardLayout) + UserDereferenceObject(ptiCurrent->KeyboardLayout); + + IntSetThreadDesktop(NULL, TRUE); + + TRACE_CH(UserThread,"Freeing pti 0x%x\n", ptiCurrent); + + /* Free the THREADINFO */ + PsSetThreadWin32Thread(Thread, NULL); + ExFreePoolWithTag(ptiCurrent, USERTAG_THREADINFO); + + return STATUS_SUCCESS; +} + +NTSTATUS +APIENTRY +Win32kThreadCallback(struct _ETHREAD *Thread, + PSW32THREADCALLOUTTYPE Type) +{ + NTSTATUS Status; + + UserEnterExclusive(); + + ASSERT(NtCurrentTeb()); + + if (Type == PsW32ThreadCalloutInitialize) + { + ASSERT(PsGetThreadWin32Thread(Thread) == NULL); + Status = UserCreateThreadInfo(Thread); + } + else + { + ASSERT(PsGetThreadWin32Thread(Thread) != NULL); + Status = UserDestroyThreadInfo(Thread); + } + UserLeave(); - DPRINT("Leave Win32kThreadCallback, Status=0x%lx\n",Status); return Status; }
12 years, 10 months
1
0
0
0
[jgardou] 55797: [CRT] - C standard for free says "if pointer is NULL, no action is taken". - MSDN for HeapFree says "if pointer is NULL, behavior is undefined". Thanks to Thomas for teaching wine ...
by jgardou@svn.reactos.org
Author: jgardou Date: Tue Feb 21 22:08:24 2012 New Revision: 55797 URL:
http://svn.reactos.org/svn/reactos?rev=55797&view=rev
Log: [CRT] - C standard for free says "if pointer is NULL, no action is taken". - MSDN for HeapFree says "if pointer is NULL, behavior is undefined". Thanks to Thomas for teaching wine guys how to read. Modified: trunk/reactos/lib/sdk/crt/wine/heap.c Modified: trunk/reactos/lib/sdk/crt/wine/heap.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/wine/heap.c?re…
============================================================================== --- trunk/reactos/lib/sdk/crt/wine/heap.c [iso-8859-1] (original) +++ trunk/reactos/lib/sdk/crt/wine/heap.c [iso-8859-1] Tue Feb 21 22:08:24 2012 @@ -298,6 +298,7 @@ */ void CDECL free(void* ptr) { + if(ptr == NULL) return; HeapFree(GetProcessHeap(),0,ptr); }
12 years, 10 months
1
0
0
0
[jgardou] 55796: revert r55794, the problem is elsewhere
by jgardou@svn.reactos.org
Author: jgardou Date: Tue Feb 21 21:58:42 2012 New Revision: 55796 URL:
http://svn.reactos.org/svn/reactos?rev=55796&view=rev
Log: revert r55794, the problem is elsewhere Modified: trunk/reactos/lib/sdk/crt/stdio/file.c Modified: trunk/reactos/lib/sdk/crt/stdio/file.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/stdio/file.c?r…
============================================================================== --- trunk/reactos/lib/sdk/crt/stdio/file.c [iso-8859-1] (original) +++ trunk/reactos/lib/sdk/crt/stdio/file.c [iso-8859-1] Tue Feb 21 21:58:42 2012 @@ -963,10 +963,10 @@ fclose(&_iob[2]); for(i=0; i<sizeof(__pioinfo)/sizeof(__pioinfo[0]); i++) - if(__pioinfo[i]) free(__pioinfo[i]); + free(__pioinfo[i]); for(i=0; i<sizeof(fstream)/sizeof(fstream[0]); i++) - if(fstream[i]) free(fstream[i]); + free(fstream[i]); file_cs.DebugInfo->Spare[0] = 0; DeleteCriticalSection(&file_cs);
12 years, 10 months
1
0
0
0
[ion] 55795: [KERNEL32]: Lock/UnlockFile APIs should not allow console handles. Also remove superflous parameter check. [KERNEL32]: Lock/UnlockFile APIs should handle STATUS_PENDING/ERROR_IO_PENDIN...
by ion@svn.reactos.org
Author: ion Date: Tue Feb 21 21:38:08 2012 New Revision: 55795 URL:
http://svn.reactos.org/svn/reactos?rev=55795&view=rev
Log: [KERNEL32]: Lock/UnlockFile APIs should not allow console handles. Also remove superflous parameter check. [KERNEL32]: Lock/UnlockFile APIs should handle STATUS_PENDING/ERROR_IO_PENDING situations instead of always assuming the Nt functions return synchronously. [KERNEL32]: Other stylying changes + commenting/annotations. Modified: trunk/reactos/dll/win32/kernel32/client/file/lock.c Modified: trunk/reactos/dll/win32/kernel32/client/file/lock.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
============================================================================== --- trunk/reactos/dll/win32/kernel32/client/file/lock.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/kernel32/client/file/lock.c [iso-8859-1] Tue Feb 21 21:38:08 2012 @@ -9,14 +9,12 @@ * Created 01/11/98 */ -/* FIXME: the large integer manipulations in this file dont handle overflow */ /* INCLUDES ****************************************************************/ #include <k32.h> #define NDEBUG #include <debug.h> -DEBUG_CHANNEL(kernel32file); /* FUNCTIONS ****************************************************************/ @@ -25,165 +23,207 @@ */ BOOL WINAPI -LockFile(HANDLE hFile, - DWORD dwFileOffsetLow, - DWORD dwFileOffsetHigh, - DWORD nNumberOfBytesToLockLow, - DWORD nNumberOfBytesToLockHigh) -{ - DWORD dwReserved; +LockFile(IN HANDLE hFile, + IN DWORD dwFileOffsetLow, + IN DWORD dwFileOffsetHigh, + IN DWORD nNumberOfBytesToLockLow, + IN DWORD nNumberOfBytesToLockHigh) +{ + IO_STATUS_BLOCK IoStatusBlock; + NTSTATUS Status; + LARGE_INTEGER BytesToLock, Offset; + + /* Is this a console handle? */ + if (IsConsoleHandle(hFile)) + { + /* Can't "lock" a console! */ + BaseSetLastNTError(STATUS_INVALID_HANDLE); + return FALSE; + } + + /* Setup the parameters in NT style and call the native API */ + BytesToLock.u.LowPart = nNumberOfBytesToLockLow; + BytesToLock.u.HighPart = nNumberOfBytesToLockHigh; + Offset.u.LowPart = dwFileOffsetLow; + Offset.u.HighPart = dwFileOffsetHigh; + Status = NtLockFile(hFile, + NULL, + NULL, + NULL, + &IoStatusBlock, + &Offset, + &BytesToLock, + 0, + TRUE, + TRUE); + if (Status == STATUS_PENDING) + { + /* Wait for completion if needed */ + Status = NtWaitForSingleObject(hFile, FALSE, NULL); + if (NT_SUCCESS(Status)) Status = IoStatusBlock.Status; + } + + /* Check if we failed */ + if (!NT_SUCCESS(Status)) + { + /* Convert the error code and fail */ + BaseSetLastNTError(Status); + return FALSE; + } + + /* Success! */ + return TRUE; +} + +/* + * @implemented + */ +BOOL +WINAPI +LockFileEx(IN HANDLE hFile, + IN DWORD dwFlags, + IN DWORD dwReserved, + IN DWORD nNumberOfBytesToLockLow, + IN DWORD nNumberOfBytesToLockHigh, + IN LPOVERLAPPED lpOverlapped) +{ + LARGE_INTEGER BytesToLock, Offset; + NTSTATUS Status; + + /* Is this a console handle? */ + if (IsConsoleHandle(hFile)) + { + /* Can't "lock" a console! */ + BaseSetLastNTError(STATUS_INVALID_HANDLE); + return FALSE; + } + + /* This parameter should be zero */ + if (dwReserved) + { + /* Fail since it isn't */ + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + /* Set the initial status in the IO_STATUS_BLOCK to pending... */ + lpOverlapped->Internal = STATUS_PENDING; + + /* Convert the parameters to NT format and call the native API */ + Offset.u.LowPart = lpOverlapped->Offset; + Offset.u.HighPart = lpOverlapped->OffsetHigh; + BytesToLock.u.LowPart = nNumberOfBytesToLockLow; + BytesToLock.u.HighPart = nNumberOfBytesToLockHigh; + Status = NtLockFile(hFile, + lpOverlapped->hEvent, + NULL, + NULL, + (PIO_STATUS_BLOCK)lpOverlapped, + &Offset, + &BytesToLock, + 0, + dwFlags & LOCKFILE_FAIL_IMMEDIATELY ? TRUE : FALSE, + dwFlags & LOCKFILE_EXCLUSIVE_LOCK ? TRUE: FALSE); + if ((NT_SUCCESS(Status)) && (Status != STATUS_PENDING)) + { + /* Pending status is *not* allowed in the Ex API */ + return TRUE; + } + + /* Convert the error code and fail */ + BaseSetLastNTError(Status); + return FALSE; +} + +/* + * @implemented + */ +BOOL +WINAPI +UnlockFile(IN HANDLE hFile, + IN DWORD dwFileOffsetLow, + IN DWORD dwFileOffsetHigh, + IN DWORD nNumberOfBytesToUnlockLow, + IN DWORD nNumberOfBytesToUnlockHigh) +{ OVERLAPPED Overlapped; - + NTSTATUS Status; + BOOLEAN Result; + + /* Convert parameters to Ex format and call the new API */ Overlapped.Offset = dwFileOffsetLow; Overlapped.OffsetHigh = dwFileOffsetHigh; - Overlapped.hEvent = NULL; - dwReserved = 0; - - return LockFileEx(hFile, - LOCKFILE_FAIL_IMMEDIATELY | - LOCKFILE_EXCLUSIVE_LOCK, - dwReserved, - nNumberOfBytesToLockLow, - nNumberOfBytesToLockHigh, - &Overlapped ) ; -} - - -/* - * @implemented - */ -BOOL -WINAPI -LockFileEx(HANDLE hFile, - DWORD dwFlags, - DWORD dwReserved, - DWORD nNumberOfBytesToLockLow, - DWORD nNumberOfBytesToLockHigh, - LPOVERLAPPED lpOverlapped /* required! */) -{ - LARGE_INTEGER BytesToLock; - BOOL LockImmediate; - BOOL LockExclusive; - NTSTATUS errCode; - LARGE_INTEGER Offset; - - if(dwReserved != 0 || lpOverlapped==NULL) - { + Result = UnlockFileEx(hFile, + 0, + nNumberOfBytesToUnlockLow, + nNumberOfBytesToUnlockHigh, + &Overlapped); + if (!(Result) && (GetLastError() == ERROR_IO_PENDING)) + { + /* Ex fails during STATUS_PENDING, handle that here by waiting */ + Status = NtWaitForSingleObject(hFile, FALSE, NULL); + if (NT_SUCCESS(Status)) Status = Overlapped.Internal; + + /* Now if the status is successful, return */ + if (!NT_SUCCESS(Status)) return TRUE; + + /* Otherwise the asynchronous operation had a failure, so fail */ + BaseSetLastNTError(Status); + return FALSE; + } + + /* Success or error case -- Ex took care of the rest, just return */ + return Result; +} + +/* + * @implemented + */ +BOOL +WINAPI +UnlockFileEx(IN HANDLE hFile, + IN DWORD dwReserved, + IN DWORD nNumberOfBytesToUnLockLow, + IN DWORD nNumberOfBytesToUnLockHigh, + IN LPOVERLAPPED lpOverlapped) +{ + LARGE_INTEGER BytesToUnLock, StartAddress; + NTSTATUS Status; + + /* Is this a console handle? */ + if (IsConsoleHandle(hFile)) + { + /* Can't "unlock" a console! */ + BaseSetLastNTError(STATUS_INVALID_HANDLE); + return FALSE; + } + + /* This parameter should be zero */ + if (dwReserved) + { + /* Fail since it isn't */ SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } - TRACE( "%p %x%08x %x%08x flags %x\n", - hFile, lpOverlapped->OffsetHigh, lpOverlapped->Offset, - nNumberOfBytesToLockHigh, nNumberOfBytesToLockLow, dwFlags ); - - lpOverlapped->Internal = STATUS_PENDING; - - Offset.u.LowPart = lpOverlapped->Offset; - Offset.u.HighPart = lpOverlapped->OffsetHigh; - - if ( (dwFlags & LOCKFILE_FAIL_IMMEDIATELY) == LOCKFILE_FAIL_IMMEDIATELY ) - LockImmediate = TRUE; - else - LockImmediate = FALSE; - - if ( (dwFlags & LOCKFILE_EXCLUSIVE_LOCK) == LOCKFILE_EXCLUSIVE_LOCK ) - LockExclusive = TRUE; - else - LockExclusive = FALSE; - - BytesToLock.u.LowPart = nNumberOfBytesToLockLow; - BytesToLock.u.HighPart = nNumberOfBytesToLockHigh; - - errCode = NtLockFile(hFile, - lpOverlapped->hEvent, - NULL, - NULL, - (PIO_STATUS_BLOCK)lpOverlapped, - &Offset, - &BytesToLock, - 0, - (BOOLEAN)LockImmediate, - (BOOLEAN)LockExclusive); - - if ( !NT_SUCCESS(errCode) ) - { - BaseSetLastNTError(errCode); - return FALSE; - } - - return TRUE; -} - - -/* - * @implemented - */ -BOOL -WINAPI -UnlockFile(HANDLE hFile, - DWORD dwFileOffsetLow, - DWORD dwFileOffsetHigh, - DWORD nNumberOfBytesToUnlockLow, - DWORD nNumberOfBytesToUnlockHigh) -{ - OVERLAPPED Overlapped; - DWORD dwReserved; - Overlapped.Offset = dwFileOffsetLow; - Overlapped.OffsetHigh = dwFileOffsetHigh; - dwReserved = 0; - - return UnlockFileEx(hFile, - dwReserved, - nNumberOfBytesToUnlockLow, - nNumberOfBytesToUnlockHigh, - &Overlapped); -} - - -/* - * @implemented - */ -BOOL -WINAPI -UnlockFileEx(HANDLE hFile, - DWORD dwReserved, - DWORD nNumberOfBytesToUnLockLow, - DWORD nNumberOfBytesToUnLockHigh, - LPOVERLAPPED lpOverlapped /* required! */) -{ - LARGE_INTEGER BytesToUnLock; - LARGE_INTEGER StartAddress; - NTSTATUS errCode; - - if(dwReserved != 0 || lpOverlapped == NULL) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } - - TRACE( "%p %x%08x %x%08x\n", - hFile, lpOverlapped->OffsetHigh, lpOverlapped->Offset, - nNumberOfBytesToUnLockHigh, nNumberOfBytesToUnLockLow); - + /* Convert to NT format and call the native function */ BytesToUnLock.u.LowPart = nNumberOfBytesToUnLockLow; BytesToUnLock.u.HighPart = nNumberOfBytesToUnLockHigh; - StartAddress.u.LowPart = lpOverlapped->Offset; StartAddress.u.HighPart = lpOverlapped->OffsetHigh; - - errCode = NtUnlockFile(hFile, - (PIO_STATUS_BLOCK)lpOverlapped, - &StartAddress, - &BytesToUnLock, - 0); - - if ( !NT_SUCCESS(errCode) ) - { - BaseSetLastNTError(errCode); - return FALSE; - } - + Status = NtUnlockFile(hFile, + (PIO_STATUS_BLOCK)lpOverlapped, + &StartAddress, + &BytesToUnLock, + 0); + if (!NT_SUCCESS(Status)) + { + /* Convert the error and fail */ + BaseSetLastNTError(Status); + return FALSE; + } + + /* All good */ return TRUE; }
12 years, 10 months
1
0
0
0
[jgardou] 55794: [CRT] - Check for NULL before freeing
by jgardou@svn.reactos.org
Author: jgardou Date: Tue Feb 21 21:36:01 2012 New Revision: 55794 URL:
http://svn.reactos.org/svn/reactos?rev=55794&view=rev
Log: [CRT] - Check for NULL before freeing Modified: trunk/reactos/lib/sdk/crt/stdio/file.c Modified: trunk/reactos/lib/sdk/crt/stdio/file.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/stdio/file.c?r…
============================================================================== --- trunk/reactos/lib/sdk/crt/stdio/file.c [iso-8859-1] (original) +++ trunk/reactos/lib/sdk/crt/stdio/file.c [iso-8859-1] Tue Feb 21 21:36:01 2012 @@ -963,10 +963,10 @@ fclose(&_iob[2]); for(i=0; i<sizeof(__pioinfo)/sizeof(__pioinfo[0]); i++) - free(__pioinfo[i]); + if(__pioinfo[i]) free(__pioinfo[i]); for(i=0; i<sizeof(fstream)/sizeof(fstream[0]); i++) - free(fstream[i]); + if(fstream[i]) free(fstream[i]); file_cs.DebugInfo->Spare[0] = 0; DeleteCriticalSection(&file_cs);
12 years, 10 months
1
0
0
0
[ion] 55793: [KERNEL32]: Format, comment, annotate, cleanup the I/O completion APIs.
by ion@svn.reactos.org
Author: ion Date: Tue Feb 21 21:31:01 2012 New Revision: 55793 URL:
http://svn.reactos.org/svn/reactos?rev=55793&view=rev
Log: [KERNEL32]: Format, comment, annotate, cleanup the I/O completion APIs. Modified: trunk/reactos/dll/win32/kernel32/client/file/iocompl.c Modified: trunk/reactos/dll/win32/kernel32/client/file/iocompl.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
============================================================================== --- trunk/reactos/dll/win32/kernel32/client/file/iocompl.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/kernel32/client/file/iocompl.c [iso-8859-1] Tue Feb 21 21:31:01 2012 @@ -13,164 +13,160 @@ #define NDEBUG #include <debug.h> -#define NANOS_TO_100NS(nanos) (((LONGLONG)(nanos)) / 100) -#define MICROS_TO_100NS(micros) (((LONGLONG)(micros)) * NANOS_TO_100NS(1000)) -#define MILLIS_TO_100NS(milli) (((LONGLONG)(milli)) * MICROS_TO_100NS(1000)) - /* * @implemented */ HANDLE WINAPI -CreateIoCompletionPort( - HANDLE FileHandle, - HANDLE ExistingCompletionPort, - ULONG_PTR CompletionKey, - DWORD NumberOfConcurrentThreads - ) -{ - HANDLE CompletionPort = NULL; - NTSTATUS errCode; - FILE_COMPLETION_INFORMATION CompletionInformation; - IO_STATUS_BLOCK IoStatusBlock; - - if ( FileHandle == INVALID_HANDLE_VALUE && ExistingCompletionPort != NULL ) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } - - if ( ExistingCompletionPort != NULL ) - { - CompletionPort = ExistingCompletionPort; - } - else - { - - errCode = NtCreateIoCompletion(&CompletionPort, - IO_COMPLETION_ALL_ACCESS, - NULL,//ObjectAttributes - NumberOfConcurrentThreads); - - if (!NT_SUCCESS(errCode) ) - { - BaseSetLastNTError (errCode); - return FALSE; - } - - } - - if ( FileHandle != INVALID_HANDLE_VALUE ) - { - CompletionInformation.Port = CompletionPort; - CompletionInformation.Key = (PVOID)CompletionKey; - - errCode = NtSetInformationFile(FileHandle, - &IoStatusBlock, - &CompletionInformation, - sizeof(FILE_COMPLETION_INFORMATION), - FileCompletionInformation); - - if ( !NT_SUCCESS(errCode) ) - { - if ( ExistingCompletionPort == NULL ) - { - NtClose(CompletionPort); - } - - BaseSetLastNTError (errCode); - return FALSE; - } - } - - return CompletionPort; -} - - -/* - * @implemented - */ -BOOL -WINAPI -GetQueuedCompletionStatus( - HANDLE CompletionHandle, - LPDWORD lpNumberOfBytesTransferred, - PULONG_PTR lpCompletionKey, - LPOVERLAPPED *lpOverlapped, - DWORD dwMilliseconds - ) -{ - NTSTATUS errCode; - IO_STATUS_BLOCK IoStatus; - ULONG_PTR CompletionKey; - LARGE_INTEGER Time; - PLARGE_INTEGER TimePtr; - - if (!lpNumberOfBytesTransferred || !lpCompletionKey || !lpOverlapped) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } - - /* Convert the timeout */ - TimePtr = BaseFormatTimeOut(&Time, dwMilliseconds); - - errCode = NtRemoveIoCompletion(CompletionHandle, +CreateIoCompletionPort(IN HANDLE FileHandle, + IN HANDLE ExistingCompletionPort, + IN ULONG_PTR CompletionKey, + IN DWORD NumberOfConcurrentThreads) +{ + NTSTATUS Status; + HANDLE NewPort; + FILE_COMPLETION_INFORMATION CompletionInformation; + IO_STATUS_BLOCK IoStatusBlock; + + /* Check if this is a new port */ + NewPort = ExistingCompletionPort; + if (!ExistingCompletionPort) + { + /* Create it */ + Status = NtCreateIoCompletion(&NewPort, + IO_COMPLETION_ALL_ACCESS, + NULL, + NumberOfConcurrentThreads); + if (!NT_SUCCESS(Status)) + { + /* Convert error and fail */ + BaseSetLastNTError(Status); + return FALSE; + } + } + + /* Check if no actual file is being associated with the completion port */ + if (FileHandle == INVALID_HANDLE_VALUE) + { + /* Was there a port already associated? */ + if (ExistingCompletionPort) + { + /* You are not allowed using an old port and dropping the handle */ + NewPort = NULL; + BaseSetLastNTError(STATUS_INVALID_PARAMETER); + } + } + else + { + /* We have a file handle, so associated it with this completion port */ + CompletionInformation.Port = NewPort; + CompletionInformation.Key = (PVOID)CompletionKey; + Status = NtSetInformationFile(FileHandle, + &IoStatusBlock, + &CompletionInformation, + sizeof(FILE_COMPLETION_INFORMATION), + FileCompletionInformation); + if (!NT_SUCCESS(Status)) + { + /* Convert the error code and close the newly created port, if any */ + BaseSetLastNTError(Status); + if (!ExistingCompletionPort) NtClose(NewPort); + return FALSE; + } + } + + /* Return the newly created port, if any */ + return NewPort; +} + +/* + * @implemented + */ +BOOL +WINAPI +GetQueuedCompletionStatus(IN HANDLE CompletionHandle, + IN LPDWORD lpNumberOfBytesTransferred, + OUT PULONG_PTR lpCompletionKey, + OUT LPOVERLAPPED *lpOverlapped, + IN DWORD dwMilliseconds) +{ + NTSTATUS Status; + IO_STATUS_BLOCK IoStatus; + ULONG_PTR CompletionKey; + LARGE_INTEGER Time; + PLARGE_INTEGER TimePtr; + + /* Convert the timeout and then call the native API */ + TimePtr = BaseFormatTimeOut(&Time, dwMilliseconds); + Status = NtRemoveIoCompletion(CompletionHandle, (PVOID*)&CompletionKey, (PVOID*)lpOverlapped, &IoStatus, TimePtr); - - if (!NT_SUCCESS(errCode) || errCode == STATUS_TIMEOUT) { - *lpOverlapped = NULL; - - if(errCode == STATUS_TIMEOUT) - SetLastError(WAIT_TIMEOUT); - else - BaseSetLastNTError(errCode); - - return FALSE; - } - - *lpCompletionKey = CompletionKey; - *lpNumberOfBytesTransferred = IoStatus.Information; - - if (!NT_SUCCESS(IoStatus.Status)){ - //failed io operation - BaseSetLastNTError(IoStatus.Status); - return FALSE; - } - - return TRUE; -} - - -/* - * @implemented - */ -BOOL -WINAPI -PostQueuedCompletionStatus( - HANDLE CompletionHandle, - DWORD dwNumberOfBytesTransferred, - ULONG_PTR dwCompletionKey, - LPOVERLAPPED lpOverlapped - ) -{ - NTSTATUS errCode; - - errCode = NtSetIoCompletion(CompletionHandle, - (PVOID)dwCompletionKey, // KeyContext - (PVOID)lpOverlapped, // ApcContext - STATUS_SUCCESS, // IoStatusBlock->Status - dwNumberOfBytesTransferred); // IoStatusBlock->Information - - if ( !NT_SUCCESS(errCode) ) - { - BaseSetLastNTError (errCode); - return FALSE; - } - return TRUE; + if (!(NT_SUCCESS(Status)) || (Status == STATUS_TIMEOUT)) + { + /* Clear out the overlapped output */ + *lpOverlapped = NULL; + + /* Check what kind of error we got */ + if (Status == STATUS_TIMEOUT) + { + /* Timeout error is set directly since there's no conversion */ + SetLastError(WAIT_TIMEOUT); + } + else + { + /* Any other error gets converted */ + BaseSetLastNTError(Status); + } + + /* This is a failure case */ + return FALSE; + } + + /* Write back the output parameters */ + *lpCompletionKey = CompletionKey; + *lpNumberOfBytesTransferred = IoStatus.Information; + + /* Check for error */ + if (!NT_SUCCESS(IoStatus.Status)) + { + /* Convert and fail */ + BaseSetLastNTError(IoStatus.Status); + return FALSE; + } + + /* Return success */ + return TRUE; +} + +/* + * @implemented + */ +BOOL +WINAPI +PostQueuedCompletionStatus(IN HANDLE CompletionHandle, + IN DWORD dwNumberOfBytesTransferred, + IN ULONG_PTR dwCompletionKey, + IN LPOVERLAPPED lpOverlapped) +{ + NTSTATUS Status; + + /* Call the native API */ + Status = NtSetIoCompletion(CompletionHandle, + (PVOID)dwCompletionKey, + (PVOID)lpOverlapped, + STATUS_SUCCESS, + dwNumberOfBytesTransferred); + if (!NT_SUCCESS(Status)) + { + /* Convert the error and fail */ + BaseSetLastNTError(Status); + return FALSE; + } + + /* Success path */ + return TRUE; } /* @@ -211,7 +207,7 @@ } /* Fail if we had an error -- the last error is already set */ - if (WaitStatus != 0) return FALSE; + if (WaitStatus) return FALSE; } /* Return bytes transferred */ @@ -234,24 +230,24 @@ */ BOOL WINAPI -BindIoCompletionCallback(HANDLE FileHandle, - LPOVERLAPPED_COMPLETION_ROUTINE Function, - ULONG Flags) -{ - NTSTATUS Status = 0; - - DPRINT("(%p, %p, %d)\n", FileHandle, Function, Flags); - +BindIoCompletionCallback(IN HANDLE FileHandle, + IN LPOVERLAPPED_COMPLETION_ROUTINE Function, + IN ULONG Flags) +{ + NTSTATUS Status; + + /* Call RTL */ Status = RtlSetIoCompletionCallback(FileHandle, (PIO_APC_ROUTINE)Function, Flags); - if (!NT_SUCCESS(Status)) { - SetLastError(RtlNtStatusToDosError(Status)); - return FALSE; - } - + /* Set error and fail */ + BaseSetLastNTError(Status); + return FALSE; + } + + /* Return success */ return TRUE; }
12 years, 10 months
1
0
0
0
[cgutman] 55792: [USBOHCI] - Fix indication of USB_PORT_STATUS_RESET changes - Fixes premature completion of resets causing assertions to fail
by cgutman@svn.reactos.org
Author: cgutman Date: Tue Feb 21 20:32:48 2012 New Revision: 55792 URL:
http://svn.reactos.org/svn/reactos?rev=55792&view=rev
Log: [USBOHCI] - Fix indication of USB_PORT_STATUS_RESET changes - Fixes premature completion of resets causing assertions to fail Modified: trunk/reactos/drivers/usb/usbohci/hardware.cpp Modified: trunk/reactos/drivers/usb/usbohci/hardware.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbohci/hardwa…
============================================================================== --- trunk/reactos/drivers/usb/usbohci/hardware.cpp [iso-8859-1] (original) +++ trunk/reactos/drivers/usb/usbohci/hardware.cpp [iso-8859-1] Tue Feb 21 20:32:48 2012 @@ -1185,14 +1185,11 @@ if (Value & OHCI_RH_PORTSTATUS_PSSC) *PortChange |= USB_PORT_STATUS_ENABLE; - // port reset started (change bit only set at completion) + // port reset started if (Value & OHCI_RH_PORTSTATUS_PRS) - { *PortStatus |= USB_PORT_STATUS_RESET; - *PortChange |= USB_PORT_STATUS_RESET; - } - - // port reset ended (change bit only set at completion) + + // port reset ended if (Value & OHCI_RH_PORTSTATUS_PRSC) *PortChange |= USB_PORT_STATUS_RESET;
12 years, 10 months
1
0
0
0
[ion] 55791: [KERNEL32]: Use macro for CreateMailSlotA->CreateMailSlotW.
by ion@svn.reactos.org
Author: ion Date: Tue Feb 21 19:19:44 2012 New Revision: 55791 URL:
http://svn.reactos.org/svn/reactos?rev=55791&view=rev
Log: [KERNEL32]: Use macro for CreateMailSlotA->CreateMailSlotW. Modified: trunk/reactos/dll/win32/kernel32/client/file/mailslot.c trunk/reactos/dll/win32/kernel32/include/base_x.h Modified: trunk/reactos/dll/win32/kernel32/client/file/mailslot.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
============================================================================== --- trunk/reactos/dll/win32/kernel32/client/file/mailslot.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/kernel32/client/file/mailslot.c [iso-8859-1] Tue Feb 21 19:19:44 2012 @@ -26,32 +26,8 @@ IN DWORD lReadTimeout, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes) { - PUNICODE_STRING NameU; - ANSI_STRING NameA; - NTSTATUS Status; - - NameU = &NtCurrentTeb()->StaticUnicodeString; - - RtlInitAnsiString(&NameA, (LPSTR)lpName); - Status = RtlAnsiStringToUnicodeString(NameU, &NameA, FALSE); - if (!NT_SUCCESS(Status)) - { - if (Status == STATUS_BUFFER_OVERFLOW) - { - SetLastError(ERROR_FILENAME_EXCED_RANGE); - } - else - { - BaseSetLastNTError(Status); - } - - return INVALID_HANDLE_VALUE; - } - - return CreateMailslotW(NameU->Buffer, - nMaxMessageSize, - lReadTimeout, - lpSecurityAttributes); + /* Call the W(ide) function */ + ConvertWin32AnsiObjectApiToUnicodeApi2(Mailslot, lpName, nMaxMessageSize, lReadTimeout, lpSecurityAttributes); } /* Modified: trunk/reactos/dll/win32/kernel32/include/base_x.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/include…
============================================================================== --- trunk/reactos/dll/win32/kernel32/include/base_x.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/kernel32/include/base_x.h [iso-8859-1] Tue Feb 21 19:19:44 2012 @@ -56,6 +56,17 @@ if (!name) return Create##obj##W(__VA_ARGS__, NULL); \ ConvertAnsiToUnicodeBody(name) \ if (NT_SUCCESS(Status)) return Create##obj##W(__VA_ARGS__, UnicodeCache->Buffer); \ + ConvertAnsiToUnicodeEpilogue + +// +// This macro uses the ConvertAnsiToUnicode macros above to convert a CreateXxxA +// Win32 API into its equivalent CreateXxxW API. +// +#define ConvertWin32AnsiObjectApiToUnicodeApi2(obj, name, ...) \ + ConvertAnsiToUnicodePrologue \ + if (!name) return Create##obj##W(NULL, __VA_ARGS__); \ + ConvertAnsiToUnicodeBody(name) \ + if (NT_SUCCESS(Status)) return Create##obj##W(UnicodeCache->Buffer, __VA_ARGS__); \ ConvertAnsiToUnicodeEpilogue //
12 years, 10 months
1
0
0
0
[ion] 55790: [KERNEL32]: CreateHardLinkW was not setting last error on failure. [KERNEL32]: Cleanup/format/comment/annotate CreateHardLink*.
by ion@svn.reactos.org
Author: ion Date: Tue Feb 21 19:18:57 2012 New Revision: 55790 URL:
http://svn.reactos.org/svn/reactos?rev=55790&view=rev
Log: [KERNEL32]: CreateHardLinkW was not setting last error on failure. [KERNEL32]: Cleanup/format/comment/annotate CreateHardLink*. Modified: trunk/reactos/dll/win32/kernel32/client/file/hardlink.c Modified: trunk/reactos/dll/win32/kernel32/client/file/hardlink.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
============================================================================== --- trunk/reactos/dll/win32/kernel32/client/file/hardlink.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/kernel32/client/file/hardlink.c [iso-8859-1] Tue Feb 21 19:18:57 2012 @@ -13,18 +13,17 @@ #include <k32.h> #define NDEBUG #include <debug.h> -DEBUG_CHANNEL(kernel32file); /* FUNCTIONS ****************************************************************/ - /* * @implemented */ -BOOL WINAPI -CreateHardLinkW(LPCWSTR lpFileName, - LPCWSTR lpExistingFileName, - LPSECURITY_ATTRIBUTES lpSecurityAttributes) +BOOL +WINAPI +CreateHardLinkW(IN LPCWSTR lpFileName, + IN LPCWSTR lpExistingFileName, + IN LPSECURITY_ATTRIBUTES lpSecurityAttributes) { NTSTATUS Status; BOOL Ret = FALSE; @@ -33,12 +32,13 @@ OBJECT_ATTRIBUTES ObjectAttributes; HANDLE hTarget = INVALID_HANDLE_VALUE; PFILE_LINK_INFORMATION LinkInformation = NULL; - UNICODE_STRING LinkTarget = {0, 0, NULL}, LinkName = {0, 0, NULL}; + UNICODE_STRING LinkTarget, LinkName; - TRACE("CreateHardLinkW: %S, %S, %p\n", lpFileName, lpExistingFileName, lpSecurityAttributes); + /* Initialize */ + LinkTarget.Buffer = LinkName.Buffer = NULL; /* Validate parameters */ - if(!lpFileName || !lpExistingFileName) + if (!(lpFileName) || !(lpExistingFileName)) { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; @@ -47,8 +47,12 @@ _SEH2_TRY { /* Get target UNC path */ - if (!RtlDosPathNameToNtPathName_U(lpExistingFileName, &LinkTarget, NULL, NULL)) + if (!RtlDosPathNameToNtPathName_U(lpExistingFileName, + &LinkTarget, + NULL, + NULL)) { + /* Set the error and fail */ SetLastError(ERROR_PATH_NOT_FOUND); _SEH2_LEAVE; } @@ -58,8 +62,9 @@ &LinkTarget, OBJ_CASE_INSENSITIVE, NULL, - (lpSecurityAttributes ? lpSecurityAttributes->lpSecurityDescriptor : NULL)); - + lpSecurityAttributes ? + lpSecurityAttributes->lpSecurityDescriptor : + NULL); Status = NtOpenFile(&hTarget, SYNCHRONIZE | FILE_WRITE_ATTRIBUTES, &ObjectAttributes, @@ -68,6 +73,7 @@ FILE_SYNCHRONOUS_IO_NONALERT | FILE_OPEN_REPARSE_POINT); if (!NT_SUCCESS(Status)) { + /* Convert the error and fail */ BaseSetLastNTError(Status); _SEH2_LEAVE; } @@ -75,95 +81,93 @@ /* Get UNC path name for link */ if (!RtlDosPathNameToNtPathName_U(lpFileName, &LinkName, NULL, NULL)) { + /* Set the error and fail */ SetLastError(ERROR_PATH_NOT_FOUND); _SEH2_LEAVE; } - /* Prepare data for link */ + /* Allocate data for link */ NeededSize = sizeof(FILE_LINK_INFORMATION) + LinkName.Length; LinkInformation = RtlAllocateHeap(RtlGetProcessHeap(), 0, NeededSize); if (!LinkInformation) { + /* We're out of memory */ SetLastError(ERROR_NOT_ENOUGH_MEMORY); _SEH2_LEAVE; } + /* Setup data for link and create it */ RtlMoveMemory(LinkInformation->FileName, LinkName.Buffer, LinkName.Length); LinkInformation->ReplaceIfExists = FALSE; LinkInformation->RootDirectory = 0; LinkInformation->FileNameLength = LinkName.Length; - - /* Create hard link */ Status = NtSetInformationFile(hTarget, &IoStatusBlock, LinkInformation, - NeededSize, + NeededSize, FileLinkInformation); if (NT_SUCCESS(Status)) { + /* Set success code */ Ret = TRUE; + } + else + { + /* Convert error code and return default (FALSE) */ + BaseSetLastNTError(Status); } } _SEH2_FINALLY { - if (LinkTarget.Buffer) - { - RtlFreeHeap(RtlGetProcessHeap(), 0, LinkTarget.Buffer); - } - - if (hTarget != INVALID_HANDLE_VALUE) - { - NtClose(hTarget); - } - - if (LinkName.Buffer) - { - RtlFreeHeap(RtlGetProcessHeap(), 0, LinkName.Buffer); - } - - if (LinkInformation) - { - RtlFreeHeap(RtlGetProcessHeap(), 0, LinkInformation); - } + /* Cleanup all allocations */ + if (LinkTarget.Buffer) RtlFreeHeap(RtlGetProcessHeap(), 0, LinkTarget.Buffer); + if (hTarget != INVALID_HANDLE_VALUE) NtClose(hTarget); + if (LinkName.Buffer) RtlFreeHeap(RtlGetProcessHeap(), 0, LinkName.Buffer); + if (LinkInformation) RtlFreeHeap(RtlGetProcessHeap(), 0, LinkInformation); } _SEH2_END; - return Ret; } /* * @implemented */ -BOOL WINAPI -CreateHardLinkA(LPCSTR lpFileName, - LPCSTR lpExistingFileName, - LPSECURITY_ATTRIBUTES lpSecurityAttributes) +BOOL +WINAPI +CreateHardLinkA(IN LPCSTR lpFileName, + IN LPCSTR lpExistingFileName, + IN LPSECURITY_ATTRIBUTES lpSecurityAttributes) { BOOL Ret; PUNICODE_STRING lpFileNameW; UNICODE_STRING ExistingFileNameW; + /* Convert the filename to unicode, using MAX_PATH limitations */ lpFileNameW = Basep8BitStringToStaticUnicodeString(lpFileName); - if (!lpFileNameW) + if (!lpFileNameW) return FALSE; + + /* Check if there's an existing name as well */ + if (lpExistingFileName) { - return FALSE; + /* We're already using the static string above, so do this dynamically */ + if (!Basep8BitStringToDynamicUnicodeString(&ExistingFileNameW, + lpExistingFileName)) + { + /* Out of memory -- fail */ + return FALSE; + } + } + else + { + /* No existing file name */ + ExistingFileNameW.Buffer = NULL; } - if (!lpExistingFileName) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } - - if (!Basep8BitStringToDynamicUnicodeString(&ExistingFileNameW, lpExistingFileName)) - { - return FALSE; - } - - Ret = CreateHardLinkW(lpFileNameW->Buffer, ExistingFileNameW.Buffer, lpSecurityAttributes); - - RtlFreeHeap(RtlGetProcessHeap(), 0, ExistingFileNameW.Buffer); - + /* Call the Wide function, and then free our dynamic string */ + Ret = CreateHardLinkW(lpFileNameW->Buffer, + ExistingFileNameW.Buffer, + lpSecurityAttributes); + RtlFreeUnicodeString(&ExistingFileNameW); return Ret; }
12 years, 10 months
1
0
0
0
[janderwald] 55789: [USBUHCI] - UHCI has 2 ports
by janderwald@svn.reactos.org
Author: janderwald Date: Tue Feb 21 18:53:04 2012 New Revision: 55789 URL:
http://svn.reactos.org/svn/reactos?rev=55789&view=rev
Log: [USBUHCI] - UHCI has 2 ports Modified: trunk/reactos/drivers/usb/usbuhci/hardware.cpp Modified: trunk/reactos/drivers/usb/usbuhci/hardware.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbuhci/hardwa…
============================================================================== --- trunk/reactos/drivers/usb/usbuhci/hardware.cpp [iso-8859-1] (original) +++ trunk/reactos/drivers/usb/usbuhci/hardware.cpp [iso-8859-1] Tue Feb 21 18:53:04 2012 @@ -558,6 +558,11 @@ DPRINT1("[USBUHCI] InitializeController\n"); // + // UHCI has two ports + // + m_NumberOfPorts = 2; + + // // get bus interface // Status = GetBusInterface(m_PhysicalDeviceObject, &BusInterface);
12 years, 10 months
1
0
0
0
← Newer
1
...
12
13
14
15
16
17
18
...
58
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Results per page:
10
25
50
100
200