[STDUNK][PORTCLS][CMIDriver] Fix issue with operator new/delete
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Sat, 25 May 2019 10:22:04 +0000 (12:22 +0200)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Mon, 24 Jun 2019 19:17:00 +0000 (21:17 +0200)
Fix for MSVC warning "C2323: 'operator new': non-member operator new or delete functions may not be declared static or in a namespace other than the global namespace."

See https://docs.microsoft.com/en-us/cpp/porting/visual-cpp-what-s-new-2003-through-2015?view=vs-2019 section "Overloaded operator new and operator delete"

CMakeLists.txt
drivers/wdm/audio/backpln/portcls/dma_slave.cpp
drivers/wdm/audio/backpln/portcls/miniport.cpp
drivers/wdm/audio/backpln/portcls/miniport_dmus.cpp
drivers/wdm/audio/backpln/portcls/pin_wavecyclic.cpp
drivers/wdm/audio/backpln/portcls/private.hpp
drivers/wdm/audio/drivers/CMIDriver/precomp.h
sdk/include/ddk/stdunk.h
sdk/lib/drivers/libusb/libusb.h
sdk/lib/drivers/sound/stdunk/cunknown.cpp

index 48b3b18..d7bf0a5 100644 (file)
@@ -186,6 +186,7 @@ else()
     endif()
 
     # Other
+    add_definitions(-D_NEW_DELETE_OPERATORS_)
     if(ARCH STREQUAL "i386")
         add_definitions(-DUSE_COMPILER_EXCEPTIONS -D_USE_32BIT_TIME_T)
     elseif(ARCH STREQUAL "amd64")
index f299d3c..a68d277 100644 (file)
 class CDmaChannelInit : public IDmaChannelInit
 {
 public:
+    inline
+    PVOID
+    operator new(
+        size_t Size,
+        POOL_TYPE PoolType,
+        ULONG Tag)
+    {
+        return ExAllocatePoolWithTag(PoolType, Size, Tag);
+    }
+
     STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
 
     STDMETHODIMP_(ULONG) AddRef()
index 992e29e..526a012 100644 (file)
 
 #include <debug.h>
 
+PVOID
+__cdecl
+operator new(
+    size_t Size,
+    POOL_TYPE PoolType,
+    ULONG Tag)
+{
+    return ExAllocatePoolWithTag(PoolType, Size, Tag);
+}
+
+void
+__cdecl
+operator delete(
+    PVOID ptr)
+{
+    ExFreePool(ptr);
+}
+
+void
+__cdecl
+operator delete(
+    PVOID ptr, UINT_PTR)
+{
+    ExFreePool(ptr);
+}
+
 NTSTATUS
 NTAPI
 PcNewMiniport(
index e13e0c4..957c84c 100644 (file)
@@ -1708,7 +1708,7 @@ NewStream
         )
     {
         CMiniportDMusUARTStream *pStream =
-            new(PoolType) CMiniportDMusUARTStream();
+            new(PoolType, 'wNcP') CMiniportDMusUARTStream();
 
         if (pStream)
         {
index c9f86c3..993ea92 100644 (file)
@@ -18,6 +18,16 @@ class CPortPinWaveCyclic : public IPortPinWaveCyclic,
                            public IServiceSink
 {
 public:
+    inline
+    PVOID
+    operator new(
+        size_t Size,
+        POOL_TYPE PoolType,
+        ULONG Tag)
+    {
+        return ExAllocatePoolWithTag(PoolType, Size, Tag);
+    }
+
     STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
 
     STDMETHODIMP_(ULONG) AddRef()
index ed75695..17caee0 100644 (file)
 #define PC_ASSERT_IRQL(x) PC_ASSERT(KeGetCurrentIrql() <= (x))
 #define PC_ASSERT_IRQL_EQUAL(x) PC_ASSERT(KeGetCurrentIrql()==(x))
 
+PVOID
+__cdecl
+operator new(
+    size_t Size,
+    POOL_TYPE PoolType,
+    ULONG Tag);
+
 extern
 "C"
 NTSTATUS
index 57b4be6..21599bc 100644 (file)
@@ -6,4 +6,11 @@
 
 #include "debug.hpp"
 
+PVOID
+__cdecl
+operator new(
+    size_t size,
+    POOL_TYPE pool_type,
+    ULONG tag);
+
 #endif /* _CMIDRIVER_PCH_ */
index 67ce3d8..6649bf9 100644 (file)
@@ -211,7 +211,7 @@ operator delete(
     ExFreePool(ptr);
 }
 
-#endif  /* ALLOCATION_OPERATORS_DEFINED */
+#endif  /* _NEW_DELETE_OPERATORS_ */
 
 
 #else   /* Being compiled with C */
index 004c2f0..ee0bf58 100644 (file)
@@ -22,7 +22,6 @@ extern "C"
 // the following includes are required to get kcom to compile
 //
 #include <portcls.h>
-#define _NEW_DELETE_OPERATORS_
 #include <kcom.h>
 
 PVOID
index d97e640..1296247 100644 (file)
 
 #include <stdunk.h>
 
+inline
+PVOID
+KCOM_New(
+    size_t size,
+    POOL_TYPE pool_type,
+    ULONG tag)
+{
+    PVOID result;
+
+    result = ExAllocatePoolWithTag(pool_type, size, tag);
+
+    if (result)
+        RtlZeroMemory(result, size);
+
+    return result;
+}
+
+PVOID
+__cdecl
+operator new(
+    size_t size,
+    POOL_TYPE pool_type)
+{
+    return KCOM_New(size, pool_type, 'wNcP');
+}
+
+PVOID
+__cdecl
+operator new(
+    size_t size,
+    POOL_TYPE pool_type,
+    ULONG tag)
+{
+    return KCOM_New(size, pool_type, tag);
+}
+
+void
+__cdecl
+operator delete(
+    PVOID ptr)
+{
+    ExFreePool(ptr);
+}
+
+void
+__cdecl
+operator delete(
+    PVOID ptr, UINT_PTR)
+{
+    ExFreePool(ptr);
+}
+
 CUnknown::CUnknown(PUNKNOWN outer_unknown)
 {
     m_ref_count = 0;