@@ -32,7 +32,7 @@ static _Return_type_success_(
3232 Free (Str );
3333 if (GetLastError () != ERROR_INSUFFICIENT_BUFFER )
3434 {
35- LOG_LAST_ERROR (L"Failed" );
35+ LOG_LAST_ERROR (L"Failed: %s" , Source );
3636 return NULL ;
3737 }
3838 Len = - Len ;
@@ -53,7 +53,7 @@ static _Return_type_success_(return != FALSE) BOOL NamespaceRuntimeInit(void)
5353 NTSTATUS Status ;
5454 if (!BCRYPT_SUCCESS (Status = BCryptOpenAlgorithmProvider (& AlgProvider , BCRYPT_SHA256_ALGORITHM , NULL , 0 )))
5555 {
56- LOG (WINTUN_LOG_ERR , L"Failed to open algorithm provider" );
56+ LOG (WINTUN_LOG_ERR , L"Failed to open algorithm provider (status: 0x%x)" , Status );
5757 LastError = RtlNtStatusToDosError (Status );
5858 goto cleanupLeaveCriticalSection ;
5959 }
@@ -88,10 +88,10 @@ static _Return_type_success_(return != FALSE) BOOL NamespaceRuntimeInit(void)
8888 break ;
8989 if ((LastError = GetLastError ()) == ERROR_PATH_NOT_FOUND )
9090 continue ;
91- LOG_ERROR (L"Failed to open private namespace" , LastError );
91+ LOG_ERROR (LastError , L"Failed to open private namespace" );
9292 }
9393 else
94- LOG_ERROR (L"Failed to create private namespace" , LastError );
94+ LOG_ERROR (LastError , L"Failed to create private namespace" );
9595 goto cleanupBoundaryDescriptor ;
9696 }
9797
@@ -118,7 +118,7 @@ _Return_type_success_(return != NULL) HANDLE NamespaceTakePoolMutex(_In_z_ const
118118 NTSTATUS Status ;
119119 if (!BCRYPT_SUCCESS (Status = BCryptCreateHash (AlgProvider , & Sha256 , NULL , 0 , NULL , 0 , 0 )))
120120 {
121- LOG (WINTUN_LOG_ERR , L"Failed to create hash" );
121+ LOG (WINTUN_LOG_ERR , L"Failed to create hash (status: 0x%x)" , Status );
122122 SetLastError (RtlNtStatusToDosError (Status ));
123123 return NULL ;
124124 }
@@ -127,7 +127,7 @@ _Return_type_success_(return != NULL) HANDLE NamespaceTakePoolMutex(_In_z_ const
127127 if (!BCRYPT_SUCCESS (
128128 Status = BCryptHashData (Sha256 , (PUCHAR )mutex_label , sizeof (mutex_label ) /* Including NULL 2 bytes */ , 0 )))
129129 {
130- LOG (WINTUN_LOG_ERR , L"Failed to hash data" );
130+ LOG (WINTUN_LOG_ERR , L"Failed to hash data (status: 0x%x)" , Status );
131131 LastError = RtlNtStatusToDosError (Status );
132132 goto cleanupSha256 ;
133133 }
@@ -140,14 +140,14 @@ _Return_type_success_(return != NULL) HANDLE NamespaceTakePoolMutex(_In_z_ const
140140 if (!BCRYPT_SUCCESS (
141141 Status = BCryptHashData (Sha256 , (PUCHAR )PoolNorm , (int )wcslen (PoolNorm ) + 2 /* Add in NULL 2 bytes */ , 0 )))
142142 {
143- LOG (WINTUN_LOG_ERR , L"Failed to hash data" );
143+ LOG (WINTUN_LOG_ERR , L"Failed to hash data (status: 0x%x)" , Status );
144144 LastError = RtlNtStatusToDosError (Status );
145145 goto cleanupPoolNorm ;
146146 }
147147 BYTE Hash [32 ];
148148 if (!BCRYPT_SUCCESS (Status = BCryptFinishHash (Sha256 , Hash , sizeof (Hash ), 0 )))
149149 {
150- LOG (WINTUN_LOG_ERR , L"Failed to calculate hash" );
150+ LOG (WINTUN_LOG_ERR , L"Failed to calculate hash (status: 0x%x)" , Status );
151151 LastError = RtlNtStatusToDosError (Status );
152152 goto cleanupPoolNorm ;
153153 }
@@ -159,18 +159,19 @@ _Return_type_success_(return != NULL) HANDLE NamespaceTakePoolMutex(_In_z_ const
159159 HANDLE Mutex = CreateMutexW (& SecurityAttributes , FALSE, MutexName );
160160 if (!Mutex )
161161 {
162- LastError = LOG_LAST_ERROR (L"Failed to create mutex" );
162+ LastError = LOG_LAST_ERROR (L"Failed to create mutex %s" , MutexName );
163163 goto cleanupPoolNorm ;
164164 }
165- switch (WaitForSingleObject (Mutex , INFINITE ))
165+ DWORD Result = WaitForSingleObject (Mutex , INFINITE );
166+ switch (Result )
166167 {
167168 case WAIT_OBJECT_0 :
168169 case WAIT_ABANDONED :
169170 Free (PoolNorm );
170171 BCryptDestroyHash (Sha256 );
171172 return Mutex ;
172173 }
173- LOG (WINTUN_LOG_ERR , L"Failed to get mutex" );
174+ LOG (WINTUN_LOG_ERR , L"Failed to get mutex %s (status: 0x%x)" , MutexName , Result );
174175 LastError = ERROR_GEN_FAILURE ;
175176 CloseHandle (Mutex );
176177cleanupPoolNorm :
@@ -192,13 +193,14 @@ _Return_type_success_(return != NULL) HANDLE NamespaceTakeDriverInstallationMute
192193 LOG_LAST_ERROR (L"Failed to create mutex" );
193194 return NULL ;
194195 }
195- switch (WaitForSingleObject (Mutex , INFINITE ))
196+ DWORD Result = WaitForSingleObject (Mutex , INFINITE );
197+ switch (Result )
196198 {
197199 case WAIT_OBJECT_0 :
198200 case WAIT_ABANDONED :
199201 return Mutex ;
200202 }
201- LOG (WINTUN_LOG_ERR , L"Failed to get mutex" );
203+ LOG (WINTUN_LOG_ERR , L"Failed to get mutex (status: 0x%x)" , Result );
202204 CloseHandle (Mutex );
203205 SetLastError (ERROR_GEN_FAILURE );
204206 return NULL ;
0 commit comments