getsentry/sentry-native

Add WINE meta-data to OS context.

Open

#1,004 opened on Jun 5, 2024

View on GitHub
 (0 comments) (0 reactions) (0 assignees)C (212 forks)auto 404
ErrorsHelp WantedImprovementNative

Repository metrics

Stars
 (557 stars)
PR merge metrics
 (PR metrics pending)

Description

One can also add Wine metadata to the context if the app is ran under that:

{
    // Add WINE version metadata if running under WINE
    HMODULE hntdll;
    typedef const char* (CDECL* wine_get_version_t)();
    typedef const char* (CDECL* wine_get_build_id_t)();
    typedef void (CDECL* wine_get_host_version_t)(const char** sysname, const char** release);
    wine_get_version_t wine_get_version;
    wine_get_build_id_t wine_get_build_id;
    wine_get_host_version_t wine_get_host_version;
    if ((hntdll = GetModuleHandleA("ntdll.dll")) && (wine_get_version = reinterpret_cast<wine_get_version_t>(GetProcAddress(hntdll, "wine_get_version"))))
    {
        sentry_value_t wine_ctx = sentry_value_new_object();

        sentry_value_set_by_key(wine_ctx, "version", sentry_value_new_string(wine_get_version())); // example: 7.11
        if (wine_get_build_id = reinterpret_cast<wine_get_build_id_t>(GetProcAddress(hntdll, "wine_get_build_id")))
            sentry_value_set_by_key(wine_ctx, "build", sentry_value_new_string(wine_get_build_id())); // example: wine-7.11
        if (wine_get_host_version = reinterpret_cast<wine_get_host_version_t>(GetProcAddress(hntdll, "wine_get_host_version")))
        {
            const char* sysname; // example: Linux
            const char* release; // example: 5.16.20-2-MANJARO
            wine_get_host_version(&sysname, &release);
            sentry_value_set_by_key(wine_ctx, "sysname", sentry_value_new_string(sysname));
            sentry_value_set_by_key(wine_ctx, "release", sentry_value_new_string(release));
        }

        sentry_set_context("wine", wine_ctx);
    }
}

Originally posted by @p0358 in https://github.com/getsentry/sentry-native/issues/943#issuecomment-2144103702

Adding this to Sentry must essentially follow the same steps as in this PR: https://github.com/getsentry/sentry-native/pull/963

Contributor guide