From cd367d4402f344bbc8061e3b74f95d9b0a47f937 Mon Sep 17 00:00:00 2001 From: Augusto Righetto Date: Mon, 13 Jan 2020 15:34:20 -0800 Subject: [PATCH 1/3] BuildBreak: UWP apps can't call GetModuleHandle It is not possible to load RtlCaptureStackBackTrace at static init time in UWP. CaptureStackBackTrace is the public version of RtlCaptureStackBackTrace. --- absl/debugging/internal/stacktrace_win32-inl.inc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/absl/debugging/internal/stacktrace_win32-inl.inc b/absl/debugging/internal/stacktrace_win32-inl.inc index 9c2c558044d..1e3e64ffe42 100644 --- a/absl/debugging/internal/stacktrace_win32-inl.inc +++ b/absl/debugging/internal/stacktrace_win32-inl.inc @@ -46,11 +46,19 @@ typedef USHORT NTAPI RtlCaptureStackBackTrace_Function( OUT PVOID *backtrace, OUT PULONG backtrace_hash); +// It is not possible to load RtlCaptureStackBackTrace at static init time in +// UWP. CaptureStackBackTrace is the public version of +// RtlCaptureStackBackTrace. +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_APP) // Load the function we need at static init time, where we don't have // to worry about someone else holding the loader's lock. static RtlCaptureStackBackTrace_Function* const RtlCaptureStackBackTrace_fn = (RtlCaptureStackBackTrace_Function*) GetProcAddress(GetModuleHandleA("ntdll.dll"), "RtlCaptureStackBackTrace"); +#else +static RtlCaptureStackBackTrace_Function* const RtlCaptureStackBackTrace_fn = + &::CaptureStackBackTrace; +#endif template static int UnwindImpl(void** result, int* sizes, int max_depth, int skip_count, From 77c43e6cafb749fbcee93fab13fbf0a5558aa4d1 Mon Sep 17 00:00:00 2001 From: Augusto Righetto Date: Tue, 21 Jan 2020 15:03:09 -0800 Subject: [PATCH 2/3] Using WINAPI_FAMILY_PARTITION family of macros Using WINAPI_FAMILY_PARTITION family of macros for detecting when building for UWP or Desktop. --- absl/debugging/internal/stacktrace_win32-inl.inc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/absl/debugging/internal/stacktrace_win32-inl.inc b/absl/debugging/internal/stacktrace_win32-inl.inc index 1e3e64ffe42..0d668ab6209 100644 --- a/absl/debugging/internal/stacktrace_win32-inl.inc +++ b/absl/debugging/internal/stacktrace_win32-inl.inc @@ -47,18 +47,19 @@ typedef USHORT NTAPI RtlCaptureStackBackTrace_Function( OUT PULONG backtrace_hash); // It is not possible to load RtlCaptureStackBackTrace at static init time in -// UWP. CaptureStackBackTrace is the public version of -// RtlCaptureStackBackTrace. -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_APP) +// UWP. CaptureStackBackTrace is the public version of RtlCaptureStackBackTrace +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ + !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +static RtlCaptureStackBackTrace_Function* const RtlCaptureStackBackTrace_fn = + &::CaptureStackBackTrace; +#else // Load the function we need at static init time, where we don't have // to worry about someone else holding the loader's lock. static RtlCaptureStackBackTrace_Function* const RtlCaptureStackBackTrace_fn = (RtlCaptureStackBackTrace_Function*) GetProcAddress(GetModuleHandleA("ntdll.dll"), "RtlCaptureStackBackTrace"); -#else -static RtlCaptureStackBackTrace_Function* const RtlCaptureStackBackTrace_fn = - &::CaptureStackBackTrace; -#endif +#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ + !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) */ template static int UnwindImpl(void** result, int* sizes, int max_depth, int skip_count, From d6bf203408747600a28dee226d25c411ae87ba9b Mon Sep 17 00:00:00 2001 From: Augusto Righetto Date: Mon, 27 Jan 2020 16:00:05 -0800 Subject: [PATCH 3/3] Simplifying comment to please lint tool. --- absl/debugging/internal/stacktrace_win32-inl.inc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/absl/debugging/internal/stacktrace_win32-inl.inc b/absl/debugging/internal/stacktrace_win32-inl.inc index 0d668ab6209..af4578a506b 100644 --- a/absl/debugging/internal/stacktrace_win32-inl.inc +++ b/absl/debugging/internal/stacktrace_win32-inl.inc @@ -58,8 +58,7 @@ static RtlCaptureStackBackTrace_Function* const RtlCaptureStackBackTrace_fn = static RtlCaptureStackBackTrace_Function* const RtlCaptureStackBackTrace_fn = (RtlCaptureStackBackTrace_Function*) GetProcAddress(GetModuleHandleA("ntdll.dll"), "RtlCaptureStackBackTrace"); -#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ - !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) */ +#endif // WINAPI_PARTITION_APP && !WINAPI_PARTITION_DESKTOP template static int UnwindImpl(void** result, int* sizes, int max_depth, int skip_count,