Browse Source

Add additional windows logging for DoMonitor

Juliusz Sosinowicz 11 months ago
parent
commit
7af1f0cf05
3 changed files with 28 additions and 3 deletions
  1. 26 1
      src/crl.c
  2. 1 1
      wolfcrypt/src/logging.c
  3. 1 1
      wolfssl/wolfcrypt/logging.h

+ 26 - 1
src/crl.c

@@ -1339,7 +1339,32 @@ static int StopMonitor(wolfSSL_CRL_mfd_t mfd)
     return 0;
 }
 
-#define DM_ERROR() do { status = MONITOR_SETUP_E; goto cleanup; } while(0)
+#ifdef DEBUG_WOLFSSL
+#define SHOW_WINDOWS_ERROR() do {                               \
+    LPVOID lpMsgBuf;                                            \
+    DWORD dw = GetLastError();                                  \
+    FormatMessageA(                                             \
+        FORMAT_MESSAGE_ALLOCATE_BUFFER |                        \
+        FORMAT_MESSAGE_FROM_SYSTEM |                            \
+        FORMAT_MESSAGE_IGNORE_INSERTS,                          \
+        NULL,                                                   \
+        dw,                                                     \
+        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),              \
+        (LPSTR) &lpMsgBuf,                                      \
+        0, NULL );                                              \
+    WOLFSSL_MSG_EX("DoMonitor failed with error %d: %s\n",      \
+        dw, lpMsgBuf);                                          \
+    LocalFree(lpMsgBuf);                                        \
+} while(0)
+#else
+#define SHOW_WINDOWS_ERROR()
+#endif
+
+#define DM_ERROR() do {                                         \
+    SHOW_WINDOWS_ERROR();                                       \
+    status = MONITOR_SETUP_E;                                   \
+    goto cleanup;                                               \
+} while(0)
 
 /* windows monitoring
  * Tested initially by hand by running

+ 1 - 1
wolfcrypt/src/logging.c

@@ -323,7 +323,7 @@ static void wolfssl_log(const int logLevel, const char *const logMessage)
 
 #ifndef WOLFSSL_DEBUG_ERRORS_ONLY
 
-#if !defined(_WIN32) && defined(XVSNPRINTF) && !defined(NO_WOLFSSL_MSG_EX)
+#if defined(XVSNPRINTF) && !defined(NO_WOLFSSL_MSG_EX)
 #include <stdarg.h> /* for var args */
 #ifndef WOLFSSL_MSG_EX_BUF_SZ
 #define WOLFSSL_MSG_EX_BUF_SZ 100

+ 1 - 1
wolfssl/wolfcrypt/logging.h

@@ -166,7 +166,7 @@ WOLFSSL_API void wolfSSL_Debugging_OFF(void);
     #define WOLFSSL_STUB(m) \
         WOLFSSL_MSG(WOLFSSL_LOG_CAT(wolfSSL Stub, m, not implemented))
     WOLFSSL_API int WOLFSSL_IS_DEBUG_ON(void);
-#if !defined(_WIN32) && defined(XVSNPRINTF)
+#if defined(XVSNPRINTF)
     WOLFSSL_API void WOLFSSL_MSG_EX(const char* fmt, ...);
     #define HAVE_WOLFSSL_MSG_EX
 #else