diff options
author | Kristian Høgsberg Kristensen <kristian.h.kristensen@intel.com> | 2016-02-13 12:34:22 -0800 |
---|---|---|
committer | Kristian Høgsberg Kristensen <kristian.h.kristensen@intel.com> | 2016-02-13 12:42:02 -0800 |
commit | 68a064ec64dab22d353dcde0b3208fa067abed51 (patch) | |
tree | 80b123d222d7f7549337f99cedf0551f9f158ef1 /tools | |
parent | a3506b52199d2ac8dbc358fbb562f700f1d9ded4 (diff) |
aubdump: Don't use .so constructors for initializing
This doesn't seem to work when mixed with constructors in other shared
objects or other creative uses of the linker. Let's stick with a simpler
mechanism, where we look up the libc functions when our hooks are called
for the first time.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/aubdump.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/tools/aubdump.c b/tools/aubdump.c index 6327b87e..01ecf0c5 100644 --- a/tools/aubdump.c +++ b/tools/aubdump.c @@ -43,8 +43,11 @@ #include "intel_aub.h" #include "intel_chipset.h" -static int (*libc_close)(int fd); -static int (*libc_ioctl)(int fd, unsigned long request, void *argp); +static int close_init_helper(int fd); +static int ioctl_init_helper(int fd, unsigned long request, ...); + +static int (*libc_close)(int fd) = close_init_helper; +static int (*libc_ioctl)(int fd, unsigned long request, ...) = ioctl_init_helper; static int drm_fd = -1; static char *filename; @@ -528,7 +531,7 @@ ioctl(int fd, unsigned long request, ...) } } -static void __attribute__ ((constructor)) +static void init(void) { const char *args = getenv("INTEL_AUBDUMP_ARGS"); @@ -553,6 +556,27 @@ init(void) fail_if(file == NULL, "intel_aubdump: failed to open file '%s'\n", filename); } +static int +close_init_helper(int fd) +{ + init(); + return libc_close(fd); +} + +static int +ioctl_init_helper(int fd, unsigned long request, ...) +{ + va_list args; + void *argp; + + va_start(args, request); + argp = va_arg(args, void *); + va_end(args); + + init(); + return libc_ioctl(fd, request, argp); +} + static void __attribute__ ((destructor)) fini(void) { |