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,