ReactOS 0.4.15-dev-5666-gc548b97
driverobj.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: GPL, see COPYING in the top level directory
3 * PROJECT: ReactOS win32 kernel mode sunsystem
4 * PURPOSE: GDI DRIVEROBJ Functions
5 * FILE: win32ss/gdi/eng/driverobj.c
6 * PROGRAMER: Timo Kreuzer
7 */
8
11#include <win32k.h>
12
13#define NDEBUG
14#include <debug.h>
15
16
22VOID
25{
26 PEDRIVEROBJ pedo = pObject;
27 FREEOBJPROC pFreeProc;
28
29 pFreeProc = pedo->drvobj.pFreeProc;
30 if (pFreeProc)
31 {
32 NT_VERIFY(pFreeProc(&pedo->drvobj));
33 }
34}
35
39HDRVOBJ
42 _In_ PVOID pvObj,
43 _In_opt_ FREEOBJPROC pFreeObjProc,
44 _In_ HDEV hdev)
45{
46 PEDRIVEROBJ pedo;
47 HDRVOBJ hdo;
48 PDEVOBJ *ppdev = (PDEVOBJ*)hdev;
49
50 /* Allocate a new DRIVEROBJ */
52 if (!pedo)
53 {
54 return NULL;
55 }
56 hdo = pedo->baseobj.hHmgr;
57
58 /* Fill in fields */
59 pedo->drvobj.pvObj = pvObj;
60 pedo->drvobj.pFreeProc = pFreeObjProc;
61 pedo->drvobj.hdev = hdev;
62 pedo->drvobj.dhpdev = ppdev->dhpdev;
63
64 /* Unlock the object */
66
67 /* Return the handle */
68 return hdo;
69}
70
71
72BOOL
75 _In_ _Post_ptr_invalid_ HDRVOBJ hdo,
76 _In_ BOOL bCallBack,
78{
79 PEDRIVEROBJ pedo;
80
81 /* Lock the object */
82 pedo = DRIVEROBJ_TryLockObject(hdo);
83 if (!pedo)
84 {
85 return FALSE;
86 }
87
88 /* Manually call cleanup callback */
89 if (bCallBack)
90 {
91 if (!pedo->drvobj.pFreeProc(&pedo->drvobj))
92 {
93 /* Callback failed */
95 return FALSE;
96 }
97 }
98
99 /* Prevent cleanup callback from being called again */
100 pedo->drvobj.pFreeProc = NULL;
101
102 /* Unlock if the caller indicates it is locked */
103 if (bLocked)
105
106 /* Now delete the object */
108 return TRUE;
109}
110
111
115 _In_ HDRVOBJ hdo)
116{
117 PEDRIVEROBJ pedo;
118
119 /* Lock the object */
120 pedo = DRIVEROBJ_TryLockObject(hdo);
121
122 /* Return pointer to the DRIVEROBJ structure */
123 return pedo ? &pedo->drvobj : NULL;
124}
125
126
127BOOL
130 _In_ _Post_ptr_invalid_ HDRVOBJ hdo)
131{
132 PEDRIVEROBJ pedo;
134
135 /* First lock to get a pointer to the object */
136 pedo = DRIVEROBJ_TryLockObject(hdo);
137 if(!pedo)
138 {
139 /* Object could not be locked, fail. */
140 return FALSE;
141 }
142
143 /* Unlock object */
146
147 /* Check if we still hold a lock */
148 if (cLocks < 2)
149 {
150 /* Object wasn't locked before, fail. */
151 return FALSE;
152 }
153
154 /* Unlock again */
156
157 /* Success */
158 return TRUE;
159}
160
BOOLEAN bLocked
Definition: Mke2fs.c:19
HGDIOBJ hHmgr(VOID)
Definition: baseobj.hpp:95
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define APIENTRY
Definition: api.h:79
VOID NTAPI DRIVEROBJ_vCleanup(PVOID pObject)
DRIVEROBJ cleanup function.
Definition: driverobj.c:24
BOOL APIENTRY EngUnlockDriverObj(_In_ _Post_ptr_invalid_ HDRVOBJ hdo)
Definition: driverobj.c:129
_Must_inspect_result_ HDRVOBJ APIENTRY EngCreateDriverObj(_In_ PVOID pvObj, _In_opt_ FREEOBJPROC pFreeObjProc, _In_ HDEV hdev)
Definition: driverobj.c:41
BOOL APIENTRY EngDeleteDriverObj(_In_ _Post_ptr_invalid_ HDRVOBJ hdo, _In_ BOOL bCallBack, _In_ BOOL bLocked)
Definition: driverobj.c:74
PDRIVEROBJ APIENTRY EngLockDriverObj(_In_ HDRVOBJ hdo)
Definition: driverobj.c:114
#define DRIVEROBJ_AllocObjectWithHandle()
Definition: driverobj.h:17
FORCEINLINE PEDRIVEROBJ DRIVEROBJ_TryLockObject(HDRVOBJ hdo)
Definition: driverobj.h:22
#define DRIVEROBJ_UnlockObject(pdo)
Definition: driverobj.h:18
unsigned int BOOL
Definition: ntddk_ex.h:94
FxObject * pObject
unsigned int ULONG
Definition: retypes.h:1
static LONG cLocks
Definition: compobj.c:119
#define _Post_ptr_invalid_
Definition: ms_sal.h:698
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define _In_
Definition: ms_sal.h:308
#define _In_opt_
Definition: ms_sal.h:309
USHORT cExclusiveLock
Definition: gdiobj.h:45
PVOID pvObj
Definition: winddi.h:409
HDEV hdev
Definition: winddi.h:411
FREEOBJPROC pFreeProc
Definition: winddi.h:410
DHPDEV dhpdev
Definition: winddi.h:412
DRIVEROBJ drvobj
Definition: driverobj.h:7
BASEOBJECT baseobj
Definition: driverobj.h:6
DHPDEV dhpdev
Definition: pdevobj.h:120
#define NTAPI
Definition: typedefs.h:36
VOID NTAPI GDIOBJ_vDeleteObject(POBJ pobj)
Definition: gdiobj.c:1111
_In_ HDEV hdev
Definition: winddi.h:3449
#define NT_VERIFY(exp)
Definition: rtlfuncs.h:3287