summaryrefslogtreecommitdiff
path: root/tools/aubdump.c
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@cryptic-dragon.jf.intel.com>2015-08-07 14:51:27 -0700
committerKristian Høgsberg Kristensen <kristian.h.kristensen@intel.com>2015-08-07 14:59:56 -0700
commit5f4fad31829b1c6dfcddb633d65e9e7066818cff (patch)
tree29070beb2437a241caaceeed16959df1fed735c3 /tools/aubdump.c
parentdb0f28aee8b7f95a10139993096d60ba2a89c6a5 (diff)
tools/aubdump: Don't rely on open for discovering the drm fd
DRI3 passes the drm fd over X protocol and as such we can't rely on hooking open to discover the drm fd. Instead we look for drm ioctl codes in the ioctl wrapper. If we don't have a drm fd and see something that looks like a drm ioctl, we stat the fd to see if it's a drm fd. If it is, we save it for later so we don't have to do an extra stat on every ioctl. We can then drop the open wrapper, but we keep the close wrapper so we can invalidate our cached drm_fd if it's closed. Signed-off-by: Kristian Høgsberg <krh@cryptic-dragon.jf.intel.com>
Diffstat (limited to 'tools/aubdump.c')
-rw-r--r--tools/aubdump.c38
1 files changed, 12 insertions, 26 deletions
diff --git a/tools/aubdump.c b/tools/aubdump.c
index 11f3e2fe..6501ee02 100644
--- a/tools/aubdump.c
+++ b/tools/aubdump.c
@@ -42,7 +42,6 @@
#include "intel_aub.h"
#include "intel_chipset.h"
-static int (*libc_open)(const char *pathname, int flags, mode_t mode);
static int (*libc_close)(int fd);
static int (*libc_ioctl)(int fd, unsigned long request, void *argp);
@@ -325,7 +324,7 @@ dump_execbuffer2(int fd, struct drm_i915_gem_execbuffer2 *execbuffer2)
gen = intel_gen(device);
if (verbose)
- printf("[intel_aubdump active: "
+ printf("[intel_aubdump: running, "
"output file %s, chipset id 0x%04x, gen %d]\n",
filename, device, gen);
}
@@ -392,27 +391,6 @@ remove_bo(int handle)
}
int
-open(const char *pathname, int flags, ...)
-{
- va_list args;
- struct stat buf;
- mode_t mode;
- int fd;
-
- va_start(args, flags);
- mode = va_arg(args, int);
- va_end(args);
-
- fd = libc_open(pathname, flags, mode);
-
- if (fd >= 0 && fstat(fd, &buf) == 0 &&
- (buf.st_mode & S_IFMT) == S_IFCHR && major(buf.st_rdev) == DRM_MAJOR)
- drm_fd = fd;
-
- return fd;
-}
-
-int
close(int fd)
{
if (fd == drm_fd)
@@ -427,11 +405,20 @@ ioctl(int fd, unsigned long request, ...)
va_list args;
void *argp;
int ret;
+ struct stat buf;
va_start(args, request);
argp = va_arg(args, void *);
va_end(args);
+ if (_IOC_TYPE(request) == DRM_IOCTL_BASE &&
+ drm_fd != fd && fstat(fd, &buf) == 0 &&
+ (buf.st_mode & S_IFMT) == S_IFCHR && major(buf.st_rdev) == DRM_MAJOR) {
+ drm_fd = fd;
+ if (verbose)
+ printf("[intel_aubdump: intercept drm ioctl on fd %d]\n", fd);
+ }
+
if (fd == drm_fd) {
switch (request) {
case DRM_IOCTL_I915_GETPARAM: {
@@ -528,11 +515,10 @@ init(void)
{
const char *args = getenv("INTEL_AUBDUMP_ARGS");
- libc_open = dlsym(RTLD_NEXT, "open");
libc_close = dlsym(RTLD_NEXT, "close");
libc_ioctl = dlsym(RTLD_NEXT, "ioctl");
- fail_if(libc_open == NULL || libc_close == NULL || libc_ioctl == NULL,
- "intel_aubdump: failed to get libc open or ioctl\n");
+ fail_if(libc_close == NULL || libc_ioctl == NULL,
+ "intel_aubdump: failed to get libc ioctl or close\n");
if (sscanf(args, "verbose=%d;file=%m[^;];device=%i",
&verbose, &filename, &device) != 3)