diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-11-02 12:07:05 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-11-02 12:07:05 +0100 |
commit | 007db8bd94b2dd4ded9ceeb8a248ea2ba8d5ab06 (patch) | |
tree | 3042fcb09e4cd09caffc23323b979f69530904df /api/namespace.c | |
parent | api: make nci.lib work on x86 (diff) | |
download | wintun-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.c | 26 |
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) { |