Skip to content

Commit

Permalink
Merge commit '3bf043bb' into github_develop
Browse files Browse the repository at this point in the history
  • Loading branch information
weswmsft committed Aug 17, 2016
2 parents aa98fe5 + 3bf043b commit 00d7752
Show file tree
Hide file tree
Showing 89 changed files with 237 additions and 14,505 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@ extern "C" void __fastfail(unsigned) {
}
/* End Intrinsic Shims */

unsigned long starboardGetCurrentThreadId() {
unsigned long _loggingGetCurrentThreadId() {
return ::GetCurrentThreadId();
}

long starboardInterlockedIncrementNoFence(long volatile* addend) {
long _loggingInterlockedIncrementNoFence(long volatile* addend) {
return ::InterlockedIncrementNoFence(addend);
}

unsigned long starboardGetLastError() {
unsigned long _loggingGetLastError() {
return ::GetLastError();
}

void starboardCopyMemory(void* destination, const void* source, size_t length) {
void _loggingCopyMemory(void* destination, const void* source, size_t length) {
::CopyMemory(destination, source, length);
}

void starboardZeroMemory(void* destination, size_t length) {
void _loggingZeroMemory(void* destination, size_t length) {
::ZeroMemory(destination, length);
}

unsigned long starboardFormatMessageW(unsigned long flags,
unsigned long _loggingFormatMessageW(unsigned long flags,
const void* source,
unsigned long messageId,
unsigned long languageId,
Expand All @@ -58,18 +58,19 @@ unsigned long starboardFormatMessageW(unsigned long flags,
return ::FormatMessageW(flags, source, messageId, languageId, buffer, size, arguments);
}

void starboardOutputDebugStringW(wchar_t* outputString) {
void _loggingOutputDebugStringW(wchar_t* outputString) {
return ::OutputDebugStringW(outputString);
}

long starboardInterlockedDecrementRelease(long volatile* addend) {
long _loggingInterlockedDecrementRelease(long volatile* addend) {
return ::InterlockedDecrementRelease(addend);
}

void* starboardInterlockedCompareExchangePointer(void* volatile* destination, void* exchange, void* comparand) {
void* _loggingInterlockedCompareExchangePointer(void* volatile* destination, void* exchange, void* comparand) {
return ::InterlockedCompareExchangePointer(destination, exchange, comparand);
}

bool failFastOnUnimplemented() {
bool _loggingFailFastOnUnimplemented() {
return false;
}

47 changes: 21 additions & 26 deletions Frameworks/Logging/LoggingNative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,20 @@
#include <winmeta.h>
#include <windows.h>
#include <TraceLoggingProvider.h>
// TODO: WIL logging hook
// #include "ErrorHandling.h"

// We export the WIL logging hook from this binary
#include "ErrorHandling.h"

bool s_isRegistered = false;
std::mutex s_isRegisteredMutex;

// TODO: WIL logging hook
// This is where we store the WIL hook
// namespace wil {
// namespace details {
//
// void(__stdcall* g_pfnLoggingCallback)(wil::FailureInfo const& failure) WI_NOEXCEPT;
//
//}
//}
// This is where we store the WIL logging hook
namespace wil {
namespace details {

void(__stdcall* g_pfnLoggingCallback)(wil::FailureInfo const& failure) WI_NOEXCEPT;

}
}

void TraceVerbose(const wchar_t* tag, const wchar_t* format, ...) {
va_list varArgs;
Expand Down Expand Up @@ -76,23 +75,21 @@ void TraceCritical(const wchar_t* tag, const wchar_t* format, ...) {
va_end(varArgs);
}

// TODO: WIL logging hook
// void __stdcall _wilLoggingCallback(wil::FailureInfo const& failure) {
// wchar_t debugString[2048];
// wil::GetFailureLogString(debugString, _countof(debugString), failure);
// TraceVerbose(L"WIL", debugString);
//}
// WIL logging hook
void __stdcall _wilLoggingCallback(wil::FailureInfo const& failure) {
wchar_t debugString[2048];
wil::GetFailureLogString(debugString, _countof(debugString), failure);
TraceError(L"WIL", debugString);
}

void TraceRegister() {
if (!s_isRegistered) {
s_isRegistered = true;
TraceLoggingRegister(s_traceLoggingProvider);
}

// TODO: WIL logging hook
// if (wil::details::g_pfnLoggingCallback == nullptr) {
// wil::details::g_pfnLoggingCallback = &_wilLoggingCallback;
//}
// Set WIL logging hook
wil::SetResultLoggingCallback(&_wilLoggingCallback);
}

void TraceUnregister() {
Expand All @@ -101,8 +98,6 @@ void TraceUnregister() {
TraceLoggingUnregister(s_traceLoggingProvider);
}

// TODO: WIL logging hook
// if (wil::details::g_pfnLoggingCallback == &_wilLoggingCallback) {
// wil::details::g_pfnLoggingCallback = nullptr;
//}
// Clear WIL logging hook
wil::SetResultLoggingCallback(nullptr);
}
75 changes: 36 additions & 39 deletions Frameworks/include/ErrorHandling.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
#ifndef __ERRORHANDLING_H
#define __ERRORHANDLING_H

#include "LoggingNative.h"

#include <sys/cdefs.h>
#include <winerror.h>
#include <stdarg.h>
#include <StarboardExport.h>

namespace wil {
struct FailureInfo;
Expand Down Expand Up @@ -197,54 +198,50 @@ struct OBJC_ENUM_FLAG_SIZED_INTEGER {
#pragma push_macro("InterlockedCompareExchangePointer")
#undef InterlockedCompareExchangePointer

__BEGIN_DECLS

// Should hitting the UNIMPLEMENTED macro cause a fast fail? If this returns false, we still log unimplemented calls but they are not fatal.
SB_EXPORT bool failFastOnUnimplemented();
LOGGING_EXPORT bool _loggingFailFastOnUnimplemented();

// Error-handling exports
SB_EXPORT unsigned long starboardGetCurrentThreadId();
SB_EXPORT long starboardInterlockedIncrementNoFence(long volatile* addend);
SB_EXPORT unsigned long starboardGetLastError();
SB_EXPORT void starboardCopyMemory(void* destination, const void* source, size_t length);
SB_EXPORT void starboardZeroMemory(void* destination, size_t length);
SB_EXPORT unsigned long starboardFormatMessageW(unsigned long flags,
const void* source,
unsigned long messageId,
unsigned long languageId,
wchar_t* buffer,
unsigned long size,
va_list* arguments);
SB_EXPORT void starboardOutputDebugStringW(wchar_t* outputString);
SB_EXPORT long starboardInterlockedDecrementRelease(long volatile* addend);
SB_EXPORT void* starboardInterlockedCompareExchangePointer(void* volatile* destination, void* exchange, void* comparand);

__END_DECLS

#define GetCurrentThreadId starboardGetCurrentThreadId
LOGGING_EXPORT unsigned long _loggingGetCurrentThreadId();
LOGGING_EXPORT long _loggingInterlockedIncrementNoFence(long volatile* addend);
LOGGING_EXPORT unsigned long _loggingGetLastError();
LOGGING_EXPORT void _loggingCopyMemory(void* destination, const void* source, size_t length);
LOGGING_EXPORT void _loggingZeroMemory(void* destination, size_t length);
LOGGING_EXPORT unsigned long _loggingFormatMessageW(unsigned long flags,
const void* source,
unsigned long messageId,
unsigned long languageId,
wchar_t* buffer,
unsigned long size,
va_list* arguments);
LOGGING_EXPORT void _loggingOutputDebugStringW(wchar_t* outputString);
LOGGING_EXPORT long _loggingInterlockedDecrementRelease(long volatile* addend);
LOGGING_EXPORT void* _loggingInterlockedCompareExchangePointer(void* volatile* destination, void* exchange, void* comparand);

#define GetCurrentThreadId _loggingGetCurrentThreadId
#ifdef InterlockedIncrementNoFence
#undef InterlockedIncrementNoFence
#endif
#define InterlockedIncrementNoFence starboardInterlockedIncrementNoFence
#define GetLastError starboardGetLastError
#define InterlockedIncrementNoFence _loggingInterlockedIncrementNoFence
#define GetLastError _loggingGetLastError
#ifdef CopyMemory
#undef CopyMemory
#endif
#define CopyMemory starboardCopyMemory
#define CopyMemory _loggingCopyMemory
#ifdef ZeroMemory
#undef ZeroMemory
#endif
#define ZeroMemory starboardZeroMemory
#define FormatMessageW starboardFormatMessageW
#define OutputDebugStringW starboardOutputDebugStringW
#define ZeroMemory _loggingZeroMemory
#define FormatMessageW _loggingFormatMessageW
#define OutputDebugStringW _loggingOutputDebugStringW
#ifdef InterlockedDecrementRelease
#undef InterlockedDecrementRelease
#endif
#define InterlockedDecrementRelease starboardInterlockedDecrementRelease
#define InterlockedDecrementRelease _loggingInterlockedDecrementRelease
#ifdef InterlockedCompareExchangePointer
#undef InterlockedCompareExchangePointer
#endif
#define InterlockedCompareExchangePointer starboardInterlockedCompareExchangePointer
#define InterlockedCompareExchangePointer _loggingInterlockedCompareExchangePointer

// Ignore some warnings in result.h
#if defined __clang__
Expand Down Expand Up @@ -313,20 +310,20 @@ __END_DECLS
//*****************************************************************************

// This should be used for functions which have no implementation yet:
#define UNIMPLEMENTED() \
if (failFastOnUnimplemented()) { \
FAIL_FAST_HR(E_NOTIMPL); \
} else { \
#define UNIMPLEMENTED() \
if (_loggingFailFastOnUnimplemented()) { \
FAIL_FAST_HR(E_NOTIMPL); \
} else { \
LOG_HR_MSG(E_NOTIMPL, "Stubbed function called!"); \
}

// This should be used to convey information along with the fact that something isn't implemented. For example, if we have a
// portion of a function implemented but we've hit something unsupported:
#define UNIMPLEMENTED_WITH_MSG(msg, ...) \
if (failFastOnUnimplemented()) { \
#define UNIMPLEMENTED_WITH_MSG(msg, ...) \
if (_loggingFailFastOnUnimplemented()) { \
FAIL_FAST_HR_MSG(E_NOTIMPL, msg, __VA_ARGS__); \
} else { \
LOG_HR_MSG(E_NOTIMPL, msg, __VA_ARGS__); \
} else { \
LOG_HR_MSG(E_NOTIMPL, msg, __VA_ARGS__); \
}

#endif // __ERRORHANDLING_H
23 changes: 9 additions & 14 deletions Frameworks/include/Telemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,45 @@
//******************************************************************************
#pragma once

#ifdef __cplusplus
extern "C" {
#endif
#include "LoggingNative.h"

//
// Send a telemetry event with the given name. E.g.:
//
// TelemetryEvent(L"MY_EVENT");
//
void TelemetryEvent(const wchar_t* name);
LOGGING_EXPORT void TelemetryEvent(const wchar_t* name);

//
// Send telemetry metric with name and value. E.g.:
//
// TelemetryMetric(L"MY_METRIC", 1.23);
//
void TelemetryMetric(const wchar_t* name, double value);
LOGGING_EXPORT void TelemetryMetric(const wchar_t* name, double value);

//
// Send a verbose telemetry trace. Also sends to local TraceVerbose. E.g.:
//
// TelemetryTraceVerbose(L"MY_TAG", "Message");
//
void TelemetryTraceVerbose(const wchar_t* tag, const wchar_t* format, ...);
LOGGING_EXPORT void TelemetryTraceVerbose(const wchar_t* tag, const wchar_t* format, ...);

//
// Send an info telemetry trace. Also sends to local TraceInfo.
//
void TelemetryTraceInfo(const wchar_t* tag, const wchar_t* format, ...);
LOGGING_EXPORT void TelemetryTraceInfo(const wchar_t* tag, const wchar_t* format, ...);

//
// Send a warning telemetry trace. Also sends to local TraceWarning.
//
void TelemetryTraceWarning(const wchar_t* tag, const wchar_t* format, ...);
LOGGING_EXPORT void TelemetryTraceWarning(const wchar_t* tag, const wchar_t* format, ...);

//
// Send an error telemetry trace. Also sends to local TraceError.
//
void TelemetryTraceError(const wchar_t* tag, const wchar_t* format, ...);
LOGGING_EXPORT void TelemetryTraceError(const wchar_t* tag, const wchar_t* format, ...);

//
// Send a critical telemetry trace. Also sends to local TraceCritical.
//
void TelemetryTraceCritical(const wchar_t* tag, const wchar_t* format, ...);

#ifdef __cplusplus
}
#endif
LOGGING_EXPORT void TelemetryTraceCritical(const wchar_t* tag, const wchar_t* format, ...);
27 changes: 7 additions & 20 deletions Frameworks/include/wil/result.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ typedef _Return_type_success_(return >= 0) LONG NTSTATUS;

#ifndef WIL_EXPORT
#ifdef __cplusplus
#define WIL_EXPORT WIL_IMPEXP extern "C"
#define WIL_EXPORT extern "C" WIL_IMPEXP
#else
#define WIL_EXPORT WIL_IMPEXP extern
#define WIL_EXPORT extern WIL_IMPEXP
#endif
#endif

Expand Down Expand Up @@ -1689,9 +1689,8 @@ namespace details {
__declspec(selectany) void(__stdcall* g_pfnTelemetryCallback)(bool alreadyReported, wil::FailureInfo const& failure) WI_NOEXCEPT = nullptr;

// Observe all errors flowing through the system with this callback (set with wil::SetResultLoggingCallback); use with custom logging
// TODO: WIL logging callback
// WIL_EXPORT void(__stdcall* g_pfnLoggingCallback)(wil::FailureInfo const& failure) WI_NOEXCEPT;
__declspec(selectany) void(__stdcall* g_pfnLoggingCallback)(wil::FailureInfo const& failure) WI_NOEXCEPT = nullptr;
// WIL logging callback; exported from our logging binary so the same instance is shared across all of our modules in a given process.
WIL_EXPORT void(__stdcall* g_pfnLoggingCallback)(wil::FailureInfo const& failure) WI_NOEXCEPT;

// True if g_pfnResultLoggingCallback is set (allows cutting off backwards compat calls to the function)
__declspec(selectany) bool g_resultMessageCallbackSet = false;
Expand Down Expand Up @@ -2554,7 +2553,7 @@ inline void SetResultTelemetryFallback(_In_opt_ decltype(details::g_pfnTelemetry

inline void SetResultLoggingCallback(_In_opt_ decltype(details::g_pfnLoggingCallback) callbackFunction) {
// Only ONE function can own the result logging callback
__FAIL_FAST_PRERELEASE_ASSERT__((details::g_pfnLoggingCallback == nullptr) || (callbackFunction == nullptr));
__FAIL_FAST_PRERELEASE_ASSERT__((details::g_pfnLoggingCallback == nullptr) || (details::g_pfnLoggingCallback == callbackFunction) || (callbackFunction == nullptr));
details::g_pfnLoggingCallback = callbackFunction;
}

Expand Down Expand Up @@ -3067,16 +3066,9 @@ inline void LogFailure(__R_FN_PARAMS_FULL,
// Caller bug: Leaking a success code into a failure-only function
FAIL_FAST_IF(SUCCEEDED(failure->hr) && (type != FailureType::FailFast));

// TODO: We probably don't want to do this once we've hooked into our logging/telemetry pipeline,
// as that will *also* log to the debugger.
// We log to OutputDebugString if:
// * Someone set g_fResultOutputDebugString to true (by the calling module or in the debugger)
bool const fUseOutputDebugString = g_fResultOutputDebugString;

// We need to generate the logging message if:
// * We're logging to OutputDebugString
// * OR the caller asked us to (generally for attaching to a C++/CX exception)
if (fWantDebugString || fUseOutputDebugString) {
// * The caller asked us to (generally for attaching to a C++/CX exception)
if (fWantDebugString) {
// Call the logging callback (if present) to allow them to generate the debug string that will be pushed to the console
// or the platform exception object if the caller desires it.
if (g_pfnResultLoggingCallback != nullptr) {
Expand All @@ -3088,11 +3080,6 @@ inline void LogFailure(__R_FN_PARAMS_FULL,
if (debugString[0] == L'\0') {
GetFailureLogString(debugString, debugStringSizeChars, *failure);
}

// Log to the debugger if required
if (fUseOutputDebugString) {
::OutputDebugStringW(debugString);
}
} else {
// [deprecated behavior]
// This callback was at one point *always* called for all failures, so we continue to call it for failures even when we don't
Expand Down
3 changes: 0 additions & 3 deletions build/ImageIO/dll/ImageIO.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
<None Include="ImageIO.def" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Logging\dll\Logging.vcxproj">
<Project>{862d36c2-cc83-4d04-b9b8-bef07f479905}</Project>
</ProjectReference>
<ProjectReference Include="..\..\CoreGraphics\dll\CoreGraphics.vcxproj">
<Project>{26DA08DA-D0B9-4579-B168-E7F0A5F20E57}</Project>
</ProjectReference>
Expand Down
Loading

0 comments on commit 00d7752

Please sign in to comment.