#include "amdgpu_public.h"
#include "util/os_file.h"
+#include "util/os_misc.h"
#include "util/u_cpu_detect.h"
#include "util/u_hash_table.h"
#include "util/hash_table.h"
simple_mtx_lock(&aws->sws_list_lock);
for (sws_iter = aws->sws_list; sws_iter; sws_iter = sws_iter->next) {
- if (os_same_file_description(sws_iter->fd, ws->fd)) {
+ r = os_same_file_description(sws_iter->fd, ws->fd);
+
+ if (r == 0) {
close(ws->fd);
FREE(ws);
ws = sws_iter;
pipe_reference(NULL, &ws->reference);
simple_mtx_unlock(&aws->sws_list_lock);
goto unlock;
+ } else if (r < 0) {
+ static bool logged;
+
+ if (!logged) {
+ os_log_message("amdgpu: os_same_file_description couldn't "
+ "determine if two DRM fds reference the same "
+ "file description.\n"
+ "If they do, bad things may happen!\n");
+ logged = true;
+ }
}
}
simple_mtx_unlock(&aws->sws_list_lock);
return buf;
}
-bool
+int
os_same_file_description(int fd1, int fd2)
{
pid_t pid = getpid();
- return syscall(SYS_kcmp, pid, pid, KCMP_FILE, fd1, fd2) == 0;
+ /* Same file descriptor trivially implies same file description */
+ if (fd1 == fd2)
+ return 0;
+
+ return syscall(SYS_kcmp, pid, pid, KCMP_FILE, fd1, fd2);
}
#else
return NULL;
}
-bool
+int
os_same_file_description(int fd1, int fd2)
{
+ /* Same file descriptor trivially implies same file description */
if (fd1 == fd2)
- return true;
+ return 0;
- debug_warn_once("Can't tell if different file descriptors reference the same"
- " file description, false negatives might cause trouble!\n");
- return false;
+ /* Otherwise we can't tell */
+ return -1;
}
#endif
os_read_file(const char *filename);
/*
- * Returns true if the two file descriptors passed in can be determined to
- * reference the same file description, false otherwise
+ * Try to determine if two file descriptors reference the same file description
+ *
+ * Return values:
+ * - 0: They reference the same file description
+ * - > 0: They do not reference the same file description
+ * - < 0: Unable to determine whether they reference the same file description
*/
-bool
+int
os_same_file_description(int fd1, int fd2);
#ifdef __cplusplus