2 * ReactOS W32 Subsystem
3 * Copyright (C) 2005 ReactOS Team
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.
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.
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.
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
34 /*!\brief Called when the process is terminated.
36 * Calls the free-proc for each existing DRIVEROBJ.
38 * \param Process Pointer to the EPROCESS struct for the process beeing terminated.
39 * \param Win32Process Pointer to the W32PROCESS
42 IntEngCleanupDriverObjs(struct _EPROCESS
*Process
,
43 PW32PROCESS Win32Process
)
46 PW32PROCESS CurrentWin32Process
;
48 CurrentWin32Process
= PsGetCurrentProcessWin32Process();
49 IntEngLockProcessDriverObjs(CurrentWin32Process
);
50 while (!IsListEmpty(&Win32Process
->DriverObjListHead
))
52 DrvObjInt
= CONTAINING_RECORD(Win32Process
->DriverObjListHead
.Flink
,
53 DRIVERGDI
, ListEntry
);
54 IntEngUnLockProcessDriverObjs(CurrentWin32Process
);
55 EngDeleteDriverObj((HDRVOBJ
)(&DrvObjInt
->DriverObj
), TRUE
, FALSE
);
56 IntEngLockProcessDriverObjs(CurrentWin32Process
);
58 IntEngUnLockProcessDriverObjs(CurrentWin32Process
);
69 IN FREEOBJPROC pFreeObjProc
,
74 PDRIVEROBJ DrvObjUser
;
75 PW32PROCESS CurrentWin32Process
;
77 /* Create DRIVEROBJ */
78 DrvObjInt
= EngAllocMem(0, sizeof (DRIVERGDI
), TAG_DRIVEROBJ
);
79 if (DrvObjInt
== NULL
)
81 DPRINT1("Failed to allocate memory for a DRIVERGDI structure!\n");
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
;
92 /* fill internal object */
93 ExInitializeFastMutex(&DrvObjInt
->Lock
);
94 CurrentWin32Process
= PsGetCurrentProcessWin32Process();
95 IntEngLockProcessDriverObjs(CurrentWin32Process
);
96 InsertTailList(&CurrentWin32Process
->DriverObjListHead
, &DrvObjInt
->ListEntry
);
97 IntEngUnLockProcessDriverObjs(CurrentWin32Process
);
99 return (HDRVOBJ
)DrvObjUser
;
114 PDRIVEROBJ DrvObjUser
= (PDRIVEROBJ
)hdo
;
115 PDRIVERGDI DrvObjInt
= ObjToGDI(DrvObjUser
, DRIVER
);
116 PW32PROCESS CurrentWin32Process
;
118 /* Make sure the obj is locked */
121 if (!ExTryToAcquireFastMutex(&DrvObjInt
->Lock
))
127 /* Call the free-proc */
130 if (!DrvObjUser
->pFreeProc(DrvObjUser
))
136 /* Free the DRIVEROBJ */
137 CurrentWin32Process
= PsGetCurrentProcessWin32Process();
138 IntEngLockProcessDriverObjs(CurrentWin32Process
);
139 RemoveEntryList(&DrvObjInt
->ListEntry
);
140 IntEngUnLockProcessDriverObjs(CurrentWin32Process
);
141 EngFreeMem(DrvObjInt
);
152 EngLockDriverObj( IN HDRVOBJ hdo
)
154 PDRIVEROBJ DrvObjUser
= (PDRIVEROBJ
)hdo
;
155 PDRIVERGDI DrvObjInt
= ObjToGDI(DrvObjUser
, DRIVER
);
157 if (!ExTryToAcquireFastMutex(&DrvObjInt
->Lock
))
171 EngUnlockDriverObj ( IN HDRVOBJ hdo
)
173 PDRIVERGDI DrvObjInt
= ObjToGDI((PDRIVEROBJ
)hdo
, DRIVER
);
175 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(&DrvObjInt
->Lock
);