replace all F_DUPFD_CLOEXEC with os_dupfd_cloexec()
authorEric Engestrom <eric@engestrom.ch>
Thu, 4 Jun 2020 23:09:35 +0000 (01:09 +0200)
committerMarge Bot <eric+marge@anholt.net>
Thu, 18 Jun 2020 02:09:56 +0000 (02:09 +0000)
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>

19 files changed:
src/egl/drivers/dri2/platform_android.c
src/egl/drivers/dri2/platform_drm.c
src/egl/main/egldisplay.c
src/freedreno/vulkan/tu_fence.c
src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
src/gallium/auxiliary/pipe-loader/pipe_loader_sw.c
src/gallium/drivers/lima/lima_fence.c
src/gallium/drivers/vc4/vc4_fence.c
src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c
src/gallium/winsys/iris/drm/iris_drm_winsys.c
src/gallium/winsys/lima/drm/lima_drm_winsys.c
src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.c
src/gallium/winsys/panfrost/drm/panfrost_drm_winsys.c
src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
src/gallium/winsys/svga/drm/vmw_screen.c
src/gallium/winsys/tegra/drm/tegra_drm_winsys.c
src/gallium/winsys/v3d/drm/v3d_drm_winsys.c
src/gallium/winsys/vc4/drm/vc4_drm_winsys.c
src/gallium/winsys/virgl/drm/virgl_drm_winsys.c

index 31acf540657862555b0297985fa80438daa0f442..b72ee0479448425f35b770503699e6264bf446ec 100644 (file)
@@ -39,6 +39,8 @@
 #include <sys/types.h>
 #include <drm-uapi/drm_fourcc.h>
 
 #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"
 #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;
    }
 
       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;
 
    if (dri2_dpy->fd < 0)
       return EGL_FALSE;
 
index d25141a52a27b1a1e7f51e9b6d702184d2b5c2a6..9e601e7d5b375addbea679b30afa826fde8e9c7a 100644 (file)
@@ -36,6 +36,8 @@
 #include <fcntl.h>
 #include <unistd.h>
 
 #include <fcntl.h>
 #include <unistd.h>
 
+#include "util/os_file.h"
+
 #include "egl_dri2.h"
 #include "egl_dri2_fallbacks.h"
 #include "loader.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->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;
       if (dri2_dpy->fd < 0) {
          err = "DRI2: failed to fcntl() existing gbm device";
          goto cleanup;
index f6e85c79aa903513d39bd6f7e1d970c5d11383f6..8cf9cb83a9155a9b3214e05ce77fa2280f92f311 100644 (file)
@@ -39,6 +39,7 @@
 #include <fcntl.h>
 #include "c11/threads.h"
 #include "util/macros.h"
 #include <fcntl.h>
 #include "c11/threads.h"
 #include "util/macros.h"
+#include "util/os_file.h"
 #include "util/u_atomic.h"
 
 #include "eglcontext.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) {
     * 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");
       if (display->Options.fd == -1) {
          /* Do not (really) need to teardown the display */
          _eglError(EGL_BAD_ALLOC, "eglGetPlatformDisplay");
index 9e4a92370f88404f522423b00179199be00a3aa9..62094c91092c561c85b135eb4968c83c6f90983f 100644 (file)
@@ -27,6 +27,7 @@
 #include <libsync.h>
 #include <unistd.h>
 
 #include <libsync.h>
 #include <unistd.h>
 
+#include "util/os_file.h"
 #include "util/os_time.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) {
    /* 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);
       if (fd < 0) {
          tu_loge("failed to dup fd %d for fence", src->fd);
          sync_wait(src->fd, -1);
index 5d6865be1b09dd6f596b015319bdfbabd8ecaaf7..c5126f16fd47db6181d408844f0c33b787f47760 100644 (file)
@@ -42,6 +42,7 @@
 #include "frontend/drm_driver.h"
 #include "pipe_loader_priv.h"
 
 #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"
 #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;
 
    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);
      return false;
 
    ret = pipe_loader_drm_probe_fd_nodup(dev, new_fd);
index 74329e4cba9ac6f5699553480db5cced7f7a00b3..b3932c7464cba0fae077fa62d52d0a872f2bb60f 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "pipe_loader_priv.h"
 
 
 #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"
 #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 (!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++) {
       goto fail;
 
    for (i = 0; sdev->dd->winsys[i].name; i++) {
index c00fcea5772bf563743c2a44b5a337bd6f3155a1..193e3ee81eb1373bdceba7d5a8b63203f2d300c8 100644 (file)
@@ -25,6 +25,7 @@
 #include <fcntl.h>
 #include <libsync.h>
 
 #include <fcntl.h>
 #include <libsync.h>
 
+#include "util/os_file.h"
 #include <util/u_memory.h>
 #include <util/u_inlines.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);
                      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
 }
 
 static void
@@ -83,7 +84,7 @@ static int
 lima_fence_get_fd(struct pipe_screen *pscreen,
                   struct pipe_fence_handle *fence)
 {
 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
 }
 
 static void
index 7e2be3eeb3610cb31b2064852d48e818566782f7..ac49a7be337f9e3294d81a8e0d18606b1f1885d7 100644 (file)
@@ -37,6 +37,7 @@
 #include <libsync.h>
 #include <fcntl.h>
 
 #include <libsync.h>
 #include <fcntl.h>
 
+#include "util/os_file.h"
 #include "util/u_inlines.h"
 
 #include "vc4_screen.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,
 
         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
 }
 
 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);
 
 {
         struct vc4_fence *fence = vc4_fence(pfence);
 
-        return fcntl(fence->fd, F_DUPFD_CLOEXEC, 3);
+        return os_dupfd_cloexec(fence->fd);
 }
 
 int
 }
 
 int
index b4ae6cf1223f1f92d381721a2c8b8af76dd85232..da9a44e8c84b5bc8af5f5cc0cbadaab08bad667d 100644 (file)
@@ -365,7 +365,7 @@ amdgpu_winsys_create(int fd, const struct pipe_screen_config *config,
       return NULL;
 
    pipe_reference_init(&ws->reference, 1);
       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);
 
    /* Look up the winsys from the dev table. */
    simple_mtx_lock(&dev_tab_mutex);
index b63dd46255b9836a31de66ea624a3c8b7fbeff92..57954e4827387e59852bf756b1e8ca4fb86e8b50 100644 (file)
 #include <unistd.h>
 #include <fcntl.h>
 
 #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)
 {
 #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);
 }
 }
index 046b47b65e7b37236404400f31ba823b88f9d0bb..b23f11137763ddb8590671b6888839c8960ef20e 100644 (file)
@@ -26,6 +26,7 @@
 #include <sys/stat.h>
 
 #include "c11/threads.h"
 #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"
 #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 {
    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) {
 
       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)
 {
 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);
 }
 }
index d123c8a1c177e65ae14233181a9097f73ef815f1..3c8345b249fbab079987dbfcbc302b7e71767af4 100644 (file)
@@ -4,6 +4,7 @@
 #include "pipe/p_context.h"
 #include "pipe/p_state.h"
 #include "util/format/u_format.h"
 #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"
 #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.
         */
         * 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)
 
        ret = nouveau_drm_new(dupfd, &drm);
        if (ret)
index 1852e1c662acbcae76e22198cb977e696fa8be1e..ac47da455a021c2169f46612b0ee9877916fca52 100644 (file)
@@ -25,6 +25,8 @@
 #include <unistd.h>
 #include <fcntl.h>
 
 #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"
 #include "renderonly/renderonly.h"
 #include "panfrost_drm_public.h"
 #include "panfrost/pan_public.h"
 struct pipe_screen *
 panfrost_drm_screen_create(int fd)
 {
 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)
 {
 }
 
 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);
 }
 }
index f2ed0d725d4d3e0178441c1b253f1e0b2826edb9..196dd7322e6ad00d67b51fdd48cf93596c8e2c89 100644 (file)
@@ -29,6 +29,7 @@
 #include "radeon_drm_cs.h"
 #include "radeon_drm_public.h"
 
 #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"
 #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;
    }
 
       return NULL;
    }
 
-   ws->fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
+   ws->fd = os_dupfd_cloexec(fd);
 
    if (!do_winsys_init(ws))
       goto fail1;
 
    if (!do_winsys_init(ws))
       goto fail1;
index 917c7ef2f2510c78cd9ab792729341685782adc7..e97f1621ed4dfef7bc1eb86fec60dbf5adbd780e 100644 (file)
@@ -28,6 +28,7 @@
 #include "vmw_fence.h"
 #include "vmw_context.h"
 
 #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"
 #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->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;
    vws->force_coherent = FALSE;
    if (!vmw_ioctl_init(vws))
       goto out_no_ioctl;
index e2a8efb0f63ff2f20b7df89e6176dd1f49e41df0..9f1732a549762942f73ac671dd495514e002502a 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <fcntl.h>
 
 
 #include <fcntl.h>
 
+#include "util/os_file.h"
 #include "util/u_debug.h"
 
 #include "tegra/tegra_screen.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.
     */
     * 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;
 
    if (fd < 0)
       return NULL;
 
index 1502cc728c45e28f904ef7e945b12641c476420c..63681e1ba11755b5ddb9e8f64d6cfdaad80f201b 100644 (file)
@@ -24,6 +24,8 @@
 #include <unistd.h>
 #include <fcntl.h>
 
 #include <unistd.h>
 #include <fcntl.h>
 
+#include "util/os_file.h"
+
 #include "v3d_drm_public.h"
 
 #include "v3d/v3d_screen.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)
 {
 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 *
 }
 
 struct pipe_screen *
index 2d05ac8cc92203d45e9947acd3fdc6f05282fddb..a507821a940d51ca2d92ea5b97a18cbe4180043b 100644 (file)
@@ -25,6 +25,8 @@
 #include <fcntl.h>
 #include <sys/ioctl.h>
 
 #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"
 #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)
 #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);
 
 #ifdef GALLIUM_KMSRO
    return kmsro_drm_screen_create(fd, config);
index b19bdf4b6f803264cec1db98c458b63e8084a6e9..01ca10181725ed42cc4fbd6dd9b711b5b20e6c99 100644 (file)
@@ -29,6 +29,7 @@
 #include <sys/stat.h>
 
 #include "os/os_mman.h"
 #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"
 #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;
       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) {
 
       vws = virgl_drm_winsys_create(dup_fd);
       if (!vws) {