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