Visual C++ backend for rbuild (for now just a hacked mingw backend) and related compi...
[reactos.git] / subsystems / win32 / win32k / eng / driverobj.c
1 /*
2 * ReactOS W32 Subsystem
3 * Copyright (C) 2005 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS kernel
22 * PURPOSE: GDI DRIVEROBJ Functions
23 * FILE: subsys/win32k/eng/driverobj.c
24 * PROGRAMER: Gregor Anich
25 * REVISION HISTORY:
26 * 04/01/2005: Created
27 */
28
29 #include <w32k.h>
30
31 #define NDEBUG
32 #include <debug.h>
33
34 /*!\brief Called when the process is terminated.
35 *
36 * Calls the free-proc for each existing DRIVEROBJ.
37 *
38 * \param Process Pointer to the EPROCESS struct for the process beeing terminated.
39 * \param Win32Process Pointer to the W32PROCESS
40 */
41 VOID FASTCALL
42 IntEngCleanupDriverObjs(struct _EPROCESS *Process,
43 PW32PROCESS Win32Process)
44 {
45 PDRIVERGDI DrvObjInt;
46 PW32PROCESS CurrentWin32Process;
47
48 CurrentWin32Process = PsGetCurrentProcessWin32Process();
49 IntEngLockProcessDriverObjs(CurrentWin32Process);
50 while (!IsListEmpty(&Win32Process->DriverObjListHead))
51 {
52 DrvObjInt = CONTAINING_RECORD(Win32Process->DriverObjListHead.Flink,
53 DRIVERGDI, ListEntry);
54 IntEngUnLockProcessDriverObjs(CurrentWin32Process);
55 EngDeleteDriverObj((HDRVOBJ)(&DrvObjInt->DriverObj), TRUE, FALSE);
56 IntEngLockProcessDriverObjs(CurrentWin32Process);
57 }
58 IntEngUnLockProcessDriverObjs(CurrentWin32Process);
59 }
60
61
62 /*
63 * @implemented
64 */
65 HDRVOBJ
66 STDCALL
67 EngCreateDriverObj(
68 IN PVOID pvObj,
69 IN FREEOBJPROC pFreeObjProc,
70 IN HDEV hdev
71 )
72 {
73 PDRIVERGDI DrvObjInt;
74 PDRIVEROBJ DrvObjUser;
75 PW32PROCESS CurrentWin32Process;
76
77 /* Create DRIVEROBJ */
78 DrvObjInt = EngAllocMem(0, sizeof (DRIVERGDI), TAG_DRIVEROBJ);
79 if (DrvObjInt == NULL)
80 {
81 DPRINT1("Failed to allocate memory for a DRIVERGDI structure!\n");
82 return NULL;
83 }
84
85 /* fill user object */
86 DrvObjUser = GDIToObj(DrvObjInt, DRIVER);
87 DrvObjUser->pvObj = pvObj;
88 DrvObjUser->pFreeProc = pFreeObjProc;
89 DrvObjUser->hdev = hdev;
90 DrvObjUser->dhpdev = ((GDIDEVICE*)hdev)->hPDev;
91
92 /* fill internal object */
93 ExInitializeFastMutex(&DrvObjInt->Lock);
94 CurrentWin32Process = PsGetCurrentProcessWin32Process();
95 IntEngLockProcessDriverObjs(CurrentWin32Process);
96 InsertTailList(&CurrentWin32Process->DriverObjListHead, &DrvObjInt->ListEntry);
97 IntEngUnLockProcessDriverObjs(CurrentWin32Process);
98
99 return (HDRVOBJ)DrvObjUser;
100 }
101
102
103 /*
104 * @implemented
105 */
106 BOOL
107 STDCALL
108 EngDeleteDriverObj(
109 IN HDRVOBJ hdo,
110 IN BOOL bCallBack,
111 IN BOOL bLocked
112 )
113 {
114 PDRIVEROBJ DrvObjUser = (PDRIVEROBJ)hdo;
115 PDRIVERGDI DrvObjInt = ObjToGDI(DrvObjUser, DRIVER);
116 PW32PROCESS CurrentWin32Process;
117
118 /* Make sure the obj is locked */
119 if (!bLocked)
120 {
121 if (!ExTryToAcquireFastMutex(&DrvObjInt->Lock))
122 {
123 return FALSE;
124 }
125 }
126
127 /* Call the free-proc */
128 if (bCallBack)
129 {
130 if (!DrvObjUser->pFreeProc(DrvObjUser))
131 {
132 return FALSE;
133 }
134 }
135
136 /* Free the DRIVEROBJ */
137 CurrentWin32Process = PsGetCurrentProcessWin32Process();
138 IntEngLockProcessDriverObjs(CurrentWin32Process);
139 RemoveEntryList(&DrvObjInt->ListEntry);
140 IntEngUnLockProcessDriverObjs(CurrentWin32Process);
141 EngFreeMem(DrvObjInt);
142
143 return TRUE;
144 }
145
146
147 /*
148 * @implemented
149 */
150 PDRIVEROBJ
151 STDCALL
152 EngLockDriverObj( IN HDRVOBJ hdo )
153 {
154 PDRIVEROBJ DrvObjUser = (PDRIVEROBJ)hdo;
155 PDRIVERGDI DrvObjInt = ObjToGDI(DrvObjUser, DRIVER);
156
157 if (!ExTryToAcquireFastMutex(&DrvObjInt->Lock))
158 {
159 return NULL;
160 }
161
162 return DrvObjUser;
163 }
164
165
166 /*
167 * @implemented
168 */
169 BOOL
170 STDCALL
171 EngUnlockDriverObj ( IN HDRVOBJ hdo )
172 {
173 PDRIVERGDI DrvObjInt = ObjToGDI((PDRIVEROBJ)hdo, DRIVER);
174
175 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(&DrvObjInt->Lock);
176 return TRUE;
177 }
178
179 /* EOF */
180