summaryrefslogtreecommitdiff
path: root/src/mir_app
diff options
context:
space:
mode:
authormikalair <mikalair@outlook.com>2019-02-01 18:18:19 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-02-01 20:56:17 +0200
commit0f3d6c04c20a21238a23102b0f3d01724eb3ac07 (patch)
tree14337ac4f236d737d2121fb43c347a85a260d224 /src/mir_app
parentd467d6677409c0a9db4dab1bdcb0d128fec1d6d0 (diff)
Initialize OpenSSL locks
Diffstat (limited to 'src/mir_app')
-rw-r--r--src/mir_app/mir_app.vcxproj2
-rw-r--r--src/mir_app/src/miranda.cpp5
-rw-r--r--src/mir_app/src/openssl.cpp67
-rw-r--r--src/mir_app/src/openssl.h30
4 files changed, 104 insertions, 0 deletions
diff --git a/src/mir_app/mir_app.vcxproj b/src/mir_app/mir_app.vcxproj
index 7ef633707c..720b8c50ba 100644
--- a/src/mir_app/mir_app.vcxproj
+++ b/src/mir_app/mir_app.vcxproj
@@ -21,6 +21,7 @@
<PropertyGroup Label="Globals">
<ProjectGuid>{538E451F-E667-4D07-BCE6-976ECC7BB8D1}</ProjectGuid>
<ProjectName>mir_app</ProjectName>
+ <WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(ProjectDir)..\..\build\vc.common\lib.props" />
@@ -35,6 +36,7 @@
<ModuleDefinitionFile Condition="'$(Platform)'=='x64'">src/mir_app64.def</ModuleDefinitionFile>
<AdditionalOptions>/ignore:4197 %(AdditionalOptions)</AdditionalOptions>
<AdditionalManifestDependencies>type=%27win32%27 name=%27Microsoft.Windows.Common-Controls%27 version=%276.0.0.0%27 processorArchitecture=%27*%27 publicKeyToken=%276595b64144ccf1df%27 language=%27*%27;type=%27win32%27 name=%27Microsoft.Windows.Gdiplus%27 version=%271.0.0.0%27 processorArchitecture=%27amd64%27 publicKeyToken=%276595b64144ccf1df%27 language=%27*%27;%(AdditionalManifestDependencies)</AdditionalManifestDependencies>
+ <AdditionalDependencies>libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Manifest>
<AdditionalManifestFiles>res/miranda32.exe.manifest</AdditionalManifestFiles>
diff --git a/src/mir_app/src/miranda.cpp b/src/mir_app/src/miranda.cpp
index 23e99d1643..423f709d75 100644
--- a/src/mir_app/src/miranda.cpp
+++ b/src/mir_app/src/miranda.cpp
@@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "stdafx.h"
+#include "openssl.h"
#if defined(VLD_ENABLED)
#include "msapi\vld.h"
@@ -325,6 +326,8 @@ int WINAPI mir_main(LPTSTR cmdLine)
if (IsWinVer7Plus())
CoCreateInstance(CLSID_TaskbarList, nullptr, CLSCTX_ALL, IID_ITaskbarList3, (void**)&pTaskbarInterface);
+ OpenSSL_Init();
+
int result = 0;
if (LoadDefaultModules()) {
g_bMirandaTerminated = true;
@@ -403,6 +406,8 @@ int WINAPI mir_main(LPTSTR cmdLine)
if (pTaskbarInterface)
pTaskbarInterface->Release();
+ OpenSSL_Cleanup();
+
OleUninitialize();
if (bufferedPaintUninit)
diff --git a/src/mir_app/src/openssl.cpp b/src/mir_app/src/openssl.cpp
new file mode 100644
index 0000000000..2a41e01437
--- /dev/null
+++ b/src/mir_app/src/openssl.cpp
@@ -0,0 +1,67 @@
+/*
+
+Miranda NG: the free IM client for Microsoft* Windows*
+
+Copyright (C) 2012-19 Miranda NG team (https://miranda-ng.org),
+Copyright (c) 2000-12 Miranda IM project,
+all portions of this codebase are copyrighted to the people
+listed in contributors.txt.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "stdafx.h"
+#include "openssl.h"
+
+
+static HANDLE *mutexes;
+
+unsigned long OpenSSL_thread_id()
+{
+ return static_cast<unsigned long>(GetCurrentThreadId());
+}
+
+void OpenSSL_lock(int mode, int n, const char *, int)
+{
+ if (mode & CRYPTO_LOCK) {
+ WaitForSingleObject(mutexes[n], INFINITE);
+ } else {
+ ReleaseMutex(mutexes[n]);
+ }
+}
+
+void OpenSSL_Init() {
+ int num_locks = CRYPTO_num_locks();
+
+ mutexes = new HANDLE[num_locks];
+
+ for (int i = 0; i < num_locks; ++i) {
+ mutexes[i] = CreateMutex(nullptr, FALSE, nullptr);
+ }
+
+ CRYPTO_set_id_callback(OpenSSL_thread_id);
+ CRYPTO_set_locking_callback(OpenSSL_lock);
+}
+
+void OpenSSL_Cleanup(){
+ CRYPTO_set_id_callback(nullptr);
+ CRYPTO_set_locking_callback(nullptr);
+
+ for (int i = 0; i < CRYPTO_num_locks(); ++i) {
+ CloseHandle(mutexes[i]);
+ }
+
+ delete[] mutexes;
+} \ No newline at end of file
diff --git a/src/mir_app/src/openssl.h b/src/mir_app/src/openssl.h
new file mode 100644
index 0000000000..8791ce28d0
--- /dev/null
+++ b/src/mir_app/src/openssl.h
@@ -0,0 +1,30 @@
+/*
+
+Miranda NG: the free IM client for Microsoft* Windows*
+
+Copyright (C) 2012-19 Miranda NG team (https://miranda-ng.org),
+Copyright (c) 2000-12 Miranda IM project,
+all portions of this codebase are copyrighted to the people
+listed in contributors.txt.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#pragma once
+
+#include <openssl/err.h>
+
+void OpenSSL_Init();
+void OpenSSL_Cleanup();