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
December 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
16 participants
242 discussions
Start a n
N
ew thread
[fireball] 54606: [NTDLL/LDR] - Improve LdrpCheckForKnownDll by adding parameters validation, return status value, better failure paths handling.
by fireball@svn.reactos.org
Author: fireball Date: Wed Dec 7 17:51:18 2011 New Revision: 54606 URL:
http://svn.reactos.org/svn/reactos?rev=54606&view=rev
Log: [NTDLL/LDR] - Improve LdrpCheckForKnownDll by adding parameters validation, return status value, better failure paths handling. Modified: trunk/reactos/dll/ntdll/include/ntdllp.h trunk/reactos/dll/ntdll/ldr/ldrutils.c Modified: trunk/reactos/dll/ntdll/include/ntdllp.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/include/ntdllp.h…
============================================================================== --- trunk/reactos/dll/ntdll/include/ntdllp.h [iso-8859-1] (original) +++ trunk/reactos/dll/ntdll/include/ntdllp.h [iso-8859-1] Wed Dec 7 17:51:18 2011 @@ -59,6 +59,7 @@ NTSTATUS NTAPI LdrpInitializeProcess(PCONTEXT Context, PVOID SystemArgument1); VOID NTAPI LdrpInitFailure(NTSTATUS Status); VOID NTAPI LdrpValidateImageForMp(IN PLDR_DATA_TABLE_ENTRY LdrDataTableEntry); +VOID NTAPI LdrpEnsureLoaderLockIsHeld(); /* ldrpe.c */ NTSTATUS Modified: trunk/reactos/dll/ntdll/ldr/ldrutils.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/ldrutils.c?r…
============================================================================== --- trunk/reactos/dll/ntdll/ldr/ldrutils.c [iso-8859-1] (original) +++ trunk/reactos/dll/ntdll/ldr/ldrutils.c [iso-8859-1] Wed Dec 7 17:51:18 2011 @@ -663,12 +663,13 @@ return (PVOID)EntryPoint; } -/* NOTE: This function is broken, wrong number of parameters, no SxS, etc */ -HANDLE +/* NOTE: This function is partially missing SxS */ +NTSTATUS NTAPI LdrpCheckForKnownDll(PWSTR DllName, PUNICODE_STRING FullDllName, - PUNICODE_STRING BaseDllName) + PUNICODE_STRING BaseDllName, + HANDLE *SectionHandle) { OBJECT_ATTRIBUTES ObjectAttributes; HANDLE Section = NULL; @@ -677,8 +678,34 @@ PCHAR p1; PWCHAR p2; + /* Zero initialize provided parameters */ + if (SectionHandle) *SectionHandle = 0; + + if (FullDllName) + { + FullDllName->Length = 0; + FullDllName->MaximumLength = 0; + FullDllName->Buffer = NULL; + } + + if (BaseDllName) + { + BaseDllName->Length = 0; + BaseDllName->MaximumLength = 0; + BaseDllName->Buffer = NULL; + } + + /* If any of these three params are missing then fail */ + if (!SectionHandle || !FullDllName || !BaseDllName) + return STATUS_INVALID_PARAMETER; + + /* Check the Loader Lock */ + LdrpEnsureLoaderLockIsHeld(); + /* Upgrade DllName to a unicode string */ RtlInitUnicodeString(&DllNameUnic, DllName); + + /* FIXME: Missing RtlComputePrivatizedDllName_U related functionality */ /* Get the activation context */ Status = RtlFindActivationContextSectionString(0, @@ -691,13 +718,21 @@ if (Status == STATUS_SXS_SECTION_NOT_FOUND || Status == STATUS_SXS_KEY_NOT_FOUND) { + /* NOTE: Here it's beneficial to allocate one big unicode string + using LdrpAllocateUnicodeString instead of fragmenting the heap + with two allocations as it's done now. */ + /* Set up BaseDllName */ BaseDllName->Length = DllNameUnic.Length; BaseDllName->MaximumLength = DllNameUnic.MaximumLength; BaseDllName->Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, DllNameUnic.MaximumLength); - if (!BaseDllName->Buffer) return NULL; + if (!BaseDllName->Buffer) + { + Status = STATUS_NO_MEMORY; + goto Failure; + } /* Copy the contents there */ RtlMoveMemory(BaseDllName->Buffer, DllNameUnic.Buffer, DllNameUnic.MaximumLength); @@ -708,9 +743,8 @@ FullDllName->Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, FullDllName->MaximumLength); if (!FullDllName->Buffer) { - /* Free base name and fail */ - RtlFreeHeap(RtlGetProcessHeap(), 0, BaseDllName->Buffer); - return NULL; + Status = STATUS_NO_MEMORY; + goto Failure; } RtlMoveMemory(FullDllName->Buffer, LdrpKnownDllPath.Buffer, LdrpKnownDllPath.Length); @@ -741,19 +775,26 @@ &ObjectAttributes); if (!NT_SUCCESS(Status)) { - /* Opening failed, free resources */ - Section = NULL; - RtlFreeHeap(RtlGetProcessHeap(), 0, BaseDllName->Buffer); - RtlFreeHeap(RtlGetProcessHeap(), 0, FullDllName->Buffer); - } - } - else - { - if (!NT_SUCCESS(Status)) Section = NULL; - } - - /* Return section handle */ - return Section; + /* Clear status in case it was just not found */ + if (Status == STATUS_OBJECT_NAME_NOT_FOUND) Status = STATUS_SUCCESS; + goto Failure; + } + + /* Pass section handle to the caller and return success */ + *SectionHandle = Section; + return STATUS_SUCCESS; + } + +Failure: + /* Close section object if it was opened */ + if (Section) NtClose(Section); + + /* Free string resources */ + if (BaseDllName->Buffer) RtlFreeHeap(RtlGetProcessHeap(), 0, BaseDllName->Buffer); + if (FullDllName->Buffer) RtlFreeHeap(RtlGetProcessHeap(), 0, FullDllName->Buffer); + + /* Return status */ + return Status; } NTSTATUS @@ -893,9 +934,23 @@ } /* Try to find a Known DLL */ - SectionHandle = LdrpCheckForKnownDll(DllName, - &FullDllName, - &BaseDllName); + Status = LdrpCheckForKnownDll(DllName, + &FullDllName, + &BaseDllName, + &SectionHandle); + + if (!NT_SUCCESS(Status) && (Status != STATUS_DLL_NOT_FOUND)) + { + /* Failure */ + DbgPrintEx(81, //DPFLTR_LDR_ID, + 0, + "LDR: %s - call to LdrpCheckForKnownDll(\"%ws\", ...) failed with status %x\n", + __FUNCTION__, + DllName, + Status); + + return Status; + } } SkipCheck:
13 years
1
0
0
0
[cgutman] 54605: [NTOSKRNL] - Optimize the LRU segment selection a bit
by cgutman@svn.reactos.org
Author: cgutman Date: Wed Dec 7 09:49:49 2011 New Revision: 54605 URL:
http://svn.reactos.org/svn/reactos?rev=54605&view=rev
Log: [NTOSKRNL] - Optimize the LRU segment selection a bit Modified: trunk/reactos/ntoskrnl/cc/view.c Modified: trunk/reactos/ntoskrnl/cc/view.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/cc/view.c?rev=546…
============================================================================== --- trunk/reactos/ntoskrnl/cc/view.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/cc/view.c [iso-8859-1] Wed Dec 7 09:49:49 2011 @@ -430,8 +430,6 @@ InsertTailList(&DirtySegmentListHead, &CacheSeg->DirtySegmentListEntry); DirtyPageCount += Bcb->CacheSegmentSize / PAGE_SIZE; } - RemoveEntryList(&CacheSeg->CacheSegmentLRUListEntry); - InsertTailList(&CacheSegmentLRUListHead, &CacheSeg->CacheSegmentLRUListEntry); if (Mapped) { @@ -517,6 +515,13 @@ KeReleaseSpinLock(&Bcb->BcbLock, oldIrql); } + KeAcquireGuardedMutex(&ViewLock); + + /* Move to the tail of the LRU list */ + RemoveEntryList(&CacheSeg->CacheSegmentLRUListEntry); + InsertTailList(&CacheSegmentLRUListHead, &CacheSeg->CacheSegmentLRUListEntry); + + KeReleaseGuardedMutex(&ViewLock); CacheSeg->Dirty = TRUE; ExReleasePushLock(&CacheSeg->Lock); @@ -770,6 +775,14 @@ current = CcRosLookupCacheSegment(Bcb, CurrentOffset); if (current != NULL) { + KeAcquireGuardedMutex(&ViewLock); + + /* Move to tail of LRU list */ + RemoveEntryList(¤t->CacheSegmentLRUListEntry); + InsertTailList(&CacheSegmentLRUListHead, ¤t->CacheSegmentLRUListEntry); + + KeReleaseGuardedMutex(&ViewLock); + CacheSegList[i] = current; } else @@ -829,6 +842,15 @@ return Status; } } + + KeAcquireGuardedMutex(&ViewLock); + + /* Move to the tail of the LRU list */ + RemoveEntryList(¤t->CacheSegmentLRUListEntry); + InsertTailList(&CacheSegmentLRUListHead, ¤t->CacheSegmentLRUListEntry); + + KeReleaseGuardedMutex(&ViewLock); + /* * Return information about the segment to the caller. */
13 years
1
0
0
0
[jimtabor] 54604: [User32] - Sync up with wine controls. See http://www.winehq.org/pipermail/wine-cvs/ for log data.
by jimtabor@svn.reactos.org
Author: jimtabor Date: Wed Dec 7 09:23:04 2011 New Revision: 54604 URL:
http://svn.reactos.org/svn/reactos?rev=54604&view=rev
Log: [User32] - Sync up with wine controls. See
http://www.winehq.org/pipermail/wine-cvs/
for log data. Modified: trunk/reactos/dll/win32/user32/CMakeLists.txt trunk/reactos/dll/win32/user32/controls/button.c trunk/reactos/dll/win32/user32/controls/combo.c trunk/reactos/dll/win32/user32/controls/edit.c trunk/reactos/dll/win32/user32/controls/listbox.c trunk/reactos/dll/win32/user32/controls/regcontrol.c trunk/reactos/dll/win32/user32/controls/static.c trunk/reactos/dll/win32/user32/include/controls.h trunk/reactos/dll/win32/user32/include/user32.h trunk/reactos/dll/win32/user32/user32.rbuild trunk/reactos/dll/win32/user32/windows/cursoricon.c trunk/reactos/dll/win32/user32/windows/dialog.c Modified: trunk/reactos/dll/win32/user32/CMakeLists.txt URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/CMakeList…
============================================================================== --- trunk/reactos/dll/win32/user32/CMakeLists.txt [iso-8859-1] (original) +++ trunk/reactos/dll/win32/user32/CMakeLists.txt [iso-8859-1] Wed Dec 7 09:23:04 2011 @@ -72,7 +72,7 @@ win32ksys ${PSEH_LIB}) -add_delay_importlibs(user32 imm32) +add_delay_importlibs(user32 imm32 usp10) add_importlibs(user32 gdi32 advapi32 msvcrt kernel32 ntdll) add_pch(user32 include/user32.h) add_cd_file(TARGET user32 DESTINATION reactos/system32 FOR all) Modified: trunk/reactos/dll/win32/user32/controls/button.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/controls/…
============================================================================== --- trunk/reactos/dll/win32/user32/controls/button.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/user32/controls/button.c [iso-8859-1] Wed Dec 7 09:23:04 2011 @@ -31,7 +31,6 @@ * Styles * - BS_NOTIFY: is it complete? * - BS_RIGHTBUTTON: same as BS_LEFTTEXT - * - BS_TYPEMASK * * Messages * - WM_CHAR: Checks a (manual or automatic) check box on '+' or '=', clears it on '-' key. @@ -75,14 +74,8 @@ #define UISTATE_GWL_OFFSET (HIMAGE_GWL_OFFSET+sizeof(HFONT)) #define NB_EXTRA_BYTES (UISTATE_GWL_OFFSET+sizeof(LONG)) - /* Button state values */ -#define BUTTON_UNCHECKED 0x00 -#define BUTTON_CHECKED 0x01 -#define BUTTON_3STATE 0x02 -#define BUTTON_HIGHLIGHTED 0x04 -#define BUTTON_HASFOCUS 0x08 + /* undocumented flags */ #define BUTTON_NSTATES 0x0F - /* undocumented flags */ #define BUTTON_BTNPRESSED 0x40 #define BUTTON_UNKNOWN2 0x20 #define BUTTON_UNKNOWN3 0x10 @@ -103,22 +96,22 @@ static void OB_Paint( HWND hwnd, HDC hDC, UINT action ); static void BUTTON_CheckAutoRadioButton( HWND hwnd ); -#define MAX_BTN_TYPE 12 +#define MAX_BTN_TYPE 16 static const WORD maxCheckState[MAX_BTN_TYPE] = { - BUTTON_UNCHECKED, /* BS_PUSHBUTTON */ - BUTTON_UNCHECKED, /* BS_DEFPUSHBUTTON */ - BUTTON_CHECKED, /* BS_CHECKBOX */ - BUTTON_CHECKED, /* BS_AUTOCHECKBOX */ - BUTTON_CHECKED, /* BS_RADIOBUTTON */ - BUTTON_3STATE, /* BS_3STATE */ - BUTTON_3STATE, /* BS_AUTO3STATE */ - BUTTON_UNCHECKED, /* BS_GROUPBOX */ - BUTTON_UNCHECKED, /* BS_USERBUTTON */ - BUTTON_CHECKED, /* BS_AUTORADIOBUTTON */ - BUTTON_UNCHECKED, /* Not defined */ - BUTTON_UNCHECKED /* BS_OWNERDRAW */ + BST_UNCHECKED, /* BS_PUSHBUTTON */ + BST_UNCHECKED, /* BS_DEFPUSHBUTTON */ + BST_CHECKED, /* BS_CHECKBOX */ + BST_CHECKED, /* BS_AUTOCHECKBOX */ + BST_CHECKED, /* BS_RADIOBUTTON */ + BST_INDETERMINATE, /* BS_3STATE */ + BST_INDETERMINATE, /* BS_AUTO3STATE */ + BST_UNCHECKED, /* BS_GROUPBOX */ + BST_UNCHECKED, /* BS_USERBUTTON */ + BST_CHECKED, /* BS_AUTORADIOBUTTON */ + BST_UNCHECKED, /* BS_PUSHBOX */ + BST_UNCHECKED /* BS_OWNERDRAW */ }; typedef void (*pfPaint)( HWND hwnd, HDC hdc, UINT action ); @@ -135,7 +128,7 @@ GB_Paint, /* BS_GROUPBOX */ UB_Paint, /* BS_USERBUTTON */ CB_Paint, /* BS_AUTORADIOBUTTON */ - NULL, /* Not defined */ + NULL, /* BS_PUSHBOX */ OB_Paint /* BS_OWNERDRAW */ }; @@ -191,7 +184,7 @@ static inline UINT get_button_type( LONG window_style ) { - return (window_style & 0x0f); + return (window_style & BS_TYPEMASK); } /* paint a button of any type */ @@ -212,15 +205,6 @@ WCHAR *buffer = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ); if (buffer) InternalGetWindowText( hwnd, buffer, len + 1 ); return buffer; -} - -static void setup_clipping( HWND hwnd, HDC hdc ) -{ - RECT rc; - - GetClientRect( hwnd, &rc ); - DPtoLP( hdc, (POINT *)&rc, 2 ); - IntersectClipRect( hdc, rc.left, rc.top, rc.right, rc.bottom ); } /* Retrieve the UI state for the control */ @@ -313,10 +297,15 @@ /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */ if (btn_type == BS_USERBUTTON ) { - style = (style & ~0x0f) | BS_PUSHBUTTON; +#ifdef __REACTOS__ + style = (style & ~BS_TYPEMASK) | BS_PUSHBUTTON; SetWindowLongPtrW( hWnd, GWL_STYLE, style ); - } - set_button_state( hWnd, BUTTON_UNCHECKED ); +#else + style = (style & ~BS_TYPEMASK) | BS_PUSHBUTTON; + WIN_SetStyle( hWnd, style, BS_TYPEMASK & ~style ); +#endif + } + set_button_state( hWnd, BST_UNCHECKED ); button_update_uistate( hWnd, unicode ); return 0; @@ -389,7 +378,7 @@ if (!(state & BUTTON_BTNPRESSED)) break; state &= BUTTON_NSTATES; set_button_state( hWnd, state ); - if (!(state & BUTTON_HIGHLIGHTED)) + if (!(state & BST_PUSHED)) { ReleaseCapture(); break; @@ -403,14 +392,14 @@ switch(btn_type) { case BS_AUTOCHECKBOX: - SendMessageW( hWnd, BM_SETCHECK, !(state & BUTTON_CHECKED), 0 ); + SendMessageW( hWnd, BM_SETCHECK, !(state & BST_CHECKED), 0 ); break; case BS_AUTORADIOBUTTON: SendMessageW( hWnd, BM_SETCHECK, TRUE, 0 ); break; case BS_AUTO3STATE: SendMessageW( hWnd, BM_SETCHECK, - (state & BUTTON_3STATE) ? 0 : ((state & 3) + 1), 0 ); + (state & BST_INDETERMINATE) ? 0 : ((state & 3) + 1), 0 ); break; } BUTTON_NOTIFY_PARENT(hWnd, BN_CLICKED); @@ -424,7 +413,7 @@ { state &= BUTTON_NSTATES; set_button_state( hWnd, state ); - if (state & BUTTON_HIGHLIGHTED) SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 ); + if (state & BST_PUSHED) SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 ); } break; @@ -490,7 +479,7 @@ case WM_SETFOCUS: TRACE("WM_SETFOCUS %p\n",hWnd); - set_button_state( hWnd, get_button_state(hWnd) | BUTTON_HASFOCUS ); + set_button_state( hWnd, get_button_state(hWnd) | BST_FOCUS ); paint_button( hWnd, btn_type, ODA_FOCUS ); if (style & BS_NOTIFY) BUTTON_NOTIFY_PARENT(hWnd, BN_SETFOCUS); @@ -499,7 +488,7 @@ case WM_KILLFOCUS: TRACE("WM_KILLFOCUS %p\n",hWnd); state = get_button_state( hWnd ); - set_button_state( hWnd, state & ~BUTTON_HASFOCUS ); + set_button_state( hWnd, state & ~BST_FOCUS ); paint_button( hWnd, btn_type, ODA_FOCUS ); if ((state & BUTTON_BTNPRESSED) && GetCapture() == hWnd) @@ -515,10 +504,11 @@ break; case BM_SETSTYLE: - if ((wParam & 0x0f) >= MAX_BTN_TYPE) break; - btn_type = wParam & 0x0f; - style = (style & ~0x0f) | btn_type; + if ((wParam & BS_TYPEMASK) >= MAX_BTN_TYPE) break; + btn_type = wParam & BS_TYPEMASK; + style = (style & ~BS_TYPEMASK) | btn_type; SetWindowLongPtrW( hWnd, GWL_STYLE, style ); + //WIN_SetStyle( hWnd, style, BS_TYPEMASK & ~style ); /* Only redraw if lParam flag is set.*/ if (lParam) @@ -559,16 +549,21 @@ state = get_button_state( hWnd ); if ((btn_type == BS_RADIOBUTTON) || (btn_type == BS_AUTORADIOBUTTON)) { +#ifdef __REACTOS__ if (wParam) style |= WS_TABSTOP; else style &= ~WS_TABSTOP; SetWindowLongPtrW( hWnd, GWL_STYLE, style ); +#else + if (wParam) WIN_SetStyle( hWnd, WS_TABSTOP, 0 ); + else WIN_SetStyle( hWnd, 0, WS_TABSTOP ); +#endif } if ((state & 3) != wParam) { set_button_state( hWnd, (state & ~3) | wParam ); paint_button( hWnd, btn_type, ODA_SELECT ); } - if ((btn_type == BS_AUTORADIOBUTTON) && (wParam == BUTTON_CHECKED) && (style & WS_CHILD)) + if ((btn_type == BS_AUTORADIOBUTTON) && (wParam == BST_CHECKED) && (style & WS_CHILD)) BUTTON_CheckAutoRadioButton( hWnd ); break; @@ -578,15 +573,10 @@ case BM_SETSTATE: state = get_button_state( hWnd ); if (wParam) - { - if (state & BUTTON_HIGHLIGHTED) break; - set_button_state( hWnd, state | BUTTON_HIGHLIGHTED ); - } + set_button_state( hWnd, state | BST_PUSHED ); else - { - if (!(state & BUTTON_HIGHLIGHTED)) break; - set_button_state( hWnd, state & ~BUTTON_HIGHLIGHTED ); - } + set_button_state( hWnd, state & ~BST_PUSHED ); + paint_button( hWnd, btn_type, ODA_SELECT ); break; @@ -642,7 +632,7 @@ /* "Convert" pushlike buttons to pushbuttons */ if (style & BS_PUSHLIKE) - style &= ~0x0F; + style &= ~BS_TYPEMASK; if (!(style & BS_MULTILINE)) dtStyle |= DT_SINGLELINE; @@ -821,7 +811,7 @@ * I don't have Win31 on hand to verify that, so I leave it as is. */ - if ((style & BS_PUSHLIKE) && (state & BUTTON_3STATE)) + if ((style & BS_PUSHLIKE) && (state & BST_INDETERMINATE)) { hbr = GetSysColorBrush(COLOR_GRAYTEXT); flags |= DSS_MONO; @@ -873,8 +863,9 @@ HFONT hFont; LONG state = get_button_state( hwnd ); LONG style = GetWindowLongPtrW( hwnd, GWL_STYLE ); - BOOL pushedState = (state & BUTTON_HIGHLIGHTED); + BOOL pushedState = (state & BST_PUSHED); HWND parent; + HRGN hrgn; GetClientRect( hwnd, &rc ); @@ -884,7 +875,7 @@ if (!parent) parent = hwnd; GetControlColor( parent, hwnd, hDC, WM_CTLCOLORBTN); - setup_clipping( hwnd, hDC ); + hrgn = set_control_clipping( hDC, &rc ); #ifdef __REACTOS__ hOldPen = SelectObject(hDC, GetStockObject(DC_PEN)); SetDCPenColor(hDC, GetSysColor(COLOR_WINDOWFRAME)); @@ -916,7 +907,7 @@ uState |= DFCS_PUSHED; } - if (state & (BUTTON_CHECKED | BUTTON_3STATE)) + if (state & (BST_CHECKED | BST_INDETERMINATE)) uState |= DFCS_CHECKED; DrawFrameControl( hDC, &rc, DFC_BUTTON, uState ); @@ -938,8 +929,7 @@ SetTextColor( hDC, oldTxtColor ); draw_focus: - if ((action == ODA_FOCUS) || - ((action == ODA_DRAWENTIRE) && (state & BUTTON_HASFOCUS))) + if (action == ODA_FOCUS || (state & BST_FOCUS)) { if (!(get_ui_state(hwnd) & UISF_HIDEFOCUS)) { @@ -952,6 +942,8 @@ SelectObject( hDC, hOldPen ); SelectObject( hDC, hOldBrush ); SetBkMode(hDC, oldBkMode); + SelectClipRgn( hDC, hrgn ); + if (hrgn) DeleteObject( hrgn ); } /********************************************************************** @@ -968,6 +960,7 @@ LONG state = get_button_state( hwnd ); LONG style = GetWindowLongPtrW( hwnd, GWL_STYLE ); HWND parent; + HRGN hrgn; if (style & BS_PUSHLIKE) { @@ -983,7 +976,7 @@ parent = GetParent(hwnd); if (!parent) parent = hwnd; hBrush = GetControlColor( parent, hwnd, hDC, WM_CTLCOLORSTATIC); - setup_clipping( hwnd, hDC ); + hrgn = set_control_clipping( hDC, &client ); if (style & BS_LEFTTEXT) { @@ -1020,11 +1013,11 @@ if ((get_button_type(style) == BS_RADIOBUTTON) || (get_button_type(style) == BS_AUTORADIOBUTTON)) flags = DFCS_BUTTONRADIO; - else if (state & BUTTON_3STATE) flags = DFCS_BUTTON3STATE; + else if (state & BST_INDETERMINATE) flags = DFCS_BUTTON3STATE; else flags = DFCS_BUTTONCHECK; - if (state & (BUTTON_CHECKED | BUTTON_3STATE)) flags |= DFCS_CHECKED; - if (state & BUTTON_HIGHLIGHTED) flags |= DFCS_PUSHED; + if (state & (BST_CHECKED | BST_INDETERMINATE)) flags |= DFCS_CHECKED; + if (state & BST_PUSHED) flags |= DFCS_PUSHED; if (style & WS_DISABLED) flags |= DFCS_INACTIVE; @@ -1067,8 +1060,7 @@ BUTTON_DrawLabel(hwnd, hDC, dtFlags, &rtext); /* ... and focus */ - if ((action == ODA_FOCUS) || - ((action == ODA_DRAWENTIRE) && (state & BUTTON_HASFOCUS))) + if (action == ODA_FOCUS || (state & BST_FOCUS)) { if (!(get_ui_state(hwnd) & UISF_HIDEFOCUS)) { @@ -1078,6 +1070,8 @@ DrawFocusRect( hDC, &rtext ); } } + SelectClipRgn( hDC, hrgn ); + if (hrgn) DeleteObject( hrgn ); } @@ -1097,8 +1091,8 @@ { if (!sibling) break; if ((hwnd != sibling) && - ((GetWindowLongPtrW( sibling, GWL_STYLE) & 0x0f) == BS_AUTORADIOBUTTON)) - SendMessageW( sibling, BM_SETCHECK, BUTTON_UNCHECKED, 0 ); + ((GetWindowLongPtrW( sibling, GWL_STYLE) & BS_TYPEMASK) == BS_AUTORADIOBUTTON)) + SendMessageW( sibling, BM_SETCHECK, BST_UNCHECKED, 0 ); sibling = GetNextDlgGroupItem( parent, sibling, FALSE ); } while (sibling != start); } @@ -1117,16 +1111,17 @@ TEXTMETRICW tm; LONG style = GetWindowLongPtrW( hwnd, GWL_STYLE ); HWND parent; + HRGN hrgn; if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont ); /* GroupBox acts like static control, so it sends CTLCOLORSTATIC */ parent = GetParent(hwnd); if (!parent) parent = hwnd; hbr = GetControlColor( parent, hwnd, hDC, WM_CTLCOLORSTATIC); - setup_clipping( hwnd, hDC ); - + GetClientRect( hwnd, &rc); rcFrame = rc; + hrgn = set_control_clipping( hDC, &rc ); GetTextMetricsW (hDC, &tm); rcFrame.top += (tm.tmHeight / 2) - 1; @@ -1135,20 +1130,22 @@ InflateRect(&rc, -7, 1); dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &rc); - if (dtFlags == (UINT)-1L) - return; - - /* Because buttons have CS_PARENTDC class style, there is a chance - * that label will be drawn out of client rect. - * But Windows doesn't clip label's rect, so do I. - */ - - /* There is 1-pixel margin at the left, right, and bottom */ - rc.left--; rc.right++; rc.bottom++; - FillRect(hDC, &rc, hbr); - rc.left++; rc.right--; rc.bottom--; - - BUTTON_DrawLabel(hwnd, hDC, dtFlags, &rc); + if (dtFlags != (UINT)-1L) + { + /* Because buttons have CS_PARENTDC class style, there is a chance + * that label will be drawn out of client rect. + * But Windows doesn't clip label's rect, so do I. + */ + + /* There is 1-pixel margin at the left, right, and bottom */ + rc.left--; rc.right++; rc.bottom++; + FillRect(hDC, &rc, hbr); + rc.left++; rc.right--; rc.bottom--; + + BUTTON_DrawLabel(hwnd, hDC, dtFlags, &rc); + } + SelectClipRgn( hDC, hrgn ); + if (hrgn) DeleteObject( hrgn ); } @@ -1164,8 +1161,6 @@ LONG state = get_button_state( hwnd ); HWND parent; - if (action == ODA_SELECT) return; - GetClientRect( hwnd, &rc); if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont ); @@ -1175,14 +1170,26 @@ hBrush = GetControlColor( parent, hwnd, hDC, WM_CTLCOLORBTN); FillRect( hDC, &rc, hBrush ); - if ((action == ODA_FOCUS) || - ((action == ODA_DRAWENTIRE) && (state & BUTTON_HASFOCUS))) + if (action == ODA_FOCUS || (state & BST_FOCUS)) { if (!(get_ui_state(hwnd) & UISF_HIDEFOCUS)) DrawFocusRect( hDC, &rc ); } - BUTTON_NOTIFY_PARENT( hwnd, BN_PAINT ); + switch (action) + { + case ODA_FOCUS: + BUTTON_NOTIFY_PARENT( hwnd, (state & BST_FOCUS) ? BN_SETFOCUS : BN_KILLFOCUS ); + break; + + case ODA_SELECT: + BUTTON_NOTIFY_PARENT( hwnd, (state & BST_PUSHED) ? BN_HILITE : BN_UNHILITE ); + break; + + default: + BUTTON_NOTIFY_PARENT( hwnd, BN_PAINT ); + break; + } } @@ -1197,13 +1204,14 @@ LONG_PTR id = GetWindowLongPtrW( hwnd, GWLP_ID ); HWND parent; HFONT hFont, hPrevFont = 0; + HRGN hrgn; dis.CtlType = ODT_BUTTON; dis.CtlID = id; dis.itemID = 0; dis.itemAction = action; - dis.itemState = ((state & BUTTON_HASFOCUS) ? ODS_FOCUS : 0) | - ((state & BUTTON_HIGHLIGHTED) ? ODS_SELECTED : 0) | + dis.itemState = ((state & BST_FOCUS) ? ODS_FOCUS : 0) | + ((state & BST_PUSHED) ? ODS_SELECTED : 0) | (IsWindowEnabled(hwnd) ? 0: ODS_DISABLED); dis.hwndItem = hwnd; dis.hDC = hDC; @@ -1215,8 +1223,10 @@ if (!parent) parent = hwnd; GetControlColor( parent, hwnd, hDC, WM_CTLCOLORBTN); - setup_clipping( hwnd, hDC ); + hrgn = set_control_clipping( hDC, &dis.rcItem ); SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis ); if (hPrevFont) SelectObject(hDC, hPrevFont); -} + SelectClipRgn( hDC, hrgn ); + if (hrgn) DeleteObject( hrgn ); +} Modified: trunk/reactos/dll/win32/user32/controls/combo.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/controls/…
============================================================================== --- trunk/reactos/dll/win32/user32/controls/combo.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/user32/controls/combo.c [iso-8859-1] Wed Dec 7 09:23:04 2011 @@ -751,19 +751,6 @@ !(lphc->wState & CBF_DROPPED) ) itemState |= ODS_SELECTED | ODS_FOCUS; - /* - * Save the current clip region. - * To retrieve the clip region, we need to create one "dummy" - * clip region. - */ - clipRegion = CreateRectRgnIndirect(&rectEdit); - - if (GetClipRgn(hdc, clipRegion)!=1) - { - DeleteObject(clipRegion); - clipRegion=NULL; - } - if (!IsWindowEnabled(lphc->self)) itemState |= ODS_DISABLED; dis.CtlType = ODT_COMBOBOX; @@ -774,22 +761,17 @@ dis.itemState = itemState; dis.hDC = hdc; dis.rcItem = rectEdit; - dis.itemData = SendMessageW(lphc->hWndLBox, LB_GETITEMDATA, - (WPARAM)id, 0 ); + dis.itemData = SendMessageW(lphc->hWndLBox, LB_GETITEMDATA, id, 0 ); /* * Clip the DC and have the parent draw the item. */ - IntersectClipRect(hdc, - rectEdit.left, rectEdit.top, - rectEdit.right, rectEdit.bottom); + clipRegion = set_control_clipping( hdc, &rectEdit ); SendMessageW(lphc->owner, WM_DRAWITEM, ctlid, (LPARAM)&dis ); - /* - * Reset the clipping region. - */ - SelectClipRgn(hdc, clipRegion); + SelectClipRgn( hdc, clipRegion); + if (clipRegion) DeleteObject( clipRegion ); } else { @@ -2153,14 +2135,24 @@ return SendMessageW(lphc->hWndLBox, LB_GETLOCALE, 0, 0); case CB_SETLOCALE: return SendMessageW(lphc->hWndLBox, LB_SETLOCALE, wParam, 0); + case CB_SETDROPPEDWIDTH: + if( (CB_GETTYPE(lphc) == CBS_SIMPLE) || + (INT)wParam >= 32768 ) + return CB_ERR; + /* new value must be higher than combobox width */ + if((INT)wParam >= lphc->droppedRect.right - lphc->droppedRect.left) + lphc->droppedWidth = wParam; + else if(wParam) + lphc->droppedWidth = 0; + + /* recalculate the combobox area */ + CBCalcPlacement(hwnd, lphc, &lphc->textRect, &lphc->buttonRect, &lphc->droppedRect ); + + /* fall through */ case CB_GETDROPPEDWIDTH: if( lphc->droppedWidth ) return lphc->droppedWidth; return lphc->droppedRect.right - lphc->droppedRect.left; - case CB_SETDROPPEDWIDTH: - if( (CB_GETTYPE(lphc) != CBS_SIMPLE) && - (INT)wParam < 32768 ) lphc->droppedWidth = (INT)wParam; - return CB_ERR; case CB_GETDROPPEDCONTROLRECT: if( lParam ) CBGetDroppedControlRect(lphc, (LPRECT)lParam ); return CB_OKAY; @@ -2233,7 +2225,7 @@ case CB_LIMITTEXT: if( lphc->wState & CBF_EDIT ) return SendMessageW(lphc->hWndEdit, EM_LIMITTEXT, wParam, lParam); - break; // ReactOS!!! removed at revision 38715 + return TRUE; case WM_UPDATEUISTATE: if (unicode) Modified: trunk/reactos/dll/win32/user32/controls/edit.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/controls/…
============================================================================== --- trunk/reactos/dll/win32/user32/controls/edit.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/user32/controls/edit.c [iso-8859-1] Wed Dec 7 09:23:04 2011 @@ -85,6 +85,7 @@ LINE_END ending; INT width; /* width of the line in pixels */ INT index; /* line index into the buffer */ + SCRIPT_STRING_ANALYSIS ssa; /* Uniscribe Data */ struct tagLINEDEF *next; } LINEDEF; @@ -141,6 +142,11 @@ */ UINT composition_len; /* length of composition, 0 == no composition */ int composition_start; /* the character position for the composition */ + /* + * Uniscribe Data + */ + SCRIPT_LOGATTR *logAttr; + SCRIPT_STRING_ANALYSIS ssa; /* Uniscribe Data for single line controls */ } EDITSTATE; @@ -158,6 +164,7 @@ } while(0) static const WCHAR empty_stringW[] = {0}; +static LRESULT EDIT_EM_PosFromChar(EDITSTATE *es, INT index, BOOL after_wrap); /********************************************************************* * @@ -233,6 +240,14 @@ } +static inline UINT get_text_length(EDITSTATE *es) +{ + if(es->text_length == (UINT)-1) + es->text_length = strlenW(es->text); + return es->text_length; +} + + /********************************************************************* * * EDIT_WordBreakProc @@ -242,61 +257,51 @@ * allows to be called without linebreaks between s[0] up to * s[count - 1]. Remember it is only called * internally, so we can decide this for ourselves. - * - */ -static INT EDIT_WordBreakProc(LPWSTR s, INT index, INT count, INT action) -{ - INT ret = 0; - - TRACE("s=%p, index=%d, count=%d, action=%d\n", s, index, count, action); - - if(!s) return 0; - - switch (action) { - case WB_LEFT: - if (!count) - break; - if (index) - index--; - if (s[index] == ' ') { - while (index && (s[index] == ' ')) - index--; - if (index) { - while (index && (s[index] != ' ')) - index--; - if (s[index] == ' ') - index++; - } - } else { - while (index && (s[index] != ' ')) - index--; - if (s[index] == ' ') - index++; - } - ret = index; - break; - case WB_RIGHT: - if (!count) - break; - if (index) - index--; - if (s[index] == ' ') - while ((index < count) && (s[index] == ' ')) index++; - else { - while (s[index] && (s[index] != ' ') && (index < count)) - index++; - while ((s[index] == ' ') && (index < count)) index++; - } - ret = index; - break; - case WB_ISDELIMITER: - ret = (s[index] == ' '); - break; - default: - ERR("unknown action code, please report !\n"); - break; - } - return ret; + * Additional we will always be breaking the full string. + * + */ +static INT EDIT_WordBreakProc(EDITSTATE *es, LPWSTR s, INT index, INT count, INT action) +{ + INT ret = 0; + + TRACE("s=%p, index=%d, count=%d, action=%d\n", s, index, count, action); + + if(!s) return 0; + + if (!es->logAttr) + { + SCRIPT_ANALYSIS psa; + + memset(&psa,0,sizeof(SCRIPT_ANALYSIS)); + psa.eScript = SCRIPT_UNDEFINED; + + es->logAttr = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPT_LOGATTR) * get_text_length(es)); + ScriptBreak(es->text, get_text_length(es), &psa, es->logAttr); + } + + switch (action) { + case WB_LEFT: + if (index) + index--; + while (index && !es->logAttr[index].fSoftBreak) + index--; + ret = index; + break; + case WB_RIGHT: + if (!count) + break; + while (s[index] && index < count && !es->logAttr[index].fSoftBreak) + index++; + ret = index; + break; + case WB_ISDELIMITER: + ret = es->logAttr[index].fWhiteSpace; + break; + default: + ERR("unknown action code, please report !\n"); + break; + } + return ret; } @@ -344,9 +349,108 @@ } } else - ret = EDIT_WordBreakProc(es->text + start, index, count, action); + ret = EDIT_WordBreakProc(es, es->text, index+start, count+start, action) - start; return ret; +} + +static inline void EDIT_InvalidateUniscribeData_linedef(LINEDEF *line_def) +{ + if (line_def->ssa) + { + ScriptStringFree(&line_def->ssa); + line_def->ssa = NULL; + } +} + +static inline void EDIT_InvalidateUniscribeData(EDITSTATE *es) +{ + LINEDEF *line_def = es->first_line_def; + while (line_def) + { + EDIT_InvalidateUniscribeData_linedef(line_def); + line_def = line_def->next; + } + if (es->ssa) + { + ScriptStringFree(&es->ssa); + es->ssa = NULL; + } +} + +static SCRIPT_STRING_ANALYSIS EDIT_UpdateUniscribeData_linedef(EDITSTATE *es, HDC dc, LINEDEF *line_def) +{ + if (!line_def) + return NULL; + + if (line_def->net_length && !line_def->ssa) + { + int index = line_def->index; + HFONT old_font = NULL; + HDC udc = dc; + SCRIPT_TABDEF tabdef; + + if (!udc) + udc = GetDC(es->hwndSelf); + if (es->font) + old_font = SelectObject(udc, es->font); + + tabdef.cTabStops = es->tabs_count; + tabdef.iScale = 0; + tabdef.pTabStops = es->tabs; + tabdef.iTabOrigin = 0; + + ScriptStringAnalyse(udc, &es->text[index], line_def->net_length, (1.5*line_def->net_length+16), -1, SSA_LINK|SSA_FALLBACK|SSA_GLYPHS|SSA_TAB, -1, NULL, NULL, NULL, &tabdef, NULL, &line_def->ssa); + + if (es->font) + SelectObject(udc, old_font); + if (udc != dc) + ReleaseDC(es->hwndSelf, udc); + } + + return line_def->ssa; +} + +static SCRIPT_STRING_ANALYSIS EDIT_UpdateUniscribeData(EDITSTATE *es, HDC dc, INT line) +{ + LINEDEF *line_def; + + if (!(es->style & ES_MULTILINE)) + { + if (!es->ssa) + { + INT length = get_text_length(es); + HFONT old_font = NULL; + HDC udc = dc; + + if (!udc) + udc = GetDC(es->hwndSelf); + if (es->font) + old_font = SelectObject(udc, es->font); + + if (es->style & ES_PASSWORD) + ScriptStringAnalyse(udc, &es->password_char, length, (1.5*length+16), -1, SSA_LINK|SSA_FALLBACK|SSA_GLYPHS|SSA_PASSWORD, -1, NULL, NULL, NULL, NULL, NULL, &es->ssa); + else + ScriptStringAnalyse(udc, es->text, length, (1.5*length+16), -1, SSA_LINK|SSA_FALLBACK|SSA_GLYPHS, -1, NULL, NULL, NULL, NULL, NULL, &es->ssa); + + if (es->font) + SelectObject(udc, old_font); + if (udc != dc) + ReleaseDC(es->hwndSelf, udc); + } + return es->ssa; + } + else + { + line_def = es->first_line_def; + while (line_def && line) + { + line_def = line_def->next; + line--; + } + + return EDIT_UpdateUniscribeData_linedef(es,dc,line_def); + } } /********************************************************************* @@ -360,8 +464,6 @@ */ static void EDIT_BuildLineDefs_ML(EDITSTATE *es, INT istart, INT iend, INT delta, HRGN hrgn) { - HDC dc; - HFONT old_font = 0; LPWSTR current_position, cp; INT fw; LINEDEF *current_line; @@ -375,10 +477,6 @@ if (istart == iend && delta == 0) return; - dc = GetDC(es->hwndSelf); - if (es->font) - old_font = SelectObject(dc, es->font); - previous_line = NULL; current_line = es->first_line_def; @@ -397,7 +495,6 @@ if (!current_line) /* Error occurred start is not inside previous buffer */ { FIXME(" modification occurred outside buffer\n"); - ReleaseDC(es->hwndSelf, dc); return; } @@ -423,9 +520,9 @@ { /* The buffer has been expanded, create a new line and insert it into the link list */ - LINEDEF *new_line = HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF)); - if (new_line == NULL) // reactos r33509 - break; // reactos r33509 + LINEDEF *new_line = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LINEDEF)); + if (new_line == NULL) // reactos r33509 + break; // reactos r33509 new_line->next = previous_line->next; previous_line->next = new_line; current_line = new_line; @@ -475,33 +572,69 @@ current_line->net_length = cp - current_position; } - /* Calculate line width */ - current_line->width = (INT)LOWORD(GetTabbedTextExtentW(dc, - current_position, current_line->net_length, - es->tabs_count, es->tabs)); + if (current_line->net_length) + { + const SIZE *sz; + EDIT_InvalidateUniscribeData_linedef(current_line); + EDIT_UpdateUniscribeData_linedef(es, NULL, current_line); + sz = ScriptString_pSize(current_line->ssa); + /* Calculate line width */ + current_line->width = sz->cx; + } + else current_line->width = 0; /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */ + +/* Line breaks just look back from the end and find the next break and try that. */ + if (!(es->style & ES_AUTOHSCROLL)) { - if (current_line->width > fw) { - INT next = 0; - INT prev; + if (current_line->width > fw && fw > es->char_width) { + + INT prev, next; + int w; + const SIZE *sz; + float d; + + prev = current_line->net_length - 1; + w = current_line->net_length; + d = (float)current_line->width/(float)fw; + if (d > 1.2) d -= 0.2; + next = prev/d; + if (next >= prev) next = prev-1; do { - prev = next; - next = EDIT_CallWordBreakProc(es, current_position - es->text, - prev + 1, current_line->net_length, WB_RIGHT); - current_line->width = (INT)LOWORD(GetTabbedTextExtentW(dc, - current_position, next, es->tabs_count, es->tabs)); - } while (current_line->width <= fw); - if (!prev) { /* Didn't find a line break so force a break */ - next = 0; + prev = EDIT_CallWordBreakProc(es, current_position - es->text, + next, current_line->net_length, WB_LEFT); + current_line->net_length = prev; + EDIT_InvalidateUniscribeData_linedef(current_line); + EDIT_UpdateUniscribeData_linedef(es, NULL, current_line); + sz = ScriptString_pSize(current_line->ssa); + if (sz) + current_line->width = sz->cx; + else + prev = 0; + next = prev - 1; + } while (prev && current_line->width > fw); + current_line->net_length = w; + + if (prev == 0) { /* Didn't find a line break so force a break */ + INT *piDx; + const INT *count; + + EDIT_InvalidateUniscribeData_linedef(current_line); + EDIT_UpdateUniscribeData_linedef(es, NULL, current_line); + + count = ScriptString_pcOutChars(current_line->ssa); + piDx = HeapAlloc(GetProcessHeap(),0,sizeof(INT) * (*count)); + ScriptStringGetLogicalWidths(current_line->ssa,piDx); + + prev = current_line->net_length-1; do { - prev = next; - next++; - current_line->width = (INT)LOWORD(GetTabbedTextExtentW(dc, - current_position, next, es->tabs_count, es->tabs)); - } while (current_line->width <= fw); - if (!prev) + current_line->width -= piDx[prev]; + prev--; + } while ( prev > 0 && current_line->width > fw); + if (prev<=0) prev = 1; + HeapFree(GetProcessHeap(),0,piDx); } /* If the first line we are calculating, wrapped before istart, we must @@ -522,8 +655,14 @@ current_line->net_length = prev; current_line->ending = END_WRAP; - current_line->width = (INT)LOWORD(GetTabbedTextExtentW(dc, current_position, - current_line->net_length, es->tabs_count, es->tabs)); + + if (current_line->net_length > 0) + { + EDIT_UpdateUniscribeData_linedef(es, NULL, current_line); + sz = ScriptString_pSize(current_line->ssa); + current_line->width = sz->cx; + } + else current_line->width = 0; } else if (current_line == start_line && current_line->index != nstart_index && @@ -570,6 +709,7 @@ while (current_line) { pnext = current_line->next; + EDIT_InvalidateUniscribeData_linedef(current_line); HeapFree(GetProcessHeap(), 0, current_line); current_line = pnext; es->line_count--; @@ -599,9 +739,7 @@ if ((es->style & ES_CENTER) || (es->style & ES_RIGHT)) rc.left = es->format_rect.left; else - rc.left = es->format_rect.left + (INT)LOWORD(GetTabbedTextExtentW(dc, - es->text + nstart_index, istart - nstart_index, - es->tabs_count, es->tabs)) - es->x_offset; /* Adjust for horz scroll */ + rc.left = LOWORD(EDIT_EM_PosFromChar(es, nstart_index, FALSE)); rc.right = es->format_rect.right; SetRectRgn(hrgn, rc.left, rc.top, rc.right, rc.bottom); @@ -624,40 +762,6 @@ CombineRgn(hrgn, hrgn, tmphrgn, RGN_OR); DeleteObject(tmphrgn); } - - if (es->font) - SelectObject(dc, old_font); - - ReleaseDC(es->hwndSelf, dc); -} - - -static inline UINT get_text_length(EDITSTATE *es) -{ - if(es->text_length == (UINT)-1) - es->text_length = strlenW(es->text); - return es->text_length; -} - -/********************************************************************* - * - * EDIT_GetPasswordPointer_SL - * - * note: caller should free the (optionally) allocated buffer - * - */ -static LPWSTR EDIT_GetPasswordPointer_SL(EDITSTATE *es) -{ - if (es->style & ES_PASSWORD) { - INT len = get_text_length(es); - LPWSTR text = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR)); - if (text == NULL) - return NULL; - text[len] = '\0'; - while(len) text[--len] = es->password_char; - return text; - } else - return es->text; } @@ -668,27 +772,15 @@ */ static void EDIT_CalcLineWidth_SL(EDITSTATE *es) { - SIZE size; - LPWSTR text; - HDC dc; - HFONT old_font = 0; - - text = EDIT_GetPasswordPointer_SL(es); - - dc = GetDC(es->hwndSelf); - if (es->font) - old_font = SelectObject(dc, es->font); - - GetTextExtentPoint32W(dc, text, strlenW(text), &size); - - if (es->font) - SelectObject(dc, old_font); - ReleaseDC(es->hwndSelf, dc); - - if (es->style & ES_PASSWORD) - HeapFree(GetProcessHeap(), 0, text); - - es->text_width = size.cx; + EDIT_UpdateUniscribeData(es, NULL, 0); + if (es->ssa) + { + const SIZE *size; + size = ScriptString_pSize(es->ssa); + es->text_width = size->cx; + } + else + es->text_width = 0; } /********************************************************************* @@ -704,20 +796,19 @@ static INT EDIT_CharFromPos(EDITSTATE *es, INT x, INT y, LPBOOL after_wrap) { INT index; - HDC dc; - HFONT old_font = 0; - INT x_high = 0, x_low = 0; if (es->style & ES_MULTILINE) { + int trailing; INT line = (y - es->format_rect.top) / es->line_height + es->y_offset; INT line_index = 0; LINEDEF *line_def = es->first_line_def; - INT low, high; + EDIT_UpdateUniscribeData(es, NULL, line); while ((line > 0) && line_def->next) { line_index += line_def->length; line_def = line_def->next; line--; } + x += es->x_offset - es->format_rect.left; if (es->style & ES_RIGHT) x -= (es->format_rect.right - es->format_rect.left) - line_def->width; @@ -728,39 +819,21 @@ *after_wrap = (line_def->ending == END_WRAP); return line_index + line_def->net_length; } - if (x <= 0) { + if (x <= 0 || !line_def->ssa) { if (after_wrap) *after_wrap = FALSE; return line_index; } - dc = GetDC(es->hwndSelf); - if (es->font) - old_font = SelectObject(dc, es->font); - low = line_index; - high = line_index + line_def->net_length + 1; - while (low < high - 1) - { - INT mid = (low + high) / 2; - INT x_now = LOWORD(GetTabbedTextExtentW(dc, es->text + line_index, mid - line_index, es->tabs_count, es->tabs)); - if (x_now > x) { - high = mid; - x_high = x_now; - } else { - low = mid; - x_low = x_now; - } - } - if (abs(x_high - x) + 1 <= abs(x_low - x)) - index = high; - else - index = low; - + + ScriptStringXtoCP(line_def->ssa, x , &index, &trailing); + if (trailing) index++; + index += line_index; if (after_wrap) *after_wrap = ((index == line_index + line_def->net_length) && (line_def->ending == END_WRAP)); } else { - LPWSTR text; - SIZE size; + INT xoff = 0; + INT trailing; if (after_wrap) *after_wrap = FALSE; x -= es->format_rect.left; @@ -776,60 +849,55 @@ x -= indent / 2; } - text = EDIT_GetPasswordPointer_SL(es); - dc = GetDC(es->hwndSelf); - if (es->font) - old_font = SelectObject(dc, es->font); + EDIT_UpdateUniscribeData(es, NULL, 0); + if (es->x_offset) + { + if (es->ssa) + { + if (es->x_offset>= get_text_length(es)) + { + const SIZE *size; + size = ScriptString_pSize(es->ssa); + xoff = size->cx; + } + ScriptStringCPtoX(es->ssa, es->x_offset, FALSE, &xoff); + } + else + xoff = 0; + } if (x < 0) - { - INT low = 0; - INT high = es->x_offset; - while (low < high - 1) - { - INT mid = (low + high) / 2; - GetTextExtentPoint32W( dc, text + mid, - es->x_offset - mid, &size ); - if (size.cx > -x) { - low = mid; - x_low = size.cx; - } else { - high = mid; - x_high = size.cx; - } - } - if (abs(x_high + x) <= abs(x_low + x) + 1) - index = high; - else - index = low; - } - else - { - INT low = es->x_offset; - INT high = get_text_length(es) + 1; - while (low < high - 1) - { - INT mid = (low + high) / 2; - GetTextExtentPoint32W( dc, text + es->x_offset, - mid - es->x_offset, &size ); - if (size.cx > x) { - high = mid; - x_high = size.cx; - } else { - low = mid; - x_low = size.cx; - } - } - if (abs(x_high - x) <= abs(x_low - x) + 1) - index = high; - else - index = low; - } - if (es->style & ES_PASSWORD) - HeapFree(GetProcessHeap(), 0, text); - } - if (es->font) - SelectObject(dc, old_font); - ReleaseDC(es->hwndSelf, dc); + { + if (x + xoff > 0 || !es->ssa) + { + ScriptStringXtoCP(es->ssa, x+xoff, &index, &trailing); + if (trailing) index++; + } + else + index = 0; + } + else + { + if (x) + { + const SIZE *size = NULL; + if (es->ssa) + size = ScriptString_pSize(es->ssa); + if (!size) + index = 0; + else if (x > size->cx) + index = get_text_length(es); + else if (es->ssa) + { + ScriptStringXtoCP(es->ssa, x+xoff, &index, &trailing); + if (trailing) index++; + } + else + index = 0; + } + else + index = es->x_offset; + } + } return index; } @@ -959,22 +1027,17 @@ INT len = get_text_length(es); INT l; INT li; - INT x; + INT x = 0; INT y = 0; INT w; INT lw = 0; - INT ll = 0; - HDC dc; - HFONT old_font = 0; - SIZE size; LINEDEF *line_def; index = min(index, len); - dc = GetDC(es->hwndSelf); - if (es->font) - old_font = SelectObject(dc, es->font); if (es->style & ES_MULTILINE) { l = EDIT_EM_LineFromChar(es, index); + EDIT_UpdateUniscribeData(es, NULL, l); + y = (l - es->y_offset) * es->line_height; li = EDIT_EM_LineIndex(es, l); if (after_wrap && (li == index) && l) { @@ -995,38 +1058,63 @@ while (line_def->index != li) line_def = line_def->next; - ll = line_def->net_length; + if (!line_def->ssa) + return 0; + lw = line_def->width; - w = es->format_rect.right - es->format_rect.left; + ScriptStringCPtoX(line_def->ssa, (index - 1) - li, TRUE, &x); + x -= es->x_offset; + if (es->style & ES_RIGHT) + x = w - (lw - x); + else if (es->style & ES_CENTER) + x += (w - lw) / 2; + } else { + INT xoff = 0; + INT xi = 0; + EDIT_UpdateUniscribeData(es, NULL, 0); + if (es->x_offset) { - x = LOWORD(GetTabbedTextExtentW(dc, es->text + li + (index - li), ll - (index - li), - es->tabs_count, es->tabs)) - es->x_offset; - x = w - x; - } - else if (es->style & ES_CENTER) + if (es->ssa) + { + if (es->x_offset >= get_text_length(es)) + { + if (es->ssa) + { + const SIZE *size; + size = ScriptString_pSize(es->ssa); + xoff = size->cx; + } + else + xoff = 0; + } + ScriptStringCPtoX(es->ssa, es->x_offset, FALSE, &xoff); + } + else + xoff = 0; + } + if (index) { - x = LOWORD(GetTabbedTextExtentW(dc, es->text + li, index - li, - es->tabs_count, es->tabs)) - es->x_offset; - x += (w - lw) / 2; - } - else /* ES_LEFT */ - { - x = LOWORD(GetTabbedTextExtentW(dc, es->text + li, index - li, - es->tabs_count, es->tabs)) - es->x_offset; - } - } else { - LPWSTR text = EDIT_GetPasswordPointer_SL(es); - if (index < es->x_offset) { - GetTextExtentPoint32W(dc, text + index, - es->x_offset - index, &size); - x = -size.cx; - } else { - GetTextExtentPoint32W(dc, text + es->x_offset, - index - es->x_offset, &size); - x = size.cx; - + if (index >= get_text_length(es)) + { + if (es->ssa) + { + const SIZE *size; + size = ScriptString_pSize(es->ssa); + xi = size->cx; + } + else + xi = 0; + } + else if (es->ssa) + ScriptStringCPtoX(es->ssa, index, FALSE, &xi); + else + xi = 0; + } + x = xi - xoff; + + if (index >= es->x_offset) { if (!es->x_offset && (es->style & (ES_RIGHT | ES_CENTER))) { w = es->format_rect.right - es->format_rect.left; @@ -1040,14 +1128,9 @@ } } y = 0; - if (es->style & ES_PASSWORD) - HeapFree(GetProcessHeap(), 0, text); } x += es->format_rect.left; y += es->format_rect.top; - if (es->font) - SelectObject(dc, old_font); - ReleaseDC(es->hwndSelf, dc); return MAKELONG((INT16)x, (INT16)y); } @@ -1063,20 +1146,27 @@ static void EDIT_GetLineRect(EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc) { INT line_index = EDIT_EM_LineIndex(es, line); + INT pt1, pt2; if (es->style & ES_MULTILINE) rc->top = es->format_rect.top + (line - es->y_offset) * es->line_height; else rc->top = es->format_rect.top; rc->bottom = rc->top + es->line_height; - rc->left = (scol == 0) ? es->format_rect.left : (short)LOWORD(EDIT_EM_PosFromChar(es, line_index + scol, TRUE)); - rc->right = (ecol == -1) ? es->format_rect.right : (short)LOWORD(EDIT_EM_PosFromChar(es, line_index + ecol, TRUE)); + pt1 = (scol == 0) ? es->format_rect.left : (short)LOWORD(EDIT_EM_PosFromChar(es, line_index + scol, TRUE)); + pt2 = (ecol == -1) ? es->format_rect.right : (short)LOWORD(EDIT_EM_PosFromChar(es, line_index + ecol, TRUE)); + rc->right = max(pt1 , pt2); + rc->left = min(pt1, pt2); } static inline void text_buffer_changed(EDITSTATE *es) { es->text_length = (UINT)-1; + + HeapFree( GetProcessHeap(), 0, es->logAttr ); + es->logAttr = NULL; + EDIT_InvalidateUniscribeData(es); } /********************************************************************* @@ -2035,7 +2125,7 @@ ret = (INT)LOWORD(TabbedTextOutW(dc, x, y, es->text + li + col, count, es->tabs_count, es->tabs, es->format_rect.left - es->x_offset)); } else { - LPWSTR text = EDIT_GetPasswordPointer_SL(es); + LPWSTR text = es->text; TextOutW(dc, x, y, text + li + col, count); GetTextExtentPoint32W(dc, text + li + col, count, &size); ret = size.cx; @@ -2068,13 +2158,14 @@ */ static void EDIT_PaintLine(EDITSTATE *es, HDC dc, INT line, BOOL rev) { - INT s = es->selection_start; - INT e = es->selection_end; - INT li; - INT ll; + INT s = 0; + INT e = 0; + INT li = 0; + INT ll = 0; INT x; INT y; LRESULT pos; + SCRIPT_STRING_ANALYSIS ssa; if (es->style & ES_MULTILINE) { INT vlc = get_vertical_line_count(es); @@ -2086,16 +2177,49 @@ TRACE("line=%d\n", line); + ssa = EDIT_UpdateUniscribeData(es, dc, line); pos = EDIT_EM_PosFromChar(es, EDIT_EM_LineIndex(es, line), FALSE); x = (short)LOWORD(pos); y = (short)HIWORD(pos); - li = EDIT_EM_LineIndex(es, line); - ll = EDIT_EM_LineLength(es, li); - s = min(es->selection_start, es->selection_end); - e = max(es->selection_start, es->selection_end); - s = min(li + ll, max(li, s)); - e = min(li + ll, max(li, e)); - if (rev && (s != e) && + + if (es->style & ES_MULTILINE) + { + int line_idx = line; + x = -es->x_offset; + if (es->style & ES_RIGHT || es->style & ES_CENTER) + { + LINEDEF *line_def = es->first_line_def; + int w, lw; + + while (line_def && line_idx) + { + line_def = line_def->next; + line_idx--; + } + w = es->format_rect.right - es->format_rect.left; + lw = line_def->width; + + if (es->style & ES_RIGHT) + x = w - (lw - x); + else if (es->style & ES_CENTER) + x += (w - lw) / 2; + } + x += es->format_rect.left; + } + + if (rev) + { + li = EDIT_EM_LineIndex(es, line); + ll = EDIT_EM_LineLength(es, li); + s = min(es->selection_start, es->selection_end); + e = max(es->selection_start, es->selection_end); + s = min(li + ll, max(li, s)); + e = min(li + ll, max(li, e)); + } + + if (ssa) + ScriptStringOut(ssa, x, y, 0, &es->format_rect, s - li, e - li, FALSE); + else if (rev && (s != e) && ((es->flags & EF_FOCUSED) || (es->style & ES_NOHIDESEL))) { x += EDIT_PaintText(es, dc, x, y, line, 0, s - li, FALSE); x += EDIT_PaintText(es, dc, x, y, line, s - li, e - s, TRUE); @@ -2391,6 +2515,7 @@ s = es->selection_start; e = es->selection_end; + EDIT_InvalidateUniscribeData(es); if ((s == e) && !strl) return; @@ -2466,12 +2591,15 @@ } else { INT fw = es->format_rect.right - es->format_rect.left; + EDIT_InvalidateUniscribeData(es); EDIT_CalcLineWidth_SL(es); /* remove chars that don't fit */ if (honor_limit && !(es->style & ES_AUTOHSCROLL) && (es->text_width > fw)) { while ((es->text_width > fw) && s + strl >= s) { strcpyW(es->text + s + strl - 1, es->text + s + strl); strl--; + es->text_length = -1; + EDIT_InvalidateUniscribeData(es); EDIT_CalcLineWidth_SL(es); } text_buffer_changed(es); @@ -2569,6 +2697,7 @@ es->flags &= ~EF_UPDATE; EDIT_NOTIFY_PARENT(es, EN_CHANGE); } + EDIT_InvalidateUniscribeData(es); } @@ -2769,6 +2898,7 @@ SetWindowLongW( es->hwndSelf, GWL_STYLE, style & ~ES_PASSWORD ); es->style &= ~ES_PASSWORD; } + EDIT_InvalidateUniscribeData(es); EDIT_UpdateText(es, NULL, TRUE); } @@ -2795,6 +2925,7 @@ } // reactos r33503 memcpy(es->tabs, tabs, count * sizeof(INT)); } + EDIT_InvalidateUniscribeData(es); return TRUE; } @@ -3125,6 +3256,7 @@ /* Windows places the menu at the edit's center in this case */ GetClientRect(es->hwndSelf, &rc); MapWindowPoints(es->hwndSelf, 0, (POINT *)&rc, 2); + //WIN_GetRectangles( es->hwndSelf, COORDS_SCREEN, NULL, &rc ); x = rc.left + (rc.right - rc.left) / 2; y = rc.top + (rc.bottom - rc.top) / 2; } @@ -3534,6 +3666,9 @@ (es->style & ES_NOHIDESEL)); dc = hdc ? hdc : BeginPaint(es->hwndSelf, &ps); + /* The dc we use for calcualting may not be the one we paint into. + This is the safest action. */ + EDIT_InvalidateUniscribeData(es); GetClientRect(es->hwndSelf, &rcClient); /* get the background brush */ @@ -3646,6 +3781,7 @@ RECT clientRect; es->font = font; + EDIT_InvalidateUniscribeData(es); dc = GetDC(es->hwndSelf); if (font) old_font = SelectObject(dc, font); @@ -3736,7 +3872,8 @@ EDIT_NOTIFY_PARENT(es, EN_CHANGE); } EDIT_EM_ScrollCaret(es); - EDIT_UpdateScrollInfo(es); + EDIT_UpdateScrollInfo(es); + EDIT_InvalidateUniscribeData(es); } @@ -4357,9 +4494,11 @@ cleanup: SetWindowLongPtrW(es->hwndSelf, 0, 0); + EDIT_InvalidateUniscribeData(es); HeapFree(GetProcessHeap(), 0, es->first_line_def); HeapFree(GetProcessHeap(), 0, es->undo_text); if (es->hloc32W) LocalFree(es->hloc32W); + HeapFree(GetProcessHeap(), 0, es->logAttr); HeapFree(GetProcessHeap(), 0, es); return FALSE; } Modified: trunk/reactos/dll/win32/user32/controls/listbox.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/controls/…
============================================================================== --- trunk/reactos/dll/win32/user32/controls/listbox.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/user32/controls/listbox.c [iso-8859-1] Wed Dec 7 09:23:04 2011 @@ -540,9 +540,7 @@ after they are done, so a region has better to exist else everything ends clipped */ GetClientRect(descr->self, &r); - hrgn = CreateRectRgnIndirect(&r); - SelectClipRgn( hdc, hrgn); - DeleteObject( hrgn ); + hrgn = set_control_clipping( hdc, &r ); dis.CtlType = ODT_LISTBOX; dis.CtlID = GetWindowLongPtrW( descr->self, GWLP_ID ); @@ -562,6 +560,8 @@ descr->self, index, item ? debugstr_w(item->str) : "", action, dis.itemState, wine_dbgstr_rect(rect) ); SendMessageW(descr->owner, WM_DRAWITEM, dis.CtlID, (LPARAM)&dis); + SelectClipRgn( hdc, hrgn ); + if (hrgn) DeleteObject( hrgn ); } else { Modified: trunk/reactos/dll/win32/user32/controls/regcontrol.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/controls/…
============================================================================== --- trunk/reactos/dll/win32/user32/controls/regcontrol.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/user32/controls/regcontrol.c [iso-8859-1] Wed Dec 7 09:23:04 2011 @@ -19,12 +19,33 @@ static PFNCLIENT pfnClientW; static PFNCLIENTWORKER pfnClientWorker; -// -// FIXME! -// These are not "System Classes" but Global Classes that are registered -// every time a process is created, so these can be unregistered as the msdn -// documents states. -// + +/*********************************************************************** + * set_control_clipping + * + * Set clipping for a builtin control that uses CS_PARENTDC. + * Return the previous clip region if any. + */ +HRGN set_control_clipping( HDC hdc, const RECT *rect ) +{ + RECT rc = *rect; + HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 ); + + if (GetClipRgn( hdc, hrgn ) != 1) + { + DeleteObject( hrgn ); + hrgn = 0; + } + DPtoLP( hdc, (POINT *)&rc, 2 ); + if (GetLayout( hdc ) & LAYOUT_RTL) /* compensate for the shifting done by IntersectClipRect */ + { + rc.left++; + rc.right++; + } + IntersectClipRect( hdc, rc.left, rc.top, rc.right, rc.bottom ); + return hrgn; +} + static const struct { const struct builtin_class_descr *desc; Modified: trunk/reactos/dll/win32/user32/controls/static.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/controls/…
============================================================================== --- trunk/reactos/dll/win32/user32/controls/static.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/user32/controls/static.c [iso-8859-1] Wed Dec 7 09:23:04 2011 @@ -105,34 +105,6 @@ 0 /* brush */ }; -static void setup_clipping(HWND hwnd, HDC hdc, HRGN *orig) -{ - RECT rc; - HRGN hrgn; - - /* Native control has always a clipping region set (this may be because - * builtin controls uses CS_PARENTDC) and an application depends on it - */ - hrgn = CreateRectRgn(0, 0, 1, 1); - if (GetClipRgn(hdc, hrgn) != 1) - { - DeleteObject(hrgn); - *orig = NULL; - } else - *orig = hrgn; - - GetClientRect(hwnd, &rc); - DPtoLP(hdc, (POINT *)&rc, 2); - IntersectClipRect(hdc, rc.left, rc.top, rc.right, rc.bottom); -} - -static void restore_clipping(HDC hdc, HRGN hrgn) -{ - SelectClipRgn(hdc, hrgn); - if (hrgn != NULL) - DeleteObject(hrgn); -} - /*********************************************************************** * STATIC_SetIcon * @@ -314,12 +286,13 @@ if (!IsRectEmpty(&rc) && IsWindowVisible(hwnd) && staticPaintFunc[style]) { HDC hdc; - HRGN hOrigClipping; + HRGN hrgn; hdc = GetDC( hwnd ); - setup_clipping(hwnd, hdc, &hOrigClipping); + hrgn = set_control_clipping( hdc, &rc ); (staticPaintFunc[style])( hwnd, hdc, full_style ); - restore_clipping(hdc, hOrigClipping); + SelectClipRgn( hdc, hrgn ); + if (hrgn) DeleteObject( hrgn ); ReleaseDC( hwnd, hdc ); } } @@ -426,13 +399,15 @@ case WM_PAINT: { PAINTSTRUCT ps; + RECT rect; HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps); + GetClientRect( hwnd, &rect ); if (staticPaintFunc[style]) { - HRGN hOrigClipping; - setup_clipping(hwnd, hdc, &hOrigClipping); + HRGN hrgn = set_control_clipping( hdc, &rect ); (staticPaintFunc[style])( hwnd, hdc, full_style ); - restore_clipping(hdc, hOrigClipping); + SelectClipRgn( hdc, hrgn ); + if (hrgn) DeleteObject( hrgn ); } if (!wParam) EndPaint(hwnd, &ps); } Modified: trunk/reactos/dll/win32/user32/include/controls.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/include/c…
============================================================================== --- trunk/reactos/dll/win32/user32/include/controls.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/user32/include/controls.h [iso-8859-1] Wed Dec 7 09:23:04 2011 @@ -88,6 +88,8 @@ #define LB_ADDSTRING_UPPER 0x1AC #define LB_ADDSTRING_LOWER 0x1AD +HRGN set_control_clipping( HDC hdc, const RECT *rect ); + LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ); LRESULT WINAPI User32DefWindowProc(HWND,UINT,WPARAM,LPARAM,BOOL); BOOL WINAPI RegisterClientPFN(VOID); Modified: trunk/reactos/dll/win32/user32/include/user32.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/include/u…
============================================================================== --- trunk/reactos/dll/win32/user32/include/user32.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/user32/include/user32.h [iso-8859-1] Wed Dec 7 09:23:04 2011 @@ -22,6 +22,7 @@ #include <windowsx.h> #include <winnls32.h> #include <strsafe.h> +#include <usp10.h> #include <ndk/cmfuncs.h> #include <ndk/kefuncs.h> #include <ndk/obfuncs.h> Modified: trunk/reactos/dll/win32/user32/user32.rbuild URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/user32.rb…
============================================================================== --- trunk/reactos/dll/win32/user32/user32.rbuild [iso-8859-1] (original) +++ trunk/reactos/dll/win32/user32/user32.rbuild [iso-8859-1] Wed Dec 7 09:23:04 2011 @@ -9,6 +9,7 @@ <library>gdi32</library> <library>advapi32</library> <library>imm32</library> + <library>usp10</library> <library>win32ksys</library> <library>pseh</library> <library>ntdll</library> Modified: trunk/reactos/dll/win32/user32/windows/cursoricon.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/windows/c…
============================================================================== --- trunk/reactos/dll/win32/user32/windows/cursoricon.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/user32/windows/cursoricon.c [iso-8859-1] Wed Dec 7 09:23:04 2011 @@ -1453,31 +1453,31 @@ // the size of the mask bitmap always determines the icon size! width = bmpAnd.bmWidth; height = bmpAnd.bmHeight; - if (bmpXor.bmPlanes * bmpXor.bmBitsPixel != 1) + if (bmpXor.bmPlanes * bmpXor.bmBitsPixel != 1 ) { color = CreateBitmap( width, height, bmpXor.bmPlanes, bmpXor.bmBitsPixel, NULL ); - if(!color) - { - ERR("Unable to create color bitmap!\n"); - return NULL; - } + if(!color) + { + ERR("Unable to create color bitmap!\n"); + return NULL; + } mask = CreateBitmap( width, height, 1, 1, NULL ); - if(!mask) - { - ERR("Unable to create mask bitmap!\n"); - DeleteObject(color); - return NULL; - } + if(!mask) + { + ERR("Unable to create mask bitmap!\n"); + DeleteObject(color); + return NULL; + } } else - { - mask = CreateBitmap( width, height * 2, 1, 1, NULL ); - if(!mask) - { - ERR("Unable to create mask bitmap!\n"); - return NULL; - } - } + { + mask = CreateBitmap( width, height * 2, 1, 1, NULL ); + if(!mask) + { + ERR("Unable to create mask bitmap!\n"); + return NULL; + } + } } else { Modified: trunk/reactos/dll/win32/user32/windows/dialog.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/windows/d…
============================================================================== --- trunk/reactos/dll/win32/user32/windows/dialog.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/user32/windows/dialog.c [iso-8859-1] Wed Dec 7 09:23:04 2011 @@ -342,7 +342,9 @@ { template = (LPCSTR)DIALOG_GetControl32( (const WORD *)template, &info, dlgTemplate->dialogEx ); - /* Is this it? */ + info.style &= ~WS_POPUP; + info.style |= WS_CHILD; + if (info.style & WS_BORDER) { info.style &= ~WS_BORDER; @@ -405,6 +407,8 @@ if (!hwndCtrl) { + WARN("control %s %s creation failed\n", debugstr_w(info.className), + debugstr_w(info.windowName)); if (dlgTemplate->style & DS_NOFAILCREATE) continue; return FALSE; } @@ -1013,6 +1017,7 @@ if (dlgProc) { HWND focus = GetNextDlgTabItem( hwnd, 0, FALSE ); + if (!focus) focus = GetNextDlgGroupItem( hwnd, 0, FALSE ); if (SendMessageW( hwnd, WM_INITDIALOG, (WPARAM)focus, param ) && IsWindow( hwnd ) && ((~template.style & DS_CONTROL) || (template.style & WS_VISIBLE))) { @@ -1020,6 +1025,7 @@ * WM_INITDIALOG may have changed the tab order, so find the first * tabstop control again. */ dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE ); + if (!dlgInfo->hwndFocus) dlgInfo->hwndFocus = GetNextDlgGroupItem( hwnd, 0, FALSE ); if( dlgInfo->hwndFocus ) SetFocus( dlgInfo->hwndFocus ); } @@ -1983,41 +1989,52 @@ BOOL WINAPI EndDialog( - HWND hDlg, - INT_PTR nResult) + HWND hwnd, + INT_PTR retval) { BOOL wasEnabled = TRUE; DIALOGINFO * dlgInfo; HWND owner; - if (!(dlgInfo = GETDLGINFO(hDlg))) - { - ERR("got invalid window handle (%p); buggy app !?\n", hDlg); + TRACE("%p %ld\n", hwnd, retval ); + + if (!(dlgInfo = GETDLGINFO(hwnd))) + { + ERR("got invalid window handle (%p); buggy app !?\n", hwnd); return FALSE; } - - dlgInfo->idResult = nResult; + dlgInfo->idResult = retval; dlgInfo->flags |= DF_END; wasEnabled = (dlgInfo->flags & DF_OWNERENABLED); - if (wasEnabled && (owner = GetWindow( hDlg, GW_OWNER ))) + owner = GetWindow( hwnd, GW_OWNER ); + if (wasEnabled && owner) DIALOG_EnableOwner( owner ); /* Windows sets the focus to the dialog itself in EndDialog */ - if (IsChild(hDlg, GetFocus())) - SetFocus( hDlg ); + if (IsChild(hwnd, GetFocus())) + SetFocus( hwnd ); /* Don't have to send a ShowWindow(SW_HIDE), just do SetWindowPos with SWP_HIDEWINDOW as done in Windows */ - SetWindowPos(hDlg, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE + SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW); - if (hDlg == GetActiveWindow()) WinPosActivateOtherWindow( hDlg ); + if (hwnd == GetActiveWindow()) + { + /* If this dialog was given an owner then set the focus to that owner + even when the owner is disabled (normally when a window closes any + disabled windows cannot receive the focus). */ + if (owner) + SetForegroundWindow( owner ); + else + WinPosActivateOtherWindow( hwnd ); + } /* unblock dialog loop */ - PostMessageA(hDlg, WM_NULL, 0, 0); + PostMessageA(hwnd, WM_NULL, 0, 0); return TRUE; }
13 years
1
0
0
0
[jimtabor] 54603: [Usp10] - Sync up to wine head. This will be needed for edit controls. Waiting for Pierres patched to be added!
by jimtabor@svn.reactos.org
Author: jimtabor Date: Wed Dec 7 05:16:30 2011 New Revision: 54603 URL:
http://svn.reactos.org/svn/reactos?rev=54603&view=rev
Log: [Usp10] - Sync up to wine head. This will be needed for edit controls. Waiting for Pierres patched to be added! Added: trunk/reactos/dll/win32/usp10/breaking.c (with props) trunk/reactos/dll/win32/usp10/indic.c (with props) trunk/reactos/dll/win32/usp10/indicsyllable.c (with props) trunk/reactos/dll/win32/usp10/linebreak.c (with props) Modified: trunk/reactos/dll/win32/usp10/CMakeLists.txt trunk/reactos/dll/win32/usp10/bidi.c trunk/reactos/dll/win32/usp10/mirror.c trunk/reactos/dll/win32/usp10/shape.c trunk/reactos/dll/win32/usp10/shaping.c trunk/reactos/dll/win32/usp10/usp10.c trunk/reactos/dll/win32/usp10/usp10.rbuild trunk/reactos/dll/win32/usp10/usp10.spec trunk/reactos/dll/win32/usp10/usp10_internal.h trunk/reactos/dll/win32/usp10/usp10_ros.diff trunk/reactos/include/psdk/usp10.h trunk/reactos/include/psdk/winnt.h [This mail would be too long, it was shortened to contain the URLs only.] Modified: trunk/reactos/dll/win32/usp10/CMakeLists.txt URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/usp10/CMakeLists…
Modified: trunk/reactos/dll/win32/usp10/bidi.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/usp10/bidi.c?rev…
Added: trunk/reactos/dll/win32/usp10/breaking.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/usp10/breaking.c…
Added: trunk/reactos/dll/win32/usp10/indic.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/usp10/indic.c?re…
Added: trunk/reactos/dll/win32/usp10/indicsyllable.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/usp10/indicsylla…
Added: trunk/reactos/dll/win32/usp10/linebreak.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/usp10/linebreak.…
Modified: trunk/reactos/dll/win32/usp10/mirror.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/usp10/mirror.c?r…
Modified: trunk/reactos/dll/win32/usp10/shape.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/usp10/shape.c?re…
Modified: trunk/reactos/dll/win32/usp10/shaping.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/usp10/shaping.c?…
Modified: trunk/reactos/dll/win32/usp10/usp10.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/usp10/usp10.c?re…
Modified: trunk/reactos/dll/win32/usp10/usp10.rbuild URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/usp10/usp10.rbui…
Modified: trunk/reactos/dll/win32/usp10/usp10.spec URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/usp10/usp10.spec…
Modified: trunk/reactos/dll/win32/usp10/usp10_internal.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/usp10/usp10_inte…
Modified: trunk/reactos/dll/win32/usp10/usp10_ros.diff URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/usp10/usp10_ros.…
Modified: trunk/reactos/include/psdk/usp10.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/psdk/usp10.h?rev=5…
Modified: trunk/reactos/include/psdk/winnt.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/psdk/winnt.h?rev=5…
13 years
1
0
0
0
[dgorbachev] 54602: [FREELDR] HACK: Fix booting with Armenian and other "exotic" languages. Bug #6727.
by dgorbachev@svn.reactos.org
Author: dgorbachev Date: Tue Dec 6 17:38:06 2011 New Revision: 54602 URL:
http://svn.reactos.org/svn/reactos?rev=54602&view=rev
Log: [FREELDR] HACK: Fix booting with Armenian and other "exotic" languages. Bug #6727. Modified: trunk/reactos/boot/freeldr/freeldr/windows/wlregistry.c Modified: trunk/reactos/boot/freeldr/freeldr/windows/wlregistry.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windo…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/windows/wlregistry.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/windows/wlregistry.c [iso-8859-1] Tue Dec 6 17:38:06 2011 @@ -225,7 +225,8 @@ if (rc != ERROR_SUCCESS) { //strcpy(szErrorOut, "ACP NLS Setting exists, but isn't readable"); - return FALSE; + //return FALSE; + wcscpy(NameBuffer, L"c_1252.nls"); // HACK: ReactOS bug #6727 } sprintf(AnsiName, "%S", NameBuffer); @@ -243,7 +244,8 @@ if (rc != ERROR_SUCCESS) { //strcpy(szErrorOut, "OEMCP NLS setting exists, but isn't readable"); - return FALSE; + //return FALSE; + wcscpy(NameBuffer, L"c_437.nls"); // HACK: ReactOS bug #6727 } sprintf(OemName, "%S", NameBuffer);
13 years
1
0
0
0
[cgutman] 54601: [NDIS] - Call MiniportReturnPacket at DISPATCH_LEVEL
by cgutman@svn.reactos.org
Author: cgutman Date: Mon Dec 5 23:38:14 2011 New Revision: 54601 URL:
http://svn.reactos.org/svn/reactos?rev=54601&view=rev
Log: [NDIS] - Call MiniportReturnPacket at DISPATCH_LEVEL Modified: trunk/reactos/drivers/network/ndis/ndis/miniport.c Modified: trunk/reactos/drivers/network/ndis/ndis/miniport.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/ndis/ndis/…
============================================================================== --- trunk/reactos/drivers/network/ndis/ndis/miniport.c [iso-8859-1] (original) +++ trunk/reactos/drivers/network/ndis/ndis/miniport.c [iso-8859-1] Mon Dec 5 23:38:14 2011 @@ -262,6 +262,7 @@ { UINT i; PLOGICAL_ADAPTER Adapter; + KIRQL OldIrql; NDIS_DbgPrint(MID_TRACE, ("Returning %d packets\n", NumberOfPackets)); @@ -274,9 +275,11 @@ NDIS_DbgPrint(MAX_TRACE, ("Freeing packet %d (adapter = 0x%p)\n", i, Adapter)); + KeRaiseIrql(DISPATCH_LEVEL, &OldIrql); Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.ReturnPacketHandler( Adapter->NdisMiniportBlock.MiniportAdapterContext, PacketsToReturn[i]); + KeLowerIrql(OldIrql); } } }
13 years
1
0
0
0
[cgutman] 54600: [TCPIP] - Make interface octets in/out stats more accurate
by cgutman@svn.reactos.org
Author: cgutman Date: Mon Dec 5 18:42:21 2011 New Revision: 54600 URL:
http://svn.reactos.org/svn/reactos?rev=54600&view=rev
Log: [TCPIP] - Make interface octets in/out stats more accurate Modified: trunk/reactos/drivers/network/tcpip/datalink/lan.c trunk/reactos/lib/drivers/ip/network/transmit.c Modified: trunk/reactos/drivers/network/tcpip/datalink/lan.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/data…
============================================================================== --- trunk/reactos/drivers/network/tcpip/datalink/lan.c [iso-8859-1] (original) +++ trunk/reactos/drivers/network/tcpip/datalink/lan.c [iso-8859-1] Mon Dec 5 18:42:21 2011 @@ -353,7 +353,8 @@ ("Ether Type = %x Total = %d\n", PacketType, IPPacket.TotalSize)); - Interface->Stats.InBytes += IPPacket.TotalSize; + /* Update interface stats */ + Interface->Stats.InBytes += IPPacket.TotalSize + Adapter->HeaderSize; /* NDIS packet is freed in all of these cases */ switch (PacketType) { @@ -680,6 +681,7 @@ PLAN_ADAPTER Adapter = (PLAN_ADAPTER)Context; KIRQL OldIrql; PNDIS_PACKET XmitPacket; + PIP_INTERFACE Interface = Adapter->Context; TI_DbgPrint(DEBUG_DATALINK, ("Called( NdisPacket %x, Offset %d, Adapter %x )\n", @@ -713,7 +715,7 @@ (*PC(NdisPacket)->DLComplete)(PC(NdisPacket)->Context, NdisPacket, NDIS_STATUS_SUCCESS); - switch (Adapter->Media) { + switch (Adapter->Media) { case NdisMedium802_3: EHeader = (PETH_HEADER)Data; @@ -728,25 +730,25 @@ RtlCopyMemory(EHeader->SrcAddr, Adapter->HWAddress, IEEE_802_ADDR_LENGTH); switch (Type) { - case LAN_PROTO_IPv4: - EHeader->EType = ETYPE_IPv4; - break; - case LAN_PROTO_ARP: - EHeader->EType = ETYPE_ARP; - break; - case LAN_PROTO_IPv6: - EHeader->EType = ETYPE_IPv6; - break; - default: - ASSERT(FALSE); - return; + case LAN_PROTO_IPv4: + EHeader->EType = ETYPE_IPv4; + break; + case LAN_PROTO_ARP: + EHeader->EType = ETYPE_ARP; + break; + case LAN_PROTO_IPv6: + EHeader->EType = ETYPE_IPv6; + break; + default: + ASSERT(FALSE); + return; } break; default: /* FIXME: Support other medias */ break; - } + } TI_DbgPrint( MID_TRACE, ("LinkAddress: %x\n", LinkAddress)); if( LinkAddress ) { @@ -761,11 +763,14 @@ ((PCHAR)LinkAddress)[5] & 0xff)); } - if (Adapter->MTU < Size) { - /* This is NOT a pointer. MSDN explicitly says so. */ - NDIS_PER_PACKET_INFO_FROM_PACKET(NdisPacket, - TcpLargeSendPacketInfo) = (PVOID)((ULONG_PTR)Adapter->MTU); - } + if (Adapter->MTU < Size) { + /* This is NOT a pointer. MSDN explicitly says so. */ + NDIS_PER_PACKET_INFO_FROM_PACKET(NdisPacket, + TcpLargeSendPacketInfo) = (PVOID)((ULONG_PTR)Adapter->MTU); + } + + /* Update interface stats */ + Interface->Stats.OutBytes += Size; TcpipAcquireSpinLock( &Adapter->Lock, &OldIrql ); TI_DbgPrint(MID_TRACE, ("NdisSend\n")); Modified: trunk/reactos/lib/drivers/ip/network/transmit.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/network/tra…
============================================================================== --- trunk/reactos/lib/drivers/ip/network/transmit.c [iso-8859-1] (original) +++ trunk/reactos/lib/drivers/ip/network/transmit.c [iso-8859-1] Mon Dec 5 18:42:21 2011 @@ -234,8 +234,6 @@ * send routine (IPSendFragment) */ { - UINT PacketSize; - TI_DbgPrint(MAX_TRACE, ("Called. IPPacket (0x%X) NCE (0x%X)\n", IPPacket, NCE)); DISPLAY_IP_PACKET(IPPacket); @@ -243,10 +241,6 @@ /* Fetch path MTU now, because it may change */ TI_DbgPrint(MID_TRACE,("PathMTU: %d\n", NCE->Interface->MTU)); - NdisQueryPacketLength(IPPacket->NdisPacket, &PacketSize); - - NCE->Interface->Stats.OutBytes += PacketSize; - return SendFragments(IPPacket, NCE, NCE->Interface->MTU); }
13 years
1
0
0
0
[jimtabor] 54599: - Fix return properties from atom.
by jimtabor@svn.reactos.org
Author: jimtabor Date: Mon Dec 5 07:43:29 2011 New Revision: 54599 URL:
http://svn.reactos.org/svn/reactos?rev=54599&view=rev
Log: - Fix return properties from atom. Modified: trunk/reactos/subsystems/win32/win32k/eng/engwindow.c trunk/reactos/subsystems/win32/win32k/ntuser/simplecall.c trunk/reactos/subsystems/win32/win32k/ntuser/windc.c Modified: trunk/reactos/subsystems/win32/win32k/eng/engwindow.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/en…
============================================================================== --- trunk/reactos/subsystems/win32/win32k/eng/engwindow.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/win32k/eng/engwindow.c [iso-8859-1] Mon Dec 5 07:43:29 2011 @@ -135,14 +135,19 @@ PWND Window, FLONG flChanged) { + PPROPERTY pprop; WNDGDI *Current; HWND hWnd; ASSERT_IRQL_LESS_OR_EQUAL(PASSIVE_LEVEL); hWnd = Window->head.h; - Current = (WNDGDI *)IntGetProp(Window, AtomWndObj); - + pprop = IntGetProp(Window, AtomWndObj); + if (!pprop) + { + return; + } + Current = (WNDGDI *)pprop->Data; if ( gcountPWO && Current && Current->Hwnd == hWnd && Modified: trunk/reactos/subsystems/win32/win32k/ntuser/simplecall.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/nt…
============================================================================== --- trunk/reactos/subsystems/win32/win32k/ntuser/simplecall.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/win32k/ntuser/simplecall.c [iso-8859-1] Mon Dec 5 07:43:29 2011 @@ -633,7 +633,7 @@ UserDerefObjectCo(Window); UserLeave(); - return (DWORD)HelpId; + return (DWORD)HelpId->Data; } case HWND_ROUTINE_REGISTERSHELLHOOKWINDOW: if (IntIsWindow(hWnd)) Modified: trunk/reactos/subsystems/win32/win32k/ntuser/windc.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/nt…
============================================================================== --- trunk/reactos/subsystems/win32/win32k/ntuser/windc.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/win32k/ntuser/windc.c [iso-8859-1] Mon Dec 5 07:43:29 2011 @@ -973,12 +973,15 @@ PWNDGDI pWndgdi; PWND Wnd; HWND hWnd; + PPROPERTY pprop; hWnd = IntWindowFromDC(hdc); if (hWnd && !(Wnd = UserGetWindowObject(hWnd))) { - pWndgdi = (WNDGDI *)IntGetProp(Wnd, AtomWndObj); + pprop = IntGetProp(Wnd, AtomWndObj); + + pWndgdi = (WNDGDI *)pprop->Data; if ( pWndgdi && pWndgdi->Hwnd == hWnd ) {
13 years
1
0
0
0
[cgutman] 54598: [TCPIP] - Fix the overflow fix
by cgutman@svn.reactos.org
Author: cgutman Date: Mon Dec 5 03:51:01 2011 New Revision: 54598 URL:
http://svn.reactos.org/svn/reactos?rev=54598&view=rev
Log: [TCPIP] - Fix the overflow fix Modified: trunk/reactos/drivers/network/tcpip/include/receive.h trunk/reactos/lib/drivers/ip/network/receive.c Modified: trunk/reactos/drivers/network/tcpip/include/receive.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/incl…
============================================================================== --- trunk/reactos/drivers/network/tcpip/include/receive.h [iso-8859-1] (original) +++ trunk/reactos/drivers/network/tcpip/include/receive.h [iso-8859-1] Mon Dec 5 03:51:01 2011 @@ -38,7 +38,7 @@ IP_ADDRESS DstAddr; /* Destination address */ UCHAR Protocol; /* Internet Protocol number */ USHORT Id; /* Identification number */ - IP_HEADER IPv4Header; /* Pointer to IP header */ + PIP_HEADER IPv4Header; /* Pointer to IP header */ UINT HeaderSize; /* Length of IP header */ LIST_ENTRY FragmentListHead; /* IP fragment list */ LIST_ENTRY HoleListHead; /* IP datagram hole list */ Modified: trunk/reactos/lib/drivers/ip/network/receive.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/network/rec…
============================================================================== --- trunk/reactos/lib/drivers/ip/network/receive.c [iso-8859-1] (original) +++ trunk/reactos/lib/drivers/ip/network/receive.c [iso-8859-1] Mon Dec 5 03:51:01 2011 @@ -108,6 +108,12 @@ CurrentEntry = NextEntry; } + if (IPDR->IPv4Header) + { + TI_DbgPrint(DEBUG_IP, ("Freeing IPDR header at (0x%X).\n", IPDR->IPv4Header)); + ExFreePoolWithTag(IPDR->IPv4Header, PACKET_BUFFER_TAG); + } + TI_DbgPrint(DEBUG_IP, ("Freeing IPDR data at (0x%X).\n", IPDR)); ExFreeToNPagedLookasideList(&IPDRList, IPDR); @@ -218,7 +224,7 @@ IPPacket->MappedHeader = FALSE; /* Copy the header into the buffer */ - RtlCopyMemory(IPPacket->Header, &IPDR->IPv4Header, sizeof(IPDR->IPv4Header)); + RtlCopyMemory(IPPacket->Header, IPDR->IPv4Header, IPDR->HeaderSize); Data = (PVOID)((ULONG_PTR)IPPacket->Header + IPDR->HeaderSize); IPPacket->Data = Data; @@ -394,11 +400,21 @@ /* If this is the first fragment, save the IP header */ if (FragFirst == 0) { - TI_DbgPrint(DEBUG_IP, ("First fragment found. Header buffer is at (0x%X). " - "Header size is (%d).\n", &IPDR->IPv4Header, IPPacket->HeaderSize)); - - RtlCopyMemory(&IPDR->IPv4Header, IPPacket->Header, sizeof(IPDR->IPv4Header)); - IPDR->HeaderSize = sizeof(IPDR->IPv4Header); + IPDR->IPv4Header = ExAllocatePoolWithTag(NonPagedPool, + IPPacket->HeaderSize, + PACKET_BUFFER_TAG); + if (!IPDR->IPv4Header) + { + Cleanup(&IPDR->Lock, OldIrql, IPDR); + return; + } + + RtlCopyMemory(IPDR->IPv4Header, IPPacket->Header, IPPacket->HeaderSize); + IPDR->HeaderSize = IPPacket->HeaderSize; + + TI_DbgPrint(DEBUG_IP, ("First fragment found. Header buffer is at (0x%X). " + "Header size is (%d).\n", &IPDR->IPv4Header, IPPacket->HeaderSize)); + } /* Create a buffer, copy the data into it and put it
13 years
1
0
0
0
[cgutman] 54597: [TCPIP] - Massive IPPacket usage overhaul (fix missing frees, initializations, and double frees) - Make IP receive completely agnostic of the buffers and data location (part 2 of 2...
by cgutman@svn.reactos.org
Author: cgutman Date: Mon Dec 5 03:14:50 2011 New Revision: 54597 URL:
http://svn.reactos.org/svn/reactos?rev=54597&view=rev
Log: [TCPIP] - Massive IPPacket usage overhaul (fix missing frees, initializations, and double frees) - Make IP receive completely agnostic of the buffers and data location (part 2 of 2) - Use paged pool for the majority of allocations during receive and assembly - Implement ProtocolReceivePacket for faster performance with 3rd party NIC drivers - Fix a buffer overflow if an IPv4 packet is received with a header larger than 20 bytes - Many more improvements and bug fixes Modified: trunk/reactos/drivers/network/tcpip/datalink/lan.c trunk/reactos/drivers/network/tcpip/include/ip.h trunk/reactos/drivers/network/tcpip/include/receive.h trunk/reactos/drivers/network/tcpip/tcpip/buffer.c trunk/reactos/lib/drivers/ip/network/arp.c trunk/reactos/lib/drivers/ip/network/icmp.c trunk/reactos/lib/drivers/ip/network/ip.c trunk/reactos/lib/drivers/ip/network/loopback.c trunk/reactos/lib/drivers/ip/network/receive.c trunk/reactos/lib/drivers/ip/network/router.c trunk/reactos/lib/drivers/ip/network/routines.c trunk/reactos/lib/drivers/ip/network/transmit.c trunk/reactos/lib/drivers/ip/transport/rawip/rawip.c trunk/reactos/lib/drivers/ip/transport/tcp/if.c trunk/reactos/lib/drivers/ip/transport/udp/udp.c Modified: trunk/reactos/drivers/network/tcpip/datalink/lan.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/data…
============================================================================== --- trunk/reactos/drivers/network/tcpip/datalink/lan.c [iso-8859-1] (original) +++ trunk/reactos/drivers/network/tcpip/datalink/lan.c [iso-8859-1] Mon Dec 5 03:14:50 2011 @@ -12,35 +12,16 @@ UINT TransferDataCalled = 0; UINT TransferDataCompleteCalled = 0; -UINT LanReceiveWorkerCalled = 0; -BOOLEAN LanReceiveWorkerBusy = FALSE; #define CCS_ROOT L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet" #define TCPIP_GUID L"{4D36E972-E325-11CE-BFC1-08002BE10318}" - -#define NGFP(_Packet) \ - { \ - PVOID _Header; \ - ULONG _ContigSize, _TotalSize; \ - PNDIS_BUFFER _NdisBuffer; \ - \ - TI_DbgPrint(MID_TRACE,("Checking Packet %x\n", _Packet)); \ - NdisGetFirstBufferFromPacket(_Packet, \ - &_NdisBuffer, \ - &_Header, \ - &_ContigSize, \ - &_TotalSize); \ - TI_DbgPrint(MID_TRACE,("NdisBuffer: %x\n", _NdisBuffer)); \ - TI_DbgPrint(MID_TRACE,("Header : %x\n", _Header)); \ - TI_DbgPrint(MID_TRACE,("ContigSize: %x\n", _ContigSize)); \ - TI_DbgPrint(MID_TRACE,("TotalSize : %x\n", _TotalSize)); \ - } typedef struct _LAN_WQ_ITEM { LIST_ENTRY ListEntry; PNDIS_PACKET Packet; PLAN_ADAPTER Adapter; UINT BytesTransferred; + BOOLEAN LegacyReceive; } LAN_WQ_ITEM, *PLAN_WQ_ITEM; NDIS_HANDLE NdisProtocolHandle = (NDIS_HANDLE)NULL; @@ -97,6 +78,83 @@ } return NdisStatus; +} + +/* Used by legacy ProtocolReceive for packet type */ +NDIS_STATUS +GetPacketTypeFromHeaderBuffer(PLAN_ADAPTER Adapter, + PVOID HeaderBuffer, + ULONG HeaderBufferSize, + PULONG PacketType) +{ + PETH_HEADER EthHeader = HeaderBuffer; + + if (HeaderBufferSize < Adapter->HeaderSize) + { + TI_DbgPrint(DEBUG_DATALINK, ("Runt frame (size %d).\n", HeaderBufferSize)); + return NDIS_STATUS_NOT_ACCEPTED; + } + + switch (Adapter->Media) + { + case NdisMedium802_3: + /* Ethernet and IEEE 802.3 frames can be destinguished by + looking at the IEEE 802.3 length field. This field is + less than or equal to 1500 for a valid IEEE 802.3 frame + and larger than 1500 is it's a valid EtherType value. + See RFC 1122, section 2.3.3 for more information */ + + *PacketType = EthHeader->EType; + break; + + default: + TI_DbgPrint(MIN_TRACE, ("Unsupported media.\n")); + + /* FIXME: Support other medias */ + return NDIS_STATUS_NOT_ACCEPTED; + } + + TI_DbgPrint(DEBUG_DATALINK, ("EtherType (0x%X).\n", *PacketType)); + + return NDIS_STATUS_SUCCESS; +} + +/* Used by ProtocolReceivePacket for packet type */ +NDIS_STATUS +GetPacketTypeFromNdisPacket(PLAN_ADAPTER Adapter, + PNDIS_PACKET NdisPacket, + PULONG PacketType) +{ + PVOID HeaderBuffer; + ULONG BytesCopied; + NDIS_STATUS Status; + + HeaderBuffer = ExAllocatePool(NonPagedPool, + Adapter->HeaderSize); + if (!HeaderBuffer) + return NDIS_STATUS_RESOURCES; + + /* Copy the media header */ + BytesCopied = CopyPacketToBuffer(HeaderBuffer, + NdisPacket, + 0, + Adapter->HeaderSize); + if (BytesCopied != Adapter->HeaderSize) + { + /* Runt frame */ + ExFreePool(HeaderBuffer); + TI_DbgPrint(DEBUG_DATALINK, ("Runt frame (size %d).\n", BytesCopied)); + return NDIS_STATUS_NOT_ACCEPTED; + } + + Status = GetPacketTypeFromHeaderBuffer(Adapter, + HeaderBuffer, + BytesCopied, + PacketType); + + ExFreePool(HeaderBuffer); + + return Status; } @@ -235,48 +293,67 @@ } VOID LanReceiveWorker( PVOID Context ) { - UINT PacketType; + ULONG PacketType; PLAN_WQ_ITEM WorkItem = (PLAN_WQ_ITEM)Context; PNDIS_PACKET Packet; PLAN_ADAPTER Adapter; UINT BytesTransferred; - PNDIS_BUFFER NdisBuffer; IP_PACKET IPPacket; + BOOLEAN LegacyReceive; + PIP_INTERFACE Interface; TI_DbgPrint(DEBUG_DATALINK, ("Called.\n")); Packet = WorkItem->Packet; Adapter = WorkItem->Adapter; BytesTransferred = WorkItem->BytesTransferred; + LegacyReceive = WorkItem->LegacyReceive; ExFreePoolWithTag(WorkItem, WQ_CONTEXT_TAG); + Interface = Adapter->Context; + IPInitializePacket(&IPPacket, 0); IPPacket.NdisPacket = Packet; - - NdisGetFirstBufferFromPacket(Packet, - &NdisBuffer, - &IPPacket.Header, - &IPPacket.ContigSize, - &IPPacket.TotalSize); - - IPPacket.ContigSize = IPPacket.TotalSize = BytesTransferred; - /* Determine which upper layer protocol that should receive - this packet and pass it to the correct receive handler */ - - TI_DbgPrint(MID_TRACE, - ("ContigSize: %d, TotalSize: %d, BytesTransferred: %d\n", - IPPacket.ContigSize, IPPacket.TotalSize, - BytesTransferred)); - - PacketType = PC(IPPacket.NdisPacket)->PacketType; - IPPacket.Position = 0; + IPPacket.ReturnPacket = !LegacyReceive; + + if (LegacyReceive) + { + /* Packet type is precomputed */ + PacketType = PC(IPPacket.NdisPacket)->PacketType; + + /* Data is at position 0 */ + IPPacket.Position = 0; + + /* Packet size is determined by bytes transferred */ + IPPacket.TotalSize = BytesTransferred; + } + else + { + /* Determine packet type from media header */ + if (GetPacketTypeFromNdisPacket(Adapter, + IPPacket.NdisPacket, + &PacketType) != NDIS_STATUS_SUCCESS) + { + /* Bad packet */ + IPPacket.Free(&IPPacket); + return; + } + + /* Data is at the end of the media header */ + IPPacket.Position = Adapter->HeaderSize; + + /* Calculate packet size (excluding media header) */ + NdisQueryPacketLength(IPPacket.NdisPacket, &IPPacket.TotalSize); + } TI_DbgPrint (DEBUG_DATALINK, - ("Ether Type = %x ContigSize = %d Total = %d\n", - PacketType, IPPacket.ContigSize, IPPacket.TotalSize)); + ("Ether Type = %x Total = %d\n", + PacketType, IPPacket.TotalSize)); + + Interface->Stats.InBytes += IPPacket.TotalSize; /* NDIS packet is freed in all of these cases */ switch (PacketType) { @@ -298,8 +375,8 @@ VOID LanSubmitReceiveWork( NDIS_HANDLE BindingContext, PNDIS_PACKET Packet, - NDIS_STATUS Status, - UINT BytesTransferred) { + UINT BytesTransferred, + BOOLEAN LegacyReceive) { PLAN_WQ_ITEM WQItem = ExAllocatePoolWithTag(NonPagedPool, sizeof(LAN_WQ_ITEM), WQ_CONTEXT_TAG); PLAN_ADAPTER Adapter = (PLAN_ADAPTER)BindingContext; @@ -311,6 +388,7 @@ WQItem->Packet = Packet; WQItem->Adapter = Adapter; WQItem->BytesTransferred = BytesTransferred; + WQItem->LegacyReceive = LegacyReceive; if (!ChewCreate( LanReceiveWorker, WQItem )) ExFreePoolWithTag(WQItem, WQ_CONTEXT_TAG); @@ -342,7 +420,30 @@ if( Status != NDIS_STATUS_SUCCESS ) return; - LanSubmitReceiveWork( BindingContext, Packet, Status, BytesTransferred ); + LanSubmitReceiveWork(BindingContext, + Packet, + BytesTransferred, + TRUE); +} + +INT NTAPI ProtocolReceivePacket( + NDIS_HANDLE BindingContext, + PNDIS_PACKET NdisPacket) +{ + PLAN_ADAPTER Adapter = BindingContext; + + if (Adapter->State != LAN_STATE_STARTED) { + TI_DbgPrint(DEBUG_DATALINK, ("Adapter is stopped.\n")); + return 0; + } + + LanSubmitReceiveWork(BindingContext, + NdisPacket, + 0, /* Unused */ + FALSE); + + /* Hold 1 reference on this packet */ + return 1; } NDIS_STATUS NTAPI ProtocolReceive( @@ -367,15 +468,12 @@ * Status of operation */ { - USHORT EType; - UINT PacketType, BytesTransferred; - UINT temp; - //IP_PACKET IPPacket; + ULONG PacketType; + UINT BytesTransferred; PCHAR BufferData; NDIS_STATUS NdisStatus; PNDIS_PACKET NdisPacket; PLAN_ADAPTER Adapter = (PLAN_ADAPTER)BindingContext; - PETH_HEADER EHeader = (PETH_HEADER)HeaderBuffer; TI_DbgPrint(DEBUG_DATALINK, ("Called. (packetsize %d)\n",PacketSize)); @@ -389,30 +487,17 @@ return NDIS_STATUS_NOT_ACCEPTED; } - if (Adapter->Media == NdisMedium802_3) { - /* Ethernet and IEEE 802.3 frames can be destinguished by - looking at the IEEE 802.3 length field. This field is - less than or equal to 1500 for a valid IEEE 802.3 frame - and larger than 1500 is it's a valid EtherType value. - See RFC 1122, section 2.3.3 for more information */ - /* FIXME: Test for Ethernet and IEEE 802.3 frame */ - if (((EType = EHeader->EType) != ETYPE_IPv4) && (EType != ETYPE_ARP)) { - TI_DbgPrint(DEBUG_DATALINK, ("Not IP or ARP frame. EtherType (0x%X).\n", EType)); - return NDIS_STATUS_NOT_ACCEPTED; - } - /* We use EtherType constants to destinguish packet types */ - PacketType = EType; - } else { - TI_DbgPrint(MIN_TRACE, ("Unsupported media.\n")); - /* FIXME: Support other medias */ + NdisStatus = GetPacketTypeFromHeaderBuffer(Adapter, + HeaderBuffer, + HeaderBufferSize, + &PacketType); + if (NdisStatus != NDIS_STATUS_SUCCESS) return NDIS_STATUS_NOT_ACCEPTED; - } - - /* Get a transfer data packet */ TI_DbgPrint(DEBUG_DATALINK, ("Adapter: %x (MTU %d)\n", Adapter, Adapter->MTU)); + /* Get a transfer data packet */ NdisStatus = AllocatePacketWithBuffer( &NdisPacket, NULL, PacketSize ); if( NdisStatus != NDIS_STATUS_SUCCESS ) { @@ -423,10 +508,7 @@ TI_DbgPrint(DEBUG_DATALINK, ("pretransfer LookaheadBufferSize %d packsize %d\n",LookaheadBufferSize,PacketSize)); - GetDataPtr( NdisPacket, 0, &BufferData, &temp ); - - //IPPacket.NdisPacket = NdisPacket; - //IPPacket.Position = 0; + GetDataPtr( NdisPacket, 0, &BufferData, &PacketSize ); TransferDataCalled++; @@ -1486,6 +1568,7 @@ ProtChars.RequestCompleteHandler = ProtocolRequestComplete; ProtChars.SendCompleteHandler = ProtocolSendComplete; ProtChars.TransferDataCompleteHandler = ProtocolTransferDataComplete; + ProtChars.ReceivePacketHandler = ProtocolReceivePacket; ProtChars.ReceiveHandler = ProtocolReceive; ProtChars.ReceiveCompleteHandler = ProtocolReceiveComplete; ProtChars.StatusHandler = ProtocolStatus; Modified: trunk/reactos/drivers/network/tcpip/include/ip.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/incl…
============================================================================== --- trunk/reactos/drivers/network/tcpip/include/ip.h [iso-8859-1] (original) +++ trunk/reactos/drivers/network/tcpip/include/ip.h [iso-8859-1] Mon Dec 5 03:14:50 2011 @@ -78,11 +78,12 @@ OBJECT_FREE_ROUTINE Free; /* Routine used to free resources for the object */ UCHAR Type; /* Type of IP packet (see IP_ADDRESS_xx above) */ UCHAR Flags; /* Flags for packet (see IP_PACKET_FLAG_xx below)*/ + BOOLEAN MappedHeader; /* States whether Header is from an MDL or allocated from pool */ + BOOLEAN ReturnPacket; /* States whether NdisPacket should be passed to NdisReturnPackets */ PVOID Header; /* Pointer to IP header for this packet */ UINT HeaderSize; /* Size of IP header */ PVOID Data; /* Current pointer into packet data */ UINT TotalSize; /* Total amount of data in packet (IP header and data) */ - UINT ContigSize; /* Number of contiguous bytes left in current buffer */ UINT Position; /* Current logical offset into packet */ PNDIS_PACKET NdisPacket; /* Pointer to NDIS packet */ IP_ADDRESS SrcAddr; /* Source address */ Modified: trunk/reactos/drivers/network/tcpip/include/receive.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/incl…
============================================================================== --- trunk/reactos/drivers/network/tcpip/include/receive.h [iso-8859-1] (original) +++ trunk/reactos/drivers/network/tcpip/include/receive.h [iso-8859-1] Mon Dec 5 03:14:50 2011 @@ -10,12 +10,13 @@ #include <ip.h> /* Number of seconds before destroying the IPDR */ -#define MAX_TIMEOUT_COUNT 5 +#define MAX_TIMEOUT_COUNT 3 /* IP datagram fragment descriptor. Used to store IP datagram fragments */ typedef struct IP_FRAGMENT { LIST_ENTRY ListEntry; /* Entry on list */ PNDIS_PACKET Packet; /* NDIS packet containing fragment data */ + BOOLEAN ReturnPacket; /* States whether to call NdisReturnPackets */ UINT PacketOffset; /* Offset into NDIS packet where data is */ UINT Offset; /* Offset into datagram where this fragment is */ UINT Size; /* Size of this fragment */ Modified: trunk/reactos/drivers/network/tcpip/tcpip/buffer.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/tcpi…
============================================================================== --- trunk/reactos/drivers/network/tcpip/tcpip/buffer.c [iso-8859-1] (original) +++ trunk/reactos/drivers/network/tcpip/tcpip/buffer.c [iso-8859-1] Mon Dec 5 03:14:50 2011 @@ -311,29 +311,6 @@ return OldSize; } -NDIS_STATUS PrependPacket( PNDIS_PACKET Packet, PCHAR Data, UINT Length, - BOOLEAN Copy ) { - PNDIS_BUFFER Buffer; - NDIS_STATUS Status; - PCHAR NewBuf; - - if( Copy ) { - NewBuf = ExAllocatePoolWithTag( NonPagedPool, Length, PACKET_BUFFER_TAG ); - if( !NewBuf ) return NDIS_STATUS_RESOURCES; - RtlCopyMemory( NewBuf, Data, Length ); - } else NewBuf = Data; - - NdisAllocateBuffer( &Status, &Buffer, GlobalBufferPool, NewBuf, Length ); - if( Status != NDIS_STATUS_SUCCESS ) { - if (Copy) ExFreePoolWithTag(NewBuf, PACKET_BUFFER_TAG); - return Status; - } - - NdisChainBufferAtFront( Packet, Buffer ); - - return STATUS_SUCCESS; -} - void GetDataPtr( PNDIS_PACKET Packet, UINT Offset, PCHAR *DataOut, Modified: trunk/reactos/lib/drivers/ip/network/arp.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/network/arp…
============================================================================== --- trunk/reactos/lib/drivers/ip/network/arp.c [iso-8859-1] (original) +++ trunk/reactos/lib/drivers/ip/network/arp.c [iso-8859-1] Mon Dec 5 03:14:50 2011 @@ -185,36 +185,88 @@ PARP_HEADER Header; IP_ADDRESS SrcAddress; IP_ADDRESS DstAddress; - PVOID SenderHWAddress; - PVOID SenderProtoAddress; - PVOID TargetProtoAddress; + PCHAR SenderHWAddress, SenderProtoAddress, TargetProtoAddress; PNEIGHBOR_CACHE_ENTRY NCE; PNDIS_PACKET NdisPacket; PIP_INTERFACE Interface = (PIP_INTERFACE)Context; + ULONG BytesCopied, DataSize; + PCHAR DataBuffer; + + PAGED_CODE(); TI_DbgPrint(DEBUG_ARP, ("Called.\n")); + + Packet->Header = ExAllocatePoolWithTag(PagedPool, + sizeof(ARP_HEADER), + PACKET_BUFFER_TAG); + if (!Packet->Header) + { + TI_DbgPrint(DEBUG_ARP, ("Unable to allocate header buffer\n")); + Packet->Free(Packet); + return; + } + Packet->MappedHeader = FALSE; + + BytesCopied = CopyPacketToBuffer((PCHAR)Packet->Header, + Packet->NdisPacket, + Packet->Position, + sizeof(ARP_HEADER)); + if (BytesCopied != sizeof(ARP_HEADER)) + { + TI_DbgPrint(DEBUG_ARP, ("Unable to copy in header buffer\n")); + Packet->Free(Packet); + return; + } Header = (PARP_HEADER)Packet->Header; /* FIXME: Ethernet only */ if (WN2H(Header->HWType) != 1) { TI_DbgPrint(DEBUG_ARP, ("Unknown ARP hardware type (0x%X).\n", WN2H(Header->HWType))); + Packet->Free(Packet); return; } /* Check protocol type */ if (Header->ProtoType != ETYPE_IPv4) { TI_DbgPrint(DEBUG_ARP, ("Unknown ARP protocol type (0x%X).\n", WN2H(Header->ProtoType))); - return; - } - - SenderHWAddress = (PVOID)((ULONG_PTR)Header + sizeof(ARP_HEADER)); - SenderProtoAddress = (PVOID)((ULONG_PTR)SenderHWAddress + Header->HWAddrLen); - TargetProtoAddress = (PVOID)((ULONG_PTR)SenderProtoAddress + Header->ProtoAddrLen + Header->HWAddrLen); + Packet->Free(Packet); + return; + } + + DataSize = (2 * Header->HWAddrLen) + (2 * Header->ProtoAddrLen); + DataBuffer = ExAllocatePool(PagedPool, + DataSize); + if (!DataBuffer) + { + TI_DbgPrint(DEBUG_ARP, ("Unable to allocate data buffer\n")); + Packet->Free(Packet); + return; + } + + BytesCopied = CopyPacketToBuffer(DataBuffer, + Packet->NdisPacket, + Packet->Position + sizeof(ARP_HEADER), + DataSize); + if (BytesCopied != DataSize) + { + TI_DbgPrint(DEBUG_ARP, ("Unable to copy in data buffer\n")); + ExFreePool(DataBuffer); + Packet->Free(Packet); + return; + } + + SenderHWAddress = (PVOID)(DataBuffer); + SenderProtoAddress = (PVOID)(SenderHWAddress + Header->HWAddrLen); + TargetProtoAddress = (PVOID)(SenderProtoAddress + Header->ProtoAddrLen + Header->HWAddrLen); AddrInitIPv4(&DstAddress, *((PULONG)TargetProtoAddress)); if (!AddrIsEqual(&DstAddress, &Interface->Unicast)) - return; + { + ExFreePool(DataBuffer); + Packet->Free(Packet); + return; + } AddrInitIPv4(&SrcAddress, *((PULONG)SenderProtoAddress)); @@ -233,7 +285,11 @@ } if (Header->Opcode != ARP_OPCODE_REQUEST) - return; + { + ExFreePool(DataBuffer); + Packet->Free(Packet); + return; + } /* This is a request for our address. Swap the addresses and send an ARP reply back to the sender */ @@ -257,6 +313,7 @@ LAN_PROTO_ARP); } + ExFreePool(DataBuffer); Packet->Free(Packet); } Modified: trunk/reactos/lib/drivers/ip/network/icmp.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/network/icm…
============================================================================== --- trunk/reactos/lib/drivers/ip/network/icmp.c [iso-8859-1] (original) +++ trunk/reactos/lib/drivers/ip/network/icmp.c [iso-8859-1] Mon Dec 5 03:14:50 2011 @@ -84,15 +84,16 @@ if( !NT_SUCCESS(NdisStatus) ) return FALSE; IPPacket->NdisPacket = NdisPacket; + IPPacket->MappedHeader = TRUE; GetDataPtr( IPPacket->NdisPacket, 0, - (PCHAR *)&IPPacket->Header, &IPPacket->ContigSize ); + (PCHAR *)&IPPacket->Header, &IPPacket->TotalSize ); + ASSERT(IPPacket->TotalSize == Size); TI_DbgPrint(DEBUG_ICMP, ("Size (%d). Data at (0x%X).\n", Size, Data)); TI_DbgPrint(DEBUG_ICMP, ("NdisPacket at (0x%X).\n", NdisPacket)); IPPacket->HeaderSize = sizeof(IPv4_HEADER); - IPPacket->TotalSize = Size; IPPacket->Data = ((PCHAR)IPPacket->Header) + IPPacket->HeaderSize; TI_DbgPrint(DEBUG_ICMP, ("Copying Address: %x -> %x\n", @@ -135,11 +136,6 @@ return TRUE; } -VOID ICMPSendPacketComplete -( PVOID Context, PNDIS_PACKET Packet, NDIS_STATUS Status ) { - FreeNdisPacket( Packet ); -} - NTSTATUS ICMPSendDatagram( PADDRESS_FILE AddrFile, PTDI_CONNECTION_INFORMATION ConnInfo, @@ -192,8 +188,8 @@ */ if(!(NCE = RouteGetRouteToDestination( &RemoteAddress ))) { - UnlockObject(AddrFile, OldIrql); - return STATUS_NETWORK_UNREACHABLE; + UnlockObject(AddrFile, OldIrql); + return STATUS_NETWORK_UNREACHABLE; } LocalAddress = NCE->Interface->Unicast; @@ -202,8 +198,8 @@ { if(!(NCE = NBLocateNeighbor( &LocalAddress ))) { - UnlockObject(AddrFile, OldIrql); - return STATUS_INVALID_PARAMETER; + UnlockObject(AddrFile, OldIrql); + return STATUS_INVALID_PARAMETER; } } @@ -217,14 +213,16 @@ UnlockObject(AddrFile, OldIrql); if( !NT_SUCCESS(Status) ) - return Status; + return Status; TI_DbgPrint(MID_TRACE,("About to send datagram\n")); Status = IPSendDatagram(&Packet, NCE); - FreeNdisPacket(Packet.NdisPacket); if (!NT_SUCCESS(Status)) + { + Packet.Free(&Packet); return Status; + } *DataUsed = DataSize; @@ -232,7 +230,6 @@ return STATUS_SUCCESS; } - VOID ICMPReceive( @@ -260,8 +257,6 @@ TI_DbgPrint(DEBUG_ICMP, ("Code (%d).\n", ICMPHeader->Code)); TI_DbgPrint(DEBUG_ICMP, ("Checksum (0x%X).\n", ICMPHeader->Checksum)); - - RawIpReceive(Interface, IPPacket); /* Checksum ICMP header and data */ if (!IPv4CorrectChecksum(IPPacket->Data, IPPacket->TotalSize - IPPacket->HeaderSize)) { @@ -270,20 +265,22 @@ return; } + RawIpReceive(Interface, IPPacket); + switch (ICMPHeader->Type) { - case ICMP_TYPE_ECHO_REQUEST: - ICMPReply( Interface, IPPacket, ICMP_TYPE_ECHO_REPLY, 0 ); - return; - - case ICMP_TYPE_ECHO_REPLY: - break; - - default: - TI_DbgPrint(DEBUG_ICMP, - ("Discarded ICMP datagram of unknown type %d.\n", - ICMPHeader->Type)); - /* Discard packet */ - break; + case ICMP_TYPE_ECHO_REQUEST: + ICMPReply( Interface, IPPacket, ICMP_TYPE_ECHO_REPLY, 0 ); + break; + + case ICMP_TYPE_ECHO_REPLY: + break; + + default: + TI_DbgPrint(DEBUG_ICMP, + ("Discarded ICMP datagram of unknown type %d.\n", + ICMPHeader->Type)); + /* Discard packet */ + break; } } @@ -300,7 +297,6 @@ */ { PNEIGHBOR_CACHE_ENTRY NCE; - NTSTATUS Status; TI_DbgPrint(DEBUG_ICMP, ("Called.\n")); @@ -311,14 +307,12 @@ /* Get a route to the destination address */ if ((NCE = RouteGetRouteToDestination(&IPPacket->DstAddr))) { /* Send the packet */ - Status = IPSendDatagram(IPPacket, NCE); - Complete(Context, IPPacket->NdisPacket, Status); + IPSendDatagram(IPPacket, NCE); } else { /* No route to destination (or no free resources) */ TI_DbgPrint(DEBUG_ICMP, ("No route to destination address 0x%X.\n", - IPPacket->DstAddr.Address.IPv4Address)); - /* Discard packet */ - Complete( Context, IPPacket->NdisPacket, NDIS_STATUS_NOT_ACCEPTED ); + IPPacket->DstAddr.Address.IPv4Address)); + IPPacket->Free(IPPacket); } } @@ -343,7 +337,7 @@ */ { UINT DataSize; - IP_PACKET NewPacket = *IPPacket; + IP_PACKET NewPacket; TI_DbgPrint(DEBUG_ICMP, ("Called. Type (%d) Code (%d).\n", Type, Code)); @@ -356,7 +350,7 @@ ((PICMP_HEADER)NewPacket.Data)->Code = Code; ((PICMP_HEADER)NewPacket.Data)->Checksum = 0; - ICMPTransmit(&NewPacket, SendICMPComplete, NULL); + ICMPTransmit(&NewPacket, NULL, NULL); } /* EOF */ Modified: trunk/reactos/lib/drivers/ip/network/ip.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/network/ip.…
============================================================================== --- trunk/reactos/lib/drivers/ip/network/ip.c [iso-8859-1] (original) +++ trunk/reactos/lib/drivers/ip/network/ip.c [iso-8859-1] Mon Dec 5 03:14:50 2011 @@ -40,12 +40,40 @@ { PIP_PACKET IPPacket = Object; + TI_DbgPrint(MAX_TRACE, ("Freeing object: 0x%p\n", Object)); + /* Detect double free */ ASSERT(IPPacket->Type != 0xFF); IPPacket->Type = 0xFF; + /* Check if there's a packet to free */ if (IPPacket->NdisPacket != NULL) - FreeNdisPacket(IPPacket->NdisPacket); + { + if (IPPacket->ReturnPacket) + { + /* Return the packet to the miniport driver */ + TI_DbgPrint(MAX_TRACE, ("Returning packet 0x%p\n", + IPPacket->NdisPacket)); + NdisReturnPackets(&IPPacket->NdisPacket, 1); + } + else + { + /* Free it the conventional way */ + TI_DbgPrint(MAX_TRACE, ("Freeing packet 0x%p\n", + IPPacket->NdisPacket)); + FreeNdisPacket(IPPacket->NdisPacket); + } + } + + /* Check if we have a pool-allocated header */ + if (!IPPacket->MappedHeader && IPPacket->Header) + { + /* Free it */ + TI_DbgPrint(MAX_TRACE, ("Freeing header: 0x%p\n", + IPPacket->Header)); + ExFreePoolWithTag(IPPacket->Header, + PACKET_BUFFER_TAG); + } } VOID FreeIF( Modified: trunk/reactos/lib/drivers/ip/network/loopback.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/network/loo…
============================================================================== --- trunk/reactos/lib/drivers/ip/network/loopback.c [iso-8859-1] (original) +++ trunk/reactos/lib/drivers/ip/network/loopback.c [iso-8859-1] Mon Dec 5 03:14:50 2011 @@ -44,7 +44,6 @@ PNDIS_PACKET XmitPacket; NDIS_STATUS NdisStatus; PIP_PACKET IPPacket; - PNDIS_BUFFER NdisBuffer; ASSERT_KM_POINTER(NdisPacket); ASSERT_KM_POINTER(PC(NdisPacket)); @@ -65,11 +64,12 @@ IPPacket->NdisPacket = XmitPacket; - NdisGetFirstBufferFromPacket(XmitPacket, - &NdisBuffer, - &IPPacket->Header, - &IPPacket->ContigSize, - &IPPacket->TotalSize); + GetDataPtr(IPPacket->NdisPacket, + 0, + (PCHAR*)&IPPacket->Header, + &IPPacket->TotalSize); + + IPPacket->MappedHeader = TRUE; if (!ChewCreate(LoopPassiveWorker, IPPacket)) { Modified: trunk/reactos/lib/drivers/ip/network/receive.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/network/rec…
============================================================================== --- trunk/reactos/lib/drivers/ip/network/receive.c [iso-8859-1] (original) +++ trunk/reactos/lib/drivers/ip/network/receive.c [iso-8859-1] Mon Dec 5 03:14:50 2011 @@ -92,7 +92,14 @@ TI_DbgPrint(DEBUG_IP, ("Freeing fragment packet at (0x%X).\n", CurrentF->Packet)); /* Free the fragment data buffer */ - FreeNdisPacket(CurrentF->Packet); + if (CurrentF->ReturnPacket) + { + NdisReturnPackets(&CurrentF->Packet, 1); + } + else + { + FreeNdisPacket(CurrentF->Packet); + } TI_DbgPrint(DEBUG_IP, ("Freeing fragment at (0x%X).\n", CurrentF)); @@ -189,27 +196,29 @@ PIP_FRAGMENT Fragment; PCHAR Data; + PAGED_CODE(); + TI_DbgPrint(DEBUG_IP, ("Reassembling datagram from IPDR at (0x%X).\n", IPDR)); TI_DbgPrint(DEBUG_IP, ("IPDR->HeaderSize = %d\n", IPDR->HeaderSize)); TI_DbgPrint(DEBUG_IP, ("IPDR->DataSize = %d\n", IPDR->DataSize)); IPPacket->TotalSize = IPDR->HeaderSize + IPDR->DataSize; - IPPacket->ContigSize = IPPacket->TotalSize; IPPacket->HeaderSize = IPDR->HeaderSize; RtlCopyMemory(&IPPacket->SrcAddr, &IPDR->SrcAddr, sizeof(IP_ADDRESS)); RtlCopyMemory(&IPPacket->DstAddr, &IPDR->DstAddr, sizeof(IP_ADDRESS)); /* Allocate space for full IP datagram */ - IPPacket->Header = ExAllocatePoolWithTag(NonPagedPool, IPPacket->TotalSize, PACKET_BUFFER_TAG); + IPPacket->Header = ExAllocatePoolWithTag(PagedPool, IPPacket->TotalSize, PACKET_BUFFER_TAG); if (!IPPacket->Header) { TI_DbgPrint(MIN_TRACE, ("Insufficient resources.\n")); (*IPPacket->Free)(IPPacket); return FALSE; } + IPPacket->MappedHeader = FALSE; /* Copy the header into the buffer */ - RtlCopyMemory(IPPacket->Header, &IPDR->IPv4Header, IPDR->HeaderSize); + RtlCopyMemory(IPPacket->Header, &IPDR->IPv4Header, sizeof(IPDR->IPv4Header)); Data = (PVOID)((ULONG_PTR)IPPacket->Header + IPDR->HeaderSize); IPPacket->Data = Data; @@ -388,8 +397,8 @@ TI_DbgPrint(DEBUG_IP, ("First fragment found. Header buffer is at (0x%X). " "Header size is (%d).\n", &IPDR->IPv4Header, IPPacket->HeaderSize)); - RtlCopyMemory(&IPDR->IPv4Header, IPPacket->Header, IPPacket->HeaderSize); - IPDR->HeaderSize = IPPacket->HeaderSize; + RtlCopyMemory(&IPDR->IPv4Header, IPPacket->Header, sizeof(IPDR->IPv4Header)); + IPDR->HeaderSize = sizeof(IPDR->IPv4Header); } /* Create a buffer, copy the data into it and put it @@ -406,6 +415,7 @@ Fragment->Size = IPPacket->TotalSize - IPPacket->HeaderSize; Fragment->Packet = IPPacket->NdisPacket; + Fragment->ReturnPacket = IPPacket->ReturnPacket; Fragment->PacketOffset = IPPacket->Position + IPPacket->HeaderSize; Fragment->Offset = FragFirst; @@ -428,14 +438,14 @@ Assemble the datagram and pass it to an upper layer protocol */ TI_DbgPrint(DEBUG_IP, ("Complete datagram received.\n")); + + RemoveIPDR(IPDR); + TcpipReleaseSpinLock(&IPDR->Lock, OldIrql); /* FIXME: Assumes IPv4 */ IPInitializePacket(&Datagram, IP_ADDRESS_V4); Success = ReassembleDatagram(&Datagram, IPDR); - - RemoveIPDR(IPDR); - TcpipReleaseSpinLock(&IPDR->Lock, OldIrql); FreeIPDR(IPDR); @@ -448,12 +458,9 @@ /* Give the packet to the protocol dispatcher */ IPDispatchProtocol(IF, &Datagram); - IF->Stats.InBytes += Datagram.TotalSize; - /* We're done with this datagram */ - ExFreePoolWithTag(Datagram.Header, PACKET_BUFFER_TAG); TI_DbgPrint(MAX_TRACE, ("Freeing datagram at (0x%X).\n", Datagram)); - (*Datagram.Free)(&Datagram); + Datagram.Free(&Datagram); } else TcpipReleaseSpinLock(&IPDR->Lock, OldIrql); } @@ -535,69 +542,78 @@ * IPPacket = Pointer to IP packet */ { + UCHAR FirstByte; + ULONG BytesCopied; + TI_DbgPrint(DEBUG_IP, ("Received IPv4 datagram.\n")); - - IPPacket->HeaderSize = (((PIPv4_HEADER)IPPacket->Header)->VerIHL & 0x0F) << 2; + + /* Read in the first IP header byte for size information */ + BytesCopied = CopyPacketToBuffer((PCHAR)&FirstByte, + IPPacket->NdisPacket, + IPPacket->Position, + sizeof(UCHAR)); + if (BytesCopied != sizeof(UCHAR)) + { + TI_DbgPrint(MIN_TRACE, ("Failed to copy in first byte\n")); + /* Discard packet */ + return; + } + + IPPacket->HeaderSize = (FirstByte & 0x0F) << 2; TI_DbgPrint(DEBUG_IP, ("IPPacket->HeaderSize = %d\n", IPPacket->HeaderSize)); if (IPPacket->HeaderSize > IPv4_MAX_HEADER_SIZE) { - TI_DbgPrint - (MIN_TRACE, - ("Datagram received with incorrect header size (%d).\n", + TI_DbgPrint(MIN_TRACE, ("Datagram received with incorrect header size (%d).\n", IPPacket->HeaderSize)); - /* Discard packet */ - return; + /* Discard packet */ + return; + } + + /* This is freed by IPPacket->Free() */ + IPPacket->Header = ExAllocatePoolWithTag(NonPagedPool, + IPPacket->HeaderSize, + PACKET_BUFFER_TAG); + if (!IPPacket->Header) + { + TI_DbgPrint(MIN_TRACE, ("No resources to allocate header\n")); + /* Discard packet */ + return; + } + + IPPacket->MappedHeader = FALSE; + + BytesCopied = CopyPacketToBuffer((PCHAR)IPPacket->Header, + IPPacket->NdisPacket, + IPPacket->Position, + IPPacket->HeaderSize); + if (BytesCopied != IPPacket->HeaderSize) + { + TI_DbgPrint(MIN_TRACE, ("Failed to copy in header\n")); + /* Discard packet */ + return; } /* Checksum IPv4 header */ if (!IPv4CorrectChecksum(IPPacket->Header, IPPacket->HeaderSize)) { - TI_DbgPrint - (MIN_TRACE, - ("Datagram received with bad checksum. Checksum field (0x%X)\n", + TI_DbgPrint(MIN_TRACE, ("Datagram received with bad checksum. Checksum field (0x%X)\n", WN2H(((PIPv4_HEADER)IPPacket->Header)->Checksum))); - /* Discard packet */ - return; + /* Discard packet */ + return; } IPPacket->TotalSize = WN2H(((PIPv4_HEADER)IPPacket->Header)->TotalLength); AddrInitIPv4(&IPPacket->SrcAddr, ((PIPv4_HEADER)IPPacket->Header)->SrcAddr); AddrInitIPv4(&IPPacket->DstAddr, ((PIPv4_HEADER)IPPacket->Header)->DstAddr); - - IPPacket->Data = (PVOID)((ULONG_PTR)IPPacket->Header + IPPacket->HeaderSize); - + TI_DbgPrint(MID_TRACE,("IPPacket->Position = %d\n", - IPPacket->Position)); - - //OskitDumpBuffer(IPPacket->Header, IPPacket->TotalSize); + IPPacket->Position)); /* FIXME: Possibly forward packets with multicast addresses */ /* FIXME: Should we allow packets to be received on the wrong interface? */ /* XXX Find out if this packet is destined for us */ ProcessFragment(IF, IPPacket); -#if 0 - } else { - /* This packet is not destined for us. If we are a router, - try to find a route and forward the packet */ - - /* FIXME: Check if acting as a router */ - NCE = NULL; - if (NCE) { - PROUTE_CACHE_NODE RCN; - - /* FIXME: Possibly fragment datagram */ - /* Forward the packet */ - if(!RouteGetRouteToDestination( &IPPacket->DstAddr, NULL, &RCN )) - IPSendDatagram(IPPacket, RCN, ReflectPacketComplete, IPPacket); - } else { - TI_DbgPrint(MIN_TRACE, ("No route to destination (0x%X).\n", - IPPacket->DstAddr.Address.IPv4Address)); - - /* FIXME: Send ICMP error code */ - } - } -#endif } @@ -609,26 +625,39 @@ * IPPacket = Pointer to IP packet */ { - UINT Version; - - /* Check that IP header has a supported version */ - Version = (((PIPv4_HEADER)IPPacket->Header)->VerIHL >> 4); - - switch (Version) { - case 4: - IPPacket->Type = IP_ADDRESS_V4; - IPv4Receive(IF, IPPacket); - break; - case 6: - IPPacket->Type = IP_ADDRESS_V6; - TI_DbgPrint(MAX_TRACE, ("Datagram of type IPv6 discarded.\n")); - break; - default: - TI_DbgPrint(MIN_TRACE, ("Datagram has an unsupported IP version %d.\n", Version)); - break; - } - - IPPacket->Free(IPPacket); + UCHAR FirstByte; + UINT Version, BytesCopied; + + /* Read in the first IP header byte for version information */ + BytesCopied = CopyPacketToBuffer((PCHAR)&FirstByte, + IPPacket->NdisPacket, + IPPacket->Position, + sizeof(UCHAR)); + if (BytesCopied != sizeof(UCHAR)) + { + TI_DbgPrint(MIN_TRACE, ("Failed to copy in first byte\n")); + IPPacket->Free(IPPacket); + return; + } + + /* Check that IP header has a supported version */ + Version = (FirstByte >> 4); + + switch (Version) { + case 4: + IPPacket->Type = IP_ADDRESS_V4; + IPv4Receive(IF, IPPacket); + break; + case 6: + IPPacket->Type = IP_ADDRESS_V6; + TI_DbgPrint(MAX_TRACE, ("Datagram of type IPv6 discarded.\n")); + break; + default: + TI_DbgPrint(MIN_TRACE, ("Datagram has an unsupported IP version %d.\n", Version)); + break; + } + + IPPacket->Free(IPPacket); } /* EOF */ Modified: trunk/reactos/lib/drivers/ip/network/router.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/network/rou…
============================================================================== --- trunk/reactos/lib/drivers/ip/network/router.c [iso-8859-1] (original) +++ trunk/reactos/lib/drivers/ip/network/router.c [iso-8859-1] Mon Dec 5 03:14:50 2011 @@ -382,8 +382,8 @@ } if( Found ) { - TI_DbgPrint(DEBUG_ROUTER, ("Deleting route\n")); - DestroyFIBE( Current ); + TI_DbgPrint(DEBUG_ROUTER, ("Deleting route\n")); + DestroyFIBE( Current ); } RouterDumpRoutes(); @@ -427,18 +427,18 @@ CurrentEntry = FIBListHead.Flink; while (CurrentEntry != &FIBListHead) { NextEntry = CurrentEntry->Flink; - Current = CONTAINING_RECORD(CurrentEntry, FIB_ENTRY, ListEntry); + Current = CONTAINING_RECORD(CurrentEntry, FIB_ENTRY, ListEntry); NCE = Current->Router; - if( AddrIsEqual(NetworkAddress, &Current->NetworkAddress) && - AddrIsEqual(Netmask, &Current->Netmask) ) { - TI_DbgPrint(DEBUG_ROUTER,("Attempting to add duplicate route to %s\n", A2S(NetworkAddress))); - TcpipReleaseSpinLock(&FIBLock, OldIrql); - return NULL; - } - - CurrentEntry = NextEntry; + if( AddrIsEqual(NetworkAddress, &Current->NetworkAddress) && + AddrIsEqual(Netmask, &Current->Netmask) ) { + TI_DbgPrint(DEBUG_ROUTER,("Attempting to add duplicate route to %s\n", A2S(NetworkAddress))); + TcpipReleaseSpinLock(&FIBLock, OldIrql); + return NULL; + } + + CurrentEntry = NextEntry; } TcpipReleaseSpinLock(&FIBLock, OldIrql); Modified: trunk/reactos/lib/drivers/ip/network/routines.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/network/rou…
============================================================================== --- trunk/reactos/lib/drivers/ip/network/routines.c [iso-8859-1] (original) +++ trunk/reactos/lib/drivers/ip/network/routines.c [iso-8859-1] Mon Dec 5 03:14:50 2011 @@ -60,10 +60,7 @@ PIP_PACKET IPPacket) { #if DBG - PCHAR p; UINT Length; - PNDIS_BUFFER Buffer; - PNDIS_BUFFER NextBuffer; PCHAR CharBuffer; if ((DbgQueryDebugFilterState(DPFLTR_TCPIP_ID, DEBUG_PBUFFER | DPFLTR_MASK) != TRUE) || @@ -76,28 +73,14 @@ return; } - TI_DbgPrint(MIN_TRACE, ("IPPacket is at (0x%X).\n", IPPacket)); + TI_DbgPrint(MIN_TRACE, ("IPPacket is at (0x%X).\n", IPPacket)); TI_DbgPrint(MIN_TRACE, ("Header buffer is at (0x%X).\n", IPPacket->Header)); TI_DbgPrint(MIN_TRACE, ("Header size is (%d).\n", IPPacket->HeaderSize)); TI_DbgPrint(MIN_TRACE, ("TotalSize (%d).\n", IPPacket->TotalSize)); - TI_DbgPrint(MIN_TRACE, ("ContigSize (%d).\n", IPPacket->ContigSize)); TI_DbgPrint(MIN_TRACE, ("NdisPacket (0x%X).\n", IPPacket->NdisPacket)); - if (IPPacket->NdisPacket) { - NdisQueryPacket(IPPacket->NdisPacket, NULL, NULL, &Buffer, NULL); - for (; Buffer != NULL; Buffer = NextBuffer) { - NdisGetNextBuffer(Buffer, &NextBuffer); - NdisQueryBuffer(Buffer, (PVOID)&p, &Length); - //OskitDumpBuffer( p, Length ); - } - } else { - p = IPPacket->Header; - Length = IPPacket->ContigSize; - //OskitDumpBuffer( p, Length ); - } - CharBuffer = IPPacket->Header; - Length = IPPacket->ContigSize; + Length = IPPacket->HeaderSize; DisplayIPHeader(CharBuffer, Length); #endif } Modified: trunk/reactos/lib/drivers/ip/network/transmit.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/network/tra…
============================================================================== --- trunk/reactos/lib/drivers/ip/network/transmit.c [iso-8859-1] (original) +++ trunk/reactos/lib/drivers/ip/network/transmit.c [iso-8859-1] Mon Dec 5 03:14:50 2011 @@ -155,22 +155,26 @@ IPPacket, NCE, PathMTU)); /* Make a smaller buffer if we will only send one fragment */ - GetDataPtr( IPPacket->NdisPacket, 0, &InData, &InSize ); + GetDataPtr( IPPacket->NdisPacket, IPPacket->Position, &InData, &InSize ); if( InSize < BufferSize ) BufferSize = InSize; TI_DbgPrint(MAX_TRACE, ("Fragment buffer is %d bytes\n", BufferSize)); IFC = ExAllocatePoolWithTag(NonPagedPool, sizeof(IPFRAGMENT_CONTEXT), IFC_TAG); if (IFC == NULL) + { + IPPacket->Free(IPPacket); return STATUS_INSUFFICIENT_RESOURCES; + } /* Allocate NDIS packet */ NdisStatus = AllocatePacketWithBuffer ( &IFC->NdisPacket, NULL, BufferSize ); if( !NT_SUCCESS(NdisStatus) ) { - ExFreePoolWithTag( IFC, IFC_TAG ); - return NdisStatus; + IPPacket->Free(IPPacket); + ExFreePoolWithTag( IFC, IFC_TAG ); + return NdisStatus; } GetDataPtr( IFC->NdisPacket, 0, (PCHAR *)&Data, &InSize ); @@ -211,6 +215,7 @@ FreeNdisPacket(IFC->NdisPacket); ExFreePoolWithTag(IFC, IFC_TAG); + IPPacket->Free(IPPacket); return NdisStatus; } @@ -234,16 +239,11 @@ TI_DbgPrint(MAX_TRACE, ("Called. IPPacket (0x%X) NCE (0x%X)\n", IPPacket, NCE)); DISPLAY_IP_PACKET(IPPacket); - /*OskitDumpBuffer( IPPacket->Header, IPPacket->TotalSize );*/ /* Fetch path MTU now, because it may change */ TI_DbgPrint(MID_TRACE,("PathMTU: %d\n", NCE->Interface->MTU)); - NdisQueryPacket(IPPacket->NdisPacket, - NULL, - NULL, - NULL, - &PacketSize); + NdisQueryPacketLength(IPPacket->NdisPacket, &PacketSize); NCE->Interface->Stats.OutBytes += PacketSize; Modified: trunk/reactos/lib/drivers/ip/transport/rawip/rawip.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/transport/r…
============================================================================== --- trunk/reactos/lib/drivers/ip/transport/rawip/rawip.c [iso-8859-1] (original) +++ trunk/reactos/lib/drivers/ip/transport/rawip/rawip.c [iso-8859-1] Mon Dec 5 03:14:50 2011 @@ -43,7 +43,8 @@ GetDataPtr( IPPacket->NdisPacket, 0, (PCHAR *)&IPPacket->Header, - &IPPacket->ContigSize ); + &IPPacket->TotalSize ); + IPPacket->MappedHeader = TRUE; IPPacket->HeaderSize = 20; @@ -144,10 +145,10 @@ } if( !NT_SUCCESS(Status) ) { - TI_DbgPrint(MIN_TRACE, ("Cannot add header. Status = (0x%X)\n", - Status)); - FreeNdisPacket(Packet->NdisPacket); - return Status; + TI_DbgPrint(MIN_TRACE, ("Cannot add header. Status = (0x%X)\n", + Status)); + Packet->Free(Packet); + return Status; } TI_DbgPrint(MID_TRACE, ("Copying data (hdr %x data %x (%d))\n", @@ -199,16 +200,16 @@ TI_DbgPrint(MID_TRACE,("RemoteAddressTa: %x\n", RemoteAddressTa)); switch( RemoteAddressTa->Address[0].AddressType ) { - case TDI_ADDRESS_TYPE_IP: - RemoteAddress.Type = IP_ADDRESS_V4; - RemoteAddress.Address.IPv4Address = - RemoteAddressTa->Address[0].Address[0].in_addr; - RemotePort = RemoteAddressTa->Address[0].Address[0].sin_port; - break; - - default: - UnlockObject(AddrFile, OldIrql); - return STATUS_UNSUCCESSFUL; + case TDI_ADDRESS_TYPE_IP: + RemoteAddress.Type = IP_ADDRESS_V4; + RemoteAddress.Address.IPv4Address = + RemoteAddressTa->Address[0].Address[0].in_addr; + RemotePort = RemoteAddressTa->Address[0].Address[0].sin_port; + break; + + default: + UnlockObject(AddrFile, OldIrql); + return STATUS_UNSUCCESSFUL; } TI_DbgPrint(MID_TRACE,("About to get route to destination\n")); @@ -221,8 +222,8 @@ * interface we're sending over */ if(!(NCE = RouteGetRouteToDestination( &RemoteAddress ))) { - UnlockObject(AddrFile, OldIrql); - return STATUS_NETWORK_UNREACHABLE; + UnlockObject(AddrFile, OldIrql); + return STATUS_NETWORK_UNREACHABLE; } LocalAddress = NCE->Interface->Unicast; @@ -230,8 +231,8 @@ else { if(!(NCE = NBLocateNeighbor( &LocalAddress ))) { - UnlockObject(AddrFile, OldIrql); - return STATUS_INVALID_PARAMETER; + UnlockObject(AddrFile, OldIrql); + return STATUS_INVALID_PARAMETER; } } @@ -247,15 +248,17 @@ UnlockObject(AddrFile, OldIrql); if( !NT_SUCCESS(Status) ) - return Status; + return Status; TI_DbgPrint(MID_TRACE,("About to send datagram\n")); Status = IPSendDatagram(&Packet, NCE); - FreeNdisPacket(Packet.NdisPacket); if (!NT_SUCCESS(Status)) + { + Packet.Free(&Packet); return Status; - + } + *DataUsed = DataSize; TI_DbgPrint(MID_TRACE,("Leaving\n")); Modified: trunk/reactos/lib/drivers/ip/transport/tcp/if.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/transport/t…
============================================================================== --- trunk/reactos/lib/drivers/ip/transport/tcp/if.c [iso-8859-1] (original) +++ trunk/reactos/lib/drivers/ip/transport/tcp/if.c [iso-8859-1] Mon Dec 5 03:14:50 2011 @@ -12,7 +12,7 @@ { NDIS_STATUS NdisStatus; PNEIGHBOR_CACHE_ENTRY NCE; - IP_PACKET Packet = { 0 }; + IP_PACKET Packet; IP_ADDRESS RemoteAddress, LocalAddress; PIPv4_HEADER Header; @@ -33,6 +33,8 @@ return ERR_IF; } + IPInitializePacket(&Packet, LocalAddress.Type); + if (!(NCE = RouteGetRouteToDestination(&RemoteAddress))) { return ERR_RTE; @@ -43,11 +45,12 @@ { return ERR_MEM; } - - GetDataPtr(Packet.NdisPacket, 0, (PCHAR*)&Packet.Header, &Packet.ContigSize); + + GetDataPtr(Packet.NdisPacket, 0, (PCHAR*)&Packet.Header, &Packet.TotalSize); + Packet.MappedHeader = TRUE; ASSERT(p->tot_len == p->len); - ASSERT(Packet.ContigSize == p->len); + ASSERT(Packet.TotalSize == p->len); RtlCopyMemory(Packet.Header, p->payload, p->len); @@ -57,12 +60,12 @@ Packet.DstAddr = RemoteAddress; NdisStatus = IPSendDatagram(&Packet, NCE); - FreeNdisPacket(Packet.NdisPacket); if (!NT_SUCCESS(NdisStatus)) { + Packet.Free(&Packet); return ERR_RTE; } - + return 0; } Modified: trunk/reactos/lib/drivers/ip/transport/udp/udp.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/transport/u…
============================================================================== --- trunk/reactos/lib/drivers/ip/transport/udp/udp.c [iso-8859-1] (original) +++ trunk/reactos/lib/drivers/ip/transport/udp/udp.c [iso-8859-1] Mon Dec 5 03:14:50 2011 @@ -105,33 +105,37 @@ Packet->TotalSize = sizeof(IPv4_HEADER) + sizeof(UDP_HEADER) + DataLen; /* Prepare packet */ - Status = AllocatePacketWithBuffer( &Packet->NdisPacket, - NULL, - Packet->TotalSize ); - - if( !NT_SUCCESS(Status) ) return Status; + Status = AllocatePacketWithBuffer(&Packet->NdisPacket, + NULL, + Packet->TotalSize ); + + if( !NT_SUCCESS(Status) ) + { + Packet->Free(Packet); + return Status; + } TI_DbgPrint(MID_TRACE, ("Allocated packet: %x\n", Packet->NdisPacket)); TI_DbgPrint(MID_TRACE, ("Local Addr : %s\n", A2S(LocalAddress))); TI_DbgPrint(MID_TRACE, ("Remote Addr: %s\n", A2S(RemoteAddress))); switch (RemoteAddress->Type) { - case IP_ADDRESS_V4: - Status = AddUDPHeaderIPv4(AddrFile, RemoteAddress, RemotePort, - LocalAddress, LocalPort, Packet, DataBuffer, DataLen); - break; - case IP_ADDRESS_V6: - /* FIXME: Support IPv6 */ - TI_DbgPrint(MIN_TRACE, ("IPv6 UDP datagrams are not supported.\n")); - default: - Status = STATUS_UNSUCCESSFUL; - break; + case IP_ADDRESS_V4: + Status = AddUDPHeaderIPv4(AddrFile, RemoteAddress, RemotePort, + LocalAddress, LocalPort, Packet, DataBuffer, DataLen); + break; + case IP_ADDRESS_V6: + /* FIXME: Support IPv6 */ + TI_DbgPrint(MIN_TRACE, ("IPv6 UDP datagrams are not supported.\n")); + default: + Status = STATUS_UNSUCCESSFUL; + break; } if (!NT_SUCCESS(Status)) { - TI_DbgPrint(MIN_TRACE, ("Cannot add UDP header. Status = (0x%X)\n", - Status)); - FreeNdisPacket(Packet->NdisPacket); - return Status; + TI_DbgPrint(MIN_TRACE, ("Cannot add UDP header. Status = (0x%X)\n", + Status)); + Packet->Free(Packet); + return Status; } TI_DbgPrint(MID_TRACE, ("Displaying packet\n")); @@ -196,8 +200,8 @@ * interface we're sending over */ if(!(NCE = RouteGetRouteToDestination( &RemoteAddress ))) { - UnlockObject(AddrFile, OldIrql); - return STATUS_NETWORK_UNREACHABLE; + UnlockObject(AddrFile, OldIrql); + return STATUS_NETWORK_UNREACHABLE; } LocalAddress = NCE->Interface->Unicast; @@ -205,8 +209,8 @@ else { if(!(NCE = NBLocateNeighbor( &LocalAddress ))) { - UnlockObject(AddrFile, OldIrql); - return STATUS_INVALID_PARAMETER; + UnlockObject(AddrFile, OldIrql); + return STATUS_INVALID_PARAMETER; } } @@ -225,10 +229,12 @@ return Status; Status = IPSendDatagram(&Packet, NCE); - FreeNdisPacket(Packet.NdisPacket); if (!NT_SUCCESS(Status)) + { + Packet.Free(&Packet); return Status; - + } + *DataUsed = DataSize; return STATUS_SUCCESS;
13 years
1
0
0
0
← Newer
1
...
17
18
19
20
21
22
23
24
25
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
Results per page:
10
25
50
100
200