1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7     FxPagedObject.hpp
8 
9 Abstract:
10 
11     This module defines the abstract FxPagedObject class.
12 
13 Author:
14 
15 
16 
17 --*/
18 
19 #ifndef _FXPAGEDOBJECT_H_
20 #define _FXPAGEDOBJECT_H_
21 
22 class FxPagedObject : public FxObject
23 {
24 private:
25     MxPagedLock* m_Lock;
26 
27 public:
28 
FxPagedObject(__in WDFTYPE Type,__in USHORT Size,__in PFX_DRIVER_GLOBALS FxDriverGlobals)29     FxPagedObject(
30         __in WDFTYPE Type,
31         __in USHORT Size,
32         __in PFX_DRIVER_GLOBALS FxDriverGlobals
33         ) :
34         FxObject(Type, Size, FxDriverGlobals)
35     {
36         m_Lock = NULL;
37 
38         // no need to hold the lock while the object is being constructed
39         MarkPassiveCallbacks(ObjectDoNotLock);
40     }
41 
42     virtual
~FxPagedObject(VOID)43     ~FxPagedObject(
44         VOID
45         )
46     {
47         if (m_Lock != NULL) {
48             FxPoolFree(m_Lock);
49             m_Lock = NULL;
50         }
51     }
52 
53     VOID
Lock(VOID)54     Lock(
55         VOID
56         )
57     {
58         m_Lock->Acquire();
59     }
60 
61     VOID
Unlock(VOID)62     Unlock(
63         VOID
64         )
65     {
66         m_Lock->Release();
67     }
68 
69     _Must_inspect_result_
70     NTSTATUS
Initialize(VOID)71     Initialize(
72         VOID
73         )
74     {
75         PFX_DRIVER_GLOBALS fxDriverGlobals;
76 
77         fxDriverGlobals = GetDriverGlobals();
78         m_Lock = (MxPagedLock*) FxPoolAllocate(fxDriverGlobals,
79                                                NonPagedPool,
80                                                sizeof(MxPagedLock));
81         if (m_Lock != NULL) {
82             return m_Lock->Initialize();
83         }
84         else {
85             return STATUS_INSUFFICIENT_RESOURCES;
86         }
87     }
88 };
89 
90 #endif //  _FXPAGEDOBJECT_H_
91