-
-
Notifications
You must be signed in to change notification settings - Fork 214
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
Merged
Merged
feat: WER integration #1837
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1c53bf6
feat: add WER integration
jpnurmi f5e185d
adapt to scope observer API changes
jpnurmi d2fefdf
clear
jpnurmi 1301cf3
Merge branch 'master' into jpnurmi/feat/wer-integration
jpnurmi cdf9193
resolve absolute paths
jpnurmi af741ab
WER_MAX_MEM_BLOCK_SIZE
jpnurmi 9d7d6ec
sanity check max lengths and sizes
jpnurmi 005cbea
Merge remote-tracking branch 'origin/master' into jpnurmi/feat/wer-in…
jpnurmi 9a2b042
another WER_MAX_MEM_BLOCK_SIZE
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
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,283 @@ | ||
| #include "sentry_integration_wer.h" | ||
|
|
||
| #include "sentry_alloc.h" | ||
| #include "sentry_attachment.h" | ||
| #include "sentry_core.h" | ||
| #include "sentry_logger.h" | ||
| #include "sentry_path.h" | ||
| #include "sentry_scope.h" | ||
| #include "sentry_string.h" | ||
|
|
||
| #include <string.h> | ||
| #include <wchar.h> | ||
| #include <werapi.h> | ||
|
|
||
| // Windows 8+ SDK | ||
| #ifndef WER_FILE_ANONYMOUS_DATA | ||
| # define WER_FILE_ANONYMOUS_DATA 0x2 | ||
| #endif | ||
| #ifndef WER_MAX_PARAM_LENGTH | ||
| # define WER_MAX_PARAM_LENGTH (MAX_PATH) | ||
| #endif | ||
| #ifndef WER_MAX_MEM_BLOCK_SIZE | ||
| # define WER_MAX_MEM_BLOCK_SIZE (64 * 1024) | ||
| #endif | ||
| #ifndef WER_METADATA_KEY_MAX_LENGTH | ||
| # define WER_METADATA_KEY_MAX_LENGTH 64 | ||
| #endif | ||
| #ifndef WER_METADATA_VALUE_MAX_LENGTH | ||
| # define WER_METADATA_VALUE_MAX_LENGTH 128 | ||
| #endif | ||
|
|
||
| typedef struct sentry_integration_wer_data_s { | ||
| HRESULT(WINAPI *WerRegisterCustomMetadata)(PCWSTR, PCWSTR); | ||
| HRESULT(WINAPI *WerUnregisterCustomMetadata)(PCWSTR); | ||
| sentry_scope_t *scope; | ||
| sentry_scope_observer_t *observer; | ||
| } sentry_integration_wer_data_t; | ||
|
|
||
| static void | ||
| wer_init(sentry_integration_wer_data_t *wer_data) | ||
| { | ||
| if (wer_data->WerRegisterCustomMetadata) { | ||
| return; | ||
| } | ||
| HMODULE kernel32 = GetModuleHandleW(L"kernel32.dll"); | ||
| if (kernel32) { | ||
| wer_data->WerRegisterCustomMetadata = (HRESULT(WINAPI *)(PCWSTR, | ||
| PCWSTR))GetProcAddress(kernel32, "WerRegisterCustomMetadata"); | ||
| wer_data->WerUnregisterCustomMetadata = (HRESULT(WINAPI *)( | ||
| PCWSTR))GetProcAddress(kernel32, "WerUnregisterCustomMetadata"); | ||
| } | ||
| if (!wer_data->WerRegisterCustomMetadata) { | ||
| SENTRY_DEBUG("WerRegisterCustomMetadata not available; " | ||
| "tag sync to WER will be skipped"); | ||
| } | ||
| } | ||
|
|
||
| static void | ||
| sentry_integration_wer_free(void *data) | ||
| { | ||
| sentry_free(data); | ||
| } | ||
|
|
||
| static void | ||
| wer_set_tag(void *data, const char *key, const char *value) | ||
| { | ||
| sentry_integration_wer_data_t *wer_data | ||
| = (sentry_integration_wer_data_t *)data; | ||
| if (!wer_data->WerRegisterCustomMetadata) { | ||
| return; | ||
| } | ||
| if (!key || !value) { | ||
| return; | ||
| } | ||
|
|
||
| wchar_t *key_w = sentry__string_to_wstr(key); | ||
| wchar_t *value_w = sentry__string_to_wstr(value); | ||
| if (!key_w || !value_w || wcslen(key_w) > WER_METADATA_KEY_MAX_LENGTH | ||
| || wcslen(value_w) > WER_METADATA_VALUE_MAX_LENGTH) { | ||
| sentry_free(key_w); | ||
| sentry_free(value_w); | ||
| return; | ||
| } | ||
|
|
||
| HRESULT hr = wer_data->WerRegisterCustomMetadata(key_w, value_w); | ||
| if (FAILED(hr)) { | ||
| SENTRY_WARNF( | ||
| "WerRegisterCustomMetadata failed: hr=0x%08lx", (unsigned long)hr); | ||
| } | ||
|
|
||
| sentry_free(key_w); | ||
| sentry_free(value_w); | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| static void | ||
| wer_remove_tag(void *data, const char *key) | ||
| { | ||
| sentry_integration_wer_data_t *wer_data | ||
| = (sentry_integration_wer_data_t *)data; | ||
| if (!wer_data->WerUnregisterCustomMetadata) { | ||
| return; | ||
| } | ||
| if (!key) { | ||
| return; | ||
| } | ||
|
|
||
| wchar_t *key_w = sentry__string_to_wstr(key); | ||
| if (!key_w || wcslen(key_w) > WER_METADATA_KEY_MAX_LENGTH) { | ||
| sentry_free(key_w); | ||
| return; | ||
| } | ||
|
|
||
| HRESULT hr = wer_data->WerUnregisterCustomMetadata(key_w); | ||
| if (FAILED(hr)) { | ||
| SENTRY_WARNF("WerUnregisterCustomMetadata failed: hr=0x%08lx", | ||
| (unsigned long)hr); | ||
| } | ||
|
|
||
| sentry_free(key_w); | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| static void | ||
| wer_add_attachment(void *UNUSED(data), sentry_attachment_t *attachment) | ||
| { | ||
| if (!attachment) { | ||
| return; | ||
| } | ||
|
|
||
| if (attachment->path) { | ||
| sentry_path_t *path = sentry__path_absolute(attachment->path); | ||
| if (!path || wcslen(path->path_w) > WER_MAX_PARAM_LENGTH) { | ||
| sentry__path_free(path); | ||
| return; | ||
| } | ||
| HRESULT hr = WerRegisterFile( | ||
| path->path_w, WerRegFileTypeOther, WER_FILE_ANONYMOUS_DATA); | ||
| if (FAILED(hr)) { | ||
| SENTRY_WARNF( | ||
| "WerRegisterFile failed: hr=0x%08lx", (unsigned long)hr); | ||
| } | ||
| sentry__path_free(path); | ||
| return; | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| if (attachment->buf && attachment->buf_len > 0 | ||
| && attachment->buf_len <= WER_MAX_MEM_BLOCK_SIZE) { | ||
| HRESULT hr = WerRegisterMemoryBlock( | ||
| (PVOID)attachment->buf, (DWORD)attachment->buf_len); | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| if (FAILED(hr)) { | ||
| SENTRY_WARNF( | ||
| "WerRegisterMemoryBlock failed: hr=0x%08lx", (unsigned long)hr); | ||
| } | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| static void | ||
| wer_remove_attachment(void *UNUSED(data), sentry_attachment_t *attachment) | ||
| { | ||
| if (!attachment) { | ||
| return; | ||
| } | ||
|
|
||
| if (attachment->path) { | ||
| sentry_path_t *path = sentry__path_absolute(attachment->path); | ||
| if (!path || wcslen(path->path_w) > WER_MAX_PARAM_LENGTH) { | ||
| sentry__path_free(path); | ||
| return; | ||
| } | ||
| HRESULT hr = WerUnregisterFile(path->path_w); | ||
| if (FAILED(hr)) { | ||
| SENTRY_WARNF( | ||
| "WerUnregisterFile failed: hr=0x%08lx", (unsigned long)hr); | ||
| } | ||
| sentry__path_free(path); | ||
| return; | ||
|
jpnurmi marked this conversation as resolved.
jpnurmi marked this conversation as resolved.
|
||
| } | ||
|
|
||
| if (attachment->buf && attachment->buf_len > 0 | ||
| && attachment->buf_len <= WER_MAX_MEM_BLOCK_SIZE) { | ||
| HRESULT hr = WerUnregisterMemoryBlock((PVOID)attachment->buf); | ||
| if (FAILED(hr)) { | ||
| SENTRY_WARNF("WerUnregisterMemoryBlock failed: hr=0x%08lx", | ||
| (unsigned long)hr); | ||
| } | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| static void | ||
| wer_cleanup_tag(const char *key, sentry_value_t UNUSED(value), void *data) | ||
| { | ||
| wer_remove_tag(data, key); | ||
| } | ||
|
sentry[bot] marked this conversation as resolved.
|
||
|
|
||
| static void | ||
| wer_clear(void *data) | ||
| { | ||
| sentry_integration_wer_data_t *wer_data | ||
| = (sentry_integration_wer_data_t *)data; | ||
| sentry_scope_t *scope = wer_data->scope; | ||
| if (!scope) { | ||
| return; | ||
| } | ||
|
|
||
| sentry__value_foreach_key_value(scope->tags, wer_cleanup_tag, wer_data); | ||
|
|
||
| for (sentry_attachment_t *attachment = scope->attachments; attachment; | ||
| attachment = attachment->next) { | ||
| wer_remove_attachment(wer_data, attachment); | ||
| } | ||
| } | ||
|
jpnurmi marked this conversation as resolved.
|
||
|
|
||
| static void | ||
| register_wer( | ||
| void *data, sentry_scope_t *scope, const sentry_options_t *UNUSED(options)) | ||
| { | ||
| sentry_integration_wer_data_t *wer_data | ||
| = (sentry_integration_wer_data_t *)data; | ||
| wer_init(wer_data); | ||
|
|
||
| sentry_scope_observer_t *observer = sentry__scope_observer_new(); | ||
| if (!observer) { | ||
| return; | ||
| } | ||
| observer->clear = wer_clear; | ||
| 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[bot] marked this conversation as resolved.
|
||
| observer->data = wer_data; | ||
|
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| if (sentry__scope_add_observer(scope, observer)) { | ||
| wer_data->scope = scope; | ||
| wer_data->observer = observer; | ||
| for (sentry_attachment_t *attachment = scope->attachments; attachment; | ||
| attachment = attachment->next) { | ||
| wer_add_attachment(wer_data, attachment); | ||
| } | ||
| } | ||
|
jpnurmi marked this conversation as resolved.
|
||
| } | ||
|
cursor[bot] marked this conversation as resolved.
jpnurmi marked this conversation as resolved.
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| static void | ||
| unregister_wer( | ||
| void *data, sentry_scope_t *scope, const sentry_options_t *UNUSED(options)) | ||
| { | ||
| sentry_integration_wer_data_t *wer_data | ||
| = (sentry_integration_wer_data_t *)data; | ||
| if (!wer_data->observer) { | ||
| return; | ||
| } | ||
|
|
||
| sentry__value_foreach_key_value(scope->tags, wer_cleanup_tag, wer_data); | ||
|
|
||
| for (sentry_attachment_t *attachment = scope->attachments; attachment; | ||
| attachment = attachment->next) { | ||
| wer_remove_attachment(wer_data, attachment); | ||
| } | ||
|
|
||
| sentry__scope_remove_observer(scope, wer_data->observer); | ||
| wer_data->scope = NULL; | ||
| wer_data->observer = NULL; | ||
| } | ||
|
|
||
| sentry_integration_t * | ||
| sentry_integration_wer_new(void) | ||
| { | ||
| sentry_integration_t *integration = SENTRY_MAKE(sentry_integration_t); | ||
| if (!integration) { | ||
| return NULL; | ||
| } | ||
|
|
||
| integration->data = SENTRY_MAKE(sentry_integration_wer_data_t); | ||
| if (!integration->data) { | ||
| sentry_free(integration); | ||
| return NULL; | ||
| } | ||
|
|
||
| integration->register_func = register_wer; | ||
| integration->unregister_func = unregister_wer; | ||
| integration->free_func = sentry_integration_wer_free; | ||
|
|
||
| return integration; | ||
| } | ||
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,11 @@ | ||
| #ifndef SENTRY_INTEGRATION_WER_H_INCLUDED | ||
| #define SENTRY_INTEGRATION_WER_H_INCLUDED | ||
|
|
||
| #include "sentry_integration.h" | ||
|
|
||
| /** | ||
| * Creates the WER integration. | ||
| */ | ||
| sentry_integration_t *sentry_integration_wer_new(void); | ||
|
|
||
| #endif |
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
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.
Uh oh!
There was an error while loading. Please reload this page.