diff options
author | Jari Vetoniemi <mailroxas@gmail.com> | 2017-01-23 11:21:51 +0200 |
---|---|---|
committer | Jari Vetoniemi <mailroxas@gmail.com> | 2017-01-23 11:21:51 +0200 |
commit | 1d71fee4c0ba9be181fc48a447b7287754dc9bd1 (patch) | |
tree | 0436c63d2a60ad0cacec79a627f5985d81868519 | |
parent | 0b35be65b43f88f0a17a6f8830a52415c3ff1aa1 (diff) |
Move out non function hook code out of hooks.h
Also reorder the code a bit
-rw-r--r-- | glcapture.c | 20 | ||||
-rw-r--r-- | hooks.h | 42 |
2 files changed, 36 insertions, 26 deletions
diff --git a/glcapture.c b/glcapture.c index 2aefb69..8db96fe 100644 --- a/glcapture.c +++ b/glcapture.c @@ -103,12 +103,23 @@ struct fifo { #define ERRX(x, y, ...) do { errx(x, "glcapture: "y, ##__VA_ARGS__); } while (0) #define WARN_ONCE(x, ...) do { static bool o = false; if (!o) { WARNX(x, ##__VA_ARGS__); o = true; } } while (0) +// "entrypoints" exposed to hooks.h static void swap_buffers(void); static void alsa_writei(snd_pcm_t *pcm, const void *buffer, const snd_pcm_uframes_t size, const char *caller); +static uint64_t get_fake_time_ns(void); #include "hooks.h" #include "glwrangle.h" +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; +} + static void reset_fifo(struct fifo *fifo) { @@ -447,3 +458,12 @@ alsa_writei(snd_pcm_t *pcm, const void *buffer, const snd_pcm_uframes_t size, co if (alsa_get_frame_info(pcm, &info, caller)) write_data(&info, buffer, snd_pcm_frames_to_bytes(pcm, size)); } + +static uint64_t +get_fake_time_ns(void) +{ + static __thread uint64_t base; + const uint64_t current = get_time_ns(); + base = (base ? base : current); + return base + (current - base) * SPEED_HACK; +} @@ -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 |