From c0398e417481750c2ca90cfc97020786f05c6d63 Mon Sep 17 00:00:00 2001 From: Brian Sheedy Date: Thu, 13 Apr 2023 20:41:23 +0000 Subject: [PATCH] Skip logging on Win official builds Skips logging in sandboxed processes on Windows official builds since the file handles will not be set properly, causing crashes when we try to write to stdout/stderr. Bug: chromium:1429665 Change-Id: Ie70d0cc2e096bd22490dc3538467752b448f213b Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/127205 Kokoro: Kokoro Auto-Submit: Brian Sheedy Reviewed-by: Austin Eng Commit-Queue: Brian Sheedy --- src/dawn/common/Log.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/dawn/common/Log.cpp b/src/dawn/common/Log.cpp index 265d156bff..c7a180b2ff 100644 --- a/src/dawn/common/Log.cpp +++ b/src/dawn/common/Log.cpp @@ -23,6 +23,9 @@ #if DAWN_PLATFORM_IS(ANDROID) #include #endif +#if DAWN_PLATFORM_IS(WINDOWS) +#include +#endif namespace dawn { @@ -99,6 +102,20 @@ LogMessage::~LogMessage() { outputStream = stderr; } +#if DAWN_PLATFORM_IS(WINDOWS) && defined(OFFICIAL_BUILD) + // If we are in a sandboxed process on an official build, the stdout/stderr + // handles are likely not set, so trying to log to them will crash. + HANDLE handle; + if (outputStream == stderr) { + handle = GetStdHandle(STD_ERROR_HANDLE); + } else { + handle = GetStdHandle(STD_OUTPUT_HANDLE); + } + if (handle == INVALID_HANDLE_VALUE) { + return; + } +#endif // DAWN_PLATFORM_IS(WINDOWS) && defined(OFFICIAL_BUILD) + // Note: we use fprintf because includes static initializers. fprintf(outputStream, "%s: %s\n", severityName, fullMessage.c_str()); fflush(outputStream);