From 5fb407cffebb8ec0cc50cb3e96e1bebf79ad1bc0 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Fri, 26 Jun 2020 01:18:40 +0200 Subject: Linux/MacOSX: use standard std::shared_ptr instead of our custom implementation which is kept for compatibility with older compilers. We also introduce compatibility code for old compilers that don't define std::unique_ptr --- src/Common/SecurityToken.cpp | 4 ++-- src/Core/CoreBase.cpp | 6 +++++- src/Core/Unix/CoreService.cpp | 6 +++--- src/Platform/SharedPtr.h | 17 +++++++++++++++++ src/Volume/EncryptionThreadPool.cpp | 4 +++- 5 files changed, 30 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Common/SecurityToken.cpp b/src/Common/SecurityToken.cpp index a6759bf8..47fa218c 100644 --- a/src/Common/SecurityToken.cpp +++ b/src/Common/SecurityToken.cpp @@ -548,8 +548,8 @@ namespace VeraCrypt if (status != CKR_OK) throw Pkcs11Exception (status); - PinCallback = std::move(pinCallback); - WarningCallback = std::move(warningCallback); + PinCallback = move_ptr(pinCallback); + WarningCallback = move_ptr(warningCallback); Initialized = true; } diff --git a/src/Core/CoreBase.cpp b/src/Core/CoreBase.cpp index 01d3981a..29bfb74d 100644 --- a/src/Core/CoreBase.cpp +++ b/src/Core/CoreBase.cpp @@ -254,7 +254,11 @@ namespace VeraCrypt bool CoreBase::IsVolumeMounted (const VolumePath &volumePath) const { - return GetMountedVolume (volumePath); + shared_ptr mountedVolume = GetMountedVolume (volumePath); + if (mountedVolume) + return true; + else + return false; } shared_ptr CoreBase::OpenVolume (shared_ptr volumePath, bool preserveTimestamps, shared_ptr password, int pim, shared_ptr kdf, bool truecryptMode, shared_ptr keyfiles, VolumeProtection::Enum protection, shared_ptr protectionPassword, int protectionPim, shared_ptr protectionKdf, shared_ptr protectionKeyfiles, bool sharedAccessAllowed, VolumeType::Enum volumeType, bool useBackupHeaders, bool partitionInSystemEncryptionScope) const diff --git a/src/Core/Unix/CoreService.cpp b/src/Core/Unix/CoreService.cpp index 41cc5ec9..b129eff0 100644 --- a/src/Core/Unix/CoreService.cpp +++ b/src/Core/Unix/CoreService.cpp @@ -90,7 +90,7 @@ namespace VeraCrypt { try { - Core = std::move(CoreDirect); + Core = move_ptr(CoreDirect); shared_ptr inputStream (new FileStream (inputFD != -1 ? inputFD : InputPipe->GetReadFD())); shared_ptr outputStream (new FileStream (outputFD != -1 ? outputFD : OutputPipe->GetWriteFD())); @@ -573,8 +573,8 @@ namespace VeraCrypt byte sync[] = { 0, 0x11, 0x22 }; ServiceInputStream->Write (ConstBufferPtr (sync, array_capacity (sync))); - AdminInputPipe = std::move(inPipe); - AdminOutputPipe = std::move(outPipe); + AdminInputPipe = move_ptr(inPipe); + AdminOutputPipe = move_ptr(outPipe); } void CoreService::Stop () diff --git a/src/Platform/SharedPtr.h b/src/Platform/SharedPtr.h index 7675c2a5..29669714 100644 --- a/src/Platform/SharedPtr.h +++ b/src/Platform/SharedPtr.h @@ -14,12 +14,25 @@ #define TC_HEADER_Platform_SharedPtr #include +#include #include "SharedVal.h" #ifdef nullptr namespace VeraCrypt { +#if (__cplusplus >= 201103L) + #define VC_USE_NATIVE_PTR 1 +#endif + +#ifdef VC_USE_NATIVE_PTR + +#define shared_ptr std::shared_ptr +#define make_shared std::make_shared +#define move_ptr std::move + +#else + template class SharedPtr { @@ -157,6 +170,10 @@ namespace VeraCrypt #define make_shared VeraCrypt::make_shared +#define unique_ptr auto_ptr +#define move_ptr(p) p + +#endif } #endif // nullptr diff --git a/src/Volume/EncryptionThreadPool.cpp b/src/Volume/EncryptionThreadPool.cpp index 04c32c7d..7c86bf49 100644 --- a/src/Volume/EncryptionThreadPool.cpp +++ b/src/Volume/EncryptionThreadPool.cpp @@ -125,7 +125,9 @@ namespace VeraCrypt firstFragmentWorkItem->ItemCompletedEvent.Wait(); - unique_ptr itemException = std::move(firstFragmentWorkItem->ItemException); + unique_ptr itemException; + if (firstFragmentWorkItem->ItemException.get()) + itemException = move_ptr(firstFragmentWorkItem->ItemException); firstFragmentWorkItem->State.Set (WorkItem::State::Free); WorkItemCompletedEvent.Signal(); -- cgit v1.2.3