egl+libsync: Add check for valid fence-fd
authorRob Clark <robdclark@chromium.org>
Sun, 6 Jun 2021 16:27:52 +0000 (09:27 -0700)
committerMarge Bot <eric+marge@anholt.net>
Mon, 7 Jun 2021 20:14:25 +0000 (20:14 +0000)
commit964efdfba9cf1d4f9a99afe6c965a7fd504319b4
treef2dec4cdd26d449af96ae12c069bb8fb08bd5d11
parentbfeff2c687d8c4f5ddd04792ed51dc0c03b22435
egl+libsync: Add check for valid fence-fd

Debugging fd mix-ups (ie. where, possibly via close()ing the original
fd, etc, you end up with something that is a valid fd but not a valid
*fence* fd) can be difficult.  Fortunately we can use the FILE_INFO
ioctl, which will return an error if the fd is not a fence fd.

For android, we instead use the libsync API, which does a similar thing
on modern kernels, but has a fallback path for older android kernels.

Note that the FILE_INFO ioctl has existed upstream since at least prior
to destaging of sync_file.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11202>
src/android_stub/sync_stub.cpp
src/egl/drivers/dri2/egl_dri2.c
src/util/libsync.h