Mesa (master): drm-shim: stub libdrm's use of realpath()

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Apr 3 21:33:15 UTC 2020


Module: Mesa
Branch: master
Commit: 373f1eb9deab9d9435fba15be6de2a28bde79b87
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=373f1eb9deab9d9435fba15be6de2a28bde79b87

Author: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Date:   Fri Apr  3 15:13:43 2020 +0300

drm-shim: stub libdrm's use of realpath()

libdrm started using realpath to get the type of bus associated with a
given device. This stubs the very specific usage that prevents
drm-shim's device from being listed.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4429>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4429>

---

 src/drm-shim/drm_shim.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/drm-shim/drm_shim.c b/src/drm-shim/drm_shim.c
index e6f7bf9e992..325a8a142e5 100644
--- a/src/drm-shim/drm_shim.c
+++ b/src/drm-shim/drm_shim.c
@@ -75,6 +75,7 @@ REAL_FUNCTION_POINTER(opendir);
 REAL_FUNCTION_POINTER(readdir);
 REAL_FUNCTION_POINTER(readdir64);
 REAL_FUNCTION_POINTER(readlink);
+REAL_FUNCTION_POINTER(realpath);
 REAL_FUNCTION_POINTER(__xstat);
 REAL_FUNCTION_POINTER(__xstat64);
 REAL_FUNCTION_POINTER(__fxstat);
@@ -84,6 +85,8 @@ REAL_FUNCTION_POINTER(__fxstat64);
 static char *render_node_path;
 /* renderD* */
 static char *render_node_dirent_name;
+/* /sys/dev/char/major:minor/device */
+static char *device_path;
 /* /sys/dev/char/major:minor/device/subsystem */
 static char *subsystem_path;
 int render_node_minor = -1;
@@ -187,6 +190,7 @@ init_shim(void)
    GET_FUNCTION_POINTER(readdir);
    GET_FUNCTION_POINTER(readdir64);
    GET_FUNCTION_POINTER(readlink);
+   GET_FUNCTION_POINTER(realpath);
    GET_FUNCTION_POINTER(__xstat);
    GET_FUNCTION_POINTER(__xstat64);
    GET_FUNCTION_POINTER(__fxstat);
@@ -199,6 +203,10 @@ init_shim(void)
               render_node_path);
    }
 
+   asprintf(&device_path,
+            "/sys/dev/char/%d:%d/device",
+            DRM_MAJOR, render_node_minor);
+
    asprintf(&subsystem_path,
             "/sys/dev/char/%d:%d/device/subsystem",
             DRM_MAJOR, render_node_minor);
@@ -476,6 +484,20 @@ readlink(const char *path, char *buf, size_t size)
    return strlen(buf) + 1;
 }
 
+/* Handles libdrm's realpath to figure out what kind of device we have. */
+PUBLIC char *
+realpath(const char *path, char *resolved_path)
+{
+   init_shim();
+
+   if (strcmp(path, device_path) != 0)
+      return real_realpath(path, resolved_path);
+
+   strcpy(resolved_path, path);
+
+   return resolved_path;
+}
+
 /* Main entrypoint to DRM drivers: the ioctl syscall.  We send all ioctls on
  * our DRM fd to drm_shim_ioctl().
  */



More information about the mesa-commit mailing list