From 1d71fee4c0ba9be181fc48a447b7287754dc9bd1 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 23 Jan 2017 11:21:51 +0200 Subject: Move out non function hook code out of hooks.h Also reorder the code a bit --- hooks.h | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) (limited to 'hooks.h') 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 -- cgit v1.2.3