-
-
Notifications
You must be signed in to change notification settings - Fork 211
WIP: feat: WER integration #1837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jpnurmi
wants to merge
13
commits into
master
Choose a base branch
from
jpnurmi/feat/wer-integration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3ece229
WIP: feat: scope observer
jpnurmi 5850b87
feat: add sentry_options_add_integration API
jpnurmi 50ca972
feat: add WER integration via scope observer
jpnurmi 3fafc29
refactor: use Qt-style compile flag for WER integration
jpnurmi 5f897b3
Allow SENTRY_INTEGRATION_WER to be enabled on non-Windows platforms
jpnurmi d05e7cc
fix: only define SENTRY_INTEGRATION_WER on Windows
jpnurmi 39bb76d
Skip compiling WER integration sources on non-Windows
jpnurmi 6b115e2
Simplify SENTRY_INTEGRATION_WER guard to single condition
jpnurmi 806214e
Remove redundant SENTRY_PLATFORM_WINDOWS guard from wer integration
jpnurmi ddaa298
Make kernel32 module handle a local variable
jpnurmi 610a159
Add clarifying comment about Windows 10 version 1703+ requirement
jpnurmi 727e266
Explain WER_FILE_ANONYMOUS_DATA fallback
jpnurmi de2ad2d
tweak
jpnurmi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| #include "sentry_integration_wer.h" | ||
|
|
||
| #include "sentry_alloc.h" | ||
| #include "sentry_attachment.h" | ||
| #include "sentry_logger.h" | ||
| #include "sentry_string.h" | ||
|
|
||
| #include <werapi.h> | ||
|
|
||
| // Windows 8+ SDK | ||
| #ifndef WER_FILE_ANONYMOUS_DATA | ||
| # define WER_FILE_ANONYMOUS_DATA 0x2 | ||
| #endif | ||
|
|
||
| // Windows 10 1703+ | ||
| static HRESULT(WINAPI *g_WerRegisterCustomMetadata)(PCWSTR, PCWSTR) = NULL; | ||
| static HRESULT(WINAPI *g_WerUnregisterCustomMetadata)(PCWSTR) = NULL; | ||
|
|
||
| static void | ||
| wer_init(void) | ||
| { | ||
| if (g_WerRegisterCustomMetadata) { | ||
| return; | ||
| } | ||
| HMODULE kernel32 = GetModuleHandleW(L"kernel32.dll"); | ||
| if (kernel32) { | ||
| g_WerRegisterCustomMetadata = (HRESULT(WINAPI *)(PCWSTR, | ||
| PCWSTR))GetProcAddress(kernel32, "WerRegisterCustomMetadata"); | ||
| g_WerUnregisterCustomMetadata = (HRESULT(WINAPI *)( | ||
| PCWSTR))GetProcAddress(kernel32, "WerUnregisterCustomMetadata"); | ||
| } | ||
| if (!g_WerRegisterCustomMetadata) { | ||
| SENTRY_DEBUG("WerRegisterCustomMetadata not available; " | ||
| "tag sync to WER will be skipped"); | ||
| } | ||
| } | ||
|
|
||
| static HRESULT | ||
| wer_set_tag(void *data, const char *key, size_t key_len, const char *value, | ||
| size_t value_len) | ||
| { | ||
| (void)data; | ||
| if (!g_WerRegisterCustomMetadata) { | ||
| return S_OK; | ||
| } | ||
| if (!key || !value) { | ||
| return S_OK; | ||
| } | ||
|
|
||
| char *key_n = sentry__string_clone_n(key, key_len); | ||
| char *value_n = sentry__string_clone_n(value, value_len); | ||
| wchar_t *key_w = sentry__string_to_wstr(key_n); | ||
| wchar_t *value_w = sentry__string_to_wstr(value_n); | ||
| sentry_free(key_n); | ||
| sentry_free(value_n); | ||
|
|
||
| if (!key_w || !value_w) { | ||
| sentry_free(key_w); | ||
| sentry_free(value_w); | ||
| return E_OUTOFMEMORY; | ||
| } | ||
|
|
||
| HRESULT hr = g_WerRegisterCustomMetadata(key_w, value_w); | ||
| if (FAILED(hr)) { | ||
| SENTRY_WARNF( | ||
| "WerRegisterCustomMetadata failed: hr=0x%08lx", (unsigned long)hr); | ||
| } | ||
|
|
||
| sentry_free(value_w); | ||
| sentry_free(key_w); | ||
| return hr; | ||
| } | ||
|
|
||
| static HRESULT | ||
| wer_remove_tag(void *data, const char *key, size_t key_len) | ||
| { | ||
| (void)data; | ||
| if (!g_WerUnregisterCustomMetadata) { | ||
| return S_OK; | ||
| } | ||
| if (!key) { | ||
| return S_OK; | ||
| } | ||
|
|
||
| char *key_n = sentry__string_clone_n(key, key_len); | ||
| wchar_t *key_w = sentry__string_to_wstr(key_n); | ||
| sentry_free(key_n); | ||
|
|
||
| if (!key_w) { | ||
| return E_OUTOFMEMORY; | ||
| } | ||
|
|
||
| HRESULT hr = g_WerUnregisterCustomMetadata(key_w); | ||
| if (FAILED(hr)) { | ||
| SENTRY_WARNF("WerUnregisterCustomMetadata failed: hr=0x%08lx", | ||
| (unsigned long)hr); | ||
| } | ||
|
|
||
| sentry_free(key_w); | ||
| return hr; | ||
| } | ||
|
|
||
| static HRESULT | ||
| wer_add_attachment(void *data, sentry_attachment_t *attachment) | ||
| { | ||
| (void)data; | ||
|
|
||
| if (!attachment) { | ||
| return S_OK; | ||
| } | ||
|
|
||
| if (attachment->path) { | ||
| const wchar_t *path_w = attachment->path->path_w; | ||
| if (!path_w) { | ||
| return S_OK; | ||
| } | ||
| HRESULT hr = WerRegisterFile( | ||
| path_w, WerRegFileTypeOther, WER_FILE_ANONYMOUS_DATA); | ||
| if (FAILED(hr)) { | ||
| SENTRY_WARNF( | ||
| "WerRegisterFile failed: hr=0x%08lx", (unsigned long)hr); | ||
| } | ||
| return hr; | ||
| } | ||
|
|
||
| if (attachment->buf && attachment->buf_len > 0) { | ||
| if (attachment->buf_len > MAXDWORD) { | ||
| SENTRY_WARNF("WerRegisterMemoryBlock: buffer too large (%zu bytes)", | ||
| attachment->buf_len); | ||
| return E_INVALIDARG; | ||
| } | ||
| HRESULT hr = WerRegisterMemoryBlock( | ||
| (PVOID)attachment->buf, (DWORD)attachment->buf_len); | ||
| if (FAILED(hr)) { | ||
| SENTRY_WARNF( | ||
| "WerRegisterMemoryBlock failed: hr=0x%08lx", (unsigned long)hr); | ||
| } | ||
| return hr; | ||
| } | ||
|
|
||
| return S_OK; | ||
| } | ||
|
|
||
| static HRESULT | ||
| wer_remove_attachment(void *data, sentry_attachment_t *attachment) | ||
| { | ||
| (void)data; | ||
|
|
||
| if (!attachment) { | ||
| return S_OK; | ||
| } | ||
|
|
||
| if (attachment->path) { | ||
| const wchar_t *path_w = attachment->path->path_w; | ||
| if (!path_w) { | ||
| return S_OK; | ||
| } | ||
| HRESULT hr = WerUnregisterFile(path_w); | ||
| if (FAILED(hr)) { | ||
| SENTRY_WARNF( | ||
| "WerUnregisterFile failed: hr=0x%08lx", (unsigned long)hr); | ||
| } | ||
| return hr; | ||
| } | ||
|
|
||
| if (attachment->buf) { | ||
| HRESULT hr = WerUnregisterMemoryBlock((PVOID)attachment->buf); | ||
| if (FAILED(hr)) { | ||
| SENTRY_WARNF("WerUnregisterMemoryBlock failed: hr=0x%08lx", | ||
| (unsigned long)hr); | ||
| } | ||
| return hr; | ||
| } | ||
|
|
||
| return S_OK; | ||
| } | ||
|
|
||
| void | ||
| sentry_integration_wer_setup(sentry_scope_t *scope) | ||
| { | ||
| wer_init(); | ||
|
|
||
| sentry_scope_observer_t *observer = sentry__scope_observer_new(); | ||
| if (!observer) { | ||
| return; | ||
| } | ||
| observer->set_tag = wer_set_tag; | ||
| observer->remove_tag = wer_remove_tag; | ||
| observer->add_attachment = wer_add_attachment; | ||
| observer->remove_attachment = wer_remove_attachment; | ||
|
|
||
| sentry__scope_add_observer(scope, observer); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #ifndef SENTRY_INTEGRATION_WER_H_INCLUDED | ||
| #define SENTRY_INTEGRATION_WER_H_INCLUDED | ||
|
|
||
| #include "sentry_scope.h" | ||
|
|
||
| /** | ||
| * Sets up the WER integration, creating and registering a scope observer | ||
| * that syncs tags and attachments to Windows Error Reporting. | ||
| * | ||
| * Must be called while holding the scope lock (i.e., from inside | ||
| * SENTRY_WITH_SCOPE_MUT). | ||
| */ | ||
| void sentry_integration_wer_setup(sentry_scope_t *scope); | ||
|
|
||
| #endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pre-init attachments skip WER
High Severity
During
sentry_init, attachments fromsentry_options_add_attachmentare moved onto the global scope before WER setup registers its observer, and noadd_attachmentnotifications run for that list. Those files never reachWerRegisterFile/WerRegisterMemoryBlock, so WER crash reports miss attachments that Sentry and crash backends still include.Additional Locations (1)
src/sentry_core.c#L226-L237Reviewed by Cursor Bugbot for commit de2ad2d. Configure here.