From 52be87ee4c1263f413cce7ecc54d3e93cef74105 Mon Sep 17 00:00:00 2001 From: Dmitry Fleytman Date: Sun, 11 May 2014 15:54:28 +0300 Subject: [PATCH] UsbDk: Make CWdmList accessors safer Accessor functions made private, corresponding list class specialization declared as friend. Signed-off-by: Dmitry Fleytman --- UsbDk/ControlDevice.h | 7 +------ UsbDk/FilterDevice.h | 18 ++++-------------- UsbDk/UsbDkUtil.h | 13 +++++++++++++ 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/UsbDk/ControlDevice.h b/UsbDk/ControlDevice.h index cc0db5c..08d28f9 100644 --- a/UsbDk/ControlDevice.h +++ b/UsbDk/ControlDevice.h @@ -64,11 +64,6 @@ public: bool operator==(const CUsbDkChildDevice &Dev) const; bool operator==(const CUsbDkRedirection &Other) const; - PLIST_ENTRY GetListEntry() - { return &m_ListEntry; } - static CUsbDkRedirection *GetByListEntry(PLIST_ENTRY entry) - { return static_cast(CONTAINING_RECORD(entry, CUsbDkRedirection, m_ListEntry)); } - void Dump() const; void NotifyRedirectorCreated(ULONG RedirectorID); @@ -89,7 +84,7 @@ private: CWdmEvent m_RedirectionCreated; ULONG m_RedirectorID = NO_REDIRECTOR; - LIST_ENTRY m_ListEntry; + DECLARE_CWDMLIST_ENTRY(CUsbDkRedirection); }; class CUsbDkControlDevice : private CWdfControlDevice, public CAllocatable diff --git a/UsbDk/FilterDevice.h b/UsbDk/FilterDevice.h index 0cbf6c2..3770ce4 100644 --- a/UsbDk/FilterDevice.h +++ b/UsbDk/FilterDevice.h @@ -57,11 +57,6 @@ public: void Dump(); - PLIST_ENTRY GetListEntry() - { return &m_ListEntry; } - static CUsbDkChildDevice *GetByListEntry(PLIST_ENTRY entry) - { return static_cast(CONTAINING_RECORD(entry, CUsbDkChildDevice, m_ListEntry)); } - private: CObjHolder m_DeviceID; CObjHolder m_InstanceID; @@ -70,12 +65,12 @@ private: PDEVICE_OBJECT m_PDO; const CUsbDkFilterDevice &m_ParentDevice; - LIST_ENTRY m_ListEntry; - bool CreateRedirectorDevice(); CUsbDkChildDevice(const CUsbDkChildDevice&) = delete; CUsbDkChildDevice& operator= (const CUsbDkChildDevice&) = delete; + + DECLARE_CWDMLIST_ENTRY(CUsbDkChildDevice); }; class CDeviceRelations; @@ -112,11 +107,6 @@ public: bool EnumerateChildrenIf(TPredicate Predicate, TFunctor Functor) { return m_Strategy->Children().ForEachIf(Predicate, Functor); } - PLIST_ENTRY GetListEntry() - { return &m_ListEntry; } - static CUsbDkFilterDevice *GetByListEntry(PLIST_ENTRY entry) - { return static_cast(CONTAINING_RECORD(entry, CUsbDkFilterDevice, m_ListEntry)); } - ULONG GetChildrenCount() { return m_Strategy->Children().GetCount(); } @@ -138,8 +128,6 @@ private: WDFDRIVER m_Driver = WDF_NO_HANDLE; - LIST_ENTRY m_ListEntry; - class CStrategist { public: @@ -161,4 +149,6 @@ private: friend class CUsbDkFilterDeviceInit; friend class CUsbDkRedirectorQueue; + + DECLARE_CWDMLIST_ENTRY(CUsbDkFilterDevice); }; diff --git a/UsbDk/UsbDkUtil.h b/UsbDk/UsbDkUtil.h index 84f71fb..e824b6a 100644 --- a/UsbDk/UsbDkUtil.h +++ b/UsbDk/UsbDkUtil.h @@ -86,6 +86,19 @@ protected: ULONG GetCount() { return 0; } }; +#define DECLARE_CWDMLIST_ENTRY(type) \ + private: \ + PLIST_ENTRY GetListEntry() \ + { return &m_ListEntry; } \ + \ + static type *GetByListEntry(PLIST_ENTRY entry) \ + { return static_cast(CONTAINING_RECORD(entry, type, m_ListEntry)); } \ + \ + template \ + friend class CWdmList; \ + \ + LIST_ENTRY m_ListEntry + template class CWdmList : private TAccessStrategy, public TCountingStrategy {