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@anholt.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12203>
This commit is contained in:
parent
c9eec12be7
commit
fc6f141304
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue