Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**Fixes**:

- Reject invalid trace- and span-ids in context update from header ([#1046](https://github.com/getsentry/sentry-native/pull/1046))
- Lookup `GetSystemTimePreciseAsFileTime()` at runtime and fall back to `GetSystemTimeAsFileTime()` to allow running on Windows < 8. ([#1051](https://github.com/getsentry/sentry-native/pull/1051))

## 0.7.10

Expand Down
5 changes: 5 additions & 0 deletions src/sentry_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "sentry_database.h"
#include "sentry_envelope.h"
#include "sentry_options.h"
#include "sentry_os.h"
#include "sentry_path.h"
#include "sentry_random.h"
#include "sentry_scope.h"
Expand Down Expand Up @@ -195,6 +196,10 @@ sentry_init(sentry_options_t *options)
sentry_start_session();
}

#ifdef SENTRY_PLATFORM_WINDOWS
sentry__init_cached_functions();
#endif

sentry__mutex_unlock(&g_options_lock);
return 0;

Expand Down
28 changes: 28 additions & 0 deletions src/sentry_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,34 @@ DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)

# endif // defined(SENTRY_BUILD_SHARED)

static void(WINAPI *g_kernel32_GetSystemTimePreciseAsFileTime)(LPFILETIME)
= NULL;

void
sentry__init_cached_functions(void)
{
// Retrieve GetSystemTimePreciseAsFileTime() for Windows 8+ targets.
// Do this at runtime, because this could still be compiled with an SDK
// where the function exists, but later runs on a Windows without it.
HINSTANCE kernel32 = GetModuleHandleW(L"kernel32.dll");
if (!kernel32) {
return;
}
g_kernel32_GetSystemTimePreciseAsFileTime = (void(WINAPI *)(
LPFILETIME))GetProcAddress(kernel32, "GetSystemTimePreciseAsFileTime");
}

void
sentry__get_system_time(LPFILETIME filetime)
{
if (g_kernel32_GetSystemTimePreciseAsFileTime) {
g_kernel32_GetSystemTimePreciseAsFileTime(filetime);
return;
}

GetSystemTimeAsFileTime(filetime);
}

#elif defined(SENTRY_PLATFORM_MACOS)

# include <sys/sysctl.h>
Expand Down
2 changes: 2 additions & 0 deletions src/sentry_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ typedef struct {
int sentry__get_kernel_version(windows_version_t *win_ver);
int sentry__get_windows_version(windows_version_t *win_ver);
void sentry__reserve_thread_stack(void);
void sentry__init_cached_functions(void);
void sentry__get_system_time(LPFILETIME filetime);

#endif

Expand Down
8 changes: 2 additions & 6 deletions src/sentry_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# include <mach/mach.h>
#endif
#ifdef SENTRY_PLATFORM_WINDOWS
# include "sentry_os.h"
# include <winnt.h>
#else
# include <sys/time.h>
Expand Down Expand Up @@ -106,12 +107,7 @@ sentry__usec_time(void)
// Contains a 64-bit value representing the number of 100-nanosecond
// intervals since January 1, 1601 (UTC).
FILETIME file_time;
# if _WIN32_WINNT >= 0x0602
GetSystemTimePreciseAsFileTime(&file_time);
# else
GetSystemTimeAsFileTime(&file_time);
# endif

sentry__get_system_time(&file_time);
uint64_t timestamp = (uint64_t)file_time.dwLowDateTime
+ ((uint64_t)file_time.dwHighDateTime << 32);
timestamp -= 116444736000000000LL; // convert to unix epoch
Expand Down