Author: jimtabor
Date: Thu Jan 14 14:33:04 2010
New Revision: 45079
URL:
http://svn.reactos.org/svn/reactos?rev=45079&view=rev
Log:
[Win32k|User32]
- Started the user handle rewrite.
Modified:
trunk/reactos/dll/win32/user32/include/user32p.h
trunk/reactos/include/reactos/win32k/ntuser.h
trunk/reactos/subsystems/win32/win32k/include/accelerator.h
trunk/reactos/subsystems/win32/win32k/include/cursoricon.h
trunk/reactos/subsystems/win32/win32k/include/menu.h
trunk/reactos/subsystems/win32/win32k/include/object.h
trunk/reactos/subsystems/win32/win32k/include/timer.h
trunk/reactos/subsystems/win32/win32k/ntuser/object.c
trunk/reactos/subsystems/win32/win32k/ntuser/timer.c
Modified: trunk/reactos/dll/win32/user32/include/user32p.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/include/u…
==============================================================================
--- trunk/reactos/dll/win32/user32/include/user32p.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/user32/include/user32p.h [iso-8859-1] Thu Jan 14 14:33:04
2010
@@ -180,6 +180,8 @@
#define USER_BODY_TO_HEADER(ObjectBody) \
((PUSER_OBJECT_HEADER)(((PUSER_OBJECT_HEADER)ObjectBody) - 1))
+#define HANDLEENTRY_INDESTROY 1
+
typedef struct _USER_HANDLE_ENTRY
{
void *ptr; /* pointer to object */
@@ -189,7 +191,8 @@
PTHREADINFO pti; // pointer to Win32ThreadInfo
PPROCESSINFO ppi; // pointer to W32ProcessInfo
};
- unsigned short type; /* object type (0 if free) */
+ unsigned char type; /* object type (0 if free) */
+ unsigned char flags;
unsigned short generation; /* generation counter */
} USER_HANDLE_ENTRY, * PUSER_HANDLE_ENTRY;
Modified: trunk/reactos/include/reactos/win32k/ntuser.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/win32k/ntu…
==============================================================================
--- trunk/reactos/include/reactos/win32k/ntuser.h [iso-8859-1] (original)
+++ trunk/reactos/include/reactos/win32k/ntuser.h [iso-8859-1] Thu Jan 14 14:33:04 2010
@@ -94,12 +94,18 @@
typedef struct _PROCDESKHEAD
{
- HANDLE h;
- DWORD cLockObj;
+ HEAD;
DWORD hTaskWow;
struct _DESKTOP *rpdesk;
PVOID pSelf;
} PROCDESKHEAD, *PPROCDESKHEAD;
+
+typedef struct _PROCMARKHEAD
+{
+ HEAD;
+ ULONG hTaskWow;
+ PPROCESSINFO ppi;
+} PROCMARKHEAD, *PPROCMARKHEAD;
#define UserHMGetHandle(obj) ((obj)->head.h)
Modified: trunk/reactos/subsystems/win32/win32k/include/accelerator.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/in…
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/include/accelerator.h [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/include/accelerator.h [iso-8859-1] Thu Jan 14
14:33:04 2010
@@ -7,6 +7,7 @@
typedef struct _ACCELERATOR_TABLE
{
+ HEAD head;
int Count;
LPACCEL Table;
} ACCELERATOR_TABLE, *PACCELERATOR_TABLE;
Modified: trunk/reactos/subsystems/win32/win32k/include/cursoricon.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/in…
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/include/cursoricon.h [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/include/cursoricon.h [iso-8859-1] Thu Jan 14
14:33:04 2010
@@ -11,6 +11,7 @@
typedef struct _CURICON_OBJECT
{
+ PROCMARKHEAD head;
LIST_ENTRY ListEntry;
HANDLE Self;
LIST_ENTRY ProcessList;
Modified: trunk/reactos/subsystems/win32/win32k/include/menu.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/in…
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/include/menu.h [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/include/menu.h [iso-8859-1] Thu Jan 14 14:33:04
2010
@@ -29,6 +29,7 @@
typedef struct _MENU_OBJECT
{
+ PROCDESKHEAD head;
PEPROCESS Process;
LIST_ENTRY ListEntry;
PMENU_ITEM MenuItemList;
Modified: trunk/reactos/subsystems/win32/win32k/include/object.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/in…
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/include/object.h [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/include/object.h [iso-8859-1] Thu Jan 14
14:33:04 2010
@@ -14,7 +14,7 @@
#define USER_BODY_TO_HEADER(ObjectBody) \
((PUSER_OBJECT_HEADER)(((PUSER_OBJECT_HEADER)ObjectBody) - 1))
-
+#define HANDLEENTRY_INDESTROY 1
typedef struct _USER_HANDLE_ENTRY
{
@@ -25,7 +25,8 @@
PTHREADINFO pti; // pointer to Win32ThreadInfo
PPROCESSINFO ppi; // pointer to W32ProcessInfo
};
- unsigned short type; /* object type (0 if free) */
+ unsigned char type; /* object type (0 if free) */
+ unsigned char flags;
unsigned short generation; /* generation counter */
} USER_HANDLE_ENTRY, * PUSER_HANDLE_ENTRY;
Modified: trunk/reactos/subsystems/win32/win32k/include/timer.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/in…
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/include/timer.h [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/include/timer.h [iso-8859-1] Thu Jan 14 14:33:04
2010
@@ -3,6 +3,7 @@
typedef struct _TIMER
{
+ HEAD head;
LIST_ENTRY ptmrList;
PTHREADINFO pti;
PWINDOW_OBJECT pWnd; // hWnd
Modified: trunk/reactos/subsystems/win32/win32k/ntuser/object.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/nt…
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/ntuser/object.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/ntuser/object.c [iso-8859-1] Thu Jan 14 14:33:04
2010
@@ -151,6 +151,7 @@
ret = entry->ptr;
entry->ptr = ht->freelist;
entry->type = 0;
+ entry->flags = 0;
entry->pi = NULL;
ht->freelist = entry;
@@ -198,6 +199,7 @@
return 0;
entry->ptr = object;
entry->type = type;
+ entry->flags = 0;
entry->pi = UserHandleOwnerByType(type);
if (++entry->generation >= 0xffff)
entry->generation = 1;
@@ -294,8 +296,6 @@
return NULL;
}
-
-
PVOID FASTCALL
UserCreateObject(PUSER_HANDLE_TABLE ht, HANDLE* h,USER_OBJECT_TYPE type , ULONG size)
{
@@ -401,7 +401,6 @@
}
-
BOOL FASTCALL UserCreateHandleTable(VOID)
{
@@ -429,3 +428,162 @@
return TRUE;
}
+
+//
+// New
+//
+PVOID
+FASTCALL
+NewUserCreateObject( PUSER_HANDLE_TABLE ht,
+ HANDLE* h,
+ USER_OBJECT_TYPE type,
+ ULONG size)
+{
+ HANDLE hi;
+ PVOID Object;
+ PTHREADINFO pti;
+ PPROCESSINFO ppi;
+ BOOL dt;
+
+ pti = GetW32ThreadInfo();
+ ppi = pti->ppi;
+
+ switch (type)
+ {
+ case otWindow:
+ Object = DesktopHeapAlloc(pti->rpdesk, size);
+ dt = TRUE;
+ break;
+
+ default:
+ Object = UserHeapAlloc(size);
+ dt = FALSE;
+ break;
+ }
+
+ if (!Object)
+ return NULL;
+
+
+ hi = UserAllocHandle(ht, Object, type );
+ if (!hi)
+ {
+ if (dt)
+ DesktopHeapFree(pti->rpdesk, Object);
+ else
+ UserHeapFree(Object);
+ return NULL;
+ }
+
+ RtlZeroMemory(Object, size);
+
+ switch (type)
+ {
+ case otWindow:
+ case otHook:
+ ((PTHRDESKHEAD)Object)->rpdesk = pti->rpdesk;
+ ((PTHRDESKHEAD)Object)->pSelf = Object;
+ case otEvent:
+ ((PTHROBJHEAD)Object)->pti = pti;
+ break;
+
+ case otMenu:
+ case otCallProc:
+ ((PPROCDESKHEAD)Object)->rpdesk = pti->rpdesk;
+ ((PPROCDESKHEAD)Object)->pSelf = Object;
+ break;
+
+ case otCursorIcon:
+ ((PPROCMARKHEAD)Object)->ppi = ppi;
+ break;
+
+ default:
+ break;
+ }
+ /* Now set default headers. */
+ ((PHEAD)Object)->h = hi;
+ ((PHEAD)Object)->cLockObj = 2; // we need this, because we create 2 refs: handle
and pointer!
+
+ if (h)
+ *h = hi;
+ return Object;
+}
+
+BOOL
+FASTCALL
+NewUserDereferenceObject(PVOID obj)
+{
+ ASSERT(((PHEAD)obj)->cLockObj >= 1);
+
+ if (--((PHEAD)obj)->cLockObj <= 0)
+ {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+BOOL
+FASTCALL
+NewUserFreeHandle(PUSER_HANDLE_TABLE ht, HANDLE handle )
+{
+ PUSER_HANDLE_ENTRY entry;
+ PVOID object;
+ USER_OBJECT_TYPE type;
+
+ if (!(entry = handle_to_entry( ht, handle )))
+ {
+ SetLastNtError( STATUS_INVALID_HANDLE );
+ return FALSE;
+ }
+
+ entry->flags = HANDLEENTRY_INDESTROY;
+
+ if (NewUserDereferenceObject(entry->ptr))
+ {
+ type = entry->type;
+ object = free_user_entry(ht, entry );
+
+ if (type == otWindow) // If more, go switch.
+ {
+ return DesktopHeapFree(GetW32ThreadInfo()->rpdesk, object);
+ }
+ return UserHeapFree(object);
+ }
+ return FALSE;
+}
+
+BOOL
+FASTCALL
+NewUserDeleteObject(HANDLE h, USER_OBJECT_TYPE type )
+{
+ PVOID body = UserGetObject(gHandleTable, h, type);
+
+ if (!body) return FALSE;
+
+ ASSERT( ((PHEAD)body)->cLockObj >= 1);
+
+ return NewUserFreeHandle(gHandleTable, h);
+}
+
+VOID
+FASTCALL
+NewUserReferenceObject(PVOID obj)
+{
+ ASSERT(((PHEAD)obj)->cLockObj >= 0);
+
+ ((PHEAD)obj)->cLockObj++;
+}
+
+PVOID
+FASTCALL
+NewUserReferenceObjectByHandle(HANDLE handle, USER_OBJECT_TYPE type)
+{
+ PVOID object;
+
+ object = UserGetObject(gHandleTable, handle, type);
+ if (object)
+ {
+ NewUserReferenceObject(object);
+ }
+ return object;
+}
Modified: trunk/reactos/subsystems/win32/win32k/ntuser/timer.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/nt…
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/ntuser/timer.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/ntuser/timer.c [iso-8859-1] Thu Jan 14 14:33:04
2010
@@ -82,6 +82,7 @@
UINT flags,
BOOL Distroy)
{
+ PLIST_ENTRY pLE;
PTIMER pTmr = FirstpTmr;
KeEnterCriticalRegion();
do
@@ -100,7 +101,8 @@
break;
}
- pTmr = (PTIMER)pTmr->ptmrList.Flink;
+ pLE = pTmr->ptmrList.Flink;
+ pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
} while (pTmr != FirstpTmr);
KeLeaveCriticalRegion();
@@ -111,6 +113,7 @@
FASTCALL
FindSystemTimer(PMSG pMsg)
{
+ PLIST_ENTRY pLE;
PTIMER pTmr = FirstpTmr;
KeEnterCriticalRegion();
do
@@ -121,7 +124,8 @@
(pTmr->flags & TMRF_SYSTEM) )
break;
- pTmr = (PTIMER)pTmr->ptmrList.Flink;
+ pLE = pTmr->ptmrList.Flink;
+ pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
} while (pTmr != FirstpTmr);
KeLeaveCriticalRegion();
@@ -135,6 +139,7 @@
WPARAM wParam,
LPARAM lParam)
{
+ PLIST_ENTRY pLE;
PTIMER pTmr = FirstpTmr;
if (!pTmr) return FALSE;
@@ -144,11 +149,11 @@
{
if ( (lParam == (LPARAM)pTmr->pfn) &&
(pTmr->flags & (TMRF_SYSTEM|TMRF_RIT)) &&
-// (pTmr->head.pti->ppi == pti->ppi) )
(pTmr->pti->ppi == pti->ppi) )
break;
- pTmr = (PTIMER)pTmr->ptmrList.Flink;
+ pLE = pTmr->ptmrList.Flink;
+ pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
} while (pTmr != FirstpTmr);
KeLeaveCriticalRegion();
@@ -265,6 +270,7 @@
FASTCALL
PostTimerMessages(PWINDOW_OBJECT Window)
{
+ PLIST_ENTRY pLE;
PUSER_MESSAGE_QUEUE ThreadQueue;
MSG Msg;
PTHREADINFO pti;
@@ -299,7 +305,8 @@
Hit = TRUE;
}
- pTmr = (PTIMER)pTmr->ptmrList.Flink;
+ pLE = pTmr->ptmrList.Flink;
+ pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
} while (pTmr != FirstpTmr);
KeLeaveCriticalRegion();
@@ -312,6 +319,7 @@
{
LARGE_INTEGER TickCount, DueTime;
LONG Time;
+ PLIST_ENTRY pLE;
PTIMER pTmr = FirstpTmr;
if (!pTmr) return;
@@ -327,7 +335,8 @@
{
if (pTmr->flags & TMRF_WAITING)
{
- pTmr = (PTIMER)pTmr->ptmrList.Flink;
+ pLE = pTmr->ptmrList.Flink;
+ pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
continue;
}
@@ -363,7 +372,8 @@
else
pTmr->cmsCountdown -= Time - TimeLast;
}
- pTmr = (PTIMER)pTmr->ptmrList.Flink;
+ pLE = pTmr->ptmrList.Flink;
+ pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
} while (pTmr != FirstpTmr);
// Restart the timer thread!