[WIN32K]
[reactos.git] / 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 #include <malloc.h>
71
72 #define USER_ASSERT(exp,file,line) \
73 if (!(exp)) {RtlAssert(#exp,(PVOID)file,line,"");}
74
75 static __inline VOID
76 UserAssertLastRef(PVOID obj, const char *file, int line)
77 {
78 PTHREADINFO W32Thread;
79 PSINGLE_LIST_ENTRY ReferenceEntry;
80 PUSER_REFERENCE_ENTRY UserReferenceEntry;
81
82 USER_ASSERT(obj != NULL, file, line);
83 W32Thread = PsGetCurrentThreadWin32Thread();
84 USER_ASSERT(W32Thread != NULL, file, line);
85 ReferenceEntry = W32Thread->ReferencesList.Next;
86 USER_ASSERT(ReferenceEntry != NULL, file, line);
87 UserReferenceEntry = CONTAINING_RECORD(ReferenceEntry, USER_REFERENCE_ENTRY, Entry);
88 USER_ASSERT(UserReferenceEntry != NULL, file, line);
89 USER_ASSERT(obj == UserReferenceEntry->obj, file, line);
90 }
91 #define ASSERT_LAST_REF(_obj_) UserAssertLastRef(_obj,__FILE__,__LINE__)
92
93 #undef USER_ASSERT
94
95 extern PUSER_HANDLE_TABLE gHandleTable;
96 VOID FASTCALL UserReferenceObject(PVOID obj);
97 PVOID FASTCALL UserReferenceObjectByHandle(HANDLE handle, USER_OBJECT_TYPE type);
98 BOOL FASTCALL UserDereferenceObject(PVOID obj);
99 PVOID FASTCALL UserCreateObject(PUSER_HANDLE_TABLE ht, struct _DESKTOP* pDesktop, HANDLE* h,USER_OBJECT_TYPE type , ULONG size);
100 BOOL FASTCALL UserDeleteObject(HANDLE h, USER_OBJECT_TYPE type );
101 PVOID UserGetObject(PUSER_HANDLE_TABLE ht, HANDLE handle, USER_OBJECT_TYPE type );
102 HANDLE UserAllocHandle(PUSER_HANDLE_TABLE ht, PVOID object, USER_OBJECT_TYPE type );
103 BOOL FASTCALL UserFreeHandle(PUSER_HANDLE_TABLE ht, HANDLE handle );
104 PVOID UserGetNextHandle(PUSER_HANDLE_TABLE ht, HANDLE* handle, USER_OBJECT_TYPE type );
105 PUSER_HANDLE_ENTRY handle_to_entry(PUSER_HANDLE_TABLE ht, HANDLE handle );
106 BOOL FASTCALL UserCreateHandleTable(VOID);
107 VOID UserInitHandleTable(PUSER_HANDLE_TABLE ht, PVOID mem, ULONG bytes);
108
109
110 static __inline VOID
111 UserRefObjectCo(PVOID obj, PUSER_REFERENCE_ENTRY UserReferenceEntry)
112 {
113 PTHREADINFO W32Thread;
114
115 W32Thread = PsGetCurrentThreadWin32Thread();
116 ASSERT(W32Thread != NULL);
117 ASSERT(UserReferenceEntry != NULL);
118 UserReferenceEntry->obj = obj;
119 UserReferenceObject(obj);
120 PushEntryList(&W32Thread->ReferencesList, &UserReferenceEntry->Entry);
121 }
122
123 static __inline VOID
124 UserDerefObjectCo(PVOID obj)
125 {
126 PTHREADINFO W32Thread;
127 PSINGLE_LIST_ENTRY ReferenceEntry;
128 PUSER_REFERENCE_ENTRY UserReferenceEntry;
129
130 ASSERT(obj != NULL);
131 W32Thread = PsGetCurrentThreadWin32Thread();
132 ASSERT(W32Thread != NULL);
133 ReferenceEntry = PopEntryList(&W32Thread->ReferencesList);
134 ASSERT(ReferenceEntry != NULL);
135 UserReferenceEntry = CONTAINING_RECORD(ReferenceEntry, USER_REFERENCE_ENTRY, Entry);
136 ASSERT(UserReferenceEntry != NULL);
137
138 ASSERT(obj == UserReferenceEntry->obj);
139 UserDereferenceObject(obj);
140 }
141
142 VOID FASTCALL CreateStockObjects (VOID);
143 VOID FASTCALL CreateSysColorObjects (VOID);
144
145 PPOINT FASTCALL GDI_Bezier (const POINT *Points, INT count, PINT nPtsOut);
146
147 /* EOF */