mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-09 08:58:02 +02:00
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>
This commit is contained in:
parent
e169a402a8
commit
0b6283e2e6
1 changed files with 19 additions and 6 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue