mirror of https://gitlab.freedesktop.org/mesa/mesa
replace all F_DUPFD_CLOEXEC with os_dupfd_cloexec()
All squashed into a single commit because it shouldn't have any behaviour change, except that it might work now on platforms where it was broken because F_DUPFD_CLOEXEC is not supported but FD_CLOEXEC is. Signed-off-by: Eric Engestrom <eric@engestrom.ch> Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com> Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5369>
This commit is contained in:
parent
0e5ea7a363
commit
4a8085d67c
|
@ -39,6 +39,8 @@
|
|||
#include <sys/types.h>
|
||||
#include <drm-uapi/drm_fourcc.h>
|
||||
|
||||
#include "util/os_file.h"
|
||||
|
||||
#include "loader.h"
|
||||
#include "egl_dri2.h"
|
||||
#include "egl_dri2_fallbacks.h"
|
||||
|
@ -1505,7 +1507,7 @@ droid_open_device(_EGLDisplay *disp, bool swrast)
|
|||
return EGL_FALSE;
|
||||
}
|
||||
|
||||
dri2_dpy->fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
|
||||
dri2_dpy->fd = os_dupfd_cloexec(fd);
|
||||
if (dri2_dpy->fd < 0)
|
||||
return EGL_FALSE;
|
||||
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util/os_file.h"
|
||||
|
||||
#include "egl_dri2.h"
|
||||
#include "egl_dri2_fallbacks.h"
|
||||
#include "loader.h"
|
||||
|
@ -715,7 +717,7 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
|
|||
}
|
||||
dri2_dpy->own_device = true;
|
||||
} else {
|
||||
dri2_dpy->fd = fcntl(gbm_device_get_fd(gbm), F_DUPFD_CLOEXEC, 3);
|
||||
dri2_dpy->fd = os_dupfd_cloexec(gbm_device_get_fd(gbm));
|
||||
if (dri2_dpy->fd < 0) {
|
||||
err = "DRI2: failed to fcntl() existing gbm device";
|
||||
goto cleanup;
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include <fcntl.h>
|
||||
#include "c11/threads.h"
|
||||
#include "util/macros.h"
|
||||
#include "util/os_file.h"
|
||||
#include "util/u_atomic.h"
|
||||
|
||||
#include "eglcontext.h"
|
||||
|
@ -618,7 +619,7 @@ _eglGetDeviceDisplay(void *native_display,
|
|||
* The new fd is guaranteed to be 3 or greater.
|
||||
*/
|
||||
if (fd != -1 && display->Options.fd == 0) {
|
||||
display->Options.fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
|
||||
display->Options.fd = os_dupfd_cloexec(fd);
|
||||
if (display->Options.fd == -1) {
|
||||
/* Do not (really) need to teardown the display */
|
||||
_eglError(EGL_BAD_ALLOC, "eglGetPlatformDisplay");
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <libsync.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util/os_file.h"
|
||||
#include "util/os_time.h"
|
||||
|
||||
/**
|
||||
|
@ -126,7 +127,7 @@ tu_fence_copy(struct tu_fence *fence, const struct tu_fence *src)
|
|||
/* dup src->fd */
|
||||
int fd = -1;
|
||||
if (src->fd >= 0) {
|
||||
fd = fcntl(src->fd, F_DUPFD_CLOEXEC, 0);
|
||||
fd = os_dupfd_cloexec(src->fd);
|
||||
if (fd < 0) {
|
||||
tu_loge("failed to dup fd %d for fence", src->fd);
|
||||
sync_wait(src->fd, -1);
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "frontend/drm_driver.h"
|
||||
#include "pipe_loader_priv.h"
|
||||
|
||||
#include "util/os_file.h"
|
||||
#include "util/u_memory.h"
|
||||
#include "util/u_dl.h"
|
||||
#include "util/u_debug.h"
|
||||
|
@ -239,7 +240,7 @@ pipe_loader_drm_probe_fd(struct pipe_loader_device **dev, int fd)
|
|||
bool ret;
|
||||
int new_fd;
|
||||
|
||||
if (fd < 0 || (new_fd = fcntl(fd, F_DUPFD_CLOEXEC, 3)) < 0)
|
||||
if (fd < 0 || (new_fd = os_dupfd_cloexec(fd)) < 0)
|
||||
return false;
|
||||
|
||||
ret = pipe_loader_drm_probe_fd_nodup(dev, new_fd);
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include "pipe_loader_priv.h"
|
||||
|
||||
#include "util/os_file.h"
|
||||
#include "util/u_memory.h"
|
||||
#include "util/u_dl.h"
|
||||
#include "sw/dri/dri_sw_winsys.h"
|
||||
|
@ -175,7 +176,7 @@ pipe_loader_sw_probe_kms(struct pipe_loader_device **devs, int fd)
|
|||
if (!pipe_loader_sw_probe_init_common(sdev))
|
||||
goto fail;
|
||||
|
||||
if (fd < 0 || (sdev->fd = fcntl(fd, F_DUPFD_CLOEXEC, 3)) < 0)
|
||||
if (fd < 0 || (sdev->fd = os_dupfd_cloexec(fd)) < 0)
|
||||
goto fail;
|
||||
|
||||
for (i = 0; sdev->dd->winsys[i].name; i++) {
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <fcntl.h>
|
||||
#include <libsync.h>
|
||||
|
||||
#include "util/os_file.h"
|
||||
#include <util/u_memory.h>
|
||||
#include <util/u_inlines.h>
|
||||
|
||||
|
@ -46,7 +47,7 @@ lima_create_fence_fd(struct pipe_context *pctx,
|
|||
int fd, enum pipe_fd_type type)
|
||||
{
|
||||
assert(type == PIPE_FD_TYPE_NATIVE_SYNC);
|
||||
*fence = lima_fence_create(fcntl(fd, F_DUPFD_CLOEXEC, 3));
|
||||
*fence = lima_fence_create(os_dupfd_cloexec(fd));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -83,7 +84,7 @@ static int
|
|||
lima_fence_get_fd(struct pipe_screen *pscreen,
|
||||
struct pipe_fence_handle *fence)
|
||||
{
|
||||
return fcntl(fence->fd, F_DUPFD_CLOEXEC, 3);
|
||||
return os_dupfd_cloexec(fence->fd);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include <libsync.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "util/os_file.h"
|
||||
#include "util/u_inlines.h"
|
||||
|
||||
#include "vc4_screen.h"
|
||||
|
@ -111,7 +112,7 @@ vc4_fence_create_fd(struct pipe_context *pctx, struct pipe_fence_handle **pf,
|
|||
|
||||
assert(type == PIPE_FD_TYPE_NATIVE_SYNC);
|
||||
*fence = vc4_fence_create(vc4->screen, vc4->last_emit_seqno,
|
||||
fcntl(fd, F_DUPFD_CLOEXEC, 3));
|
||||
os_dupfd_cloexec(fd));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -130,7 +131,7 @@ vc4_fence_get_fd(struct pipe_screen *screen, struct pipe_fence_handle *pfence)
|
|||
{
|
||||
struct vc4_fence *fence = vc4_fence(pfence);
|
||||
|
||||
return fcntl(fence->fd, F_DUPFD_CLOEXEC, 3);
|
||||
return os_dupfd_cloexec(fence->fd);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -365,7 +365,7 @@ amdgpu_winsys_create(int fd, const struct pipe_screen_config *config,
|
|||
return NULL;
|
||||
|
||||
pipe_reference_init(&ws->reference, 1);
|
||||
ws->fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
|
||||
ws->fd = os_dupfd_cloexec(fd);
|
||||
|
||||
/* Look up the winsys from the dev table. */
|
||||
simple_mtx_lock(&dev_tab_mutex);
|
||||
|
|
|
@ -24,11 +24,13 @@
|
|||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "util/os_file.h"
|
||||
|
||||
#include "iris_drm_public.h"
|
||||
extern struct pipe_screen *iris_screen_create(int fd, const struct pipe_screen_config *config);
|
||||
|
||||
struct pipe_screen *
|
||||
iris_drm_screen_create(int fd, const struct pipe_screen_config *config)
|
||||
{
|
||||
return iris_screen_create(fcntl(fd, F_DUPFD_CLOEXEC, 3), config);
|
||||
return iris_screen_create(os_dupfd_cloexec(fd), config);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <sys/stat.h>
|
||||
|
||||
#include "c11/threads.h"
|
||||
#include "util/os_file.h"
|
||||
#include "util/u_hash_table.h"
|
||||
#include "util/u_pointer.h"
|
||||
#include "renderonly/renderonly.h"
|
||||
|
@ -73,7 +74,7 @@ lima_drm_screen_create(int fd)
|
|||
if (pscreen) {
|
||||
lima_screen(pscreen)->refcnt++;
|
||||
} else {
|
||||
int dup_fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
|
||||
int dup_fd = os_dupfd_cloexec(fd);
|
||||
|
||||
pscreen = lima_screen_create(dup_fd, NULL);
|
||||
if (pscreen) {
|
||||
|
@ -96,5 +97,5 @@ unlock:
|
|||
struct pipe_screen *
|
||||
lima_drm_screen_create_renderonly(struct renderonly *ro)
|
||||
{
|
||||
return lima_screen_create(fcntl(ro->gpu_fd, F_DUPFD_CLOEXEC, 3), ro);
|
||||
return lima_screen_create(os_dupfd_cloexec(ro->gpu_fd), ro);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "pipe/p_context.h"
|
||||
#include "pipe/p_state.h"
|
||||
#include "util/format/u_format.h"
|
||||
#include "util/os_file.h"
|
||||
#include "util/u_memory.h"
|
||||
#include "util/u_inlines.h"
|
||||
#include "util/u_hash_table.h"
|
||||
|
@ -71,7 +72,7 @@ nouveau_drm_screen_create(int fd)
|
|||
* nouveau_device_wrap does not close the fd in case of a device
|
||||
* creation error.
|
||||
*/
|
||||
dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
|
||||
dupfd = os_dupfd_cloexec(fd);
|
||||
|
||||
ret = nouveau_drm_new(dupfd, &drm);
|
||||
if (ret)
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "util/os_file.h"
|
||||
|
||||
#include "renderonly/renderonly.h"
|
||||
#include "panfrost_drm_public.h"
|
||||
#include "panfrost/pan_public.h"
|
||||
|
@ -32,11 +34,11 @@
|
|||
struct pipe_screen *
|
||||
panfrost_drm_screen_create(int fd)
|
||||
{
|
||||
return panfrost_create_screen(fcntl(fd, F_DUPFD_CLOEXEC, 3), NULL);
|
||||
return panfrost_create_screen(os_dupfd_cloexec(fd), NULL);
|
||||
}
|
||||
|
||||
struct pipe_screen *
|
||||
panfrost_drm_screen_create_renderonly(struct renderonly *ro)
|
||||
{
|
||||
return panfrost_create_screen(fcntl(ro->gpu_fd, F_DUPFD_CLOEXEC, 3), ro);
|
||||
return panfrost_create_screen(os_dupfd_cloexec(ro->gpu_fd), ro);
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "radeon_drm_cs.h"
|
||||
#include "radeon_drm_public.h"
|
||||
|
||||
#include "util/os_file.h"
|
||||
#include "util/u_cpu_detect.h"
|
||||
#include "util/u_memory.h"
|
||||
#include "util/u_hash_table.h"
|
||||
|
@ -840,7 +841,7 @@ radeon_drm_winsys_create(int fd, const struct pipe_screen_config *config,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
ws->fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
|
||||
ws->fd = os_dupfd_cloexec(fd);
|
||||
|
||||
if (!do_winsys_init(ws))
|
||||
goto fail1;
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "vmw_fence.h"
|
||||
#include "vmw_context.h"
|
||||
|
||||
#include "util/os_file.h"
|
||||
#include "util/u_memory.h"
|
||||
#include "pipe/p_compiler.h"
|
||||
#include "util/u_hash_table.h"
|
||||
|
@ -90,7 +91,7 @@ vmw_winsys_create( int fd )
|
|||
|
||||
vws->device = stat_buf.st_rdev;
|
||||
vws->open_count = 1;
|
||||
vws->ioctl.drm_fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
|
||||
vws->ioctl.drm_fd = os_dupfd_cloexec(fd);
|
||||
vws->force_coherent = FALSE;
|
||||
if (!vmw_ioctl_init(vws))
|
||||
goto out_no_ioctl;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "util/os_file.h"
|
||||
#include "util/u_debug.h"
|
||||
|
||||
#include "tegra/tegra_screen.h"
|
||||
|
@ -37,7 +38,7 @@ struct pipe_screen *tegra_drm_screen_create(int fd)
|
|||
* NOTE: There are reportedly issues with reusing the file descriptor
|
||||
* as-is related to Xinerama. Duplicate it to side-step any issues.
|
||||
*/
|
||||
fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
|
||||
fd = os_dupfd_cloexec(fd);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "util/os_file.h"
|
||||
|
||||
#include "v3d_drm_public.h"
|
||||
|
||||
#include "v3d/v3d_screen.h"
|
||||
|
@ -31,7 +33,7 @@
|
|||
struct pipe_screen *
|
||||
v3d_drm_screen_create(int fd, const struct pipe_screen_config *config)
|
||||
{
|
||||
return v3d_screen_create(fcntl(fd, F_DUPFD_CLOEXEC, 3), config, NULL);
|
||||
return v3d_screen_create(os_dupfd_cloexec(fd), config, NULL);
|
||||
}
|
||||
|
||||
struct pipe_screen *
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include "util/os_file.h"
|
||||
|
||||
#include "renderonly/renderonly.h"
|
||||
#include "kmsro/drm/kmsro_drm_public.h"
|
||||
#include "vc4_drm_public.h"
|
||||
|
@ -46,7 +48,7 @@ vc4_drm_screen_create(int fd, const struct pipe_screen_config *config)
|
|||
#endif
|
||||
|
||||
if (v3d_present)
|
||||
return vc4_screen_create(fcntl(fd, F_DUPFD_CLOEXEC, 3), NULL);
|
||||
return vc4_screen_create(os_dupfd_cloexec(fd), NULL);
|
||||
|
||||
#ifdef GALLIUM_KMSRO
|
||||
return kmsro_drm_screen_create(fd, config);
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <sys/stat.h>
|
||||
|
||||
#include "os/os_mman.h"
|
||||
#include "util/os_file.h"
|
||||
#include "util/os_time.h"
|
||||
#include "util/u_memory.h"
|
||||
#include "util/format/u_format.h"
|
||||
|
@ -1046,7 +1047,7 @@ virgl_drm_screen_create(int fd, const struct pipe_screen_config *config)
|
|||
virgl_screen(pscreen)->refcnt++;
|
||||
} else {
|
||||
struct virgl_winsys *vws;
|
||||
int dup_fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
|
||||
int dup_fd = os_dupfd_cloexec(fd);
|
||||
|
||||
vws = virgl_drm_winsys_create(dup_fd);
|
||||
if (!vws) {
|
||||
|
|
Loading…
Reference in New Issue