From: Chia-I Wu Date: Wed, 10 May 2023 18:27:42 +0000 (-0700) Subject: drm-shim: apply file overrides for open X-Git-Tag: upstream/23.3.3~8864 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0b6283e2e6b5a1c5e8fea865145dda9a4edc7e19;p=platform%2Fupstream%2Fmesa.git 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: --- diff --git a/src/drm-shim/drm_shim.c b/src/drm-shim/drm_shim.c index f59bb6e..5bbbb12 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);