ReactOS  0.4.14-dev-1112-g2b067d6
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 
22 VOID
23 NTAPI
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 
39 HDRVOBJ
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 
72 BOOL
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 
113 APIENTRY
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->drvobj;
124 }
125 
126 
127 BOOL
128 APIENTRY
130  _In_ _Post_ptr_invalid_ HDRVOBJ hdo)
131 {
132  PEDRIVEROBJ pedo;
133  ULONG cLocks;
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 */
144  cLocks = pedo->baseobj.cExclusiveLock;
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 
DHPDEV dhpdev
Definition: pdevobj.h:121
#define _Must_inspect_result_
Definition: no_sal2.h:314
#define TRUE
Definition: types.h:120
BASEOBJECT baseobj
Definition: driverobj.h:6
static LONG cLocks
Definition: compobj.c:119
FREEOBJPROC pFreeProc
Definition: winddi.h:410
DRIVEROBJ drvobj
Definition: driverobj.h:7
USHORT cExclusiveLock
Definition: gdiobj.h:45
#define NT_VERIFY(exp)
Definition: rtlfuncs.h:3289
#define _In_opt_
Definition: no_sal2.h:213
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define DRIVEROBJ_UnlockObject(pdo)
Definition: driverobj.h:18
HGDIOBJ hHmgr(VOID)
Definition: baseobj.hpp:95
smooth NULL
Definition: ftsmooth.c:416
DHPDEV dhpdev
Definition: winddi.h:412
VOID NTAPI GDIOBJ_vDeleteObject(POBJ pobj)
Definition: gdiobj.c:1108
BOOLEAN bLocked
Definition: Mke2fs.c:19
BOOL APIENTRY EngUnlockDriverObj(_In_ _Post_ptr_invalid_ HDRVOBJ hdo)
Definition: driverobj.c:129
#define DRIVEROBJ_AllocObjectWithHandle()
Definition: driverobj.h:17
BOOL APIENTRY EngDeleteDriverObj(_In_ _Post_ptr_invalid_ HDRVOBJ hdo, _In_ BOOL bCallBack, _In_ BOOL bLocked)
Definition: driverobj.c:74
#define _In_
Definition: no_sal2.h:204
VOID NTAPI DRIVEROBJ_vCleanup(PVOID pObject)
DRIVEROBJ cleanup function.
Definition: driverobj.c:24
#define _Post_ptr_invalid_
Definition: no_sal2.h:462
unsigned int ULONG
Definition: retypes.h:1
FORCEINLINE PEDRIVEROBJ DRIVEROBJ_TryLockObject(HDRVOBJ hdo)
Definition: driverobj.h:22
PDRIVEROBJ APIENTRY EngLockDriverObj(_In_ HDRVOBJ hdo)
Definition: driverobj.c:114
PVOID pvObj
Definition: winddi.h:409
_Must_inspect_result_ HDRVOBJ APIENTRY EngCreateDriverObj(_In_ PVOID pvObj, _In_opt_ FREEOBJPROC pFreeObjProc, _In_ HDEV hdev)
Definition: driverobj.c:41
_In_ HDEV hdev
Definition: winddi.h:3449
#define APIENTRY
Definition: api.h:79
HDEV hdev
Definition: winddi.h:411