[User32|Win32k]
[reactos.git] / reactos / subsystems / win32 / win32k / include / object.h
1 #pragma once
2
3 #include "gdiobj.h"
4 #include "bitmaps.h"
5 #include "pen.h"
6
7 #define FIRST_USER_HANDLE 0x0020 /* first possible value for low word of user handle */
8 #define LAST_USER_HANDLE 0xffef /* last possible value for low word of user handle */
9
10 #define HANDLEENTRY_INDESTROY 1
11
12 typedef struct _USER_HANDLE_ENTRY
13 {
14 void *ptr; /* pointer to object */
15 union
16 {
17 PVOID pi;
18 PTHREADINFO pti; // pointer to Win32ThreadInfo
19 PPROCESSINFO ppi; // pointer to W32ProcessInfo
20 };
21 unsigned char type; /* object type (0 if free) */
22 unsigned char flags;
23 unsigned short generation; /* generation counter */
24 } USER_HANDLE_ENTRY, * PUSER_HANDLE_ENTRY;
25
26
27
28 typedef struct _USER_HANDLE_TABLE
29 {
30 PUSER_HANDLE_ENTRY handles;
31 PUSER_HANDLE_ENTRY freelist;
32 int nb_handles;
33 int allocated_handles;
34 } USER_HANDLE_TABLE, * PUSER_HANDLE_TABLE;
35
36
37
38 typedef enum _USER_OBJECT_TYPE
39 {
40 otFree = 0,
41 otWindow,
42 otMenu,
43 otCursorIcon,
44 otSMWP,
45 otHook,
46 otClipBoardData,
47 otCallProc,
48 otAccel,
49 otDDEaccess,
50 otDDEconv,
51 otDDExact,
52 otMonitor,
53 otKBDlayout,
54 otKBDfile,
55 otEvent,
56 otTimer,
57 otInputContext,
58 otHidData,
59 otDeviceInfo,
60 otTouchInput,
61 otGestureInfo
62 } USER_OBJECT_TYPE;
63
64 typedef struct _USER_REFERENCE_ENTRY
65 {
66 SINGLE_LIST_ENTRY Entry;
67 PVOID obj;
68 } USER_REFERENCE_ENTRY, *PUSER_REFERENCE_ENTRY;
69
70 #define USER_ASSERT(exp,file,line) \
71 if (!(exp)) {RtlAssert(#exp,(PVOID)file,line,"");}
72
73 static __inline VOID
74 UserAssertLastRef(PVOID obj, const char *file, int line)
75 {
76 PTHREADINFO W32Thread;
77 PSINGLE_LIST_ENTRY ReferenceEntry;
78 PUSER_REFERENCE_ENTRY UserReferenceEntry;
79
80 USER_ASSERT(obj != NULL, file, line);
81 W32Thread = PsGetCurrentThreadWin32Thread();
82 USER_ASSERT(W32Thread != NULL, file, line);
83 ReferenceEntry = W32Thread->ReferencesList.Next;
84 USER_ASSERT(ReferenceEntry != NULL, file, line);
85 UserReferenceEntry = CONTAINING_RECORD(ReferenceEntry, USER_REFERENCE_ENTRY, Entry);
86 USER_ASSERT(UserReferenceEntry != NULL, file, line);
87 USER_ASSERT(obj == UserReferenceEntry->obj, file, line);
88 }
89 #define ASSERT_LAST_REF(_obj_) UserAssertLastRef(_obj,__FILE__,__LINE__)
90
91 #undef USER_ASSERT
92
93 extern PUSER_HANDLE_TABLE gHandleTable;
94 VOID FASTCALL UserReferenceObject(PVOID obj);
95 PVOID FASTCALL UserReferenceObjectByHandle(HANDLE handle, USER_OBJECT_TYPE type);
96 BOOL FASTCALL UserDereferenceObject(PVOID obj);
97 PVOID FASTCALL UserCreateObject(PUSER_HANDLE_TABLE ht, struct _DESKTOP* pDesktop, HANDLE* h,USER_OBJECT_TYPE type , ULONG size);
98 BOOL FASTCALL UserDeleteObject(HANDLE h, USER_OBJECT_TYPE type );
99 PVOID UserGetObject(PUSER_HANDLE_TABLE ht, HANDLE handle, USER_OBJECT_TYPE type );
100 HANDLE UserAllocHandle(PUSER_HANDLE_TABLE ht, PVOID object, USER_OBJECT_TYPE type );
101 BOOL FASTCALL UserFreeHandle(PUSER_HANDLE_TABLE ht, HANDLE handle );
102 PVOID UserGetNextHandle(PUSER_HANDLE_TABLE ht, HANDLE* handle, USER_OBJECT_TYPE type );
103 PUSER_HANDLE_ENTRY handle_to_entry(PUSER_HANDLE_TABLE ht, HANDLE handle );
104 BOOL FASTCALL UserCreateHandleTable(VOID);
105 VOID UserInitHandleTable(PUSER_HANDLE_TABLE ht, PVOID mem, ULONG bytes);
106
107
108 static __inline VOID
109 UserRefObjectCo(PVOID obj, PUSER_REFERENCE_ENTRY UserReferenceEntry)
110 {
111 PTHREADINFO W32Thread;
112
113 W32Thread = PsGetCurrentThreadWin32Thread();
114 ASSERT(W32Thread != NULL);
115 ASSERT(UserReferenceEntry != NULL);
116 UserReferenceEntry->obj = obj;
117 UserReferenceObject(obj);
118 PushEntryList(&W32Thread->ReferencesList, &UserReferenceEntry->Entry);
119 }
120
121 static __inline VOID
122 UserDerefObjectCo(PVOID obj)
123 {
124 PTHREADINFO W32Thread;
125 PSINGLE_LIST_ENTRY ReferenceEntry;
126 PUSER_REFERENCE_ENTRY UserReferenceEntry;
127
128 ASSERT(obj != NULL);
129 W32Thread = PsGetCurrentThreadWin32Thread();
130 ASSERT(W32Thread != NULL);
131 ReferenceEntry = PopEntryList(&W32Thread->ReferencesList);
132 ASSERT(ReferenceEntry != NULL);
133 UserReferenceEntry = CONTAINING_RECORD(ReferenceEntry, USER_REFERENCE_ENTRY, Entry);
134 ASSERT(UserReferenceEntry != NULL);
135
136 ASSERT(obj == UserReferenceEntry->obj);
137 UserDereferenceObject(obj);
138 }
139
140 VOID FASTCALL CreateStockObjects (VOID);
141 VOID FASTCALL CreateSysColorObjects (VOID);
142
143 PPOINT FASTCALL GDI_Bezier (const POINT *Points, INT count, PINT nPtsOut);
144
145 /* EOF */