aboutsummaryrefslogtreecommitdiffstats
path: root/api/namespace.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-11-02 12:07:05 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-11-02 12:07:05 +0100
commit007db8bd94b2dd4ded9ceeb8a248ea2ba8d5ab06 (patch)
tree3042fcb09e4cd09caffc23323b979f69530904df /api/namespace.c
parentapi: make nci.lib work on x86 (diff)
downloadwintun-007db8bd94b2dd4ded9ceeb8a248ea2ba8d5ab06.tar.xz
wintun-007db8bd94b2dd4ded9ceeb8a248ea2ba8d5ab06.zip
api: serialize driver installation
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'api/namespace.c')
-rw-r--r--api/namespace.c26
1 files changed, 25 insertions, 1 deletions
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)
{