Mesa (main): drm-shim: Implement a shim function for close

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Apr 12 10:32:44 UTC 2022


Module: Mesa
Branch: main
Commit: fc6f1413042f1dad32c68bd968fa9abcca61659a
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=fc6f1413042f1dad32c68bd968fa9abcca61659a

Author: Icecream95 <ixn at disroot.org>
Date:   Mon Sep  6 19:54:32 2021 +1200

drm-shim: Implement a shim function for close

Remove the fd from the fd_map, so that if the fd is later reused for
another file then mmap won't be intercepted.

Reviewed-by: Emma Anholt <emma at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12203>

---

 src/drm-shim/device.c   |  5 +++++
 src/drm-shim/drm_shim.c | 12 +++++++++++-
 src/drm-shim/drm_shim.h |  1 +
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/drm-shim/device.c b/src/drm-shim/device.c
index fecdb1fcd21..d5ddd66fdf7 100644
--- a/src/drm-shim/device.c
+++ b/src/drm-shim/device.c
@@ -135,6 +135,11 @@ void drm_shim_fd_register(int fd, struct shim_fd *shim_fd)
    _mesa_hash_table_insert(shim_device.fd_map, (void *)(uintptr_t)(fd + 1), shim_fd);
 }
 
+void drm_shim_fd_unregister(int fd)
+{
+   _mesa_hash_table_remove_key(shim_device.fd_map, (void *)(uintptr_t)(fd + 1));
+}
+
 struct shim_fd *
 drm_shim_fd_lookup(int fd)
 {
diff --git a/src/drm-shim/drm_shim.c b/src/drm-shim/drm_shim.c
index 8b587f81fea..c7025edda42 100644
--- a/src/drm-shim/drm_shim.c
+++ b/src/drm-shim/drm_shim.c
@@ -63,7 +63,7 @@ bool drm_shim_debug;
  */
 DIR *fake_dev_dri = (void *)&opendir_set;
 
-/* XXX: implement REAL_FUNCTION_POINTER(close); */
+REAL_FUNCTION_POINTER(close);
 REAL_FUNCTION_POINTER(closedir);
 REAL_FUNCTION_POINTER(dup);
 REAL_FUNCTION_POINTER(fcntl);
@@ -204,6 +204,7 @@ init_shim(void)
                                   _mesa_hash_string,
                                   _mesa_key_string_equal);
 
+   GET_FUNCTION_POINTER(close);
    GET_FUNCTION_POINTER(closedir);
    GET_FUNCTION_POINTER(dup);
    GET_FUNCTION_POINTER(fcntl);
@@ -292,6 +293,15 @@ PUBLIC int open(const char *path, int flags, ...)
 }
 PUBLIC int open64(const char*, int, ...) __attribute__((alias("open")));
 
+PUBLIC int close(int fd)
+{
+   init_shim();
+
+   drm_shim_fd_unregister(fd);
+
+   return real_close(fd);
+}
+
 #if HAS_XSTAT
 /* Fakes stat to return character device stuff for our fake render node. */
 PUBLIC int __xstat(int ver, const char *path, struct stat *st)
diff --git a/src/drm-shim/drm_shim.h b/src/drm-shim/drm_shim.h
index dbb831747da..503a9109d69 100644
--- a/src/drm-shim/drm_shim.h
+++ b/src/drm-shim/drm_shim.h
@@ -80,6 +80,7 @@ void drm_shim_device_init(void);
 void drm_shim_override_file(const char *contents,
                             const char *path_format, ...) PRINTFLIKE(2, 3);
 void drm_shim_fd_register(int fd, struct shim_fd *shim_fd);
+void drm_shim_fd_unregister(int fd);
 struct shim_fd *drm_shim_fd_lookup(int fd);
 int drm_shim_ioctl(int fd, unsigned long request, void *arg);
 void *drm_shim_mmap(struct shim_fd *shim_fd, size_t length, int prot, int flags,



More information about the mesa-commit mailing list