Skip to content

Commit 73fb1e8

Browse files
feat(native): enable the native backend on Xbox (#1666)
* feat(native): allow building for Xbox * Guard ToolHelp32 use in daemon on Xbox console * initialize XGameRuntime in daemon on Xbox console * Forward-declare XGameRuntime entry points instead of including header * Pre-warm network init * Test without XGameRuntimeInitialize * Test markers * Restore XGameRuntime and network init in daemon * Remove Xbox daemon diagnostic markers * Clean up * Update changelog * Fix PR suggestion * Use SENTRY_PLATFORM_XBOX in minidump dbghelp.lib guard * Use sentry-xbox helpers for XGameRuntime init/uninit * Update CHANGELOG.md Co-authored-by: JoshuaMoelans <60878493+JoshuaMoelans@users.noreply.github.com> * Update src/backends/native/sentry_crash_daemon.c Co-authored-by: JoshuaMoelans <60878493+JoshuaMoelans@users.noreply.github.com> --------- Co-authored-by: JoshuaMoelans <60878493+JoshuaMoelans@users.noreply.github.com>
1 parent 79911f8 commit 73fb1e8

4 files changed

Lines changed: 64 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
**Features**:
66

7+
- Enable experimental `native` backend on Xbox. ([#1666](https://github.com/getsentry/sentry-native/pull/1666))
78
- Linux: support 32-bit ARM. ([#1659](https://github.com/getsentry/sentry-native/issues/1659))
89
- Crashpad: capture handler process log output to `<run>/crashpad-handler.log`, matching the SDK's `debug` verbosity. ([#1658](https://github.com/getsentry/sentry-native/pull/1658))
910

src/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,12 @@ elseif(SENTRY_BACKEND_NATIVE)
202202
${SECURITY_LIBRARY}
203203
)
204204
elseif(WIN32)
205-
# Windows needs dbghelp for MiniDumpWriteDump
206-
target_link_libraries(sentry PRIVATE dbghelp)
205+
if(NOT XBOX)
206+
# Windows needs dbghelp for MiniDumpWriteDump. On Xbox console
207+
# MiniDumpWriteDump is supplied by xgameplatform.lib (linked by
208+
# the Xbox toolchain as a standard library), so skip dbghelp.
209+
target_link_libraries(sentry PRIVATE dbghelp)
210+
endif()
207211
endif()
208212

209213
# Enable C11 for atomics support

src/backends/native/minidump/sentry_minidump_windows.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111
# include "sentry_minidump_writer.h"
1212
# include "sentry_string.h"
1313

14-
# pragma comment(lib, "dbghelp.lib")
14+
/**
15+
* On Xbox, MiniDumpWriteDump is provided by xgameplatform.lib
16+
* (linked by the Xbox toolchain), not dbghelp.lib.
17+
*/
18+
# if !defined(SENTRY_PLATFORM_XBOX)
19+
# pragma comment(lib, "dbghelp.lib")
20+
# endif
1521

1622
/**
1723
* Windows minidump writer

src/backends/native/sentry_crash_daemon.c

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1710,10 +1710,19 @@ get_thread_name(HANDLE hThread, sentry_thread_context_windows_t *tctx)
17101710
/**
17111711
* Enumerate threads from the crashed process for the native event on Windows
17121712
* Captures thread contexts for stack walking.
1713+
*
1714+
* Not available on Xbox (the ToolHelp32 API is not part of the gaming
1715+
* partition). MiniDumpWriteDump still captures all thread contexts from the
1716+
* target process independently, so skipping this only loses supplementary
1717+
* per-thread metadata from the Sentry event payload.
17131718
*/
17141719
static void
17151720
enumerate_threads_from_process(sentry_crash_context_t *ctx)
17161721
{
1722+
# if defined(SENTRY_PLATFORM_XBOX)
1723+
(void)ctx;
1724+
return;
1725+
# else
17171726
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
17181727
if (hSnapshot == INVALID_HANDLE_VALUE) {
17191728
SENTRY_WARN("CreateToolhelp32Snapshot failed");
@@ -1810,6 +1819,7 @@ enumerate_threads_from_process(sentry_crash_context_t *ctx)
18101819
ctx->platform.num_threads = thread_count;
18111820
SENTRY_DEBUGF("Enumerated %u threads from process %d", thread_count,
18121821
ctx->crashed_pid);
1822+
# endif // SENTRY_PLATFORM_XBOX
18131823
}
18141824
#endif // SENTRY_PLATFORM_WINDOWS
18151825

@@ -3595,6 +3605,23 @@ sentry__crash_daemon_start(pid_t app_pid, uint64_t app_tid, HANDLE event_handle,
35953605
// When built as standalone executable, provide main entry point
35963606
#ifdef SENTRY_CRASH_DAEMON_STANDALONE
35973607

3608+
# if defined(SENTRY_PLATFORM_XBOX)
3609+
// Thin wrappers provided by sentry-xbox; the daemon doesn't link XGameRuntime
3610+
// directly so these indirections keep all Xbox-platform coupling on that side.
3611+
extern bool sentry__xbox_game_runtime_initialize(void);
3612+
extern void sentry__xbox_game_runtime_uninitialize(void);
3613+
3614+
extern bool sentry__xbox_ensure_network_initialized(void);
3615+
3616+
static DWORD WINAPI
3617+
sentry__xbox_network_prewarm_thread_proc(LPVOID param)
3618+
{
3619+
(void)param;
3620+
(void)sentry__xbox_ensure_network_initialized();
3621+
return 0;
3622+
}
3623+
# endif
3624+
35983625
int
35993626
main(int argc, char **argv)
36003627
{
@@ -3637,8 +3664,30 @@ main(int argc, char **argv)
36373664
unsigned long long ready_event_val = strtoull(argv[4], NULL, 10);
36383665
HANDLE event_handle = (HANDLE)(uintptr_t)event_handle_val;
36393666
HANDLE ready_event_handle = (HANDLE)(uintptr_t)ready_event_val;
3640-
return sentry__crash_daemon_main(
3667+
3668+
# if defined(SENTRY_PLATFORM_XBOX)
3669+
// Required before any XNetworking call the transport makes at
3670+
// crash-upload time.
3671+
if (!sentry__xbox_game_runtime_initialize()) {
3672+
return 1;
3673+
}
3674+
3675+
HANDLE network_prewarm_thread = CreateThread(
3676+
NULL, 0, sentry__xbox_network_prewarm_thread_proc, NULL, 0, NULL);
3677+
# endif
3678+
3679+
int rv = sentry__crash_daemon_main(
36413680
app_pid, app_tid, event_handle, ready_event_handle);
3681+
3682+
# if defined(SENTRY_PLATFORM_XBOX)
3683+
if (network_prewarm_thread) {
3684+
WaitForSingleObject(network_prewarm_thread, INFINITE);
3685+
CloseHandle(network_prewarm_thread);
3686+
}
3687+
3688+
sentry__xbox_game_runtime_uninitialize();
3689+
# endif
3690+
return rv;
36423691
# else
36433692
fprintf(stderr, "Platform not supported\n");
36443693
return 1;

0 commit comments

Comments
 (0)