[LIBUSB] Add additional operator new/delete
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Sat, 24 Feb 2018 10:20:27 +0000 (11:20 +0100)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Sun, 1 Jul 2018 12:45:21 +0000 (14:45 +0200)
This is required, since newer versions of MSVC demand that non-member operator new/delete are in the global namespace and neither static nor inline. See https://msdn.microsoft.com/en-us/library/mt723604.aspx ("Overloaded operator new and operator delete")

sdk/lib/drivers/libusb/libusb.cpp
sdk/lib/drivers/libusb/libusb.h

index f5dc0f1..6326148 100644 (file)
 //
 DRIVER_ADD_DEVICE USBLIB_AddDevice;
 
+PVOID
+__cdecl
+operator new(
+    size_t iSize,
+    POOL_TYPE poolType,
+    ULONG tag)
+{
+    PVOID result = ExAllocatePoolWithTag(poolType, iSize, tag);
+    if (result) {
+        RtlZeroMemory(result, iSize);
+    }
+    return result;
+}
+
+void
+__cdecl
+operator delete(
+    PVOID pVoid)
+{
+    if (pVoid) ExFreePool(pVoid);
+}
+
+void
+__cdecl
+operator delete(
+    PVOID pVoid, UINT_PTR)
+{
+    if (pVoid) ExFreePool(pVoid);
+}
+
 extern
 "C"
 {
index f241901..004c2f0 100644 (file)
@@ -22,8 +22,17 @@ extern "C"
 // the following includes are required to get kcom to compile
 //
 #include <portcls.h>
+#define _NEW_DELETE_OPERATORS_
 #include <kcom.h>
 
+PVOID
+__cdecl
+operator new(
+    size_t iSize,
+    POOL_TYPE poolType,
+    ULONG tag);
+
+
 #include "common_interfaces.h"
 
 //