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 <noreply+kokoro@google.com>
Auto-Submit: Brian Sheedy <bsheedy@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Brian Sheedy <bsheedy@google.com>
This commit is contained in:
Brian Sheedy 2023-04-13 20:41:23 +00:00 committed by Dawn LUCI CQ
parent a49353d4cd
commit c0398e4174
1 changed files with 17 additions and 0 deletions

View File

@ -23,6 +23,9 @@
#if DAWN_PLATFORM_IS(ANDROID) #if DAWN_PLATFORM_IS(ANDROID)
#include <android/log.h> #include <android/log.h>
#endif #endif
#if DAWN_PLATFORM_IS(WINDOWS)
#include <windows.h>
#endif
namespace dawn { namespace dawn {
@ -99,6 +102,20 @@ LogMessage::~LogMessage() {
outputStream = stderr; 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 <iostream> includes static initializers. // Note: we use fprintf because <iostream> includes static initializers.
fprintf(outputStream, "%s: %s\n", severityName, fullMessage.c_str()); fprintf(outputStream, "%s: %s\n", severityName, fullMessage.c_str());
fflush(outputStream); fflush(outputStream);