Skip to content
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ target_compile_definitions(crashpad_interface INTERFACE
CRASHPAD_LSS_SOURCE_EMBEDDED
)

if(MSVC)
if(WIN32)
target_compile_definitions(crashpad_interface INTERFACE
NOMINMAX
UNICODE
Expand All @@ -108,6 +108,8 @@ if(MSVC)
_HAS_EXCEPTIONS=0
_UNICODE
)
endif()
if(MSVC)
string(REGEX REPLACE "/[Ww][0123]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string(REGEX REPLACE "/[Ww][0123]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
target_compile_options(crashpad_interface INTERFACE
Expand Down Expand Up @@ -135,6 +137,11 @@ elseif(MINGW)
# redirect to wmain
# FIXME: cmake 3.13 added target_link_options
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -municode")
if(CRASHPAD_WER_ENABLED)
message(STATUS "WER support enabled")
else()
message(STATUS "WER support disabled. Define CRASHPAD_WER_ENABLED = TRUE to enable.")
endif()
endif()
add_library(crashpad::interface ALIAS crashpad_interface)

Expand Down
30 changes: 30 additions & 0 deletions compat/mingw/dbghelp.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,36 @@ typedef struct MINIDUMP_MISC_INFO_5 MINIDUMP_MISC_INFO_N;

#endif

#ifdef __cplusplus
extern "C" {
#endif

//! \brief Contains the name of the thread with the given thread ID.
struct __attribute__((packed, aligned(4))) MINIDUMP_THREAD_NAME {
//! \brief The identifier of the thread.
uint32_t ThreadId;

//! \brief RVA64 of a MINIDUMP_STRING containing the name of the thread.
RVA64 RvaOfThreadName;
};

//! \brief Variable-sized struct which contains a list of MINIDUMP_THREAD_NAME
//! structs.
struct __attribute__((packed, aligned(4))) MINIDUMP_THREAD_NAME_LIST {
//! \brief The number of MINIDUMP_THREAD_NAME structs following this field.
uint32_t NumberOfThreadNames;

//! \brief A variably-sized array containing zero of more
//! MINIDUMP_THREAD_NAME.
//! The length of the array is indicated by the NumberOfThreadNames field
//! in this struct.
struct MINIDUMP_THREAD_NAME ThreadNames[0];
};

#ifdef __cplusplus
}
#endif

#pragma clang diagnostic pop

#endif // CRASHPAD_COMPAT_MINGW_DBGHELP_H_
28 changes: 28 additions & 0 deletions compat/mingw/werapi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2015 The Crashpad Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef CRASHPAD_COMPAT_MINGW_WERAPI_H_
#define CRASHPAD_COMPAT_MINGW_WERAPI_H_

typedef HANDLE HREPORT;

#ifndef WER_MAX_PREFERRED_MODULES_BUFFER
#define WER_MAX_PREFERRED_MODULES_BUFFER 256
#endif

#define PWER_SUBMIT_RESULT WER_SUBMIT_RESULT*

#include_next <werapi.h>

#endif // CRASHPAD_COMPAT_MINGW_WERAPI_H_
12 changes: 12 additions & 0 deletions compat/mingw/winnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,16 @@ struct PROCESSOR_POWER_INFORMATION {
#define PROCESSOR_ARCHITECTURE_ARM32_ON_WIN64 13
#endif

#include <apisetcconv.h>

#ifdef __cplusplus
extern "C" {
#endif

WINBASEAPI HRESULT WINAPI GetThreadDescription(HANDLE,PWSTR *);

#ifdef __cplusplus
}
#endif

#endif // CRASHPAD_COMPAT_MINGW_WINNT_H_
3 changes: 3 additions & 0 deletions handler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,12 @@ if(CRASHPAD_WER_ENABLED)
target_link_libraries(crashpad_wer
PRIVATE
$<BUILD_INTERFACE:crashpad_interface>
PUBLIC
crashpad_compat
)

set_property(TARGET crashpad_wer PROPERTY EXPORT_NAME crashpad_wer)
set_property(TARGET crashpad_wer PROPERTY PREFIX "") # ensure MINGW doesn't prefix "lib" to dll name
add_library(crashpad::wer ALIAS crashpad_wer)

install(TARGETS crashpad_wer EXPORT crashpad_export
Expand Down
9 changes: 9 additions & 0 deletions snapshot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ if(WIN32)
"-Wno-unknown-attributes"
)
endif()

# Define NTDDI_VERSION >= NTDDI_WIN10_RS5 - so InitializeContext2 definition is always available in process_reader_win.cc
# NTDDI_WIN10_RS5 = 0x0A000006 /* ABRACADABRA_WIN10_RS5 */
set_property(
SOURCE "win/process_reader_win.cc"
APPEND
PROPERTY COMPILE_DEFINITIONS
WINVER=0x0A00 _WIN32_WINNT=0x0A00 NTDDI_VERSION=0x0A000006
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please set these definitions only for MinGW?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC (it’s been a bit since I tested) these definitions were also needed - even if using a modern Windows 10 / 11 SDK that has the appropriate header entries - when compiling with MSVC if CMAKE_SYSTEM_VERSION (for the embedding sentry-native project) was set to < 10 (targeting a Windows 7 minimum, for example).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer that we make this as conditional as possible. The crashpad build scripts are littered with unconditional settings that only make sense in a subset of the configurations affected. Since no CI setup would test (at least the build of) MSVC projects targeting Windows 7 (which we also don't officially support), these settings should be isolated as much as possible.

How about wrapping it inside something along the lines of

if (MINGW OR ("${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}" STREQUAL ""))
endif()

this should hit all MSVC target configurations below 10 (since it either isn't defined or empty), and it will work for MinGW.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, a check on CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION doesn't cover at least one common MSVC scenario.

Testing this with latest MSVC & Windows SDK, embedding sentry-native + these patches into a project with set(CMAKE_SYSTEM_VERSION "6.1"):

CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION is set in this case (10.0.20348.0, as it is picking it up from the installed recent Windows SDK), but with actual targeting set at Windows 7+, this CMake check is insufficient and compilation ultimately fails on MSVC.

[...] external\crashpad\snapshot\win\process_reader_win.cc(332,7): error C2039: 'InitializeContext2': is not a member of '`global namespace''
(etc)

So the NTDDI_VERSION (etc) overrides are still required to expose the definitions.

I've adjusted this check to:
if (MINGW OR ("${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}" STREQUAL "") OR (CMAKE_SYSTEM_VERSION LESS 10))

which does work in the several scenarios I've tested.

endif()

if(APPLE AND NOT IOS AND CRASHPAD_ENABLE_STACKTRACE)
Expand Down
6 changes: 1 addition & 5 deletions third_party/zlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
if(CRASHPAD_ZLIB_SYSTEM)
add_library(crashpad_zlib INTERFACE)
string(REPLACE ";" "$<SEMICOLON>" GENEX_ZLIB_LIBRARIES "${ZLIB_LIBRARIES}")
target_include_directories(crashpad_zlib INTERFACE
$<BUILD_INTERFACE:${ZLIB_INCLUDE_DIRS}>
)
target_compile_definitions(crashpad_zlib INTERFACE
ZLIB_CONST
CRASHPAD_ZLIB_SOURCE_SYSTEM
$<BUILD_INTERFACE:${ZLIB_COMPILE_DEFINITIONS}>
)
target_link_libraries(crashpad_zlib INTERFACE $<BUILD_INTERFACE:${GENEX_ZLIB_LIBRARIES}>)
target_link_libraries(crashpad_zlib INTERFACE ZLIB::ZLIB)
else()
add_library(crashpad_zlib STATIC
zlib/adler32.c
Expand Down