From 007db8bd94b2dd4ded9ceeb8a248ea2ba8d5ab06 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 2 Nov 2020 12:07:05 +0100 Subject: api: serialize driver installation Signed-off-by: Jason A. Donenfeld --- api/namespace.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'api/namespace.c') diff --git a/api/namespace.c b/api/namespace.c index 9258b53..7f6959b 100644 --- a/api/namespace.c +++ b/api/namespace.c @@ -102,7 +102,7 @@ cleanupLeaveCriticalSection: _Check_return_ HANDLE -NamespaceTakeMutex(_In_z_ const WCHAR *Pool) +NamespaceTakePoolMutex(_In_z_ const WCHAR *Pool) { HANDLE Mutex = NULL; @@ -147,6 +147,30 @@ cleanupSha256: return Mutex; } +_Check_return_ +HANDLE +NamespaceTakeDriverInstallationMutex(void) +{ + HANDLE Mutex = NULL; + + if (NamespaceRuntimeInit() != ERROR_SUCCESS) + return NULL; + Mutex = CreateMutexW(&SecurityAttributes, FALSE, L"Wintun\\Wintun-Driver-Installation-Mutex"); + if (!Mutex) + return NULL; + switch (WaitForSingleObject(Mutex, INFINITE)) + { + case WAIT_OBJECT_0: + case WAIT_ABANDONED: + goto out; + } + + CloseHandle(Mutex); + Mutex = NULL; +out: + return Mutex; +} + void NamespaceReleaseMutex(_In_ HANDLE Mutex) { -- cgit v1.2.3-59-g8ed1b