From: Eric Engestrom Date: Thu, 4 Jun 2020 23:09:35 +0000 (+0200) Subject: replace all F_DUPFD_CLOEXEC with os_dupfd_cloexec() X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4a8085d67ca7b41690edf22c410e4dc0a28e3187;p=mesa.git 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 Reviewed-by: Kristian H. Kristensen Reviewed-by: Lionel Landwerlin Part-of: --- diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c index 31acf540657..b72ee047944 100644 --- a/src/egl/drivers/dri2/platform_android.c +++ b/src/egl/drivers/dri2/platform_android.c @@ -39,6 +39,8 @@ #include #include +#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; diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c index d25141a52a2..9e601e7d5b3 100644 --- a/src/egl/drivers/dri2/platform_drm.c +++ b/src/egl/drivers/dri2/platform_drm.c @@ -36,6 +36,8 @@ #include #include +#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; diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index f6e85c79aa9..8cf9cb83a91 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -39,6 +39,7 @@ #include #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"); diff --git a/src/freedreno/vulkan/tu_fence.c b/src/freedreno/vulkan/tu_fence.c index 9e4a92370f8..62094c91092 100644 --- a/src/freedreno/vulkan/tu_fence.c +++ b/src/freedreno/vulkan/tu_fence.c @@ -27,6 +27,7 @@ #include #include +#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); diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c index 5d6865be1b0..c5126f16fd4 100644 --- a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c +++ b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c @@ -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); diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader_sw.c b/src/gallium/auxiliary/pipe-loader/pipe_loader_sw.c index 74329e4cba9..b3932c7464c 100644 --- a/src/gallium/auxiliary/pipe-loader/pipe_loader_sw.c +++ b/src/gallium/auxiliary/pipe-loader/pipe_loader_sw.c @@ -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++) { diff --git a/src/gallium/drivers/lima/lima_fence.c b/src/gallium/drivers/lima/lima_fence.c index c00fcea5772..193e3ee81eb 100644 --- a/src/gallium/drivers/lima/lima_fence.c +++ b/src/gallium/drivers/lima/lima_fence.c @@ -25,6 +25,7 @@ #include #include +#include "util/os_file.h" #include #include @@ -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 diff --git a/src/gallium/drivers/vc4/vc4_fence.c b/src/gallium/drivers/vc4/vc4_fence.c index 7e2be3eeb36..ac49a7be337 100644 --- a/src/gallium/drivers/vc4/vc4_fence.c +++ b/src/gallium/drivers/vc4/vc4_fence.c @@ -37,6 +37,7 @@ #include #include +#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 diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c index b4ae6cf1223..da9a44e8c84 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c @@ -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); diff --git a/src/gallium/winsys/iris/drm/iris_drm_winsys.c b/src/gallium/winsys/iris/drm/iris_drm_winsys.c index b63dd46255b..57954e48273 100644 --- a/src/gallium/winsys/iris/drm/iris_drm_winsys.c +++ b/src/gallium/winsys/iris/drm/iris_drm_winsys.c @@ -24,11 +24,13 @@ #include #include +#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); } diff --git a/src/gallium/winsys/lima/drm/lima_drm_winsys.c b/src/gallium/winsys/lima/drm/lima_drm_winsys.c index 046b47b65e7..b23f1113776 100644 --- a/src/gallium/winsys/lima/drm/lima_drm_winsys.c +++ b/src/gallium/winsys/lima/drm/lima_drm_winsys.c @@ -26,6 +26,7 @@ #include #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); } diff --git a/src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.c b/src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.c index d123c8a1c17..3c8345b249f 100644 --- a/src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.c +++ b/src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.c @@ -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) diff --git a/src/gallium/winsys/panfrost/drm/panfrost_drm_winsys.c b/src/gallium/winsys/panfrost/drm/panfrost_drm_winsys.c index 1852e1c662a..ac47da455a0 100644 --- a/src/gallium/winsys/panfrost/drm/panfrost_drm_winsys.c +++ b/src/gallium/winsys/panfrost/drm/panfrost_drm_winsys.c @@ -25,6 +25,8 @@ #include #include +#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); } diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c index f2ed0d725d4..196dd7322e6 100644 --- a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c +++ b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c @@ -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; diff --git a/src/gallium/winsys/svga/drm/vmw_screen.c b/src/gallium/winsys/svga/drm/vmw_screen.c index 917c7ef2f25..e97f1621ed4 100644 --- a/src/gallium/winsys/svga/drm/vmw_screen.c +++ b/src/gallium/winsys/svga/drm/vmw_screen.c @@ -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; diff --git a/src/gallium/winsys/tegra/drm/tegra_drm_winsys.c b/src/gallium/winsys/tegra/drm/tegra_drm_winsys.c index e2a8efb0f63..9f1732a5497 100644 --- a/src/gallium/winsys/tegra/drm/tegra_drm_winsys.c +++ b/src/gallium/winsys/tegra/drm/tegra_drm_winsys.c @@ -23,6 +23,7 @@ #include +#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; diff --git a/src/gallium/winsys/v3d/drm/v3d_drm_winsys.c b/src/gallium/winsys/v3d/drm/v3d_drm_winsys.c index 1502cc728c4..63681e1ba11 100644 --- a/src/gallium/winsys/v3d/drm/v3d_drm_winsys.c +++ b/src/gallium/winsys/v3d/drm/v3d_drm_winsys.c @@ -24,6 +24,8 @@ #include #include +#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 * diff --git a/src/gallium/winsys/vc4/drm/vc4_drm_winsys.c b/src/gallium/winsys/vc4/drm/vc4_drm_winsys.c index 2d05ac8cc92..a507821a940 100644 --- a/src/gallium/winsys/vc4/drm/vc4_drm_winsys.c +++ b/src/gallium/winsys/vc4/drm/vc4_drm_winsys.c @@ -25,6 +25,8 @@ #include #include +#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); diff --git a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c index b19bdf4b6f8..01ca1018172 100644 --- a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c +++ b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c @@ -29,6 +29,7 @@ #include #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) {