Skip to content

Commit

Permalink
feat: add support for Xbox Series X/S. (#1100)
Browse files Browse the repository at this point in the history
  • Loading branch information
supervacuus authored Jan 13, 2025
1 parent 3981ea7 commit 65c109d
Show file tree
Hide file tree
Showing 13 changed files with 552 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

**Features**:

- Add support for Xbox Series X/S. ([#1100](https://github.com/getsentry/sentry-native/pull/1100))
- Add option to set debug log level. ([#1107](https://github.com/getsentry/sentry-native/pull/1107))
- Provide support for C++17 compilers when using the `crashpad` backend. ([#1110](https://github.com/getsentry/sentry-native/pull/1110), [crashpad#116](https://github.com/getsentry/crashpad/pull/116), [mini_chromium#1](https://github.com/getsentry/mini_chromium/pull/1))

Expand Down
40 changes: 32 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ else()
cmake_minimum_required (VERSION 3.10)
cmake_policy(SET CMP0077 NEW)
endif()
set(SENTRY_TOOLCHAINS_DIR "${CMAKE_CURRENT_LIST_DIR}/toolchains")
if ("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "Gaming.Xbox.Scarlett.x64")
include("${SENTRY_TOOLCHAINS_DIR}/xbox/CMakeGDKScarlett.cmake")
endif()

#read sentry-native version
file(READ "include/sentry.h" _SENTRY_HEADER_CONTENT)
Expand Down Expand Up @@ -69,10 +73,12 @@ option(SENTRY_TRANSPORT_COMPRESSION "Enable transport gzip compression" OFF)
option(SENTRY_BUILD_TESTS "Build sentry-native tests" "${SENTRY_MAIN_PROJECT}")
option(SENTRY_BUILD_EXAMPLES "Build sentry-native example(s)" "${SENTRY_MAIN_PROJECT}")

option(SENTRY_LINK_PTHREAD "Link platform threads library" ON)
if(SENTRY_LINK_PTHREAD)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if (NOT ("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "Gaming.Xbox.Scarlett.x64"))
option(SENTRY_LINK_PTHREAD "Link platform threads library" ON)
if(SENTRY_LINK_PTHREAD)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
endif()
endif()

if(MSVC)
Expand Down Expand Up @@ -137,6 +143,8 @@ option(SENTRY_ENABLE_INSTALL "Enable sentry installation" "${SENTRY_MAIN_PROJECT
if(MSVC AND CMAKE_GENERATOR_TOOLSET MATCHES "_xp$")
message(WARNING "Crashpad is not supported for MSVC with XP toolset. Default backend was switched to 'breakpad'")
set(SENTRY_DEFAULT_BACKEND "breakpad")
elseif(MSVC AND "${CMAKE_GENERATOR_PLATFORM}" STREQUAL "Gaming.Xbox.Scarlett.x64")
set(SENTRY_DEFAULT_BACKEND "breakpad")
elseif((APPLE AND NOT IOS) OR WIN32 OR LINUX)
set(SENTRY_DEFAULT_BACKEND "crashpad")
else()
Expand Down Expand Up @@ -233,6 +241,9 @@ endfunction()
# ===== sentry library =====

add_library(sentry ${SENTRY_LIBRARY_TYPE} "${PROJECT_SOURCE_DIR}/vendor/mpack.c")
if ("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "Gaming.Xbox.Scarlett.x64")
set_target_properties(sentry PROPERTIES VS_USER_PROPS gdk_build.props)
endif()
target_sources(sentry PRIVATE "${PROJECT_SOURCE_DIR}/include/sentry.h")
add_library(sentry::sentry ALIAS sentry)
add_subdirectory(src)
Expand Down Expand Up @@ -314,7 +325,11 @@ if(MSVC)

# using `/Wall` is not feasible, as it spews tons of warnings from windows headers
# supress C5105, introduced in VS 16.8, which breaks on the Windows SDKs own `winbase.h` header
target_compile_options(sentry PRIVATE $<BUILD_INTERFACE:/W4 /wd5105>)
if ("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "Gaming.Xbox.Scarlett.x64")
target_compile_options(sentry PRIVATE $<BUILD_INTERFACE:/W4 /wd5105 /wd4115>)
else()
target_compile_options(sentry PRIVATE $<BUILD_INTERFACE:/W4 /wd5105>)
endif()
# ignore all warnings for mpack
set_source_files_properties(
"${PROJECT_SOURCE_DIR}/vendor/mpack.c"
Expand Down Expand Up @@ -389,16 +404,22 @@ if(ANDROID)
elseif(LINUX)
set(_SENTRY_PLATFORM_LIBS "dl" "rt")
elseif(WIN32)
set(_SENTRY_PLATFORM_LIBS "dbghelp" "shlwapi" "version")
if ("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "Gaming.Xbox.Scarlett.x64")
set(_SENTRY_PLATFORM_LIBS "version")
else()
set(_SENTRY_PLATFORM_LIBS "dbghelp" "shlwapi" "version")
endif()
endif()

if(SENTRY_TRANSPORT_WINHTTP)
list(APPEND _SENTRY_PLATFORM_LIBS "winhttp")
endif()

# handle platform threads library
if(SENTRY_LINK_PTHREAD)
list(APPEND _SENTRY_PLATFORM_LIBS "Threads::Threads")
if (NOT ("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "Gaming.Xbox.Scarlett.x64"))
if(SENTRY_LINK_PTHREAD)
list(APPEND _SENTRY_PLATFORM_LIBS "Threads::Threads")
endif()
endif()

# apply platform libraries to sentry library
Expand Down Expand Up @@ -575,6 +596,9 @@ endif()

if(SENTRY_BUILD_EXAMPLES)
add_executable(sentry_example examples/example.c)
if ("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "Gaming.Xbox.Scarlett.x64")
set_target_properties(sentry_example PROPERTIES VS_USER_PROPS gdk_build.props)
endif()
target_link_libraries(sentry_example PRIVATE sentry)

if(MSVC)
Expand Down
4 changes: 3 additions & 1 deletion examples/example.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#ifdef _WIN32
# define WIN32_LEAN_AND_MEAN
# ifndef _GAMING_XBOX_SCARLETT
# define WIN32_LEAN_AND_MEAN
# endif
# define NOMINMAX
# define _CRT_SECURE_NO_WARNINGS
#endif
Expand Down
2 changes: 1 addition & 1 deletion external/breakpad
44 changes: 43 additions & 1 deletion src/modulefinder/sentry_modulefinder_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
#include "sentry_uuid.h"
#include "sentry_value.h"

#include <dbghelp.h>
#ifndef _GAMING_XBOX_SCARLETT
# include <dbghelp.h>
#else
# include <Psapi.h>
#endif
#include <tlhelp32.h>

static bool g_initialized = false;
Expand Down Expand Up @@ -91,6 +95,7 @@ extract_pdb_info(uintptr_t module_addr, sentry_value_t module)
static void
load_modules(void)
{
#ifndef _GAMING_XBOX_SCARLETT
HANDLE snapshot
= CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId());
MODULEENTRY32W module = { 0 };
Expand Down Expand Up @@ -126,6 +131,43 @@ load_modules(void)
CloseHandle(snapshot);

sentry_value_freeze(g_modules);
#else
HMODULE hMods[1024];
HANDLE hProcess = GetCurrentProcess();
DWORD cbNeeded;

g_modules = sentry_value_new_list();
if (EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded)) {
for (unsigned int i = 0; i < (cbNeeded / sizeof(HMODULE)); i++) {
wchar_t szModName[MAX_PATH];
if (GetModuleFileNameW(
hMods[i], szModName, sizeof(szModName) / sizeof(wchar_t))) {
HMODULE handle
= LoadLibraryExW(szModName, NULL, LOAD_LIBRARY_AS_DATAFILE);
MEMORY_BASIC_INFORMATION vmem_info = { 0 };
if (handle
&& sizeof(vmem_info)
== VirtualQuery(hMods[i], &vmem_info, sizeof(vmem_info))
&& vmem_info.State == MEM_COMMIT) {
sentry_value_t rv = sentry_value_new_object();
sentry_value_set_by_key(
rv, "type", sentry_value_new_string("pe"));
sentry_value_set_by_key(rv, "image_addr",
sentry__value_new_addr((uint64_t)handle));

sentry_value_set_by_key(rv, "code_file",
sentry__value_new_string_from_wstr(szModName));
extract_pdb_info((uintptr_t)handle, rv);
sentry_value_append(g_modules, rv);

FreeLibrary(handle);
}
}
}
}

sentry_value_freeze(g_modules);
#endif // _GAMING_XBOX_SCARLETT
}

sentry_value_t
Expand Down
32 changes: 28 additions & 4 deletions src/sentry_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

#ifdef SENTRY_PLATFORM_WINDOWS

# include <windows.h>
# define CURRENT_VERSION "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"
# if !defined(_GAMING_XBOX_SCARLETT)
# include <windows.h>
# define CURRENT_VERSION \
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"

void *
sentry__try_file_version(const LPCWSTR filename)
Expand Down Expand Up @@ -102,13 +104,34 @@ sentry__get_windows_version(windows_version_t *win_ver)
return 1;
}

# endif // !defined(_GAMING_XBOX_SCARLETT)

sentry_value_t
sentry__get_os_context(void)
{
const sentry_value_t os = sentry_value_new_object();
if (sentry_value_is_null(os)) {
return os;
}

# if defined(_GAMING_XBOX_SCARLETT)
# pragma warning(push)
# pragma warning(disable : 4996)
sentry_value_set_by_key(os, "name", sentry_value_new_string("Windows"));
OSVERSIONINFO os_ver = { 0 };
char buf[128];
buf[0] = 0;
os_ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&os_ver);
snprintf(buf, sizeof(buf), "%u.%u.%u", os_ver.dwMajorVersion,
os_ver.dwMinorVersion, os_ver.dwBuildNumber);
sentry_value_set_by_key(os, "version", sentry_value_new_string(buf));

sentry_value_freeze(os);
return os;
# pragma warning(pop)
# else

sentry_value_set_by_key(os, "name", sentry_value_new_string("Windows"));

bool at_least_one_key_successful = false;
Expand Down Expand Up @@ -141,6 +164,7 @@ sentry__get_os_context(void)

sentry_value_decref(os);
return sentry_value_new_null();
# endif // defined(_GAMING_XBOX_SCARLETT)
}

void
Expand All @@ -155,7 +179,7 @@ sentry__reserve_thread_stack(void)
}
}

# if defined(SENTRY_BUILD_SHARED)
# if defined(SENTRY_BUILD_SHARED) && !defined(_GAMING_XBOX_SCARLETT)

BOOL APIENTRY
DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
Expand All @@ -174,7 +198,7 @@ DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
return TRUE;
}

# endif // defined(SENTRY_BUILD_SHARED)
# endif // defined(SENTRY_BUILD_SHARED) && !defined(_GAMING_XBOX_SCARLETT)

static void(WINAPI *g_kernel32_GetSystemTimePreciseAsFileTime)(LPFILETIME)
= NULL;
Expand Down
6 changes: 6 additions & 0 deletions src/symbolizer/sentry_symbolizer_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ bool
sentry__symbolize(
void *addr, void (*func)(const sentry_frame_info_t *, void *), void *data)
{
#ifdef _GAMING_XBOX_SCARLETT
(void)data;
(void)func;
(void)addr;
#else
HANDLE proc = sentry__init_dbghelp();

SYMBOL_INFO *sym = (SYMBOL_INFO *)_alloca(sizeof(SYMBOL_INFO) + MAX_SYM);
Expand All @@ -35,6 +40,7 @@ sentry__symbolize(
frame_info.symbol = sym->Name;
frame_info.object_name = mod_name;
func(&frame_info, data);
#endif // _GAMING_XBOX_SCARLETT

return true;
}
Loading

0 comments on commit 65c109d

Please sign in to comment.