diff options
author | Chia-I Wu <olvaffe@gmail.com> | 2023-05-10 11:27:42 -0700 |
---|---|---|
committer | Marge Bot <emma+marge@anholt.net> | 2023-05-11 00:17:40 +0000 |
commit | 0b6283e2e6b5a1c5e8fea865145dda9a4edc7e19 (patch) | |
tree | 4b82ed6f13d3bc58d6f3f75736a369af01cc24d4 | |
parent | e169a402a8c314633a7ce3e102df72af99362847 (diff) |
drm-shim: apply file overrides for open
loader_get_pci_driver calls os_read_file on linux to get the pci id, and
os_read_file uses open instead of fopen.
This allows loader_get_pci_driver to work rather than falling back to
loader_get_kernel_driver_name.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22951>
-rw-r--r-- | src/drm-shim/drm_shim.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/drm-shim/drm_shim.c b/src/drm-shim/drm_shim.c index f59bb6ed10d..5bbbb12132e 100644 --- a/src/drm-shim/drm_shim.c +++ b/src/drm-shim/drm_shim.c @@ -293,11 +293,8 @@ static bool hide_drm_device_path(const char *path) return false; } -/* Override libdrm's reading of various sysfs files for device enumeration. */ -PUBLIC FILE *fopen(const char *path, const char *mode) +static int file_override_open(const char *path) { - init_shim(); - for (int i = 0; i < file_overrides_count; i++) { if (strcmp(file_overrides[i].path, path) == 0) { int fds[2]; @@ -305,10 +302,22 @@ PUBLIC FILE *fopen(const char *path, const char *mode) write(fds[1], file_overrides[i].contents, strlen(file_overrides[i].contents)); close(fds[1]); - return fdopen(fds[0], "r"); + return fds[0]; } } + return -1; +} + +/* Override libdrm's reading of various sysfs files for device enumeration. */ +PUBLIC FILE *fopen(const char *path, const char *mode) +{ + init_shim(); + + int fd = file_override_open(path); + if (fd >= 0) + return fdopen(fd, "r"); + return real_fopen(path, mode); } PUBLIC FILE *fopen64(const char *path, const char *mode) @@ -324,6 +333,10 @@ PUBLIC int open(const char *path, int flags, ...) mode_t mode = va_arg(ap, mode_t); va_end(ap); + int fd = file_override_open(path); + if (fd >= 0) + return fd; + if (hide_drm_device_path(path)) { errno = ENOENT; return -1; @@ -332,7 +345,7 @@ PUBLIC int open(const char *path, int flags, ...) if (strcmp(path, render_node_path) != 0) return real_open(path, flags, mode); - int fd = real_open("/dev/null", O_RDWR, 0); + fd = real_open("/dev/null", O_RDWR, 0); drm_shim_fd_register(fd, NULL); |