summaryrefslogtreecommitdiff
path: root/hooks.h
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2017-01-23 11:21:51 +0200
committerJari Vetoniemi <mailroxas@gmail.com>2017-01-23 11:21:51 +0200
commit1d71fee4c0ba9be181fc48a447b7287754dc9bd1 (patch)
tree0436c63d2a60ad0cacec79a627f5985d81868519 /hooks.h
parent0b35be65b43f88f0a17a6f8830a52415c3ff1aa1 (diff)
Move out non function hook code out of hooks.h
Also reorder the code a bit
Diffstat (limited to 'hooks.h')
-rw-r--r--hooks.h42
1 files changed, 16 insertions, 26 deletions
diff --git a/hooks.h b/hooks.h
index a96fcae..b844fcd 100644
--- a/hooks.h
+++ b/hooks.h
@@ -16,15 +16,6 @@ static void hook_function(void**, const char*, const bool);
#define HOOK(x) hook_function((void**)&_##x, #x, false)
-static uint64_t
-get_time_ns(void)
-{
- struct timespec ts;
- HOOK(clock_gettime);
- _clock_gettime(CLOCK_MONOTONIC, &ts);
- return (uint64_t)ts.tv_sec * (uint64_t)1e9 + (uint64_t)ts.tv_nsec;
-}
-
EGLBoolean
eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
{
@@ -100,10 +91,7 @@ clock_gettime(clockid_t clk_id, struct timespec *tp)
HOOK(clock_gettime);
if ((clk_id == CLOCK_MONOTONIC || clk_id == CLOCK_MONOTONIC_RAW)) {
- static __thread uint64_t base;
- const uint64_t current = get_time_ns();
- if (!base) base = current;
- const uint64_t fake = base + (current - base) * SPEED_HACK;
+ const uint64_t fake = get_fake_time_ns();
tp->tv_sec = fake / (uint64_t)1e9;
tp->tv_nsec = (fake % (uint64_t)1e9);
return 0;
@@ -112,19 +100,6 @@ clock_gettime(clockid_t clk_id, struct timespec *tp)
return _clock_gettime(clk_id, tp);
}
-#define HOOK_DLSYM(x) hook_function((void**)&_##x, #x, true)
-
-void*
-dlsym(void *handle, const char *symbol)
-{
- HOOK_DLSYM(dlsym);
-
- if (!strcmp(symbol, "dlsym"))
- return dlsym;
-
- return store_real_symbol_and_return_fake_symbol(symbol, _dlsym(handle, symbol));
-}
-
static void*
store_real_symbol_and_return_fake_symbol(const char *symbol, void *ret)
{
@@ -150,6 +125,8 @@ store_real_symbol_and_return_fake_symbol(const char *symbol, void *ret)
return ret;
}
+#define HOOK_DLSYM(x) hook_function((void**)&_##x, #x, true)
+
static void
hook_function(void **ptr, const char *name, const bool versioned)
{
@@ -170,3 +147,16 @@ hook_function(void **ptr, const char *name, const bool versioned)
WARNX("HOOK %s", name);
}
+
+void*
+dlsym(void *handle, const char *symbol)
+{
+ HOOK_DLSYM(dlsym);
+
+ if (!strcmp(symbol, "dlsym"))
+ return dlsym;
+
+ return store_real_symbol_and_return_fake_symbol(symbol, _dlsym(handle, symbol));
+}
+
+#undef HOOK_DLSYM